OLD | NEW |
1 // Copyright 2005, Google Inc. | 1 // Copyright 2005, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 // T must be contextually convertible to bool. | 266 // T must be contextually convertible to bool. |
267 // | 267 // |
268 // The second parameter prevents this overload from being considered if | 268 // The second parameter prevents this overload from being considered if |
269 // the argument is implicitly convertible to AssertionResult. In that case | 269 // the argument is implicitly convertible to AssertionResult. In that case |
270 // we want AssertionResult's copy constructor to be used. | 270 // we want AssertionResult's copy constructor to be used. |
271 template <typename T> | 271 template <typename T> |
272 explicit AssertionResult( | 272 explicit AssertionResult( |
273 const T& success, | 273 const T& success, |
274 typename internal::EnableIf< | 274 typename internal::EnableIf< |
275 !internal::ImplicitlyConvertible<T, AssertionResult>::value>::type* | 275 !internal::ImplicitlyConvertible<T, AssertionResult>::value>::type* |
276 /*enabler*/ = NULL) | 276 /*enabler*/ = NULL) |
277 : success_(success) {} | 277 : success_(success) {} |
278 | 278 |
279 GTEST_DISABLE_MSC_WARNINGS_POP_() | 279 GTEST_DISABLE_MSC_WARNINGS_POP_() |
280 | 280 |
281 // Assignment operator. | 281 // Assignment operator. |
282 AssertionResult& operator=(AssertionResult other) { | 282 AssertionResult& operator=(AssertionResult other) { |
283 swap(other); | 283 swap(other); |
284 return *this; | 284 return *this; |
285 } | 285 } |
286 | 286 |
287 // Returns true iff the assertion succeeded. | 287 // Returns true iff the assertion succeeded. |
288 operator bool() const { return success_; } // NOLINT | 288 operator bool() const { return success_; } // NOLINT |
289 | 289 |
290 // Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE. | 290 // Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE. |
291 AssertionResult operator!() const; | 291 AssertionResult operator!() const; |
292 | 292 |
293 // Returns the text streamed into this AssertionResult. Test assertions | 293 // Returns the text streamed into this AssertionResult. Test assertions |
294 // use it when they fail (i.e., the predicate's outcome doesn't match the | 294 // use it when they fail (i.e., the predicate's outcome doesn't match the |
295 // assertion's expectation). When nothing has been streamed into the | 295 // assertion's expectation). When nothing has been streamed into the |
296 // object, returns an empty string. | 296 // object, returns an empty string. |
297 const char* message() const { | 297 const char* message() const { |
298 return message_.get() != NULL ? message_->c_str() : ""; | 298 return message_.get() != NULL ? message_->c_str() : ""; |
299 } | 299 } |
300 // TODO(vladl@google.com): Remove this after making sure no clients use it. | 300 // TODO(vladl@google.com): Remove this after making sure no clients use it. |
301 // Deprecated; please use message() instead. | 301 // Deprecated; please use message() instead. |
302 const char* failure_message() const { return message(); } | 302 const char* failure_message() const { return message(); } |
303 | 303 |
304 // Streams a custom failure message into this object. | 304 // Streams a custom failure message into this object. |
305 template <typename T> AssertionResult& operator<<(const T& value) { | 305 template <typename T> |
| 306 AssertionResult& operator<<(const T& value) { |
306 AppendMessage(Message() << value); | 307 AppendMessage(Message() << value); |
307 return *this; | 308 return *this; |
308 } | 309 } |
309 | 310 |
310 // Allows streaming basic output manipulators such as endl or flush into | 311 // Allows streaming basic output manipulators such as endl or flush into |
311 // this object. | 312 // this object. |
312 AssertionResult& operator<<( | 313 AssertionResult& operator<<( |
313 ::std::ostream& (*basic_manipulator)(::std::ostream& stream)) { | 314 ::std::ostream& (*basic_manipulator)(::std::ostream& stream)) { |
314 AppendMessage(Message() << basic_manipulator); | 315 AppendMessage(Message() << basic_manipulator); |
315 return *this; | 316 return *this; |
316 } | 317 } |
317 | 318 |
318 private: | 319 private: |
319 // Appends the contents of message to message_. | 320 // Appends the contents of message to message_. |
320 void AppendMessage(const Message& a_message) { | 321 void AppendMessage(const Message& a_message) { |
321 if (message_.get() == NULL) | 322 if (message_.get() == NULL) message_.reset(new ::std::string); |
322 message_.reset(new ::std::string); | |
323 message_->append(a_message.GetString().c_str()); | 323 message_->append(a_message.GetString().c_str()); |
324 } | 324 } |
325 | 325 |
326 // Swap the contents of this AssertionResult with other. | 326 // Swap the contents of this AssertionResult with other. |
327 void swap(AssertionResult& other); | 327 void swap(AssertionResult& other); |
328 | 328 |
329 // Stores result of the assertion predicate. | 329 // Stores result of the assertion predicate. |
330 bool success_; | 330 bool success_; |
331 // Stores the message describing the condition in case the expectation | 331 // Stores the message describing the condition in case the expectation |
332 // construct is not satisfied with the predicate's outcome. | 332 // construct is not satisfied with the predicate's outcome. |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 | 482 |
483 // A copyable object representing a user specified test property which can be | 483 // A copyable object representing a user specified test property which can be |
484 // output as a key/value string pair. | 484 // output as a key/value string pair. |
485 // | 485 // |
486 // Don't inherit from TestProperty as its destructor is not virtual. | 486 // Don't inherit from TestProperty as its destructor is not virtual. |
487 class TestProperty { | 487 class TestProperty { |
488 public: | 488 public: |
489 // C'tor. TestProperty does NOT have a default constructor. | 489 // C'tor. TestProperty does NOT have a default constructor. |
490 // Always use this constructor (with parameters) to create a | 490 // Always use this constructor (with parameters) to create a |
491 // TestProperty object. | 491 // TestProperty object. |
492 TestProperty(const std::string& a_key, const std::string& a_value) : | 492 TestProperty(const std::string& a_key, const std::string& a_value) |
493 key_(a_key), value_(a_value) { | 493 : key_(a_key), value_(a_value) {} |
494 } | |
495 | 494 |
496 // Gets the user supplied key. | 495 // Gets the user supplied key. |
497 const char* key() const { | 496 const char* key() const { return key_.c_str(); } |
498 return key_.c_str(); | |
499 } | |
500 | 497 |
501 // Gets the user supplied value. | 498 // Gets the user supplied value. |
502 const char* value() const { | 499 const char* value() const { return value_.c_str(); } |
503 return value_.c_str(); | |
504 } | |
505 | 500 |
506 // Sets a new value, overriding the one supplied in the constructor. | 501 // Sets a new value, overriding the one supplied in the constructor. |
507 void SetValue(const std::string& new_value) { | 502 void SetValue(const std::string& new_value) { value_ = new_value; } |
508 value_ = new_value; | |
509 } | |
510 | 503 |
511 private: | 504 private: |
512 // The key supplied by the user. | 505 // The key supplied by the user. |
513 std::string key_; | 506 std::string key_; |
514 // The value supplied by the user. | 507 // The value supplied by the user. |
515 std::string value_; | 508 std::string value_; |
516 }; | 509 }; |
517 | 510 |
518 // The result of a single Test. This includes a list of | 511 // The result of a single Test. This includes a list of |
519 // TestPartResults, a list of TestProperties, a count of how many | 512 // TestPartResults, a list of TestProperties, a count of how many |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 | 643 |
651 // Returns the test case name. | 644 // Returns the test case name. |
652 const char* test_case_name() const { return test_case_name_.c_str(); } | 645 const char* test_case_name() const { return test_case_name_.c_str(); } |
653 | 646 |
654 // Returns the test name. | 647 // Returns the test name. |
655 const char* name() const { return name_.c_str(); } | 648 const char* name() const { return name_.c_str(); } |
656 | 649 |
657 // Returns the name of the parameter type, or NULL if this is not a typed | 650 // Returns the name of the parameter type, or NULL if this is not a typed |
658 // or a type-parameterized test. | 651 // or a type-parameterized test. |
659 const char* type_param() const { | 652 const char* type_param() const { |
660 if (type_param_.get() != NULL) | 653 if (type_param_.get() != NULL) return type_param_->c_str(); |
661 return type_param_->c_str(); | |
662 return NULL; | 654 return NULL; |
663 } | 655 } |
664 | 656 |
665 // Returns the text representation of the value parameter, or NULL if this | 657 // Returns the text representation of the value parameter, or NULL if this |
666 // is not a value-parameterized test. | 658 // is not a value-parameterized test. |
667 const char* value_param() const { | 659 const char* value_param() const { |
668 if (value_param_.get() != NULL) | 660 if (value_param_.get() != NULL) return value_param_->c_str(); |
669 return value_param_->c_str(); | |
670 return NULL; | 661 return NULL; |
671 } | 662 } |
672 | 663 |
673 // Returns true if this test should run, that is if the test is not | 664 // Returns true if this test should run, that is if the test is not |
674 // disabled (or it is disabled but the also_run_disabled_tests flag has | 665 // disabled (or it is disabled but the also_run_disabled_tests flag has |
675 // been specified) and its full name matches the user-specified filter. | 666 // been specified) and its full name matches the user-specified filter. |
676 // | 667 // |
677 // Google Test allows the user to filter the tests by their full names. | 668 // Google Test allows the user to filter the tests by their full names. |
678 // The full name of a test Bar in test case Foo is defined as | 669 // The full name of a test Bar in test case Foo is defined as |
679 // "Foo.Bar". Only the tests that match the filter will run. | 670 // "Foo.Bar". Only the tests that match the filter will run. |
(...skipping 21 matching lines...) Expand all Loading... |
701 | 692 |
702 private: | 693 private: |
703 #if GTEST_HAS_DEATH_TEST | 694 #if GTEST_HAS_DEATH_TEST |
704 friend class internal::DefaultDeathTestFactory; | 695 friend class internal::DefaultDeathTestFactory; |
705 #endif // GTEST_HAS_DEATH_TEST | 696 #endif // GTEST_HAS_DEATH_TEST |
706 friend class Test; | 697 friend class Test; |
707 friend class TestCase; | 698 friend class TestCase; |
708 friend class internal::UnitTestImpl; | 699 friend class internal::UnitTestImpl; |
709 friend class internal::StreamingListenerTest; | 700 friend class internal::StreamingListenerTest; |
710 friend TestInfo* internal::MakeAndRegisterTestInfo( | 701 friend TestInfo* internal::MakeAndRegisterTestInfo( |
711 const char* test_case_name, | 702 const char* test_case_name, const char* name, const char* type_param, |
712 const char* name, | 703 const char* value_param, internal::TypeId fixture_class_id, |
713 const char* type_param, | |
714 const char* value_param, | |
715 internal::TypeId fixture_class_id, | |
716 Test::SetUpTestCaseFunc set_up_tc, | 704 Test::SetUpTestCaseFunc set_up_tc, |
717 Test::TearDownTestCaseFunc tear_down_tc, | 705 Test::TearDownTestCaseFunc tear_down_tc, |
718 internal::TestFactoryBase* factory); | 706 internal::TestFactoryBase* factory); |
719 | 707 |
720 // Constructs a TestInfo object. The newly constructed instance assumes | 708 // Constructs a TestInfo object. The newly constructed instance assumes |
721 // ownership of the factory object. | 709 // ownership of the factory object. |
722 TestInfo(const std::string& test_case_name, | 710 TestInfo(const std::string& test_case_name, const std::string& name, |
723 const std::string& name, | |
724 const char* a_type_param, // NULL if not a type-parameterized test | 711 const char* a_type_param, // NULL if not a type-parameterized test |
725 const char* a_value_param, // NULL if not a value-parameterized test | 712 const char* a_value_param, // NULL if not a value-parameterized test |
726 internal::TypeId fixture_class_id, | 713 internal::TypeId fixture_class_id, |
727 internal::TestFactoryBase* factory); | 714 internal::TestFactoryBase* factory); |
728 | 715 |
729 // Increments the number of death tests encountered in this test so | 716 // Increments the number of death tests encountered in this test so |
730 // far. | 717 // far. |
731 int increment_death_test_count() { | 718 int increment_death_test_count() { |
732 return result_.increment_death_test_count(); | 719 return result_.increment_death_test_count(); |
733 } | 720 } |
734 | 721 |
735 // Creates the test object, runs it, records its result, and then | 722 // Creates the test object, runs it, records its result, and then |
736 // deletes it. | 723 // deletes it. |
737 void Run(); | 724 void Run(); |
738 | 725 |
739 static void ClearTestResult(TestInfo* test_info) { | 726 static void ClearTestResult(TestInfo* test_info) { |
740 test_info->result_.Clear(); | 727 test_info->result_.Clear(); |
741 } | 728 } |
742 | 729 |
743 // These fields are immutable properties of the test. | 730 // These fields are immutable properties of the test. |
744 const std::string test_case_name_; // Test case name | 731 const std::string test_case_name_; // Test case name |
745 const std::string name_; // Test name | 732 const std::string name_; // Test name |
746 // Name of the parameter type, or NULL if this is not a typed or a | 733 // Name of the parameter type, or NULL if this is not a typed or a |
747 // type-parameterized test. | 734 // type-parameterized test. |
748 const internal::scoped_ptr<const ::std::string> type_param_; | 735 const internal::scoped_ptr<const ::std::string> type_param_; |
749 // Text representation of the value parameter, or NULL if this is not a | 736 // Text representation of the value parameter, or NULL if this is not a |
750 // value-parameterized test. | 737 // value-parameterized test. |
751 const internal::scoped_ptr<const ::std::string> value_param_; | 738 const internal::scoped_ptr<const ::std::string> value_param_; |
752 const internal::TypeId fixture_class_id_; // ID of the test fixture class | 739 const internal::TypeId fixture_class_id_; // ID of the test fixture class |
753 bool should_run_; // True iff this test should run | 740 bool should_run_; // True iff this test should run |
754 bool is_disabled_; // True iff this test is disabled | 741 bool is_disabled_; // True iff this test is disabled |
755 bool matches_filter_; // True if this test matches the | 742 bool matches_filter_; // True if this test matches the |
756 // user-specified filter. | 743 // user-specified filter. |
757 internal::TestFactoryBase* const factory_; // The factory that creates | 744 internal::TestFactoryBase* const factory_; // The factory that creates |
758 // the test object | 745 // the test object |
759 | 746 |
760 // This field is mutable and needs to be reset before running the | 747 // This field is mutable and needs to be reset before running the |
761 // test for the second time. | 748 // test for the second time. |
762 TestResult result_; | 749 TestResult result_; |
763 | 750 |
764 GTEST_DISALLOW_COPY_AND_ASSIGN_(TestInfo); | 751 GTEST_DISALLOW_COPY_AND_ASSIGN_(TestInfo); |
765 }; | 752 }; |
766 | 753 |
(...skipping 20 matching lines...) Expand all Loading... |
787 | 774 |
788 // Destructor of TestCase. | 775 // Destructor of TestCase. |
789 virtual ~TestCase(); | 776 virtual ~TestCase(); |
790 | 777 |
791 // Gets the name of the TestCase. | 778 // Gets the name of the TestCase. |
792 const char* name() const { return name_.c_str(); } | 779 const char* name() const { return name_.c_str(); } |
793 | 780 |
794 // Returns the name of the parameter type, or NULL if this is not a | 781 // Returns the name of the parameter type, or NULL if this is not a |
795 // type-parameterized test case. | 782 // type-parameterized test case. |
796 const char* type_param() const { | 783 const char* type_param() const { |
797 if (type_param_.get() != NULL) | 784 if (type_param_.get() != NULL) return type_param_->c_str(); |
798 return type_param_->c_str(); | |
799 return NULL; | 785 return NULL; |
800 } | 786 } |
801 | 787 |
802 // Returns true if any test in this test case should run. | 788 // Returns true if any test in this test case should run. |
803 bool should_run() const { return should_run_; } | 789 bool should_run() const { return should_run_; } |
804 | 790 |
805 // Gets the number of successful tests in this test case. | 791 // Gets the number of successful tests in this test case. |
806 int successful_test_count() const; | 792 int successful_test_count() const; |
807 | 793 |
808 // Gets the number of failed tests in this test case. | 794 // Gets the number of failed tests in this test case. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
854 | 840 |
855 // Returns the i-th test among all the tests. i can range from 0 to | 841 // Returns the i-th test among all the tests. i can range from 0 to |
856 // total_test_count() - 1. If i is not in that range, returns NULL. | 842 // total_test_count() - 1. If i is not in that range, returns NULL. |
857 TestInfo* GetMutableTestInfo(int i); | 843 TestInfo* GetMutableTestInfo(int i); |
858 | 844 |
859 // Sets the should_run member. | 845 // Sets the should_run member. |
860 void set_should_run(bool should) { should_run_ = should; } | 846 void set_should_run(bool should) { should_run_ = should; } |
861 | 847 |
862 // Adds a TestInfo to this test case. Will delete the TestInfo upon | 848 // Adds a TestInfo to this test case. Will delete the TestInfo upon |
863 // destruction of the TestCase object. | 849 // destruction of the TestCase object. |
864 void AddTestInfo(TestInfo * test_info); | 850 void AddTestInfo(TestInfo* test_info); |
865 | 851 |
866 // Clears the results of all tests in this test case. | 852 // Clears the results of all tests in this test case. |
867 void ClearResult(); | 853 void ClearResult(); |
868 | 854 |
869 // Clears the results of all tests in the given test case. | 855 // Clears the results of all tests in the given test case. |
870 static void ClearTestCaseResult(TestCase* test_case) { | 856 static void ClearTestCaseResult(TestCase* test_case) { |
871 test_case->ClearResult(); | 857 test_case->ClearResult(); |
872 } | 858 } |
873 | 859 |
874 // Runs every test in this TestCase. | 860 // Runs every test in this TestCase. |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
964 class Environment { | 950 class Environment { |
965 public: | 951 public: |
966 // The d'tor is virtual as we need to subclass Environment. | 952 // The d'tor is virtual as we need to subclass Environment. |
967 virtual ~Environment() {} | 953 virtual ~Environment() {} |
968 | 954 |
969 // Override this to define how to set up the environment. | 955 // Override this to define how to set up the environment. |
970 virtual void SetUp() {} | 956 virtual void SetUp() {} |
971 | 957 |
972 // Override this to define how to tear down the environment. | 958 // Override this to define how to tear down the environment. |
973 virtual void TearDown() {} | 959 virtual void TearDown() {} |
| 960 |
974 private: | 961 private: |
975 // If you see an error about overriding the following function or | 962 // If you see an error about overriding the following function or |
976 // about it being private, you have mis-spelled SetUp() as Setup(). | 963 // about it being private, you have mis-spelled SetUp() as Setup(). |
977 struct Setup_should_be_spelled_SetUp {}; | 964 struct Setup_should_be_spelled_SetUp {}; |
978 virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; } | 965 virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; } |
979 }; | 966 }; |
980 | 967 |
981 // The interface for tracing execution of tests. The methods are organized in | 968 // The interface for tracing execution of tests. The methods are organized in |
982 // the order the corresponding events are fired. | 969 // the order the corresponding events are fired. |
983 class TestEventListener { | 970 class TestEventListener { |
(...skipping 30 matching lines...) Expand all Loading... |
1014 // Fired after the test case ends. | 1001 // Fired after the test case ends. |
1015 virtual void OnTestCaseEnd(const TestCase& test_case) = 0; | 1002 virtual void OnTestCaseEnd(const TestCase& test_case) = 0; |
1016 | 1003 |
1017 // Fired before environment tear-down for each iteration of tests starts. | 1004 // Fired before environment tear-down for each iteration of tests starts. |
1018 virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test) = 0; | 1005 virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test) = 0; |
1019 | 1006 |
1020 // Fired after environment tear-down for each iteration of tests ends. | 1007 // Fired after environment tear-down for each iteration of tests ends. |
1021 virtual void OnEnvironmentsTearDownEnd(const UnitTest& unit_test) = 0; | 1008 virtual void OnEnvironmentsTearDownEnd(const UnitTest& unit_test) = 0; |
1022 | 1009 |
1023 // Fired after each iteration of tests finishes. | 1010 // Fired after each iteration of tests finishes. |
1024 virtual void OnTestIterationEnd(const UnitTest& unit_test, | 1011 virtual void OnTestIterationEnd(const UnitTest& unit_test, int iteration) = 0; |
1025 int iteration) = 0; | |
1026 | 1012 |
1027 // Fired after all test activities have ended. | 1013 // Fired after all test activities have ended. |
1028 virtual void OnTestProgramEnd(const UnitTest& unit_test) = 0; | 1014 virtual void OnTestProgramEnd(const UnitTest& unit_test) = 0; |
1029 }; | 1015 }; |
1030 | 1016 |
1031 // The convenience class for users who need to override just one or two | 1017 // The convenience class for users who need to override just one or two |
1032 // methods and are not concerned that a possible change to a signature of | 1018 // methods and are not concerned that a possible change to a signature of |
1033 // the methods they override will not be caught during the build. For | 1019 // the methods they override will not be caught during the build. For |
1034 // comments about each method please see the definition of TestEventListener | 1020 // comments about each method please see the definition of TestEventListener |
1035 // above. | 1021 // above. |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1154 // | 1140 // |
1155 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | 1141 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. |
1156 int Run() GTEST_MUST_USE_RESULT_; | 1142 int Run() GTEST_MUST_USE_RESULT_; |
1157 | 1143 |
1158 // Returns the working directory when the first TEST() or TEST_F() | 1144 // Returns the working directory when the first TEST() or TEST_F() |
1159 // was executed. The UnitTest object owns the string. | 1145 // was executed. The UnitTest object owns the string. |
1160 const char* original_working_dir() const; | 1146 const char* original_working_dir() const; |
1161 | 1147 |
1162 // Returns the TestCase object for the test that's currently running, | 1148 // Returns the TestCase object for the test that's currently running, |
1163 // or NULL if no test is running. | 1149 // or NULL if no test is running. |
1164 const TestCase* current_test_case() const | 1150 const TestCase* current_test_case() const GTEST_LOCK_EXCLUDED_(mutex_); |
1165 GTEST_LOCK_EXCLUDED_(mutex_); | |
1166 | 1151 |
1167 // Returns the TestInfo object for the test that's currently running, | 1152 // Returns the TestInfo object for the test that's currently running, |
1168 // or NULL if no test is running. | 1153 // or NULL if no test is running. |
1169 const TestInfo* current_test_info() const | 1154 const TestInfo* current_test_info() const GTEST_LOCK_EXCLUDED_(mutex_); |
1170 GTEST_LOCK_EXCLUDED_(mutex_); | |
1171 | 1155 |
1172 // Returns the random seed used at the start of the current test run. | 1156 // Returns the random seed used at the start of the current test run. |
1173 int random_seed() const; | 1157 int random_seed() const; |
1174 | 1158 |
1175 #if GTEST_HAS_PARAM_TEST | 1159 #if GTEST_HAS_PARAM_TEST |
1176 // Returns the ParameterizedTestCaseRegistry object used to keep track of | 1160 // Returns the ParameterizedTestCaseRegistry object used to keep track of |
1177 // value-parameterized tests and instantiate and register them. | 1161 // value-parameterized tests and instantiate and register them. |
1178 // | 1162 // |
1179 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | 1163 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. |
1180 internal::ParameterizedTestCaseRegistry& parameterized_test_registry() | 1164 internal::ParameterizedTestCaseRegistry& parameterized_test_registry() |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1251 // The UnitTest object takes ownership of the given environment. | 1235 // The UnitTest object takes ownership of the given environment. |
1252 // | 1236 // |
1253 // This method can only be called from the main thread. | 1237 // This method can only be called from the main thread. |
1254 Environment* AddEnvironment(Environment* env); | 1238 Environment* AddEnvironment(Environment* env); |
1255 | 1239 |
1256 // Adds a TestPartResult to the current TestResult object. All | 1240 // Adds a TestPartResult to the current TestResult object. All |
1257 // Google Test assertion macros (e.g. ASSERT_TRUE, EXPECT_EQ, etc) | 1241 // Google Test assertion macros (e.g. ASSERT_TRUE, EXPECT_EQ, etc) |
1258 // eventually call this to report their results. The user code | 1242 // eventually call this to report their results. The user code |
1259 // should use the assertion macros instead of calling this directly. | 1243 // should use the assertion macros instead of calling this directly. |
1260 void AddTestPartResult(TestPartResult::Type result_type, | 1244 void AddTestPartResult(TestPartResult::Type result_type, |
1261 const char* file_name, | 1245 const char* file_name, int line_number, |
1262 int line_number, | |
1263 const std::string& message, | 1246 const std::string& message, |
1264 const std::string& os_stack_trace) | 1247 const std::string& os_stack_trace) |
1265 GTEST_LOCK_EXCLUDED_(mutex_); | 1248 GTEST_LOCK_EXCLUDED_(mutex_); |
1266 | 1249 |
1267 // Adds a TestProperty to the current TestResult object when invoked from | 1250 // Adds a TestProperty to the current TestResult object when invoked from |
1268 // inside a test, to current TestCase's ad_hoc_test_result_ when invoked | 1251 // inside a test, to current TestCase's ad_hoc_test_result_ when invoked |
1269 // from SetUpTestCase or TearDownTestCase, or to the global property set | 1252 // from SetUpTestCase or TearDownTestCase, or to the global property set |
1270 // when invoked elsewhere. If the result already contains a property with | 1253 // when invoked elsewhere. If the result already contains a property with |
1271 // the same key, the value will be updated. | 1254 // the same key, the value will be updated. |
1272 void RecordProperty(const std::string& key, const std::string& value); | 1255 void RecordProperty(const std::string& key, const std::string& value); |
1273 | 1256 |
1274 // Gets the i-th test case among all the test cases. i can range from 0 to | 1257 // Gets the i-th test case among all the test cases. i can range from 0 to |
1275 // total_test_case_count() - 1. If i is not in that range, returns NULL. | 1258 // total_test_case_count() - 1. If i is not in that range, returns NULL. |
1276 TestCase* GetMutableTestCase(int i); | 1259 TestCase* GetMutableTestCase(int i); |
1277 | 1260 |
1278 // Accessors for the implementation object. | 1261 // Accessors for the implementation object. |
1279 internal::UnitTestImpl* impl() { return impl_; } | 1262 internal::UnitTestImpl* impl() { return impl_; } |
1280 const internal::UnitTestImpl* impl() const { return impl_; } | 1263 const internal::UnitTestImpl* impl() const { return impl_; } |
1281 | 1264 |
1282 // These classes and funcions are friends as they need to access private | 1265 // These classes and funcions are friends as they need to access private |
1283 // members of UnitTest. | 1266 // members of UnitTest. |
1284 friend class Test; | 1267 friend class Test; |
1285 friend class internal::AssertHelper; | 1268 friend class internal::AssertHelper; |
1286 friend class internal::ScopedTrace; | 1269 friend class internal::ScopedTrace; |
1287 friend class internal::StreamingListenerTest; | 1270 friend class internal::StreamingListenerTest; |
1288 friend class internal::UnitTestRecordPropertyTestHelper; | 1271 friend class internal::UnitTestRecordPropertyTestHelper; |
1289 friend Environment* AddGlobalTestEnvironment(Environment* env); | 1272 friend Environment* AddGlobalTestEnvironment(Environment* env); |
1290 friend internal::UnitTestImpl* internal::GetUnitTestImpl(); | 1273 friend internal::UnitTestImpl* internal::GetUnitTestImpl(); |
1291 friend void internal::ReportFailureInUnknownLocation( | 1274 friend void internal::ReportFailureInUnknownLocation( |
1292 TestPartResult::Type result_type, | 1275 TestPartResult::Type result_type, const std::string& message); |
1293 const std::string& message); | |
1294 | 1276 |
1295 // Creates an empty UnitTest. | 1277 // Creates an empty UnitTest. |
1296 UnitTest(); | 1278 UnitTest(); |
1297 | 1279 |
1298 // D'tor | 1280 // D'tor |
1299 virtual ~UnitTest(); | 1281 virtual ~UnitTest(); |
1300 | 1282 |
1301 // Pushes a trace defined by SCOPED_TRACE() on to the per-thread | 1283 // Pushes a trace defined by SCOPED_TRACE() on to the per-thread |
1302 // Google Test trace stack. | 1284 // Google Test trace stack. |
1303 void PushGTestTrace(const internal::TraceInfo& trace) | 1285 void PushGTestTrace(const internal::TraceInfo& trace) |
1304 GTEST_LOCK_EXCLUDED_(mutex_); | 1286 GTEST_LOCK_EXCLUDED_(mutex_); |
1305 | 1287 |
1306 // Pops a trace from the per-thread Google Test trace stack. | 1288 // Pops a trace from the per-thread Google Test trace stack. |
1307 void PopGTestTrace() | 1289 void PopGTestTrace() GTEST_LOCK_EXCLUDED_(mutex_); |
1308 GTEST_LOCK_EXCLUDED_(mutex_); | |
1309 | 1290 |
1310 // Protects mutable state in *impl_. This is mutable as some const | 1291 // Protects mutable state in *impl_. This is mutable as some const |
1311 // methods need to lock it too. | 1292 // methods need to lock it too. |
1312 mutable internal::Mutex mutex_; | 1293 mutable internal::Mutex mutex_; |
1313 | 1294 |
1314 // Opaque implementation object. This field is never changed once | 1295 // Opaque implementation object. This field is never changed once |
1315 // the object is constructed. We don't mark it as const here, as | 1296 // the object is constructed. We don't mark it as const here, as |
1316 // doing so will cause a warning in the constructor of UnitTest. | 1297 // doing so will cause a warning in the constructor of UnitTest. |
1317 // Mutable state in *impl_ is protected by mutex_. | 1298 // Mutable state in *impl_ is protected by mutex_. |
1318 internal::UnitTestImpl* impl_; | 1299 internal::UnitTestImpl* impl_; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1408 GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const char); | 1389 GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const char); |
1409 GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(wchar_t); | 1390 GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(wchar_t); |
1410 GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const wchar_t); | 1391 GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const wchar_t); |
1411 | 1392 |
1412 #undef GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_ | 1393 #undef GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_ |
1413 | 1394 |
1414 // If a C string is compared with an STL string object, we know it's meant | 1395 // If a C string is compared with an STL string object, we know it's meant |
1415 // to point to a NUL-terminated string, and thus can print it as a string. | 1396 // to point to a NUL-terminated string, and thus can print it as a string. |
1416 | 1397 |
1417 #define GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(CharType, OtherStringType) \ | 1398 #define GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(CharType, OtherStringType) \ |
1418 template <> \ | 1399 template <> \ |
1419 class FormatForComparison<CharType*, OtherStringType> { \ | 1400 class FormatForComparison<CharType*, OtherStringType> { \ |
1420 public: \ | 1401 public: \ |
1421 static ::std::string Format(CharType* value) { \ | 1402 static ::std::string Format(CharType* value) { \ |
1422 return ::testing::PrintToString(value); \ | 1403 return ::testing::PrintToString(value); \ |
1423 } \ | 1404 } \ |
1424 } | 1405 } |
1425 | 1406 |
1426 GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char, ::std::string); | 1407 GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char, ::std::string); |
1427 GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char, ::std::string); | 1408 GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char, ::std::string); |
1428 | 1409 |
1429 #if GTEST_HAS_GLOBAL_STRING | 1410 #if GTEST_HAS_GLOBAL_STRING |
1430 GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char, ::string); | 1411 GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char, ::string); |
1431 GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char, ::string); | 1412 GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char, ::string); |
1432 #endif | 1413 #endif |
1433 | 1414 |
(...skipping 11 matching lines...) Expand all Loading... |
1445 | 1426 |
1446 // Formats a comparison assertion (e.g. ASSERT_EQ, EXPECT_LT, and etc) | 1427 // Formats a comparison assertion (e.g. ASSERT_EQ, EXPECT_LT, and etc) |
1447 // operand to be used in a failure message. The type (but not value) | 1428 // operand to be used in a failure message. The type (but not value) |
1448 // of the other operand may affect the format. This allows us to | 1429 // of the other operand may affect the format. This allows us to |
1449 // print a char* as a raw pointer when it is compared against another | 1430 // print a char* as a raw pointer when it is compared against another |
1450 // char* or void*, and print it as a C string when it is compared | 1431 // char* or void*, and print it as a C string when it is compared |
1451 // against an std::string object, for example. | 1432 // against an std::string object, for example. |
1452 // | 1433 // |
1453 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | 1434 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. |
1454 template <typename T1, typename T2> | 1435 template <typename T1, typename T2> |
1455 std::string FormatForComparisonFailureMessage( | 1436 std::string FormatForComparisonFailureMessage(const T1& value, |
1456 const T1& value, const T2& /* other_operand */) { | 1437 const T2& /* other_operand */) { |
1457 return FormatForComparison<T1, T2>::Format(value); | 1438 return FormatForComparison<T1, T2>::Format(value); |
1458 } | 1439 } |
1459 | 1440 |
1460 // The helper function for {ASSERT|EXPECT}_EQ. | 1441 // The helper function for {ASSERT|EXPECT}_EQ. |
1461 template <typename T1, typename T2> | 1442 template <typename T1, typename T2> |
1462 AssertionResult CmpHelperEQ(const char* expected_expression, | 1443 AssertionResult CmpHelperEQ(const char* expected_expression, |
1463 const char* actual_expression, | 1444 const char* actual_expression, const T1& expected, |
1464 const T1& expected, | |
1465 const T2& actual) { | 1445 const T2& actual) { |
1466 GTEST_DISABLE_MSC_WARNINGS_PUSH_(4389 /* signed/unsigned mismatch */) | 1446 GTEST_DISABLE_MSC_WARNINGS_PUSH_(4389 /* signed/unsigned mismatch */) |
1467 if (expected == actual) { | 1447 if (expected == actual) { |
1468 return AssertionSuccess(); | 1448 return AssertionSuccess(); |
1469 } | 1449 } |
1470 GTEST_DISABLE_MSC_WARNINGS_POP_() | 1450 GTEST_DISABLE_MSC_WARNINGS_POP_() |
1471 | 1451 |
1472 return EqFailure(expected_expression, | 1452 return EqFailure(expected_expression, actual_expression, |
1473 actual_expression, | |
1474 FormatForComparisonFailureMessage(expected, actual), | 1453 FormatForComparisonFailureMessage(expected, actual), |
1475 FormatForComparisonFailureMessage(actual, expected), | 1454 FormatForComparisonFailureMessage(actual, expected), false); |
1476 false); | |
1477 } | 1455 } |
1478 | 1456 |
1479 // With this overloaded version, we allow anonymous enums to be used | 1457 // With this overloaded version, we allow anonymous enums to be used |
1480 // in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous enums | 1458 // in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous enums |
1481 // can be implicitly cast to BiggestInt. | 1459 // can be implicitly cast to BiggestInt. |
1482 GTEST_API_ AssertionResult CmpHelperEQ(const char* expected_expression, | 1460 GTEST_API_ AssertionResult CmpHelperEQ(const char* expected_expression, |
1483 const char* actual_expression, | 1461 const char* actual_expression, |
1484 BiggestInt expected, | 1462 BiggestInt expected, BiggestInt actual); |
1485 BiggestInt actual); | |
1486 | 1463 |
1487 // The helper class for {ASSERT|EXPECT}_EQ. The template argument | 1464 // The helper class for {ASSERT|EXPECT}_EQ. The template argument |
1488 // lhs_is_null_literal is true iff the first argument to ASSERT_EQ() | 1465 // lhs_is_null_literal is true iff the first argument to ASSERT_EQ() |
1489 // is a null pointer literal. The following default implementation is | 1466 // is a null pointer literal. The following default implementation is |
1490 // for lhs_is_null_literal being false. | 1467 // for lhs_is_null_literal being false. |
1491 template <bool lhs_is_null_literal> | 1468 template <bool lhs_is_null_literal> |
1492 class EqHelper { | 1469 class EqHelper { |
1493 public: | 1470 public: |
1494 // This templatized version is for the general case. | 1471 // This templatized version is for the general case. |
1495 template <typename T1, typename T2> | 1472 template <typename T1, typename T2> |
1496 static AssertionResult Compare(const char* expected_expression, | 1473 static AssertionResult Compare(const char* expected_expression, |
1497 const char* actual_expression, | 1474 const char* actual_expression, |
1498 const T1& expected, | 1475 const T1& expected, const T2& actual) { |
1499 const T2& actual) { | |
1500 return CmpHelperEQ(expected_expression, actual_expression, expected, | 1476 return CmpHelperEQ(expected_expression, actual_expression, expected, |
1501 actual); | 1477 actual); |
1502 } | 1478 } |
1503 | 1479 |
1504 // With this overloaded version, we allow anonymous enums to be used | 1480 // With this overloaded version, we allow anonymous enums to be used |
1505 // in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous | 1481 // in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous |
1506 // enums can be implicitly cast to BiggestInt. | 1482 // enums can be implicitly cast to BiggestInt. |
1507 // | 1483 // |
1508 // Even though its body looks the same as the above version, we | 1484 // Even though its body looks the same as the above version, we |
1509 // cannot merge the two, as it will make anonymous enums unhappy. | 1485 // cannot merge the two, as it will make anonymous enums unhappy. |
1510 static AssertionResult Compare(const char* expected_expression, | 1486 static AssertionResult Compare(const char* expected_expression, |
1511 const char* actual_expression, | 1487 const char* actual_expression, |
1512 BiggestInt expected, | 1488 BiggestInt expected, BiggestInt actual) { |
1513 BiggestInt actual) { | |
1514 return CmpHelperEQ(expected_expression, actual_expression, expected, | 1489 return CmpHelperEQ(expected_expression, actual_expression, expected, |
1515 actual); | 1490 actual); |
1516 } | 1491 } |
1517 }; | 1492 }; |
1518 | 1493 |
1519 // This specialization is used when the first argument to ASSERT_EQ() | 1494 // This specialization is used when the first argument to ASSERT_EQ() |
1520 // is a null pointer literal, like NULL, false, or 0. | 1495 // is a null pointer literal, like NULL, false, or 0. |
1521 template <> | 1496 template <> |
1522 class EqHelper<true> { | 1497 class EqHelper<true> { |
1523 public: | 1498 public: |
1524 // We define two overloaded versions of Compare(). The first | 1499 // We define two overloaded versions of Compare(). The first |
1525 // version will be picked when the second argument to ASSERT_EQ() is | 1500 // version will be picked when the second argument to ASSERT_EQ() is |
1526 // NOT a pointer, e.g. ASSERT_EQ(0, AnIntFunction()) or | 1501 // NOT a pointer, e.g. ASSERT_EQ(0, AnIntFunction()) or |
1527 // EXPECT_EQ(false, a_bool). | 1502 // EXPECT_EQ(false, a_bool). |
1528 template <typename T1, typename T2> | 1503 template <typename T1, typename T2> |
1529 static AssertionResult Compare( | 1504 static AssertionResult Compare( |
1530 const char* expected_expression, | 1505 const char* expected_expression, const char* actual_expression, |
1531 const char* actual_expression, | 1506 const T1& expected, const T2& actual, |
1532 const T1& expected, | |
1533 const T2& actual, | |
1534 // The following line prevents this overload from being considered if T2 | 1507 // The following line prevents this overload from being considered if T2 |
1535 // is not a pointer type. We need this because ASSERT_EQ(NULL, my_ptr) | 1508 // is not a pointer type. We need this because ASSERT_EQ(NULL, my_ptr) |
1536 // expands to Compare("", "", NULL, my_ptr), which requires a conversion | 1509 // expands to Compare("", "", NULL, my_ptr), which requires a conversion |
1537 // to match the Secret* in the other overload, which would otherwise make | 1510 // to match the Secret* in the other overload, which would otherwise make |
1538 // this template match better. | 1511 // this template match better. |
1539 typename EnableIf<!is_pointer<T2>::value>::type* = 0) { | 1512 typename EnableIf<!is_pointer<T2>::value>::type* = 0) { |
1540 return CmpHelperEQ(expected_expression, actual_expression, expected, | 1513 return CmpHelperEQ(expected_expression, actual_expression, expected, |
1541 actual); | 1514 actual); |
1542 } | 1515 } |
1543 | 1516 |
1544 // This version will be picked when the second argument to ASSERT_EQ() is a | 1517 // This version will be picked when the second argument to ASSERT_EQ() is a |
1545 // pointer, e.g. ASSERT_EQ(NULL, a_pointer). | 1518 // pointer, e.g. ASSERT_EQ(NULL, a_pointer). |
1546 template <typename T> | 1519 template <typename T> |
1547 static AssertionResult Compare( | 1520 static AssertionResult Compare( |
1548 const char* expected_expression, | 1521 const char* expected_expression, const char* actual_expression, |
1549 const char* actual_expression, | |
1550 // We used to have a second template parameter instead of Secret*. That | 1522 // We used to have a second template parameter instead of Secret*. That |
1551 // template parameter would deduce to 'long', making this a better match | 1523 // template parameter would deduce to 'long', making this a better match |
1552 // than the first overload even without the first overload's EnableIf. | 1524 // than the first overload even without the first overload's EnableIf. |
1553 // Unfortunately, gcc with -Wconversion-null warns when "passing NULL to | 1525 // Unfortunately, gcc with -Wconversion-null warns when "passing NULL to |
1554 // non-pointer argument" (even a deduced integral argument), so the old | 1526 // non-pointer argument" (even a deduced integral argument), so the old |
1555 // implementation caused warnings in user code. | 1527 // implementation caused warnings in user code. |
1556 Secret* /* expected (NULL) */, | 1528 Secret* /* expected (NULL) */, T* actual) { |
1557 T* actual) { | |
1558 // We already know that 'expected' is a null pointer. | 1529 // We already know that 'expected' is a null pointer. |
1559 return CmpHelperEQ(expected_expression, actual_expression, | 1530 return CmpHelperEQ(expected_expression, actual_expression, |
1560 static_cast<T*>(NULL), actual); | 1531 static_cast<T*>(NULL), actual); |
1561 } | 1532 } |
1562 }; | 1533 }; |
1563 | 1534 |
1564 // A macro for implementing the helper functions needed to implement | 1535 // A macro for implementing the helper functions needed to implement |
1565 // ASSERT_?? and EXPECT_??. It is here just to avoid copy-and-paste | 1536 // ASSERT_?? and EXPECT_??. It is here just to avoid copy-and-paste |
1566 // of similar code. | 1537 // of similar code. |
1567 // | 1538 // |
1568 // For each templatized helper function, we also define an overloaded | 1539 // For each templatized helper function, we also define an overloaded |
1569 // version for BiggestInt in order to reduce code bloat and allow | 1540 // version for BiggestInt in order to reduce code bloat and allow |
1570 // anonymous enums to be used with {ASSERT|EXPECT}_?? when compiled | 1541 // anonymous enums to be used with {ASSERT|EXPECT}_?? when compiled |
1571 // with gcc 4. | 1542 // with gcc 4. |
1572 // | 1543 // |
1573 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | 1544 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. |
1574 #define GTEST_IMPL_CMP_HELPER_(op_name, op)\ | 1545 #define GTEST_IMPL_CMP_HELPER_(op_name, op) \ |
1575 template <typename T1, typename T2>\ | 1546 template <typename T1, typename T2> \ |
1576 AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \ | 1547 AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \ |
1577 const T1& val1, const T2& val2) {\ | 1548 const T1& val1, const T2& val2) { \ |
1578 if (val1 op val2) {\ | 1549 if (val1 op val2) { \ |
1579 return AssertionSuccess();\ | 1550 return AssertionSuccess(); \ |
1580 } else {\ | 1551 } else { \ |
1581 return AssertionFailure() \ | 1552 return AssertionFailure() \ |
1582 << "Expected: (" << expr1 << ") " #op " (" << expr2\ | 1553 << "Expected: (" << expr1 << ") " #op " (" << expr2 \ |
1583 << "), actual: " << FormatForComparisonFailureMessage(val1, val2)\ | 1554 << "), actual: " << FormatForComparisonFailureMessage(val1, val2) \ |
1584 << " vs " << FormatForComparisonFailureMessage(val2, val1);\ | 1555 << " vs " << FormatForComparisonFailureMessage(val2, val1); \ |
1585 }\ | 1556 } \ |
1586 }\ | 1557 } \ |
1587 GTEST_API_ AssertionResult CmpHelper##op_name(\ | 1558 GTEST_API_ AssertionResult CmpHelper##op_name( \ |
1588 const char* expr1, const char* expr2, BiggestInt val1, BiggestInt val2) | 1559 const char* expr1, const char* expr2, BiggestInt val1, BiggestInt val2) |
1589 | 1560 |
1590 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | 1561 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. |
1591 | 1562 |
1592 // Implements the helper function for {ASSERT|EXPECT}_NE | 1563 // Implements the helper function for {ASSERT|EXPECT}_NE |
1593 GTEST_IMPL_CMP_HELPER_(NE, !=); | 1564 GTEST_IMPL_CMP_HELPER_(NE, != ); |
1594 // Implements the helper function for {ASSERT|EXPECT}_LE | 1565 // Implements the helper function for {ASSERT|EXPECT}_LE |
1595 GTEST_IMPL_CMP_HELPER_(LE, <=); | 1566 GTEST_IMPL_CMP_HELPER_(LE, <= ); |
1596 // Implements the helper function for {ASSERT|EXPECT}_LT | 1567 // Implements the helper function for {ASSERT|EXPECT}_LT |
1597 GTEST_IMPL_CMP_HELPER_(LT, <); | 1568 GTEST_IMPL_CMP_HELPER_(LT, < ); |
1598 // Implements the helper function for {ASSERT|EXPECT}_GE | 1569 // Implements the helper function for {ASSERT|EXPECT}_GE |
1599 GTEST_IMPL_CMP_HELPER_(GE, >=); | 1570 GTEST_IMPL_CMP_HELPER_(GE, >= ); |
1600 // Implements the helper function for {ASSERT|EXPECT}_GT | 1571 // Implements the helper function for {ASSERT|EXPECT}_GT |
1601 GTEST_IMPL_CMP_HELPER_(GT, >); | 1572 GTEST_IMPL_CMP_HELPER_(GT, > ); |
1602 | 1573 |
1603 #undef GTEST_IMPL_CMP_HELPER_ | 1574 #undef GTEST_IMPL_CMP_HELPER_ |
1604 | 1575 |
1605 // The helper function for {ASSERT|EXPECT}_STREQ. | 1576 // The helper function for {ASSERT|EXPECT}_STREQ. |
1606 // | 1577 // |
1607 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | 1578 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. |
1608 GTEST_API_ AssertionResult CmpHelperSTREQ(const char* expected_expression, | 1579 GTEST_API_ AssertionResult CmpHelperSTREQ(const char* expected_expression, |
1609 const char* actual_expression, | 1580 const char* actual_expression, |
1610 const char* expected, | 1581 const char* expected, |
1611 const char* actual); | 1582 const char* actual); |
1612 | 1583 |
1613 // The helper function for {ASSERT|EXPECT}_STRCASEEQ. | 1584 // The helper function for {ASSERT|EXPECT}_STRCASEEQ. |
1614 // | 1585 // |
1615 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | 1586 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. |
1616 GTEST_API_ AssertionResult CmpHelperSTRCASEEQ(const char* expected_expression, | 1587 GTEST_API_ AssertionResult CmpHelperSTRCASEEQ(const char* expected_expression, |
1617 const char* actual_expression, | 1588 const char* actual_expression, |
1618 const char* expected, | 1589 const char* expected, |
1619 const char* actual); | 1590 const char* actual); |
1620 | 1591 |
1621 // The helper function for {ASSERT|EXPECT}_STRNE. | 1592 // The helper function for {ASSERT|EXPECT}_STRNE. |
1622 // | 1593 // |
1623 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | 1594 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. |
1624 GTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression, | 1595 GTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression, |
1625 const char* s2_expression, | 1596 const char* s2_expression, |
1626 const char* s1, | 1597 const char* s1, const char* s2); |
1627 const char* s2); | |
1628 | 1598 |
1629 // The helper function for {ASSERT|EXPECT}_STRCASENE. | 1599 // The helper function for {ASSERT|EXPECT}_STRCASENE. |
1630 // | 1600 // |
1631 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | 1601 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. |
1632 GTEST_API_ AssertionResult CmpHelperSTRCASENE(const char* s1_expression, | 1602 GTEST_API_ AssertionResult CmpHelperSTRCASENE(const char* s1_expression, |
1633 const char* s2_expression, | 1603 const char* s2_expression, |
1634 const char* s1, | 1604 const char* s1, const char* s2); |
1635 const char* s2); | |
1636 | |
1637 | 1605 |
1638 // Helper function for *_STREQ on wide strings. | 1606 // Helper function for *_STREQ on wide strings. |
1639 // | 1607 // |
1640 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | 1608 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. |
1641 GTEST_API_ AssertionResult CmpHelperSTREQ(const char* expected_expression, | 1609 GTEST_API_ AssertionResult CmpHelperSTREQ(const char* expected_expression, |
1642 const char* actual_expression, | 1610 const char* actual_expression, |
1643 const wchar_t* expected, | 1611 const wchar_t* expected, |
1644 const wchar_t* actual); | 1612 const wchar_t* actual); |
1645 | 1613 |
1646 // Helper function for *_STRNE on wide strings. | 1614 // Helper function for *_STRNE on wide strings. |
1647 // | 1615 // |
1648 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | 1616 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. |
1649 GTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression, | 1617 GTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression, |
1650 const char* s2_expression, | 1618 const char* s2_expression, |
1651 const wchar_t* s1, | 1619 const wchar_t* s1, const wchar_t* s2); |
1652 const wchar_t* s2); | |
1653 | 1620 |
1654 } // namespace internal | 1621 } // namespace internal |
1655 | 1622 |
1656 // IsSubstring() and IsNotSubstring() are intended to be used as the | 1623 // IsSubstring() and IsNotSubstring() are intended to be used as the |
1657 // first argument to {EXPECT,ASSERT}_PRED_FORMAT2(), not by | 1624 // first argument to {EXPECT,ASSERT}_PRED_FORMAT2(), not by |
1658 // themselves. They check whether needle is a substring of haystack | 1625 // themselves. They check whether needle is a substring of haystack |
1659 // (NULL is considered a substring of itself only), and return an | 1626 // (NULL is considered a substring of itself only), and return an |
1660 // appropriate error message when they fail. | 1627 // appropriate error message when they fail. |
1661 // | 1628 // |
1662 // The {needle,haystack}_expr arguments are the stringified | 1629 // The {needle,haystack}_expr arguments are the stringified |
1663 // expressions that generated the two real arguments. | 1630 // expressions that generated the two real arguments. |
1664 GTEST_API_ AssertionResult IsSubstring( | 1631 GTEST_API_ AssertionResult |
1665 const char* needle_expr, const char* haystack_expr, | 1632 IsSubstring(const char* needle_expr, const char* haystack_expr, |
1666 const char* needle, const char* haystack); | 1633 const char* needle, const char* haystack); |
1667 GTEST_API_ AssertionResult IsSubstring( | 1634 GTEST_API_ AssertionResult |
1668 const char* needle_expr, const char* haystack_expr, | 1635 IsSubstring(const char* needle_expr, const char* haystack_expr, |
1669 const wchar_t* needle, const wchar_t* haystack); | 1636 const wchar_t* needle, const wchar_t* haystack); |
1670 GTEST_API_ AssertionResult IsNotSubstring( | 1637 GTEST_API_ AssertionResult |
1671 const char* needle_expr, const char* haystack_expr, | 1638 IsNotSubstring(const char* needle_expr, const char* haystack_expr, |
1672 const char* needle, const char* haystack); | 1639 const char* needle, const char* haystack); |
1673 GTEST_API_ AssertionResult IsNotSubstring( | 1640 GTEST_API_ AssertionResult |
1674 const char* needle_expr, const char* haystack_expr, | 1641 IsNotSubstring(const char* needle_expr, const char* haystack_expr, |
1675 const wchar_t* needle, const wchar_t* haystack); | 1642 const wchar_t* needle, const wchar_t* haystack); |
1676 GTEST_API_ AssertionResult IsSubstring( | 1643 GTEST_API_ AssertionResult |
1677 const char* needle_expr, const char* haystack_expr, | 1644 IsSubstring(const char* needle_expr, const char* haystack_expr, |
1678 const ::std::string& needle, const ::std::string& haystack); | 1645 const ::std::string& needle, const ::std::string& haystack); |
1679 GTEST_API_ AssertionResult IsNotSubstring( | 1646 GTEST_API_ AssertionResult |
1680 const char* needle_expr, const char* haystack_expr, | 1647 IsNotSubstring(const char* needle_expr, const char* haystack_expr, |
1681 const ::std::string& needle, const ::std::string& haystack); | 1648 const ::std::string& needle, const ::std::string& haystack); |
1682 | 1649 |
1683 #if GTEST_HAS_STD_WSTRING | 1650 #if GTEST_HAS_STD_WSTRING |
1684 GTEST_API_ AssertionResult IsSubstring( | 1651 GTEST_API_ AssertionResult |
1685 const char* needle_expr, const char* haystack_expr, | 1652 IsSubstring(const char* needle_expr, const char* haystack_expr, |
1686 const ::std::wstring& needle, const ::std::wstring& haystack); | 1653 const ::std::wstring& needle, const ::std::wstring& haystack); |
1687 GTEST_API_ AssertionResult IsNotSubstring( | 1654 GTEST_API_ AssertionResult IsNotSubstring(const char* needle_expr, |
1688 const char* needle_expr, const char* haystack_expr, | 1655 const char* haystack_expr, |
1689 const ::std::wstring& needle, const ::std::wstring& haystack); | 1656 const ::std::wstring& needle, |
| 1657 const ::std::wstring& haystack); |
1690 #endif // GTEST_HAS_STD_WSTRING | 1658 #endif // GTEST_HAS_STD_WSTRING |
1691 | 1659 |
1692 namespace internal { | 1660 namespace internal { |
1693 | 1661 |
1694 // Helper template function for comparing floating-points. | 1662 // Helper template function for comparing floating-points. |
1695 // | 1663 // |
1696 // Template parameter: | 1664 // Template parameter: |
1697 // | 1665 // |
1698 // RawType: the raw floating-point type (either float or double) | 1666 // RawType: the raw floating-point type (either float or double) |
1699 // | 1667 // |
1700 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | 1668 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. |
1701 template <typename RawType> | 1669 template <typename RawType> |
1702 AssertionResult CmpHelperFloatingPointEQ(const char* expected_expression, | 1670 AssertionResult CmpHelperFloatingPointEQ(const char* expected_expression, |
1703 const char* actual_expression, | 1671 const char* actual_expression, |
1704 RawType expected, | 1672 RawType expected, RawType actual) { |
1705 RawType actual) { | |
1706 const FloatingPoint<RawType> lhs(expected), rhs(actual); | 1673 const FloatingPoint<RawType> lhs(expected), rhs(actual); |
1707 | 1674 |
1708 if (lhs.AlmostEquals(rhs)) { | 1675 if (lhs.AlmostEquals(rhs)) { |
1709 return AssertionSuccess(); | 1676 return AssertionSuccess(); |
1710 } | 1677 } |
1711 | 1678 |
1712 ::std::stringstream expected_ss; | 1679 ::std::stringstream expected_ss; |
1713 expected_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2) | 1680 expected_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2) |
1714 << expected; | 1681 << expected; |
1715 | 1682 |
1716 ::std::stringstream actual_ss; | 1683 ::std::stringstream actual_ss; |
1717 actual_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2) | 1684 actual_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2) |
1718 << actual; | 1685 << actual; |
1719 | 1686 |
1720 return EqFailure(expected_expression, | 1687 return EqFailure(expected_expression, actual_expression, |
1721 actual_expression, | |
1722 StringStreamToString(&expected_ss), | 1688 StringStreamToString(&expected_ss), |
1723 StringStreamToString(&actual_ss), | 1689 StringStreamToString(&actual_ss), false); |
1724 false); | |
1725 } | 1690 } |
1726 | 1691 |
1727 // Helper function for implementing ASSERT_NEAR. | 1692 // Helper function for implementing ASSERT_NEAR. |
1728 // | 1693 // |
1729 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | 1694 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. |
1730 GTEST_API_ AssertionResult DoubleNearPredFormat(const char* expr1, | 1695 GTEST_API_ AssertionResult |
1731 const char* expr2, | 1696 DoubleNearPredFormat(const char* expr1, const char* expr2, |
1732 const char* abs_error_expr, | 1697 const char* abs_error_expr, double val1, double val2, |
1733 double val1, | 1698 double abs_error); |
1734 double val2, | |
1735 double abs_error); | |
1736 | 1699 |
1737 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. | 1700 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. |
1738 // A class that enables one to stream messages to assertion macros | 1701 // A class that enables one to stream messages to assertion macros |
1739 class GTEST_API_ AssertHelper { | 1702 class GTEST_API_ AssertHelper { |
1740 public: | 1703 public: |
1741 // Constructor. | 1704 // Constructor. |
1742 AssertHelper(TestPartResult::Type type, | 1705 AssertHelper(TestPartResult::Type type, const char* file, int line, |
1743 const char* file, | |
1744 int line, | |
1745 const char* message); | 1706 const char* message); |
1746 ~AssertHelper(); | 1707 ~AssertHelper(); |
1747 | 1708 |
1748 // Message assignment is a semantic trick to enable assertion | 1709 // Message assignment is a semantic trick to enable assertion |
1749 // streaming; see the GTEST_MESSAGE_ macro below. | 1710 // streaming; see the GTEST_MESSAGE_ macro below. |
1750 void operator=(const Message& message) const; | 1711 void operator=(const Message& message) const; |
1751 | 1712 |
1752 private: | 1713 private: |
1753 // We put our data in a struct so that the size of the AssertHelper class can | 1714 // We put our data in a struct so that the size of the AssertHelper class can |
1754 // be as small as possible. This is important because gcc is incapable of | 1715 // be as small as possible. This is important because gcc is incapable of |
1755 // re-using stack space even for temporary variables, so every EXPECT_EQ | 1716 // re-using stack space even for temporary variables, so every EXPECT_EQ |
1756 // reserves stack space for another AssertHelper. | 1717 // reserves stack space for another AssertHelper. |
1757 struct AssertHelperData { | 1718 struct AssertHelperData { |
1758 AssertHelperData(TestPartResult::Type t, | 1719 AssertHelperData(TestPartResult::Type t, const char* srcfile, int line_num, |
1759 const char* srcfile, | |
1760 int line_num, | |
1761 const char* msg) | 1720 const char* msg) |
1762 : type(t), file(srcfile), line(line_num), message(msg) { } | 1721 : type(t), file(srcfile), line(line_num), message(msg) {} |
1763 | 1722 |
1764 TestPartResult::Type const type; | 1723 TestPartResult::Type const type; |
1765 const char* const file; | 1724 const char* const file; |
1766 int const line; | 1725 int const line; |
1767 std::string const message; | 1726 std::string const message; |
1768 | 1727 |
1769 private: | 1728 private: |
1770 GTEST_DISALLOW_COPY_AND_ASSIGN_(AssertHelperData); | 1729 GTEST_DISALLOW_COPY_AND_ASSIGN_(AssertHelperData); |
1771 }; | 1730 }; |
1772 | 1731 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1826 const ParamType& GetParam() const { | 1785 const ParamType& GetParam() const { |
1827 GTEST_CHECK_(parameter_ != NULL) | 1786 GTEST_CHECK_(parameter_ != NULL) |
1828 << "GetParam() can only be called inside a value-parameterized test " | 1787 << "GetParam() can only be called inside a value-parameterized test " |
1829 << "-- did you intend to write TEST_P instead of TEST_F?"; | 1788 << "-- did you intend to write TEST_P instead of TEST_F?"; |
1830 return *parameter_; | 1789 return *parameter_; |
1831 } | 1790 } |
1832 | 1791 |
1833 private: | 1792 private: |
1834 // Sets parameter value. The caller is responsible for making sure the value | 1793 // Sets parameter value. The caller is responsible for making sure the value |
1835 // remains alive and unchanged throughout the current test. | 1794 // remains alive and unchanged throughout the current test. |
1836 static void SetParam(const ParamType* parameter) { | 1795 static void SetParam(const ParamType* parameter) { parameter_ = parameter; } |
1837 parameter_ = parameter; | |
1838 } | |
1839 | 1796 |
1840 // Static value used for accessing parameter during a test lifetime. | 1797 // Static value used for accessing parameter during a test lifetime. |
1841 static const ParamType* parameter_; | 1798 static const ParamType* parameter_; |
1842 | 1799 |
1843 // TestClass must be a subclass of WithParamInterface<T> and Test. | 1800 // TestClass must be a subclass of WithParamInterface<T> and Test. |
1844 template <class TestClass> friend class internal::ParameterizedTestFactory; | 1801 template <class TestClass> |
| 1802 friend class internal::ParameterizedTestFactory; |
1845 }; | 1803 }; |
1846 | 1804 |
1847 template <typename T> | 1805 template <typename T> |
1848 const T* WithParamInterface<T>::parameter_ = NULL; | 1806 const T* WithParamInterface<T>::parameter_ = NULL; |
1849 | 1807 |
1850 // Most value-parameterized classes can ignore the existence of | 1808 // Most value-parameterized classes can ignore the existence of |
1851 // WithParamInterface, and can just inherit from ::testing::TestWithParam. | 1809 // WithParamInterface, and can just inherit from ::testing::TestWithParam. |
1852 | 1810 |
1853 template <typename T> | 1811 template <typename T> |
1854 class TestWithParam : public Test, public WithParamInterface<T> { | 1812 class TestWithParam : public Test, public WithParamInterface<T> {}; |
1855 }; | |
1856 | 1813 |
1857 #endif // GTEST_HAS_PARAM_TEST | 1814 #endif // GTEST_HAS_PARAM_TEST |
1858 | 1815 |
1859 // Macros for indicating success/failure in test code. | 1816 // Macros for indicating success/failure in test code. |
1860 | 1817 |
1861 // ADD_FAILURE unconditionally adds a failure to the current test. | 1818 // ADD_FAILURE unconditionally adds a failure to the current test. |
1862 // SUCCEED generates a success - it doesn't automatically make the | 1819 // SUCCEED generates a success - it doesn't automatically make the |
1863 // current test successful, as a test is only successful when it has | 1820 // current test successful, as a test is only successful when it has |
1864 // no failure. | 1821 // no failure. |
1865 // | 1822 // |
1866 // EXPECT_* verifies that a certain condition is satisfied. If not, | 1823 // EXPECT_* verifies that a certain condition is satisfied. If not, |
1867 // it behaves like ADD_FAILURE. In particular: | 1824 // it behaves like ADD_FAILURE. In particular: |
1868 // | 1825 // |
1869 // EXPECT_TRUE verifies that a Boolean condition is true. | 1826 // EXPECT_TRUE verifies that a Boolean condition is true. |
1870 // EXPECT_FALSE verifies that a Boolean condition is false. | 1827 // EXPECT_FALSE verifies that a Boolean condition is false. |
1871 // | 1828 // |
1872 // FAIL and ASSERT_* are similar to ADD_FAILURE and EXPECT_*, except | 1829 // FAIL and ASSERT_* are similar to ADD_FAILURE and EXPECT_*, except |
1873 // that they will also abort the current function on failure. People | 1830 // that they will also abort the current function on failure. People |
1874 // usually want the fail-fast behavior of FAIL and ASSERT_*, but those | 1831 // usually want the fail-fast behavior of FAIL and ASSERT_*, but those |
1875 // writing data-driven tests often find themselves using ADD_FAILURE | 1832 // writing data-driven tests often find themselves using ADD_FAILURE |
1876 // and EXPECT_* more. | 1833 // and EXPECT_* more. |
1877 | 1834 |
1878 // Generates a nonfatal failure with a generic message. | 1835 // Generates a nonfatal failure with a generic message. |
1879 #define ADD_FAILURE() GTEST_NONFATAL_FAILURE_("Failed") | 1836 #define ADD_FAILURE() GTEST_NONFATAL_FAILURE_("Failed") |
1880 | 1837 |
1881 // Generates a nonfatal failure at the given source file location with | 1838 // Generates a nonfatal failure at the given source file location with |
1882 // a generic message. | 1839 // a generic message. |
1883 #define ADD_FAILURE_AT(file, line) \ | 1840 #define ADD_FAILURE_AT(file, line) \ |
1884 GTEST_MESSAGE_AT_(file, line, "Failed", \ | 1841 GTEST_MESSAGE_AT_(file, line, "Failed", \ |
1885 ::testing::TestPartResult::kNonFatalFailure) | 1842 ::testing::TestPartResult::kNonFatalFailure) |
1886 | 1843 |
1887 // Generates a fatal failure with a generic message. | 1844 // Generates a fatal failure with a generic message. |
1888 #define GTEST_FAIL() GTEST_FATAL_FAILURE_("Failed") | 1845 #define GTEST_FAIL() GTEST_FATAL_FAILURE_("Failed") |
1889 | 1846 |
1890 // Define this macro to 1 to omit the definition of FAIL(), which is a | 1847 // Define this macro to 1 to omit the definition of FAIL(), which is a |
1891 // generic name and clashes with some other libraries. | 1848 // generic name and clashes with some other libraries. |
1892 #if !GTEST_DONT_DEFINE_FAIL | 1849 #if !GTEST_DONT_DEFINE_FAIL |
1893 # define FAIL() GTEST_FAIL() | 1850 #define FAIL() GTEST_FAIL() |
1894 #endif | 1851 #endif |
1895 | 1852 |
1896 // Generates a success with a generic message. | 1853 // Generates a success with a generic message. |
1897 #define GTEST_SUCCEED() GTEST_SUCCESS_("Succeeded") | 1854 #define GTEST_SUCCEED() GTEST_SUCCESS_("Succeeded") |
1898 | 1855 |
1899 // Define this macro to 1 to omit the definition of SUCCEED(), which | 1856 // Define this macro to 1 to omit the definition of SUCCEED(), which |
1900 // is a generic name and clashes with some other libraries. | 1857 // is a generic name and clashes with some other libraries. |
1901 #if !GTEST_DONT_DEFINE_SUCCEED | 1858 #if !GTEST_DONT_DEFINE_SUCCEED |
1902 # define SUCCEED() GTEST_SUCCEED() | 1859 #define SUCCEED() GTEST_SUCCEED() |
1903 #endif | 1860 #endif |
1904 | 1861 |
1905 // Macros for testing exceptions. | 1862 // Macros for testing exceptions. |
1906 // | 1863 // |
1907 // * {ASSERT|EXPECT}_THROW(statement, expected_exception): | 1864 // * {ASSERT|EXPECT}_THROW(statement, expected_exception): |
1908 // Tests that the statement throws the expected exception. | 1865 // Tests that the statement throws the expected exception. |
1909 // * {ASSERT|EXPECT}_NO_THROW(statement): | 1866 // * {ASSERT|EXPECT}_NO_THROW(statement): |
1910 // Tests that the statement doesn't throw any exception. | 1867 // Tests that the statement doesn't throw any exception. |
1911 // * {ASSERT|EXPECT}_ANY_THROW(statement): | 1868 // * {ASSERT|EXPECT}_ANY_THROW(statement): |
1912 // Tests that the statement throws an exception. | 1869 // Tests that the statement throws an exception. |
1913 | 1870 |
1914 #define EXPECT_THROW(statement, expected_exception) \ | 1871 #define EXPECT_THROW(statement, expected_exception) \ |
1915 GTEST_TEST_THROW_(statement, expected_exception, GTEST_NONFATAL_FAILURE_) | 1872 GTEST_TEST_THROW_(statement, expected_exception, GTEST_NONFATAL_FAILURE_) |
1916 #define EXPECT_NO_THROW(statement) \ | 1873 #define EXPECT_NO_THROW(statement) \ |
1917 GTEST_TEST_NO_THROW_(statement, GTEST_NONFATAL_FAILURE_) | 1874 GTEST_TEST_NO_THROW_(statement, GTEST_NONFATAL_FAILURE_) |
1918 #define EXPECT_ANY_THROW(statement) \ | 1875 #define EXPECT_ANY_THROW(statement) \ |
1919 GTEST_TEST_ANY_THROW_(statement, GTEST_NONFATAL_FAILURE_) | 1876 GTEST_TEST_ANY_THROW_(statement, GTEST_NONFATAL_FAILURE_) |
1920 #define ASSERT_THROW(statement, expected_exception) \ | 1877 #define ASSERT_THROW(statement, expected_exception) \ |
1921 GTEST_TEST_THROW_(statement, expected_exception, GTEST_FATAL_FAILURE_) | 1878 GTEST_TEST_THROW_(statement, expected_exception, GTEST_FATAL_FAILURE_) |
1922 #define ASSERT_NO_THROW(statement) \ | 1879 #define ASSERT_NO_THROW(statement) \ |
1923 GTEST_TEST_NO_THROW_(statement, GTEST_FATAL_FAILURE_) | 1880 GTEST_TEST_NO_THROW_(statement, GTEST_FATAL_FAILURE_) |
1924 #define ASSERT_ANY_THROW(statement) \ | 1881 #define ASSERT_ANY_THROW(statement) \ |
1925 GTEST_TEST_ANY_THROW_(statement, GTEST_FATAL_FAILURE_) | 1882 GTEST_TEST_ANY_THROW_(statement, GTEST_FATAL_FAILURE_) |
1926 | 1883 |
1927 // Boolean assertions. Condition can be either a Boolean expression or an | 1884 // Boolean assertions. Condition can be either a Boolean expression or an |
1928 // AssertionResult. For more information on how to use AssertionResult with | 1885 // AssertionResult. For more information on how to use AssertionResult with |
1929 // these macros see comments on that class. | 1886 // these macros see comments on that class. |
1930 #define EXPECT_TRUE(condition) \ | 1887 #define EXPECT_TRUE(condition) \ |
1931 GTEST_TEST_BOOLEAN_(condition, #condition, false, true, \ | 1888 GTEST_TEST_BOOLEAN_(condition, #condition, false, true, \ |
1932 GTEST_NONFATAL_FAILURE_) | 1889 GTEST_NONFATAL_FAILURE_) |
1933 #define EXPECT_FALSE(condition) \ | 1890 #define EXPECT_FALSE(condition) \ |
1934 GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \ | 1891 GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \ |
1935 GTEST_NONFATAL_FAILURE_) | 1892 GTEST_NONFATAL_FAILURE_) |
1936 #define ASSERT_TRUE(condition) \ | 1893 #define ASSERT_TRUE(condition) \ |
1937 GTEST_TEST_BOOLEAN_(condition, #condition, false, true, \ | 1894 GTEST_TEST_BOOLEAN_(condition, #condition, false, true, GTEST_FATAL_FAILURE_) |
1938 GTEST_FATAL_FAILURE_) | 1895 #define ASSERT_FALSE(condition) \ |
1939 #define ASSERT_FALSE(condition) \ | |
1940 GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \ | 1896 GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \ |
1941 GTEST_FATAL_FAILURE_) | 1897 GTEST_FATAL_FAILURE_) |
1942 | 1898 |
1943 // Includes the auto-generated header that implements a family of | 1899 // Includes the auto-generated header that implements a family of |
1944 // generic predicate assertion macros. | 1900 // generic predicate assertion macros. |
1945 #include "gtest/gtest_pred_impl.h" | 1901 #include "gtest/gtest_pred_impl.h" |
1946 | 1902 |
1947 // Macros for testing equalities and inequalities. | 1903 // Macros for testing equalities and inequalities. |
1948 // | 1904 // |
1949 // * {ASSERT|EXPECT}_EQ(expected, actual): Tests that expected == actual | 1905 // * {ASSERT|EXPECT}_EQ(expected, actual): Tests that expected == actual |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1983 // | 1939 // |
1984 // 5. These macros evaluate their arguments exactly once. | 1940 // 5. These macros evaluate their arguments exactly once. |
1985 // | 1941 // |
1986 // Examples: | 1942 // Examples: |
1987 // | 1943 // |
1988 // EXPECT_NE(5, Foo()); | 1944 // EXPECT_NE(5, Foo()); |
1989 // EXPECT_EQ(NULL, a_pointer); | 1945 // EXPECT_EQ(NULL, a_pointer); |
1990 // ASSERT_LT(i, array_size); | 1946 // ASSERT_LT(i, array_size); |
1991 // ASSERT_GT(records.size(), 0) << "There is no record left."; | 1947 // ASSERT_GT(records.size(), 0) << "There is no record left."; |
1992 | 1948 |
1993 #define EXPECT_EQ(expected, actual) \ | 1949 #define EXPECT_EQ(expected, actual) \ |
1994 EXPECT_PRED_FORMAT2(::testing::internal:: \ | 1950 EXPECT_PRED_FORMAT2(::testing::internal::EqHelper< \ |
1995 EqHelper<GTEST_IS_NULL_LITERAL_(expected)>::Compare, \ | 1951 GTEST_IS_NULL_LITERAL_(expected)>::Compare, \ |
1996 expected, actual) | 1952 expected, actual) |
1997 #define EXPECT_NE(expected, actual) \ | 1953 #define EXPECT_NE(expected, actual) \ |
1998 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperNE, expected, actual) | 1954 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperNE, expected, actual) |
1999 #define EXPECT_LE(val1, val2) \ | 1955 #define EXPECT_LE(val1, val2) \ |
2000 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2) | 1956 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2) |
2001 #define EXPECT_LT(val1, val2) \ | 1957 #define EXPECT_LT(val1, val2) \ |
2002 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2) | 1958 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2) |
2003 #define EXPECT_GE(val1, val2) \ | 1959 #define EXPECT_GE(val1, val2) \ |
2004 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2) | 1960 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2) |
2005 #define EXPECT_GT(val1, val2) \ | 1961 #define EXPECT_GT(val1, val2) \ |
2006 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2) | 1962 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2) |
2007 | 1963 |
2008 #define GTEST_ASSERT_EQ(expected, actual) \ | 1964 #define GTEST_ASSERT_EQ(expected, actual) \ |
2009 ASSERT_PRED_FORMAT2(::testing::internal:: \ | 1965 ASSERT_PRED_FORMAT2(::testing::internal::EqHelper< \ |
2010 EqHelper<GTEST_IS_NULL_LITERAL_(expected)>::Compare, \ | 1966 GTEST_IS_NULL_LITERAL_(expected)>::Compare, \ |
2011 expected, actual) | 1967 expected, actual) |
2012 #define GTEST_ASSERT_NE(val1, val2) \ | 1968 #define GTEST_ASSERT_NE(val1, val2) \ |
2013 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2) | 1969 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2) |
2014 #define GTEST_ASSERT_LE(val1, val2) \ | 1970 #define GTEST_ASSERT_LE(val1, val2) \ |
2015 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2) | 1971 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2) |
2016 #define GTEST_ASSERT_LT(val1, val2) \ | 1972 #define GTEST_ASSERT_LT(val1, val2) \ |
2017 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2) | 1973 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2) |
2018 #define GTEST_ASSERT_GE(val1, val2) \ | 1974 #define GTEST_ASSERT_GE(val1, val2) \ |
2019 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2) | 1975 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2) |
2020 #define GTEST_ASSERT_GT(val1, val2) \ | 1976 #define GTEST_ASSERT_GT(val1, val2) \ |
2021 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2) | 1977 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2) |
2022 | 1978 |
2023 // Define macro GTEST_DONT_DEFINE_ASSERT_XY to 1 to omit the definition of | 1979 // Define macro GTEST_DONT_DEFINE_ASSERT_XY to 1 to omit the definition of |
2024 // ASSERT_XY(), which clashes with some users' own code. | 1980 // ASSERT_XY(), which clashes with some users' own code. |
2025 | 1981 |
2026 #if !GTEST_DONT_DEFINE_ASSERT_EQ | 1982 #if !GTEST_DONT_DEFINE_ASSERT_EQ |
2027 # define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2) | 1983 #define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2) |
2028 #endif | 1984 #endif |
2029 | 1985 |
2030 #if !GTEST_DONT_DEFINE_ASSERT_NE | 1986 #if !GTEST_DONT_DEFINE_ASSERT_NE |
2031 # define ASSERT_NE(val1, val2) GTEST_ASSERT_NE(val1, val2) | 1987 #define ASSERT_NE(val1, val2) GTEST_ASSERT_NE(val1, val2) |
2032 #endif | 1988 #endif |
2033 | 1989 |
2034 #if !GTEST_DONT_DEFINE_ASSERT_LE | 1990 #if !GTEST_DONT_DEFINE_ASSERT_LE |
2035 # define ASSERT_LE(val1, val2) GTEST_ASSERT_LE(val1, val2) | 1991 #define ASSERT_LE(val1, val2) GTEST_ASSERT_LE(val1, val2) |
2036 #endif | 1992 #endif |
2037 | 1993 |
2038 #if !GTEST_DONT_DEFINE_ASSERT_LT | 1994 #if !GTEST_DONT_DEFINE_ASSERT_LT |
2039 # define ASSERT_LT(val1, val2) GTEST_ASSERT_LT(val1, val2) | 1995 #define ASSERT_LT(val1, val2) GTEST_ASSERT_LT(val1, val2) |
2040 #endif | 1996 #endif |
2041 | 1997 |
2042 #if !GTEST_DONT_DEFINE_ASSERT_GE | 1998 #if !GTEST_DONT_DEFINE_ASSERT_GE |
2043 # define ASSERT_GE(val1, val2) GTEST_ASSERT_GE(val1, val2) | 1999 #define ASSERT_GE(val1, val2) GTEST_ASSERT_GE(val1, val2) |
2044 #endif | 2000 #endif |
2045 | 2001 |
2046 #if !GTEST_DONT_DEFINE_ASSERT_GT | 2002 #if !GTEST_DONT_DEFINE_ASSERT_GT |
2047 # define ASSERT_GT(val1, val2) GTEST_ASSERT_GT(val1, val2) | 2003 #define ASSERT_GT(val1, val2) GTEST_ASSERT_GT(val1, val2) |
2048 #endif | 2004 #endif |
2049 | 2005 |
2050 // C-string Comparisons. All tests treat NULL and any non-NULL string | 2006 // C-string Comparisons. All tests treat NULL and any non-NULL string |
2051 // as different. Two NULLs are equal. | 2007 // as different. Two NULLs are equal. |
2052 // | 2008 // |
2053 // * {ASSERT|EXPECT}_STREQ(s1, s2): Tests that s1 == s2 | 2009 // * {ASSERT|EXPECT}_STREQ(s1, s2): Tests that s1 == s2 |
2054 // * {ASSERT|EXPECT}_STRNE(s1, s2): Tests that s1 != s2 | 2010 // * {ASSERT|EXPECT}_STRNE(s1, s2): Tests that s1 != s2 |
2055 // * {ASSERT|EXPECT}_STRCASEEQ(s1, s2): Tests that s1 == s2, ignoring case | 2011 // * {ASSERT|EXPECT}_STRCASEEQ(s1, s2): Tests that s1 == s2, ignoring case |
2056 // * {ASSERT|EXPECT}_STRCASENE(s1, s2): Tests that s1 != s2, ignoring case | 2012 // * {ASSERT|EXPECT}_STRCASENE(s1, s2): Tests that s1 != s2, ignoring case |
2057 // | 2013 // |
2058 // For wide or narrow string objects, you can use the | 2014 // For wide or narrow string objects, you can use the |
2059 // {ASSERT|EXPECT}_??() macros. | 2015 // {ASSERT|EXPECT}_??() macros. |
2060 // | 2016 // |
2061 // Don't depend on the order in which the arguments are evaluated, | 2017 // Don't depend on the order in which the arguments are evaluated, |
2062 // which is undefined. | 2018 // which is undefined. |
2063 // | 2019 // |
2064 // These macros evaluate their arguments exactly once. | 2020 // These macros evaluate their arguments exactly once. |
2065 | 2021 |
2066 #define EXPECT_STREQ(expected, actual) \ | 2022 #define EXPECT_STREQ(expected, actual) \ |
2067 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, expected, actual) | 2023 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, expected, actual) |
2068 #define EXPECT_STRNE(s1, s2) \ | 2024 #define EXPECT_STRNE(s1, s2) \ |
2069 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2) | 2025 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2) |
2070 #define EXPECT_STRCASEEQ(expected, actual) \ | 2026 #define EXPECT_STRCASEEQ(expected, actual) \ |
2071 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, expected, actual) | 2027 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, expected, actual) |
2072 #define EXPECT_STRCASENE(s1, s2)\ | 2028 #define EXPECT_STRCASENE(s1, s2) \ |
2073 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2) | 2029 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2) |
2074 | 2030 |
2075 #define ASSERT_STREQ(expected, actual) \ | 2031 #define ASSERT_STREQ(expected, actual) \ |
2076 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, expected, actual) | 2032 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, expected, actual) |
2077 #define ASSERT_STRNE(s1, s2) \ | 2033 #define ASSERT_STRNE(s1, s2) \ |
2078 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2) | 2034 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2) |
2079 #define ASSERT_STRCASEEQ(expected, actual) \ | 2035 #define ASSERT_STRCASEEQ(expected, actual) \ |
2080 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, expected, actual) | 2036 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, expected, actual) |
2081 #define ASSERT_STRCASENE(s1, s2)\ | 2037 #define ASSERT_STRCASENE(s1, s2) \ |
2082 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2) | 2038 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2) |
2083 | 2039 |
2084 // Macros for comparing floating-point numbers. | 2040 // Macros for comparing floating-point numbers. |
2085 // | 2041 // |
2086 // * {ASSERT|EXPECT}_FLOAT_EQ(expected, actual): | 2042 // * {ASSERT|EXPECT}_FLOAT_EQ(expected, actual): |
2087 // Tests that two float values are almost equal. | 2043 // Tests that two float values are almost equal. |
2088 // * {ASSERT|EXPECT}_DOUBLE_EQ(expected, actual): | 2044 // * {ASSERT|EXPECT}_DOUBLE_EQ(expected, actual): |
2089 // Tests that two double values are almost equal. | 2045 // Tests that two double values are almost equal. |
2090 // * {ASSERT|EXPECT}_NEAR(v1, v2, abs_error): | 2046 // * {ASSERT|EXPECT}_NEAR(v1, v2, abs_error): |
2091 // Tests that v1 and v2 are within the given distance to each other. | 2047 // Tests that v1 and v2 are within the given distance to each other. |
2092 // | 2048 // |
2093 // Google Test uses ULP-based comparison to automatically pick a default | 2049 // Google Test uses ULP-based comparison to automatically pick a default |
2094 // error bound that is appropriate for the operands. See the | 2050 // error bound that is appropriate for the operands. See the |
2095 // FloatingPoint template class in gtest-internal.h if you are | 2051 // FloatingPoint template class in gtest-internal.h if you are |
2096 // interested in the implementation details. | 2052 // interested in the implementation details. |
2097 | 2053 |
2098 #define EXPECT_FLOAT_EQ(expected, actual)\ | 2054 #define EXPECT_FLOAT_EQ(expected, actual) \ |
2099 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \ | 2055 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \ |
2100 expected, actual) | 2056 expected, actual) |
2101 | 2057 |
2102 #define EXPECT_DOUBLE_EQ(expected, actual)\ | 2058 #define EXPECT_DOUBLE_EQ(expected, actual) \ |
2103 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \ | 2059 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \ |
2104 expected, actual) | 2060 expected, actual) |
2105 | 2061 |
2106 #define ASSERT_FLOAT_EQ(expected, actual)\ | 2062 #define ASSERT_FLOAT_EQ(expected, actual) \ |
2107 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \ | 2063 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \ |
2108 expected, actual) | 2064 expected, actual) |
2109 | 2065 |
2110 #define ASSERT_DOUBLE_EQ(expected, actual)\ | 2066 #define ASSERT_DOUBLE_EQ(expected, actual) \ |
2111 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \ | 2067 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \ |
2112 expected, actual) | 2068 expected, actual) |
2113 | 2069 |
2114 #define EXPECT_NEAR(val1, val2, abs_error)\ | 2070 #define EXPECT_NEAR(val1, val2, abs_error) \ |
2115 EXPECT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, \ | 2071 EXPECT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, val1, val2, \ |
2116 val1, val2, abs_error) | 2072 abs_error) |
2117 | 2073 |
2118 #define ASSERT_NEAR(val1, val2, abs_error)\ | 2074 #define ASSERT_NEAR(val1, val2, abs_error) \ |
2119 ASSERT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, \ | 2075 ASSERT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, val1, val2, \ |
2120 val1, val2, abs_error) | 2076 abs_error) |
2121 | 2077 |
2122 // These predicate format functions work on floating-point values, and | 2078 // These predicate format functions work on floating-point values, and |
2123 // can be used in {ASSERT|EXPECT}_PRED_FORMAT2*(), e.g. | 2079 // can be used in {ASSERT|EXPECT}_PRED_FORMAT2*(), e.g. |
2124 // | 2080 // |
2125 // EXPECT_PRED_FORMAT2(testing::DoubleLE, Foo(), 5.0); | 2081 // EXPECT_PRED_FORMAT2(testing::DoubleLE, Foo(), 5.0); |
2126 | 2082 |
2127 // Asserts that val1 is less than, or almost equal to, val2. Fails | 2083 // Asserts that val1 is less than, or almost equal to, val2. Fails |
2128 // otherwise. In particular, it fails if either val1 or val2 is NaN. | 2084 // otherwise. In particular, it fails if either val1 or val2 is NaN. |
2129 GTEST_API_ AssertionResult FloatLE(const char* expr1, const char* expr2, | 2085 GTEST_API_ AssertionResult |
2130 float val1, float val2); | 2086 FloatLE(const char* expr1, const char* expr2, float val1, float val2); |
2131 GTEST_API_ AssertionResult DoubleLE(const char* expr1, const char* expr2, | 2087 GTEST_API_ AssertionResult |
2132 double val1, double val2); | 2088 DoubleLE(const char* expr1, const char* expr2, double val1, double val2); |
2133 | |
2134 | 2089 |
2135 #if GTEST_OS_WINDOWS | 2090 #if GTEST_OS_WINDOWS |
2136 | 2091 |
2137 // Macros that test for HRESULT failure and success, these are only useful | 2092 // Macros that test for HRESULT failure and success, these are only useful |
2138 // on Windows, and rely on Windows SDK macros and APIs to compile. | 2093 // on Windows, and rely on Windows SDK macros and APIs to compile. |
2139 // | 2094 // |
2140 // * {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED}(expr) | 2095 // * {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED}(expr) |
2141 // | 2096 // |
2142 // When expr unexpectedly fails or succeeds, Google Test prints the | 2097 // When expr unexpectedly fails or succeeds, Google Test prints the |
2143 // expected result and the actual result with both a human-readable | 2098 // expected result and the actual result with both a human-readable |
2144 // string representation of the error, if available, as well as the | 2099 // string representation of the error, if available, as well as the |
2145 // hex result code. | 2100 // hex result code. |
2146 # define EXPECT_HRESULT_SUCCEEDED(expr) \ | 2101 #define EXPECT_HRESULT_SUCCEEDED(expr) \ |
2147 EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr)) | 2102 EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr)) |
2148 | 2103 |
2149 # define ASSERT_HRESULT_SUCCEEDED(expr) \ | 2104 #define ASSERT_HRESULT_SUCCEEDED(expr) \ |
2150 ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr)) | 2105 ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr)) |
2151 | 2106 |
2152 # define EXPECT_HRESULT_FAILED(expr) \ | 2107 #define EXPECT_HRESULT_FAILED(expr) \ |
2153 EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr)) | 2108 EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr)) |
2154 | 2109 |
2155 # define ASSERT_HRESULT_FAILED(expr) \ | 2110 #define ASSERT_HRESULT_FAILED(expr) \ |
2156 ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr)) | 2111 ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr)) |
2157 | 2112 |
2158 #endif // GTEST_OS_WINDOWS | 2113 #endif // GTEST_OS_WINDOWS |
2159 | 2114 |
2160 // Macros that execute statement and check that it doesn't generate new fatal | 2115 // Macros that execute statement and check that it doesn't generate new fatal |
2161 // failures in the current thread. | 2116 // failures in the current thread. |
2162 // | 2117 // |
2163 // * {ASSERT|EXPECT}_NO_FATAL_FAILURE(statement); | 2118 // * {ASSERT|EXPECT}_NO_FATAL_FAILURE(statement); |
2164 // | 2119 // |
2165 // Examples: | 2120 // Examples: |
2166 // | 2121 // |
2167 // EXPECT_NO_FATAL_FAILURE(Process()); | 2122 // EXPECT_NO_FATAL_FAILURE(Process()); |
2168 // ASSERT_NO_FATAL_FAILURE(Process()) << "Process() failed"; | 2123 // ASSERT_NO_FATAL_FAILURE(Process()) << "Process() failed"; |
2169 // | 2124 // |
2170 #define ASSERT_NO_FATAL_FAILURE(statement) \ | 2125 #define ASSERT_NO_FATAL_FAILURE(statement) \ |
2171 GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_FATAL_FAILURE_) | 2126 GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_FATAL_FAILURE_) |
2172 #define EXPECT_NO_FATAL_FAILURE(statement) \ | 2127 #define EXPECT_NO_FATAL_FAILURE(statement) \ |
2173 GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_NONFATAL_FAILURE_) | 2128 GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_NONFATAL_FAILURE_) |
2174 | 2129 |
2175 // Causes a trace (including the source file path, the current line | 2130 // Causes a trace (including the source file path, the current line |
2176 // number, and the given message) to be included in every test failure | 2131 // number, and the given message) to be included in every test failure |
2177 // message generated by code in the current scope. The effect is | 2132 // message generated by code in the current scope. The effect is |
2178 // undone when the control leaves the current scope. | 2133 // undone when the control leaves the current scope. |
2179 // | 2134 // |
2180 // The message argument can be anything streamable to std::ostream. | 2135 // The message argument can be anything streamable to std::ostream. |
2181 // | 2136 // |
2182 // In the implementation, we include the current line number as part | 2137 // In the implementation, we include the current line number as part |
2183 // of the dummy variable name, thus allowing multiple SCOPED_TRACE()s | 2138 // of the dummy variable name, thus allowing multiple SCOPED_TRACE()s |
2184 // to appear in the same block - as long as they are on different | 2139 // to appear in the same block - as long as they are on different |
2185 // lines. | 2140 // lines. |
2186 #define SCOPED_TRACE(message) \ | 2141 #define SCOPED_TRACE(message) \ |
2187 ::testing::internal::ScopedTrace GTEST_CONCAT_TOKEN_(gtest_trace_, __LINE__)(\ | 2142 ::testing::internal::ScopedTrace GTEST_CONCAT_TOKEN_( \ |
2188 __FILE__, __LINE__, ::testing::Message() << (message)) | 2143 gtest_trace_, __LINE__)(__FILE__, __LINE__, ::testing::Message() \ |
| 2144 << (message)) |
2189 | 2145 |
2190 // Compile-time assertion for type equality. | 2146 // Compile-time assertion for type equality. |
2191 // StaticAssertTypeEq<type1, type2>() compiles iff type1 and type2 are | 2147 // StaticAssertTypeEq<type1, type2>() compiles iff type1 and type2 are |
2192 // the same type. The value it returns is not interesting. | 2148 // the same type. The value it returns is not interesting. |
2193 // | 2149 // |
2194 // Instead of making StaticAssertTypeEq a class template, we make it a | 2150 // Instead of making StaticAssertTypeEq a class template, we make it a |
2195 // function template that invokes a helper class template. This | 2151 // function template that invokes a helper class template. This |
2196 // prevents a user from misusing StaticAssertTypeEq<T1, T2> by | 2152 // prevents a user from misusing StaticAssertTypeEq<T1, T2> by |
2197 // defining objects of that type. | 2153 // defining objects of that type. |
2198 // | 2154 // |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2241 | 2197 |
2242 // Note that we call GetTestTypeId() instead of GetTypeId< | 2198 // Note that we call GetTestTypeId() instead of GetTypeId< |
2243 // ::testing::Test>() here to get the type ID of testing::Test. This | 2199 // ::testing::Test>() here to get the type ID of testing::Test. This |
2244 // is to work around a suspected linker bug when using Google Test as | 2200 // is to work around a suspected linker bug when using Google Test as |
2245 // a framework on Mac OS X. The bug causes GetTypeId< | 2201 // a framework on Mac OS X. The bug causes GetTypeId< |
2246 // ::testing::Test>() to return different values depending on whether | 2202 // ::testing::Test>() to return different values depending on whether |
2247 // the call is from the Google Test framework itself or from user test | 2203 // the call is from the Google Test framework itself or from user test |
2248 // code. GetTestTypeId() is guaranteed to always return the same | 2204 // code. GetTestTypeId() is guaranteed to always return the same |
2249 // value, as it always calls GetTypeId<>() from the Google Test | 2205 // value, as it always calls GetTypeId<>() from the Google Test |
2250 // framework. | 2206 // framework. |
2251 #define GTEST_TEST(test_case_name, test_name)\ | 2207 #define GTEST_TEST(test_case_name, test_name) \ |
2252 GTEST_TEST_(test_case_name, test_name, \ | 2208 GTEST_TEST_(test_case_name, test_name, ::testing::Test, \ |
2253 ::testing::Test, ::testing::internal::GetTestTypeId()) | 2209 ::testing::internal::GetTestTypeId()) |
2254 | 2210 |
2255 // Define this macro to 1 to omit the definition of TEST(), which | 2211 // Define this macro to 1 to omit the definition of TEST(), which |
2256 // is a generic name and clashes with some other libraries. | 2212 // is a generic name and clashes with some other libraries. |
2257 #if !GTEST_DONT_DEFINE_TEST | 2213 #if !GTEST_DONT_DEFINE_TEST |
2258 # define TEST(test_case_name, test_name) GTEST_TEST(test_case_name, test_name) | 2214 #define TEST(test_case_name, test_name) GTEST_TEST(test_case_name, test_name) |
2259 #endif | 2215 #endif |
2260 | 2216 |
2261 // Defines a test that uses a test fixture. | 2217 // Defines a test that uses a test fixture. |
2262 // | 2218 // |
2263 // The first parameter is the name of the test fixture class, which | 2219 // The first parameter is the name of the test fixture class, which |
2264 // also doubles as the test case name. The second parameter is the | 2220 // also doubles as the test case name. The second parameter is the |
2265 // name of the test within the test case. | 2221 // name of the test within the test case. |
2266 // | 2222 // |
2267 // A test fixture class must be declared earlier. The user should put | 2223 // A test fixture class must be declared earlier. The user should put |
2268 // his test code between braces after using this macro. Example: | 2224 // his test code between braces after using this macro. Example: |
2269 // | 2225 // |
2270 // class FooTest : public testing::Test { | 2226 // class FooTest : public testing::Test { |
2271 // protected: | 2227 // protected: |
2272 // virtual void SetUp() { b_.AddElement(3); } | 2228 // virtual void SetUp() { b_.AddElement(3); } |
2273 // | 2229 // |
2274 // Foo a_; | 2230 // Foo a_; |
2275 // Foo b_; | 2231 // Foo b_; |
2276 // }; | 2232 // }; |
2277 // | 2233 // |
2278 // TEST_F(FooTest, InitializesCorrectly) { | 2234 // TEST_F(FooTest, InitializesCorrectly) { |
2279 // EXPECT_TRUE(a_.StatusIsOK()); | 2235 // EXPECT_TRUE(a_.StatusIsOK()); |
2280 // } | 2236 // } |
2281 // | 2237 // |
2282 // TEST_F(FooTest, ReturnsElementCountCorrectly) { | 2238 // TEST_F(FooTest, ReturnsElementCountCorrectly) { |
2283 // EXPECT_EQ(0, a_.size()); | 2239 // EXPECT_EQ(0, a_.size()); |
2284 // EXPECT_EQ(1, b_.size()); | 2240 // EXPECT_EQ(1, b_.size()); |
2285 // } | 2241 // } |
2286 | 2242 |
2287 #define TEST_F(test_fixture, test_name)\ | 2243 #define TEST_F(test_fixture, test_name) \ |
2288 GTEST_TEST_(test_fixture, test_name, test_fixture, \ | 2244 GTEST_TEST_(test_fixture, test_name, test_fixture, \ |
2289 ::testing::internal::GetTypeId<test_fixture>()) | 2245 ::testing::internal::GetTypeId<test_fixture>()) |
2290 | 2246 |
2291 } // namespace testing | 2247 } // namespace testing |
2292 | 2248 |
2293 // Use this function in main() to run all tests. It returns 0 if all | 2249 // Use this function in main() to run all tests. It returns 0 if all |
2294 // tests are successful, or 1 otherwise. | 2250 // tests are successful, or 1 otherwise. |
2295 // | 2251 // |
2296 // RUN_ALL_TESTS() should be invoked after the command line has been | 2252 // RUN_ALL_TESTS() should be invoked after the command line has been |
2297 // parsed by InitGoogleTest(). | 2253 // parsed by InitGoogleTest(). |
2298 // | 2254 // |
2299 // This function was formerly a macro; thus, it is in the global | 2255 // This function was formerly a macro; thus, it is in the global |
2300 // namespace and has an all-caps name. | 2256 // namespace and has an all-caps name. |
2301 int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_; | 2257 int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_; |
2302 | 2258 |
2303 inline int RUN_ALL_TESTS() { | 2259 inline int RUN_ALL_TESTS() { return ::testing::UnitTest::GetInstance()->Run(); } |
2304 return ::testing::UnitTest::GetInstance()->Run(); | |
2305 } | |
2306 | 2260 |
2307 #endif // GTEST_INCLUDE_GTEST_GTEST_H_ | 2261 #endif // GTEST_INCLUDE_GTEST_GTEST_H_ |
OLD | NEW |