Qucs-core  0.0.19
gtest.h
Go to the documentation of this file.
00001 // Copyright 2005, Google Inc.
00002 // All rights reserved.
00003 //
00004 // Redistribution and use in source and binary forms, with or without
00005 // modification, are permitted provided that the following conditions are
00006 // met:
00007 //
00008 //     * Redistributions of source code must retain the above copyright
00009 // notice, this list of conditions and the following disclaimer.
00010 //     * Redistributions in binary form must reproduce the above
00011 // copyright notice, this list of conditions and the following disclaimer
00012 // in the documentation and/or other materials provided with the
00013 // distribution.
00014 //     * Neither the name of Google Inc. nor the names of its
00015 // contributors may be used to endorse or promote products derived from
00016 // this software without specific prior written permission.
00017 //
00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00019 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00020 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00021 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00022 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00023 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00024 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00025 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00026 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00027 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00028 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 //
00030 // Author: wan@google.com (Zhanyong Wan)
00031 //
00032 // The Google C++ Testing Framework (Google Test)
00033 //
00034 // This header file defines the public API for Google Test.  It should be
00035 // included by any test program that uses Google Test.
00036 //
00037 // IMPORTANT NOTE: Due to limitation of the C++ language, we have to
00038 // leave some internal implementation details in this header file.
00039 // They are clearly marked by comments like this:
00040 //
00041 //   // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
00042 //
00043 // Such code is NOT meant to be used by a user directly, and is subject
00044 // to CHANGE WITHOUT NOTICE.  Therefore DO NOT DEPEND ON IT in a user
00045 // program!
00046 //
00047 // Acknowledgment: Google Test borrowed the idea of automatic test
00048 // registration from Barthelemy Dagenais' (barthelemy@prologique.com)
00049 // easyUnit framework.
00050 
00051 #ifndef GTEST_INCLUDE_GTEST_GTEST_H_
00052 #define GTEST_INCLUDE_GTEST_GTEST_H_
00053 
00054 #include <limits>
00055 #include <ostream>
00056 #include <vector>
00057 
00058 #include "gtest/internal/gtest-internal.h"
00059 #include "gtest/internal/gtest-string.h"
00060 #include "gtest/gtest-death-test.h"
00061 #include "gtest/gtest-message.h"
00062 #include "gtest/gtest-param-test.h"
00063 #include "gtest/gtest-printers.h"
00064 #include "gtest/gtest_prod.h"
00065 #include "gtest/gtest-test-part.h"
00066 #include "gtest/gtest-typed-test.h"
00067 
00068 // Depending on the platform, different string classes are available.
00069 // On Linux, in addition to ::std::string, Google also makes use of
00070 // class ::string, which has the same interface as ::std::string, but
00071 // has a different implementation.
00072 //
00073 // The user can define GTEST_HAS_GLOBAL_STRING to 1 to indicate that
00074 // ::string is available AND is a distinct type to ::std::string, or
00075 // define it to 0 to indicate otherwise.
00076 //
00077 // If the user's ::std::string and ::string are the same class due to
00078 // aliasing, he should define GTEST_HAS_GLOBAL_STRING to 0.
00079 //
00080 // If the user doesn't define GTEST_HAS_GLOBAL_STRING, it is defined
00081 // heuristically.
00082 
00083 namespace testing {
00084 
00085 // Declares the flags.
00086 
00087 // This flag temporary enables the disabled tests.
00088 GTEST_DECLARE_bool_(also_run_disabled_tests);
00089 
00090 // This flag brings the debugger on an assertion failure.
00091 GTEST_DECLARE_bool_(break_on_failure);
00092 
00093 // This flag controls whether Google Test catches all test-thrown exceptions
00094 // and logs them as failures.
00095 GTEST_DECLARE_bool_(catch_exceptions);
00096 
00097 // This flag enables using colors in terminal output. Available values are
00098 // "yes" to enable colors, "no" (disable colors), or "auto" (the default)
00099 // to let Google Test decide.
00100 GTEST_DECLARE_string_(color);
00101 
00102 // This flag sets up the filter to select by name using a glob pattern
00103 // the tests to run. If the filter is not given all tests are executed.
00104 GTEST_DECLARE_string_(filter);
00105 
00106 // This flag causes the Google Test to list tests. None of the tests listed
00107 // are actually run if the flag is provided.
00108 GTEST_DECLARE_bool_(list_tests);
00109 
00110 // This flag controls whether Google Test emits a detailed XML report to a file
00111 // in addition to its normal textual output.
00112 GTEST_DECLARE_string_(output);
00113 
00114 // This flags control whether Google Test prints the elapsed time for each
00115 // test.
00116 GTEST_DECLARE_bool_(print_time);
00117 
00118 // This flag specifies the random number seed.
00119 GTEST_DECLARE_int32_(random_seed);
00120 
00121 // This flag sets how many times the tests are repeated. The default value
00122 // is 1. If the value is -1 the tests are repeating forever.
00123 GTEST_DECLARE_int32_(repeat);
00124 
00125 // This flag controls whether Google Test includes Google Test internal
00126 // stack frames in failure stack traces.
00127 GTEST_DECLARE_bool_(show_internal_stack_frames);
00128 
00129 // When this flag is specified, tests' order is randomized on every iteration.
00130 GTEST_DECLARE_bool_(shuffle);
00131 
00132 // This flag specifies the maximum number of stack frames to be
00133 // printed in a failure message.
00134 GTEST_DECLARE_int32_(stack_trace_depth);
00135 
00136 // When this flag is specified, a failed assertion will throw an
00137 // exception if exceptions are enabled, or exit the program with a
00138 // non-zero code otherwise.
00139 GTEST_DECLARE_bool_(throw_on_failure);
00140 
00141 // When this flag is set with a "host:port" string, on supported
00142 // platforms test results are streamed to the specified port on
00143 // the specified host machine.
00144 GTEST_DECLARE_string_(stream_result_to);
00145 
00146 // The upper limit for valid stack trace depths.
00147 const int kMaxStackTraceDepth = 100;
00148 
00149 namespace internal {
00150 
00151 class AssertHelper;
00152 class DefaultGlobalTestPartResultReporter;
00153 class ExecDeathTest;
00154 class NoExecDeathTest;
00155 class FinalSuccessChecker;
00156 class GTestFlagSaver;
00157 class StreamingListenerTest;
00158 class TestResultAccessor;
00159 class TestEventListenersAccessor;
00160 class TestEventRepeater;
00161 class UnitTestRecordPropertyTestHelper;
00162 class WindowsDeathTest;
00163 class UnitTestImpl* GetUnitTestImpl();
00164 void ReportFailureInUnknownLocation(TestPartResult::Type result_type,
00165                                     const std::string& message);
00166 
00167 }  // namespace internal
00168 
00169 // The friend relationship of some of these classes is cyclic.
00170 // If we don't forward declare them the compiler might confuse the classes
00171 // in friendship clauses with same named classes on the scope.
00172 class Test;
00173 class TestCase;
00174 class TestInfo;
00175 class UnitTest;
00176 
00177 // A class for indicating whether an assertion was successful.  When
00178 // the assertion wasn't successful, the AssertionResult object
00179 // remembers a non-empty message that describes how it failed.
00180 //
00181 // To create an instance of this class, use one of the factory functions
00182 // (AssertionSuccess() and AssertionFailure()).
00183 //
00184 // This class is useful for two purposes:
00185 //   1. Defining predicate functions to be used with Boolean test assertions
00186 //      EXPECT_TRUE/EXPECT_FALSE and their ASSERT_ counterparts
00187 //   2. Defining predicate-format functions to be
00188 //      used with predicate assertions (ASSERT_PRED_FORMAT*, etc).
00189 //
00190 // For example, if you define IsEven predicate:
00191 //
00192 //   testing::AssertionResult IsEven(int n) {
00193 //     if ((n % 2) == 0)
00194 //       return testing::AssertionSuccess();
00195 //     else
00196 //       return testing::AssertionFailure() << n << " is odd";
00197 //   }
00198 //
00199 // Then the failed expectation EXPECT_TRUE(IsEven(Fib(5)))
00200 // will print the message
00201 //
00202 //   Value of: IsEven(Fib(5))
00203 //     Actual: false (5 is odd)
00204 //   Expected: true
00205 //
00206 // instead of a more opaque
00207 //
00208 //   Value of: IsEven(Fib(5))
00209 //     Actual: false
00210 //   Expected: true
00211 //
00212 // in case IsEven is a simple Boolean predicate.
00213 //
00214 // If you expect your predicate to be reused and want to support informative
00215 // messages in EXPECT_FALSE and ASSERT_FALSE (negative assertions show up
00216 // about half as often as positive ones in our tests), supply messages for
00217 // both success and failure cases:
00218 //
00219 //   testing::AssertionResult IsEven(int n) {
00220 //     if ((n % 2) == 0)
00221 //       return testing::AssertionSuccess() << n << " is even";
00222 //     else
00223 //       return testing::AssertionFailure() << n << " is odd";
00224 //   }
00225 //
00226 // Then a statement EXPECT_FALSE(IsEven(Fib(6))) will print
00227 //
00228 //   Value of: IsEven(Fib(6))
00229 //     Actual: true (8 is even)
00230 //   Expected: false
00231 //
00232 // NB: Predicates that support negative Boolean assertions have reduced
00233 // performance in positive ones so be careful not to use them in tests
00234 // that have lots (tens of thousands) of positive Boolean assertions.
00235 //
00236 // To use this class with EXPECT_PRED_FORMAT assertions such as:
00237 //
00238 //   // Verifies that Foo() returns an even number.
00239 //   EXPECT_PRED_FORMAT1(IsEven, Foo());
00240 //
00241 // you need to define:
00242 //
00243 //   testing::AssertionResult IsEven(const char* expr, int n) {
00244 //     if ((n % 2) == 0)
00245 //       return testing::AssertionSuccess();
00246 //     else
00247 //       return testing::AssertionFailure()
00248 //         << "Expected: " << expr << " is even\n  Actual: it's " << n;
00249 //   }
00250 //
00251 // If Foo() returns 5, you will see the following message:
00252 //
00253 //   Expected: Foo() is even
00254 //     Actual: it's 5
00255 //
00256 class GTEST_API_ AssertionResult {
00257  public:
00258   // Copy constructor.
00259   // Used in EXPECT_TRUE/FALSE(assertion_result).
00260   AssertionResult(const AssertionResult& other);
00261   // Used in the EXPECT_TRUE/FALSE(bool_expression).
00262   explicit AssertionResult(bool success) : success_(success) {}
00263 
00264   // Returns true iff the assertion succeeded.
00265   operator bool() const { return success_; }  // NOLINT
00266 
00267   // Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE.
00268   AssertionResult operator!() const;
00269 
00270   // Returns the text streamed into this AssertionResult. Test assertions
00271   // use it when they fail (i.e., the predicate's outcome doesn't match the
00272   // assertion's expectation). When nothing has been streamed into the
00273   // object, returns an empty string.
00274   const char* message() const {
00275     return message_.get() != NULL ?  message_->c_str() : "";
00276   }
00277   // TODO(vladl@google.com): Remove this after making sure no clients use it.
00278   // Deprecated; please use message() instead.
00279   const char* failure_message() const { return message(); }
00280 
00281   // Streams a custom failure message into this object.
00282   template <typename T> AssertionResult& operator<<(const T& value) {
00283     AppendMessage(Message() << value);
00284     return *this;
00285   }
00286 
00287   // Allows streaming basic output manipulators such as endl or flush into
00288   // this object.
00289   AssertionResult& operator<<(
00290       ::std::ostream& (*basic_manipulator)(::std::ostream& stream)) {
00291     AppendMessage(Message() << basic_manipulator);
00292     return *this;
00293   }
00294 
00295  private:
00296   // Appends the contents of message to message_.
00297   void AppendMessage(const Message& a_message) {
00298     if (message_.get() == NULL)
00299       message_.reset(new ::std::string);
00300     message_->append(a_message.GetString().c_str());
00301   }
00302 
00303   // Stores result of the assertion predicate.
00304   bool success_;
00305   // Stores the message describing the condition in case the expectation
00306   // construct is not satisfied with the predicate's outcome.
00307   // Referenced via a pointer to avoid taking too much stack frame space
00308   // with test assertions.
00309   internal::scoped_ptr< ::std::string> message_;
00310 
00311   GTEST_DISALLOW_ASSIGN_(AssertionResult);
00312 };
00313 
00314 // Makes a successful assertion result.
00315 GTEST_API_ AssertionResult AssertionSuccess();
00316 
00317 // Makes a failed assertion result.
00318 GTEST_API_ AssertionResult AssertionFailure();
00319 
00320 // Makes a failed assertion result with the given failure message.
00321 // Deprecated; use AssertionFailure() << msg.
00322 GTEST_API_ AssertionResult AssertionFailure(const Message& msg);
00323 
00324 // The abstract class that all tests inherit from.
00325 //
00326 // In Google Test, a unit test program contains one or many TestCases, and
00327 // each TestCase contains one or many Tests.
00328 //
00329 // When you define a test using the TEST macro, you don't need to
00330 // explicitly derive from Test - the TEST macro automatically does
00331 // this for you.
00332 //
00333 // The only time you derive from Test is when defining a test fixture
00334 // to be used a TEST_F.  For example:
00335 //
00336 //   class FooTest : public testing::Test {
00337 //    protected:
00338 //     virtual void SetUp() { ... }
00339 //     virtual void TearDown() { ... }
00340 //     ...
00341 //   };
00342 //
00343 //   TEST_F(FooTest, Bar) { ... }
00344 //   TEST_F(FooTest, Baz) { ... }
00345 //
00346 // Test is not copyable.
00347 class GTEST_API_ Test {
00348  public:
00349   friend class TestInfo;
00350 
00351   // Defines types for pointers to functions that set up and tear down
00352   // a test case.
00353   typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc;
00354   typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc;
00355 
00356   // The d'tor is virtual as we intend to inherit from Test.
00357   virtual ~Test();
00358 
00359   // Sets up the stuff shared by all tests in this test case.
00360   //
00361   // Google Test will call Foo::SetUpTestCase() before running the first
00362   // test in test case Foo.  Hence a sub-class can define its own
00363   // SetUpTestCase() method to shadow the one defined in the super
00364   // class.
00365   static void SetUpTestCase() {}
00366 
00367   // Tears down the stuff shared by all tests in this test case.
00368   //
00369   // Google Test will call Foo::TearDownTestCase() after running the last
00370   // test in test case Foo.  Hence a sub-class can define its own
00371   // TearDownTestCase() method to shadow the one defined in the super
00372   // class.
00373   static void TearDownTestCase() {}
00374 
00375   // Returns true iff the current test has a fatal failure.
00376   static bool HasFatalFailure();
00377 
00378   // Returns true iff the current test has a non-fatal failure.
00379   static bool HasNonfatalFailure();
00380 
00381   // Returns true iff the current test has a (either fatal or
00382   // non-fatal) failure.
00383   static bool HasFailure() { return HasFatalFailure() || HasNonfatalFailure(); }
00384 
00385   // Logs a property for the current test, test case, or for the entire
00386   // invocation of the test program when used outside of the context of a
00387   // test case.  Only the last value for a given key is remembered.  These
00388   // are public static so they can be called from utility functions that are
00389   // not members of the test fixture.  Calls to RecordProperty made during
00390   // lifespan of the test (from the moment its constructor starts to the
00391   // moment its destructor finishes) will be output in XML as attributes of
00392   // the <testcase> element.  Properties recorded from fixture's
00393   // SetUpTestCase or TearDownTestCase are logged as attributes of the
00394   // corresponding <testsuite> element.  Calls to RecordProperty made in the
00395   // global context (before or after invocation of RUN_ALL_TESTS and from
00396   // SetUp/TearDown method of Environment objects registered with Google
00397   // Test) will be output as attributes of the <testsuites> element.
00398   static void RecordProperty(const std::string& key, const std::string& value);
00399   static void RecordProperty(const std::string& key, int value);
00400 
00401  protected:
00402   // Creates a Test object.
00403   Test();
00404 
00405   // Sets up the test fixture.
00406   virtual void SetUp();
00407 
00408   // Tears down the test fixture.
00409   virtual void TearDown();
00410 
00411  private:
00412   // Returns true iff the current test has the same fixture class as
00413   // the first test in the current test case.
00414   static bool HasSameFixtureClass();
00415 
00416   // Runs the test after the test fixture has been set up.
00417   //
00418   // A sub-class must implement this to define the test logic.
00419   //
00420   // DO NOT OVERRIDE THIS FUNCTION DIRECTLY IN A USER PROGRAM.
00421   // Instead, use the TEST or TEST_F macro.
00422   virtual void TestBody() = 0;
00423 
00424   // Sets up, executes, and tears down the test.
00425   void Run();
00426 
00427   // Deletes self.  We deliberately pick an unusual name for this
00428   // internal method to avoid clashing with names used in user TESTs.
00429   void DeleteSelf_() { delete this; }
00430 
00431   // Uses a GTestFlagSaver to save and restore all Google Test flags.
00432   const internal::GTestFlagSaver* const gtest_flag_saver_;
00433 
00434   // Often a user mis-spells SetUp() as Setup() and spends a long time
00435   // wondering why it is never called by Google Test.  The declaration of
00436   // the following method is solely for catching such an error at
00437   // compile time:
00438   //
00439   //   - The return type is deliberately chosen to be not void, so it
00440   //   will be a conflict if a user declares void Setup() in his test
00441   //   fixture.
00442   //
00443   //   - This method is private, so it will be another compiler error
00444   //   if a user calls it from his test fixture.
00445   //
00446   // DO NOT OVERRIDE THIS FUNCTION.
00447   //
00448   // If you see an error about overriding the following function or
00449   // about it being private, you have mis-spelled SetUp() as Setup().
00450   struct Setup_should_be_spelled_SetUp {};
00451   virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; }
00452 
00453   // We disallow copying Tests.
00454   GTEST_DISALLOW_COPY_AND_ASSIGN_(Test);
00455 };
00456 
00457 typedef internal::TimeInMillis TimeInMillis;
00458 
00459 // A copyable object representing a user specified test property which can be
00460 // output as a key/value string pair.
00461 //
00462 // Don't inherit from TestProperty as its destructor is not virtual.
00463 class TestProperty {
00464  public:
00465   // C'tor.  TestProperty does NOT have a default constructor.
00466   // Always use this constructor (with parameters) to create a
00467   // TestProperty object.
00468   TestProperty(const std::string& a_key, const std::string& a_value) :
00469     key_(a_key), value_(a_value) {
00470   }
00471 
00472   // Gets the user supplied key.
00473   const char* key() const {
00474     return key_.c_str();
00475   }
00476 
00477   // Gets the user supplied value.
00478   const char* value() const {
00479     return value_.c_str();
00480   }
00481 
00482   // Sets a new value, overriding the one supplied in the constructor.
00483   void SetValue(const std::string& new_value) {
00484     value_ = new_value;
00485   }
00486 
00487  private:
00488   // The key supplied by the user.
00489   std::string key_;
00490   // The value supplied by the user.
00491   std::string value_;
00492 };
00493 
00494 // The result of a single Test.  This includes a list of
00495 // TestPartResults, a list of TestProperties, a count of how many
00496 // death tests there are in the Test, and how much time it took to run
00497 // the Test.
00498 //
00499 // TestResult is not copyable.
00500 class GTEST_API_ TestResult {
00501  public:
00502   // Creates an empty TestResult.
00503   TestResult();
00504 
00505   // D'tor.  Do not inherit from TestResult.
00506   ~TestResult();
00507 
00508   // Gets the number of all test parts.  This is the sum of the number
00509   // of successful test parts and the number of failed test parts.
00510   int total_part_count() const;
00511 
00512   // Returns the number of the test properties.
00513   int test_property_count() const;
00514 
00515   // Returns true iff the test passed (i.e. no test part failed).
00516   bool Passed() const { return !Failed(); }
00517 
00518   // Returns true iff the test failed.
00519   bool Failed() const;
00520 
00521   // Returns true iff the test fatally failed.
00522   bool HasFatalFailure() const;
00523 
00524   // Returns true iff the test has a non-fatal failure.
00525   bool HasNonfatalFailure() const;
00526 
00527   // Returns the elapsed time, in milliseconds.
00528   TimeInMillis elapsed_time() const { return elapsed_time_; }
00529 
00530   // Returns the i-th test part result among all the results. i can range
00531   // from 0 to test_property_count() - 1. If i is not in that range, aborts
00532   // the program.
00533   const TestPartResult& GetTestPartResult(int i) const;
00534 
00535   // Returns the i-th test property. i can range from 0 to
00536   // test_property_count() - 1. If i is not in that range, aborts the
00537   // program.
00538   const TestProperty& GetTestProperty(int i) const;
00539 
00540  private:
00541   friend class TestInfo;
00542   friend class TestCase;
00543   friend class UnitTest;
00544   friend class internal::DefaultGlobalTestPartResultReporter;
00545   friend class internal::ExecDeathTest;
00546   friend class internal::TestResultAccessor;
00547   friend class internal::UnitTestImpl;
00548   friend class internal::WindowsDeathTest;
00549 
00550   // Gets the vector of TestPartResults.
00551   const std::vector<TestPartResult>& test_part_results() const {
00552     return test_part_results_;
00553   }
00554 
00555   // Gets the vector of TestProperties.
00556   const std::vector<TestProperty>& test_properties() const {
00557     return test_properties_;
00558   }
00559 
00560   // Sets the elapsed time.
00561   void set_elapsed_time(TimeInMillis elapsed) { elapsed_time_ = elapsed; }
00562 
00563   // Adds a test property to the list. The property is validated and may add
00564   // a non-fatal failure if invalid (e.g., if it conflicts with reserved
00565   // key names). If a property is already recorded for the same key, the
00566   // value will be updated, rather than storing multiple values for the same
00567   // key.  xml_element specifies the element for which the property is being
00568   // recorded and is used for validation.
00569   void RecordProperty(const std::string& xml_element,
00570                       const TestProperty& test_property);
00571 
00572   // Adds a failure if the key is a reserved attribute of Google Test
00573   // testcase tags.  Returns true if the property is valid.
00574   // TODO(russr): Validate attribute names are legal and human readable.
00575   static bool ValidateTestProperty(const std::string& xml_element,
00576                                    const TestProperty& test_property);
00577 
00578   // Adds a test part result to the list.
00579   void AddTestPartResult(const TestPartResult& test_part_result);
00580 
00581   // Returns the death test count.
00582   int death_test_count() const { return death_test_count_; }
00583 
00584   // Increments the death test count, returning the new count.
00585   int increment_death_test_count() { return ++death_test_count_; }
00586 
00587   // Clears the test part results.
00588   void ClearTestPartResults();
00589 
00590   // Clears the object.
00591   void Clear();
00592 
00593   // Protects mutable state of the property vector and of owned
00594   // properties, whose values may be updated.
00595   internal::Mutex test_properites_mutex_;
00596 
00597   // The vector of TestPartResults
00598   std::vector<TestPartResult> test_part_results_;
00599   // The vector of TestProperties
00600   std::vector<TestProperty> test_properties_;
00601   // Running count of death tests.
00602   int death_test_count_;
00603   // The elapsed time, in milliseconds.
00604   TimeInMillis elapsed_time_;
00605 
00606   // We disallow copying TestResult.
00607   GTEST_DISALLOW_COPY_AND_ASSIGN_(TestResult);
00608 };  // class TestResult
00609 
00610 // A TestInfo object stores the following information about a test:
00611 //
00612 //   Test case name
00613 //   Test name
00614 //   Whether the test should be run
00615 //   A function pointer that creates the test object when invoked
00616 //   Test result
00617 //
00618 // The constructor of TestInfo registers itself with the UnitTest
00619 // singleton such that the RUN_ALL_TESTS() macro knows which tests to
00620 // run.
00621 class GTEST_API_ TestInfo {
00622  public:
00623   // Destructs a TestInfo object.  This function is not virtual, so
00624   // don't inherit from TestInfo.
00625   ~TestInfo();
00626 
00627   // Returns the test case name.
00628   const char* test_case_name() const { return test_case_name_.c_str(); }
00629 
00630   // Returns the test name.
00631   const char* name() const { return name_.c_str(); }
00632 
00633   // Returns the name of the parameter type, or NULL if this is not a typed
00634   // or a type-parameterized test.
00635   const char* type_param() const {
00636     if (type_param_.get() != NULL)
00637       return type_param_->c_str();
00638     return NULL;
00639   }
00640 
00641   // Returns the text representation of the value parameter, or NULL if this
00642   // is not a value-parameterized test.
00643   const char* value_param() const {
00644     if (value_param_.get() != NULL)
00645       return value_param_->c_str();
00646     return NULL;
00647   }
00648 
00649   // Returns true if this test should run, that is if the test is not
00650   // disabled (or it is disabled but the also_run_disabled_tests flag has
00651   // been specified) and its full name matches the user-specified filter.
00652   //
00653   // Google Test allows the user to filter the tests by their full names.
00654   // The full name of a test Bar in test case Foo is defined as
00655   // "Foo.Bar".  Only the tests that match the filter will run.
00656   //
00657   // A filter is a colon-separated list of glob (not regex) patterns,
00658   // optionally followed by a '-' and a colon-separated list of
00659   // negative patterns (tests to exclude).  A test is run if it
00660   // matches one of the positive patterns and does not match any of
00661   // the negative patterns.
00662   //
00663   // For example, *A*:Foo.* is a filter that matches any string that
00664   // contains the character 'A' or starts with "Foo.".
00665   bool should_run() const { return should_run_; }
00666 
00667   // Returns true iff this test will appear in the XML report.
00668   bool is_reportable() const {
00669     // For now, the XML report includes all tests matching the filter.
00670     // In the future, we may trim tests that are excluded because of
00671     // sharding.
00672     return matches_filter_;
00673   }
00674 
00675   // Returns the result of the test.
00676   const TestResult* result() const { return &result_; }
00677 
00678  private:
00679 #if GTEST_HAS_DEATH_TEST
00680   friend class internal::DefaultDeathTestFactory;
00681 #endif  // GTEST_HAS_DEATH_TEST
00682   friend class Test;
00683   friend class TestCase;
00684   friend class internal::UnitTestImpl;
00685   friend class internal::StreamingListenerTest;
00686   friend TestInfo* internal::MakeAndRegisterTestInfo(
00687       const char* test_case_name,
00688       const char* name,
00689       const char* type_param,
00690       const char* value_param,
00691       internal::TypeId fixture_class_id,
00692       Test::SetUpTestCaseFunc set_up_tc,
00693       Test::TearDownTestCaseFunc tear_down_tc,
00694       internal::TestFactoryBase* factory);
00695 
00696   // Constructs a TestInfo object. The newly constructed instance assumes
00697   // ownership of the factory object.
00698   TestInfo(const std::string& test_case_name,
00699            const std::string& name,
00700            const char* a_type_param,   // NULL if not a type-parameterized test
00701            const char* a_value_param,  // NULL if not a value-parameterized test
00702            internal::TypeId fixture_class_id,
00703            internal::TestFactoryBase* factory);
00704 
00705   // Increments the number of death tests encountered in this test so
00706   // far.
00707   int increment_death_test_count() {
00708     return result_.increment_death_test_count();
00709   }
00710 
00711   // Creates the test object, runs it, records its result, and then
00712   // deletes it.
00713   void Run();
00714 
00715   static void ClearTestResult(TestInfo* test_info) {
00716     test_info->result_.Clear();
00717   }
00718 
00719   // These fields are immutable properties of the test.
00720   const std::string test_case_name_;     // Test case name
00721   const std::string name_;               // Test name
00722   // Name of the parameter type, or NULL if this is not a typed or a
00723   // type-parameterized test.
00724   const internal::scoped_ptr<const ::std::string> type_param_;
00725   // Text representation of the value parameter, or NULL if this is not a
00726   // value-parameterized test.
00727   const internal::scoped_ptr<const ::std::string> value_param_;
00728   const internal::TypeId fixture_class_id_;   // ID of the test fixture class
00729   bool should_run_;                 // True iff this test should run
00730   bool is_disabled_;                // True iff this test is disabled
00731   bool matches_filter_;             // True if this test matches the
00732                                     // user-specified filter.
00733   internal::TestFactoryBase* const factory_;  // The factory that creates
00734                                               // the test object
00735 
00736   // This field is mutable and needs to be reset before running the
00737   // test for the second time.
00738   TestResult result_;
00739 
00740   GTEST_DISALLOW_COPY_AND_ASSIGN_(TestInfo);
00741 };
00742 
00743 // A test case, which consists of a vector of TestInfos.
00744 //
00745 // TestCase is not copyable.
00746 class GTEST_API_ TestCase {
00747  public:
00748   // Creates a TestCase with the given name.
00749   //
00750   // TestCase does NOT have a default constructor.  Always use this
00751   // constructor to create a TestCase object.
00752   //
00753   // Arguments:
00754   //
00755   //   name:         name of the test case
00756   //   a_type_param: the name of the test's type parameter, or NULL if
00757   //                 this is not a type-parameterized test.
00758   //   set_up_tc:    pointer to the function that sets up the test case
00759   //   tear_down_tc: pointer to the function that tears down the test case
00760   TestCase(const char* name, const char* a_type_param,
00761            Test::SetUpTestCaseFunc set_up_tc,
00762            Test::TearDownTestCaseFunc tear_down_tc);
00763 
00764   // Destructor of TestCase.
00765   virtual ~TestCase();
00766 
00767   // Gets the name of the TestCase.
00768   const char* name() const { return name_.c_str(); }
00769 
00770   // Returns the name of the parameter type, or NULL if this is not a
00771   // type-parameterized test case.
00772   const char* type_param() const {
00773     if (type_param_.get() != NULL)
00774       return type_param_->c_str();
00775     return NULL;
00776   }
00777 
00778   // Returns true if any test in this test case should run.
00779   bool should_run() const { return should_run_; }
00780 
00781   // Gets the number of successful tests in this test case.
00782   int successful_test_count() const;
00783 
00784   // Gets the number of failed tests in this test case.
00785   int failed_test_count() const;
00786 
00787   // Gets the number of disabled tests that will be reported in the XML report.
00788   int reportable_disabled_test_count() const;
00789 
00790   // Gets the number of disabled tests in this test case.
00791   int disabled_test_count() const;
00792 
00793   // Gets the number of tests to be printed in the XML report.
00794   int reportable_test_count() const;
00795 
00796   // Get the number of tests in this test case that should run.
00797   int test_to_run_count() const;
00798 
00799   // Gets the number of all tests in this test case.
00800   int total_test_count() const;
00801 
00802   // Returns true iff the test case passed.
00803   bool Passed() const { return !Failed(); }
00804 
00805   // Returns true iff the test case failed.
00806   bool Failed() const { return failed_test_count() > 0; }
00807 
00808   // Returns the elapsed time, in milliseconds.
00809   TimeInMillis elapsed_time() const { return elapsed_time_; }
00810 
00811   // Returns the i-th test among all the tests. i can range from 0 to
00812   // total_test_count() - 1. If i is not in that range, returns NULL.
00813   const TestInfo* GetTestInfo(int i) const;
00814 
00815   // Returns the TestResult that holds test properties recorded during
00816   // execution of SetUpTestCase and TearDownTestCase.
00817   const TestResult& ad_hoc_test_result() const { return ad_hoc_test_result_; }
00818 
00819  private:
00820   friend class Test;
00821   friend class internal::UnitTestImpl;
00822 
00823   // Gets the (mutable) vector of TestInfos in this TestCase.
00824   std::vector<TestInfo*>& test_info_list() { return test_info_list_; }
00825 
00826   // Gets the (immutable) vector of TestInfos in this TestCase.
00827   const std::vector<TestInfo*>& test_info_list() const {
00828     return test_info_list_;
00829   }
00830 
00831   // Returns the i-th test among all the tests. i can range from 0 to
00832   // total_test_count() - 1. If i is not in that range, returns NULL.
00833   TestInfo* GetMutableTestInfo(int i);
00834 
00835   // Sets the should_run member.
00836   void set_should_run(bool should) { should_run_ = should; }
00837 
00838   // Adds a TestInfo to this test case.  Will delete the TestInfo upon
00839   // destruction of the TestCase object.
00840   void AddTestInfo(TestInfo * test_info);
00841 
00842   // Clears the results of all tests in this test case.
00843   void ClearResult();
00844 
00845   // Clears the results of all tests in the given test case.
00846   static void ClearTestCaseResult(TestCase* test_case) {
00847     test_case->ClearResult();
00848   }
00849 
00850   // Runs every test in this TestCase.
00851   void Run();
00852 
00853   // Runs SetUpTestCase() for this TestCase.  This wrapper is needed
00854   // for catching exceptions thrown from SetUpTestCase().
00855   void RunSetUpTestCase() { (*set_up_tc_)(); }
00856 
00857   // Runs TearDownTestCase() for this TestCase.  This wrapper is
00858   // needed for catching exceptions thrown from TearDownTestCase().
00859   void RunTearDownTestCase() { (*tear_down_tc_)(); }
00860 
00861   // Returns true iff test passed.
00862   static bool TestPassed(const TestInfo* test_info) {
00863     return test_info->should_run() && test_info->result()->Passed();
00864   }
00865 
00866   // Returns true iff test failed.
00867   static bool TestFailed(const TestInfo* test_info) {
00868     return test_info->should_run() && test_info->result()->Failed();
00869   }
00870 
00871   // Returns true iff the test is disabled and will be reported in the XML
00872   // report.
00873   static bool TestReportableDisabled(const TestInfo* test_info) {
00874     return test_info->is_reportable() && test_info->is_disabled_;
00875   }
00876 
00877   // Returns true iff test is disabled.
00878   static bool TestDisabled(const TestInfo* test_info) {
00879     return test_info->is_disabled_;
00880   }
00881 
00882   // Returns true iff this test will appear in the XML report.
00883   static bool TestReportable(const TestInfo* test_info) {
00884     return test_info->is_reportable();
00885   }
00886 
00887   // Returns true if the given test should run.
00888   static bool ShouldRunTest(const TestInfo* test_info) {
00889     return test_info->should_run();
00890   }
00891 
00892   // Shuffles the tests in this test case.
00893   void ShuffleTests(internal::Random* random);
00894 
00895   // Restores the test order to before the first shuffle.
00896   void UnshuffleTests();
00897 
00898   // Name of the test case.
00899   std::string name_;
00900   // Name of the parameter type, or NULL if this is not a typed or a
00901   // type-parameterized test.
00902   const internal::scoped_ptr<const ::std::string> type_param_;
00903   // The vector of TestInfos in their original order.  It owns the
00904   // elements in the vector.
00905   std::vector<TestInfo*> test_info_list_;
00906   // Provides a level of indirection for the test list to allow easy
00907   // shuffling and restoring the test order.  The i-th element in this
00908   // vector is the index of the i-th test in the shuffled test list.
00909   std::vector<int> test_indices_;
00910   // Pointer to the function that sets up the test case.
00911   Test::SetUpTestCaseFunc set_up_tc_;
00912   // Pointer to the function that tears down the test case.
00913   Test::TearDownTestCaseFunc tear_down_tc_;
00914   // True iff any test in this test case should run.
00915   bool should_run_;
00916   // Elapsed time, in milliseconds.
00917   TimeInMillis elapsed_time_;
00918   // Holds test properties recorded during execution of SetUpTestCase and
00919   // TearDownTestCase.
00920   TestResult ad_hoc_test_result_;
00921 
00922   // We disallow copying TestCases.
00923   GTEST_DISALLOW_COPY_AND_ASSIGN_(TestCase);
00924 };
00925 
00926 // An Environment object is capable of setting up and tearing down an
00927 // environment.  The user should subclass this to define his own
00928 // environment(s).
00929 //
00930 // An Environment object does the set-up and tear-down in virtual
00931 // methods SetUp() and TearDown() instead of the constructor and the
00932 // destructor, as:
00933 //
00934 //   1. You cannot safely throw from a destructor.  This is a problem
00935 //      as in some cases Google Test is used where exceptions are enabled, and
00936 //      we may want to implement ASSERT_* using exceptions where they are
00937 //      available.
00938 //   2. You cannot use ASSERT_* directly in a constructor or
00939 //      destructor.
00940 class Environment {
00941  public:
00942   // The d'tor is virtual as we need to subclass Environment.
00943   virtual ~Environment() {}
00944 
00945   // Override this to define how to set up the environment.
00946   virtual void SetUp() {}
00947 
00948   // Override this to define how to tear down the environment.
00949   virtual void TearDown() {}
00950  private:
00951   // If you see an error about overriding the following function or
00952   // about it being private, you have mis-spelled SetUp() as Setup().
00953   struct Setup_should_be_spelled_SetUp {};
00954   virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; }
00955 };
00956 
00957 // The interface for tracing execution of tests. The methods are organized in
00958 // the order the corresponding events are fired.
00959 class TestEventListener {
00960  public:
00961   virtual ~TestEventListener() {}
00962 
00963   // Fired before any test activity starts.
00964   virtual void OnTestProgramStart(const UnitTest& unit_test) = 0;
00965 
00966   // Fired before each iteration of tests starts.  There may be more than
00967   // one iteration if GTEST_FLAG(repeat) is set. iteration is the iteration
00968   // index, starting from 0.
00969   virtual void OnTestIterationStart(const UnitTest& unit_test,
00970                                     int iteration) = 0;
00971 
00972   // Fired before environment set-up for each iteration of tests starts.
00973   virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test) = 0;
00974 
00975   // Fired after environment set-up for each iteration of tests ends.
00976   virtual void OnEnvironmentsSetUpEnd(const UnitTest& unit_test) = 0;
00977 
00978   // Fired before the test case starts.
00979   virtual void OnTestCaseStart(const TestCase& test_case) = 0;
00980 
00981   // Fired before the test starts.
00982   virtual void OnTestStart(const TestInfo& test_info) = 0;
00983 
00984   // Fired after a failed assertion or a SUCCEED() invocation.
00985   virtual void OnTestPartResult(const TestPartResult& test_part_result) = 0;
00986 
00987   // Fired after the test ends.
00988   virtual void OnTestEnd(const TestInfo& test_info) = 0;
00989 
00990   // Fired after the test case ends.
00991   virtual void OnTestCaseEnd(const TestCase& test_case) = 0;
00992 
00993   // Fired before environment tear-down for each iteration of tests starts.
00994   virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test) = 0;
00995 
00996   // Fired after environment tear-down for each iteration of tests ends.
00997   virtual void OnEnvironmentsTearDownEnd(const UnitTest& unit_test) = 0;
00998 
00999   // Fired after each iteration of tests finishes.
01000   virtual void OnTestIterationEnd(const UnitTest& unit_test,
01001                                   int iteration) = 0;
01002 
01003   // Fired after all test activities have ended.
01004   virtual void OnTestProgramEnd(const UnitTest& unit_test) = 0;
01005 };
01006 
01007 // The convenience class for users who need to override just one or two
01008 // methods and are not concerned that a possible change to a signature of
01009 // the methods they override will not be caught during the build.  For
01010 // comments about each method please see the definition of TestEventListener
01011 // above.
01012 class EmptyTestEventListener : public TestEventListener {
01013  public:
01014   virtual void OnTestProgramStart(const UnitTest& /*unit_test*/) {}
01015   virtual void OnTestIterationStart(const UnitTest& /*unit_test*/,
01016                                     int /*iteration*/) {}
01017   virtual void OnEnvironmentsSetUpStart(const UnitTest& /*unit_test*/) {}
01018   virtual void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) {}
01019   virtual void OnTestCaseStart(const TestCase& /*test_case*/) {}
01020   virtual void OnTestStart(const TestInfo& /*test_info*/) {}
01021   virtual void OnTestPartResult(const TestPartResult& /*test_part_result*/) {}
01022   virtual void OnTestEnd(const TestInfo& /*test_info*/) {}
01023   virtual void OnTestCaseEnd(const TestCase& /*test_case*/) {}
01024   virtual void OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) {}
01025   virtual void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) {}
01026   virtual void OnTestIterationEnd(const UnitTest& /*unit_test*/,
01027                                   int /*iteration*/) {}
01028   virtual void OnTestProgramEnd(const UnitTest& /*unit_test*/) {}
01029 };
01030 
01031 // TestEventListeners lets users add listeners to track events in Google Test.
01032 class GTEST_API_ TestEventListeners {
01033  public:
01034   TestEventListeners();
01035   ~TestEventListeners();
01036 
01037   // Appends an event listener to the end of the list. Google Test assumes
01038   // the ownership of the listener (i.e. it will delete the listener when
01039   // the test program finishes).
01040   void Append(TestEventListener* listener);
01041 
01042   // Removes the given event listener from the list and returns it.  It then
01043   // becomes the caller's responsibility to delete the listener. Returns
01044   // NULL if the listener is not found in the list.
01045   TestEventListener* Release(TestEventListener* listener);
01046 
01047   // Returns the standard listener responsible for the default console
01048   // output.  Can be removed from the listeners list to shut down default
01049   // console output.  Note that removing this object from the listener list
01050   // with Release transfers its ownership to the caller and makes this
01051   // function return NULL the next time.
01052   TestEventListener* default_result_printer() const {
01053     return default_result_printer_;
01054   }
01055 
01056   // Returns the standard listener responsible for the default XML output
01057   // controlled by the --gtest_output=xml flag.  Can be removed from the
01058   // listeners list by users who want to shut down the default XML output
01059   // controlled by this flag and substitute it with custom one.  Note that
01060   // removing this object from the listener list with Release transfers its
01061   // ownership to the caller and makes this function return NULL the next
01062   // time.
01063   TestEventListener* default_xml_generator() const {
01064     return default_xml_generator_;
01065   }
01066 
01067  private:
01068   friend class TestCase;
01069   friend class TestInfo;
01070   friend class internal::DefaultGlobalTestPartResultReporter;
01071   friend class internal::NoExecDeathTest;
01072   friend class internal::TestEventListenersAccessor;
01073   friend class internal::UnitTestImpl;
01074 
01075   // Returns repeater that broadcasts the TestEventListener events to all
01076   // subscribers.
01077   TestEventListener* repeater();
01078 
01079   // Sets the default_result_printer attribute to the provided listener.
01080   // The listener is also added to the listener list and previous
01081   // default_result_printer is removed from it and deleted. The listener can
01082   // also be NULL in which case it will not be added to the list. Does
01083   // nothing if the previous and the current listener objects are the same.
01084   void SetDefaultResultPrinter(TestEventListener* listener);
01085 
01086   // Sets the default_xml_generator attribute to the provided listener.  The
01087   // listener is also added to the listener list and previous
01088   // default_xml_generator is removed from it and deleted. The listener can
01089   // also be NULL in which case it will not be added to the list. Does
01090   // nothing if the previous and the current listener objects are the same.
01091   void SetDefaultXmlGenerator(TestEventListener* listener);
01092 
01093   // Controls whether events will be forwarded by the repeater to the
01094   // listeners in the list.
01095   bool EventForwardingEnabled() const;
01096   void SuppressEventForwarding();
01097 
01098   // The actual list of listeners.
01099   internal::TestEventRepeater* repeater_;
01100   // Listener responsible for the standard result output.
01101   TestEventListener* default_result_printer_;
01102   // Listener responsible for the creation of the XML output file.
01103   TestEventListener* default_xml_generator_;
01104 
01105   // We disallow copying TestEventListeners.
01106   GTEST_DISALLOW_COPY_AND_ASSIGN_(TestEventListeners);
01107 };
01108 
01109 // A UnitTest consists of a vector of TestCases.
01110 //
01111 // This is a singleton class.  The only instance of UnitTest is
01112 // created when UnitTest::GetInstance() is first called.  This
01113 // instance is never deleted.
01114 //
01115 // UnitTest is not copyable.
01116 //
01117 // This class is thread-safe as long as the methods are called
01118 // according to their specification.
01119 class GTEST_API_ UnitTest {
01120  public:
01121   // Gets the singleton UnitTest object.  The first time this method
01122   // is called, a UnitTest object is constructed and returned.
01123   // Consecutive calls will return the same object.
01124   static UnitTest* GetInstance();
01125 
01126   // Runs all tests in this UnitTest object and prints the result.
01127   // Returns 0 if successful, or 1 otherwise.
01128   //
01129   // This method can only be called from the main thread.
01130   //
01131   // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
01132   int Run() GTEST_MUST_USE_RESULT_;
01133 
01134   // Returns the working directory when the first TEST() or TEST_F()
01135   // was executed.  The UnitTest object owns the string.
01136   const char* original_working_dir() const;
01137 
01138   // Returns the TestCase object for the test that's currently running,
01139   // or NULL if no test is running.
01140   const TestCase* current_test_case() const
01141       GTEST_LOCK_EXCLUDED_(mutex_);
01142 
01143   // Returns the TestInfo object for the test that's currently running,
01144   // or NULL if no test is running.
01145   const TestInfo* current_test_info() const
01146       GTEST_LOCK_EXCLUDED_(mutex_);
01147 
01148   // Returns the random seed used at the start of the current test run.
01149   int random_seed() const;
01150 
01151 #if GTEST_HAS_PARAM_TEST
01152   // Returns the ParameterizedTestCaseRegistry object used to keep track of
01153   // value-parameterized tests and instantiate and register them.
01154   //
01155   // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
01156   internal::ParameterizedTestCaseRegistry& parameterized_test_registry()
01157       GTEST_LOCK_EXCLUDED_(mutex_);
01158 #endif  // GTEST_HAS_PARAM_TEST
01159 
01160   // Gets the number of successful test cases.
01161   int successful_test_case_count() const;
01162 
01163   // Gets the number of failed test cases.
01164   int failed_test_case_count() const;
01165 
01166   // Gets the number of all test cases.
01167   int total_test_case_count() const;
01168 
01169   // Gets the number of all test cases that contain at least one test
01170   // that should run.
01171   int test_case_to_run_count() const;
01172 
01173   // Gets the number of successful tests.
01174   int successful_test_count() const;
01175 
01176   // Gets the number of failed tests.
01177   int failed_test_count() const;
01178 
01179   // Gets the number of disabled tests that will be reported in the XML report.
01180   int reportable_disabled_test_count() const;
01181 
01182   // Gets the number of disabled tests.
01183   int disabled_test_count() const;
01184 
01185   // Gets the number of tests to be printed in the XML report.
01186   int reportable_test_count() const;
01187 
01188   // Gets the number of all tests.
01189   int total_test_count() const;
01190 
01191   // Gets the number of tests that should run.
01192   int test_to_run_count() const;
01193 
01194   // Gets the time of the test program start, in ms from the start of the
01195   // UNIX epoch.
01196   TimeInMillis start_timestamp() const;
01197 
01198   // Gets the elapsed time, in milliseconds.
01199   TimeInMillis elapsed_time() const;
01200 
01201   // Returns true iff the unit test passed (i.e. all test cases passed).
01202   bool Passed() const;
01203 
01204   // Returns true iff the unit test failed (i.e. some test case failed
01205   // or something outside of all tests failed).
01206   bool Failed() const;
01207 
01208   // Gets the i-th test case among all the test cases. i can range from 0 to
01209   // total_test_case_count() - 1. If i is not in that range, returns NULL.
01210   const TestCase* GetTestCase(int i) const;
01211 
01212   // Returns the TestResult containing information on test failures and
01213   // properties logged outside of individual test cases.
01214   const TestResult& ad_hoc_test_result() const;
01215 
01216   // Returns the list of event listeners that can be used to track events
01217   // inside Google Test.
01218   TestEventListeners& listeners();
01219 
01220  private:
01221   // Registers and returns a global test environment.  When a test
01222   // program is run, all global test environments will be set-up in
01223   // the order they were registered.  After all tests in the program
01224   // have finished, all global test environments will be torn-down in
01225   // the *reverse* order they were registered.
01226   //
01227   // The UnitTest object takes ownership of the given environment.
01228   //
01229   // This method can only be called from the main thread.
01230   Environment* AddEnvironment(Environment* env);
01231 
01232   // Adds a TestPartResult to the current TestResult object.  All
01233   // Google Test assertion macros (e.g. ASSERT_TRUE, EXPECT_EQ, etc)
01234   // eventually call this to report their results.  The user code
01235   // should use the assertion macros instead of calling this directly.
01236   void AddTestPartResult(TestPartResult::Type result_type,
01237                          const char* file_name,
01238                          int line_number,
01239                          const std::string& message,
01240                          const std::string& os_stack_trace)
01241       GTEST_LOCK_EXCLUDED_(mutex_);
01242 
01243   // Adds a TestProperty to the current TestResult object when invoked from
01244   // inside a test, to current TestCase's ad_hoc_test_result_ when invoked
01245   // from SetUpTestCase or TearDownTestCase, or to the global property set
01246   // when invoked elsewhere.  If the result already contains a property with
01247   // the same key, the value will be updated.
01248   void RecordProperty(const std::string& key, const std::string& value);
01249 
01250   // Gets the i-th test case among all the test cases. i can range from 0 to
01251   // total_test_case_count() - 1. If i is not in that range, returns NULL.
01252   TestCase* GetMutableTestCase(int i);
01253 
01254   // Accessors for the implementation object.
01255   internal::UnitTestImpl* impl() { return impl_; }
01256   const internal::UnitTestImpl* impl() const { return impl_; }
01257 
01258   // These classes and funcions are friends as they need to access private
01259   // members of UnitTest.
01260   friend class Test;
01261   friend class internal::AssertHelper;
01262   friend class internal::ScopedTrace;
01263   friend class internal::StreamingListenerTest;
01264   friend class internal::UnitTestRecordPropertyTestHelper;
01265   friend Environment* AddGlobalTestEnvironment(Environment* env);
01266   friend internal::UnitTestImpl* internal::GetUnitTestImpl();
01267   friend void internal::ReportFailureInUnknownLocation(
01268       TestPartResult::Type result_type,
01269       const std::string& message);
01270 
01271   // Creates an empty UnitTest.
01272   UnitTest();
01273 
01274   // D'tor
01275   virtual ~UnitTest();
01276 
01277   // Pushes a trace defined by SCOPED_TRACE() on to the per-thread
01278   // Google Test trace stack.
01279   void PushGTestTrace(const internal::TraceInfo& trace)
01280       GTEST_LOCK_EXCLUDED_(mutex_);
01281 
01282   // Pops a trace from the per-thread Google Test trace stack.
01283   void PopGTestTrace()
01284       GTEST_LOCK_EXCLUDED_(mutex_);
01285 
01286   // Protects mutable state in *impl_.  This is mutable as some const
01287   // methods need to lock it too.
01288   mutable internal::Mutex mutex_;
01289 
01290   // Opaque implementation object.  This field is never changed once
01291   // the object is constructed.  We don't mark it as const here, as
01292   // doing so will cause a warning in the constructor of UnitTest.
01293   // Mutable state in *impl_ is protected by mutex_.
01294   internal::UnitTestImpl* impl_;
01295 
01296   // We disallow copying UnitTest.
01297   GTEST_DISALLOW_COPY_AND_ASSIGN_(UnitTest);
01298 };
01299 
01300 // A convenient wrapper for adding an environment for the test
01301 // program.
01302 //
01303 // You should call this before RUN_ALL_TESTS() is called, probably in
01304 // main().  If you use gtest_main, you need to call this before main()
01305 // starts for it to take effect.  For example, you can define a global
01306 // variable like this:
01307 //
01308 //   testing::Environment* const foo_env =
01309 //       testing::AddGlobalTestEnvironment(new FooEnvironment);
01310 //
01311 // However, we strongly recommend you to write your own main() and
01312 // call AddGlobalTestEnvironment() there, as relying on initialization
01313 // of global variables makes the code harder to read and may cause
01314 // problems when you register multiple environments from different
01315 // translation units and the environments have dependencies among them
01316 // (remember that the compiler doesn't guarantee the order in which
01317 // global variables from different translation units are initialized).
01318 inline Environment* AddGlobalTestEnvironment(Environment* env) {
01319   return UnitTest::GetInstance()->AddEnvironment(env);
01320 }
01321 
01322 // Initializes Google Test.  This must be called before calling
01323 // RUN_ALL_TESTS().  In particular, it parses a command line for the
01324 // flags that Google Test recognizes.  Whenever a Google Test flag is
01325 // seen, it is removed from argv, and *argc is decremented.
01326 //
01327 // No value is returned.  Instead, the Google Test flag variables are
01328 // updated.
01329 //
01330 // Calling the function for the second time has no user-visible effect.
01331 GTEST_API_ void InitGoogleTest(int* argc, char** argv);
01332 
01333 // This overloaded version can be used in Windows programs compiled in
01334 // UNICODE mode.
01335 GTEST_API_ void InitGoogleTest(int* argc, wchar_t** argv);
01336 
01337 namespace internal {
01338 
01339 // FormatForComparison<ToPrint, OtherOperand>::Format(value) formats a
01340 // value of type ToPrint that is an operand of a comparison assertion
01341 // (e.g. ASSERT_EQ).  OtherOperand is the type of the other operand in
01342 // the comparison, and is used to help determine the best way to
01343 // format the value.  In particular, when the value is a C string
01344 // (char pointer) and the other operand is an STL string object, we
01345 // want to format the C string as a string, since we know it is
01346 // compared by value with the string object.  If the value is a char
01347 // pointer but the other operand is not an STL string object, we don't
01348 // know whether the pointer is supposed to point to a NUL-terminated
01349 // string, and thus want to print it as a pointer to be safe.
01350 //
01351 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
01352 
01353 // The default case.
01354 template <typename ToPrint, typename OtherOperand>
01355 class FormatForComparison {
01356  public:
01357   static ::std::string Format(const ToPrint& value) {
01358     return ::testing::PrintToString(value);
01359   }
01360 };
01361 
01362 // Array.
01363 template <typename ToPrint, size_t N, typename OtherOperand>
01364 class FormatForComparison<ToPrint[N], OtherOperand> {
01365  public:
01366   static ::std::string Format(const ToPrint* value) {
01367     return FormatForComparison<const ToPrint*, OtherOperand>::Format(value);
01368   }
01369 };
01370 
01371 // By default, print C string as pointers to be safe, as we don't know
01372 // whether they actually point to a NUL-terminated string.
01373 
01374 #define GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(CharType)                \
01375   template <typename OtherOperand>                                      \
01376   class FormatForComparison<CharType*, OtherOperand> {                  \
01377    public:                                                              \
01378     static ::std::string Format(CharType* value) {                      \
01379       return ::testing::PrintToString(static_cast<const void*>(value)); \
01380     }                                                                   \
01381   }
01382 
01383 GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(char);
01384 GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const char);
01385 GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(wchar_t);
01386 GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const wchar_t);
01387 
01388 #undef GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_
01389 
01390 // If a C string is compared with an STL string object, we know it's meant
01391 // to point to a NUL-terminated string, and thus can print it as a string.
01392 
01393 #define GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(CharType, OtherStringType) \
01394   template <>                                                           \
01395   class FormatForComparison<CharType*, OtherStringType> {               \
01396    public:                                                              \
01397     static ::std::string Format(CharType* value) {                      \
01398       return ::testing::PrintToString(value);                           \
01399     }                                                                   \
01400   }
01401 
01402 GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char, ::std::string);
01403 GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char, ::std::string);
01404 
01405 #if GTEST_HAS_GLOBAL_STRING
01406 GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char, ::string);
01407 GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char, ::string);
01408 #endif
01409 
01410 #if GTEST_HAS_GLOBAL_WSTRING
01411 GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(wchar_t, ::wstring);
01412 GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const wchar_t, ::wstring);
01413 #endif
01414 
01415 #if GTEST_HAS_STD_WSTRING
01416 GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(wchar_t, ::std::wstring);
01417 GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const wchar_t, ::std::wstring);
01418 #endif
01419 
01420 #undef GTEST_IMPL_FORMAT_C_STRING_AS_STRING_
01421 
01422 // Formats a comparison assertion (e.g. ASSERT_EQ, EXPECT_LT, and etc)
01423 // operand to be used in a failure message.  The type (but not value)
01424 // of the other operand may affect the format.  This allows us to
01425 // print a char* as a raw pointer when it is compared against another
01426 // char* or void*, and print it as a C string when it is compared
01427 // against an std::string object, for example.
01428 //
01429 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
01430 template <typename T1, typename T2>
01431 std::string FormatForComparisonFailureMessage(
01432     const T1& value, const T2& /* other_operand */) {
01433   return FormatForComparison<T1, T2>::Format(value);
01434 }
01435 
01436 // The helper function for {ASSERT|EXPECT}_EQ.
01437 template <typename T1, typename T2>
01438 AssertionResult CmpHelperEQ(const char* expected_expression,
01439                             const char* actual_expression,
01440                             const T1& expected,
01441                             const T2& actual) {
01442 #ifdef _MSC_VER
01443 # pragma warning(push)          // Saves the current warning state.
01444 # pragma warning(disable:4389)  // Temporarily disables warning on
01445                                 // signed/unsigned mismatch.
01446 #endif
01447 
01448   if (expected == actual) {
01449     return AssertionSuccess();
01450   }
01451 
01452 #ifdef _MSC_VER
01453 # pragma warning(pop)          // Restores the warning state.
01454 #endif
01455 
01456   return EqFailure(expected_expression,
01457                    actual_expression,
01458                    FormatForComparisonFailureMessage(expected, actual),
01459                    FormatForComparisonFailureMessage(actual, expected),
01460                    false);
01461 }
01462 
01463 // With this overloaded version, we allow anonymous enums to be used
01464 // in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous enums
01465 // can be implicitly cast to BiggestInt.
01466 GTEST_API_ AssertionResult CmpHelperEQ(const char* expected_expression,
01467                                        const char* actual_expression,
01468                                        BiggestInt expected,
01469                                        BiggestInt actual);
01470 
01471 // The helper class for {ASSERT|EXPECT}_EQ.  The template argument
01472 // lhs_is_null_literal is true iff the first argument to ASSERT_EQ()
01473 // is a null pointer literal.  The following default implementation is
01474 // for lhs_is_null_literal being false.
01475 template <bool lhs_is_null_literal>
01476 class EqHelper {
01477  public:
01478   // This templatized version is for the general case.
01479   template <typename T1, typename T2>
01480   static AssertionResult Compare(const char* expected_expression,
01481                                  const char* actual_expression,
01482                                  const T1& expected,
01483                                  const T2& actual) {
01484     return CmpHelperEQ(expected_expression, actual_expression, expected,
01485                        actual);
01486   }
01487 
01488   // With this overloaded version, we allow anonymous enums to be used
01489   // in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous
01490   // enums can be implicitly cast to BiggestInt.
01491   //
01492   // Even though its body looks the same as the above version, we
01493   // cannot merge the two, as it will make anonymous enums unhappy.
01494   static AssertionResult Compare(const char* expected_expression,
01495                                  const char* actual_expression,
01496                                  BiggestInt expected,
01497                                  BiggestInt actual) {
01498     return CmpHelperEQ(expected_expression, actual_expression, expected,
01499                        actual);
01500   }
01501 };
01502 
01503 // This specialization is used when the first argument to ASSERT_EQ()
01504 // is a null pointer literal, like NULL, false, or 0.
01505 template <>
01506 class EqHelper<true> {
01507  public:
01508   // We define two overloaded versions of Compare().  The first
01509   // version will be picked when the second argument to ASSERT_EQ() is
01510   // NOT a pointer, e.g. ASSERT_EQ(0, AnIntFunction()) or
01511   // EXPECT_EQ(false, a_bool).
01512   template <typename T1, typename T2>
01513   static AssertionResult Compare(
01514       const char* expected_expression,
01515       const char* actual_expression,
01516       const T1& expected,
01517       const T2& actual,
01518       // The following line prevents this overload from being considered if T2
01519       // is not a pointer type.  We need this because ASSERT_EQ(NULL, my_ptr)
01520       // expands to Compare("", "", NULL, my_ptr), which requires a conversion
01521       // to match the Secret* in the other overload, which would otherwise make
01522       // this template match better.
01523       typename EnableIf<!is_pointer<T2>::value>::type* = 0) {
01524     return CmpHelperEQ(expected_expression, actual_expression, expected,
01525                        actual);
01526   }
01527 
01528   // This version will be picked when the second argument to ASSERT_EQ() is a
01529   // pointer, e.g. ASSERT_EQ(NULL, a_pointer).
01530   template <typename T>
01531   static AssertionResult Compare(
01532       const char* expected_expression,
01533       const char* actual_expression,
01534       // We used to have a second template parameter instead of Secret*.  That
01535       // template parameter would deduce to 'long', making this a better match
01536       // than the first overload even without the first overload's EnableIf.
01537       // Unfortunately, gcc with -Wconversion-null warns when "passing NULL to
01538       // non-pointer argument" (even a deduced integral argument), so the old
01539       // implementation caused warnings in user code.
01540       Secret* /* expected (NULL) */,
01541       T* actual) {
01542     // We already know that 'expected' is a null pointer.
01543     return CmpHelperEQ(expected_expression, actual_expression,
01544                        static_cast<T*>(NULL), actual);
01545   }
01546 };
01547 
01548 // A macro for implementing the helper functions needed to implement
01549 // ASSERT_?? and EXPECT_??.  It is here just to avoid copy-and-paste
01550 // of similar code.
01551 //
01552 // For each templatized helper function, we also define an overloaded
01553 // version for BiggestInt in order to reduce code bloat and allow
01554 // anonymous enums to be used with {ASSERT|EXPECT}_?? when compiled
01555 // with gcc 4.
01556 //
01557 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
01558 #define GTEST_IMPL_CMP_HELPER_(op_name, op)\
01559 template <typename T1, typename T2>\
01560 AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \
01561                                    const T1& val1, const T2& val2) {\
01562   if (val1 op val2) {\
01563     return AssertionSuccess();\
01564   } else {\
01565     return AssertionFailure() \
01566         << "Expected: (" << expr1 << ") " #op " (" << expr2\
01567         << "), actual: " << FormatForComparisonFailureMessage(val1, val2)\
01568         << " vs " << FormatForComparisonFailureMessage(val2, val1);\
01569   }\
01570 }\
01571 GTEST_API_ AssertionResult CmpHelper##op_name(\
01572     const char* expr1, const char* expr2, BiggestInt val1, BiggestInt val2)
01573 
01574 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
01575 
01576 // Implements the helper function for {ASSERT|EXPECT}_NE
01577 GTEST_IMPL_CMP_HELPER_(NE, !=);
01578 // Implements the helper function for {ASSERT|EXPECT}_LE
01579 GTEST_IMPL_CMP_HELPER_(LE, <=);
01580 // Implements the helper function for {ASSERT|EXPECT}_LT
01581 GTEST_IMPL_CMP_HELPER_(LT, <);
01582 // Implements the helper function for {ASSERT|EXPECT}_GE
01583 GTEST_IMPL_CMP_HELPER_(GE, >=);
01584 // Implements the helper function for {ASSERT|EXPECT}_GT
01585 GTEST_IMPL_CMP_HELPER_(GT, >);
01586 
01587 #undef GTEST_IMPL_CMP_HELPER_
01588 
01589 // The helper function for {ASSERT|EXPECT}_STREQ.
01590 //
01591 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
01592 GTEST_API_ AssertionResult CmpHelperSTREQ(const char* expected_expression,
01593                                           const char* actual_expression,
01594                                           const char* expected,
01595                                           const char* actual);
01596 
01597 // The helper function for {ASSERT|EXPECT}_STRCASEEQ.
01598 //
01599 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
01600 GTEST_API_ AssertionResult CmpHelperSTRCASEEQ(const char* expected_expression,
01601                                               const char* actual_expression,
01602                                               const char* expected,
01603                                               const char* actual);
01604 
01605 // The helper function for {ASSERT|EXPECT}_STRNE.
01606 //
01607 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
01608 GTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression,
01609                                           const char* s2_expression,
01610                                           const char* s1,
01611                                           const char* s2);
01612 
01613 // The helper function for {ASSERT|EXPECT}_STRCASENE.
01614 //
01615 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
01616 GTEST_API_ AssertionResult CmpHelperSTRCASENE(const char* s1_expression,
01617                                               const char* s2_expression,
01618                                               const char* s1,
01619                                               const char* s2);
01620 
01621 
01622 // Helper function for *_STREQ on wide strings.
01623 //
01624 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
01625 GTEST_API_ AssertionResult CmpHelperSTREQ(const char* expected_expression,
01626                                           const char* actual_expression,
01627                                           const wchar_t* expected,
01628                                           const wchar_t* actual);
01629 
01630 // Helper function for *_STRNE on wide strings.
01631 //
01632 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
01633 GTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression,
01634                                           const char* s2_expression,
01635                                           const wchar_t* s1,
01636                                           const wchar_t* s2);
01637 
01638 }  // namespace internal
01639 
01640 // IsSubstring() and IsNotSubstring() are intended to be used as the
01641 // first argument to {EXPECT,ASSERT}_PRED_FORMAT2(), not by
01642 // themselves.  They check whether needle is a substring of haystack
01643 // (NULL is considered a substring of itself only), and return an
01644 // appropriate error message when they fail.
01645 //
01646 // The {needle,haystack}_expr arguments are the stringified
01647 // expressions that generated the two real arguments.
01648 GTEST_API_ AssertionResult IsSubstring(
01649     const char* needle_expr, const char* haystack_expr,
01650     const char* needle, const char* haystack);
01651 GTEST_API_ AssertionResult IsSubstring(
01652     const char* needle_expr, const char* haystack_expr,
01653     const wchar_t* needle, const wchar_t* haystack);
01654 GTEST_API_ AssertionResult IsNotSubstring(
01655     const char* needle_expr, const char* haystack_expr,
01656     const char* needle, const char* haystack);
01657 GTEST_API_ AssertionResult IsNotSubstring(
01658     const char* needle_expr, const char* haystack_expr,
01659     const wchar_t* needle, const wchar_t* haystack);
01660 GTEST_API_ AssertionResult IsSubstring(
01661     const char* needle_expr, const char* haystack_expr,
01662     const ::std::string& needle, const ::std::string& haystack);
01663 GTEST_API_ AssertionResult IsNotSubstring(
01664     const char* needle_expr, const char* haystack_expr,
01665     const ::std::string& needle, const ::std::string& haystack);
01666 
01667 #if GTEST_HAS_STD_WSTRING
01668 GTEST_API_ AssertionResult IsSubstring(
01669     const char* needle_expr, const char* haystack_expr,
01670     const ::std::wstring& needle, const ::std::wstring& haystack);
01671 GTEST_API_ AssertionResult IsNotSubstring(
01672     const char* needle_expr, const char* haystack_expr,
01673     const ::std::wstring& needle, const ::std::wstring& haystack);
01674 #endif  // GTEST_HAS_STD_WSTRING
01675 
01676 namespace internal {
01677 
01678 // Helper template function for comparing floating-points.
01679 //
01680 // Template parameter:
01681 //
01682 //   RawType: the raw floating-point type (either float or double)
01683 //
01684 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
01685 template <typename RawType>
01686 AssertionResult CmpHelperFloatingPointEQ(const char* expected_expression,
01687                                          const char* actual_expression,
01688                                          RawType expected,
01689                                          RawType actual) {
01690   const FloatingPoint<RawType> lhs(expected), rhs(actual);
01691 
01692   if (lhs.AlmostEquals(rhs)) {
01693     return AssertionSuccess();
01694   }
01695 
01696   ::std::stringstream expected_ss;
01697   expected_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
01698               << expected;
01699 
01700   ::std::stringstream actual_ss;
01701   actual_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
01702             << actual;
01703 
01704   return EqFailure(expected_expression,
01705                    actual_expression,
01706                    StringStreamToString(&expected_ss),
01707                    StringStreamToString(&actual_ss),
01708                    false);
01709 }
01710 
01711 // Helper function for implementing ASSERT_NEAR.
01712 //
01713 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
01714 GTEST_API_ AssertionResult DoubleNearPredFormat(const char* expr1,
01715                                                 const char* expr2,
01716                                                 const char* abs_error_expr,
01717                                                 double val1,
01718                                                 double val2,
01719                                                 double abs_error);
01720 
01721 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
01722 // A class that enables one to stream messages to assertion macros
01723 class GTEST_API_ AssertHelper {
01724  public:
01725   // Constructor.
01726   AssertHelper(TestPartResult::Type type,
01727                const char* file,
01728                int line,
01729                const char* message);
01730   ~AssertHelper();
01731 
01732   // Message assignment is a semantic trick to enable assertion
01733   // streaming; see the GTEST_MESSAGE_ macro below.
01734   void operator=(const Message& message) const;
01735 
01736  private:
01737   // We put our data in a struct so that the size of the AssertHelper class can
01738   // be as small as possible.  This is important because gcc is incapable of
01739   // re-using stack space even for temporary variables, so every EXPECT_EQ
01740   // reserves stack space for another AssertHelper.
01741   struct AssertHelperData {
01742     AssertHelperData(TestPartResult::Type t,
01743                      const char* srcfile,
01744                      int line_num,
01745                      const char* msg)
01746         : type(t), file(srcfile), line(line_num), message(msg) { }
01747 
01748     TestPartResult::Type const type;
01749     const char* const file;
01750     int const line;
01751     std::string const message;
01752 
01753    private:
01754     GTEST_DISALLOW_COPY_AND_ASSIGN_(AssertHelperData);
01755   };
01756 
01757   AssertHelperData* const data_;
01758 
01759   GTEST_DISALLOW_COPY_AND_ASSIGN_(AssertHelper);
01760 };
01761 
01762 }  // namespace internal
01763 
01764 #if GTEST_HAS_PARAM_TEST
01765 // The pure interface class that all value-parameterized tests inherit from.
01766 // A value-parameterized class must inherit from both ::testing::Test and
01767 // ::testing::WithParamInterface. In most cases that just means inheriting
01768 // from ::testing::TestWithParam, but more complicated test hierarchies
01769 // may need to inherit from Test and WithParamInterface at different levels.
01770 //
01771 // This interface has support for accessing the test parameter value via
01772 // the GetParam() method.
01773 //
01774 // Use it with one of the parameter generator defining functions, like Range(),
01775 // Values(), ValuesIn(), Bool(), and Combine().
01776 //
01777 // class FooTest : public ::testing::TestWithParam<int> {
01778 //  protected:
01779 //   FooTest() {
01780 //     // Can use GetParam() here.
01781 //   }
01782 //   virtual ~FooTest() {
01783 //     // Can use GetParam() here.
01784 //   }
01785 //   virtual void SetUp() {
01786 //     // Can use GetParam() here.
01787 //   }
01788 //   virtual void TearDown {
01789 //     // Can use GetParam() here.
01790 //   }
01791 // };
01792 // TEST_P(FooTest, DoesBar) {
01793 //   // Can use GetParam() method here.
01794 //   Foo foo;
01795 //   ASSERT_TRUE(foo.DoesBar(GetParam()));
01796 // }
01797 // INSTANTIATE_TEST_CASE_P(OneToTenRange, FooTest, ::testing::Range(1, 10));
01798 
01799 template <typename T>
01800 class WithParamInterface {
01801  public:
01802   typedef T ParamType;
01803   virtual ~WithParamInterface() {}
01804 
01805   // The current parameter value. Is also available in the test fixture's
01806   // constructor. This member function is non-static, even though it only
01807   // references static data, to reduce the opportunity for incorrect uses
01808   // like writing 'WithParamInterface<bool>::GetParam()' for a test that
01809   // uses a fixture whose parameter type is int.
01810   const ParamType& GetParam() const {
01811     GTEST_CHECK_(parameter_ != NULL)
01812         << "GetParam() can only be called inside a value-parameterized test "
01813         << "-- did you intend to write TEST_P instead of TEST_F?";
01814     return *parameter_;
01815   }
01816 
01817  private:
01818   // Sets parameter value. The caller is responsible for making sure the value
01819   // remains alive and unchanged throughout the current test.
01820   static void SetParam(const ParamType* parameter) {
01821     parameter_ = parameter;
01822   }
01823 
01824   // Static value used for accessing parameter during a test lifetime.
01825   static const ParamType* parameter_;
01826 
01827   // TestClass must be a subclass of WithParamInterface<T> and Test.
01828   template <class TestClass> friend class internal::ParameterizedTestFactory;
01829 };
01830 
01831 template <typename T>
01832 const T* WithParamInterface<T>::parameter_ = NULL;
01833 
01834 // Most value-parameterized classes can ignore the existence of
01835 // WithParamInterface, and can just inherit from ::testing::TestWithParam.
01836 
01837 template <typename T>
01838 class TestWithParam : public Test, public WithParamInterface<T> {
01839 };
01840 
01841 #endif  // GTEST_HAS_PARAM_TEST
01842 
01843 // Macros for indicating success/failure in test code.
01844 
01845 // ADD_FAILURE unconditionally adds a failure to the current test.
01846 // SUCCEED generates a success - it doesn't automatically make the
01847 // current test successful, as a test is only successful when it has
01848 // no failure.
01849 //
01850 // EXPECT_* verifies that a certain condition is satisfied.  If not,
01851 // it behaves like ADD_FAILURE.  In particular:
01852 //
01853 //   EXPECT_TRUE  verifies that a Boolean condition is true.
01854 //   EXPECT_FALSE verifies that a Boolean condition is false.
01855 //
01856 // FAIL and ASSERT_* are similar to ADD_FAILURE and EXPECT_*, except
01857 // that they will also abort the current function on failure.  People
01858 // usually want the fail-fast behavior of FAIL and ASSERT_*, but those
01859 // writing data-driven tests often find themselves using ADD_FAILURE
01860 // and EXPECT_* more.
01861 
01862 // Generates a nonfatal failure with a generic message.
01863 #define ADD_FAILURE() GTEST_NONFATAL_FAILURE_("Failed")
01864 
01865 // Generates a nonfatal failure at the given source file location with
01866 // a generic message.
01867 #define ADD_FAILURE_AT(file, line) \
01868   GTEST_MESSAGE_AT_(file, line, "Failed", \
01869                     ::testing::TestPartResult::kNonFatalFailure)
01870 
01871 // Generates a fatal failure with a generic message.
01872 #define GTEST_FAIL() GTEST_FATAL_FAILURE_("Failed")
01873 
01874 // Define this macro to 1 to omit the definition of FAIL(), which is a
01875 // generic name and clashes with some other libraries.
01876 #if !GTEST_DONT_DEFINE_FAIL
01877 # define FAIL() GTEST_FAIL()
01878 #endif
01879 
01880 // Generates a success with a generic message.
01881 #define GTEST_SUCCEED() GTEST_SUCCESS_("Succeeded")
01882 
01883 // Define this macro to 1 to omit the definition of SUCCEED(), which
01884 // is a generic name and clashes with some other libraries.
01885 #if !GTEST_DONT_DEFINE_SUCCEED
01886 # define SUCCEED() GTEST_SUCCEED()
01887 #endif
01888 
01889 // Macros for testing exceptions.
01890 //
01891 //    * {ASSERT|EXPECT}_THROW(statement, expected_exception):
01892 //         Tests that the statement throws the expected exception.
01893 //    * {ASSERT|EXPECT}_NO_THROW(statement):
01894 //         Tests that the statement doesn't throw any exception.
01895 //    * {ASSERT|EXPECT}_ANY_THROW(statement):
01896 //         Tests that the statement throws an exception.
01897 
01898 #define EXPECT_THROW(statement, expected_exception) \
01899   GTEST_TEST_THROW_(statement, expected_exception, GTEST_NONFATAL_FAILURE_)
01900 #define EXPECT_NO_THROW(statement) \
01901   GTEST_TEST_NO_THROW_(statement, GTEST_NONFATAL_FAILURE_)
01902 #define EXPECT_ANY_THROW(statement) \
01903   GTEST_TEST_ANY_THROW_(statement, GTEST_NONFATAL_FAILURE_)
01904 #define ASSERT_THROW(statement, expected_exception) \
01905   GTEST_TEST_THROW_(statement, expected_exception, GTEST_FATAL_FAILURE_)
01906 #define ASSERT_NO_THROW(statement) \
01907   GTEST_TEST_NO_THROW_(statement, GTEST_FATAL_FAILURE_)
01908 #define ASSERT_ANY_THROW(statement) \
01909   GTEST_TEST_ANY_THROW_(statement, GTEST_FATAL_FAILURE_)
01910 
01911 // Boolean assertions. Condition can be either a Boolean expression or an
01912 // AssertionResult. For more information on how to use AssertionResult with
01913 // these macros see comments on that class.
01914 #define EXPECT_TRUE(condition) \
01915   GTEST_TEST_BOOLEAN_(condition, #condition, false, true, \
01916                       GTEST_NONFATAL_FAILURE_)
01917 #define EXPECT_FALSE(condition) \
01918   GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \
01919                       GTEST_NONFATAL_FAILURE_)
01920 #define ASSERT_TRUE(condition) \
01921   GTEST_TEST_BOOLEAN_(condition, #condition, false, true, \
01922                       GTEST_FATAL_FAILURE_)
01923 #define ASSERT_FALSE(condition) \
01924   GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \
01925                       GTEST_FATAL_FAILURE_)
01926 
01927 // Includes the auto-generated header that implements a family of
01928 // generic predicate assertion macros.
01929 #include "gtest/gtest_pred_impl.h"
01930 
01931 // Macros for testing equalities and inequalities.
01932 //
01933 //    * {ASSERT|EXPECT}_EQ(expected, actual): Tests that expected == actual
01934 //    * {ASSERT|EXPECT}_NE(v1, v2):           Tests that v1 != v2
01935 //    * {ASSERT|EXPECT}_LT(v1, v2):           Tests that v1 < v2
01936 //    * {ASSERT|EXPECT}_LE(v1, v2):           Tests that v1 <= v2
01937 //    * {ASSERT|EXPECT}_GT(v1, v2):           Tests that v1 > v2
01938 //    * {ASSERT|EXPECT}_GE(v1, v2):           Tests that v1 >= v2
01939 //
01940 // When they are not, Google Test prints both the tested expressions and
01941 // their actual values.  The values must be compatible built-in types,
01942 // or you will get a compiler error.  By "compatible" we mean that the
01943 // values can be compared by the respective operator.
01944 //
01945 // Note:
01946 //
01947 //   1. It is possible to make a user-defined type work with
01948 //   {ASSERT|EXPECT}_??(), but that requires overloading the
01949 //   comparison operators and is thus discouraged by the Google C++
01950 //   Usage Guide.  Therefore, you are advised to use the
01951 //   {ASSERT|EXPECT}_TRUE() macro to assert that two objects are
01952 //   equal.
01953 //
01954 //   2. The {ASSERT|EXPECT}_??() macros do pointer comparisons on
01955 //   pointers (in particular, C strings).  Therefore, if you use it
01956 //   with two C strings, you are testing how their locations in memory
01957 //   are related, not how their content is related.  To compare two C
01958 //   strings by content, use {ASSERT|EXPECT}_STR*().
01959 //
01960 //   3. {ASSERT|EXPECT}_EQ(expected, actual) is preferred to
01961 //   {ASSERT|EXPECT}_TRUE(expected == actual), as the former tells you
01962 //   what the actual value is when it fails, and similarly for the
01963 //   other comparisons.
01964 //
01965 //   4. Do not depend on the order in which {ASSERT|EXPECT}_??()
01966 //   evaluate their arguments, which is undefined.
01967 //
01968 //   5. These macros evaluate their arguments exactly once.
01969 //
01970 // Examples:
01971 //
01972 //   EXPECT_NE(5, Foo());
01973 //   EXPECT_EQ(NULL, a_pointer);
01974 //   ASSERT_LT(i, array_size);
01975 //   ASSERT_GT(records.size(), 0) << "There is no record left.";
01976 
01977 #define EXPECT_EQ(expected, actual) \
01978   EXPECT_PRED_FORMAT2(::testing::internal:: \
01979                       EqHelper<GTEST_IS_NULL_LITERAL_(expected)>::Compare, \
01980                       expected, actual)
01981 #define EXPECT_NE(expected, actual) \
01982   EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperNE, expected, actual)
01983 #define EXPECT_LE(val1, val2) \
01984   EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2)
01985 #define EXPECT_LT(val1, val2) \
01986   EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2)
01987 #define EXPECT_GE(val1, val2) \
01988   EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2)
01989 #define EXPECT_GT(val1, val2) \
01990   EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2)
01991 
01992 #define GTEST_ASSERT_EQ(expected, actual) \
01993   ASSERT_PRED_FORMAT2(::testing::internal:: \
01994                       EqHelper<GTEST_IS_NULL_LITERAL_(expected)>::Compare, \
01995                       expected, actual)
01996 #define GTEST_ASSERT_NE(val1, val2) \
01997   ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2)
01998 #define GTEST_ASSERT_LE(val1, val2) \
01999   ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2)
02000 #define GTEST_ASSERT_LT(val1, val2) \
02001   ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2)
02002 #define GTEST_ASSERT_GE(val1, val2) \
02003   ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2)
02004 #define GTEST_ASSERT_GT(val1, val2) \
02005   ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2)
02006 
02007 // Define macro GTEST_DONT_DEFINE_ASSERT_XY to 1 to omit the definition of
02008 // ASSERT_XY(), which clashes with some users' own code.
02009 
02010 #if !GTEST_DONT_DEFINE_ASSERT_EQ
02011 # define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2)
02012 #endif
02013 
02014 #if !GTEST_DONT_DEFINE_ASSERT_NE
02015 # define ASSERT_NE(val1, val2) GTEST_ASSERT_NE(val1, val2)
02016 #endif
02017 
02018 #if !GTEST_DONT_DEFINE_ASSERT_LE
02019 # define ASSERT_LE(val1, val2) GTEST_ASSERT_LE(val1, val2)
02020 #endif
02021 
02022 #if !GTEST_DONT_DEFINE_ASSERT_LT
02023 # define ASSERT_LT(val1, val2) GTEST_ASSERT_LT(val1, val2)
02024 #endif
02025 
02026 #if !GTEST_DONT_DEFINE_ASSERT_GE
02027 # define ASSERT_GE(val1, val2) GTEST_ASSERT_GE(val1, val2)
02028 #endif
02029 
02030 #if !GTEST_DONT_DEFINE_ASSERT_GT
02031 # define ASSERT_GT(val1, val2) GTEST_ASSERT_GT(val1, val2)
02032 #endif
02033 
02034 // C-string Comparisons.  All tests treat NULL and any non-NULL string
02035 // as different.  Two NULLs are equal.
02036 //
02037 //    * {ASSERT|EXPECT}_STREQ(s1, s2):     Tests that s1 == s2
02038 //    * {ASSERT|EXPECT}_STRNE(s1, s2):     Tests that s1 != s2
02039 //    * {ASSERT|EXPECT}_STRCASEEQ(s1, s2): Tests that s1 == s2, ignoring case
02040 //    * {ASSERT|EXPECT}_STRCASENE(s1, s2): Tests that s1 != s2, ignoring case
02041 //
02042 // For wide or narrow string objects, you can use the
02043 // {ASSERT|EXPECT}_??() macros.
02044 //
02045 // Don't depend on the order in which the arguments are evaluated,
02046 // which is undefined.
02047 //
02048 // These macros evaluate their arguments exactly once.
02049 
02050 #define EXPECT_STREQ(expected, actual) \
02051   EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, expected, actual)
02052 #define EXPECT_STRNE(s1, s2) \
02053   EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2)
02054 #define EXPECT_STRCASEEQ(expected, actual) \
02055   EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, expected, actual)
02056 #define EXPECT_STRCASENE(s1, s2)\
02057   EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2)
02058 
02059 #define ASSERT_STREQ(expected, actual) \
02060   ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, expected, actual)
02061 #define ASSERT_STRNE(s1, s2) \
02062   ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2)
02063 #define ASSERT_STRCASEEQ(expected, actual) \
02064   ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, expected, actual)
02065 #define ASSERT_STRCASENE(s1, s2)\
02066   ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2)
02067 
02068 // Macros for comparing floating-point numbers.
02069 //
02070 //    * {ASSERT|EXPECT}_FLOAT_EQ(expected, actual):
02071 //         Tests that two float values are almost equal.
02072 //    * {ASSERT|EXPECT}_DOUBLE_EQ(expected, actual):
02073 //         Tests that two double values are almost equal.
02074 //    * {ASSERT|EXPECT}_NEAR(v1, v2, abs_error):
02075 //         Tests that v1 and v2 are within the given distance to each other.
02076 //
02077 // Google Test uses ULP-based comparison to automatically pick a default
02078 // error bound that is appropriate for the operands.  See the
02079 // FloatingPoint template class in gtest-internal.h if you are
02080 // interested in the implementation details.
02081 
02082 #define EXPECT_FLOAT_EQ(expected, actual)\
02083   EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \
02084                       expected, actual)
02085 
02086 #define EXPECT_DOUBLE_EQ(expected, actual)\
02087   EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \
02088                       expected, actual)
02089 
02090 #define ASSERT_FLOAT_EQ(expected, actual)\
02091   ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \
02092                       expected, actual)
02093 
02094 #define ASSERT_DOUBLE_EQ(expected, actual)\
02095   ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \
02096                       expected, actual)
02097 
02098 #define EXPECT_NEAR(val1, val2, abs_error)\
02099   EXPECT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, \
02100                       val1, val2, abs_error)
02101 
02102 #define ASSERT_NEAR(val1, val2, abs_error)\
02103   ASSERT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, \
02104                       val1, val2, abs_error)
02105 
02106 // These predicate format functions work on floating-point values, and
02107 // can be used in {ASSERT|EXPECT}_PRED_FORMAT2*(), e.g.
02108 //
02109 //   EXPECT_PRED_FORMAT2(testing::DoubleLE, Foo(), 5.0);
02110 
02111 // Asserts that val1 is less than, or almost equal to, val2.  Fails
02112 // otherwise.  In particular, it fails if either val1 or val2 is NaN.
02113 GTEST_API_ AssertionResult FloatLE(const char* expr1, const char* expr2,
02114                                    float val1, float val2);
02115 GTEST_API_ AssertionResult DoubleLE(const char* expr1, const char* expr2,
02116                                     double val1, double val2);
02117 
02118 
02119 #if GTEST_OS_WINDOWS
02120 
02121 // Macros that test for HRESULT failure and success, these are only useful
02122 // on Windows, and rely on Windows SDK macros and APIs to compile.
02123 //
02124 //    * {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED}(expr)
02125 //
02126 // When expr unexpectedly fails or succeeds, Google Test prints the
02127 // expected result and the actual result with both a human-readable
02128 // string representation of the error, if available, as well as the
02129 // hex result code.
02130 # define EXPECT_HRESULT_SUCCEEDED(expr) \
02131     EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr))
02132 
02133 # define ASSERT_HRESULT_SUCCEEDED(expr) \
02134     ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr))
02135 
02136 # define EXPECT_HRESULT_FAILED(expr) \
02137     EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr))
02138 
02139 # define ASSERT_HRESULT_FAILED(expr) \
02140     ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr))
02141 
02142 #endif  // GTEST_OS_WINDOWS
02143 
02144 // Macros that execute statement and check that it doesn't generate new fatal
02145 // failures in the current thread.
02146 //
02147 //   * {ASSERT|EXPECT}_NO_FATAL_FAILURE(statement);
02148 //
02149 // Examples:
02150 //
02151 //   EXPECT_NO_FATAL_FAILURE(Process());
02152 //   ASSERT_NO_FATAL_FAILURE(Process()) << "Process() failed";
02153 //
02154 #define ASSERT_NO_FATAL_FAILURE(statement) \
02155     GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_FATAL_FAILURE_)
02156 #define EXPECT_NO_FATAL_FAILURE(statement) \
02157     GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_NONFATAL_FAILURE_)
02158 
02159 // Causes a trace (including the source file path, the current line
02160 // number, and the given message) to be included in every test failure
02161 // message generated by code in the current scope.  The effect is
02162 // undone when the control leaves the current scope.
02163 //
02164 // The message argument can be anything streamable to std::ostream.
02165 //
02166 // In the implementation, we include the current line number as part
02167 // of the dummy variable name, thus allowing multiple SCOPED_TRACE()s
02168 // to appear in the same block - as long as they are on different
02169 // lines.
02170 #define SCOPED_TRACE(message) \
02171   ::testing::internal::ScopedTrace GTEST_CONCAT_TOKEN_(gtest_trace_, __LINE__)(\
02172     __FILE__, __LINE__, ::testing::Message() << (message))
02173 
02174 // Compile-time assertion for type equality.
02175 // StaticAssertTypeEq<type1, type2>() compiles iff type1 and type2 are
02176 // the same type.  The value it returns is not interesting.
02177 //
02178 // Instead of making StaticAssertTypeEq a class template, we make it a
02179 // function template that invokes a helper class template.  This
02180 // prevents a user from misusing StaticAssertTypeEq<T1, T2> by
02181 // defining objects of that type.
02182 //
02183 // CAVEAT:
02184 //
02185 // When used inside a method of a class template,
02186 // StaticAssertTypeEq<T1, T2>() is effective ONLY IF the method is
02187 // instantiated.  For example, given:
02188 //
02189 //   template <typename T> class Foo {
02190 //    public:
02191 //     void Bar() { testing::StaticAssertTypeEq<int, T>(); }
02192 //   };
02193 //
02194 // the code:
02195 //
02196 //   void Test1() { Foo<bool> foo; }
02197 //
02198 // will NOT generate a compiler error, as Foo<bool>::Bar() is never
02199 // actually instantiated.  Instead, you need:
02200 //
02201 //   void Test2() { Foo<bool> foo; foo.Bar(); }
02202 //
02203 // to cause a compiler error.
02204 template <typename T1, typename T2>
02205 bool StaticAssertTypeEq() {
02206   (void)internal::StaticAssertTypeEqHelper<T1, T2>();
02207   return true;
02208 }
02209 
02210 // Defines a test.
02211 //
02212 // The first parameter is the name of the test case, and the second
02213 // parameter is the name of the test within the test case.
02214 //
02215 // The convention is to end the test case name with "Test".  For
02216 // example, a test case for the Foo class can be named FooTest.
02217 //
02218 // The user should put his test code between braces after using this
02219 // macro.  Example:
02220 //
02221 //   TEST(FooTest, InitializesCorrectly) {
02222 //     Foo foo;
02223 //     EXPECT_TRUE(foo.StatusIsOK());
02224 //   }
02225 
02226 // Note that we call GetTestTypeId() instead of GetTypeId<
02227 // ::testing::Test>() here to get the type ID of testing::Test.  This
02228 // is to work around a suspected linker bug when using Google Test as
02229 // a framework on Mac OS X.  The bug causes GetTypeId<
02230 // ::testing::Test>() to return different values depending on whether
02231 // the call is from the Google Test framework itself or from user test
02232 // code.  GetTestTypeId() is guaranteed to always return the same
02233 // value, as it always calls GetTypeId<>() from the Google Test
02234 // framework.
02235 #define GTEST_TEST(test_case_name, test_name)\
02236   GTEST_TEST_(test_case_name, test_name, \
02237               ::testing::Test, ::testing::internal::GetTestTypeId())
02238 
02239 // Define this macro to 1 to omit the definition of TEST(), which
02240 // is a generic name and clashes with some other libraries.
02241 #if !GTEST_DONT_DEFINE_TEST
02242 # define TEST(test_case_name, test_name) GTEST_TEST(test_case_name, test_name)
02243 #endif
02244 
02245 // Defines a test that uses a test fixture.
02246 //
02247 // The first parameter is the name of the test fixture class, which
02248 // also doubles as the test case name.  The second parameter is the
02249 // name of the test within the test case.
02250 //
02251 // A test fixture class must be declared earlier.  The user should put
02252 // his test code between braces after using this macro.  Example:
02253 //
02254 //   class FooTest : public testing::Test {
02255 //    protected:
02256 //     virtual void SetUp() { b_.AddElement(3); }
02257 //
02258 //     Foo a_;
02259 //     Foo b_;
02260 //   };
02261 //
02262 //   TEST_F(FooTest, InitializesCorrectly) {
02263 //     EXPECT_TRUE(a_.StatusIsOK());
02264 //   }
02265 //
02266 //   TEST_F(FooTest, ReturnsElementCountCorrectly) {
02267 //     EXPECT_EQ(0, a_.size());
02268 //     EXPECT_EQ(1, b_.size());
02269 //   }
02270 
02271 #define TEST_F(test_fixture, test_name)\
02272   GTEST_TEST_(test_fixture, test_name, test_fixture, \
02273               ::testing::internal::GetTypeId<test_fixture>())
02274 
02275 }  // namespace testing
02276 
02277 // Use this function in main() to run all tests.  It returns 0 if all
02278 // tests are successful, or 1 otherwise.
02279 //
02280 // RUN_ALL_TESTS() should be invoked after the command line has been
02281 // parsed by InitGoogleTest().
02282 //
02283 // This function was formerly a macro; thus, it is in the global
02284 // namespace and has an all-caps name.
02285 int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_;
02286 
02287 inline int RUN_ALL_TESTS() {
02288   return ::testing::UnitTest::GetInstance()->Run();
02289 }
02290 
02291 #endif  // GTEST_INCLUDE_GTEST_GTEST_H_