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


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Tue Jan 19 2021 03:12:00