gtest.h
Go to the documentation of this file.
1 // Copyright 2005, Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 // * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // Author: wan@google.com (Zhanyong Wan)
31 //
32 // The Google C++ Testing Framework (Google Test)
33 //
34 // This header file defines the public API for Google Test. It should be
35 // included by any test program that uses Google Test.
36 //
37 // IMPORTANT NOTE: Due to limitation of the C++ language, we have to
38 // leave some internal implementation details in this header file.
39 // They are clearly marked by comments like this:
40 //
41 // // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
42 //
43 // Such code is NOT meant to be used by a user directly, and is subject
44 // to CHANGE WITHOUT NOTICE. Therefore DO NOT DEPEND ON IT in a user
45 // program!
46 //
47 // Acknowledgment: Google Test borrowed the idea of automatic test
48 // registration from Barthelemy Dagenais' (barthelemy@prologique.com)
49 // easyUnit framework.
50 
51 #ifndef GTEST_INCLUDE_GTEST_GTEST_H_
52 #define GTEST_INCLUDE_GTEST_GTEST_H_
53 
54 #include <limits>
55 #include <ostream>
56 #include <vector>
57 
60 #include "gtest/gtest-death-test.h"
61 #include "gtest/gtest-message.h"
62 #include "gtest/gtest-param-test.h"
63 #include "gtest/gtest-printers.h"
64 #include "gtest/gtest_prod.h"
65 #include "gtest/gtest-test-part.h"
66 #include "gtest/gtest-typed-test.h"
67 
68 // Depending on the platform, different string classes are available.
69 // On Linux, in addition to ::std::string, Google also makes use of
70 // class ::string, which has the same interface as ::std::string, but
71 // has a different implementation.
72 //
73 // You can define GTEST_HAS_GLOBAL_STRING to 1 to indicate that
74 // ::string is available AND is a distinct type to ::std::string, or
75 // define it to 0 to indicate otherwise.
76 //
77 // If ::std::string and ::string are the same class on your platform
78 // due to aliasing, you should define GTEST_HAS_GLOBAL_STRING to 0.
79 //
80 // If you do not define GTEST_HAS_GLOBAL_STRING, it is defined
81 // heuristically.
82 
83 namespace testing {
84 
85 // Declares the flags.
86 
87 // This flag temporary enables the disabled tests.
88 GTEST_DECLARE_bool_(also_run_disabled_tests);
89 
90 // This flag brings the debugger on an assertion failure.
91 GTEST_DECLARE_bool_(break_on_failure);
92 
93 // This flag controls whether Google Test catches all test-thrown exceptions
94 // and logs them as failures.
95 GTEST_DECLARE_bool_(catch_exceptions);
96 
97 // This flag enables using colors in terminal output. Available values are
98 // "yes" to enable colors, "no" (disable colors), or "auto" (the default)
99 // to let Google Test decide.
100 GTEST_DECLARE_string_(color);
101 
102 // This flag sets up the filter to select by name using a glob pattern
103 // the tests to run. If the filter is not given all tests are executed.
104 GTEST_DECLARE_string_(filter);
105 
106 // This flag causes the Google Test to list tests. None of the tests listed
107 // are actually run if the flag is provided.
108 GTEST_DECLARE_bool_(list_tests);
109 
110 // This flag controls whether Google Test emits a detailed XML report to a file
111 // in addition to its normal textual output.
113 
114 // This flags control whether Google Test prints the elapsed time for each
115 // test.
116 GTEST_DECLARE_bool_(print_time);
117 
118 // This flag specifies the random number seed.
119 GTEST_DECLARE_int32_(random_seed);
120 
121 // This flag sets how many times the tests are repeated. The default value
122 // is 1. If the value is -1 the tests are repeating forever.
123 GTEST_DECLARE_int32_(repeat);
124 
125 // This flag controls whether Google Test includes Google Test internal
126 // stack frames in failure stack traces.
127 GTEST_DECLARE_bool_(show_internal_stack_frames);
128 
129 // When this flag is specified, tests' order is randomized on every iteration.
130 GTEST_DECLARE_bool_(shuffle);
131 
132 // This flag specifies the maximum number of stack frames to be
133 // printed in a failure message.
134 GTEST_DECLARE_int32_(stack_trace_depth);
135 
136 // When this flag is specified, a failed assertion will throw an
137 // exception if exceptions are enabled, or exit the program with a
138 // non-zero code otherwise.
139 GTEST_DECLARE_bool_(throw_on_failure);
140 
141 // When this flag is set with a "host:port" string, on supported
142 // platforms test results are streamed to the specified port on
143 // the specified host machine.
144 GTEST_DECLARE_string_(stream_result_to);
145 
146 // The upper limit for valid stack trace depths.
147 const int kMaxStackTraceDepth = 100;
148 
149 namespace internal {
150 
151 class AssertHelper;
152 class DefaultGlobalTestPartResultReporter;
153 class ExecDeathTest;
154 class NoExecDeathTest;
155 class FinalSuccessChecker;
156 class GTestFlagSaver;
157 class StreamingListenerTest;
158 class TestResultAccessor;
159 class TestEventListenersAccessor;
160 class TestEventRepeater;
161 class UnitTestRecordPropertyTestHelper;
162 class WindowsDeathTest;
163 class UnitTestImpl* GetUnitTestImpl();
165  const std::string& message);
166 
167 } // namespace internal
168 
169 // The friend relationship of some of these classes is cyclic.
170 // If we don't forward declare them the compiler might confuse the classes
171 // in friendship clauses with same named classes on the scope.
172 class Test;
173 class TestCase;
174 class TestInfo;
175 class UnitTest;
176 
177 // A class for indicating whether an assertion was successful. When
178 // the assertion wasn't successful, the AssertionResult object
179 // remembers a non-empty message that describes how it failed.
180 //
181 // To create an instance of this class, use one of the factory functions
182 // (AssertionSuccess() and AssertionFailure()).
183 //
184 // This class is useful for two purposes:
185 // 1. Defining predicate functions to be used with Boolean test assertions
186 // EXPECT_TRUE/EXPECT_FALSE and their ASSERT_ counterparts
187 // 2. Defining predicate-format functions to be
188 // used with predicate assertions (ASSERT_PRED_FORMAT*, etc).
189 //
190 // For example, if you define IsEven predicate:
191 //
192 // testing::AssertionResult IsEven(int n) {
193 // if ((n % 2) == 0)
194 // return testing::AssertionSuccess();
195 // else
196 // return testing::AssertionFailure() << n << " is odd";
197 // }
198 //
199 // Then the failed expectation EXPECT_TRUE(IsEven(Fib(5)))
200 // will print the message
201 //
202 // Value of: IsEven(Fib(5))
203 // Actual: false (5 is odd)
204 // Expected: true
205 //
206 // instead of a more opaque
207 //
208 // Value of: IsEven(Fib(5))
209 // Actual: false
210 // Expected: true
211 //
212 // in case IsEven is a simple Boolean predicate.
213 //
214 // If you expect your predicate to be reused and want to support informative
215 // messages in EXPECT_FALSE and ASSERT_FALSE (negative assertions show up
216 // about half as often as positive ones in our tests), supply messages for
217 // both success and failure cases:
218 //
219 // testing::AssertionResult IsEven(int n) {
220 // if ((n % 2) == 0)
221 // return testing::AssertionSuccess() << n << " is even";
222 // else
223 // return testing::AssertionFailure() << n << " is odd";
224 // }
225 //
226 // Then a statement EXPECT_FALSE(IsEven(Fib(6))) will print
227 //
228 // Value of: IsEven(Fib(6))
229 // Actual: true (8 is even)
230 // Expected: false
231 //
232 // NB: Predicates that support negative Boolean assertions have reduced
233 // performance in positive ones so be careful not to use them in tests
234 // that have lots (tens of thousands) of positive Boolean assertions.
235 //
236 // To use this class with EXPECT_PRED_FORMAT assertions such as:
237 //
238 // // Verifies that Foo() returns an even number.
239 // EXPECT_PRED_FORMAT1(IsEven, Foo());
240 //
241 // you need to define:
242 //
243 // testing::AssertionResult IsEven(const char* expr, int n) {
244 // if ((n % 2) == 0)
245 // return testing::AssertionSuccess();
246 // else
247 // return testing::AssertionFailure()
248 // << "Expected: " << expr << " is even\n Actual: it's " << n;
249 // }
250 //
251 // If Foo() returns 5, you will see the following message:
252 //
253 // Expected: Foo() is even
254 // Actual: it's 5
255 //
257  public:
258  // Copy constructor.
259  // Used in EXPECT_TRUE/FALSE(assertion_result).
260  AssertionResult(const AssertionResult& other);
261 
262  GTEST_DISABLE_MSC_WARNINGS_PUSH_(4800 /* forcing value to bool */)
263 
264  // Used in the EXPECT_TRUE/FALSE(bool_expression).
265  //
266  // T must be contextually convertible to bool.
267  //
268  // The second parameter prevents this overload from being considered if
269  // the argument is implicitly convertible to AssertionResult. In that case
270  // we want AssertionResult's copy constructor to be used.
271  template <typename T>
272  explicit AssertionResult(
273  const T& success,
274  typename internal::EnableIf<
276  /*enabler*/ = NULL)
277  : success_(success) {}
278 
280 
281  // Assignment operator.
282  AssertionResult& operator=(AssertionResult other) {
283  swap(other);
284  return *this;
285  }
286 
287  // Returns true iff the assertion succeeded.
288  operator bool() const { return success_; } // NOLINT
289 
290  // Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE.
291  AssertionResult operator!() const;
292 
293  // Returns the text streamed into this AssertionResult. Test assertions
294  // use it when they fail (i.e., the predicate's outcome doesn't match the
295  // assertion's expectation). When nothing has been streamed into the
296  // object, returns an empty string.
297  const char* message() const {
298  return message_.get() != NULL ? message_->c_str() : "";
299  }
300  // TODO(vladl@google.com): Remove this after making sure no clients use it.
301  // Deprecated; please use message() instead.
302  const char* failure_message() const { return message(); }
303 
304  // Streams a custom failure message into this object.
305  template <typename T> AssertionResult& operator<<(const T& value) {
306  AppendMessage(Message() << value);
307  return *this;
308  }
309 
310  // Allows streaming basic output manipulators such as endl or flush into
311  // this object.
313  ::std::ostream& (*basic_manipulator)(::std::ostream& stream)) {
314  AppendMessage(Message() << basic_manipulator);
315  return *this;
316  }
317 
318  private:
319  // Appends the contents of message to message_.
320  void AppendMessage(const Message& a_message) {
321  if (message_.get() == NULL)
322  message_.reset(new ::std::string);
323  message_->append(a_message.GetString().c_str());
324  }
325 
326  // Swap the contents of this AssertionResult with other.
327  void swap(AssertionResult& other);
328 
329  // Stores result of the assertion predicate.
330  bool success_;
331  // Stores the message describing the condition in case the expectation
332  // construct is not satisfied with the predicate's outcome.
333  // Referenced via a pointer to avoid taking too much stack frame space
334  // with test assertions.
336 };
337 
338 // Makes a successful assertion result.
340 
341 // Makes a failed assertion result.
343 
344 // Makes a failed assertion result with the given failure message.
345 // Deprecated; use AssertionFailure() << msg.
347 
348 // The abstract class that all tests inherit from.
349 //
350 // In Google Test, a unit test program contains one or many TestCases, and
351 // each TestCase contains one or many Tests.
352 //
353 // When you define a test using the TEST macro, you don't need to
354 // explicitly derive from Test - the TEST macro automatically does
355 // this for you.
356 //
357 // The only time you derive from Test is when defining a test fixture
358 // to be used a TEST_F. For example:
359 //
360 // class FooTest : public testing::Test {
361 // protected:
362 // void SetUp() override { ... }
363 // void TearDown() override { ... }
364 // ...
365 // };
366 //
367 // TEST_F(FooTest, Bar) { ... }
368 // TEST_F(FooTest, Baz) { ... }
369 //
370 // Test is not copyable.
372  public:
373  friend class TestInfo;
374 
375  // Defines types for pointers to functions that set up and tear down
376  // a test case.
379 
380  // The d'tor is virtual as we intend to inherit from Test.
381  virtual ~Test();
382 
383  // Sets up the stuff shared by all tests in this test case.
384  //
385  // Google Test will call Foo::SetUpTestCase() before running the first
386  // test in test case Foo. Hence a sub-class can define its own
387  // SetUpTestCase() method to shadow the one defined in the super
388  // class.
389  static void SetUpTestCase() {}
390 
391  // Tears down the stuff shared by all tests in this test case.
392  //
393  // Google Test will call Foo::TearDownTestCase() after running the last
394  // test in test case Foo. Hence a sub-class can define its own
395  // TearDownTestCase() method to shadow the one defined in the super
396  // class.
397  static void TearDownTestCase() {}
398 
399  // Returns true iff the current test has a fatal failure.
400  static bool HasFatalFailure();
401 
402  // Returns true iff the current test has a non-fatal failure.
403  static bool HasNonfatalFailure();
404 
405  // Returns true iff the current test has a (either fatal or
406  // non-fatal) failure.
407  static bool HasFailure() { return HasFatalFailure() || HasNonfatalFailure(); }
408 
409  // Logs a property for the current test, test case, or for the entire
410  // invocation of the test program when used outside of the context of a
411  // test case. Only the last value for a given key is remembered. These
412  // are public static so they can be called from utility functions that are
413  // not members of the test fixture. Calls to RecordProperty made during
414  // lifespan of the test (from the moment its constructor starts to the
415  // moment its destructor finishes) will be output in XML as attributes of
416  // the <testcase> element. Properties recorded from fixture's
417  // SetUpTestCase or TearDownTestCase are logged as attributes of the
418  // corresponding <testsuite> element. Calls to RecordProperty made in the
419  // global context (before or after invocation of RUN_ALL_TESTS and from
420  // SetUp/TearDown method of Environment objects registered with Google
421  // Test) will be output as attributes of the <testsuites> element.
422  static void RecordProperty(const std::string& key, const std::string& value);
423  static void RecordProperty(const std::string& key, int value);
424 
425  protected:
426  // Creates a Test object.
427  Test();
428 
429  // Sets up the test fixture.
430  virtual void SetUp();
431 
432  // Tears down the test fixture.
433  virtual void TearDown();
434 
435  private:
436  // Returns true iff the current test has the same fixture class as
437  // the first test in the current test case.
438  static bool HasSameFixtureClass();
439 
440  // Runs the test after the test fixture has been set up.
441  //
442  // A sub-class must implement this to define the test logic.
443  //
444  // DO NOT OVERRIDE THIS FUNCTION DIRECTLY IN A USER PROGRAM.
445  // Instead, use the TEST or TEST_F macro.
446  virtual void TestBody() = 0;
447 
448  // Sets up, executes, and tears down the test.
449  void Run();
450 
451  // Deletes self. We deliberately pick an unusual name for this
452  // internal method to avoid clashing with names used in user TESTs.
453  void DeleteSelf_() { delete this; }
454 
455  // Uses a GTestFlagSaver to save and restore all Google Test flags.
457 
458  // Often a user misspells SetUp() as Setup() and spends a long time
459  // wondering why it is never called by Google Test. The declaration of
460  // the following method is solely for catching such an error at
461  // compile time:
462  //
463  // - The return type is deliberately chosen to be not void, so it
464  // will be a conflict if void Setup() is declared in the user's
465  // test fixture.
466  //
467  // - This method is private, so it will be another compiler error
468  // if the method is called from the user's test fixture.
469  //
470  // DO NOT OVERRIDE THIS FUNCTION.
471  //
472  // If you see an error about overriding the following function or
473  // about it being private, you have mis-spelled SetUp() as Setup().
475  virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; }
476 
477  // We disallow copying Tests.
479 };
480 
482 
483 // A copyable object representing a user specified test property which can be
484 // output as a key/value string pair.
485 //
486 // Don't inherit from TestProperty as its destructor is not virtual.
488  public:
489  // C'tor. TestProperty does NOT have a default constructor.
490  // Always use this constructor (with parameters) to create a
491  // TestProperty object.
492  TestProperty(const std::string& a_key, const std::string& a_value) :
493  key_(a_key), value_(a_value) {
494  }
495 
496  // Gets the user supplied key.
497  const char* key() const {
498  return key_.c_str();
499  }
500 
501  // Gets the user supplied value.
502  const char* value() const {
503  return value_.c_str();
504  }
505 
506  // Sets a new value, overriding the one supplied in the constructor.
507  void SetValue(const std::string& new_value) {
508  value_ = new_value;
509  }
510 
511  private:
512  // The key supplied by the user.
514  // The value supplied by the user.
516 };
517 
518 // The result of a single Test. This includes a list of
519 // TestPartResults, a list of TestProperties, a count of how many
520 // death tests there are in the Test, and how much time it took to run
521 // the Test.
522 //
523 // TestResult is not copyable.
525  public:
526  // Creates an empty TestResult.
527  TestResult();
528 
529  // D'tor. Do not inherit from TestResult.
530  ~TestResult();
531 
532  // Gets the number of all test parts. This is the sum of the number
533  // of successful test parts and the number of failed test parts.
534  int total_part_count() const;
535 
536  // Returns the number of the test properties.
537  int test_property_count() const;
538 
539  // Returns true iff the test passed (i.e. no test part failed).
540  bool Passed() const { return !Failed(); }
541 
542  // Returns true iff the test failed.
543  bool Failed() const;
544 
545  // Returns true iff the test fatally failed.
546  bool HasFatalFailure() const;
547 
548  // Returns true iff the test has a non-fatal failure.
549  bool HasNonfatalFailure() const;
550 
551  // Returns the elapsed time, in milliseconds.
552  TimeInMillis elapsed_time() const { return elapsed_time_; }
553 
554  // Returns the i-th test part result among all the results. i can range
555  // from 0 to test_property_count() - 1. If i is not in that range, aborts
556  // the program.
557  const TestPartResult& GetTestPartResult(int i) const;
558 
559  // Returns the i-th test property. i can range from 0 to
560  // test_property_count() - 1. If i is not in that range, aborts the
561  // program.
562  const TestProperty& GetTestProperty(int i) const;
563 
564  private:
565  friend class TestInfo;
566  friend class TestCase;
567  friend class UnitTest;
569  friend class internal::ExecDeathTest;
572  friend class internal::WindowsDeathTest;
573 
574  // Gets the vector of TestPartResults.
575  const std::vector<TestPartResult>& test_part_results() const {
576  return test_part_results_;
577  }
578 
579  // Gets the vector of TestProperties.
580  const std::vector<TestProperty>& test_properties() const {
581  return test_properties_;
582  }
583 
584  // Sets the elapsed time.
585  void set_elapsed_time(TimeInMillis elapsed) { elapsed_time_ = elapsed; }
586 
587  // Adds a test property to the list. The property is validated and may add
588  // a non-fatal failure if invalid (e.g., if it conflicts with reserved
589  // key names). If a property is already recorded for the same key, the
590  // value will be updated, rather than storing multiple values for the same
591  // key. xml_element specifies the element for which the property is being
592  // recorded and is used for validation.
593  void RecordProperty(const std::string& xml_element,
594  const TestProperty& test_property);
595 
596  // Adds a failure if the key is a reserved attribute of Google Test
597  // testcase tags. Returns true if the property is valid.
598  // TODO(russr): Validate attribute names are legal and human readable.
599  static bool ValidateTestProperty(const std::string& xml_element,
600  const TestProperty& test_property);
601 
602  // Adds a test part result to the list.
603  void AddTestPartResult(const TestPartResult& test_part_result);
604 
605  // Returns the death test count.
606  int death_test_count() const { return death_test_count_; }
607 
608  // Increments the death test count, returning the new count.
609  int increment_death_test_count() { return ++death_test_count_; }
610 
611  // Clears the test part results.
612  void ClearTestPartResults();
613 
614  // Clears the object.
615  void Clear();
616 
617  // Protects mutable state of the property vector and of owned
618  // properties, whose values may be updated.
620 
621  // The vector of TestPartResults
622  std::vector<TestPartResult> test_part_results_;
623  // The vector of TestProperties
624  std::vector<TestProperty> test_properties_;
625  // Running count of death tests.
627  // The elapsed time, in milliseconds.
628  TimeInMillis elapsed_time_;
629 
630  // We disallow copying TestResult.
632 }; // class TestResult
633 
634 // A TestInfo object stores the following information about a test:
635 //
636 // Test case name
637 // Test name
638 // Whether the test should be run
639 // A function pointer that creates the test object when invoked
640 // Test result
641 //
642 // The constructor of TestInfo registers itself with the UnitTest
643 // singleton such that the RUN_ALL_TESTS() macro knows which tests to
644 // run.
646  public:
647  // Destructs a TestInfo object. This function is not virtual, so
648  // don't inherit from TestInfo.
649  ~TestInfo();
650 
651  // Returns the test case name.
652  const char* test_case_name() const { return test_case_name_.c_str(); }
653 
654  // Returns the test name.
655  const char* name() const { return name_.c_str(); }
656 
657  // Returns the name of the parameter type, or NULL if this is not a typed
658  // or a type-parameterized test.
659  const char* type_param() const {
660  if (type_param_.get() != NULL)
661  return type_param_->c_str();
662  return NULL;
663  }
664 
665  // Returns the text representation of the value parameter, or NULL if this
666  // is not a value-parameterized test.
667  const char* value_param() const {
668  if (value_param_.get() != NULL)
669  return value_param_->c_str();
670  return NULL;
671  }
672 
673  // Returns true if this test should run, that is if the test is not
674  // disabled (or it is disabled but the also_run_disabled_tests flag has
675  // been specified) and its full name matches the user-specified filter.
676  //
677  // Google Test allows the user to filter the tests by their full names.
678  // The full name of a test Bar in test case Foo is defined as
679  // "Foo.Bar". Only the tests that match the filter will run.
680  //
681  // A filter is a colon-separated list of glob (not regex) patterns,
682  // optionally followed by a '-' and a colon-separated list of
683  // negative patterns (tests to exclude). A test is run if it
684  // matches one of the positive patterns and does not match any of
685  // the negative patterns.
686  //
687  // For example, *A*:Foo.* is a filter that matches any string that
688  // contains the character 'A' or starts with "Foo.".
689  bool should_run() const { return should_run_; }
690 
691  // Returns true iff this test will appear in the XML report.
692  bool is_reportable() const {
693  // For now, the XML report includes all tests matching the filter.
694  // In the future, we may trim tests that are excluded because of
695  // sharding.
696  return matches_filter_;
697  }
698 
699  // Returns the result of the test.
700  const TestResult* result() const { return &result_; }
701 
702  private:
703 #if GTEST_HAS_DEATH_TEST
704  friend class internal::DefaultDeathTestFactory;
705 #endif // GTEST_HAS_DEATH_TEST
706  friend class Test;
707  friend class TestCase;
709  friend class internal::StreamingListenerTest;
711  const char* test_case_name,
712  const char* name,
713  const char* type_param,
714  const char* value_param,
715  internal::TypeId fixture_class_id,
716  Test::SetUpTestCaseFunc set_up_tc,
717  Test::TearDownTestCaseFunc tear_down_tc,
718  internal::TestFactoryBase* factory);
719 
720  // Constructs a TestInfo object. The newly constructed instance assumes
721  // ownership of the factory object.
722  TestInfo(const std::string& test_case_name,
723  const std::string& name,
724  const char* a_type_param, // NULL if not a type-parameterized test
725  const char* a_value_param, // NULL if not a value-parameterized test
726  internal::TypeId fixture_class_id,
727  internal::TestFactoryBase* factory);
728 
729  // Increments the number of death tests encountered in this test so
730  // far.
732  return result_.increment_death_test_count();
733  }
734 
735  // Creates the test object, runs it, records its result, and then
736  // deletes it.
737  void Run();
738 
739  static void ClearTestResult(TestInfo* test_info) {
740  test_info->result_.Clear();
741  }
742 
743  // These fields are immutable properties of the test.
744  const std::string test_case_name_; // Test case name
745  const std::string name_; // Test name
746  // Name of the parameter type, or NULL if this is not a typed or a
747  // type-parameterized test.
749  // Text representation of the value parameter, or NULL if this is not a
750  // value-parameterized test.
752  const internal::TypeId fixture_class_id_; // ID of the test fixture class
753  bool should_run_; // True iff this test should run
754  bool is_disabled_; // True iff this test is disabled
755  bool matches_filter_; // True if this test matches the
756  // user-specified filter.
757  internal::TestFactoryBase* const factory_; // The factory that creates
758  // the test object
759 
760  // This field is mutable and needs to be reset before running the
761  // test for the second time.
763 
765 };
766 
767 // A test case, which consists of a vector of TestInfos.
768 //
769 // TestCase is not copyable.
771  public:
772  // Creates a TestCase with the given name.
773  //
774  // TestCase does NOT have a default constructor. Always use this
775  // constructor to create a TestCase object.
776  //
777  // Arguments:
778  //
779  // name: name of the test case
780  // a_type_param: the name of the test's type parameter, or NULL if
781  // this is not a type-parameterized test.
782  // set_up_tc: pointer to the function that sets up the test case
783  // tear_down_tc: pointer to the function that tears down the test case
784  TestCase(const char* name, const char* a_type_param,
785  Test::SetUpTestCaseFunc set_up_tc,
786  Test::TearDownTestCaseFunc tear_down_tc);
787 
788  // Destructor of TestCase.
789  virtual ~TestCase();
790 
791  // Gets the name of the TestCase.
792  const char* name() const { return name_.c_str(); }
793 
794  // Returns the name of the parameter type, or NULL if this is not a
795  // type-parameterized test case.
796  const char* type_param() const {
797  if (type_param_.get() != NULL)
798  return type_param_->c_str();
799  return NULL;
800  }
801 
802  // Returns true if any test in this test case should run.
803  bool should_run() const { return should_run_; }
804 
805  // Gets the number of successful tests in this test case.
806  int successful_test_count() const;
807 
808  // Gets the number of failed tests in this test case.
809  int failed_test_count() const;
810 
811  // Gets the number of disabled tests that will be reported in the XML report.
812  int reportable_disabled_test_count() const;
813 
814  // Gets the number of disabled tests in this test case.
815  int disabled_test_count() const;
816 
817  // Gets the number of tests to be printed in the XML report.
818  int reportable_test_count() const;
819 
820  // Get the number of tests in this test case that should run.
821  int test_to_run_count() const;
822 
823  // Gets the number of all tests in this test case.
824  int total_test_count() const;
825 
826  // Returns true iff the test case passed.
827  bool Passed() const { return !Failed(); }
828 
829  // Returns true iff the test case failed.
830  bool Failed() const { return failed_test_count() > 0; }
831 
832  // Returns the elapsed time, in milliseconds.
833  TimeInMillis elapsed_time() const { return elapsed_time_; }
834 
835  // Returns the i-th test among all the tests. i can range from 0 to
836  // total_test_count() - 1. If i is not in that range, returns NULL.
837  const TestInfo* GetTestInfo(int i) const;
838 
839  // Returns the TestResult that holds test properties recorded during
840  // execution of SetUpTestCase and TearDownTestCase.
841  const TestResult& ad_hoc_test_result() const { return ad_hoc_test_result_; }
842 
843  private:
844  friend class Test;
846 
847  // Gets the (mutable) vector of TestInfos in this TestCase.
848  std::vector<TestInfo*>& test_info_list() { return test_info_list_; }
849 
850  // Gets the (immutable) vector of TestInfos in this TestCase.
851  const std::vector<TestInfo*>& test_info_list() const {
852  return test_info_list_;
853  }
854 
855  // Returns the i-th test among all the tests. i can range from 0 to
856  // total_test_count() - 1. If i is not in that range, returns NULL.
857  TestInfo* GetMutableTestInfo(int i);
858 
859  // Sets the should_run member.
860  void set_should_run(bool should) { should_run_ = should; }
861 
862  // Adds a TestInfo to this test case. Will delete the TestInfo upon
863  // destruction of the TestCase object.
864  void AddTestInfo(TestInfo * test_info);
865 
866  // Clears the results of all tests in this test case.
867  void ClearResult();
868 
869  // Clears the results of all tests in the given test case.
870  static void ClearTestCaseResult(TestCase* test_case) {
871  test_case->ClearResult();
872  }
873 
874  // Runs every test in this TestCase.
875  void Run();
876 
877  // Runs SetUpTestCase() for this TestCase. This wrapper is needed
878  // for catching exceptions thrown from SetUpTestCase().
879  void RunSetUpTestCase() { (*set_up_tc_)(); }
880 
881  // Runs TearDownTestCase() for this TestCase. This wrapper is
882  // needed for catching exceptions thrown from TearDownTestCase().
883  void RunTearDownTestCase() { (*tear_down_tc_)(); }
884 
885  // Returns true iff test passed.
886  static bool TestPassed(const TestInfo* test_info) {
887  return test_info->should_run() && test_info->result()->Passed();
888  }
889 
890  // Returns true iff test failed.
891  static bool TestFailed(const TestInfo* test_info) {
892  return test_info->should_run() && test_info->result()->Failed();
893  }
894 
895  // Returns true iff the test is disabled and will be reported in the XML
896  // report.
897  static bool TestReportableDisabled(const TestInfo* test_info) {
898  return test_info->is_reportable() && test_info->is_disabled_;
899  }
900 
901  // Returns true iff test is disabled.
902  static bool TestDisabled(const TestInfo* test_info) {
903  return test_info->is_disabled_;
904  }
905 
906  // Returns true iff this test will appear in the XML report.
907  static bool TestReportable(const TestInfo* test_info) {
908  return test_info->is_reportable();
909  }
910 
911  // Returns true if the given test should run.
912  static bool ShouldRunTest(const TestInfo* test_info) {
913  return test_info->should_run();
914  }
915 
916  // Shuffles the tests in this test case.
917  void ShuffleTests(internal::Random* random);
918 
919  // Restores the test order to before the first shuffle.
920  void UnshuffleTests();
921 
922  // Name of the test case.
924  // Name of the parameter type, or NULL if this is not a typed or a
925  // type-parameterized test.
927  // The vector of TestInfos in their original order. It owns the
928  // elements in the vector.
929  std::vector<TestInfo*> test_info_list_;
930  // Provides a level of indirection for the test list to allow easy
931  // shuffling and restoring the test order. The i-th element in this
932  // vector is the index of the i-th test in the shuffled test list.
933  std::vector<int> test_indices_;
934  // Pointer to the function that sets up the test case.
936  // Pointer to the function that tears down the test case.
938  // True iff any test in this test case should run.
940  // Elapsed time, in milliseconds.
941  TimeInMillis elapsed_time_;
942  // Holds test properties recorded during execution of SetUpTestCase and
943  // TearDownTestCase.
945 
946  // We disallow copying TestCases.
948 };
949 
950 // An Environment object is capable of setting up and tearing down an
951 // environment. You should subclass this to define your own
952 // environment(s).
953 //
954 // An Environment object does the set-up and tear-down in virtual
955 // methods SetUp() and TearDown() instead of the constructor and the
956 // destructor, as:
957 //
958 // 1. You cannot safely throw from a destructor. This is a problem
959 // as in some cases Google Test is used where exceptions are enabled, and
960 // we may want to implement ASSERT_* using exceptions where they are
961 // available.
962 // 2. You cannot use ASSERT_* directly in a constructor or
963 // destructor.
964 class Environment {
965  public:
966  // The d'tor is virtual as we need to subclass Environment.
967  virtual ~Environment() {}
968 
969  // Override this to define how to set up the environment.
970  virtual void SetUp() {}
971 
972  // Override this to define how to tear down the environment.
973  virtual void TearDown() {}
974  private:
975  // If you see an error about overriding the following function or
976  // about it being private, you have mis-spelled SetUp() as Setup().
978  virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; }
979 };
980 
981 // The interface for tracing execution of tests. The methods are organized in
982 // the order the corresponding events are fired.
984  public:
985  virtual ~TestEventListener() {}
986 
987  // Fired before any test activity starts.
988  virtual void OnTestProgramStart(const UnitTest& unit_test) = 0;
989 
990  // Fired before each iteration of tests starts. There may be more than
991  // one iteration if GTEST_FLAG(repeat) is set. iteration is the iteration
992  // index, starting from 0.
993  virtual void OnTestIterationStart(const UnitTest& unit_test,
994  int iteration) = 0;
995 
996  // Fired before environment set-up for each iteration of tests starts.
997  virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test) = 0;
998 
999  // Fired after environment set-up for each iteration of tests ends.
1000  virtual void OnEnvironmentsSetUpEnd(const UnitTest& unit_test) = 0;
1001 
1002  // Fired before the test case starts.
1003  virtual void OnTestCaseStart(const TestCase& test_case) = 0;
1004 
1005  // Fired before the test starts.
1006  virtual void OnTestStart(const TestInfo& test_info) = 0;
1007 
1008  // Fired after a failed assertion or a SUCCEED() invocation.
1009  virtual void OnTestPartResult(const TestPartResult& test_part_result) = 0;
1010 
1011  // Fired after the test ends.
1012  virtual void OnTestEnd(const TestInfo& test_info) = 0;
1013 
1014  // Fired after the test case ends.
1015  virtual void OnTestCaseEnd(const TestCase& test_case) = 0;
1016 
1017  // Fired before environment tear-down for each iteration of tests starts.
1018  virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test) = 0;
1019 
1020  // Fired after environment tear-down for each iteration of tests ends.
1021  virtual void OnEnvironmentsTearDownEnd(const UnitTest& unit_test) = 0;
1022 
1023  // Fired after each iteration of tests finishes.
1024  virtual void OnTestIterationEnd(const UnitTest& unit_test,
1025  int iteration) = 0;
1026 
1027  // Fired after all test activities have ended.
1028  virtual void OnTestProgramEnd(const UnitTest& unit_test) = 0;
1029 };
1030 
1031 // The convenience class for users who need to override just one or two
1032 // methods and are not concerned that a possible change to a signature of
1033 // the methods they override will not be caught during the build. For
1034 // comments about each method please see the definition of TestEventListener
1035 // above.
1037  public:
1038  virtual void OnTestProgramStart(const UnitTest& /*unit_test*/) {}
1039  virtual void OnTestIterationStart(const UnitTest& /*unit_test*/,
1040  int /*iteration*/) {}
1041  virtual void OnEnvironmentsSetUpStart(const UnitTest& /*unit_test*/) {}
1042  virtual void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) {}
1043  virtual void OnTestCaseStart(const TestCase& /*test_case*/) {}
1044  virtual void OnTestStart(const TestInfo& /*test_info*/) {}
1045  virtual void OnTestPartResult(const TestPartResult& /*test_part_result*/) {}
1046  virtual void OnTestEnd(const TestInfo& /*test_info*/) {}
1047  virtual void OnTestCaseEnd(const TestCase& /*test_case*/) {}
1048  virtual void OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) {}
1049  virtual void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) {}
1050  virtual void OnTestIterationEnd(const UnitTest& /*unit_test*/,
1051  int /*iteration*/) {}
1052  virtual void OnTestProgramEnd(const UnitTest& /*unit_test*/) {}
1053 };
1054 
1055 // TestEventListeners lets users add listeners to track events in Google Test.
1057  public:
1059  ~TestEventListeners();
1060 
1061  // Appends an event listener to the end of the list. Google Test assumes
1062  // the ownership of the listener (i.e. it will delete the listener when
1063  // the test program finishes).
1064  void Append(TestEventListener* listener);
1065 
1066  // Removes the given event listener from the list and returns it. It then
1067  // becomes the caller's responsibility to delete the listener. Returns
1068  // NULL if the listener is not found in the list.
1069  TestEventListener* Release(TestEventListener* listener);
1070 
1071  // Returns the standard listener responsible for the default console
1072  // output. Can be removed from the listeners list to shut down default
1073  // console output. Note that removing this object from the listener list
1074  // with Release transfers its ownership to the caller and makes this
1075  // function return NULL the next time.
1077  return default_result_printer_;
1078  }
1079 
1080  // Returns the standard listener responsible for the default XML output
1081  // controlled by the --gtest_output=xml flag. Can be removed from the
1082  // listeners list by users who want to shut down the default XML output
1083  // controlled by this flag and substitute it with custom one. Note that
1084  // removing this object from the listener list with Release transfers its
1085  // ownership to the caller and makes this function return NULL the next
1086  // time.
1088  return default_xml_generator_;
1089  }
1090 
1091  private:
1092  friend class TestCase;
1093  friend class TestInfo;
1095  friend class internal::NoExecDeathTest;
1098 
1099  // Returns repeater that broadcasts the TestEventListener events to all
1100  // subscribers.
1101  TestEventListener* repeater();
1102 
1103  // Sets the default_result_printer attribute to the provided listener.
1104  // The listener is also added to the listener list and previous
1105  // default_result_printer is removed from it and deleted. The listener can
1106  // also be NULL in which case it will not be added to the list. Does
1107  // nothing if the previous and the current listener objects are the same.
1108  void SetDefaultResultPrinter(TestEventListener* listener);
1109 
1110  // Sets the default_xml_generator attribute to the provided listener. The
1111  // listener is also added to the listener list and previous
1112  // default_xml_generator is removed from it and deleted. The listener can
1113  // also be NULL in which case it will not be added to the list. Does
1114  // nothing if the previous and the current listener objects are the same.
1115  void SetDefaultXmlGenerator(TestEventListener* listener);
1116 
1117  // Controls whether events will be forwarded by the repeater to the
1118  // listeners in the list.
1119  bool EventForwardingEnabled() const;
1120  void SuppressEventForwarding();
1121 
1122  // The actual list of listeners.
1124  // Listener responsible for the standard result output.
1126  // Listener responsible for the creation of the XML output file.
1128 
1129  // We disallow copying TestEventListeners.
1131 };
1132 
1133 // A UnitTest consists of a vector of TestCases.
1134 //
1135 // This is a singleton class. The only instance of UnitTest is
1136 // created when UnitTest::GetInstance() is first called. This
1137 // instance is never deleted.
1138 //
1139 // UnitTest is not copyable.
1140 //
1141 // This class is thread-safe as long as the methods are called
1142 // according to their specification.
1144  public:
1145  // Gets the singleton UnitTest object. The first time this method
1146  // is called, a UnitTest object is constructed and returned.
1147  // Consecutive calls will return the same object.
1148  static UnitTest* GetInstance();
1149 
1150  // Runs all tests in this UnitTest object and prints the result.
1151  // Returns 0 if successful, or 1 otherwise.
1152  //
1153  // This method can only be called from the main thread.
1154  //
1155  // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1156  int Run() GTEST_MUST_USE_RESULT_;
1157 
1158  // Returns the working directory when the first TEST() or TEST_F()
1159  // was executed. The UnitTest object owns the string.
1160  const char* original_working_dir() const;
1161 
1162  // Returns the TestCase object for the test that's currently running,
1163  // or NULL if no test is running.
1164  const TestCase* current_test_case() const
1165  GTEST_LOCK_EXCLUDED_(mutex_);
1166 
1167  // Returns the TestInfo object for the test that's currently running,
1168  // or NULL if no test is running.
1169  const TestInfo* current_test_info() const
1170  GTEST_LOCK_EXCLUDED_(mutex_);
1171 
1172  // Returns the random seed used at the start of the current test run.
1173  int random_seed() const;
1174 
1175 #if GTEST_HAS_PARAM_TEST
1176  // Returns the ParameterizedTestCaseRegistry object used to keep track of
1177  // value-parameterized tests and instantiate and register them.
1178  //
1179  // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1180  internal::ParameterizedTestCaseRegistry& parameterized_test_registry()
1181  GTEST_LOCK_EXCLUDED_(mutex_);
1182 #endif // GTEST_HAS_PARAM_TEST
1183 
1184  // Gets the number of successful test cases.
1185  int successful_test_case_count() const;
1186 
1187  // Gets the number of failed test cases.
1188  int failed_test_case_count() const;
1189 
1190  // Gets the number of all test cases.
1191  int total_test_case_count() const;
1192 
1193  // Gets the number of all test cases that contain at least one test
1194  // that should run.
1195  int test_case_to_run_count() const;
1196 
1197  // Gets the number of successful tests.
1198  int successful_test_count() const;
1199 
1200  // Gets the number of failed tests.
1201  int failed_test_count() const;
1202 
1203  // Gets the number of disabled tests that will be reported in the XML report.
1204  int reportable_disabled_test_count() const;
1205 
1206  // Gets the number of disabled tests.
1207  int disabled_test_count() const;
1208 
1209  // Gets the number of tests to be printed in the XML report.
1210  int reportable_test_count() const;
1211 
1212  // Gets the number of all tests.
1213  int total_test_count() const;
1214 
1215  // Gets the number of tests that should run.
1216  int test_to_run_count() const;
1217 
1218  // Gets the time of the test program start, in ms from the start of the
1219  // UNIX epoch.
1220  TimeInMillis start_timestamp() const;
1221 
1222  // Gets the elapsed time, in milliseconds.
1223  TimeInMillis elapsed_time() const;
1224 
1225  // Returns true iff the unit test passed (i.e. all test cases passed).
1226  bool Passed() const;
1227 
1228  // Returns true iff the unit test failed (i.e. some test case failed
1229  // or something outside of all tests failed).
1230  bool Failed() const;
1231 
1232  // Gets the i-th test case among all the test cases. i can range from 0 to
1233  // total_test_case_count() - 1. If i is not in that range, returns NULL.
1234  const TestCase* GetTestCase(int i) const;
1235 
1236  // Returns the TestResult containing information on test failures and
1237  // properties logged outside of individual test cases.
1238  const TestResult& ad_hoc_test_result() const;
1239 
1240  // Returns the list of event listeners that can be used to track events
1241  // inside Google Test.
1242  TestEventListeners& listeners();
1243 
1244  private:
1245  // Registers and returns a global test environment. When a test
1246  // program is run, all global test environments will be set-up in
1247  // the order they were registered. After all tests in the program
1248  // have finished, all global test environments will be torn-down in
1249  // the *reverse* order they were registered.
1250  //
1251  // The UnitTest object takes ownership of the given environment.
1252  //
1253  // This method can only be called from the main thread.
1254  Environment* AddEnvironment(Environment* env);
1255 
1256  // Adds a TestPartResult to the current TestResult object. All
1257  // Google Test assertion macros (e.g. ASSERT_TRUE, EXPECT_EQ, etc)
1258  // eventually call this to report their results. The user code
1259  // should use the assertion macros instead of calling this directly.
1260  void AddTestPartResult(TestPartResult::Type result_type,
1261  const char* file_name,
1262  int line_number,
1263  const std::string& message,
1264  const std::string& os_stack_trace)
1265  GTEST_LOCK_EXCLUDED_(mutex_);
1266 
1267  // Adds a TestProperty to the current TestResult object when invoked from
1268  // inside a test, to current TestCase's ad_hoc_test_result_ when invoked
1269  // from SetUpTestCase or TearDownTestCase, or to the global property set
1270  // when invoked elsewhere. If the result already contains a property with
1271  // the same key, the value will be updated.
1272  void RecordProperty(const std::string& key, const std::string& value);
1273 
1274  // Gets the i-th test case among all the test cases. i can range from 0 to
1275  // total_test_case_count() - 1. If i is not in that range, returns NULL.
1276  TestCase* GetMutableTestCase(int i);
1277 
1278  // Accessors for the implementation object.
1279  internal::UnitTestImpl* impl() { return impl_; }
1280  const internal::UnitTestImpl* impl() const { return impl_; }
1281 
1282  // These classes and funcions are friends as they need to access private
1283  // members of UnitTest.
1284  friend class Test;
1287  friend class internal::StreamingListenerTest;
1292  TestPartResult::Type result_type,
1293  const std::string& message);
1294 
1295  // Creates an empty UnitTest.
1296  UnitTest();
1297 
1298  // D'tor
1299  virtual ~UnitTest();
1300 
1301  // Pushes a trace defined by SCOPED_TRACE() on to the per-thread
1302  // Google Test trace stack.
1303  void PushGTestTrace(const internal::TraceInfo& trace)
1304  GTEST_LOCK_EXCLUDED_(mutex_);
1305 
1306  // Pops a trace from the per-thread Google Test trace stack.
1307  void PopGTestTrace()
1308  GTEST_LOCK_EXCLUDED_(mutex_);
1309 
1310  // Protects mutable state in *impl_. This is mutable as some const
1311  // methods need to lock it too.
1312  mutable internal::Mutex mutex_;
1313 
1314  // Opaque implementation object. This field is never changed once
1315  // the object is constructed. We don't mark it as const here, as
1316  // doing so will cause a warning in the constructor of UnitTest.
1317  // Mutable state in *impl_ is protected by mutex_.
1318  internal::UnitTestImpl* impl_;
1319 
1320  // We disallow copying UnitTest.
1322 };
1323 
1324 // A convenient wrapper for adding an environment for the test
1325 // program.
1326 //
1327 // You should call this before RUN_ALL_TESTS() is called, probably in
1328 // main(). If you use gtest_main, you need to call this before main()
1329 // starts for it to take effect. For example, you can define a global
1330 // variable like this:
1331 //
1332 // testing::Environment* const foo_env =
1333 // testing::AddGlobalTestEnvironment(new FooEnvironment);
1334 //
1335 // However, we strongly recommend you to write your own main() and
1336 // call AddGlobalTestEnvironment() there, as relying on initialization
1337 // of global variables makes the code harder to read and may cause
1338 // problems when you register multiple environments from different
1339 // translation units and the environments have dependencies among them
1340 // (remember that the compiler doesn't guarantee the order in which
1341 // global variables from different translation units are initialized).
1343  return UnitTest::GetInstance()->AddEnvironment(env);
1344 }
1345 
1346 // Initializes Google Test. This must be called before calling
1347 // RUN_ALL_TESTS(). In particular, it parses a command line for the
1348 // flags that Google Test recognizes. Whenever a Google Test flag is
1349 // seen, it is removed from argv, and *argc is decremented.
1350 //
1351 // No value is returned. Instead, the Google Test flag variables are
1352 // updated.
1353 //
1354 // Calling the function for the second time has no user-visible effect.
1355 GTEST_API_ void InitGoogleTest(int* argc, char** argv);
1356 
1357 // This overloaded version can be used in Windows programs compiled in
1358 // UNICODE mode.
1359 GTEST_API_ void InitGoogleTest(int* argc, wchar_t** argv);
1360 
1361 namespace internal {
1362 
1363 // FormatForComparison<ToPrint, OtherOperand>::Format(value) formats a
1364 // value of type ToPrint that is an operand of a comparison assertion
1365 // (e.g. ASSERT_EQ). OtherOperand is the type of the other operand in
1366 // the comparison, and is used to help determine the best way to
1367 // format the value. In particular, when the value is a C string
1368 // (char pointer) and the other operand is an STL string object, we
1369 // want to format the C string as a string, since we know it is
1370 // compared by value with the string object. If the value is a char
1371 // pointer but the other operand is not an STL string object, we don't
1372 // know whether the pointer is supposed to point to a NUL-terminated
1373 // string, and thus want to print it as a pointer to be safe.
1374 //
1375 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1376 
1377 // The default case.
1378 template <typename ToPrint, typename OtherOperand>
1380  public:
1381  static ::std::string Format(const ToPrint& value) {
1383  }
1384 };
1385 
1386 // Array.
1387 template <typename ToPrint, size_t N, typename OtherOperand>
1388 class FormatForComparison<ToPrint[N], OtherOperand> {
1389  public:
1390  static ::std::string Format(const ToPrint* value) {
1392  }
1393 };
1394 
1395 // By default, print C string as pointers to be safe, as we don't know
1396 // whether they actually point to a NUL-terminated string.
1397 
1398 #define GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(CharType) \
1399  template <typename OtherOperand> \
1400  class FormatForComparison<CharType*, OtherOperand> { \
1401  public: \
1402  static ::std::string Format(CharType* value) { \
1403  return ::testing::PrintToString(static_cast<const void*>(value)); \
1404  } \
1405  }
1406 
1411 
1412 #undef GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_
1413 
1414 // If a C string is compared with an STL string object, we know it's meant
1415 // to point to a NUL-terminated string, and thus can print it as a string.
1416 
1417 #define GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(CharType, OtherStringType) \
1418  template <> \
1419  class FormatForComparison<CharType*, OtherStringType> { \
1420  public: \
1421  static ::std::string Format(CharType* value) { \
1422  return ::testing::PrintToString(value); \
1423  } \
1424  }
1425 
1428 
1429 #if GTEST_HAS_GLOBAL_STRING
1431 GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char, ::string);
1432 #endif
1433 
1434 #if GTEST_HAS_GLOBAL_WSTRING
1437 #endif
1438 
1439 #if GTEST_HAS_STD_WSTRING
1442 #endif
1443 
1444 #undef GTEST_IMPL_FORMAT_C_STRING_AS_STRING_
1445 
1446 // Formats a comparison assertion (e.g. ASSERT_EQ, EXPECT_LT, and etc)
1447 // operand to be used in a failure message. The type (but not value)
1448 // of the other operand may affect the format. This allows us to
1449 // print a char* as a raw pointer when it is compared against another
1450 // char* or void*, and print it as a C string when it is compared
1451 // against an std::string object, for example.
1452 //
1453 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1454 template <typename T1, typename T2>
1456  const T1& value, const T2& /* other_operand */) {
1458 }
1459 
1460 // Separate the error generating code from the code path to reduce the stack
1461 // frame size of CmpHelperEQ. This helps reduce the overhead of some sanitizers
1462 // when calling EXPECT_* in a tight loop.
1463 template <typename T1, typename T2>
1464 AssertionResult CmpHelperEQFailure(const char* expected_expression,
1465  const char* actual_expression,
1466  const T1& expected, const T2& actual) {
1467  return EqFailure(expected_expression,
1468  actual_expression,
1469  FormatForComparisonFailureMessage(expected, actual),
1470  FormatForComparisonFailureMessage(actual, expected),
1471  false);
1472 }
1473 
1474 // The helper function for {ASSERT|EXPECT}_EQ.
1475 template <typename T1, typename T2>
1476 AssertionResult CmpHelperEQ(const char* expected_expression,
1477  const char* actual_expression,
1478  const T1& expected,
1479  const T2& actual) {
1480 GTEST_DISABLE_MSC_WARNINGS_PUSH_(4389 /* signed/unsigned mismatch */)
1481  if (expected == actual) {
1482  return AssertionSuccess();
1483  }
1485 
1486  return CmpHelperEQFailure(expected_expression, actual_expression, expected,
1487  actual);
1488 }
1489 
1490 // With this overloaded version, we allow anonymous enums to be used
1491 // in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous enums
1492 // can be implicitly cast to BiggestInt.
1493 GTEST_API_ AssertionResult CmpHelperEQ(const char* expected_expression,
1494  const char* actual_expression,
1495  BiggestInt expected,
1496  BiggestInt actual);
1497 
1498 // The helper class for {ASSERT|EXPECT}_EQ. The template argument
1499 // lhs_is_null_literal is true iff the first argument to ASSERT_EQ()
1500 // is a null pointer literal. The following default implementation is
1501 // for lhs_is_null_literal being false.
1502 template <bool lhs_is_null_literal>
1503 class EqHelper {
1504  public:
1505  // This templatized version is for the general case.
1506  template <typename T1, typename T2>
1507  static AssertionResult Compare(const char* expected_expression,
1508  const char* actual_expression,
1509  const T1& expected,
1510  const T2& actual) {
1511  return CmpHelperEQ(expected_expression, actual_expression, expected,
1512  actual);
1513  }
1514 
1515  // With this overloaded version, we allow anonymous enums to be used
1516  // in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous
1517  // enums can be implicitly cast to BiggestInt.
1518  //
1519  // Even though its body looks the same as the above version, we
1520  // cannot merge the two, as it will make anonymous enums unhappy.
1521  static AssertionResult Compare(const char* expected_expression,
1522  const char* actual_expression,
1523  BiggestInt expected,
1524  BiggestInt actual) {
1525  return CmpHelperEQ(expected_expression, actual_expression, expected,
1526  actual);
1527  }
1528 };
1529 
1530 // This specialization is used when the first argument to ASSERT_EQ()
1531 // is a null pointer literal, like NULL, false, or 0.
1532 template <>
1533 class EqHelper<true> {
1534  public:
1535  // We define two overloaded versions of Compare(). The first
1536  // version will be picked when the second argument to ASSERT_EQ() is
1537  // NOT a pointer, e.g. ASSERT_EQ(0, AnIntFunction()) or
1538  // EXPECT_EQ(false, a_bool).
1539  template <typename T1, typename T2>
1541  const char* expected_expression,
1542  const char* actual_expression,
1543  const T1& expected,
1544  const T2& actual,
1545  // The following line prevents this overload from being considered if T2
1546  // is not a pointer type. We need this because ASSERT_EQ(NULL, my_ptr)
1547  // expands to Compare("", "", NULL, my_ptr), which requires a conversion
1548  // to match the Secret* in the other overload, which would otherwise make
1549  // this template match better.
1550  typename EnableIf<!is_pointer<T2>::value>::type* = 0) {
1551  return CmpHelperEQ(expected_expression, actual_expression, expected,
1552  actual);
1553  }
1554 
1555  // This version will be picked when the second argument to ASSERT_EQ() is a
1556  // pointer, e.g. ASSERT_EQ(NULL, a_pointer).
1557  template <typename T>
1559  const char* expected_expression,
1560  const char* actual_expression,
1561  // We used to have a second template parameter instead of Secret*. That
1562  // template parameter would deduce to 'long', making this a better match
1563  // than the first overload even without the first overload's EnableIf.
1564  // Unfortunately, gcc with -Wconversion-null warns when "passing NULL to
1565  // non-pointer argument" (even a deduced integral argument), so the old
1566  // implementation caused warnings in user code.
1567  Secret* /* expected (NULL) */,
1568  T* actual) {
1569  // We already know that 'expected' is a null pointer.
1570  return CmpHelperEQ(expected_expression, actual_expression,
1571  static_cast<T*>(NULL), actual);
1572  }
1573 };
1574 
1575 // Separate the error generating code from the code path to reduce the stack
1576 // frame size of CmpHelperOP. This helps reduce the overhead of some sanitizers
1577 // when calling EXPECT_OP in a tight loop.
1578 template <typename T1, typename T2>
1579 AssertionResult CmpHelperOpFailure(const char* expr1, const char* expr2,
1580  const T1& val1, const T2& val2,
1581  const char* op) {
1582  return AssertionFailure()
1583  << "Expected: (" << expr1 << ") " << op << " (" << expr2
1584  << "), actual: " << FormatForComparisonFailureMessage(val1, val2)
1585  << " vs " << FormatForComparisonFailureMessage(val2, val1);
1586 }
1587 
1588 // A macro for implementing the helper functions needed to implement
1589 // ASSERT_?? and EXPECT_??. It is here just to avoid copy-and-paste
1590 // of similar code.
1591 //
1592 // For each templatized helper function, we also define an overloaded
1593 // version for BiggestInt in order to reduce code bloat and allow
1594 // anonymous enums to be used with {ASSERT|EXPECT}_?? when compiled
1595 // with gcc 4.
1596 //
1597 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1598 
1599 #define GTEST_IMPL_CMP_HELPER_(op_name, op)\
1600 template <typename T1, typename T2>\
1601 AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \
1602  const T1& val1, const T2& val2) {\
1603  if (val1 op val2) {\
1604  return AssertionSuccess();\
1605  } else {\
1606  return CmpHelperOpFailure(expr1, expr2, val1, val2, #op);\
1607  }\
1608 }\
1609 GTEST_API_ AssertionResult CmpHelper##op_name(\
1610  const char* expr1, const char* expr2, BiggestInt val1, BiggestInt val2)
1611 
1612 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1613 
1614 // Implements the helper function for {ASSERT|EXPECT}_NE
1615 GTEST_IMPL_CMP_HELPER_(NE, !=);
1616 // Implements the helper function for {ASSERT|EXPECT}_LE
1617 GTEST_IMPL_CMP_HELPER_(LE, <=);
1618 // Implements the helper function for {ASSERT|EXPECT}_LT
1619 GTEST_IMPL_CMP_HELPER_(LT, <);
1620 // Implements the helper function for {ASSERT|EXPECT}_GE
1621 GTEST_IMPL_CMP_HELPER_(GE, >=);
1622 // Implements the helper function for {ASSERT|EXPECT}_GT
1623 GTEST_IMPL_CMP_HELPER_(GT, >);
1624 
1625 #undef GTEST_IMPL_CMP_HELPER_
1626 
1627 // The helper function for {ASSERT|EXPECT}_STREQ.
1628 //
1629 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1630 GTEST_API_ AssertionResult CmpHelperSTREQ(const char* expected_expression,
1631  const char* actual_expression,
1632  const char* expected,
1633  const char* actual);
1634 
1635 // The helper function for {ASSERT|EXPECT}_STRCASEEQ.
1636 //
1637 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1638 GTEST_API_ AssertionResult CmpHelperSTRCASEEQ(const char* expected_expression,
1639  const char* actual_expression,
1640  const char* expected,
1641  const char* actual);
1642 
1643 // The helper function for {ASSERT|EXPECT}_STRNE.
1644 //
1645 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1646 GTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression,
1647  const char* s2_expression,
1648  const char* s1,
1649  const char* s2);
1650 
1651 // The helper function for {ASSERT|EXPECT}_STRCASENE.
1652 //
1653 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1654 GTEST_API_ AssertionResult CmpHelperSTRCASENE(const char* s1_expression,
1655  const char* s2_expression,
1656  const char* s1,
1657  const char* s2);
1658 
1659 
1660 // Helper function for *_STREQ on wide strings.
1661 //
1662 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1663 GTEST_API_ AssertionResult CmpHelperSTREQ(const char* expected_expression,
1664  const char* actual_expression,
1665  const wchar_t* expected,
1666  const wchar_t* actual);
1667 
1668 // Helper function for *_STRNE on wide strings.
1669 //
1670 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1671 GTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression,
1672  const char* s2_expression,
1673  const wchar_t* s1,
1674  const wchar_t* s2);
1675 
1676 } // namespace internal
1677 
1678 // IsSubstring() and IsNotSubstring() are intended to be used as the
1679 // first argument to {EXPECT,ASSERT}_PRED_FORMAT2(), not by
1680 // themselves. They check whether needle is a substring of haystack
1681 // (NULL is considered a substring of itself only), and return an
1682 // appropriate error message when they fail.
1683 //
1684 // The {needle,haystack}_expr arguments are the stringified
1685 // expressions that generated the two real arguments.
1686 GTEST_API_ AssertionResult IsSubstring(
1687  const char* needle_expr, const char* haystack_expr,
1688  const char* needle, const char* haystack);
1689 GTEST_API_ AssertionResult IsSubstring(
1690  const char* needle_expr, const char* haystack_expr,
1691  const wchar_t* needle, const wchar_t* haystack);
1692 GTEST_API_ AssertionResult IsNotSubstring(
1693  const char* needle_expr, const char* haystack_expr,
1694  const char* needle, const char* haystack);
1695 GTEST_API_ AssertionResult IsNotSubstring(
1696  const char* needle_expr, const char* haystack_expr,
1697  const wchar_t* needle, const wchar_t* haystack);
1698 GTEST_API_ AssertionResult IsSubstring(
1699  const char* needle_expr, const char* haystack_expr,
1700  const ::std::string& needle, const ::std::string& haystack);
1701 GTEST_API_ AssertionResult IsNotSubstring(
1702  const char* needle_expr, const char* haystack_expr,
1703  const ::std::string& needle, const ::std::string& haystack);
1704 
1705 #if GTEST_HAS_STD_WSTRING
1706 GTEST_API_ AssertionResult IsSubstring(
1707  const char* needle_expr, const char* haystack_expr,
1708  const ::std::wstring& needle, const ::std::wstring& haystack);
1709 GTEST_API_ AssertionResult IsNotSubstring(
1710  const char* needle_expr, const char* haystack_expr,
1711  const ::std::wstring& needle, const ::std::wstring& haystack);
1712 #endif // GTEST_HAS_STD_WSTRING
1713 
1714 namespace internal {
1715 
1716 // Helper template function for comparing floating-points.
1717 //
1718 // Template parameter:
1719 //
1720 // RawType: the raw floating-point type (either float or double)
1721 //
1722 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1723 template <typename RawType>
1724 AssertionResult CmpHelperFloatingPointEQ(const char* expected_expression,
1725  const char* actual_expression,
1726  RawType expected,
1727  RawType actual) {
1728  const FloatingPoint<RawType> lhs(expected), rhs(actual);
1729 
1730  if (lhs.AlmostEquals(rhs)) {
1731  return AssertionSuccess();
1732  }
1733 
1734  ::std::stringstream expected_ss;
1735  expected_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
1736  << expected;
1737 
1738  ::std::stringstream actual_ss;
1739  actual_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
1740  << actual;
1741 
1742  return EqFailure(expected_expression,
1743  actual_expression,
1744  StringStreamToString(&expected_ss),
1745  StringStreamToString(&actual_ss),
1746  false);
1747 }
1748 
1749 // Helper function for implementing ASSERT_NEAR.
1750 //
1751 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1753  const char* expr2,
1754  const char* abs_error_expr,
1755  double val1,
1756  double val2,
1757  double abs_error);
1758 
1759 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
1760 // A class that enables one to stream messages to assertion macros
1762  public:
1763  // Constructor.
1765  const char* file,
1766  int line,
1767  const char* message);
1768  ~AssertHelper();
1769 
1770  // Message assignment is a semantic trick to enable assertion
1771  // streaming; see the GTEST_MESSAGE_ macro below.
1772  void operator=(const Message& message) const;
1773 
1774  private:
1775  // We put our data in a struct so that the size of the AssertHelper class can
1776  // be as small as possible. This is important because gcc is incapable of
1777  // re-using stack space even for temporary variables, so every EXPECT_EQ
1778  // reserves stack space for another AssertHelper.
1781  const char* srcfile,
1782  int line_num,
1783  const char* msg)
1784  : type(t), file(srcfile), line(line_num), message(msg) { }
1785 
1787  const char* const file;
1788  int const line;
1790 
1791  private:
1793  };
1794 
1796 
1798 };
1799 
1800 } // namespace internal
1801 
1802 #if GTEST_HAS_PARAM_TEST
1803 // The pure interface class that all value-parameterized tests inherit from.
1804 // A value-parameterized class must inherit from both ::testing::Test and
1805 // ::testing::WithParamInterface. In most cases that just means inheriting
1806 // from ::testing::TestWithParam, but more complicated test hierarchies
1807 // may need to inherit from Test and WithParamInterface at different levels.
1808 //
1809 // This interface has support for accessing the test parameter value via
1810 // the GetParam() method.
1811 //
1812 // Use it with one of the parameter generator defining functions, like Range(),
1813 // Values(), ValuesIn(), Bool(), and Combine().
1814 //
1815 // class FooTest : public ::testing::TestWithParam<int> {
1816 // protected:
1817 // FooTest() {
1818 // // Can use GetParam() here.
1819 // }
1820 // virtual ~FooTest() {
1821 // // Can use GetParam() here.
1822 // }
1823 // virtual void SetUp() {
1824 // // Can use GetParam() here.
1825 // }
1826 // virtual void TearDown {
1827 // // Can use GetParam() here.
1828 // }
1829 // };
1830 // TEST_P(FooTest, DoesBar) {
1831 // // Can use GetParam() method here.
1832 // Foo foo;
1833 // ASSERT_TRUE(foo.DoesBar(GetParam()));
1834 // }
1835 // INSTANTIATE_TEST_CASE_P(OneToTenRange, FooTest, ::testing::Range(1, 10));
1836 
1837 template <typename T>
1838 class WithParamInterface {
1839  public:
1840  typedef T ParamType;
1841  virtual ~WithParamInterface() {}
1842 
1843  // The current parameter value. Is also available in the test fixture's
1844  // constructor. This member function is non-static, even though it only
1845  // references static data, to reduce the opportunity for incorrect uses
1846  // like writing 'WithParamInterface<bool>::GetParam()' for a test that
1847  // uses a fixture whose parameter type is int.
1848  const ParamType& GetParam() const {
1849  GTEST_CHECK_(parameter_ != NULL)
1850  << "GetParam() can only be called inside a value-parameterized test "
1851  << "-- did you intend to write TEST_P instead of TEST_F?";
1852  return *parameter_;
1853  }
1854 
1855  private:
1856  // Sets parameter value. The caller is responsible for making sure the value
1857  // remains alive and unchanged throughout the current test.
1858  static void SetParam(const ParamType* parameter) {
1859  parameter_ = parameter;
1860  }
1861 
1862  // Static value used for accessing parameter during a test lifetime.
1863  static const ParamType* parameter_;
1864 
1865  // TestClass must be a subclass of WithParamInterface<T> and Test.
1866  template <class TestClass> friend class internal::ParameterizedTestFactory;
1867 };
1868 
1869 template <typename T>
1870 const T* WithParamInterface<T>::parameter_ = NULL;
1871 
1872 // Most value-parameterized classes can ignore the existence of
1873 // WithParamInterface, and can just inherit from ::testing::TestWithParam.
1874 
1875 template <typename T>
1876 class TestWithParam : public Test, public WithParamInterface<T> {
1877 };
1878 
1879 #endif // GTEST_HAS_PARAM_TEST
1880 
1881 // Macros for indicating success/failure in test code.
1882 
1883 // ADD_FAILURE unconditionally adds a failure to the current test.
1884 // SUCCEED generates a success - it doesn't automatically make the
1885 // current test successful, as a test is only successful when it has
1886 // no failure.
1887 //
1888 // EXPECT_* verifies that a certain condition is satisfied. If not,
1889 // it behaves like ADD_FAILURE. In particular:
1890 //
1891 // EXPECT_TRUE verifies that a Boolean condition is true.
1892 // EXPECT_FALSE verifies that a Boolean condition is false.
1893 //
1894 // FAIL and ASSERT_* are similar to ADD_FAILURE and EXPECT_*, except
1895 // that they will also abort the current function on failure. People
1896 // usually want the fail-fast behavior of FAIL and ASSERT_*, but those
1897 // writing data-driven tests often find themselves using ADD_FAILURE
1898 // and EXPECT_* more.
1899 
1900 // Generates a nonfatal failure with a generic message.
1901 #define ADD_FAILURE() GTEST_NONFATAL_FAILURE_("Failed")
1902 
1903 // Generates a nonfatal failure at the given source file location with
1904 // a generic message.
1905 #define ADD_FAILURE_AT(file, line) \
1906  GTEST_MESSAGE_AT_(file, line, "Failed", \
1907  ::testing::TestPartResult::kNonFatalFailure)
1908 
1909 // Generates a fatal failure with a generic message.
1910 #define GTEST_FAIL() GTEST_FATAL_FAILURE_("Failed")
1911 
1912 // Define this macro to 1 to omit the definition of FAIL(), which is a
1913 // generic name and clashes with some other libraries.
1914 #if !GTEST_DONT_DEFINE_FAIL
1915 # define FAIL() GTEST_FAIL()
1916 #endif
1917 
1918 // Generates a success with a generic message.
1919 #define GTEST_SUCCEED() GTEST_SUCCESS_("Succeeded")
1920 
1921 // Define this macro to 1 to omit the definition of SUCCEED(), which
1922 // is a generic name and clashes with some other libraries.
1923 #if !GTEST_DONT_DEFINE_SUCCEED
1924 # define SUCCEED() GTEST_SUCCEED()
1925 #endif
1926 
1927 // Macros for testing exceptions.
1928 //
1929 // * {ASSERT|EXPECT}_THROW(statement, expected_exception):
1930 // Tests that the statement throws the expected exception.
1931 // * {ASSERT|EXPECT}_NO_THROW(statement):
1932 // Tests that the statement doesn't throw any exception.
1933 // * {ASSERT|EXPECT}_ANY_THROW(statement):
1934 // Tests that the statement throws an exception.
1935 
1936 #define EXPECT_THROW(statement, expected_exception) \
1937  GTEST_TEST_THROW_(statement, expected_exception, GTEST_NONFATAL_FAILURE_)
1938 #define EXPECT_NO_THROW(statement) \
1939  GTEST_TEST_NO_THROW_(statement, GTEST_NONFATAL_FAILURE_)
1940 #define EXPECT_ANY_THROW(statement) \
1941  GTEST_TEST_ANY_THROW_(statement, GTEST_NONFATAL_FAILURE_)
1942 #define ASSERT_THROW(statement, expected_exception) \
1943  GTEST_TEST_THROW_(statement, expected_exception, GTEST_FATAL_FAILURE_)
1944 #define ASSERT_NO_THROW(statement) \
1945  GTEST_TEST_NO_THROW_(statement, GTEST_FATAL_FAILURE_)
1946 #define ASSERT_ANY_THROW(statement) \
1947  GTEST_TEST_ANY_THROW_(statement, GTEST_FATAL_FAILURE_)
1948 
1949 // Boolean assertions. Condition can be either a Boolean expression or an
1950 // AssertionResult. For more information on how to use AssertionResult with
1951 // these macros see comments on that class.
1952 #define EXPECT_TRUE(condition) \
1953  GTEST_TEST_BOOLEAN_(condition, #condition, false, true, \
1954  GTEST_NONFATAL_FAILURE_)
1955 #define EXPECT_FALSE(condition) \
1956  GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \
1957  GTEST_NONFATAL_FAILURE_)
1958 #define ASSERT_TRUE(condition) \
1959  GTEST_TEST_BOOLEAN_(condition, #condition, false, true, \
1960  GTEST_FATAL_FAILURE_)
1961 #define ASSERT_FALSE(condition) \
1962  GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \
1963  GTEST_FATAL_FAILURE_)
1964 
1965 // Includes the auto-generated header that implements a family of
1966 // generic predicate assertion macros.
1967 #include "gtest/gtest_pred_impl.h"
1968 
1969 // Macros for testing equalities and inequalities.
1970 //
1971 // * {ASSERT|EXPECT}_EQ(expected, actual): Tests that expected == actual
1972 // * {ASSERT|EXPECT}_NE(v1, v2): Tests that v1 != v2
1973 // * {ASSERT|EXPECT}_LT(v1, v2): Tests that v1 < v2
1974 // * {ASSERT|EXPECT}_LE(v1, v2): Tests that v1 <= v2
1975 // * {ASSERT|EXPECT}_GT(v1, v2): Tests that v1 > v2
1976 // * {ASSERT|EXPECT}_GE(v1, v2): Tests that v1 >= v2
1977 //
1978 // When they are not, Google Test prints both the tested expressions and
1979 // their actual values. The values must be compatible built-in types,
1980 // or you will get a compiler error. By "compatible" we mean that the
1981 // values can be compared by the respective operator.
1982 //
1983 // Note:
1984 //
1985 // 1. It is possible to make a user-defined type work with
1986 // {ASSERT|EXPECT}_??(), but that requires overloading the
1987 // comparison operators and is thus discouraged by the Google C++
1988 // Usage Guide. Therefore, you are advised to use the
1989 // {ASSERT|EXPECT}_TRUE() macro to assert that two objects are
1990 // equal.
1991 //
1992 // 2. The {ASSERT|EXPECT}_??() macros do pointer comparisons on
1993 // pointers (in particular, C strings). Therefore, if you use it
1994 // with two C strings, you are testing how their locations in memory
1995 // are related, not how their content is related. To compare two C
1996 // strings by content, use {ASSERT|EXPECT}_STR*().
1997 //
1998 // 3. {ASSERT|EXPECT}_EQ(expected, actual) is preferred to
1999 // {ASSERT|EXPECT}_TRUE(expected == actual), as the former tells you
2000 // what the actual value is when it fails, and similarly for the
2001 // other comparisons.
2002 //
2003 // 4. Do not depend on the order in which {ASSERT|EXPECT}_??()
2004 // evaluate their arguments, which is undefined.
2005 //
2006 // 5. These macros evaluate their arguments exactly once.
2007 //
2008 // Examples:
2009 //
2010 // EXPECT_NE(5, Foo());
2011 // EXPECT_EQ(NULL, a_pointer);
2012 // ASSERT_LT(i, array_size);
2013 // ASSERT_GT(records.size(), 0) << "There is no record left.";
2014 
2015 #define EXPECT_EQ(expected, actual) \
2016  EXPECT_PRED_FORMAT2(::testing::internal:: \
2017  EqHelper<GTEST_IS_NULL_LITERAL_(expected)>::Compare, \
2018  expected, actual)
2019 #define EXPECT_NE(expected, actual) \
2020  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperNE, expected, actual)
2021 #define EXPECT_LE(val1, val2) \
2022  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2)
2023 #define EXPECT_LT(val1, val2) \
2024  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2)
2025 #define EXPECT_GE(val1, val2) \
2026  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2)
2027 #define EXPECT_GT(val1, val2) \
2028  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2)
2029 
2030 #define GTEST_ASSERT_EQ(expected, actual) \
2031  ASSERT_PRED_FORMAT2(::testing::internal:: \
2032  EqHelper<GTEST_IS_NULL_LITERAL_(expected)>::Compare, \
2033  expected, actual)
2034 #define GTEST_ASSERT_NE(val1, val2) \
2035  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2)
2036 #define GTEST_ASSERT_LE(val1, val2) \
2037  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2)
2038 #define GTEST_ASSERT_LT(val1, val2) \
2039  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2)
2040 #define GTEST_ASSERT_GE(val1, val2) \
2041  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2)
2042 #define GTEST_ASSERT_GT(val1, val2) \
2043  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2)
2044 
2045 // Define macro GTEST_DONT_DEFINE_ASSERT_XY to 1 to omit the definition of
2046 // ASSERT_XY(), which clashes with some users' own code.
2047 
2048 #if !GTEST_DONT_DEFINE_ASSERT_EQ
2049 # define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2)
2050 #endif
2051 
2052 #if !GTEST_DONT_DEFINE_ASSERT_NE
2053 # define ASSERT_NE(val1, val2) GTEST_ASSERT_NE(val1, val2)
2054 #endif
2055 
2056 #if !GTEST_DONT_DEFINE_ASSERT_LE
2057 # define ASSERT_LE(val1, val2) GTEST_ASSERT_LE(val1, val2)
2058 #endif
2059 
2060 #if !GTEST_DONT_DEFINE_ASSERT_LT
2061 # define ASSERT_LT(val1, val2) GTEST_ASSERT_LT(val1, val2)
2062 #endif
2063 
2064 #if !GTEST_DONT_DEFINE_ASSERT_GE
2065 # define ASSERT_GE(val1, val2) GTEST_ASSERT_GE(val1, val2)
2066 #endif
2067 
2068 #if !GTEST_DONT_DEFINE_ASSERT_GT
2069 # define ASSERT_GT(val1, val2) GTEST_ASSERT_GT(val1, val2)
2070 #endif
2071 
2072 // C-string Comparisons. All tests treat NULL and any non-NULL string
2073 // as different. Two NULLs are equal.
2074 //
2075 // * {ASSERT|EXPECT}_STREQ(s1, s2): Tests that s1 == s2
2076 // * {ASSERT|EXPECT}_STRNE(s1, s2): Tests that s1 != s2
2077 // * {ASSERT|EXPECT}_STRCASEEQ(s1, s2): Tests that s1 == s2, ignoring case
2078 // * {ASSERT|EXPECT}_STRCASENE(s1, s2): Tests that s1 != s2, ignoring case
2079 //
2080 // For wide or narrow string objects, you can use the
2081 // {ASSERT|EXPECT}_??() macros.
2082 //
2083 // Don't depend on the order in which the arguments are evaluated,
2084 // which is undefined.
2085 //
2086 // These macros evaluate their arguments exactly once.
2087 
2088 #define EXPECT_STREQ(expected, actual) \
2089  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, expected, actual)
2090 #define EXPECT_STRNE(s1, s2) \
2091  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2)
2092 #define EXPECT_STRCASEEQ(expected, actual) \
2093  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, expected, actual)
2094 #define EXPECT_STRCASENE(s1, s2)\
2095  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2)
2096 
2097 #define ASSERT_STREQ(expected, actual) \
2098  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, expected, actual)
2099 #define ASSERT_STRNE(s1, s2) \
2100  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2)
2101 #define ASSERT_STRCASEEQ(expected, actual) \
2102  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, expected, actual)
2103 #define ASSERT_STRCASENE(s1, s2)\
2104  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2)
2105 
2106 // Macros for comparing floating-point numbers.
2107 //
2108 // * {ASSERT|EXPECT}_FLOAT_EQ(expected, actual):
2109 // Tests that two float values are almost equal.
2110 // * {ASSERT|EXPECT}_DOUBLE_EQ(expected, actual):
2111 // Tests that two double values are almost equal.
2112 // * {ASSERT|EXPECT}_NEAR(v1, v2, abs_error):
2113 // Tests that v1 and v2 are within the given distance to each other.
2114 //
2115 // Google Test uses ULP-based comparison to automatically pick a default
2116 // error bound that is appropriate for the operands. See the
2117 // FloatingPoint template class in gtest-internal.h if you are
2118 // interested in the implementation details.
2119 
2120 #define EXPECT_FLOAT_EQ(expected, actual)\
2121  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \
2122  expected, actual)
2123 
2124 #define EXPECT_DOUBLE_EQ(expected, actual)\
2125  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \
2126  expected, actual)
2127 
2128 #define ASSERT_FLOAT_EQ(expected, actual)\
2129  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \
2130  expected, actual)
2131 
2132 #define ASSERT_DOUBLE_EQ(expected, actual)\
2133  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \
2134  expected, actual)
2135 
2136 #define EXPECT_NEAR(val1, val2, abs_error)\
2137  EXPECT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, \
2138  val1, val2, abs_error)
2139 
2140 #define ASSERT_NEAR(val1, val2, abs_error)\
2141  ASSERT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, \
2142  val1, val2, abs_error)
2143 
2144 // These predicate format functions work on floating-point values, and
2145 // can be used in {ASSERT|EXPECT}_PRED_FORMAT2*(), e.g.
2146 //
2147 // EXPECT_PRED_FORMAT2(testing::DoubleLE, Foo(), 5.0);
2148 
2149 // Asserts that val1 is less than, or almost equal to, val2. Fails
2150 // otherwise. In particular, it fails if either val1 or val2 is NaN.
2151 GTEST_API_ AssertionResult FloatLE(const char* expr1, const char* expr2,
2152  float val1, float val2);
2153 GTEST_API_ AssertionResult DoubleLE(const char* expr1, const char* expr2,
2154  double val1, double val2);
2155 
2156 
2157 #if GTEST_OS_WINDOWS
2158 
2159 // Macros that test for HRESULT failure and success, these are only useful
2160 // on Windows, and rely on Windows SDK macros and APIs to compile.
2161 //
2162 // * {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED}(expr)
2163 //
2164 // When expr unexpectedly fails or succeeds, Google Test prints the
2165 // expected result and the actual result with both a human-readable
2166 // string representation of the error, if available, as well as the
2167 // hex result code.
2168 # define EXPECT_HRESULT_SUCCEEDED(expr) \
2169  EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr))
2170 
2171 # define ASSERT_HRESULT_SUCCEEDED(expr) \
2172  ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr))
2173 
2174 # define EXPECT_HRESULT_FAILED(expr) \
2175  EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr))
2176 
2177 # define ASSERT_HRESULT_FAILED(expr) \
2178  ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr))
2179 
2180 #endif // GTEST_OS_WINDOWS
2181 
2182 // Macros that execute statement and check that it doesn't generate new fatal
2183 // failures in the current thread.
2184 //
2185 // * {ASSERT|EXPECT}_NO_FATAL_FAILURE(statement);
2186 //
2187 // Examples:
2188 //
2189 // EXPECT_NO_FATAL_FAILURE(Process());
2190 // ASSERT_NO_FATAL_FAILURE(Process()) << "Process() failed";
2191 //
2192 #define ASSERT_NO_FATAL_FAILURE(statement) \
2193  GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_FATAL_FAILURE_)
2194 #define EXPECT_NO_FATAL_FAILURE(statement) \
2195  GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_NONFATAL_FAILURE_)
2196 
2197 // Causes a trace (including the source file path, the current line
2198 // number, and the given message) to be included in every test failure
2199 // message generated by code in the current scope. The effect is
2200 // undone when the control leaves the current scope.
2201 //
2202 // The message argument can be anything streamable to std::ostream.
2203 //
2204 // In the implementation, we include the current line number as part
2205 // of the dummy variable name, thus allowing multiple SCOPED_TRACE()s
2206 // to appear in the same block - as long as they are on different
2207 // lines.
2208 #define SCOPED_TRACE(message) \
2209  ::testing::internal::ScopedTrace GTEST_CONCAT_TOKEN_(gtest_trace_, __LINE__)(\
2210  __FILE__, __LINE__, ::testing::Message() << (message))
2211 
2212 // Compile-time assertion for type equality.
2213 // StaticAssertTypeEq<type1, type2>() compiles iff type1 and type2 are
2214 // the same type. The value it returns is not interesting.
2215 //
2216 // Instead of making StaticAssertTypeEq a class template, we make it a
2217 // function template that invokes a helper class template. This
2218 // prevents a user from misusing StaticAssertTypeEq<T1, T2> by
2219 // defining objects of that type.
2220 //
2221 // CAVEAT:
2222 //
2223 // When used inside a method of a class template,
2224 // StaticAssertTypeEq<T1, T2>() is effective ONLY IF the method is
2225 // instantiated. For example, given:
2226 //
2227 // template <typename T> class Foo {
2228 // public:
2229 // void Bar() { testing::StaticAssertTypeEq<int, T>(); }
2230 // };
2231 //
2232 // the code:
2233 //
2234 // void Test1() { Foo<bool> foo; }
2235 //
2236 // will NOT generate a compiler error, as Foo<bool>::Bar() is never
2237 // actually instantiated. Instead, you need:
2238 //
2239 // void Test2() { Foo<bool> foo; foo.Bar(); }
2240 //
2241 // to cause a compiler error.
2242 template <typename T1, typename T2>
2245  return true;
2246 }
2247 
2248 // Defines a test.
2249 //
2250 // The first parameter is the name of the test case, and the second
2251 // parameter is the name of the test within the test case.
2252 //
2253 // The convention is to end the test case name with "Test". For
2254 // example, a test case for the Foo class can be named FooTest.
2255 //
2256 // Test code should appear between braces after an invocation of
2257 // this macro. Example:
2258 //
2259 // TEST(FooTest, InitializesCorrectly) {
2260 // Foo foo;
2261 // EXPECT_TRUE(foo.StatusIsOK());
2262 // }
2263 
2264 // Note that we call GetTestTypeId() instead of GetTypeId<
2265 // ::testing::Test>() here to get the type ID of testing::Test. This
2266 // is to work around a suspected linker bug when using Google Test as
2267 // a framework on Mac OS X. The bug causes GetTypeId<
2268 // ::testing::Test>() to return different values depending on whether
2269 // the call is from the Google Test framework itself or from user test
2270 // code. GetTestTypeId() is guaranteed to always return the same
2271 // value, as it always calls GetTypeId<>() from the Google Test
2272 // framework.
2273 #define GTEST_TEST(test_case_name, test_name)\
2274  GTEST_TEST_(test_case_name, test_name, \
2275  ::testing::Test, ::testing::internal::GetTestTypeId())
2276 
2277 // Define this macro to 1 to omit the definition of TEST(), which
2278 // is a generic name and clashes with some other libraries.
2279 #if !GTEST_DONT_DEFINE_TEST
2280 # define TEST(test_case_name, test_name) GTEST_TEST(test_case_name, test_name)
2281 #endif
2282 
2283 // Defines a test that uses a test fixture.
2284 //
2285 // The first parameter is the name of the test fixture class, which
2286 // also doubles as the test case name. The second parameter is the
2287 // name of the test within the test case.
2288 //
2289 // A test fixture class must be declared earlier. The user should put
2290 // his test code between braces after using this macro. Example:
2291 //
2292 // class FooTest : public testing::Test {
2293 // protected:
2294 // virtual void SetUp() { b_.AddElement(3); }
2295 //
2296 // Foo a_;
2297 // Foo b_;
2298 // };
2299 //
2300 // TEST_F(FooTest, InitializesCorrectly) {
2301 // EXPECT_TRUE(a_.StatusIsOK());
2302 // }
2303 //
2304 // TEST_F(FooTest, ReturnsElementCountCorrectly) {
2305 // EXPECT_EQ(0, a_.size());
2306 // EXPECT_EQ(1, b_.size());
2307 // }
2308 
2309 #define TEST_F(test_fixture, test_name)\
2310  GTEST_TEST_(test_fixture, test_name, test_fixture, \
2311  ::testing::internal::GetTypeId<test_fixture>())
2312 
2313 } // namespace testing
2314 
2315 // Use this function in main() to run all tests. It returns 0 if all
2316 // tests are successful, or 1 otherwise.
2317 //
2318 // RUN_ALL_TESTS() should be invoked after the command line has been
2319 // parsed by InitGoogleTest().
2320 //
2321 // This function was formerly a macro; thus, it is in the global
2322 // namespace and has an all-caps name.
2324 
2325 inline int RUN_ALL_TESTS() {
2326  return ::testing::UnitTest::GetInstance()->Run();
2327 }
2328 
2329 #endif // GTEST_INCLUDE_GTEST_GTEST_H_
const internal::GTestFlagSaver *const gtest_flag_saver_
Definition: gtest.h:456
class UnitTestImpl * GetUnitTestImpl()
internal::SetUpTestCaseFunc SetUpTestCaseFunc
Definition: gtest.h:377
const char * type_param() const
Definition: gtest.h:796
::std::string Format(const ToPrint &value)
Definition: gtest.h:1381
void ReportFailureInUnknownLocation(TestPartResult::Type result_type, const std::string &message)
Definition: gtest.cc:2212
Environment * AddGlobalTestEnvironment(Environment *env)
Definition: gtest.h:1342
virtual void SetUp()
Definition: gtest.h:970
virtual void OnTestProgramStart(const UnitTest &)
Definition: gtest.h:1038
virtual void OnEnvironmentsSetUpEnd(const UnitTest &)
Definition: gtest.h:1042
int death_test_count() const
Definition: gtest.h:606
static AssertionResult Compare(const char *expected_expression, const char *actual_expression, Secret *, T *actual)
Definition: gtest.h:1558
std::vector< TestInfo * > test_info_list_
Definition: gtest.h:929
static void SetUpTestCase()
Definition: gtest.h:389
GTEST_API_ AssertionResult AssertionFailure()
Definition: gtest.cc:978
const std::vector< TestProperty > & test_properties() const
Definition: gtest.h:580
bool should_run_
Definition: gtest.h:753
GTEST_DECLARE_int32_(random_seed)
bool Passed() const
Definition: gtest.h:827
virtual ~TestEventListener()
Definition: gtest.h:985
#define GTEST_DISABLE_MSC_WARNINGS_POP_()
Definition: gtest-port.h:363
internal::TestEventRepeater * repeater_
Definition: gtest.h:1123
static AssertionResult Compare(const char *expected_expression, const char *actual_expression, BiggestInt expected, BiggestInt actual)
Definition: gtest.h:1521
static bool TestFailed(const TestInfo *test_info)
Definition: gtest.h:891
::std::string PrintToString(const T &value)
AssertionResult CmpHelperFloatingPointEQ(const char *expected_expression, const char *actual_expression, RawType expected, RawType actual)
Definition: gtest.h:1724
static bool TestReportableDisabled(const TestInfo *test_info)
Definition: gtest.h:897
const internal::UnitTestImpl * impl() const
Definition: gtest.h:1280
static void ClearTestResult(TestInfo *test_info)
Definition: gtest.h:739
internal::Mutex test_properites_mutex_
Definition: gtest.h:619
std::string name_
Definition: gtest.h:923
virtual void OnTestCaseEnd(const TestCase &)
Definition: gtest.h:1047
const std::vector< TestPartResult > & test_part_results() const
Definition: gtest.h:575
int increment_death_test_count()
Definition: gtest.h:609
GTEST_API_ AssertionResult CmpHelperSTRCASENE(const char *s1_expression, const char *s2_expression, const char *s1, const char *s2)
Definition: gtest.cc:1496
bool should_run() const
Definition: gtest.h:803
::std::string string
Definition: gtest-port.h:1129
const char * key() const
Definition: gtest.h:497
static bool HasFailure()
Definition: gtest.h:407
TimeInMillis elapsed_time_
Definition: gtest.h:941
bool matches_filter_
Definition: gtest.h:755
::std::wstring wstring
Definition: gtest-port.h:1135
void ClearResult()
Definition: gtest.cc:2743
GTEST_DECLARE_bool_(also_run_disabled_tests)
AssertionResult CmpHelperEQFailure(const char *expected_expression, const char *actual_expression, const T1 &expected, const T2 &actual)
Definition: gtest.h:1464
void set_elapsed_time(TimeInMillis elapsed)
Definition: gtest.h:585
TestEventListener * default_xml_generator() const
Definition: gtest.h:1087
GTEST_API_ AssertionResult DoubleNearPredFormat(const char *expr1, const char *expr2, const char *abs_error_expr, double val1, double val2, double abs_error)
Definition: gtest.cc:1325
virtual void OnTestPartResult(const TestPartResult &)
Definition: gtest.h:1045
std::vector< TestInfo * > & test_info_list()
Definition: gtest.h:848
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char,::std::string)
internal::TearDownTestCaseFunc TearDownTestCaseFunc
Definition: gtest.h:378
static AssertionResult Compare(const char *expected_expression, const char *actual_expression, const T1 &expected, const T2 &actual, typename EnableIf<!is_pointer< T2 >::value >::type *=0)
Definition: gtest.h:1540
#define GTEST_API_
Definition: gtest-port.h:966
GTEST_API_ TestInfo * MakeAndRegisterTestInfo(const char *test_case_name, const char *name, const char *type_param, const char *value_param, TypeId fixture_class_id, SetUpTestCaseFunc set_up_tc, TearDownTestCaseFunc tear_down_tc, TestFactoryBase *factory)
Definition: gtest.cc:2502
std::string FormatForComparisonFailureMessage(const T1 &value, const T2 &)
Definition: gtest.h:1455
TypeWithSize< 8 >::Int TimeInMillis
Definition: gtest-port.h:2440
#define GTEST_LOCK_EXCLUDED_(locks)
Definition: gtest-port.h:2464
AssertHelperData *const data_
Definition: gtest.h:1795
virtual void OnEnvironmentsTearDownEnd(const UnitTest &)
Definition: gtest.h:1049
unsigned int i
Definition: unit1303.c:79
const char * failure_message() const
Definition: gtest.h:302
void AppendMessage(const Message &a_message)
Definition: gtest.h:320
void SetValue(const std::string &new_value)
Definition: gtest.h:507
const std::string name_
Definition: gtest.h:745
internal::scoped_ptr< ::std::string > message_
Definition: gtest.h:335
TestResult result_
Definition: gtest.h:762
int increment_death_test_count()
Definition: gtest.h:731
internal::TestFactoryBase *const factory_
Definition: gtest.h:757
const void * TypeId
const internal::TypeId fixture_class_id_
Definition: gtest.h:752
int death_test_count_
Definition: gtest.h:626
trace
Definition: tool_sdecls.h:122
bool Failed() const
Definition: gtest.cc:2133
AssertionResult(const T &success, typename internal::EnableIf< !internal::ImplicitlyConvertible< T, AssertionResult >::value >::type *=NULL)
Definition: gtest.h:272
TestResult ad_hoc_test_result_
Definition: gtest.h:944
virtual Setup_should_be_spelled_SetUp * Setup()
Definition: gtest.h:978
const std::vector< TestInfo * > & test_info_list() const
Definition: gtest.h:851
GTEST_IMPL_CMP_HELPER_(NE,!=)
bool is_reportable() const
Definition: gtest.h:692
UNITTEST_START char * output
Definition: unit1302.c:50
const char * name() const
Definition: gtest.h:655
const char * message() const
Definition: gtest.h:297
GTEST_API_ AssertionResult AssertionSuccess()
Definition: gtest.cc:973
#define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
Definition: gtest-port.h:362
bool Passed() const
Definition: gtest.h:540
#define GTEST_CHECK_(condition)
Definition: gtest-port.h:1322
AssertionResult & operator<<(const T &value)
Definition: gtest.h:305
const internal::scoped_ptr< const ::std::string > type_param_
Definition: gtest.h:748
const int kMaxStackTraceDepth
Definition: gtest.h:147
std::vector< TestPartResult > test_part_results_
Definition: gtest.h:622
std::vector< TestProperty > test_properties_
Definition: gtest.h:624
static bool TestPassed(const TestInfo *test_info)
Definition: gtest.h:886
GTEST_DECLARE_string_(death_test_style)
AssertionResult CmpHelperOpFailure(const char *expr1, const char *expr2, const T1 &val1, const T2 &val2, const char *op)
Definition: gtest.h:1579
const internal::scoped_ptr< const ::std::string > type_param_
Definition: gtest.h:926
void(* SetUpTestCaseFunc)()
bool should_run_
Definition: gtest.h:939
void(* TearDownTestCaseFunc)()
Test::SetUpTestCaseFunc set_up_tc_
Definition: gtest.h:935
virtual Setup_should_be_spelled_SetUp * Setup()
Definition: gtest.h:475
virtual void OnTestIterationStart(const UnitTest &, int)
Definition: gtest.h:1039
long long BiggestInt
Definition: gtest-port.h:2183
const char * value_param() const
Definition: gtest.h:667
std::string GetString() const
Definition: gtest.cc:944
GTEST_API_ AssertionResult IsSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
Definition: gtest.cc:1569
GTEST_API_ AssertionResult CmpHelperSTRCASEEQ(const char *expected_expression, const char *actual_expression, const char *expected, const char *actual)
Definition: gtest.cc:1466
AssertHelperData(TestPartResult::Type t, const char *srcfile, int line_num, const char *msg)
Definition: gtest.h:1780
const char * test_case_name() const
Definition: gtest.h:652
std::string name_
Definition: gtest.cc:2563
void DeleteSelf_()
Definition: gtest.h:453
GTEST_API_ AssertionResult CmpHelperSTRNE(const char *s1_expression, const char *s2_expression, const char *s1, const char *s2)
Definition: gtest.cc:1482
const TestResult & ad_hoc_test_result() const
Definition: gtest.h:841
virtual void OnEnvironmentsTearDownStart(const UnitTest &)
Definition: gtest.h:1048
virtual ~Environment()
Definition: gtest.h:967
#define true
Environment * AddEnvironment(Environment *env)
Definition: gtest.cc:4058
AssertionResult & operator<<(::std::ostream &(*basic_manipulator)(::std::ostream &stream))
Definition: gtest.h:312
Test::TearDownTestCaseFunc tear_down_tc_
Definition: gtest.h:937
internal::UnitTestImpl * impl()
Definition: gtest.h:1279
virtual void OnTestCaseStart(const TestCase &)
Definition: gtest.h:1043
virtual void OnTestProgramEnd(const UnitTest &)
Definition: gtest.h:1052
static void ClearTestCaseResult(TestCase *test_case)
Definition: gtest.h:870
static bool TestDisabled(const TestInfo *test_info)
Definition: gtest.h:902
GTEST_API_ AssertionResult EqFailure(const char *expected_expression, const char *actual_expression, const std::string &expected_value, const std::string &actual_value, bool ignoring_case)
Definition: gtest.cc:1275
AssertionResult CmpHelperEQ(const char *expected_expression, const char *actual_expression, const T1 &expected, const T2 &actual)
Definition: gtest.h:1476
TestProperty(const std::string &a_key, const std::string &a_value)
Definition: gtest.h:492
static bool TestReportable(const TestInfo *test_info)
Definition: gtest.h:907
TestEventListener * default_xml_generator_
Definition: gtest.h:1127
virtual void OnTestIterationEnd(const UnitTest &, int)
Definition: gtest.h:1050
Append
void RunTearDownTestCase()
Definition: gtest.h:883
TimeInMillis elapsed_time_
Definition: gtest.h:628
TestEventListener * default_result_printer_
Definition: gtest.h:1125
bool Failed() const
Definition: gtest.h:830
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
Definition: gtest-port.h:906
GTEST_API_ std::string StringStreamToString(::std::stringstream *stream)
Definition: gtest.cc:1945
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition: gtest.h:2325
bool StaticAssertTypeEq()
Definition: gtest.h:2243
virtual void OnEnvironmentsSetUpStart(const UnitTest &)
Definition: gtest.h:1041
bool is_disabled_
Definition: gtest.h:754
GTEST_API_ AssertionResult DoubleLE(const char *expr1, const char *expr2, double val1, double val2)
Definition: gtest.cc:1391
void set_should_run(bool should)
Definition: gtest.h:860
UNITTEST_START int * value
Definition: unit1602.c:51
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition: gtest.cc:5292
const char * name() const
Definition: gtest.h:792
TimeInMillis elapsed_time() const
Definition: gtest.h:833
const TestResult * result() const
Definition: gtest.h:700
GTEST_API_ AssertionResult IsNotSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
Definition: gtest.cc:1581
static UnitTest * GetInstance()
Definition: gtest.cc:3935
std::string value_
Definition: gtest.h:515
GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(char)
TestEventListener * default_result_printer() const
Definition: gtest.h:1076
GTEST_API_ AssertionResult CmpHelperSTREQ(const char *expected_expression, const char *actual_expression, const char *expected, const char *actual)
Definition: gtest.cc:1450
const char * type_param() const
Definition: gtest.h:659
bool should_run() const
Definition: gtest.h:689
virtual void OnTestStart(const TestInfo &)
Definition: gtest.h:1044
const char * value() const
Definition: gtest.h:502
void swap(scoped_ptr< T > &, scoped_ptr< T > &)
const internal::scoped_ptr< const ::std::string > value_param_
Definition: gtest.h:751
const char * name
Definition: curl_sasl.c:54
IMETHOD void random(Vector &a)
static bool ShouldRunTest(const TestInfo *test_info)
Definition: gtest.h:912
static AssertionResult Compare(const char *expected_expression, const char *actual_expression, const T1 &expected, const T2 &actual)
Definition: gtest.h:1507
virtual void OnTestEnd(const TestInfo &)
Definition: gtest.h:1046
int key
Definition: unit1602.c:56
std::vector< int > test_indices_
Definition: gtest.h:933
static void TearDownTestCase()
Definition: gtest.h:397
#define GTEST_MUST_USE_RESULT_
Definition: gtest-port.h:918
virtual void TearDown()
Definition: gtest.h:973
std::string key_
Definition: gtest.h:513
GTEST_API_ AssertionResult FloatLE(const char *expr1, const char *expr2, float val1, float val2)
Definition: gtest.cc:1384
void RunSetUpTestCase()
Definition: gtest.h:879
const std::string test_case_name_
Definition: gtest.h:744
TimeInMillis elapsed_time() const
Definition: gtest.h:552


rc_tagdetect_client
Author(s): Monika Florek-Jasinska , Raphael Schaller
autogenerated on Sat Feb 13 2021 03:42:13