Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:43:10

0001 // Copyright 2005, Google Inc.
0002 // All rights reserved.
0003 //
0004 // Redistribution and use in source and binary forms, with or without
0005 // modification, are permitted provided that the following conditions are
0006 // met:
0007 //
0008 //     * Redistributions of source code must retain the above copyright
0009 // notice, this list of conditions and the following disclaimer.
0010 //     * Redistributions in binary form must reproduce the above
0011 // copyright notice, this list of conditions and the following disclaimer
0012 // in the documentation and/or other materials provided with the
0013 // distribution.
0014 //     * Neither the name of Google Inc. nor the names of its
0015 // contributors may be used to endorse or promote products derived from
0016 // this software without specific prior written permission.
0017 //
0018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0019 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0020 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0021 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0022 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0023 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0024 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0025 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0026 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0027 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0028 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0029 
0030 // The Google C++ Testing and Mocking Framework (Google Test)
0031 //
0032 // This header file defines the public API for Google Test.  It should be
0033 // included by any test program that uses Google Test.
0034 //
0035 // IMPORTANT NOTE: Due to limitation of the C++ language, we have to
0036 // leave some internal implementation details in this header file.
0037 // They are clearly marked by comments like this:
0038 //
0039 //   // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
0040 //
0041 // Such code is NOT meant to be used by a user directly, and is subject
0042 // to CHANGE WITHOUT NOTICE.  Therefore DO NOT DEPEND ON IT in a user
0043 // program!
0044 //
0045 // Acknowledgment: Google Test borrowed the idea of automatic test
0046 // registration from Barthelemy Dagenais' (barthelemy@prologique.com)
0047 // easyUnit framework.
0048 
0049 #ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_H_
0050 #define GOOGLETEST_INCLUDE_GTEST_GTEST_H_
0051 
0052 #include <cstddef>
0053 #include <limits>
0054 #include <memory>
0055 #include <ostream>
0056 #include <type_traits>
0057 #include <vector>
0058 
0059 #include "gtest/gtest-assertion-result.h"
0060 #include "gtest/gtest-death-test.h"
0061 #include "gtest/gtest-matchers.h"
0062 #include "gtest/gtest-message.h"
0063 #include "gtest/gtest-param-test.h"
0064 #include "gtest/gtest-printers.h"
0065 #include "gtest/gtest-test-part.h"
0066 #include "gtest/gtest-typed-test.h"
0067 #include "gtest/gtest_pred_impl.h"
0068 #include "gtest/gtest_prod.h"
0069 #include "gtest/internal/gtest-internal.h"
0070 #include "gtest/internal/gtest-string.h"
0071 
0072 GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
0073 /* class A needs to have dll-interface to be used by clients of class B */)
0074 
0075 // Declares the flags.
0076 
0077 // This flag temporary enables the disabled tests.
0078 GTEST_DECLARE_bool_(also_run_disabled_tests);
0079 
0080 // This flag brings the debugger on an assertion failure.
0081 GTEST_DECLARE_bool_(break_on_failure);
0082 
0083 // This flag controls whether Google Test catches all test-thrown exceptions
0084 // and logs them as failures.
0085 GTEST_DECLARE_bool_(catch_exceptions);
0086 
0087 // This flag enables using colors in terminal output. Available values are
0088 // "yes" to enable colors, "no" (disable colors), or "auto" (the default)
0089 // to let Google Test decide.
0090 GTEST_DECLARE_string_(color);
0091 
0092 // This flag controls whether the test runner should continue execution past
0093 // first failure.
0094 GTEST_DECLARE_bool_(fail_fast);
0095 
0096 // This flag sets up the filter to select by name using a glob pattern
0097 // the tests to run. If the filter is not given all tests are executed.
0098 GTEST_DECLARE_string_(filter);
0099 
0100 // This flag controls whether Google Test installs a signal handler that dumps
0101 // debugging information when fatal signals are raised.
0102 GTEST_DECLARE_bool_(install_failure_signal_handler);
0103 
0104 // This flag causes the Google Test to list tests. None of the tests listed
0105 // are actually run if the flag is provided.
0106 GTEST_DECLARE_bool_(list_tests);
0107 
0108 // This flag controls whether Google Test emits a detailed XML report to a file
0109 // in addition to its normal textual output.
0110 GTEST_DECLARE_string_(output);
0111 
0112 // This flags control whether Google Test prints only test failures.
0113 GTEST_DECLARE_bool_(brief);
0114 
0115 // This flags control whether Google Test prints the elapsed time for each
0116 // test.
0117 GTEST_DECLARE_bool_(print_time);
0118 
0119 // This flags control whether Google Test prints UTF8 characters as text.
0120 GTEST_DECLARE_bool_(print_utf8);
0121 
0122 // This flag specifies the random number seed.
0123 GTEST_DECLARE_int32_(random_seed);
0124 
0125 // This flag sets how many times the tests are repeated. The default value
0126 // is 1. If the value is -1 the tests are repeating forever.
0127 GTEST_DECLARE_int32_(repeat);
0128 
0129 // This flag controls whether Google Test Environments are recreated for each
0130 // repeat of the tests. The default value is true. If set to false the global
0131 // test Environment objects are only set up once, for the first iteration, and
0132 // only torn down once, for the last.
0133 GTEST_DECLARE_bool_(recreate_environments_when_repeating);
0134 
0135 // This flag controls whether Google Test includes Google Test internal
0136 // stack frames in failure stack traces.
0137 GTEST_DECLARE_bool_(show_internal_stack_frames);
0138 
0139 // When this flag is specified, tests' order is randomized on every iteration.
0140 GTEST_DECLARE_bool_(shuffle);
0141 
0142 // This flag specifies the maximum number of stack frames to be
0143 // printed in a failure message.
0144 GTEST_DECLARE_int32_(stack_trace_depth);
0145 
0146 // When this flag is specified, a failed assertion will throw an
0147 // exception if exceptions are enabled, or exit the program with a
0148 // non-zero code otherwise. For use with an external test framework.
0149 GTEST_DECLARE_bool_(throw_on_failure);
0150 
0151 // When this flag is set with a "host:port" string, on supported
0152 // platforms test results are streamed to the specified port on
0153 // the specified host machine.
0154 GTEST_DECLARE_string_(stream_result_to);
0155 
0156 #if GTEST_USE_OWN_FLAGFILE_FLAG_
0157 GTEST_DECLARE_string_(flagfile);
0158 #endif  // GTEST_USE_OWN_FLAGFILE_FLAG_
0159 
0160 namespace testing {
0161 
0162 // Silence C4100 (unreferenced formal parameter) and 4805
0163 // unsafe mix of type 'const int' and type 'const bool'
0164 #ifdef _MSC_VER
0165 #pragma warning(push)
0166 #pragma warning(disable : 4805)
0167 #pragma warning(disable : 4100)
0168 #endif
0169 
0170 // The upper limit for valid stack trace depths.
0171 const int kMaxStackTraceDepth = 100;
0172 
0173 namespace internal {
0174 
0175 class AssertHelper;
0176 class DefaultGlobalTestPartResultReporter;
0177 class ExecDeathTest;
0178 class NoExecDeathTest;
0179 class FinalSuccessChecker;
0180 class GTestFlagSaver;
0181 class StreamingListenerTest;
0182 class TestResultAccessor;
0183 class TestEventListenersAccessor;
0184 class TestEventRepeater;
0185 class UnitTestRecordPropertyTestHelper;
0186 class WindowsDeathTest;
0187 class FuchsiaDeathTest;
0188 class UnitTestImpl* GetUnitTestImpl();
0189 void ReportFailureInUnknownLocation(TestPartResult::Type result_type,
0190                                     const std::string& message);
0191 std::set<std::string>* GetIgnoredParameterizedTestSuites();
0192 
0193 }  // namespace internal
0194 
0195 // The friend relationship of some of these classes is cyclic.
0196 // If we don't forward declare them the compiler might confuse the classes
0197 // in friendship clauses with same named classes on the scope.
0198 class Test;
0199 class TestSuite;
0200 
0201 // Old API is still available but deprecated
0202 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
0203 using TestCase = TestSuite;
0204 #endif
0205 class TestInfo;
0206 class UnitTest;
0207 
0208 // The abstract class that all tests inherit from.
0209 //
0210 // In Google Test, a unit test program contains one or many TestSuites, and
0211 // each TestSuite contains one or many Tests.
0212 //
0213 // When you define a test using the TEST macro, you don't need to
0214 // explicitly derive from Test - the TEST macro automatically does
0215 // this for you.
0216 //
0217 // The only time you derive from Test is when defining a test fixture
0218 // to be used in a TEST_F.  For example:
0219 //
0220 //   class FooTest : public testing::Test {
0221 //    protected:
0222 //     void SetUp() override { ... }
0223 //     void TearDown() override { ... }
0224 //     ...
0225 //   };
0226 //
0227 //   TEST_F(FooTest, Bar) { ... }
0228 //   TEST_F(FooTest, Baz) { ... }
0229 //
0230 // Test is not copyable.
0231 class GTEST_API_ Test {
0232  public:
0233   friend class TestInfo;
0234 
0235   // The d'tor is virtual as we intend to inherit from Test.
0236   virtual ~Test();
0237 
0238   // Sets up the stuff shared by all tests in this test suite.
0239   //
0240   // Google Test will call Foo::SetUpTestSuite() before running the first
0241   // test in test suite Foo.  Hence a sub-class can define its own
0242   // SetUpTestSuite() method to shadow the one defined in the super
0243   // class.
0244   static void SetUpTestSuite() {}
0245 
0246   // Tears down the stuff shared by all tests in this test suite.
0247   //
0248   // Google Test will call Foo::TearDownTestSuite() after running the last
0249   // test in test suite Foo.  Hence a sub-class can define its own
0250   // TearDownTestSuite() method to shadow the one defined in the super
0251   // class.
0252   static void TearDownTestSuite() {}
0253 
0254   // Legacy API is deprecated but still available. Use SetUpTestSuite and
0255   // TearDownTestSuite instead.
0256 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
0257   static void TearDownTestCase() {}
0258   static void SetUpTestCase() {}
0259 #endif  // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
0260 
0261   // Returns true if and only if the current test has a fatal failure.
0262   static bool HasFatalFailure();
0263 
0264   // Returns true if and only if the current test has a non-fatal failure.
0265   static bool HasNonfatalFailure();
0266 
0267   // Returns true if and only if the current test was skipped.
0268   static bool IsSkipped();
0269 
0270   // Returns true if and only if the current test has a (either fatal or
0271   // non-fatal) failure.
0272   static bool HasFailure() { return HasFatalFailure() || HasNonfatalFailure(); }
0273 
0274   // Logs a property for the current test, test suite, or for the entire
0275   // invocation of the test program when used outside of the context of a
0276   // test suite.  Only the last value for a given key is remembered.  These
0277   // are public static so they can be called from utility functions that are
0278   // not members of the test fixture.  Calls to RecordProperty made during
0279   // lifespan of the test (from the moment its constructor starts to the
0280   // moment its destructor finishes) will be output in XML as attributes of
0281   // the <testcase> element.  Properties recorded from fixture's
0282   // SetUpTestSuite or TearDownTestSuite are logged as attributes of the
0283   // corresponding <testsuite> element.  Calls to RecordProperty made in the
0284   // global context (before or after invocation of RUN_ALL_TESTS and from
0285   // SetUp/TearDown method of Environment objects registered with Google
0286   // Test) will be output as attributes of the <testsuites> element.
0287   static void RecordProperty(const std::string& key, const std::string& value);
0288   static void RecordProperty(const std::string& key, int value);
0289 
0290  protected:
0291   // Creates a Test object.
0292   Test();
0293 
0294   // Sets up the test fixture.
0295   virtual void SetUp();
0296 
0297   // Tears down the test fixture.
0298   virtual void TearDown();
0299 
0300  private:
0301   // Returns true if and only if the current test has the same fixture class
0302   // as the first test in the current test suite.
0303   static bool HasSameFixtureClass();
0304 
0305   // Runs the test after the test fixture has been set up.
0306   //
0307   // A sub-class must implement this to define the test logic.
0308   //
0309   // DO NOT OVERRIDE THIS FUNCTION DIRECTLY IN A USER PROGRAM.
0310   // Instead, use the TEST or TEST_F macro.
0311   virtual void TestBody() = 0;
0312 
0313   // Sets up, executes, and tears down the test.
0314   void Run();
0315 
0316   // Deletes self.  We deliberately pick an unusual name for this
0317   // internal method to avoid clashing with names used in user TESTs.
0318   void DeleteSelf_() { delete this; }
0319 
0320   const std::unique_ptr<GTEST_FLAG_SAVER_> gtest_flag_saver_;
0321 
0322   // Often a user misspells SetUp() as Setup() and spends a long time
0323   // wondering why it is never called by Google Test.  The declaration of
0324   // the following method is solely for catching such an error at
0325   // compile time:
0326   //
0327   //   - The return type is deliberately chosen to be not void, so it
0328   //   will be a conflict if void Setup() is declared in the user's
0329   //   test fixture.
0330   //
0331   //   - This method is private, so it will be another compiler error
0332   //   if the method is called from the user's test fixture.
0333   //
0334   // DO NOT OVERRIDE THIS FUNCTION.
0335   //
0336   // If you see an error about overriding the following function or
0337   // about it being private, you have mis-spelled SetUp() as Setup().
0338   struct Setup_should_be_spelled_SetUp {};
0339   virtual Setup_should_be_spelled_SetUp* Setup() { return nullptr; }
0340 
0341   // We disallow copying Tests.
0342   Test(const Test&) = delete;
0343   Test& operator=(const Test&) = delete;
0344 };
0345 
0346 typedef internal::TimeInMillis TimeInMillis;
0347 
0348 // A copyable object representing a user specified test property which can be
0349 // output as a key/value string pair.
0350 //
0351 // Don't inherit from TestProperty as its destructor is not virtual.
0352 class TestProperty {
0353  public:
0354   // C'tor.  TestProperty does NOT have a default constructor.
0355   // Always use this constructor (with parameters) to create a
0356   // TestProperty object.
0357   TestProperty(const std::string& a_key, const std::string& a_value)
0358       : key_(a_key), value_(a_value) {}
0359 
0360   // Gets the user supplied key.
0361   const char* key() const { return key_.c_str(); }
0362 
0363   // Gets the user supplied value.
0364   const char* value() const { return value_.c_str(); }
0365 
0366   // Sets a new value, overriding the one supplied in the constructor.
0367   void SetValue(const std::string& new_value) { value_ = new_value; }
0368 
0369  private:
0370   // The key supplied by the user.
0371   std::string key_;
0372   // The value supplied by the user.
0373   std::string value_;
0374 };
0375 
0376 // The result of a single Test.  This includes a list of
0377 // TestPartResults, a list of TestProperties, a count of how many
0378 // death tests there are in the Test, and how much time it took to run
0379 // the Test.
0380 //
0381 // TestResult is not copyable.
0382 class GTEST_API_ TestResult {
0383  public:
0384   // Creates an empty TestResult.
0385   TestResult();
0386 
0387   // D'tor.  Do not inherit from TestResult.
0388   ~TestResult();
0389 
0390   // Gets the number of all test parts.  This is the sum of the number
0391   // of successful test parts and the number of failed test parts.
0392   int total_part_count() const;
0393 
0394   // Returns the number of the test properties.
0395   int test_property_count() const;
0396 
0397   // Returns true if and only if the test passed (i.e. no test part failed).
0398   bool Passed() const { return !Skipped() && !Failed(); }
0399 
0400   // Returns true if and only if the test was skipped.
0401   bool Skipped() const;
0402 
0403   // Returns true if and only if the test failed.
0404   bool Failed() const;
0405 
0406   // Returns true if and only if the test fatally failed.
0407   bool HasFatalFailure() const;
0408 
0409   // Returns true if and only if the test has a non-fatal failure.
0410   bool HasNonfatalFailure() const;
0411 
0412   // Returns the elapsed time, in milliseconds.
0413   TimeInMillis elapsed_time() const { return elapsed_time_; }
0414 
0415   // Gets the time of the test case start, in ms from the start of the
0416   // UNIX epoch.
0417   TimeInMillis start_timestamp() const { return start_timestamp_; }
0418 
0419   // Returns the i-th test part result among all the results. i can range from 0
0420   // to total_part_count() - 1. If i is not in that range, aborts the program.
0421   const TestPartResult& GetTestPartResult(int i) const;
0422 
0423   // Returns the i-th test property. i can range from 0 to
0424   // test_property_count() - 1. If i is not in that range, aborts the
0425   // program.
0426   const TestProperty& GetTestProperty(int i) const;
0427 
0428  private:
0429   friend class TestInfo;
0430   friend class TestSuite;
0431   friend class UnitTest;
0432   friend class internal::DefaultGlobalTestPartResultReporter;
0433   friend class internal::ExecDeathTest;
0434   friend class internal::TestResultAccessor;
0435   friend class internal::UnitTestImpl;
0436   friend class internal::WindowsDeathTest;
0437   friend class internal::FuchsiaDeathTest;
0438 
0439   // Gets the vector of TestPartResults.
0440   const std::vector<TestPartResult>& test_part_results() const {
0441     return test_part_results_;
0442   }
0443 
0444   // Gets the vector of TestProperties.
0445   const std::vector<TestProperty>& test_properties() const {
0446     return test_properties_;
0447   }
0448 
0449   // Sets the start time.
0450   void set_start_timestamp(TimeInMillis start) { start_timestamp_ = start; }
0451 
0452   // Sets the elapsed time.
0453   void set_elapsed_time(TimeInMillis elapsed) { elapsed_time_ = elapsed; }
0454 
0455   // Adds a test property to the list. The property is validated and may add
0456   // a non-fatal failure if invalid (e.g., if it conflicts with reserved
0457   // key names). If a property is already recorded for the same key, the
0458   // value will be updated, rather than storing multiple values for the same
0459   // key.  xml_element specifies the element for which the property is being
0460   // recorded and is used for validation.
0461   void RecordProperty(const std::string& xml_element,
0462                       const TestProperty& test_property);
0463 
0464   // Adds a failure if the key is a reserved attribute of Google Test
0465   // testsuite tags.  Returns true if the property is valid.
0466   // FIXME: Validate attribute names are legal and human readable.
0467   static bool ValidateTestProperty(const std::string& xml_element,
0468                                    const TestProperty& test_property);
0469 
0470   // Adds a test part result to the list.
0471   void AddTestPartResult(const TestPartResult& test_part_result);
0472 
0473   // Returns the death test count.
0474   int death_test_count() const { return death_test_count_; }
0475 
0476   // Increments the death test count, returning the new count.
0477   int increment_death_test_count() { return ++death_test_count_; }
0478 
0479   // Clears the test part results.
0480   void ClearTestPartResults();
0481 
0482   // Clears the object.
0483   void Clear();
0484 
0485   // Protects mutable state of the property vector and of owned
0486   // properties, whose values may be updated.
0487   internal::Mutex test_properties_mutex_;
0488 
0489   // The vector of TestPartResults
0490   std::vector<TestPartResult> test_part_results_;
0491   // The vector of TestProperties
0492   std::vector<TestProperty> test_properties_;
0493   // Running count of death tests.
0494   int death_test_count_;
0495   // The start time, in milliseconds since UNIX Epoch.
0496   TimeInMillis start_timestamp_;
0497   // The elapsed time, in milliseconds.
0498   TimeInMillis elapsed_time_;
0499 
0500   // We disallow copying TestResult.
0501   TestResult(const TestResult&) = delete;
0502   TestResult& operator=(const TestResult&) = delete;
0503 };  // class TestResult
0504 
0505 // A TestInfo object stores the following information about a test:
0506 //
0507 //   Test suite name
0508 //   Test name
0509 //   Whether the test should be run
0510 //   A function pointer that creates the test object when invoked
0511 //   Test result
0512 //
0513 // The constructor of TestInfo registers itself with the UnitTest
0514 // singleton such that the RUN_ALL_TESTS() macro knows which tests to
0515 // run.
0516 class GTEST_API_ TestInfo {
0517  public:
0518   // Destructs a TestInfo object.  This function is not virtual, so
0519   // don't inherit from TestInfo.
0520   ~TestInfo();
0521 
0522   // Returns the test suite name.
0523   const char* test_suite_name() const { return test_suite_name_.c_str(); }
0524 
0525 // Legacy API is deprecated but still available
0526 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
0527   const char* test_case_name() const { return test_suite_name(); }
0528 #endif  // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
0529 
0530   // Returns the test name.
0531   const char* name() const { return name_.c_str(); }
0532 
0533   // Returns the name of the parameter type, or NULL if this is not a typed
0534   // or a type-parameterized test.
0535   const char* type_param() const {
0536     if (type_param_.get() != nullptr) return type_param_->c_str();
0537     return nullptr;
0538   }
0539 
0540   // Returns the text representation of the value parameter, or NULL if this
0541   // is not a value-parameterized test.
0542   const char* value_param() const {
0543     if (value_param_.get() != nullptr) return value_param_->c_str();
0544     return nullptr;
0545   }
0546 
0547   // Returns the file name where this test is defined.
0548   const char* file() const { return location_.file.c_str(); }
0549 
0550   // Returns the line where this test is defined.
0551   int line() const { return location_.line; }
0552 
0553   // Return true if this test should not be run because it's in another shard.
0554   bool is_in_another_shard() const { return is_in_another_shard_; }
0555 
0556   // Returns true if this test should run, that is if the test is not
0557   // disabled (or it is disabled but the also_run_disabled_tests flag has
0558   // been specified) and its full name matches the user-specified filter.
0559   //
0560   // Google Test allows the user to filter the tests by their full names.
0561   // The full name of a test Bar in test suite Foo is defined as
0562   // "Foo.Bar".  Only the tests that match the filter will run.
0563   //
0564   // A filter is a colon-separated list of glob (not regex) patterns,
0565   // optionally followed by a '-' and a colon-separated list of
0566   // negative patterns (tests to exclude).  A test is run if it
0567   // matches one of the positive patterns and does not match any of
0568   // the negative patterns.
0569   //
0570   // For example, *A*:Foo.* is a filter that matches any string that
0571   // contains the character 'A' or starts with "Foo.".
0572   bool should_run() const { return should_run_; }
0573 
0574   // Returns true if and only if this test will appear in the XML report.
0575   bool is_reportable() const {
0576     // The XML report includes tests matching the filter, excluding those
0577     // run in other shards.
0578     return matches_filter_ && !is_in_another_shard_;
0579   }
0580 
0581   // Returns the result of the test.
0582   const TestResult* result() const { return &result_; }
0583 
0584  private:
0585 #if GTEST_HAS_DEATH_TEST
0586   friend class internal::DefaultDeathTestFactory;
0587 #endif  // GTEST_HAS_DEATH_TEST
0588   friend class Test;
0589   friend class TestSuite;
0590   friend class internal::UnitTestImpl;
0591   friend class internal::StreamingListenerTest;
0592   friend TestInfo* internal::MakeAndRegisterTestInfo(
0593       const char* test_suite_name, const char* name, const char* type_param,
0594       const char* value_param, internal::CodeLocation code_location,
0595       internal::TypeId fixture_class_id, internal::SetUpTestSuiteFunc set_up_tc,
0596       internal::TearDownTestSuiteFunc tear_down_tc,
0597       internal::TestFactoryBase* factory);
0598 
0599   // Constructs a TestInfo object. The newly constructed instance assumes
0600   // ownership of the factory object.
0601   TestInfo(const std::string& test_suite_name, const std::string& name,
0602            const char* a_type_param,   // NULL if not a type-parameterized test
0603            const char* a_value_param,  // NULL if not a value-parameterized test
0604            internal::CodeLocation a_code_location,
0605            internal::TypeId fixture_class_id,
0606            internal::TestFactoryBase* factory);
0607 
0608   // Increments the number of death tests encountered in this test so
0609   // far.
0610   int increment_death_test_count() {
0611     return result_.increment_death_test_count();
0612   }
0613 
0614   // Creates the test object, runs it, records its result, and then
0615   // deletes it.
0616   void Run();
0617 
0618   // Skip and records the test result for this object.
0619   void Skip();
0620 
0621   static void ClearTestResult(TestInfo* test_info) {
0622     test_info->result_.Clear();
0623   }
0624 
0625   // These fields are immutable properties of the test.
0626   const std::string test_suite_name_;  // test suite name
0627   const std::string name_;             // Test name
0628   // Name of the parameter type, or NULL if this is not a typed or a
0629   // type-parameterized test.
0630   const std::unique_ptr<const ::std::string> type_param_;
0631   // Text representation of the value parameter, or NULL if this is not a
0632   // value-parameterized test.
0633   const std::unique_ptr<const ::std::string> value_param_;
0634   internal::CodeLocation location_;
0635   const internal::TypeId fixture_class_id_;  // ID of the test fixture class
0636   bool should_run_;           // True if and only if this test should run
0637   bool is_disabled_;          // True if and only if this test is disabled
0638   bool matches_filter_;       // True if this test matches the
0639                               // user-specified filter.
0640   bool is_in_another_shard_;  // Will be run in another shard.
0641   internal::TestFactoryBase* const factory_;  // The factory that creates
0642                                               // the test object
0643 
0644   // This field is mutable and needs to be reset before running the
0645   // test for the second time.
0646   TestResult result_;
0647 
0648   TestInfo(const TestInfo&) = delete;
0649   TestInfo& operator=(const TestInfo&) = delete;
0650 };
0651 
0652 // A test suite, which consists of a vector of TestInfos.
0653 //
0654 // TestSuite is not copyable.
0655 class GTEST_API_ TestSuite {
0656  public:
0657   // Creates a TestSuite with the given name.
0658   //
0659   // TestSuite does NOT have a default constructor.  Always use this
0660   // constructor to create a TestSuite object.
0661   //
0662   // Arguments:
0663   //
0664   //   name:         name of the test suite
0665   //   a_type_param: the name of the test's type parameter, or NULL if
0666   //                 this is not a type-parameterized test.
0667   //   set_up_tc:    pointer to the function that sets up the test suite
0668   //   tear_down_tc: pointer to the function that tears down the test suite
0669   TestSuite(const char* name, const char* a_type_param,
0670             internal::SetUpTestSuiteFunc set_up_tc,
0671             internal::TearDownTestSuiteFunc tear_down_tc);
0672 
0673   // Destructor of TestSuite.
0674   virtual ~TestSuite();
0675 
0676   // Gets the name of the TestSuite.
0677   const char* name() const { return name_.c_str(); }
0678 
0679   // Returns the name of the parameter type, or NULL if this is not a
0680   // type-parameterized test suite.
0681   const char* type_param() const {
0682     if (type_param_.get() != nullptr) return type_param_->c_str();
0683     return nullptr;
0684   }
0685 
0686   // Returns true if any test in this test suite should run.
0687   bool should_run() const { return should_run_; }
0688 
0689   // Gets the number of successful tests in this test suite.
0690   int successful_test_count() const;
0691 
0692   // Gets the number of skipped tests in this test suite.
0693   int skipped_test_count() const;
0694 
0695   // Gets the number of failed tests in this test suite.
0696   int failed_test_count() const;
0697 
0698   // Gets the number of disabled tests that will be reported in the XML report.
0699   int reportable_disabled_test_count() const;
0700 
0701   // Gets the number of disabled tests in this test suite.
0702   int disabled_test_count() const;
0703 
0704   // Gets the number of tests to be printed in the XML report.
0705   int reportable_test_count() const;
0706 
0707   // Get the number of tests in this test suite that should run.
0708   int test_to_run_count() const;
0709 
0710   // Gets the number of all tests in this test suite.
0711   int total_test_count() const;
0712 
0713   // Returns true if and only if the test suite passed.
0714   bool Passed() const { return !Failed(); }
0715 
0716   // Returns true if and only if the test suite failed.
0717   bool Failed() const {
0718     return failed_test_count() > 0 || ad_hoc_test_result().Failed();
0719   }
0720 
0721   // Returns the elapsed time, in milliseconds.
0722   TimeInMillis elapsed_time() const { return elapsed_time_; }
0723 
0724   // Gets the time of the test suite start, in ms from the start of the
0725   // UNIX epoch.
0726   TimeInMillis start_timestamp() const { return start_timestamp_; }
0727 
0728   // Returns the i-th test among all the tests. i can range from 0 to
0729   // total_test_count() - 1. If i is not in that range, returns NULL.
0730   const TestInfo* GetTestInfo(int i) const;
0731 
0732   // Returns the TestResult that holds test properties recorded during
0733   // execution of SetUpTestSuite and TearDownTestSuite.
0734   const TestResult& ad_hoc_test_result() const { return ad_hoc_test_result_; }
0735 
0736  private:
0737   friend class Test;
0738   friend class internal::UnitTestImpl;
0739 
0740   // Gets the (mutable) vector of TestInfos in this TestSuite.
0741   std::vector<TestInfo*>& test_info_list() { return test_info_list_; }
0742 
0743   // Gets the (immutable) vector of TestInfos in this TestSuite.
0744   const std::vector<TestInfo*>& test_info_list() const {
0745     return test_info_list_;
0746   }
0747 
0748   // Returns the i-th test among all the tests. i can range from 0 to
0749   // total_test_count() - 1. If i is not in that range, returns NULL.
0750   TestInfo* GetMutableTestInfo(int i);
0751 
0752   // Sets the should_run member.
0753   void set_should_run(bool should) { should_run_ = should; }
0754 
0755   // Adds a TestInfo to this test suite.  Will delete the TestInfo upon
0756   // destruction of the TestSuite object.
0757   void AddTestInfo(TestInfo* test_info);
0758 
0759   // Clears the results of all tests in this test suite.
0760   void ClearResult();
0761 
0762   // Clears the results of all tests in the given test suite.
0763   static void ClearTestSuiteResult(TestSuite* test_suite) {
0764     test_suite->ClearResult();
0765   }
0766 
0767   // Runs every test in this TestSuite.
0768   void Run();
0769 
0770   // Skips the execution of tests under this TestSuite
0771   void Skip();
0772 
0773   // Runs SetUpTestSuite() for this TestSuite.  This wrapper is needed
0774   // for catching exceptions thrown from SetUpTestSuite().
0775   void RunSetUpTestSuite() {
0776     if (set_up_tc_ != nullptr) {
0777       (*set_up_tc_)();
0778     }
0779   }
0780 
0781   // Runs TearDownTestSuite() for this TestSuite.  This wrapper is
0782   // needed for catching exceptions thrown from TearDownTestSuite().
0783   void RunTearDownTestSuite() {
0784     if (tear_down_tc_ != nullptr) {
0785       (*tear_down_tc_)();
0786     }
0787   }
0788 
0789   // Returns true if and only if test passed.
0790   static bool TestPassed(const TestInfo* test_info) {
0791     return test_info->should_run() && test_info->result()->Passed();
0792   }
0793 
0794   // Returns true if and only if test skipped.
0795   static bool TestSkipped(const TestInfo* test_info) {
0796     return test_info->should_run() && test_info->result()->Skipped();
0797   }
0798 
0799   // Returns true if and only if test failed.
0800   static bool TestFailed(const TestInfo* test_info) {
0801     return test_info->should_run() && test_info->result()->Failed();
0802   }
0803 
0804   // Returns true if and only if the test is disabled and will be reported in
0805   // the XML report.
0806   static bool TestReportableDisabled(const TestInfo* test_info) {
0807     return test_info->is_reportable() && test_info->is_disabled_;
0808   }
0809 
0810   // Returns true if and only if test is disabled.
0811   static bool TestDisabled(const TestInfo* test_info) {
0812     return test_info->is_disabled_;
0813   }
0814 
0815   // Returns true if and only if this test will appear in the XML report.
0816   static bool TestReportable(const TestInfo* test_info) {
0817     return test_info->is_reportable();
0818   }
0819 
0820   // Returns true if the given test should run.
0821   static bool ShouldRunTest(const TestInfo* test_info) {
0822     return test_info->should_run();
0823   }
0824 
0825   // Shuffles the tests in this test suite.
0826   void ShuffleTests(internal::Random* random);
0827 
0828   // Restores the test order to before the first shuffle.
0829   void UnshuffleTests();
0830 
0831   // Name of the test suite.
0832   std::string name_;
0833   // Name of the parameter type, or NULL if this is not a typed or a
0834   // type-parameterized test.
0835   const std::unique_ptr<const ::std::string> type_param_;
0836   // The vector of TestInfos in their original order.  It owns the
0837   // elements in the vector.
0838   std::vector<TestInfo*> test_info_list_;
0839   // Provides a level of indirection for the test list to allow easy
0840   // shuffling and restoring the test order.  The i-th element in this
0841   // vector is the index of the i-th test in the shuffled test list.
0842   std::vector<int> test_indices_;
0843   // Pointer to the function that sets up the test suite.
0844   internal::SetUpTestSuiteFunc set_up_tc_;
0845   // Pointer to the function that tears down the test suite.
0846   internal::TearDownTestSuiteFunc tear_down_tc_;
0847   // True if and only if any test in this test suite should run.
0848   bool should_run_;
0849   // The start time, in milliseconds since UNIX Epoch.
0850   TimeInMillis start_timestamp_;
0851   // Elapsed time, in milliseconds.
0852   TimeInMillis elapsed_time_;
0853   // Holds test properties recorded during execution of SetUpTestSuite and
0854   // TearDownTestSuite.
0855   TestResult ad_hoc_test_result_;
0856 
0857   // We disallow copying TestSuites.
0858   TestSuite(const TestSuite&) = delete;
0859   TestSuite& operator=(const TestSuite&) = delete;
0860 };
0861 
0862 // An Environment object is capable of setting up and tearing down an
0863 // environment.  You should subclass this to define your own
0864 // environment(s).
0865 //
0866 // An Environment object does the set-up and tear-down in virtual
0867 // methods SetUp() and TearDown() instead of the constructor and the
0868 // destructor, as:
0869 //
0870 //   1. You cannot safely throw from a destructor.  This is a problem
0871 //      as in some cases Google Test is used where exceptions are enabled, and
0872 //      we may want to implement ASSERT_* using exceptions where they are
0873 //      available.
0874 //   2. You cannot use ASSERT_* directly in a constructor or
0875 //      destructor.
0876 class Environment {
0877  public:
0878   // The d'tor is virtual as we need to subclass Environment.
0879   virtual ~Environment() {}
0880 
0881   // Override this to define how to set up the environment.
0882   virtual void SetUp() {}
0883 
0884   // Override this to define how to tear down the environment.
0885   virtual void TearDown() {}
0886 
0887  private:
0888   // If you see an error about overriding the following function or
0889   // about it being private, you have mis-spelled SetUp() as Setup().
0890   struct Setup_should_be_spelled_SetUp {};
0891   virtual Setup_should_be_spelled_SetUp* Setup() { return nullptr; }
0892 };
0893 
0894 #if GTEST_HAS_EXCEPTIONS
0895 
0896 // Exception which can be thrown from TestEventListener::OnTestPartResult.
0897 class GTEST_API_ AssertionException
0898     : public internal::GoogleTestFailureException {
0899  public:
0900   explicit AssertionException(const TestPartResult& result)
0901       : GoogleTestFailureException(result) {}
0902 };
0903 
0904 #endif  // GTEST_HAS_EXCEPTIONS
0905 
0906 // The interface for tracing execution of tests. The methods are organized in
0907 // the order the corresponding events are fired.
0908 class TestEventListener {
0909  public:
0910   virtual ~TestEventListener() {}
0911 
0912   // Fired before any test activity starts.
0913   virtual void OnTestProgramStart(const UnitTest& unit_test) = 0;
0914 
0915   // Fired before each iteration of tests starts.  There may be more than
0916   // one iteration if GTEST_FLAG(repeat) is set. iteration is the iteration
0917   // index, starting from 0.
0918   virtual void OnTestIterationStart(const UnitTest& unit_test,
0919                                     int iteration) = 0;
0920 
0921   // Fired before environment set-up for each iteration of tests starts.
0922   virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test) = 0;
0923 
0924   // Fired after environment set-up for each iteration of tests ends.
0925   virtual void OnEnvironmentsSetUpEnd(const UnitTest& unit_test) = 0;
0926 
0927   // Fired before the test suite starts.
0928   virtual void OnTestSuiteStart(const TestSuite& /*test_suite*/) {}
0929 
0930   //  Legacy API is deprecated but still available
0931 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
0932   virtual void OnTestCaseStart(const TestCase& /*test_case*/) {}
0933 #endif  //  GTEST_REMOVE_LEGACY_TEST_CASEAPI_
0934 
0935   // Fired before the test starts.
0936   virtual void OnTestStart(const TestInfo& test_info) = 0;
0937 
0938   // Fired when a test is disabled
0939   virtual void OnTestDisabled(const TestInfo& /*test_info*/) {}
0940 
0941   // Fired after a failed assertion or a SUCCEED() invocation.
0942   // If you want to throw an exception from this function to skip to the next
0943   // TEST, it must be AssertionException defined above, or inherited from it.
0944   virtual void OnTestPartResult(const TestPartResult& test_part_result) = 0;
0945 
0946   // Fired after the test ends.
0947   virtual void OnTestEnd(const TestInfo& test_info) = 0;
0948 
0949   // Fired after the test suite ends.
0950   virtual void OnTestSuiteEnd(const TestSuite& /*test_suite*/) {}
0951 
0952 //  Legacy API is deprecated but still available
0953 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
0954   virtual void OnTestCaseEnd(const TestCase& /*test_case*/) {}
0955 #endif  //  GTEST_REMOVE_LEGACY_TEST_CASEAPI_
0956 
0957   // Fired before environment tear-down for each iteration of tests starts.
0958   virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test) = 0;
0959 
0960   // Fired after environment tear-down for each iteration of tests ends.
0961   virtual void OnEnvironmentsTearDownEnd(const UnitTest& unit_test) = 0;
0962 
0963   // Fired after each iteration of tests finishes.
0964   virtual void OnTestIterationEnd(const UnitTest& unit_test, int iteration) = 0;
0965 
0966   // Fired after all test activities have ended.
0967   virtual void OnTestProgramEnd(const UnitTest& unit_test) = 0;
0968 };
0969 
0970 // The convenience class for users who need to override just one or two
0971 // methods and are not concerned that a possible change to a signature of
0972 // the methods they override will not be caught during the build.  For
0973 // comments about each method please see the definition of TestEventListener
0974 // above.
0975 class EmptyTestEventListener : public TestEventListener {
0976  public:
0977   void OnTestProgramStart(const UnitTest& /*unit_test*/) override {}
0978   void OnTestIterationStart(const UnitTest& /*unit_test*/,
0979                             int /*iteration*/) override {}
0980   void OnEnvironmentsSetUpStart(const UnitTest& /*unit_test*/) override {}
0981   void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) override {}
0982   void OnTestSuiteStart(const TestSuite& /*test_suite*/) override {}
0983 //  Legacy API is deprecated but still available
0984 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
0985   void OnTestCaseStart(const TestCase& /*test_case*/) override {}
0986 #endif  //  GTEST_REMOVE_LEGACY_TEST_CASEAPI_
0987 
0988   void OnTestStart(const TestInfo& /*test_info*/) override {}
0989   void OnTestDisabled(const TestInfo& /*test_info*/) override {}
0990   void OnTestPartResult(const TestPartResult& /*test_part_result*/) override {}
0991   void OnTestEnd(const TestInfo& /*test_info*/) override {}
0992   void OnTestSuiteEnd(const TestSuite& /*test_suite*/) override {}
0993 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
0994   void OnTestCaseEnd(const TestCase& /*test_case*/) override {}
0995 #endif  //  GTEST_REMOVE_LEGACY_TEST_CASEAPI_
0996 
0997   void OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) override {}
0998   void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) override {}
0999   void OnTestIterationEnd(const UnitTest& /*unit_test*/,
1000                           int /*iteration*/) override {}
1001   void OnTestProgramEnd(const UnitTest& /*unit_test*/) override {}
1002 };
1003 
1004 // TestEventListeners lets users add listeners to track events in Google Test.
1005 class GTEST_API_ TestEventListeners {
1006  public:
1007   TestEventListeners();
1008   ~TestEventListeners();
1009 
1010   // Appends an event listener to the end of the list. Google Test assumes
1011   // the ownership of the listener (i.e. it will delete the listener when
1012   // the test program finishes).
1013   void Append(TestEventListener* listener);
1014 
1015   // Removes the given event listener from the list and returns it.  It then
1016   // becomes the caller's responsibility to delete the listener. Returns
1017   // NULL if the listener is not found in the list.
1018   TestEventListener* Release(TestEventListener* listener);
1019 
1020   // Returns the standard listener responsible for the default console
1021   // output.  Can be removed from the listeners list to shut down default
1022   // console output.  Note that removing this object from the listener list
1023   // with Release transfers its ownership to the caller and makes this
1024   // function return NULL the next time.
1025   TestEventListener* default_result_printer() const {
1026     return default_result_printer_;
1027   }
1028 
1029   // Returns the standard listener responsible for the default XML output
1030   // controlled by the --gtest_output=xml flag.  Can be removed from the
1031   // listeners list by users who want to shut down the default XML output
1032   // controlled by this flag and substitute it with custom one.  Note that
1033   // removing this object from the listener list with Release transfers its
1034   // ownership to the caller and makes this function return NULL the next
1035   // time.
1036   TestEventListener* default_xml_generator() const {
1037     return default_xml_generator_;
1038   }
1039 
1040  private:
1041   friend class TestSuite;
1042   friend class TestInfo;
1043   friend class internal::DefaultGlobalTestPartResultReporter;
1044   friend class internal::NoExecDeathTest;
1045   friend class internal::TestEventListenersAccessor;
1046   friend class internal::UnitTestImpl;
1047 
1048   // Returns repeater that broadcasts the TestEventListener events to all
1049   // subscribers.
1050   TestEventListener* repeater();
1051 
1052   // Sets the default_result_printer attribute to the provided listener.
1053   // The listener is also added to the listener list and previous
1054   // default_result_printer is removed from it and deleted. The listener can
1055   // also be NULL in which case it will not be added to the list. Does
1056   // nothing if the previous and the current listener objects are the same.
1057   void SetDefaultResultPrinter(TestEventListener* listener);
1058 
1059   // Sets the default_xml_generator attribute to the provided listener.  The
1060   // listener is also added to the listener list and previous
1061   // default_xml_generator is removed from it and deleted. The listener can
1062   // also be NULL in which case it will not be added to the list. Does
1063   // nothing if the previous and the current listener objects are the same.
1064   void SetDefaultXmlGenerator(TestEventListener* listener);
1065 
1066   // Controls whether events will be forwarded by the repeater to the
1067   // listeners in the list.
1068   bool EventForwardingEnabled() const;
1069   void SuppressEventForwarding();
1070 
1071   // The actual list of listeners.
1072   internal::TestEventRepeater* repeater_;
1073   // Listener responsible for the standard result output.
1074   TestEventListener* default_result_printer_;
1075   // Listener responsible for the creation of the XML output file.
1076   TestEventListener* default_xml_generator_;
1077 
1078   // We disallow copying TestEventListeners.
1079   TestEventListeners(const TestEventListeners&) = delete;
1080   TestEventListeners& operator=(const TestEventListeners&) = delete;
1081 };
1082 
1083 // A UnitTest consists of a vector of TestSuites.
1084 //
1085 // This is a singleton class.  The only instance of UnitTest is
1086 // created when UnitTest::GetInstance() is first called.  This
1087 // instance is never deleted.
1088 //
1089 // UnitTest is not copyable.
1090 //
1091 // This class is thread-safe as long as the methods are called
1092 // according to their specification.
1093 class GTEST_API_ UnitTest {
1094  public:
1095   // Gets the singleton UnitTest object.  The first time this method
1096   // is called, a UnitTest object is constructed and returned.
1097   // Consecutive calls will return the same object.
1098   static UnitTest* GetInstance();
1099 
1100   // Runs all tests in this UnitTest object and prints the result.
1101   // Returns 0 if successful, or 1 otherwise.
1102   //
1103   // This method can only be called from the main thread.
1104   //
1105   // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1106   int Run() GTEST_MUST_USE_RESULT_;
1107 
1108   // Returns the working directory when the first TEST() or TEST_F()
1109   // was executed.  The UnitTest object owns the string.
1110   const char* original_working_dir() const;
1111 
1112   // Returns the TestSuite object for the test that's currently running,
1113   // or NULL if no test is running.
1114   const TestSuite* current_test_suite() const GTEST_LOCK_EXCLUDED_(mutex_);
1115 
1116 // Legacy API is still available but deprecated
1117 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
1118   const TestCase* current_test_case() const GTEST_LOCK_EXCLUDED_(mutex_);
1119 #endif
1120 
1121   // Returns the TestInfo object for the test that's currently running,
1122   // or NULL if no test is running.
1123   const TestInfo* current_test_info() const GTEST_LOCK_EXCLUDED_(mutex_);
1124 
1125   // Returns the random seed used at the start of the current test run.
1126   int random_seed() const;
1127 
1128   // Returns the ParameterizedTestSuiteRegistry object used to keep track of
1129   // value-parameterized tests and instantiate and register them.
1130   //
1131   // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1132   internal::ParameterizedTestSuiteRegistry& parameterized_test_registry()
1133       GTEST_LOCK_EXCLUDED_(mutex_);
1134 
1135   // Gets the number of successful test suites.
1136   int successful_test_suite_count() const;
1137 
1138   // Gets the number of failed test suites.
1139   int failed_test_suite_count() const;
1140 
1141   // Gets the number of all test suites.
1142   int total_test_suite_count() const;
1143 
1144   // Gets the number of all test suites that contain at least one test
1145   // that should run.
1146   int test_suite_to_run_count() const;
1147 
1148   //  Legacy API is deprecated but still available
1149 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
1150   int successful_test_case_count() const;
1151   int failed_test_case_count() const;
1152   int total_test_case_count() const;
1153   int test_case_to_run_count() const;
1154 #endif  //  GTEST_REMOVE_LEGACY_TEST_CASEAPI_
1155 
1156   // Gets the number of successful tests.
1157   int successful_test_count() const;
1158 
1159   // Gets the number of skipped tests.
1160   int skipped_test_count() const;
1161 
1162   // Gets the number of failed tests.
1163   int failed_test_count() const;
1164 
1165   // Gets the number of disabled tests that will be reported in the XML report.
1166   int reportable_disabled_test_count() const;
1167 
1168   // Gets the number of disabled tests.
1169   int disabled_test_count() const;
1170 
1171   // Gets the number of tests to be printed in the XML report.
1172   int reportable_test_count() const;
1173 
1174   // Gets the number of all tests.
1175   int total_test_count() const;
1176 
1177   // Gets the number of tests that should run.
1178   int test_to_run_count() const;
1179 
1180   // Gets the time of the test program start, in ms from the start of the
1181   // UNIX epoch.
1182   TimeInMillis start_timestamp() const;
1183 
1184   // Gets the elapsed time, in milliseconds.
1185   TimeInMillis elapsed_time() const;
1186 
1187   // Returns true if and only if the unit test passed (i.e. all test suites
1188   // passed).
1189   bool Passed() const;
1190 
1191   // Returns true if and only if the unit test failed (i.e. some test suite
1192   // failed or something outside of all tests failed).
1193   bool Failed() const;
1194 
1195   // Gets the i-th test suite among all the test suites. i can range from 0 to
1196   // total_test_suite_count() - 1. If i is not in that range, returns NULL.
1197   const TestSuite* GetTestSuite(int i) const;
1198 
1199 //  Legacy API is deprecated but still available
1200 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
1201   const TestCase* GetTestCase(int i) const;
1202 #endif  //  GTEST_REMOVE_LEGACY_TEST_CASEAPI_
1203 
1204   // Returns the TestResult containing information on test failures and
1205   // properties logged outside of individual test suites.
1206   const TestResult& ad_hoc_test_result() const;
1207 
1208   // Returns the list of event listeners that can be used to track events
1209   // inside Google Test.
1210   TestEventListeners& listeners();
1211 
1212  private:
1213   // Registers and returns a global test environment.  When a test
1214   // program is run, all global test environments will be set-up in
1215   // the order they were registered.  After all tests in the program
1216   // have finished, all global test environments will be torn-down in
1217   // the *reverse* order they were registered.
1218   //
1219   // The UnitTest object takes ownership of the given environment.
1220   //
1221   // This method can only be called from the main thread.
1222   Environment* AddEnvironment(Environment* env);
1223 
1224   // Adds a TestPartResult to the current TestResult object.  All
1225   // Google Test assertion macros (e.g. ASSERT_TRUE, EXPECT_EQ, etc)
1226   // eventually call this to report their results.  The user code
1227   // should use the assertion macros instead of calling this directly.
1228   void AddTestPartResult(TestPartResult::Type result_type,
1229                          const char* file_name, int line_number,
1230                          const std::string& message,
1231                          const std::string& os_stack_trace)
1232       GTEST_LOCK_EXCLUDED_(mutex_);
1233 
1234   // Adds a TestProperty to the current TestResult object when invoked from
1235   // inside a test, to current TestSuite's ad_hoc_test_result_ when invoked
1236   // from SetUpTestSuite or TearDownTestSuite, or to the global property set
1237   // when invoked elsewhere.  If the result already contains a property with
1238   // the same key, the value will be updated.
1239   void RecordProperty(const std::string& key, const std::string& value);
1240 
1241   // Gets the i-th test suite among all the test suites. i can range from 0 to
1242   // total_test_suite_count() - 1. If i is not in that range, returns NULL.
1243   TestSuite* GetMutableTestSuite(int i);
1244 
1245   // Accessors for the implementation object.
1246   internal::UnitTestImpl* impl() { return impl_; }
1247   const internal::UnitTestImpl* impl() const { return impl_; }
1248 
1249   // These classes and functions are friends as they need to access private
1250   // members of UnitTest.
1251   friend class ScopedTrace;
1252   friend class Test;
1253   friend class internal::AssertHelper;
1254   friend class internal::StreamingListenerTest;
1255   friend class internal::UnitTestRecordPropertyTestHelper;
1256   friend Environment* AddGlobalTestEnvironment(Environment* env);
1257   friend std::set<std::string>* internal::GetIgnoredParameterizedTestSuites();
1258   friend internal::UnitTestImpl* internal::GetUnitTestImpl();
1259   friend void internal::ReportFailureInUnknownLocation(
1260       TestPartResult::Type result_type, const std::string& message);
1261 
1262   // Creates an empty UnitTest.
1263   UnitTest();
1264 
1265   // D'tor
1266   virtual ~UnitTest();
1267 
1268   // Pushes a trace defined by SCOPED_TRACE() on to the per-thread
1269   // Google Test trace stack.
1270   void PushGTestTrace(const internal::TraceInfo& trace)
1271       GTEST_LOCK_EXCLUDED_(mutex_);
1272 
1273   // Pops a trace from the per-thread Google Test trace stack.
1274   void PopGTestTrace() GTEST_LOCK_EXCLUDED_(mutex_);
1275 
1276   // Protects mutable state in *impl_.  This is mutable as some const
1277   // methods need to lock it too.
1278   mutable internal::Mutex mutex_;
1279 
1280   // Opaque implementation object.  This field is never changed once
1281   // the object is constructed.  We don't mark it as const here, as
1282   // doing so will cause a warning in the constructor of UnitTest.
1283   // Mutable state in *impl_ is protected by mutex_.
1284   internal::UnitTestImpl* impl_;
1285 
1286   // We disallow copying UnitTest.
1287   UnitTest(const UnitTest&) = delete;
1288   UnitTest& operator=(const UnitTest&) = delete;
1289 };
1290 
1291 // A convenient wrapper for adding an environment for the test
1292 // program.
1293 //
1294 // You should call this before RUN_ALL_TESTS() is called, probably in
1295 // main().  If you use gtest_main, you need to call this before main()
1296 // starts for it to take effect.  For example, you can define a global
1297 // variable like this:
1298 //
1299 //   testing::Environment* const foo_env =
1300 //       testing::AddGlobalTestEnvironment(new FooEnvironment);
1301 //
1302 // However, we strongly recommend you to write your own main() and
1303 // call AddGlobalTestEnvironment() there, as relying on initialization
1304 // of global variables makes the code harder to read and may cause
1305 // problems when you register multiple environments from different
1306 // translation units and the environments have dependencies among them
1307 // (remember that the compiler doesn't guarantee the order in which
1308 // global variables from different translation units are initialized).
1309 inline Environment* AddGlobalTestEnvironment(Environment* env) {
1310   return UnitTest::GetInstance()->AddEnvironment(env);
1311 }
1312 
1313 // Initializes Google Test.  This must be called before calling
1314 // RUN_ALL_TESTS().  In particular, it parses a command line for the
1315 // flags that Google Test recognizes.  Whenever a Google Test flag is
1316 // seen, it is removed from argv, and *argc is decremented.
1317 //
1318 // No value is returned.  Instead, the Google Test flag variables are
1319 // updated.
1320 //
1321 // Calling the function for the second time has no user-visible effect.
1322 GTEST_API_ void InitGoogleTest(int* argc, char** argv);
1323 
1324 // This overloaded version can be used in Windows programs compiled in
1325 // UNICODE mode.
1326 GTEST_API_ void InitGoogleTest(int* argc, wchar_t** argv);
1327 
1328 // This overloaded version can be used on Arduino/embedded platforms where
1329 // there is no argc/argv.
1330 GTEST_API_ void InitGoogleTest();
1331 
1332 namespace internal {
1333 
1334 // Separate the error generating code from the code path to reduce the stack
1335 // frame size of CmpHelperEQ. This helps reduce the overhead of some sanitizers
1336 // when calling EXPECT_* in a tight loop.
1337 template <typename T1, typename T2>
1338 AssertionResult CmpHelperEQFailure(const char* lhs_expression,
1339                                    const char* rhs_expression, const T1& lhs,
1340                                    const T2& rhs) {
1341   return EqFailure(lhs_expression, rhs_expression,
1342                    FormatForComparisonFailureMessage(lhs, rhs),
1343                    FormatForComparisonFailureMessage(rhs, lhs), false);
1344 }
1345 
1346 // This block of code defines operator==/!=
1347 // to block lexical scope lookup.
1348 // It prevents using invalid operator==/!= defined at namespace scope.
1349 struct faketype {};
1350 inline bool operator==(faketype, faketype) { return true; }
1351 inline bool operator!=(faketype, faketype) { return false; }
1352 
1353 // The helper function for {ASSERT|EXPECT}_EQ.
1354 template <typename T1, typename T2>
1355 AssertionResult CmpHelperEQ(const char* lhs_expression,
1356                             const char* rhs_expression, const T1& lhs,
1357                             const T2& rhs) {
1358   if (lhs == rhs) {
1359     return AssertionSuccess();
1360   }
1361 
1362   return CmpHelperEQFailure(lhs_expression, rhs_expression, lhs, rhs);
1363 }
1364 
1365 class EqHelper {
1366  public:
1367   // This templatized version is for the general case.
1368   template <
1369       typename T1, typename T2,
1370       // Disable this overload for cases where one argument is a pointer
1371       // and the other is the null pointer constant.
1372       typename std::enable_if<!std::is_integral<T1>::value ||
1373                               !std::is_pointer<T2>::value>::type* = nullptr>
1374   static AssertionResult Compare(const char* lhs_expression,
1375                                  const char* rhs_expression, const T1& lhs,
1376                                  const T2& rhs) {
1377     return CmpHelperEQ(lhs_expression, rhs_expression, lhs, rhs);
1378   }
1379 
1380   // With this overloaded version, we allow anonymous enums to be used
1381   // in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous
1382   // enums can be implicitly cast to BiggestInt.
1383   //
1384   // Even though its body looks the same as the above version, we
1385   // cannot merge the two, as it will make anonymous enums unhappy.
1386   static AssertionResult Compare(const char* lhs_expression,
1387                                  const char* rhs_expression, BiggestInt lhs,
1388                                  BiggestInt rhs) {
1389     return CmpHelperEQ(lhs_expression, rhs_expression, lhs, rhs);
1390   }
1391 
1392   template <typename T>
1393   static AssertionResult Compare(
1394       const char* lhs_expression, const char* rhs_expression,
1395       // Handle cases where '0' is used as a null pointer literal.
1396       std::nullptr_t /* lhs */, T* rhs) {
1397     // We already know that 'lhs' is a null pointer.
1398     return CmpHelperEQ(lhs_expression, rhs_expression, static_cast<T*>(nullptr),
1399                        rhs);
1400   }
1401 };
1402 
1403 // Separate the error generating code from the code path to reduce the stack
1404 // frame size of CmpHelperOP. This helps reduce the overhead of some sanitizers
1405 // when calling EXPECT_OP in a tight loop.
1406 template <typename T1, typename T2>
1407 AssertionResult CmpHelperOpFailure(const char* expr1, const char* expr2,
1408                                    const T1& val1, const T2& val2,
1409                                    const char* op) {
1410   return AssertionFailure()
1411          << "Expected: (" << expr1 << ") " << op << " (" << expr2
1412          << "), actual: " << FormatForComparisonFailureMessage(val1, val2)
1413          << " vs " << FormatForComparisonFailureMessage(val2, val1);
1414 }
1415 
1416 // A macro for implementing the helper functions needed to implement
1417 // ASSERT_?? and EXPECT_??.  It is here just to avoid copy-and-paste
1418 // of similar code.
1419 //
1420 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1421 
1422 #define GTEST_IMPL_CMP_HELPER_(op_name, op)                                \
1423   template <typename T1, typename T2>                                      \
1424   AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \
1425                                      const T1& val1, const T2& val2) {     \
1426     if (val1 op val2) {                                                    \
1427       return AssertionSuccess();                                           \
1428     } else {                                                               \
1429       return CmpHelperOpFailure(expr1, expr2, val1, val2, #op);            \
1430     }                                                                      \
1431   }
1432 
1433 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1434 
1435 // Implements the helper function for {ASSERT|EXPECT}_NE
1436 GTEST_IMPL_CMP_HELPER_(NE, !=)
1437 // Implements the helper function for {ASSERT|EXPECT}_LE
1438 GTEST_IMPL_CMP_HELPER_(LE, <=)
1439 // Implements the helper function for {ASSERT|EXPECT}_LT
1440 GTEST_IMPL_CMP_HELPER_(LT, <)
1441 // Implements the helper function for {ASSERT|EXPECT}_GE
1442 GTEST_IMPL_CMP_HELPER_(GE, >=)
1443 // Implements the helper function for {ASSERT|EXPECT}_GT
1444 GTEST_IMPL_CMP_HELPER_(GT, >)
1445 
1446 #undef GTEST_IMPL_CMP_HELPER_
1447 
1448 // The helper function for {ASSERT|EXPECT}_STREQ.
1449 //
1450 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1451 GTEST_API_ AssertionResult CmpHelperSTREQ(const char* s1_expression,
1452                                           const char* s2_expression,
1453                                           const char* s1, const char* s2);
1454 
1455 // The helper function for {ASSERT|EXPECT}_STRCASEEQ.
1456 //
1457 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1458 GTEST_API_ AssertionResult CmpHelperSTRCASEEQ(const char* s1_expression,
1459                                               const char* s2_expression,
1460                                               const char* s1, const char* s2);
1461 
1462 // The helper function for {ASSERT|EXPECT}_STRNE.
1463 //
1464 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1465 GTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression,
1466                                           const char* s2_expression,
1467                                           const char* s1, const char* s2);
1468 
1469 // The helper function for {ASSERT|EXPECT}_STRCASENE.
1470 //
1471 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1472 GTEST_API_ AssertionResult CmpHelperSTRCASENE(const char* s1_expression,
1473                                               const char* s2_expression,
1474                                               const char* s1, const char* s2);
1475 
1476 // Helper function for *_STREQ on wide strings.
1477 //
1478 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1479 GTEST_API_ AssertionResult CmpHelperSTREQ(const char* s1_expression,
1480                                           const char* s2_expression,
1481                                           const wchar_t* s1, const wchar_t* s2);
1482 
1483 // Helper function for *_STRNE on wide strings.
1484 //
1485 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1486 GTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression,
1487                                           const char* s2_expression,
1488                                           const wchar_t* s1, const wchar_t* s2);
1489 
1490 }  // namespace internal
1491 
1492 // IsSubstring() and IsNotSubstring() are intended to be used as the
1493 // first argument to {EXPECT,ASSERT}_PRED_FORMAT2(), not by
1494 // themselves.  They check whether needle is a substring of haystack
1495 // (NULL is considered a substring of itself only), and return an
1496 // appropriate error message when they fail.
1497 //
1498 // The {needle,haystack}_expr arguments are the stringified
1499 // expressions that generated the two real arguments.
1500 GTEST_API_ AssertionResult IsSubstring(const char* needle_expr,
1501                                        const char* haystack_expr,
1502                                        const char* needle,
1503                                        const char* haystack);
1504 GTEST_API_ AssertionResult IsSubstring(const char* needle_expr,
1505                                        const char* haystack_expr,
1506                                        const wchar_t* needle,
1507                                        const wchar_t* haystack);
1508 GTEST_API_ AssertionResult IsNotSubstring(const char* needle_expr,
1509                                           const char* haystack_expr,
1510                                           const char* needle,
1511                                           const char* haystack);
1512 GTEST_API_ AssertionResult IsNotSubstring(const char* needle_expr,
1513                                           const char* haystack_expr,
1514                                           const wchar_t* needle,
1515                                           const wchar_t* haystack);
1516 GTEST_API_ AssertionResult IsSubstring(const char* needle_expr,
1517                                        const char* haystack_expr,
1518                                        const ::std::string& needle,
1519                                        const ::std::string& haystack);
1520 GTEST_API_ AssertionResult IsNotSubstring(const char* needle_expr,
1521                                           const char* haystack_expr,
1522                                           const ::std::string& needle,
1523                                           const ::std::string& haystack);
1524 
1525 #if GTEST_HAS_STD_WSTRING
1526 GTEST_API_ AssertionResult IsSubstring(const char* needle_expr,
1527                                        const char* haystack_expr,
1528                                        const ::std::wstring& needle,
1529                                        const ::std::wstring& haystack);
1530 GTEST_API_ AssertionResult IsNotSubstring(const char* needle_expr,
1531                                           const char* haystack_expr,
1532                                           const ::std::wstring& needle,
1533                                           const ::std::wstring& haystack);
1534 #endif  // GTEST_HAS_STD_WSTRING
1535 
1536 namespace internal {
1537 
1538 // Helper template function for comparing floating-points.
1539 //
1540 // Template parameter:
1541 //
1542 //   RawType: the raw floating-point type (either float or double)
1543 //
1544 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1545 template <typename RawType>
1546 AssertionResult CmpHelperFloatingPointEQ(const char* lhs_expression,
1547                                          const char* rhs_expression,
1548                                          RawType lhs_value, RawType rhs_value) {
1549   const FloatingPoint<RawType> lhs(lhs_value), rhs(rhs_value);
1550 
1551   if (lhs.AlmostEquals(rhs)) {
1552     return AssertionSuccess();
1553   }
1554 
1555   ::std::stringstream lhs_ss;
1556   lhs_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
1557          << lhs_value;
1558 
1559   ::std::stringstream rhs_ss;
1560   rhs_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
1561          << rhs_value;
1562 
1563   return EqFailure(lhs_expression, rhs_expression,
1564                    StringStreamToString(&lhs_ss), StringStreamToString(&rhs_ss),
1565                    false);
1566 }
1567 
1568 // Helper function for implementing ASSERT_NEAR.
1569 //
1570 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1571 GTEST_API_ AssertionResult DoubleNearPredFormat(const char* expr1,
1572                                                 const char* expr2,
1573                                                 const char* abs_error_expr,
1574                                                 double val1, double val2,
1575                                                 double abs_error);
1576 
1577 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
1578 // A class that enables one to stream messages to assertion macros
1579 class GTEST_API_ AssertHelper {
1580  public:
1581   // Constructor.
1582   AssertHelper(TestPartResult::Type type, const char* file, int line,
1583                const char* message);
1584   ~AssertHelper();
1585 
1586   // Message assignment is a semantic trick to enable assertion
1587   // streaming; see the GTEST_MESSAGE_ macro below.
1588   void operator=(const Message& message) const;
1589 
1590  private:
1591   // We put our data in a struct so that the size of the AssertHelper class can
1592   // be as small as possible.  This is important because gcc is incapable of
1593   // re-using stack space even for temporary variables, so every EXPECT_EQ
1594   // reserves stack space for another AssertHelper.
1595   struct AssertHelperData {
1596     AssertHelperData(TestPartResult::Type t, const char* srcfile, int line_num,
1597                      const char* msg)
1598         : type(t), file(srcfile), line(line_num), message(msg) {}
1599 
1600     TestPartResult::Type const type;
1601     const char* const file;
1602     int const line;
1603     std::string const message;
1604 
1605    private:
1606     AssertHelperData(const AssertHelperData&) = delete;
1607     AssertHelperData& operator=(const AssertHelperData&) = delete;
1608   };
1609 
1610   AssertHelperData* const data_;
1611 
1612   AssertHelper(const AssertHelper&) = delete;
1613   AssertHelper& operator=(const AssertHelper&) = delete;
1614 };
1615 
1616 }  // namespace internal
1617 
1618 // The pure interface class that all value-parameterized tests inherit from.
1619 // A value-parameterized class must inherit from both ::testing::Test and
1620 // ::testing::WithParamInterface. In most cases that just means inheriting
1621 // from ::testing::TestWithParam, but more complicated test hierarchies
1622 // may need to inherit from Test and WithParamInterface at different levels.
1623 //
1624 // This interface has support for accessing the test parameter value via
1625 // the GetParam() method.
1626 //
1627 // Use it with one of the parameter generator defining functions, like Range(),
1628 // Values(), ValuesIn(), Bool(), and Combine().
1629 //
1630 // class FooTest : public ::testing::TestWithParam<int> {
1631 //  protected:
1632 //   FooTest() {
1633 //     // Can use GetParam() here.
1634 //   }
1635 //   ~FooTest() override {
1636 //     // Can use GetParam() here.
1637 //   }
1638 //   void SetUp() override {
1639 //     // Can use GetParam() here.
1640 //   }
1641 //   void TearDown override {
1642 //     // Can use GetParam() here.
1643 //   }
1644 // };
1645 // TEST_P(FooTest, DoesBar) {
1646 //   // Can use GetParam() method here.
1647 //   Foo foo;
1648 //   ASSERT_TRUE(foo.DoesBar(GetParam()));
1649 // }
1650 // INSTANTIATE_TEST_SUITE_P(OneToTenRange, FooTest, ::testing::Range(1, 10));
1651 
1652 template <typename T>
1653 class WithParamInterface {
1654  public:
1655   typedef T ParamType;
1656   virtual ~WithParamInterface() {}
1657 
1658   // The current parameter value. Is also available in the test fixture's
1659   // constructor.
1660   static const ParamType& GetParam() {
1661     GTEST_CHECK_(parameter_ != nullptr)
1662         << "GetParam() can only be called inside a value-parameterized test "
1663         << "-- did you intend to write TEST_P instead of TEST_F?";
1664     return *parameter_;
1665   }
1666 
1667  private:
1668   // Sets parameter value. The caller is responsible for making sure the value
1669   // remains alive and unchanged throughout the current test.
1670   static void SetParam(const ParamType* parameter) { parameter_ = parameter; }
1671 
1672   // Static value used for accessing parameter during a test lifetime.
1673   static const ParamType* parameter_;
1674 
1675   // TestClass must be a subclass of WithParamInterface<T> and Test.
1676   template <class TestClass>
1677   friend class internal::ParameterizedTestFactory;
1678 };
1679 
1680 template <typename T>
1681 const T* WithParamInterface<T>::parameter_ = nullptr;
1682 
1683 // Most value-parameterized classes can ignore the existence of
1684 // WithParamInterface, and can just inherit from ::testing::TestWithParam.
1685 
1686 template <typename T>
1687 class TestWithParam : public Test, public WithParamInterface<T> {};
1688 
1689 // Macros for indicating success/failure in test code.
1690 
1691 // Skips test in runtime.
1692 // Skipping test aborts current function.
1693 // Skipped tests are neither successful nor failed.
1694 #define GTEST_SKIP() GTEST_SKIP_("")
1695 
1696 // ADD_FAILURE unconditionally adds a failure to the current test.
1697 // SUCCEED generates a success - it doesn't automatically make the
1698 // current test successful, as a test is only successful when it has
1699 // no failure.
1700 //
1701 // EXPECT_* verifies that a certain condition is satisfied.  If not,
1702 // it behaves like ADD_FAILURE.  In particular:
1703 //
1704 //   EXPECT_TRUE  verifies that a Boolean condition is true.
1705 //   EXPECT_FALSE verifies that a Boolean condition is false.
1706 //
1707 // FAIL and ASSERT_* are similar to ADD_FAILURE and EXPECT_*, except
1708 // that they will also abort the current function on failure.  People
1709 // usually want the fail-fast behavior of FAIL and ASSERT_*, but those
1710 // writing data-driven tests often find themselves using ADD_FAILURE
1711 // and EXPECT_* more.
1712 
1713 // Generates a nonfatal failure with a generic message.
1714 #define ADD_FAILURE() GTEST_NONFATAL_FAILURE_("Failed")
1715 
1716 // Generates a nonfatal failure at the given source file location with
1717 // a generic message.
1718 #define ADD_FAILURE_AT(file, line)        \
1719   GTEST_MESSAGE_AT_(file, line, "Failed", \
1720                     ::testing::TestPartResult::kNonFatalFailure)
1721 
1722 // Generates a fatal failure with a generic message.
1723 #define GTEST_FAIL() GTEST_FATAL_FAILURE_("Failed")
1724 
1725 // Like GTEST_FAIL(), but at the given source file location.
1726 #define GTEST_FAIL_AT(file, line)         \
1727   GTEST_MESSAGE_AT_(file, line, "Failed", \
1728                     ::testing::TestPartResult::kFatalFailure)
1729 
1730 // Define this macro to 1 to omit the definition of FAIL(), which is a
1731 // generic name and clashes with some other libraries.
1732 #if !GTEST_DONT_DEFINE_FAIL
1733 #define FAIL() GTEST_FAIL()
1734 #endif
1735 
1736 // Generates a success with a generic message.
1737 #define GTEST_SUCCEED() GTEST_SUCCESS_("Succeeded")
1738 
1739 // Define this macro to 1 to omit the definition of SUCCEED(), which
1740 // is a generic name and clashes with some other libraries.
1741 #if !GTEST_DONT_DEFINE_SUCCEED
1742 #define SUCCEED() GTEST_SUCCEED()
1743 #endif
1744 
1745 // Macros for testing exceptions.
1746 //
1747 //    * {ASSERT|EXPECT}_THROW(statement, expected_exception):
1748 //         Tests that the statement throws the expected exception.
1749 //    * {ASSERT|EXPECT}_NO_THROW(statement):
1750 //         Tests that the statement doesn't throw any exception.
1751 //    * {ASSERT|EXPECT}_ANY_THROW(statement):
1752 //         Tests that the statement throws an exception.
1753 
1754 #define EXPECT_THROW(statement, expected_exception) \
1755   GTEST_TEST_THROW_(statement, expected_exception, GTEST_NONFATAL_FAILURE_)
1756 #define EXPECT_NO_THROW(statement) \
1757   GTEST_TEST_NO_THROW_(statement, GTEST_NONFATAL_FAILURE_)
1758 #define EXPECT_ANY_THROW(statement) \
1759   GTEST_TEST_ANY_THROW_(statement, GTEST_NONFATAL_FAILURE_)
1760 #define ASSERT_THROW(statement, expected_exception) \
1761   GTEST_TEST_THROW_(statement, expected_exception, GTEST_FATAL_FAILURE_)
1762 #define ASSERT_NO_THROW(statement) \
1763   GTEST_TEST_NO_THROW_(statement, GTEST_FATAL_FAILURE_)
1764 #define ASSERT_ANY_THROW(statement) \
1765   GTEST_TEST_ANY_THROW_(statement, GTEST_FATAL_FAILURE_)
1766 
1767 // Boolean assertions. Condition can be either a Boolean expression or an
1768 // AssertionResult. For more information on how to use AssertionResult with
1769 // these macros see comments on that class.
1770 #define GTEST_EXPECT_TRUE(condition)                      \
1771   GTEST_TEST_BOOLEAN_(condition, #condition, false, true, \
1772                       GTEST_NONFATAL_FAILURE_)
1773 #define GTEST_EXPECT_FALSE(condition)                        \
1774   GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \
1775                       GTEST_NONFATAL_FAILURE_)
1776 #define GTEST_ASSERT_TRUE(condition) \
1777   GTEST_TEST_BOOLEAN_(condition, #condition, false, true, GTEST_FATAL_FAILURE_)
1778 #define GTEST_ASSERT_FALSE(condition)                        \
1779   GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \
1780                       GTEST_FATAL_FAILURE_)
1781 
1782 // Define these macros to 1 to omit the definition of the corresponding
1783 // EXPECT or ASSERT, which clashes with some users' own code.
1784 
1785 #if !GTEST_DONT_DEFINE_EXPECT_TRUE
1786 #define EXPECT_TRUE(condition) GTEST_EXPECT_TRUE(condition)
1787 #endif
1788 
1789 #if !GTEST_DONT_DEFINE_EXPECT_FALSE
1790 #define EXPECT_FALSE(condition) GTEST_EXPECT_FALSE(condition)
1791 #endif
1792 
1793 #if !GTEST_DONT_DEFINE_ASSERT_TRUE
1794 #define ASSERT_TRUE(condition) GTEST_ASSERT_TRUE(condition)
1795 #endif
1796 
1797 #if !GTEST_DONT_DEFINE_ASSERT_FALSE
1798 #define ASSERT_FALSE(condition) GTEST_ASSERT_FALSE(condition)
1799 #endif
1800 
1801 // Macros for testing equalities and inequalities.
1802 //
1803 //    * {ASSERT|EXPECT}_EQ(v1, v2): Tests that v1 == v2
1804 //    * {ASSERT|EXPECT}_NE(v1, v2): Tests that v1 != v2
1805 //    * {ASSERT|EXPECT}_LT(v1, v2): Tests that v1 < v2
1806 //    * {ASSERT|EXPECT}_LE(v1, v2): Tests that v1 <= v2
1807 //    * {ASSERT|EXPECT}_GT(v1, v2): Tests that v1 > v2
1808 //    * {ASSERT|EXPECT}_GE(v1, v2): Tests that v1 >= v2
1809 //
1810 // When they are not, Google Test prints both the tested expressions and
1811 // their actual values.  The values must be compatible built-in types,
1812 // or you will get a compiler error.  By "compatible" we mean that the
1813 // values can be compared by the respective operator.
1814 //
1815 // Note:
1816 //
1817 //   1. It is possible to make a user-defined type work with
1818 //   {ASSERT|EXPECT}_??(), but that requires overloading the
1819 //   comparison operators and is thus discouraged by the Google C++
1820 //   Usage Guide.  Therefore, you are advised to use the
1821 //   {ASSERT|EXPECT}_TRUE() macro to assert that two objects are
1822 //   equal.
1823 //
1824 //   2. The {ASSERT|EXPECT}_??() macros do pointer comparisons on
1825 //   pointers (in particular, C strings).  Therefore, if you use it
1826 //   with two C strings, you are testing how their locations in memory
1827 //   are related, not how their content is related.  To compare two C
1828 //   strings by content, use {ASSERT|EXPECT}_STR*().
1829 //
1830 //   3. {ASSERT|EXPECT}_EQ(v1, v2) is preferred to
1831 //   {ASSERT|EXPECT}_TRUE(v1 == v2), as the former tells you
1832 //   what the actual value is when it fails, and similarly for the
1833 //   other comparisons.
1834 //
1835 //   4. Do not depend on the order in which {ASSERT|EXPECT}_??()
1836 //   evaluate their arguments, which is undefined.
1837 //
1838 //   5. These macros evaluate their arguments exactly once.
1839 //
1840 // Examples:
1841 //
1842 //   EXPECT_NE(Foo(), 5);
1843 //   EXPECT_EQ(a_pointer, NULL);
1844 //   ASSERT_LT(i, array_size);
1845 //   ASSERT_GT(records.size(), 0) << "There is no record left.";
1846 
1847 #define EXPECT_EQ(val1, val2) \
1848   EXPECT_PRED_FORMAT2(::testing::internal::EqHelper::Compare, val1, val2)
1849 #define EXPECT_NE(val1, val2) \
1850   EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2)
1851 #define EXPECT_LE(val1, val2) \
1852   EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2)
1853 #define EXPECT_LT(val1, val2) \
1854   EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2)
1855 #define EXPECT_GE(val1, val2) \
1856   EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2)
1857 #define EXPECT_GT(val1, val2) \
1858   EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2)
1859 
1860 #define GTEST_ASSERT_EQ(val1, val2) \
1861   ASSERT_PRED_FORMAT2(::testing::internal::EqHelper::Compare, val1, val2)
1862 #define GTEST_ASSERT_NE(val1, val2) \
1863   ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2)
1864 #define GTEST_ASSERT_LE(val1, val2) \
1865   ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2)
1866 #define GTEST_ASSERT_LT(val1, val2) \
1867   ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2)
1868 #define GTEST_ASSERT_GE(val1, val2) \
1869   ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2)
1870 #define GTEST_ASSERT_GT(val1, val2) \
1871   ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2)
1872 
1873 // Define macro GTEST_DONT_DEFINE_ASSERT_XY to 1 to omit the definition of
1874 // ASSERT_XY(), which clashes with some users' own code.
1875 
1876 #if !GTEST_DONT_DEFINE_ASSERT_EQ
1877 #define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2)
1878 #endif
1879 
1880 #if !GTEST_DONT_DEFINE_ASSERT_NE
1881 #define ASSERT_NE(val1, val2) GTEST_ASSERT_NE(val1, val2)
1882 #endif
1883 
1884 #if !GTEST_DONT_DEFINE_ASSERT_LE
1885 #define ASSERT_LE(val1, val2) GTEST_ASSERT_LE(val1, val2)
1886 #endif
1887 
1888 #if !GTEST_DONT_DEFINE_ASSERT_LT
1889 #define ASSERT_LT(val1, val2) GTEST_ASSERT_LT(val1, val2)
1890 #endif
1891 
1892 #if !GTEST_DONT_DEFINE_ASSERT_GE
1893 #define ASSERT_GE(val1, val2) GTEST_ASSERT_GE(val1, val2)
1894 #endif
1895 
1896 #if !GTEST_DONT_DEFINE_ASSERT_GT
1897 #define ASSERT_GT(val1, val2) GTEST_ASSERT_GT(val1, val2)
1898 #endif
1899 
1900 // C-string Comparisons.  All tests treat NULL and any non-NULL string
1901 // as different.  Two NULLs are equal.
1902 //
1903 //    * {ASSERT|EXPECT}_STREQ(s1, s2):     Tests that s1 == s2
1904 //    * {ASSERT|EXPECT}_STRNE(s1, s2):     Tests that s1 != s2
1905 //    * {ASSERT|EXPECT}_STRCASEEQ(s1, s2): Tests that s1 == s2, ignoring case
1906 //    * {ASSERT|EXPECT}_STRCASENE(s1, s2): Tests that s1 != s2, ignoring case
1907 //
1908 // For wide or narrow string objects, you can use the
1909 // {ASSERT|EXPECT}_??() macros.
1910 //
1911 // Don't depend on the order in which the arguments are evaluated,
1912 // which is undefined.
1913 //
1914 // These macros evaluate their arguments exactly once.
1915 
1916 #define EXPECT_STREQ(s1, s2) \
1917   EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, s1, s2)
1918 #define EXPECT_STRNE(s1, s2) \
1919   EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2)
1920 #define EXPECT_STRCASEEQ(s1, s2) \
1921   EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, s1, s2)
1922 #define EXPECT_STRCASENE(s1, s2) \
1923   EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2)
1924 
1925 #define ASSERT_STREQ(s1, s2) \
1926   ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, s1, s2)
1927 #define ASSERT_STRNE(s1, s2) \
1928   ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2)
1929 #define ASSERT_STRCASEEQ(s1, s2) \
1930   ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, s1, s2)
1931 #define ASSERT_STRCASENE(s1, s2) \
1932   ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2)
1933 
1934 // Macros for comparing floating-point numbers.
1935 //
1936 //    * {ASSERT|EXPECT}_FLOAT_EQ(val1, val2):
1937 //         Tests that two float values are almost equal.
1938 //    * {ASSERT|EXPECT}_DOUBLE_EQ(val1, val2):
1939 //         Tests that two double values are almost equal.
1940 //    * {ASSERT|EXPECT}_NEAR(v1, v2, abs_error):
1941 //         Tests that v1 and v2 are within the given distance to each other.
1942 //
1943 // Google Test uses ULP-based comparison to automatically pick a default
1944 // error bound that is appropriate for the operands.  See the
1945 // FloatingPoint template class in gtest-internal.h if you are
1946 // interested in the implementation details.
1947 
1948 #define EXPECT_FLOAT_EQ(val1, val2)                                         \
1949   EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \
1950                       val1, val2)
1951 
1952 #define EXPECT_DOUBLE_EQ(val1, val2)                                         \
1953   EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \
1954                       val1, val2)
1955 
1956 #define ASSERT_FLOAT_EQ(val1, val2)                                         \
1957   ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \
1958                       val1, val2)
1959 
1960 #define ASSERT_DOUBLE_EQ(val1, val2)                                         \
1961   ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \
1962                       val1, val2)
1963 
1964 #define EXPECT_NEAR(val1, val2, abs_error)                                   \
1965   EXPECT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, val1, val2, \
1966                       abs_error)
1967 
1968 #define ASSERT_NEAR(val1, val2, abs_error)                                   \
1969   ASSERT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, val1, val2, \
1970                       abs_error)
1971 
1972 // These predicate format functions work on floating-point values, and
1973 // can be used in {ASSERT|EXPECT}_PRED_FORMAT2*(), e.g.
1974 //
1975 //   EXPECT_PRED_FORMAT2(testing::DoubleLE, Foo(), 5.0);
1976 
1977 // Asserts that val1 is less than, or almost equal to, val2.  Fails
1978 // otherwise.  In particular, it fails if either val1 or val2 is NaN.
1979 GTEST_API_ AssertionResult FloatLE(const char* expr1, const char* expr2,
1980                                    float val1, float val2);
1981 GTEST_API_ AssertionResult DoubleLE(const char* expr1, const char* expr2,
1982                                     double val1, double val2);
1983 
1984 #if GTEST_OS_WINDOWS
1985 
1986 // Macros that test for HRESULT failure and success, these are only useful
1987 // on Windows, and rely on Windows SDK macros and APIs to compile.
1988 //
1989 //    * {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED}(expr)
1990 //
1991 // When expr unexpectedly fails or succeeds, Google Test prints the
1992 // expected result and the actual result with both a human-readable
1993 // string representation of the error, if available, as well as the
1994 // hex result code.
1995 #define EXPECT_HRESULT_SUCCEEDED(expr) \
1996   EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr))
1997 
1998 #define ASSERT_HRESULT_SUCCEEDED(expr) \
1999   ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr))
2000 
2001 #define EXPECT_HRESULT_FAILED(expr) \
2002   EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr))
2003 
2004 #define ASSERT_HRESULT_FAILED(expr) \
2005   ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr))
2006 
2007 #endif  // GTEST_OS_WINDOWS
2008 
2009 // Macros that execute statement and check that it doesn't generate new fatal
2010 // failures in the current thread.
2011 //
2012 //   * {ASSERT|EXPECT}_NO_FATAL_FAILURE(statement);
2013 //
2014 // Examples:
2015 //
2016 //   EXPECT_NO_FATAL_FAILURE(Process());
2017 //   ASSERT_NO_FATAL_FAILURE(Process()) << "Process() failed";
2018 //
2019 #define ASSERT_NO_FATAL_FAILURE(statement) \
2020   GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_FATAL_FAILURE_)
2021 #define EXPECT_NO_FATAL_FAILURE(statement) \
2022   GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_NONFATAL_FAILURE_)
2023 
2024 // Causes a trace (including the given source file path and line number,
2025 // and the given message) to be included in every test failure message generated
2026 // by code in the scope of the lifetime of an instance of this class. The effect
2027 // is undone with the destruction of the instance.
2028 //
2029 // The message argument can be anything streamable to std::ostream.
2030 //
2031 // Example:
2032 //   testing::ScopedTrace trace("file.cc", 123, "message");
2033 //
2034 class GTEST_API_ ScopedTrace {
2035  public:
2036   // The c'tor pushes the given source file location and message onto
2037   // a trace stack maintained by Google Test.
2038 
2039   // Template version. Uses Message() to convert the values into strings.
2040   // Slow, but flexible.
2041   template <typename T>
2042   ScopedTrace(const char* file, int line, const T& message) {
2043     PushTrace(file, line, (Message() << message).GetString());
2044   }
2045 
2046   // Optimize for some known types.
2047   ScopedTrace(const char* file, int line, const char* message) {
2048     PushTrace(file, line, message ? message : "(null)");
2049   }
2050 
2051   ScopedTrace(const char* file, int line, const std::string& message) {
2052     PushTrace(file, line, message);
2053   }
2054 
2055   // The d'tor pops the info pushed by the c'tor.
2056   //
2057   // Note that the d'tor is not virtual in order to be efficient.
2058   // Don't inherit from ScopedTrace!
2059   ~ScopedTrace();
2060 
2061  private:
2062   void PushTrace(const char* file, int line, std::string message);
2063 
2064   ScopedTrace(const ScopedTrace&) = delete;
2065   ScopedTrace& operator=(const ScopedTrace&) = delete;
2066 } GTEST_ATTRIBUTE_UNUSED_;  // A ScopedTrace object does its job in its
2067                             // c'tor and d'tor.  Therefore it doesn't
2068                             // need to be used otherwise.
2069 
2070 // Causes a trace (including the source file path, the current line
2071 // number, and the given message) to be included in every test failure
2072 // message generated by code in the current scope.  The effect is
2073 // undone when the control leaves the current scope.
2074 //
2075 // The message argument can be anything streamable to std::ostream.
2076 //
2077 // In the implementation, we include the current line number as part
2078 // of the dummy variable name, thus allowing multiple SCOPED_TRACE()s
2079 // to appear in the same block - as long as they are on different
2080 // lines.
2081 //
2082 // Assuming that each thread maintains its own stack of traces.
2083 // Therefore, a SCOPED_TRACE() would (correctly) only affect the
2084 // assertions in its own thread.
2085 #define SCOPED_TRACE(message)                                         \
2086   ::testing::ScopedTrace GTEST_CONCAT_TOKEN_(gtest_trace_, __LINE__)( \
2087       __FILE__, __LINE__, (message))
2088 
2089 // Compile-time assertion for type equality.
2090 // StaticAssertTypeEq<type1, type2>() compiles if and only if type1 and type2
2091 // are the same type.  The value it returns is not interesting.
2092 //
2093 // Instead of making StaticAssertTypeEq a class template, we make it a
2094 // function template that invokes a helper class template.  This
2095 // prevents a user from misusing StaticAssertTypeEq<T1, T2> by
2096 // defining objects of that type.
2097 //
2098 // CAVEAT:
2099 //
2100 // When used inside a method of a class template,
2101 // StaticAssertTypeEq<T1, T2>() is effective ONLY IF the method is
2102 // instantiated.  For example, given:
2103 //
2104 //   template <typename T> class Foo {
2105 //    public:
2106 //     void Bar() { testing::StaticAssertTypeEq<int, T>(); }
2107 //   };
2108 //
2109 // the code:
2110 //
2111 //   void Test1() { Foo<bool> foo; }
2112 //
2113 // will NOT generate a compiler error, as Foo<bool>::Bar() is never
2114 // actually instantiated.  Instead, you need:
2115 //
2116 //   void Test2() { Foo<bool> foo; foo.Bar(); }
2117 //
2118 // to cause a compiler error.
2119 template <typename T1, typename T2>
2120 constexpr bool StaticAssertTypeEq() noexcept {
2121   static_assert(std::is_same<T1, T2>::value, "T1 and T2 are not the same type");
2122   return true;
2123 }
2124 
2125 // Defines a test.
2126 //
2127 // The first parameter is the name of the test suite, and the second
2128 // parameter is the name of the test within the test suite.
2129 //
2130 // The convention is to end the test suite name with "Test".  For
2131 // example, a test suite for the Foo class can be named FooTest.
2132 //
2133 // Test code should appear between braces after an invocation of
2134 // this macro.  Example:
2135 //
2136 //   TEST(FooTest, InitializesCorrectly) {
2137 //     Foo foo;
2138 //     EXPECT_TRUE(foo.StatusIsOK());
2139 //   }
2140 
2141 // Note that we call GetTestTypeId() instead of GetTypeId<
2142 // ::testing::Test>() here to get the type ID of testing::Test.  This
2143 // is to work around a suspected linker bug when using Google Test as
2144 // a framework on Mac OS X.  The bug causes GetTypeId<
2145 // ::testing::Test>() to return different values depending on whether
2146 // the call is from the Google Test framework itself or from user test
2147 // code.  GetTestTypeId() is guaranteed to always return the same
2148 // value, as it always calls GetTypeId<>() from the Google Test
2149 // framework.
2150 #define GTEST_TEST(test_suite_name, test_name)             \
2151   GTEST_TEST_(test_suite_name, test_name, ::testing::Test, \
2152               ::testing::internal::GetTestTypeId())
2153 
2154 // Define this macro to 1 to omit the definition of TEST(), which
2155 // is a generic name and clashes with some other libraries.
2156 #if !GTEST_DONT_DEFINE_TEST
2157 #define TEST(test_suite_name, test_name) GTEST_TEST(test_suite_name, test_name)
2158 #endif
2159 
2160 // Defines a test that uses a test fixture.
2161 //
2162 // The first parameter is the name of the test fixture class, which
2163 // also doubles as the test suite name.  The second parameter is the
2164 // name of the test within the test suite.
2165 //
2166 // A test fixture class must be declared earlier.  The user should put
2167 // the test code between braces after using this macro.  Example:
2168 //
2169 //   class FooTest : public testing::Test {
2170 //    protected:
2171 //     void SetUp() override { b_.AddElement(3); }
2172 //
2173 //     Foo a_;
2174 //     Foo b_;
2175 //   };
2176 //
2177 //   TEST_F(FooTest, InitializesCorrectly) {
2178 //     EXPECT_TRUE(a_.StatusIsOK());
2179 //   }
2180 //
2181 //   TEST_F(FooTest, ReturnsElementCountCorrectly) {
2182 //     EXPECT_EQ(a_.size(), 0);
2183 //     EXPECT_EQ(b_.size(), 1);
2184 //   }
2185 #define GTEST_TEST_F(test_fixture, test_name)        \
2186   GTEST_TEST_(test_fixture, test_name, test_fixture, \
2187               ::testing::internal::GetTypeId<test_fixture>())
2188 #if !GTEST_DONT_DEFINE_TEST_F
2189 #define TEST_F(test_fixture, test_name) GTEST_TEST_F(test_fixture, test_name)
2190 #endif
2191 
2192 // Returns a path to temporary directory.
2193 // Tries to determine an appropriate directory for the platform.
2194 GTEST_API_ std::string TempDir();
2195 
2196 #ifdef _MSC_VER
2197 #pragma warning(pop)
2198 #endif
2199 
2200 // Dynamically registers a test with the framework.
2201 //
2202 // This is an advanced API only to be used when the `TEST` macros are
2203 // insufficient. The macros should be preferred when possible, as they avoid
2204 // most of the complexity of calling this function.
2205 //
2206 // The `factory` argument is a factory callable (move-constructible) object or
2207 // function pointer that creates a new instance of the Test object. It
2208 // handles ownership to the caller. The signature of the callable is
2209 // `Fixture*()`, where `Fixture` is the test fixture class for the test. All
2210 // tests registered with the same `test_suite_name` must return the same
2211 // fixture type. This is checked at runtime.
2212 //
2213 // The framework will infer the fixture class from the factory and will call
2214 // the `SetUpTestSuite` and `TearDownTestSuite` for it.
2215 //
2216 // Must be called before `RUN_ALL_TESTS()` is invoked, otherwise behavior is
2217 // undefined.
2218 //
2219 // Use case example:
2220 //
2221 // class MyFixture : public ::testing::Test {
2222 //  public:
2223 //   // All of these optional, just like in regular macro usage.
2224 //   static void SetUpTestSuite() { ... }
2225 //   static void TearDownTestSuite() { ... }
2226 //   void SetUp() override { ... }
2227 //   void TearDown() override { ... }
2228 // };
2229 //
2230 // class MyTest : public MyFixture {
2231 //  public:
2232 //   explicit MyTest(int data) : data_(data) {}
2233 //   void TestBody() override { ... }
2234 //
2235 //  private:
2236 //   int data_;
2237 // };
2238 //
2239 // void RegisterMyTests(const std::vector<int>& values) {
2240 //   for (int v : values) {
2241 //     ::testing::RegisterTest(
2242 //         "MyFixture", ("Test" + std::to_string(v)).c_str(), nullptr,
2243 //         std::to_string(v).c_str(),
2244 //         __FILE__, __LINE__,
2245 //         // Important to use the fixture type as the return type here.
2246 //         [=]() -> MyFixture* { return new MyTest(v); });
2247 //   }
2248 // }
2249 // ...
2250 // int main(int argc, char** argv) {
2251 //   ::testing::InitGoogleTest(&argc, argv);
2252 //   std::vector<int> values_to_test = LoadValuesFromConfig();
2253 //   RegisterMyTests(values_to_test);
2254 //   ...
2255 //   return RUN_ALL_TESTS();
2256 // }
2257 //
2258 template <int&... ExplicitParameterBarrier, typename Factory>
2259 TestInfo* RegisterTest(const char* test_suite_name, const char* test_name,
2260                        const char* type_param, const char* value_param,
2261                        const char* file, int line, Factory factory) {
2262   using TestT = typename std::remove_pointer<decltype(factory())>::type;
2263 
2264   class FactoryImpl : public internal::TestFactoryBase {
2265    public:
2266     explicit FactoryImpl(Factory f) : factory_(std::move(f)) {}
2267     Test* CreateTest() override { return factory_(); }
2268 
2269    private:
2270     Factory factory_;
2271   };
2272 
2273   return internal::MakeAndRegisterTestInfo(
2274       test_suite_name, test_name, type_param, value_param,
2275       internal::CodeLocation(file, line), internal::GetTypeId<TestT>(),
2276       internal::SuiteApiResolver<TestT>::GetSetUpCaseOrSuite(file, line),
2277       internal::SuiteApiResolver<TestT>::GetTearDownCaseOrSuite(file, line),
2278       new FactoryImpl{std::move(factory)});
2279 }
2280 
2281 }  // namespace testing
2282 
2283 // Use this function in main() to run all tests.  It returns 0 if all
2284 // tests are successful, or 1 otherwise.
2285 //
2286 // RUN_ALL_TESTS() should be invoked after the command line has been
2287 // parsed by InitGoogleTest().
2288 //
2289 // This function was formerly a macro; thus, it is in the global
2290 // namespace and has an all-caps name.
2291 int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_;
2292 
2293 inline int RUN_ALL_TESTS() { return ::testing::UnitTest::GetInstance()->Run(); }
2294 
2295 GTEST_DISABLE_MSC_WARNINGS_POP_()  //  4251
2296 
2297 #endif  // GOOGLETEST_INCLUDE_GTEST_GTEST_H_