gtest.h (googletest-release-1.11.0) | : | gtest.h (googletest-release-1.12.0) | ||
---|---|---|---|---|
skipping to change at line 30 | skipping to change at line 30 | |||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
// | ||||
// The Google C++ Testing and Mocking Framework (Google Test) | // The Google C++ Testing and Mocking Framework (Google Test) | |||
// | // | |||
// This header file defines the public API for Google Test. It should be | // This header file defines the public API for Google Test. It should be | |||
// included by any test program that uses Google Test. | // included by any test program that uses Google Test. | |||
// | // | |||
// IMPORTANT NOTE: Due to limitation of the C++ language, we have to | // IMPORTANT NOTE: Due to limitation of the C++ language, we have to | |||
// leave some internal implementation details in this header file. | // leave some internal implementation details in this header file. | |||
// They are clearly marked by comments like this: | // They are clearly marked by comments like this: | |||
// | // | |||
// // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | // // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | |||
// | // | |||
// Such code is NOT meant to be used by a user directly, and is subject | // Such code is NOT meant to be used by a user directly, and is subject | |||
// to CHANGE WITHOUT NOTICE. Therefore DO NOT DEPEND ON IT in a user | // to CHANGE WITHOUT NOTICE. Therefore DO NOT DEPEND ON IT in a user | |||
// program! | // program! | |||
// | // | |||
// Acknowledgment: Google Test borrowed the idea of automatic test | // Acknowledgment: Google Test borrowed the idea of automatic test | |||
// registration from Barthelemy Dagenais' (barthelemy@prologique.com) | // registration from Barthelemy Dagenais' (barthelemy@prologique.com) | |||
// easyUnit framework. | // easyUnit framework. | |||
// GOOGLETEST_CM0001 DO NOT DELETE | ||||
#ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_H_ | #ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_H_ | |||
#define GOOGLETEST_INCLUDE_GTEST_GTEST_H_ | #define GOOGLETEST_INCLUDE_GTEST_GTEST_H_ | |||
#include <cstddef> | #include <cstddef> | |||
#include <limits> | #include <limits> | |||
#include <memory> | #include <memory> | |||
#include <ostream> | #include <ostream> | |||
#include <type_traits> | #include <type_traits> | |||
#include <vector> | #include <vector> | |||
#include "gtest/internal/gtest-internal.h" | #include "gtest/gtest-assertion-result.h" | |||
#include "gtest/internal/gtest-string.h" | ||||
#include "gtest/gtest-death-test.h" | #include "gtest/gtest-death-test.h" | |||
#include "gtest/gtest-matchers.h" | #include "gtest/gtest-matchers.h" | |||
#include "gtest/gtest-message.h" | #include "gtest/gtest-message.h" | |||
#include "gtest/gtest-param-test.h" | #include "gtest/gtest-param-test.h" | |||
#include "gtest/gtest-printers.h" | #include "gtest/gtest-printers.h" | |||
#include "gtest/gtest_prod.h" | ||||
#include "gtest/gtest-test-part.h" | #include "gtest/gtest-test-part.h" | |||
#include "gtest/gtest-typed-test.h" | #include "gtest/gtest-typed-test.h" | |||
#include "gtest/gtest_pred_impl.h" | ||||
#include "gtest/gtest_prod.h" | ||||
#include "gtest/internal/gtest-internal.h" | ||||
#include "gtest/internal/gtest-string.h" | ||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ | GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ | |||
/* class A needs to have dll-interface to be used by clients of class B */) | /* class A needs to have dll-interface to be used by clients of class B */) | |||
namespace testing { | ||||
// Silence C4100 (unreferenced formal parameter) and 4805 | ||||
// unsafe mix of type 'const int' and type 'const bool' | ||||
#ifdef _MSC_VER | ||||
# pragma warning(push) | ||||
# pragma warning(disable:4805) | ||||
# pragma warning(disable:4100) | ||||
#endif | ||||
// Declares the flags. | // Declares the flags. | |||
// This flag temporary enables the disabled tests. | // This flag temporary enables the disabled tests. | |||
GTEST_DECLARE_bool_(also_run_disabled_tests); | GTEST_DECLARE_bool_(also_run_disabled_tests); | |||
// This flag brings the debugger on an assertion failure. | // This flag brings the debugger on an assertion failure. | |||
GTEST_DECLARE_bool_(break_on_failure); | GTEST_DECLARE_bool_(break_on_failure); | |||
// This flag controls whether Google Test catches all test-thrown exceptions | // This flag controls whether Google Test catches all test-thrown exceptions | |||
// and logs them as failures. | // and logs them as failures. | |||
skipping to change at line 140 | skipping to change at line 129 | |||
// This flags control whether Google Test prints UTF8 characters as text. | // This flags control whether Google Test prints UTF8 characters as text. | |||
GTEST_DECLARE_bool_(print_utf8); | GTEST_DECLARE_bool_(print_utf8); | |||
// This flag specifies the random number seed. | // This flag specifies the random number seed. | |||
GTEST_DECLARE_int32_(random_seed); | GTEST_DECLARE_int32_(random_seed); | |||
// This flag sets how many times the tests are repeated. The default value | // This flag sets how many times the tests are repeated. The default value | |||
// is 1. If the value is -1 the tests are repeating forever. | // is 1. If the value is -1 the tests are repeating forever. | |||
GTEST_DECLARE_int32_(repeat); | GTEST_DECLARE_int32_(repeat); | |||
// This flag controls whether Google Test Environments are recreated for each | ||||
// repeat of the tests. The default value is true. If set to false the global | ||||
// test Environment objects are only set up once, for the first iteration, and | ||||
// only torn down once, for the last. | ||||
GTEST_DECLARE_bool_(recreate_environments_when_repeating); | ||||
// This flag controls whether Google Test includes Google Test internal | // This flag controls whether Google Test includes Google Test internal | |||
// stack frames in failure stack traces. | // stack frames in failure stack traces. | |||
GTEST_DECLARE_bool_(show_internal_stack_frames); | GTEST_DECLARE_bool_(show_internal_stack_frames); | |||
// When this flag is specified, tests' order is randomized on every iteration. | // When this flag is specified, tests' order is randomized on every iteration. | |||
GTEST_DECLARE_bool_(shuffle); | GTEST_DECLARE_bool_(shuffle); | |||
// This flag specifies the maximum number of stack frames to be | // This flag specifies the maximum number of stack frames to be | |||
// printed in a failure message. | // printed in a failure message. | |||
GTEST_DECLARE_int32_(stack_trace_depth); | GTEST_DECLARE_int32_(stack_trace_depth); | |||
skipping to change at line 165 | skipping to change at line 160 | |||
// When this flag is set with a "host:port" string, on supported | // When this flag is set with a "host:port" string, on supported | |||
// platforms test results are streamed to the specified port on | // platforms test results are streamed to the specified port on | |||
// the specified host machine. | // the specified host machine. | |||
GTEST_DECLARE_string_(stream_result_to); | GTEST_DECLARE_string_(stream_result_to); | |||
#if GTEST_USE_OWN_FLAGFILE_FLAG_ | #if GTEST_USE_OWN_FLAGFILE_FLAG_ | |||
GTEST_DECLARE_string_(flagfile); | GTEST_DECLARE_string_(flagfile); | |||
#endif // GTEST_USE_OWN_FLAGFILE_FLAG_ | #endif // GTEST_USE_OWN_FLAGFILE_FLAG_ | |||
namespace testing { | ||||
// Silence C4100 (unreferenced formal parameter) and 4805 | ||||
// unsafe mix of type 'const int' and type 'const bool' | ||||
#ifdef _MSC_VER | ||||
#pragma warning(push) | ||||
#pragma warning(disable : 4805) | ||||
#pragma warning(disable : 4100) | ||||
#endif | ||||
// The upper limit for valid stack trace depths. | // The upper limit for valid stack trace depths. | |||
const int kMaxStackTraceDepth = 100; | const int kMaxStackTraceDepth = 100; | |||
namespace internal { | namespace internal { | |||
class AssertHelper; | class AssertHelper; | |||
class DefaultGlobalTestPartResultReporter; | class DefaultGlobalTestPartResultReporter; | |||
class ExecDeathTest; | class ExecDeathTest; | |||
class NoExecDeathTest; | class NoExecDeathTest; | |||
class FinalSuccessChecker; | class FinalSuccessChecker; | |||
skipping to change at line 203 | skipping to change at line 208 | |||
class Test; | class Test; | |||
class TestSuite; | class TestSuite; | |||
// Old API is still available but deprecated | // Old API is still available but deprecated | |||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ | #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ | |||
using TestCase = TestSuite; | using TestCase = TestSuite; | |||
#endif | #endif | |||
class TestInfo; | class TestInfo; | |||
class UnitTest; | class UnitTest; | |||
// A class for indicating whether an assertion was successful. When | ||||
// the assertion wasn't successful, the AssertionResult object | ||||
// remembers a non-empty message that describes how it failed. | ||||
// | ||||
// To create an instance of this class, use one of the factory functions | ||||
// (AssertionSuccess() and AssertionFailure()). | ||||
// | ||||
// This class is useful for two purposes: | ||||
// 1. Defining predicate functions to be used with Boolean test assertions | ||||
// EXPECT_TRUE/EXPECT_FALSE and their ASSERT_ counterparts | ||||
// 2. Defining predicate-format functions to be | ||||
// used with predicate assertions (ASSERT_PRED_FORMAT*, etc). | ||||
// | ||||
// For example, if you define IsEven predicate: | ||||
// | ||||
// testing::AssertionResult IsEven(int n) { | ||||
// if ((n % 2) == 0) | ||||
// return testing::AssertionSuccess(); | ||||
// else | ||||
// return testing::AssertionFailure() << n << " is odd"; | ||||
// } | ||||
// | ||||
// Then the failed expectation EXPECT_TRUE(IsEven(Fib(5))) | ||||
// will print the message | ||||
// | ||||
// Value of: IsEven(Fib(5)) | ||||
// Actual: false (5 is odd) | ||||
// Expected: true | ||||
// | ||||
// instead of a more opaque | ||||
// | ||||
// Value of: IsEven(Fib(5)) | ||||
// Actual: false | ||||
// Expected: true | ||||
// | ||||
// in case IsEven is a simple Boolean predicate. | ||||
// | ||||
// If you expect your predicate to be reused and want to support informative | ||||
// messages in EXPECT_FALSE and ASSERT_FALSE (negative assertions show up | ||||
// about half as often as positive ones in our tests), supply messages for | ||||
// both success and failure cases: | ||||
// | ||||
// testing::AssertionResult IsEven(int n) { | ||||
// if ((n % 2) == 0) | ||||
// return testing::AssertionSuccess() << n << " is even"; | ||||
// else | ||||
// return testing::AssertionFailure() << n << " is odd"; | ||||
// } | ||||
// | ||||
// Then a statement EXPECT_FALSE(IsEven(Fib(6))) will print | ||||
// | ||||
// Value of: IsEven(Fib(6)) | ||||
// Actual: true (8 is even) | ||||
// Expected: false | ||||
// | ||||
// NB: Predicates that support negative Boolean assertions have reduced | ||||
// performance in positive ones so be careful not to use them in tests | ||||
// that have lots (tens of thousands) of positive Boolean assertions. | ||||
// | ||||
// To use this class with EXPECT_PRED_FORMAT assertions such as: | ||||
// | ||||
// // Verifies that Foo() returns an even number. | ||||
// EXPECT_PRED_FORMAT1(IsEven, Foo()); | ||||
// | ||||
// you need to define: | ||||
// | ||||
// testing::AssertionResult IsEven(const char* expr, int n) { | ||||
// if ((n % 2) == 0) | ||||
// return testing::AssertionSuccess(); | ||||
// else | ||||
// return testing::AssertionFailure() | ||||
// << "Expected: " << expr << " is even\n Actual: it's " << n; | ||||
// } | ||||
// | ||||
// If Foo() returns 5, you will see the following message: | ||||
// | ||||
// Expected: Foo() is even | ||||
// Actual: it's 5 | ||||
// | ||||
class GTEST_API_ AssertionResult { | ||||
public: | ||||
// Copy constructor. | ||||
// Used in EXPECT_TRUE/FALSE(assertion_result). | ||||
AssertionResult(const AssertionResult& other); | ||||
// C4800 is a level 3 warning in Visual Studio 2015 and earlier. | ||||
// This warning is not emitted in Visual Studio 2017. | ||||
// This warning is off by default starting in Visual Studio 2019 but can be | ||||
// enabled with command-line options. | ||||
#if defined(_MSC_VER) && (_MSC_VER < 1910 || _MSC_VER >= 1920) | ||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4800 /* forcing value to bool */) | ||||
#endif | ||||
// Used in the EXPECT_TRUE/FALSE(bool_expression). | ||||
// | ||||
// T must be contextually convertible to bool. | ||||
// | ||||
// The second parameter prevents this overload from being considered if | ||||
// the argument is implicitly convertible to AssertionResult. In that case | ||||
// we want AssertionResult's copy constructor to be used. | ||||
template <typename T> | ||||
explicit AssertionResult( | ||||
const T& success, | ||||
typename std::enable_if< | ||||
!std::is_convertible<T, AssertionResult>::value>::type* | ||||
/*enabler*/ | ||||
= nullptr) | ||||
: success_(success) {} | ||||
#if defined(_MSC_VER) && (_MSC_VER < 1910 || _MSC_VER >= 1920) | ||||
GTEST_DISABLE_MSC_WARNINGS_POP_() | ||||
#endif | ||||
// Assignment operator. | ||||
AssertionResult& operator=(AssertionResult other) { | ||||
swap(other); | ||||
return *this; | ||||
} | ||||
// Returns true if and only if the assertion succeeded. | ||||
operator bool() const { return success_; } // NOLINT | ||||
// Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE. | ||||
AssertionResult operator!() const; | ||||
// Returns the text streamed into this AssertionResult. Test assertions | ||||
// use it when they fail (i.e., the predicate's outcome doesn't match the | ||||
// assertion's expectation). When nothing has been streamed into the | ||||
// object, returns an empty string. | ||||
const char* message() const { | ||||
return message_.get() != nullptr ? message_->c_str() : ""; | ||||
} | ||||
// Deprecated; please use message() instead. | ||||
const char* failure_message() const { return message(); } | ||||
// Streams a custom failure message into this object. | ||||
template <typename T> AssertionResult& operator<<(const T& value) { | ||||
AppendMessage(Message() << value); | ||||
return *this; | ||||
} | ||||
// Allows streaming basic output manipulators such as endl or flush into | ||||
// this object. | ||||
AssertionResult& operator<<( | ||||
::std::ostream& (*basic_manipulator)(::std::ostream& stream)) { | ||||
AppendMessage(Message() << basic_manipulator); | ||||
return *this; | ||||
} | ||||
private: | ||||
// Appends the contents of message to message_. | ||||
void AppendMessage(const Message& a_message) { | ||||
if (message_.get() == nullptr) message_.reset(new ::std::string); | ||||
message_->append(a_message.GetString().c_str()); | ||||
} | ||||
// Swap the contents of this AssertionResult with other. | ||||
void swap(AssertionResult& other); | ||||
// Stores result of the assertion predicate. | ||||
bool success_; | ||||
// Stores the message describing the condition in case the expectation | ||||
// construct is not satisfied with the predicate's outcome. | ||||
// Referenced via a pointer to avoid taking too much stack frame space | ||||
// with test assertions. | ||||
std::unique_ptr< ::std::string> message_; | ||||
}; | ||||
// Makes a successful assertion result. | ||||
GTEST_API_ AssertionResult AssertionSuccess(); | ||||
// Makes a failed assertion result. | ||||
GTEST_API_ AssertionResult AssertionFailure(); | ||||
// Makes a failed assertion result with the given failure message. | ||||
// Deprecated; use AssertionFailure() << msg. | ||||
GTEST_API_ AssertionResult AssertionFailure(const Message& msg); | ||||
} // namespace testing | ||||
// Includes the auto-generated header that implements a family of generic | ||||
// predicate assertion macros. This include comes late because it relies on | ||||
// APIs declared above. | ||||
#include "gtest/gtest_pred_impl.h" | ||||
namespace testing { | ||||
// The abstract class that all tests inherit from. | // The abstract class that all tests inherit from. | |||
// | // | |||
// In Google Test, a unit test program contains one or many TestSuites, and | // In Google Test, a unit test program contains one or many TestSuites, and | |||
// each TestSuite contains one or many Tests. | // each TestSuite contains one or many Tests. | |||
// | // | |||
// When you define a test using the TEST macro, you don't need to | // When you define a test using the TEST macro, you don't need to | |||
// explicitly derive from Test - the TEST macro automatically does | // explicitly derive from Test - the TEST macro automatically does | |||
// this for you. | // this for you. | |||
// | // | |||
// The only time you derive from Test is when defining a test fixture | // The only time you derive from Test is when defining a test fixture | |||
skipping to change at line 524 | skipping to change at line 342 | |||
// if the method is called from the user's test fixture. | // if the method is called from the user's test fixture. | |||
// | // | |||
// DO NOT OVERRIDE THIS FUNCTION. | // DO NOT OVERRIDE THIS FUNCTION. | |||
// | // | |||
// If you see an error about overriding the following function or | // If you see an error about overriding the following function or | |||
// about it being private, you have mis-spelled SetUp() as Setup(). | // about it being private, you have mis-spelled SetUp() as Setup(). | |||
struct Setup_should_be_spelled_SetUp {}; | struct Setup_should_be_spelled_SetUp {}; | |||
virtual Setup_should_be_spelled_SetUp* Setup() { return nullptr; } | virtual Setup_should_be_spelled_SetUp* Setup() { return nullptr; } | |||
// We disallow copying Tests. | // We disallow copying Tests. | |||
GTEST_DISALLOW_COPY_AND_ASSIGN_(Test); | Test(const Test&) = delete; | |||
Test& operator=(const Test&) = delete; | ||||
}; | }; | |||
typedef internal::TimeInMillis TimeInMillis; | typedef internal::TimeInMillis TimeInMillis; | |||
// A copyable object representing a user specified test property which can be | // A copyable object representing a user specified test property which can be | |||
// output as a key/value string pair. | // output as a key/value string pair. | |||
// | // | |||
// Don't inherit from TestProperty as its destructor is not virtual. | // Don't inherit from TestProperty as its destructor is not virtual. | |||
class TestProperty { | class TestProperty { | |||
public: | public: | |||
// C'tor. TestProperty does NOT have a default constructor. | // C'tor. TestProperty does NOT have a default constructor. | |||
// Always use this constructor (with parameters) to create a | // Always use this constructor (with parameters) to create a | |||
// TestProperty object. | // TestProperty object. | |||
TestProperty(const std::string& a_key, const std::string& a_value) : | TestProperty(const std::string& a_key, const std::string& a_value) | |||
key_(a_key), value_(a_value) { | : key_(a_key), value_(a_value) {} | |||
} | ||||
// Gets the user supplied key. | // Gets the user supplied key. | |||
const char* key() const { | const char* key() const { return key_.c_str(); } | |||
return key_.c_str(); | ||||
} | ||||
// Gets the user supplied value. | // Gets the user supplied value. | |||
const char* value() const { | const char* value() const { return value_.c_str(); } | |||
return value_.c_str(); | ||||
} | ||||
// Sets a new value, overriding the one supplied in the constructor. | // Sets a new value, overriding the one supplied in the constructor. | |||
void SetValue(const std::string& new_value) { | void SetValue(const std::string& new_value) { value_ = new_value; } | |||
value_ = new_value; | ||||
} | ||||
private: | private: | |||
// The key supplied by the user. | // The key supplied by the user. | |||
std::string key_; | std::string key_; | |||
// The value supplied by the user. | // The value supplied by the user. | |||
std::string value_; | std::string value_; | |||
}; | }; | |||
// The result of a single Test. This includes a list of | // The result of a single Test. This includes a list of | |||
// TestPartResults, a list of TestProperties, a count of how many | // TestPartResults, a list of TestProperties, a count of how many | |||
skipping to change at line 689 | skipping to change at line 501 | |||
// The vector of TestProperties | // The vector of TestProperties | |||
std::vector<TestProperty> test_properties_; | std::vector<TestProperty> test_properties_; | |||
// Running count of death tests. | // Running count of death tests. | |||
int death_test_count_; | int death_test_count_; | |||
// The start time, in milliseconds since UNIX Epoch. | // The start time, in milliseconds since UNIX Epoch. | |||
TimeInMillis start_timestamp_; | TimeInMillis start_timestamp_; | |||
// The elapsed time, in milliseconds. | // The elapsed time, in milliseconds. | |||
TimeInMillis elapsed_time_; | TimeInMillis elapsed_time_; | |||
// We disallow copying TestResult. | // We disallow copying TestResult. | |||
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestResult); | TestResult(const TestResult&) = delete; | |||
TestResult& operator=(const TestResult&) = delete; | ||||
}; // class TestResult | }; // class TestResult | |||
// A TestInfo object stores the following information about a test: | // A TestInfo object stores the following information about a test: | |||
// | // | |||
// Test suite name | // Test suite name | |||
// Test name | // Test name | |||
// Whether the test should be run | // Whether the test should be run | |||
// A function pointer that creates the test object when invoked | // A function pointer that creates the test object when invoked | |||
// Test result | // Test result | |||
// | // | |||
skipping to change at line 813 | skipping to change at line 626 | |||
void Run(); | void Run(); | |||
// Skip and records the test result for this object. | // Skip and records the test result for this object. | |||
void Skip(); | void Skip(); | |||
static void ClearTestResult(TestInfo* test_info) { | static void ClearTestResult(TestInfo* test_info) { | |||
test_info->result_.Clear(); | test_info->result_.Clear(); | |||
} | } | |||
// These fields are immutable properties of the test. | // These fields are immutable properties of the test. | |||
const std::string test_suite_name_; // test suite name | const std::string test_suite_name_; // test suite name | |||
const std::string name_; // Test name | const std::string name_; // Test name | |||
// Name of the parameter type, or NULL if this is not a typed or a | // Name of the parameter type, or NULL if this is not a typed or a | |||
// type-parameterized test. | // type-parameterized test. | |||
const std::unique_ptr<const ::std::string> type_param_; | const std::unique_ptr<const ::std::string> type_param_; | |||
// Text representation of the value parameter, or NULL if this is not a | // Text representation of the value parameter, or NULL if this is not a | |||
// value-parameterized test. | // value-parameterized test. | |||
const std::unique_ptr<const ::std::string> value_param_; | const std::unique_ptr<const ::std::string> value_param_; | |||
internal::CodeLocation location_; | internal::CodeLocation location_; | |||
const internal::TypeId fixture_class_id_; // ID of the test fixture class | const internal::TypeId fixture_class_id_; // ID of the test fixture class | |||
bool should_run_; // True if and only if this test should run | bool should_run_; // True if and only if this test should run | |||
bool is_disabled_; // True if and only if this test is disabled | bool is_disabled_; // True if and only if this test is disabled | |||
bool matches_filter_; // True if this test matches the | bool matches_filter_; // True if this test matches the | |||
// user-specified filter. | // user-specified filter. | |||
bool is_in_another_shard_; // Will be run in another shard. | bool is_in_another_shard_; // Will be run in another shard. | |||
internal::TestFactoryBase* const factory_; // The factory that creates | internal::TestFactoryBase* const factory_; // The factory that creates | |||
// the test object | // the test object | |||
// This field is mutable and needs to be reset before running the | // This field is mutable and needs to be reset before running the | |||
// test for the second time. | // test for the second time. | |||
TestResult result_; | TestResult result_; | |||
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestInfo); | TestInfo(const TestInfo&) = delete; | |||
TestInfo& operator=(const TestInfo&) = delete; | ||||
}; | }; | |||
// A test suite, which consists of a vector of TestInfos. | // A test suite, which consists of a vector of TestInfos. | |||
// | // | |||
// TestSuite is not copyable. | // TestSuite is not copyable. | |||
class GTEST_API_ TestSuite { | class GTEST_API_ TestSuite { | |||
public: | public: | |||
// Creates a TestSuite with the given name. | // Creates a TestSuite with the given name. | |||
// | // | |||
// TestSuite does NOT have a default constructor. Always use this | // TestSuite does NOT have a default constructor. Always use this | |||
skipping to change at line 943 | skipping to change at line 757 | |||
// Returns the i-th test among all the tests. i can range from 0 to | // Returns the i-th test among all the tests. i can range from 0 to | |||
// total_test_count() - 1. If i is not in that range, returns NULL. | // total_test_count() - 1. If i is not in that range, returns NULL. | |||
TestInfo* GetMutableTestInfo(int i); | TestInfo* GetMutableTestInfo(int i); | |||
// Sets the should_run member. | // Sets the should_run member. | |||
void set_should_run(bool should) { should_run_ = should; } | void set_should_run(bool should) { should_run_ = should; } | |||
// Adds a TestInfo to this test suite. Will delete the TestInfo upon | // Adds a TestInfo to this test suite. Will delete the TestInfo upon | |||
// destruction of the TestSuite object. | // destruction of the TestSuite object. | |||
void AddTestInfo(TestInfo * test_info); | void AddTestInfo(TestInfo* test_info); | |||
// Clears the results of all tests in this test suite. | // Clears the results of all tests in this test suite. | |||
void ClearResult(); | void ClearResult(); | |||
// Clears the results of all tests in the given test suite. | // Clears the results of all tests in the given test suite. | |||
static void ClearTestSuiteResult(TestSuite* test_suite) { | static void ClearTestSuiteResult(TestSuite* test_suite) { | |||
test_suite->ClearResult(); | test_suite->ClearResult(); | |||
} | } | |||
// Runs every test in this TestSuite. | // Runs every test in this TestSuite. | |||
skipping to change at line 1044 | skipping to change at line 858 | |||
bool should_run_; | bool should_run_; | |||
// The start time, in milliseconds since UNIX Epoch. | // The start time, in milliseconds since UNIX Epoch. | |||
TimeInMillis start_timestamp_; | TimeInMillis start_timestamp_; | |||
// Elapsed time, in milliseconds. | // Elapsed time, in milliseconds. | |||
TimeInMillis elapsed_time_; | TimeInMillis elapsed_time_; | |||
// Holds test properties recorded during execution of SetUpTestSuite and | // Holds test properties recorded during execution of SetUpTestSuite and | |||
// TearDownTestSuite. | // TearDownTestSuite. | |||
TestResult ad_hoc_test_result_; | TestResult ad_hoc_test_result_; | |||
// We disallow copying TestSuites. | // We disallow copying TestSuites. | |||
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestSuite); | TestSuite(const TestSuite&) = delete; | |||
TestSuite& operator=(const TestSuite&) = delete; | ||||
}; | }; | |||
// An Environment object is capable of setting up and tearing down an | // An Environment object is capable of setting up and tearing down an | |||
// environment. You should subclass this to define your own | // environment. You should subclass this to define your own | |||
// environment(s). | // environment(s). | |||
// | // | |||
// An Environment object does the set-up and tear-down in virtual | // An Environment object does the set-up and tear-down in virtual | |||
// methods SetUp() and TearDown() instead of the constructor and the | // methods SetUp() and TearDown() instead of the constructor and the | |||
// destructor, as: | // destructor, as: | |||
// | // | |||
skipping to change at line 1071 | skipping to change at line 886 | |||
class Environment { | class Environment { | |||
public: | public: | |||
// The d'tor is virtual as we need to subclass Environment. | // The d'tor is virtual as we need to subclass Environment. | |||
virtual ~Environment() {} | virtual ~Environment() {} | |||
// Override this to define how to set up the environment. | // Override this to define how to set up the environment. | |||
virtual void SetUp() {} | virtual void SetUp() {} | |||
// Override this to define how to tear down the environment. | // Override this to define how to tear down the environment. | |||
virtual void TearDown() {} | virtual void TearDown() {} | |||
private: | private: | |||
// If you see an error about overriding the following function or | // If you see an error about overriding the following function or | |||
// about it being private, you have mis-spelled SetUp() as Setup(). | // about it being private, you have mis-spelled SetUp() as Setup(). | |||
struct Setup_should_be_spelled_SetUp {}; | struct Setup_should_be_spelled_SetUp {}; | |||
virtual Setup_should_be_spelled_SetUp* Setup() { return nullptr; } | virtual Setup_should_be_spelled_SetUp* Setup() { return nullptr; } | |||
}; | }; | |||
#if GTEST_HAS_EXCEPTIONS | #if GTEST_HAS_EXCEPTIONS | |||
// Exception which can be thrown from TestEventListener::OnTestPartResult. | // Exception which can be thrown from TestEventListener::OnTestPartResult. | |||
skipping to change at line 1122 | skipping to change at line 938 | |||
virtual void OnTestSuiteStart(const TestSuite& /*test_suite*/) {} | virtual void OnTestSuiteStart(const TestSuite& /*test_suite*/) {} | |||
// Legacy API is deprecated but still available | // Legacy API is deprecated but still available | |||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ | #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ | |||
virtual void OnTestCaseStart(const TestCase& /*test_case*/) {} | virtual void OnTestCaseStart(const TestCase& /*test_case*/) {} | |||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ | #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ | |||
// Fired before the test starts. | // Fired before the test starts. | |||
virtual void OnTestStart(const TestInfo& test_info) = 0; | virtual void OnTestStart(const TestInfo& test_info) = 0; | |||
// Fired when a test is disabled | ||||
virtual void OnTestDisabled(const TestInfo& /*test_info*/) {} | ||||
// Fired after a failed assertion or a SUCCEED() invocation. | // Fired after a failed assertion or a SUCCEED() invocation. | |||
// If you want to throw an exception from this function to skip to the next | // If you want to throw an exception from this function to skip to the next | |||
// TEST, it must be AssertionException defined above, or inherited from it. | // TEST, it must be AssertionException defined above, or inherited from it. | |||
virtual void OnTestPartResult(const TestPartResult& test_part_result) = 0; | virtual void OnTestPartResult(const TestPartResult& test_part_result) = 0; | |||
// Fired after the test ends. | // Fired after the test ends. | |||
virtual void OnTestEnd(const TestInfo& test_info) = 0; | virtual void OnTestEnd(const TestInfo& test_info) = 0; | |||
// Fired after the test suite ends. | // Fired after the test suite ends. | |||
virtual void OnTestSuiteEnd(const TestSuite& /*test_suite*/) {} | virtual void OnTestSuiteEnd(const TestSuite& /*test_suite*/) {} | |||
skipping to change at line 1145 | skipping to change at line 964 | |||
virtual void OnTestCaseEnd(const TestCase& /*test_case*/) {} | virtual void OnTestCaseEnd(const TestCase& /*test_case*/) {} | |||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ | #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ | |||
// Fired before environment tear-down for each iteration of tests starts. | // Fired before environment tear-down for each iteration of tests starts. | |||
virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test) = 0; | virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test) = 0; | |||
// Fired after environment tear-down for each iteration of tests ends. | // Fired after environment tear-down for each iteration of tests ends. | |||
virtual void OnEnvironmentsTearDownEnd(const UnitTest& unit_test) = 0; | virtual void OnEnvironmentsTearDownEnd(const UnitTest& unit_test) = 0; | |||
// Fired after each iteration of tests finishes. | // Fired after each iteration of tests finishes. | |||
virtual void OnTestIterationEnd(const UnitTest& unit_test, | virtual void OnTestIterationEnd(const UnitTest& unit_test, int iteration) = 0; | |||
int iteration) = 0; | ||||
// Fired after all test activities have ended. | // Fired after all test activities have ended. | |||
virtual void OnTestProgramEnd(const UnitTest& unit_test) = 0; | virtual void OnTestProgramEnd(const UnitTest& unit_test) = 0; | |||
}; | }; | |||
// The convenience class for users who need to override just one or two | // The convenience class for users who need to override just one or two | |||
// methods and are not concerned that a possible change to a signature of | // methods and are not concerned that a possible change to a signature of | |||
// the methods they override will not be caught during the build. For | // the methods they override will not be caught during the build. For | |||
// comments about each method please see the definition of TestEventListener | // comments about each method please see the definition of TestEventListener | |||
// above. | // above. | |||
skipping to change at line 1171 | skipping to change at line 989 | |||
int /*iteration*/) override {} | int /*iteration*/) override {} | |||
void OnEnvironmentsSetUpStart(const UnitTest& /*unit_test*/) override {} | void OnEnvironmentsSetUpStart(const UnitTest& /*unit_test*/) override {} | |||
void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) override {} | void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) override {} | |||
void OnTestSuiteStart(const TestSuite& /*test_suite*/) override {} | void OnTestSuiteStart(const TestSuite& /*test_suite*/) override {} | |||
// Legacy API is deprecated but still available | // Legacy API is deprecated but still available | |||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ | #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ | |||
void OnTestCaseStart(const TestCase& /*test_case*/) override {} | void OnTestCaseStart(const TestCase& /*test_case*/) override {} | |||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ | #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ | |||
void OnTestStart(const TestInfo& /*test_info*/) override {} | void OnTestStart(const TestInfo& /*test_info*/) override {} | |||
void OnTestDisabled(const TestInfo& /*test_info*/) override {} | ||||
void OnTestPartResult(const TestPartResult& /*test_part_result*/) override {} | void OnTestPartResult(const TestPartResult& /*test_part_result*/) override {} | |||
void OnTestEnd(const TestInfo& /*test_info*/) override {} | void OnTestEnd(const TestInfo& /*test_info*/) override {} | |||
void OnTestSuiteEnd(const TestSuite& /*test_suite*/) override {} | void OnTestSuiteEnd(const TestSuite& /*test_suite*/) override {} | |||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ | #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ | |||
void OnTestCaseEnd(const TestCase& /*test_case*/) override {} | void OnTestCaseEnd(const TestCase& /*test_case*/) override {} | |||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ | #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ | |||
void OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) override {} | void OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) override {} | |||
void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) override {} | void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) override {} | |||
void OnTestIterationEnd(const UnitTest& /*unit_test*/, | void OnTestIterationEnd(const UnitTest& /*unit_test*/, | |||
skipping to change at line 1260 | skipping to change at line 1079 | |||
void SuppressEventForwarding(); | void SuppressEventForwarding(); | |||
// The actual list of listeners. | // The actual list of listeners. | |||
internal::TestEventRepeater* repeater_; | internal::TestEventRepeater* repeater_; | |||
// Listener responsible for the standard result output. | // Listener responsible for the standard result output. | |||
TestEventListener* default_result_printer_; | TestEventListener* default_result_printer_; | |||
// Listener responsible for the creation of the XML output file. | // Listener responsible for the creation of the XML output file. | |||
TestEventListener* default_xml_generator_; | TestEventListener* default_xml_generator_; | |||
// We disallow copying TestEventListeners. | // We disallow copying TestEventListeners. | |||
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestEventListeners); | TestEventListeners(const TestEventListeners&) = delete; | |||
TestEventListeners& operator=(const TestEventListeners&) = delete; | ||||
}; | }; | |||
// A UnitTest consists of a vector of TestSuites. | // A UnitTest consists of a vector of TestSuites. | |||
// | // | |||
// This is a singleton class. The only instance of UnitTest is | // This is a singleton class. The only instance of UnitTest is | |||
// created when UnitTest::GetInstance() is first called. This | // created when UnitTest::GetInstance() is first called. This | |||
// instance is never deleted. | // instance is never deleted. | |||
// | // | |||
// UnitTest is not copyable. | // UnitTest is not copyable. | |||
// | // | |||
skipping to change at line 1303 | skipping to change at line 1123 | |||
// or NULL if no test is running. | // or NULL if no test is running. | |||
const TestSuite* current_test_suite() const GTEST_LOCK_EXCLUDED_(mutex_); | const TestSuite* current_test_suite() const GTEST_LOCK_EXCLUDED_(mutex_); | |||
// Legacy API is still available but deprecated | // Legacy API is still available but deprecated | |||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ | #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ | |||
const TestCase* current_test_case() const GTEST_LOCK_EXCLUDED_(mutex_); | const TestCase* current_test_case() const GTEST_LOCK_EXCLUDED_(mutex_); | |||
#endif | #endif | |||
// Returns the TestInfo object for the test that's currently running, | // Returns the TestInfo object for the test that's currently running, | |||
// or NULL if no test is running. | // or NULL if no test is running. | |||
const TestInfo* current_test_info() const | const TestInfo* current_test_info() const GTEST_LOCK_EXCLUDED_(mutex_); | |||
GTEST_LOCK_EXCLUDED_(mutex_); | ||||
// Returns the random seed used at the start of the current test run. | // Returns the random seed used at the start of the current test run. | |||
int random_seed() const; | int random_seed() const; | |||
// Returns the ParameterizedTestSuiteRegistry object used to keep track of | // Returns the ParameterizedTestSuiteRegistry object used to keep track of | |||
// value-parameterized tests and instantiate and register them. | // value-parameterized tests and instantiate and register them. | |||
// | // | |||
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | |||
internal::ParameterizedTestSuiteRegistry& parameterized_test_registry() | internal::ParameterizedTestSuiteRegistry& parameterized_test_registry() | |||
GTEST_LOCK_EXCLUDED_(mutex_); | GTEST_LOCK_EXCLUDED_(mutex_); | |||
skipping to change at line 1410 | skipping to change at line 1229 | |||
// The UnitTest object takes ownership of the given environment. | // The UnitTest object takes ownership of the given environment. | |||
// | // | |||
// This method can only be called from the main thread. | // This method can only be called from the main thread. | |||
Environment* AddEnvironment(Environment* env); | Environment* AddEnvironment(Environment* env); | |||
// Adds a TestPartResult to the current TestResult object. All | // Adds a TestPartResult to the current TestResult object. All | |||
// Google Test assertion macros (e.g. ASSERT_TRUE, EXPECT_EQ, etc) | // Google Test assertion macros (e.g. ASSERT_TRUE, EXPECT_EQ, etc) | |||
// eventually call this to report their results. The user code | // eventually call this to report their results. The user code | |||
// should use the assertion macros instead of calling this directly. | // should use the assertion macros instead of calling this directly. | |||
void AddTestPartResult(TestPartResult::Type result_type, | void AddTestPartResult(TestPartResult::Type result_type, | |||
const char* file_name, | const char* file_name, int line_number, | |||
int line_number, | ||||
const std::string& message, | const std::string& message, | |||
const std::string& os_stack_trace) | const std::string& os_stack_trace) | |||
GTEST_LOCK_EXCLUDED_(mutex_); | GTEST_LOCK_EXCLUDED_(mutex_); | |||
// Adds a TestProperty to the current TestResult object when invoked from | // Adds a TestProperty to the current TestResult object when invoked from | |||
// inside a test, to current TestSuite's ad_hoc_test_result_ when invoked | // inside a test, to current TestSuite's ad_hoc_test_result_ when invoked | |||
// from SetUpTestSuite or TearDownTestSuite, or to the global property set | // from SetUpTestSuite or TearDownTestSuite, or to the global property set | |||
// when invoked elsewhere. If the result already contains a property with | // when invoked elsewhere. If the result already contains a property with | |||
// the same key, the value will be updated. | // the same key, the value will be updated. | |||
void RecordProperty(const std::string& key, const std::string& value); | void RecordProperty(const std::string& key, const std::string& value); | |||
skipping to change at line 1442 | skipping to change at line 1260 | |||
// members of UnitTest. | // members of UnitTest. | |||
friend class ScopedTrace; | friend class ScopedTrace; | |||
friend class Test; | friend class Test; | |||
friend class internal::AssertHelper; | friend class internal::AssertHelper; | |||
friend class internal::StreamingListenerTest; | friend class internal::StreamingListenerTest; | |||
friend class internal::UnitTestRecordPropertyTestHelper; | friend class internal::UnitTestRecordPropertyTestHelper; | |||
friend Environment* AddGlobalTestEnvironment(Environment* env); | friend Environment* AddGlobalTestEnvironment(Environment* env); | |||
friend std::set<std::string>* internal::GetIgnoredParameterizedTestSuites(); | friend std::set<std::string>* internal::GetIgnoredParameterizedTestSuites(); | |||
friend internal::UnitTestImpl* internal::GetUnitTestImpl(); | friend internal::UnitTestImpl* internal::GetUnitTestImpl(); | |||
friend void internal::ReportFailureInUnknownLocation( | friend void internal::ReportFailureInUnknownLocation( | |||
TestPartResult::Type result_type, | TestPartResult::Type result_type, const std::string& message); | |||
const std::string& message); | ||||
// Creates an empty UnitTest. | // Creates an empty UnitTest. | |||
UnitTest(); | UnitTest(); | |||
// D'tor | // D'tor | |||
virtual ~UnitTest(); | virtual ~UnitTest(); | |||
// Pushes a trace defined by SCOPED_TRACE() on to the per-thread | // Pushes a trace defined by SCOPED_TRACE() on to the per-thread | |||
// Google Test trace stack. | // Google Test trace stack. | |||
void PushGTestTrace(const internal::TraceInfo& trace) | void PushGTestTrace(const internal::TraceInfo& trace) | |||
GTEST_LOCK_EXCLUDED_(mutex_); | GTEST_LOCK_EXCLUDED_(mutex_); | |||
// Pops a trace from the per-thread Google Test trace stack. | // Pops a trace from the per-thread Google Test trace stack. | |||
void PopGTestTrace() | void PopGTestTrace() GTEST_LOCK_EXCLUDED_(mutex_); | |||
GTEST_LOCK_EXCLUDED_(mutex_); | ||||
// Protects mutable state in *impl_. This is mutable as some const | // Protects mutable state in *impl_. This is mutable as some const | |||
// methods need to lock it too. | // methods need to lock it too. | |||
mutable internal::Mutex mutex_; | mutable internal::Mutex mutex_; | |||
// Opaque implementation object. This field is never changed once | // Opaque implementation object. This field is never changed once | |||
// the object is constructed. We don't mark it as const here, as | // the object is constructed. We don't mark it as const here, as | |||
// doing so will cause a warning in the constructor of UnitTest. | // doing so will cause a warning in the constructor of UnitTest. | |||
// Mutable state in *impl_ is protected by mutex_. | // Mutable state in *impl_ is protected by mutex_. | |||
internal::UnitTestImpl* impl_; | internal::UnitTestImpl* impl_; | |||
// We disallow copying UnitTest. | // We disallow copying UnitTest. | |||
GTEST_DISALLOW_COPY_AND_ASSIGN_(UnitTest); | UnitTest(const UnitTest&) = delete; | |||
UnitTest& operator=(const UnitTest&) = delete; | ||||
}; | }; | |||
// A convenient wrapper for adding an environment for the test | // A convenient wrapper for adding an environment for the test | |||
// program. | // program. | |||
// | // | |||
// You should call this before RUN_ALL_TESTS() is called, probably in | // You should call this before RUN_ALL_TESTS() is called, probably in | |||
// main(). If you use gtest_main, you need to call this before main() | // main(). If you use gtest_main, you need to call this before main() | |||
// starts for it to take effect. For example, you can define a global | // starts for it to take effect. For example, you can define a global | |||
// variable like this: | // variable like this: | |||
// | // | |||
skipping to change at line 1522 | skipping to change at line 1339 | |||
// there is no argc/argv. | // there is no argc/argv. | |||
GTEST_API_ void InitGoogleTest(); | GTEST_API_ void InitGoogleTest(); | |||
namespace internal { | namespace internal { | |||
// Separate the error generating code from the code path to reduce the stack | // Separate the error generating code from the code path to reduce the stack | |||
// frame size of CmpHelperEQ. This helps reduce the overhead of some sanitizers | // frame size of CmpHelperEQ. This helps reduce the overhead of some sanitizers | |||
// when calling EXPECT_* in a tight loop. | // when calling EXPECT_* in a tight loop. | |||
template <typename T1, typename T2> | template <typename T1, typename T2> | |||
AssertionResult CmpHelperEQFailure(const char* lhs_expression, | AssertionResult CmpHelperEQFailure(const char* lhs_expression, | |||
const char* rhs_expression, | const char* rhs_expression, const T1& lhs, | |||
const T1& lhs, const T2& rhs) { | const T2& rhs) { | |||
return EqFailure(lhs_expression, | return EqFailure(lhs_expression, rhs_expression, | |||
rhs_expression, | ||||
FormatForComparisonFailureMessage(lhs, rhs), | FormatForComparisonFailureMessage(lhs, rhs), | |||
FormatForComparisonFailureMessage(rhs, lhs), | FormatForComparisonFailureMessage(rhs, lhs), false); | |||
false); | ||||
} | } | |||
// This block of code defines operator==/!= | // This block of code defines operator==/!= | |||
// to block lexical scope lookup. | // to block lexical scope lookup. | |||
// It prevents using invalid operator==/!= defined at namespace scope. | // It prevents using invalid operator==/!= defined at namespace scope. | |||
struct faketype {}; | struct faketype {}; | |||
inline bool operator==(faketype, faketype) { return true; } | inline bool operator==(faketype, faketype) { return true; } | |||
inline bool operator!=(faketype, faketype) { return false; } | inline bool operator!=(faketype, faketype) { return false; } | |||
// The helper function for {ASSERT|EXPECT}_EQ. | // The helper function for {ASSERT|EXPECT}_EQ. | |||
template <typename T1, typename T2> | template <typename T1, typename T2> | |||
AssertionResult CmpHelperEQ(const char* lhs_expression, | AssertionResult CmpHelperEQ(const char* lhs_expression, | |||
const char* rhs_expression, | const char* rhs_expression, const T1& lhs, | |||
const T1& lhs, | ||||
const T2& rhs) { | const T2& rhs) { | |||
if (lhs == rhs) { | if (lhs == rhs) { | |||
return AssertionSuccess(); | return AssertionSuccess(); | |||
} | } | |||
return CmpHelperEQFailure(lhs_expression, rhs_expression, lhs, rhs); | return CmpHelperEQFailure(lhs_expression, rhs_expression, lhs, rhs); | |||
} | } | |||
class EqHelper { | class EqHelper { | |||
public: | public: | |||
skipping to change at line 1573 | skipping to change at line 1387 | |||
return CmpHelperEQ(lhs_expression, rhs_expression, lhs, rhs); | return CmpHelperEQ(lhs_expression, rhs_expression, lhs, rhs); | |||
} | } | |||
// With this overloaded version, we allow anonymous enums to be used | // With this overloaded version, we allow anonymous enums to be used | |||
// in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous | // in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous | |||
// enums can be implicitly cast to BiggestInt. | // enums can be implicitly cast to BiggestInt. | |||
// | // | |||
// Even though its body looks the same as the above version, we | // Even though its body looks the same as the above version, we | |||
// cannot merge the two, as it will make anonymous enums unhappy. | // cannot merge the two, as it will make anonymous enums unhappy. | |||
static AssertionResult Compare(const char* lhs_expression, | static AssertionResult Compare(const char* lhs_expression, | |||
const char* rhs_expression, | const char* rhs_expression, BiggestInt lhs, | |||
BiggestInt lhs, | ||||
BiggestInt rhs) { | BiggestInt rhs) { | |||
return CmpHelperEQ(lhs_expression, rhs_expression, lhs, rhs); | return CmpHelperEQ(lhs_expression, rhs_expression, lhs, rhs); | |||
} | } | |||
template <typename T> | template <typename T> | |||
static AssertionResult Compare( | static AssertionResult Compare( | |||
const char* lhs_expression, const char* rhs_expression, | const char* lhs_expression, const char* rhs_expression, | |||
// Handle cases where '0' is used as a null pointer literal. | // Handle cases where '0' is used as a null pointer literal. | |||
std::nullptr_t /* lhs */, T* rhs) { | std::nullptr_t /* lhs */, T* rhs) { | |||
// We already know that 'lhs' is a null pointer. | // We already know that 'lhs' is a null pointer. | |||
skipping to change at line 1609 | skipping to change at line 1422 | |||
<< "), actual: " << FormatForComparisonFailureMessage(val1, val2) | << "), actual: " << FormatForComparisonFailureMessage(val1, val2) | |||
<< " vs " << FormatForComparisonFailureMessage(val2, val1); | << " vs " << FormatForComparisonFailureMessage(val2, val1); | |||
} | } | |||
// A macro for implementing the helper functions needed to implement | // A macro for implementing the helper functions needed to implement | |||
// ASSERT_?? and EXPECT_??. It is here just to avoid copy-and-paste | // ASSERT_?? and EXPECT_??. It is here just to avoid copy-and-paste | |||
// of similar code. | // of similar code. | |||
// | // | |||
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | |||
#define GTEST_IMPL_CMP_HELPER_(op_name, op)\ | #define GTEST_IMPL_CMP_HELPER_(op_name, op) \ | |||
template <typename T1, typename T2>\ | template <typename T1, typename T2> \ | |||
AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \ | AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \ | |||
const T1& val1, const T2& val2) {\ | const T1& val1, const T2& val2) { \ | |||
if (val1 op val2) {\ | if (val1 op val2) { \ | |||
return AssertionSuccess();\ | return AssertionSuccess(); \ | |||
} else {\ | } else { \ | |||
return CmpHelperOpFailure(expr1, expr2, val1, val2, #op);\ | return CmpHelperOpFailure(expr1, expr2, val1, val2, #op); \ | |||
}\ | } \ | |||
} | } | |||
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | |||
// Implements the helper function for {ASSERT|EXPECT}_NE | // Implements the helper function for {ASSERT|EXPECT}_NE | |||
GTEST_IMPL_CMP_HELPER_(NE, !=) | GTEST_IMPL_CMP_HELPER_(NE, !=) | |||
// Implements the helper function for {ASSERT|EXPECT}_LE | // Implements the helper function for {ASSERT|EXPECT}_LE | |||
GTEST_IMPL_CMP_HELPER_(LE, <=) | GTEST_IMPL_CMP_HELPER_(LE, <=) | |||
// Implements the helper function for {ASSERT|EXPECT}_LT | // Implements the helper function for {ASSERT|EXPECT}_LT | |||
GTEST_IMPL_CMP_HELPER_(LT, <) | GTEST_IMPL_CMP_HELPER_(LT, <) | |||
// Implements the helper function for {ASSERT|EXPECT}_GE | // Implements the helper function for {ASSERT|EXPECT}_GE | |||
skipping to change at line 1640 | skipping to change at line 1453 | |||
// Implements the helper function for {ASSERT|EXPECT}_GT | // Implements the helper function for {ASSERT|EXPECT}_GT | |||
GTEST_IMPL_CMP_HELPER_(GT, >) | GTEST_IMPL_CMP_HELPER_(GT, >) | |||
#undef GTEST_IMPL_CMP_HELPER_ | #undef GTEST_IMPL_CMP_HELPER_ | |||
// The helper function for {ASSERT|EXPECT}_STREQ. | // The helper function for {ASSERT|EXPECT}_STREQ. | |||
// | // | |||
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | |||
GTEST_API_ AssertionResult CmpHelperSTREQ(const char* s1_expression, | GTEST_API_ AssertionResult CmpHelperSTREQ(const char* s1_expression, | |||
const char* s2_expression, | const char* s2_expression, | |||
const char* s1, | const char* s1, const char* s2); | |||
const char* s2); | ||||
// The helper function for {ASSERT|EXPECT}_STRCASEEQ. | // The helper function for {ASSERT|EXPECT}_STRCASEEQ. | |||
// | // | |||
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | |||
GTEST_API_ AssertionResult CmpHelperSTRCASEEQ(const char* s1_expression, | GTEST_API_ AssertionResult CmpHelperSTRCASEEQ(const char* s1_expression, | |||
const char* s2_expression, | const char* s2_expression, | |||
const char* s1, | const char* s1, const char* s2); | |||
const char* s2); | ||||
// The helper function for {ASSERT|EXPECT}_STRNE. | // The helper function for {ASSERT|EXPECT}_STRNE. | |||
// | // | |||
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | |||
GTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression, | GTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression, | |||
const char* s2_expression, | const char* s2_expression, | |||
const char* s1, | const char* s1, const char* s2); | |||
const char* s2); | ||||
// The helper function for {ASSERT|EXPECT}_STRCASENE. | // The helper function for {ASSERT|EXPECT}_STRCASENE. | |||
// | // | |||
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | |||
GTEST_API_ AssertionResult CmpHelperSTRCASENE(const char* s1_expression, | GTEST_API_ AssertionResult CmpHelperSTRCASENE(const char* s1_expression, | |||
const char* s2_expression, | const char* s2_expression, | |||
const char* s1, | const char* s1, const char* s2); | |||
const char* s2); | ||||
// Helper function for *_STREQ on wide strings. | // Helper function for *_STREQ on wide strings. | |||
// | // | |||
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | |||
GTEST_API_ AssertionResult CmpHelperSTREQ(const char* s1_expression, | GTEST_API_ AssertionResult CmpHelperSTREQ(const char* s1_expression, | |||
const char* s2_expression, | const char* s2_expression, | |||
const wchar_t* s1, | const wchar_t* s1, const wchar_t* s2); | |||
const wchar_t* s2); | ||||
// Helper function for *_STRNE on wide strings. | // Helper function for *_STRNE on wide strings. | |||
// | // | |||
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | |||
GTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression, | GTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression, | |||
const char* s2_expression, | const char* s2_expression, | |||
const wchar_t* s1, | const wchar_t* s1, const wchar_t* s2); | |||
const wchar_t* s2); | ||||
} // namespace internal | } // namespace internal | |||
// IsSubstring() and IsNotSubstring() are intended to be used as the | // IsSubstring() and IsNotSubstring() are intended to be used as the | |||
// first argument to {EXPECT,ASSERT}_PRED_FORMAT2(), not by | // first argument to {EXPECT,ASSERT}_PRED_FORMAT2(), not by | |||
// themselves. They check whether needle is a substring of haystack | // themselves. They check whether needle is a substring of haystack | |||
// (NULL is considered a substring of itself only), and return an | // (NULL is considered a substring of itself only), and return an | |||
// appropriate error message when they fail. | // appropriate error message when they fail. | |||
// | // | |||
// The {needle,haystack}_expr arguments are the stringified | // The {needle,haystack}_expr arguments are the stringified | |||
// expressions that generated the two real arguments. | // expressions that generated the two real arguments. | |||
GTEST_API_ AssertionResult IsSubstring( | GTEST_API_ AssertionResult IsSubstring(const char* needle_expr, | |||
const char* needle_expr, const char* haystack_expr, | const char* haystack_expr, | |||
const char* needle, const char* haystack); | const char* needle, | |||
GTEST_API_ AssertionResult IsSubstring( | const char* haystack); | |||
const char* needle_expr, const char* haystack_expr, | GTEST_API_ AssertionResult IsSubstring(const char* needle_expr, | |||
const wchar_t* needle, const wchar_t* haystack); | const char* haystack_expr, | |||
GTEST_API_ AssertionResult IsNotSubstring( | const wchar_t* needle, | |||
const char* needle_expr, const char* haystack_expr, | const wchar_t* haystack); | |||
const char* needle, const char* haystack); | GTEST_API_ AssertionResult IsNotSubstring(const char* needle_expr, | |||
GTEST_API_ AssertionResult IsNotSubstring( | const char* haystack_expr, | |||
const char* needle_expr, const char* haystack_expr, | const char* needle, | |||
const wchar_t* needle, const wchar_t* haystack); | const char* haystack); | |||
GTEST_API_ AssertionResult IsSubstring( | GTEST_API_ AssertionResult IsNotSubstring(const char* needle_expr, | |||
const char* needle_expr, const char* haystack_expr, | const char* haystack_expr, | |||
const ::std::string& needle, const ::std::string& haystack); | const wchar_t* needle, | |||
GTEST_API_ AssertionResult IsNotSubstring( | const wchar_t* haystack); | |||
const char* needle_expr, const char* haystack_expr, | GTEST_API_ AssertionResult IsSubstring(const char* needle_expr, | |||
const ::std::string& needle, const ::std::string& haystack); | const char* haystack_expr, | |||
const ::std::string& needle, | ||||
const ::std::string& haystack); | ||||
GTEST_API_ AssertionResult IsNotSubstring(const char* needle_expr, | ||||
const char* haystack_expr, | ||||
const ::std::string& needle, | ||||
const ::std::string& haystack); | ||||
#if GTEST_HAS_STD_WSTRING | #if GTEST_HAS_STD_WSTRING | |||
GTEST_API_ AssertionResult IsSubstring( | GTEST_API_ AssertionResult IsSubstring(const char* needle_expr, | |||
const char* needle_expr, const char* haystack_expr, | const char* haystack_expr, | |||
const ::std::wstring& needle, const ::std::wstring& haystack); | const ::std::wstring& needle, | |||
GTEST_API_ AssertionResult IsNotSubstring( | const ::std::wstring& haystack); | |||
const char* needle_expr, const char* haystack_expr, | GTEST_API_ AssertionResult IsNotSubstring(const char* needle_expr, | |||
const ::std::wstring& needle, const ::std::wstring& haystack); | const char* haystack_expr, | |||
const ::std::wstring& needle, | ||||
const ::std::wstring& haystack); | ||||
#endif // GTEST_HAS_STD_WSTRING | #endif // GTEST_HAS_STD_WSTRING | |||
namespace internal { | namespace internal { | |||
// Helper template function for comparing floating-points. | // Helper template function for comparing floating-points. | |||
// | // | |||
// Template parameter: | // Template parameter: | |||
// | // | |||
// RawType: the raw floating-point type (either float or double) | // RawType: the raw floating-point type (either float or double) | |||
// | // | |||
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | |||
template <typename RawType> | template <typename RawType> | |||
AssertionResult CmpHelperFloatingPointEQ(const char* lhs_expression, | AssertionResult CmpHelperFloatingPointEQ(const char* lhs_expression, | |||
const char* rhs_expression, | const char* rhs_expression, | |||
RawType lhs_value, | RawType lhs_value, RawType rhs_value) { | |||
RawType rhs_value) { | ||||
const FloatingPoint<RawType> lhs(lhs_value), rhs(rhs_value); | const FloatingPoint<RawType> lhs(lhs_value), rhs(rhs_value); | |||
if (lhs.AlmostEquals(rhs)) { | if (lhs.AlmostEquals(rhs)) { | |||
return AssertionSuccess(); | return AssertionSuccess(); | |||
} | } | |||
::std::stringstream lhs_ss; | ::std::stringstream lhs_ss; | |||
lhs_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2) | lhs_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2) | |||
<< lhs_value; | << lhs_value; | |||
::std::stringstream rhs_ss; | ::std::stringstream rhs_ss; | |||
rhs_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2) | rhs_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2) | |||
<< rhs_value; | << rhs_value; | |||
return EqFailure(lhs_expression, | return EqFailure(lhs_expression, rhs_expression, | |||
rhs_expression, | StringStreamToString(&lhs_ss), StringStreamToString(&rhs_ss), | |||
StringStreamToString(&lhs_ss), | ||||
StringStreamToString(&rhs_ss), | ||||
false); | false); | |||
} | } | |||
// Helper function for implementing ASSERT_NEAR. | // Helper function for implementing ASSERT_NEAR. | |||
// | // | |||
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | |||
GTEST_API_ AssertionResult DoubleNearPredFormat(const char* expr1, | GTEST_API_ AssertionResult DoubleNearPredFormat(const char* expr1, | |||
const char* expr2, | const char* expr2, | |||
const char* abs_error_expr, | const char* abs_error_expr, | |||
double val1, | double val1, double val2, | |||
double val2, | ||||
double abs_error); | double abs_error); | |||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. | // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. | |||
// A class that enables one to stream messages to assertion macros | // A class that enables one to stream messages to assertion macros | |||
class GTEST_API_ AssertHelper { | class GTEST_API_ AssertHelper { | |||
public: | public: | |||
// Constructor. | // Constructor. | |||
AssertHelper(TestPartResult::Type type, | AssertHelper(TestPartResult::Type type, const char* file, int line, | |||
const char* file, | ||||
int line, | ||||
const char* message); | const char* message); | |||
~AssertHelper(); | ~AssertHelper(); | |||
// Message assignment is a semantic trick to enable assertion | // Message assignment is a semantic trick to enable assertion | |||
// streaming; see the GTEST_MESSAGE_ macro below. | // streaming; see the GTEST_MESSAGE_ macro below. | |||
void operator=(const Message& message) const; | void operator=(const Message& message) const; | |||
private: | private: | |||
// We put our data in a struct so that the size of the AssertHelper class can | // We put our data in a struct so that the size of the AssertHelper class can | |||
// be as small as possible. This is important because gcc is incapable of | // be as small as possible. This is important because gcc is incapable of | |||
// re-using stack space even for temporary variables, so every EXPECT_EQ | // re-using stack space even for temporary variables, so every EXPECT_EQ | |||
// reserves stack space for another AssertHelper. | // reserves stack space for another AssertHelper. | |||
struct AssertHelperData { | struct AssertHelperData { | |||
AssertHelperData(TestPartResult::Type t, | AssertHelperData(TestPartResult::Type t, const char* srcfile, int line_num, | |||
const char* srcfile, | ||||
int line_num, | ||||
const char* msg) | const char* msg) | |||
: type(t), file(srcfile), line(line_num), message(msg) { } | : type(t), file(srcfile), line(line_num), message(msg) {} | |||
TestPartResult::Type const type; | TestPartResult::Type const type; | |||
const char* const file; | const char* const file; | |||
int const line; | int const line; | |||
std::string const message; | std::string const message; | |||
private: | private: | |||
GTEST_DISALLOW_COPY_AND_ASSIGN_(AssertHelperData); | AssertHelperData(const AssertHelperData&) = delete; | |||
AssertHelperData& operator=(const AssertHelperData&) = delete; | ||||
}; | }; | |||
AssertHelperData* const data_; | AssertHelperData* const data_; | |||
GTEST_DISALLOW_COPY_AND_ASSIGN_(AssertHelper); | AssertHelper(const AssertHelper&) = delete; | |||
AssertHelper& operator=(const AssertHelper&) = delete; | ||||
}; | }; | |||
} // namespace internal | } // namespace internal | |||
// The pure interface class that all value-parameterized tests inherit from. | // The pure interface class that all value-parameterized tests inherit from. | |||
// A value-parameterized class must inherit from both ::testing::Test and | // A value-parameterized class must inherit from both ::testing::Test and | |||
// ::testing::WithParamInterface. In most cases that just means inheriting | // ::testing::WithParamInterface. In most cases that just means inheriting | |||
// from ::testing::TestWithParam, but more complicated test hierarchies | // from ::testing::TestWithParam, but more complicated test hierarchies | |||
// may need to inherit from Test and WithParamInterface at different levels. | // may need to inherit from Test and WithParamInterface at different levels. | |||
// | // | |||
skipping to change at line 1861 | skipping to change at line 1670 | |||
static const ParamType& GetParam() { | static const ParamType& GetParam() { | |||
GTEST_CHECK_(parameter_ != nullptr) | GTEST_CHECK_(parameter_ != nullptr) | |||
<< "GetParam() can only be called inside a value-parameterized test " | << "GetParam() can only be called inside a value-parameterized test " | |||
<< "-- did you intend to write TEST_P instead of TEST_F?"; | << "-- did you intend to write TEST_P instead of TEST_F?"; | |||
return *parameter_; | return *parameter_; | |||
} | } | |||
private: | private: | |||
// Sets parameter value. The caller is responsible for making sure the value | // Sets parameter value. The caller is responsible for making sure the value | |||
// remains alive and unchanged throughout the current test. | // remains alive and unchanged throughout the current test. | |||
static void SetParam(const ParamType* parameter) { | static void SetParam(const ParamType* parameter) { parameter_ = parameter; } | |||
parameter_ = parameter; | ||||
} | ||||
// Static value used for accessing parameter during a test lifetime. | // Static value used for accessing parameter during a test lifetime. | |||
static const ParamType* parameter_; | static const ParamType* parameter_; | |||
// TestClass must be a subclass of WithParamInterface<T> and Test. | // TestClass must be a subclass of WithParamInterface<T> and Test. | |||
template <class TestClass> friend class internal::ParameterizedTestFactory; | template <class TestClass> | |||
friend class internal::ParameterizedTestFactory; | ||||
}; | }; | |||
template <typename T> | template <typename T> | |||
const T* WithParamInterface<T>::parameter_ = nullptr; | const T* WithParamInterface<T>::parameter_ = nullptr; | |||
// Most value-parameterized classes can ignore the existence of | // Most value-parameterized classes can ignore the existence of | |||
// WithParamInterface, and can just inherit from ::testing::TestWithParam. | // WithParamInterface, and can just inherit from ::testing::TestWithParam. | |||
template <typename T> | template <typename T> | |||
class TestWithParam : public Test, public WithParamInterface<T> { | class TestWithParam : public Test, public WithParamInterface<T> {}; | |||
}; | ||||
// Macros for indicating success/failure in test code. | // Macros for indicating success/failure in test code. | |||
// Skips test in runtime. | // Skips test in runtime. | |||
// Skipping test aborts current function. | // Skipping test aborts current function. | |||
// Skipped tests are neither successful nor failed. | // Skipped tests are neither successful nor failed. | |||
#define GTEST_SKIP() GTEST_SKIP_("") | #define GTEST_SKIP() GTEST_SKIP_("") | |||
// ADD_FAILURE unconditionally adds a failure to the current test. | // ADD_FAILURE unconditionally adds a failure to the current test. | |||
// SUCCEED generates a success - it doesn't automatically make the | // SUCCEED generates a success - it doesn't automatically make the | |||
skipping to change at line 1911 | skipping to change at line 1718 | |||
// that they will also abort the current function on failure. People | // that they will also abort the current function on failure. People | |||
// usually want the fail-fast behavior of FAIL and ASSERT_*, but those | // usually want the fail-fast behavior of FAIL and ASSERT_*, but those | |||
// writing data-driven tests often find themselves using ADD_FAILURE | // writing data-driven tests often find themselves using ADD_FAILURE | |||
// and EXPECT_* more. | // and EXPECT_* more. | |||
// Generates a nonfatal failure with a generic message. | // Generates a nonfatal failure with a generic message. | |||
#define ADD_FAILURE() GTEST_NONFATAL_FAILURE_("Failed") | #define ADD_FAILURE() GTEST_NONFATAL_FAILURE_("Failed") | |||
// Generates a nonfatal failure at the given source file location with | // Generates a nonfatal failure at the given source file location with | |||
// a generic message. | // a generic message. | |||
#define ADD_FAILURE_AT(file, line) \ | #define ADD_FAILURE_AT(file, line) \ | |||
GTEST_MESSAGE_AT_(file, line, "Failed", \ | GTEST_MESSAGE_AT_(file, line, "Failed", \ | |||
::testing::TestPartResult::kNonFatalFailure) | ::testing::TestPartResult::kNonFatalFailure) | |||
// Generates a fatal failure with a generic message. | // Generates a fatal failure with a generic message. | |||
#define GTEST_FAIL() GTEST_FATAL_FAILURE_("Failed") | #define GTEST_FAIL() GTEST_FATAL_FAILURE_("Failed") | |||
// Like GTEST_FAIL(), but at the given source file location. | // Like GTEST_FAIL(), but at the given source file location. | |||
#define GTEST_FAIL_AT(file, line) \ | #define GTEST_FAIL_AT(file, line) \ | |||
GTEST_MESSAGE_AT_(file, line, "Failed", \ | GTEST_MESSAGE_AT_(file, line, "Failed", \ | |||
::testing::TestPartResult::kFatalFailure) | ::testing::TestPartResult::kFatalFailure) | |||
// Define this macro to 1 to omit the definition of FAIL(), which is a | // Define this macro to 1 to omit the definition of FAIL(), which is a | |||
// generic name and clashes with some other libraries. | // generic name and clashes with some other libraries. | |||
#if !GTEST_DONT_DEFINE_FAIL | #if !GTEST_DONT_DEFINE_FAIL | |||
# define FAIL() GTEST_FAIL() | #define FAIL() GTEST_FAIL() | |||
#endif | #endif | |||
// Generates a success with a generic message. | // Generates a success with a generic message. | |||
#define GTEST_SUCCEED() GTEST_SUCCESS_("Succeeded") | #define GTEST_SUCCEED() GTEST_SUCCESS_("Succeeded") | |||
// Define this macro to 1 to omit the definition of SUCCEED(), which | // Define this macro to 1 to omit the definition of SUCCEED(), which | |||
// is a generic name and clashes with some other libraries. | // is a generic name and clashes with some other libraries. | |||
#if !GTEST_DONT_DEFINE_SUCCEED | #if !GTEST_DONT_DEFINE_SUCCEED | |||
# define SUCCEED() GTEST_SUCCEED() | #define SUCCEED() GTEST_SUCCEED() | |||
#endif | #endif | |||
// Macros for testing exceptions. | // Macros for testing exceptions. | |||
// | // | |||
// * {ASSERT|EXPECT}_THROW(statement, expected_exception): | // * {ASSERT|EXPECT}_THROW(statement, expected_exception): | |||
// Tests that the statement throws the expected exception. | // Tests that the statement throws the expected exception. | |||
// * {ASSERT|EXPECT}_NO_THROW(statement): | // * {ASSERT|EXPECT}_NO_THROW(statement): | |||
// Tests that the statement doesn't throw any exception. | // Tests that the statement doesn't throw any exception. | |||
// * {ASSERT|EXPECT}_ANY_THROW(statement): | // * {ASSERT|EXPECT}_ANY_THROW(statement): | |||
// Tests that the statement throws an exception. | // Tests that the statement throws an exception. | |||
skipping to change at line 1963 | skipping to change at line 1770 | |||
#define ASSERT_THROW(statement, expected_exception) \ | #define ASSERT_THROW(statement, expected_exception) \ | |||
GTEST_TEST_THROW_(statement, expected_exception, GTEST_FATAL_FAILURE_) | GTEST_TEST_THROW_(statement, expected_exception, GTEST_FATAL_FAILURE_) | |||
#define ASSERT_NO_THROW(statement) \ | #define ASSERT_NO_THROW(statement) \ | |||
GTEST_TEST_NO_THROW_(statement, GTEST_FATAL_FAILURE_) | GTEST_TEST_NO_THROW_(statement, GTEST_FATAL_FAILURE_) | |||
#define ASSERT_ANY_THROW(statement) \ | #define ASSERT_ANY_THROW(statement) \ | |||
GTEST_TEST_ANY_THROW_(statement, GTEST_FATAL_FAILURE_) | GTEST_TEST_ANY_THROW_(statement, GTEST_FATAL_FAILURE_) | |||
// Boolean assertions. Condition can be either a Boolean expression or an | // Boolean assertions. Condition can be either a Boolean expression or an | |||
// AssertionResult. For more information on how to use AssertionResult with | // AssertionResult. For more information on how to use AssertionResult with | |||
// these macros see comments on that class. | // these macros see comments on that class. | |||
#define GTEST_EXPECT_TRUE(condition) \ | #define GTEST_EXPECT_TRUE(condition) \ | |||
GTEST_TEST_BOOLEAN_(condition, #condition, false, true, \ | GTEST_TEST_BOOLEAN_(condition, #condition, false, true, \ | |||
GTEST_NONFATAL_FAILURE_) | GTEST_NONFATAL_FAILURE_) | |||
#define GTEST_EXPECT_FALSE(condition) \ | #define GTEST_EXPECT_FALSE(condition) \ | |||
GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \ | GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \ | |||
GTEST_NONFATAL_FAILURE_) | GTEST_NONFATAL_FAILURE_) | |||
#define GTEST_ASSERT_TRUE(condition) \ | #define GTEST_ASSERT_TRUE(condition) \ | |||
GTEST_TEST_BOOLEAN_(condition, #condition, false, true, \ | GTEST_TEST_BOOLEAN_(condition, #condition, false, true, GTEST_FATAL_FAILURE_) | |||
GTEST_FATAL_FAILURE_) | #define GTEST_ASSERT_FALSE(condition) \ | |||
#define GTEST_ASSERT_FALSE(condition) \ | ||||
GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \ | GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \ | |||
GTEST_FATAL_FAILURE_) | GTEST_FATAL_FAILURE_) | |||
// Define these macros to 1 to omit the definition of the corresponding | // Define these macros to 1 to omit the definition of the corresponding | |||
// EXPECT or ASSERT, which clashes with some users' own code. | // EXPECT or ASSERT, which clashes with some users' own code. | |||
#if !GTEST_DONT_DEFINE_EXPECT_TRUE | #if !GTEST_DONT_DEFINE_EXPECT_TRUE | |||
#define EXPECT_TRUE(condition) GTEST_EXPECT_TRUE(condition) | #define EXPECT_TRUE(condition) GTEST_EXPECT_TRUE(condition) | |||
#endif | #endif | |||
skipping to change at line 2071 | skipping to change at line 1877 | |||
ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2) | ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2) | |||
#define GTEST_ASSERT_GE(val1, val2) \ | #define GTEST_ASSERT_GE(val1, val2) \ | |||
ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2) | ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2) | |||
#define GTEST_ASSERT_GT(val1, val2) \ | #define GTEST_ASSERT_GT(val1, val2) \ | |||
ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2) | ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2) | |||
// Define macro GTEST_DONT_DEFINE_ASSERT_XY to 1 to omit the definition of | // Define macro GTEST_DONT_DEFINE_ASSERT_XY to 1 to omit the definition of | |||
// ASSERT_XY(), which clashes with some users' own code. | // ASSERT_XY(), which clashes with some users' own code. | |||
#if !GTEST_DONT_DEFINE_ASSERT_EQ | #if !GTEST_DONT_DEFINE_ASSERT_EQ | |||
# define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2) | #define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2) | |||
#endif | #endif | |||
#if !GTEST_DONT_DEFINE_ASSERT_NE | #if !GTEST_DONT_DEFINE_ASSERT_NE | |||
# define ASSERT_NE(val1, val2) GTEST_ASSERT_NE(val1, val2) | #define ASSERT_NE(val1, val2) GTEST_ASSERT_NE(val1, val2) | |||
#endif | #endif | |||
#if !GTEST_DONT_DEFINE_ASSERT_LE | #if !GTEST_DONT_DEFINE_ASSERT_LE | |||
# define ASSERT_LE(val1, val2) GTEST_ASSERT_LE(val1, val2) | #define ASSERT_LE(val1, val2) GTEST_ASSERT_LE(val1, val2) | |||
#endif | #endif | |||
#if !GTEST_DONT_DEFINE_ASSERT_LT | #if !GTEST_DONT_DEFINE_ASSERT_LT | |||
# define ASSERT_LT(val1, val2) GTEST_ASSERT_LT(val1, val2) | #define ASSERT_LT(val1, val2) GTEST_ASSERT_LT(val1, val2) | |||
#endif | #endif | |||
#if !GTEST_DONT_DEFINE_ASSERT_GE | #if !GTEST_DONT_DEFINE_ASSERT_GE | |||
# define ASSERT_GE(val1, val2) GTEST_ASSERT_GE(val1, val2) | #define ASSERT_GE(val1, val2) GTEST_ASSERT_GE(val1, val2) | |||
#endif | #endif | |||
#if !GTEST_DONT_DEFINE_ASSERT_GT | #if !GTEST_DONT_DEFINE_ASSERT_GT | |||
# define ASSERT_GT(val1, val2) GTEST_ASSERT_GT(val1, val2) | #define ASSERT_GT(val1, val2) GTEST_ASSERT_GT(val1, val2) | |||
#endif | #endif | |||
// C-string Comparisons. All tests treat NULL and any non-NULL string | // C-string Comparisons. All tests treat NULL and any non-NULL string | |||
// as different. Two NULLs are equal. | // as different. Two NULLs are equal. | |||
// | // | |||
// * {ASSERT|EXPECT}_STREQ(s1, s2): Tests that s1 == s2 | // * {ASSERT|EXPECT}_STREQ(s1, s2): Tests that s1 == s2 | |||
// * {ASSERT|EXPECT}_STRNE(s1, s2): Tests that s1 != s2 | // * {ASSERT|EXPECT}_STRNE(s1, s2): Tests that s1 != s2 | |||
// * {ASSERT|EXPECT}_STRCASEEQ(s1, s2): Tests that s1 == s2, ignoring case | // * {ASSERT|EXPECT}_STRCASEEQ(s1, s2): Tests that s1 == s2, ignoring case | |||
// * {ASSERT|EXPECT}_STRCASENE(s1, s2): Tests that s1 != s2, ignoring case | // * {ASSERT|EXPECT}_STRCASENE(s1, s2): Tests that s1 != s2, ignoring case | |||
// | // | |||
skipping to change at line 2116 | skipping to change at line 1922 | |||
// which is undefined. | // which is undefined. | |||
// | // | |||
// These macros evaluate their arguments exactly once. | // These macros evaluate their arguments exactly once. | |||
#define EXPECT_STREQ(s1, s2) \ | #define EXPECT_STREQ(s1, s2) \ | |||
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, s1, s2) | EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, s1, s2) | |||
#define EXPECT_STRNE(s1, s2) \ | #define EXPECT_STRNE(s1, s2) \ | |||
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2) | EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2) | |||
#define EXPECT_STRCASEEQ(s1, s2) \ | #define EXPECT_STRCASEEQ(s1, s2) \ | |||
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, s1, s2) | EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, s1, s2) | |||
#define EXPECT_STRCASENE(s1, s2)\ | #define EXPECT_STRCASENE(s1, s2) \ | |||
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2) | EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2) | |||
#define ASSERT_STREQ(s1, s2) \ | #define ASSERT_STREQ(s1, s2) \ | |||
ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, s1, s2) | ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, s1, s2) | |||
#define ASSERT_STRNE(s1, s2) \ | #define ASSERT_STRNE(s1, s2) \ | |||
ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2) | ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2) | |||
#define ASSERT_STRCASEEQ(s1, s2) \ | #define ASSERT_STRCASEEQ(s1, s2) \ | |||
ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, s1, s2) | ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, s1, s2) | |||
#define ASSERT_STRCASENE(s1, s2)\ | #define ASSERT_STRCASENE(s1, s2) \ | |||
ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2) | ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2) | |||
// Macros for comparing floating-point numbers. | // Macros for comparing floating-point numbers. | |||
// | // | |||
// * {ASSERT|EXPECT}_FLOAT_EQ(val1, val2): | // * {ASSERT|EXPECT}_FLOAT_EQ(val1, val2): | |||
// Tests that two float values are almost equal. | // Tests that two float values are almost equal. | |||
// * {ASSERT|EXPECT}_DOUBLE_EQ(val1, val2): | // * {ASSERT|EXPECT}_DOUBLE_EQ(val1, val2): | |||
// Tests that two double values are almost equal. | // Tests that two double values are almost equal. | |||
// * {ASSERT|EXPECT}_NEAR(v1, v2, abs_error): | // * {ASSERT|EXPECT}_NEAR(v1, v2, abs_error): | |||
// Tests that v1 and v2 are within the given distance to each other. | // Tests that v1 and v2 are within the given distance to each other. | |||
// | // | |||
// Google Test uses ULP-based comparison to automatically pick a default | // Google Test uses ULP-based comparison to automatically pick a default | |||
// error bound that is appropriate for the operands. See the | // error bound that is appropriate for the operands. See the | |||
// FloatingPoint template class in gtest-internal.h if you are | // FloatingPoint template class in gtest-internal.h if you are | |||
// interested in the implementation details. | // interested in the implementation details. | |||
#define EXPECT_FLOAT_EQ(val1, val2)\ | #define EXPECT_FLOAT_EQ(val1, val2) \ | |||
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \ | EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \ | |||
val1, val2) | val1, val2) | |||
#define EXPECT_DOUBLE_EQ(val1, val2)\ | #define EXPECT_DOUBLE_EQ(val1, val2) \ | |||
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \ | EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \ | |||
val1, val2) | val1, val2) | |||
#define ASSERT_FLOAT_EQ(val1, val2)\ | #define ASSERT_FLOAT_EQ(val1, val2) \ | |||
ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \ | ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \ | |||
val1, val2) | val1, val2) | |||
#define ASSERT_DOUBLE_EQ(val1, val2)\ | #define ASSERT_DOUBLE_EQ(val1, val2) \ | |||
ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \ | ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \ | |||
val1, val2) | val1, val2) | |||
#define EXPECT_NEAR(val1, val2, abs_error)\ | #define EXPECT_NEAR(val1, val2, abs_error) \ | |||
EXPECT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, \ | EXPECT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, val1, val2, \ | |||
val1, val2, abs_error) | abs_error) | |||
#define ASSERT_NEAR(val1, val2, abs_error)\ | #define ASSERT_NEAR(val1, val2, abs_error) \ | |||
ASSERT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, \ | ASSERT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, val1, val2, \ | |||
val1, val2, abs_error) | abs_error) | |||
// These predicate format functions work on floating-point values, and | // These predicate format functions work on floating-point values, and | |||
// can be used in {ASSERT|EXPECT}_PRED_FORMAT2*(), e.g. | // can be used in {ASSERT|EXPECT}_PRED_FORMAT2*(), e.g. | |||
// | // | |||
// EXPECT_PRED_FORMAT2(testing::DoubleLE, Foo(), 5.0); | // EXPECT_PRED_FORMAT2(testing::DoubleLE, Foo(), 5.0); | |||
// Asserts that val1 is less than, or almost equal to, val2. Fails | // Asserts that val1 is less than, or almost equal to, val2. Fails | |||
// otherwise. In particular, it fails if either val1 or val2 is NaN. | // otherwise. In particular, it fails if either val1 or val2 is NaN. | |||
GTEST_API_ AssertionResult FloatLE(const char* expr1, const char* expr2, | GTEST_API_ AssertionResult FloatLE(const char* expr1, const char* expr2, | |||
float val1, float val2); | float val1, float val2); | |||
skipping to change at line 2189 | skipping to change at line 1995 | |||
// Macros that test for HRESULT failure and success, these are only useful | // Macros that test for HRESULT failure and success, these are only useful | |||
// on Windows, and rely on Windows SDK macros and APIs to compile. | // on Windows, and rely on Windows SDK macros and APIs to compile. | |||
// | // | |||
// * {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED}(expr) | // * {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED}(expr) | |||
// | // | |||
// When expr unexpectedly fails or succeeds, Google Test prints the | // When expr unexpectedly fails or succeeds, Google Test prints the | |||
// expected result and the actual result with both a human-readable | // expected result and the actual result with both a human-readable | |||
// string representation of the error, if available, as well as the | // string representation of the error, if available, as well as the | |||
// hex result code. | // hex result code. | |||
# define EXPECT_HRESULT_SUCCEEDED(expr) \ | #define EXPECT_HRESULT_SUCCEEDED(expr) \ | |||
EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr)) | EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr)) | |||
# define ASSERT_HRESULT_SUCCEEDED(expr) \ | #define ASSERT_HRESULT_SUCCEEDED(expr) \ | |||
ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr)) | ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr)) | |||
# define EXPECT_HRESULT_FAILED(expr) \ | #define EXPECT_HRESULT_FAILED(expr) \ | |||
EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr)) | EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr)) | |||
# define ASSERT_HRESULT_FAILED(expr) \ | #define ASSERT_HRESULT_FAILED(expr) \ | |||
ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr)) | ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr)) | |||
#endif // GTEST_OS_WINDOWS | #endif // GTEST_OS_WINDOWS | |||
// Macros that execute statement and check that it doesn't generate new fatal | // Macros that execute statement and check that it doesn't generate new fatal | |||
// failures in the current thread. | // failures in the current thread. | |||
// | // | |||
// * {ASSERT|EXPECT}_NO_FATAL_FAILURE(statement); | // * {ASSERT|EXPECT}_NO_FATAL_FAILURE(statement); | |||
// | // | |||
// Examples: | // Examples: | |||
// | // | |||
// EXPECT_NO_FATAL_FAILURE(Process()); | // EXPECT_NO_FATAL_FAILURE(Process()); | |||
// ASSERT_NO_FATAL_FAILURE(Process()) << "Process() failed"; | // ASSERT_NO_FATAL_FAILURE(Process()) << "Process() failed"; | |||
// | // | |||
#define ASSERT_NO_FATAL_FAILURE(statement) \ | #define ASSERT_NO_FATAL_FAILURE(statement) \ | |||
GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_FATAL_FAILURE_) | GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_FATAL_FAILURE_) | |||
#define EXPECT_NO_FATAL_FAILURE(statement) \ | #define EXPECT_NO_FATAL_FAILURE(statement) \ | |||
GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_NONFATAL_FAILURE_) | GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_NONFATAL_FAILURE_) | |||
// Causes a trace (including the given source file path and line number, | // Causes a trace (including the given source file path and line number, | |||
// and the given message) to be included in every test failure message generated | // and the given message) to be included in every test failure message generated | |||
// by code in the scope of the lifetime of an instance of this class. The effect | // by code in the scope of the lifetime of an instance of this class. The effect | |||
// is undone with the destruction of the instance. | // is undone with the destruction of the instance. | |||
// | // | |||
// The message argument can be anything streamable to std::ostream. | // The message argument can be anything streamable to std::ostream. | |||
// | // | |||
// Example: | // Example: | |||
// testing::ScopedTrace trace("file.cc", 123, "message"); | // testing::ScopedTrace trace("file.cc", 123, "message"); | |||
skipping to change at line 2258 | skipping to change at line 2064 | |||
// The d'tor pops the info pushed by the c'tor. | // The d'tor pops the info pushed by the c'tor. | |||
// | // | |||
// Note that the d'tor is not virtual in order to be efficient. | // Note that the d'tor is not virtual in order to be efficient. | |||
// Don't inherit from ScopedTrace! | // Don't inherit from ScopedTrace! | |||
~ScopedTrace(); | ~ScopedTrace(); | |||
private: | private: | |||
void PushTrace(const char* file, int line, std::string message); | void PushTrace(const char* file, int line, std::string message); | |||
GTEST_DISALLOW_COPY_AND_ASSIGN_(ScopedTrace); | ScopedTrace(const ScopedTrace&) = delete; | |||
ScopedTrace& operator=(const ScopedTrace&) = delete; | ||||
} GTEST_ATTRIBUTE_UNUSED_; // A ScopedTrace object does its job in its | } GTEST_ATTRIBUTE_UNUSED_; // A ScopedTrace object does its job in its | |||
// c'tor and d'tor. Therefore it doesn't | // c'tor and d'tor. Therefore it doesn't | |||
// need to be used otherwise. | // need to be used otherwise. | |||
// Causes a trace (including the source file path, the current line | // Causes a trace (including the source file path, the current line | |||
// number, and the given message) to be included in every test failure | // number, and the given message) to be included in every test failure | |||
// message generated by code in the current scope. The effect is | // message generated by code in the current scope. The effect is | |||
// undone when the control leaves the current scope. | // undone when the control leaves the current scope. | |||
// | // | |||
// The message argument can be anything streamable to std::ostream. | // The message argument can be anything streamable to std::ostream. | |||
// | // | |||
// In the implementation, we include the current line number as part | // In the implementation, we include the current line number as part | |||
// of the dummy variable name, thus allowing multiple SCOPED_TRACE()s | // of the dummy variable name, thus allowing multiple SCOPED_TRACE()s | |||
// to appear in the same block - as long as they are on different | // to appear in the same block - as long as they are on different | |||
// lines. | // lines. | |||
// | // | |||
// Assuming that each thread maintains its own stack of traces. | // Assuming that each thread maintains its own stack of traces. | |||
// Therefore, a SCOPED_TRACE() would (correctly) only affect the | // Therefore, a SCOPED_TRACE() would (correctly) only affect the | |||
// assertions in its own thread. | // assertions in its own thread. | |||
#define SCOPED_TRACE(message) \ | #define SCOPED_TRACE(message) \ | |||
::testing::ScopedTrace GTEST_CONCAT_TOKEN_(gtest_trace_, __LINE__)(\ | ::testing::ScopedTrace GTEST_CONCAT_TOKEN_(gtest_trace_, __LINE__)( \ | |||
__FILE__, __LINE__, (message)) | __FILE__, __LINE__, (message)) | |||
// Compile-time assertion for type equality. | // Compile-time assertion for type equality. | |||
// StaticAssertTypeEq<type1, type2>() compiles if and only if type1 and type2 | // StaticAssertTypeEq<type1, type2>() compiles if and only if type1 and type2 | |||
// are the same type. The value it returns is not interesting. | // are the same type. The value it returns is not interesting. | |||
// | // | |||
// Instead of making StaticAssertTypeEq a class template, we make it a | // Instead of making StaticAssertTypeEq a class template, we make it a | |||
// function template that invokes a helper class template. This | // function template that invokes a helper class template. This | |||
// prevents a user from misusing StaticAssertTypeEq<T1, T2> by | // prevents a user from misusing StaticAssertTypeEq<T1, T2> by | |||
// defining objects of that type. | // defining objects of that type. | |||
// | // | |||
skipping to change at line 2378 | skipping to change at line 2185 | |||
// }; | // }; | |||
// | // | |||
// TEST_F(FooTest, InitializesCorrectly) { | // TEST_F(FooTest, InitializesCorrectly) { | |||
// EXPECT_TRUE(a_.StatusIsOK()); | // EXPECT_TRUE(a_.StatusIsOK()); | |||
// } | // } | |||
// | // | |||
// TEST_F(FooTest, ReturnsElementCountCorrectly) { | // TEST_F(FooTest, ReturnsElementCountCorrectly) { | |||
// EXPECT_EQ(a_.size(), 0); | // EXPECT_EQ(a_.size(), 0); | |||
// EXPECT_EQ(b_.size(), 1); | // EXPECT_EQ(b_.size(), 1); | |||
// } | // } | |||
// | #define GTEST_TEST_F(test_fixture, test_name) \ | |||
// GOOGLETEST_CM0011 DO NOT DELETE | ||||
#if !GTEST_DONT_DEFINE_TEST | ||||
#define TEST_F(test_fixture, test_name)\ | ||||
GTEST_TEST_(test_fixture, test_name, test_fixture, \ | GTEST_TEST_(test_fixture, test_name, test_fixture, \ | |||
::testing::internal::GetTypeId<test_fixture>()) | ::testing::internal::GetTypeId<test_fixture>()) | |||
#endif // !GTEST_DONT_DEFINE_TEST | #if !GTEST_DONT_DEFINE_TEST_F | |||
#define TEST_F(test_fixture, test_name) GTEST_TEST_F(test_fixture, test_name) | ||||
#endif | ||||
// Returns a path to temporary directory. | // Returns a path to temporary directory. | |||
// Tries to determine an appropriate directory for the platform. | // Tries to determine an appropriate directory for the platform. | |||
GTEST_API_ std::string TempDir(); | GTEST_API_ std::string TempDir(); | |||
#ifdef _MSC_VER | #ifdef _MSC_VER | |||
# pragma warning(pop) | #pragma warning(pop) | |||
#endif | #endif | |||
// Dynamically registers a test with the framework. | // Dynamically registers a test with the framework. | |||
// | // | |||
// This is an advanced API only to be used when the `TEST` macros are | // This is an advanced API only to be used when the `TEST` macros are | |||
// insufficient. The macros should be preferred when possible, as they avoid | // insufficient. The macros should be preferred when possible, as they avoid | |||
// most of the complexity of calling this function. | // most of the complexity of calling this function. | |||
// | // | |||
// The `factory` argument is a factory callable (move-constructible) object or | // The `factory` argument is a factory callable (move-constructible) object or | |||
// function pointer that creates a new instance of the Test object. It | // function pointer that creates a new instance of the Test object. It | |||
skipping to change at line 2445 | skipping to change at line 2251 | |||
// ::testing::RegisterTest( | // ::testing::RegisterTest( | |||
// "MyFixture", ("Test" + std::to_string(v)).c_str(), nullptr, | // "MyFixture", ("Test" + std::to_string(v)).c_str(), nullptr, | |||
// std::to_string(v).c_str(), | // std::to_string(v).c_str(), | |||
// __FILE__, __LINE__, | // __FILE__, __LINE__, | |||
// // Important to use the fixture type as the return type here. | // // Important to use the fixture type as the return type here. | |||
// [=]() -> MyFixture* { return new MyTest(v); }); | // [=]() -> MyFixture* { return new MyTest(v); }); | |||
// } | // } | |||
// } | // } | |||
// ... | // ... | |||
// int main(int argc, char** argv) { | // int main(int argc, char** argv) { | |||
// ::testing::InitGoogleTest(&argc, argv); | ||||
// std::vector<int> values_to_test = LoadValuesFromConfig(); | // std::vector<int> values_to_test = LoadValuesFromConfig(); | |||
// RegisterMyTests(values_to_test); | // RegisterMyTests(values_to_test); | |||
// ... | // ... | |||
// return RUN_ALL_TESTS(); | // return RUN_ALL_TESTS(); | |||
// } | // } | |||
// | // | |||
template <int&... ExplicitParameterBarrier, typename Factory> | template <int&... ExplicitParameterBarrier, typename Factory> | |||
TestInfo* RegisterTest(const char* test_suite_name, const char* test_name, | TestInfo* RegisterTest(const char* test_suite_name, const char* test_name, | |||
const char* type_param, const char* value_param, | const char* type_param, const char* value_param, | |||
const char* file, int line, Factory factory) { | const char* file, int line, Factory factory) { | |||
skipping to change at line 2486 | skipping to change at line 2293 | |||
// Use this function in main() to run all tests. It returns 0 if all | // Use this function in main() to run all tests. It returns 0 if all | |||
// tests are successful, or 1 otherwise. | // tests are successful, or 1 otherwise. | |||
// | // | |||
// RUN_ALL_TESTS() should be invoked after the command line has been | // RUN_ALL_TESTS() should be invoked after the command line has been | |||
// parsed by InitGoogleTest(). | // parsed by InitGoogleTest(). | |||
// | // | |||
// This function was formerly a macro; thus, it is in the global | // This function was formerly a macro; thus, it is in the global | |||
// namespace and has an all-caps name. | // namespace and has an all-caps name. | |||
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_; | int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_; | |||
inline int RUN_ALL_TESTS() { | inline int RUN_ALL_TESTS() { return ::testing::UnitTest::GetInstance()->Run(); } | |||
return ::testing::UnitTest::GetInstance()->Run(); | ||||
} | ||||
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 | GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 | |||
#endif // GOOGLETEST_INCLUDE_GTEST_GTEST_H_ | #endif // GOOGLETEST_INCLUDE_GTEST_GTEST_H_ | |||
End of changes. 85 change blocks. | ||||
363 lines changed or deleted | 168 lines changed or added |