Commit b007c54f authored by Abseil Team's avatar Abseil Team Committed by Copybara-Service
Browse files

Running clang-format over all of GoogleTest

A few tests are examining code locations and looking af the resulting line
numbers to verify that GoogleTest shows those to users correctly. Some of those
locations change when clang-format is run. For those locations, I've wrapped
portions in:
// clang-format off
...
// clang-format on

There may be other locations that are currently not tickled by running
clang-format.

PiperOrigin-RevId: 434844712
Change-Id: I3a9f0a6f39eff741c576b6de389bef9b1d11139d
parent 8a422b83
...@@ -353,24 +353,17 @@ class TestProperty { ...@@ -353,24 +353,17 @@ class TestProperty {
// 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.
...@@ -628,8 +621,8 @@ class GTEST_API_ TestInfo { ...@@ -628,8 +621,8 @@ class GTEST_API_ TestInfo {
} }
// 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_;
...@@ -758,7 +751,7 @@ class GTEST_API_ TestSuite { ...@@ -758,7 +751,7 @@ class GTEST_API_ TestSuite {
// 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();
...@@ -886,6 +879,7 @@ class Environment { ...@@ -886,6 +879,7 @@ class Environment {
// 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().
...@@ -963,8 +957,7 @@ class TestEventListener { ...@@ -963,8 +957,7 @@ class TestEventListener {
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;
...@@ -1122,8 +1115,7 @@ class GTEST_API_ UnitTest { ...@@ -1122,8 +1115,7 @@ class GTEST_API_ UnitTest {
// 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;
...@@ -1229,8 +1221,7 @@ class GTEST_API_ UnitTest { ...@@ -1229,8 +1221,7 @@ class GTEST_API_ UnitTest {
// 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_);
...@@ -1261,8 +1252,7 @@ class GTEST_API_ UnitTest { ...@@ -1261,8 +1252,7 @@ class GTEST_API_ UnitTest {
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();
...@@ -1276,8 +1266,7 @@ class GTEST_API_ UnitTest { ...@@ -1276,8 +1266,7 @@ class GTEST_API_ UnitTest {
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.
...@@ -1341,13 +1330,11 @@ namespace internal { ...@@ -1341,13 +1330,11 @@ namespace internal {
// 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==/!=
...@@ -1360,8 +1347,7 @@ inline bool operator!=(faketype, faketype) { return false; } ...@@ -1360,8 +1347,7 @@ 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();
...@@ -1392,8 +1378,7 @@ class EqHelper { ...@@ -1392,8 +1378,7 @@ class EqHelper {
// 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);
} }
...@@ -1428,16 +1413,16 @@ AssertionResult CmpHelperOpFailure(const char* expr1, const char* expr2, ...@@ -1428,16 +1413,16 @@ AssertionResult CmpHelperOpFailure(const char* expr1, const char* expr2,
// //
// 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.
...@@ -1459,49 +1444,42 @@ GTEST_IMPL_CMP_HELPER_(GT, >) ...@@ -1459,49 +1444,42 @@ GTEST_IMPL_CMP_HELPER_(GT, >)
// 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
...@@ -1513,32 +1491,40 @@ GTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression, ...@@ -1513,32 +1491,40 @@ GTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression,
// //
// 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 {
...@@ -1553,8 +1539,7 @@ namespace internal { ...@@ -1553,8 +1539,7 @@ namespace internal {
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)) {
...@@ -1569,10 +1554,8 @@ AssertionResult CmpHelperFloatingPointEQ(const char* lhs_expression, ...@@ -1569,10 +1554,8 @@ AssertionResult CmpHelperFloatingPointEQ(const char* lhs_expression,
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);
} }
...@@ -1582,8 +1565,7 @@ AssertionResult CmpHelperFloatingPointEQ(const char* lhs_expression, ...@@ -1582,8 +1565,7 @@ AssertionResult CmpHelperFloatingPointEQ(const char* lhs_expression,
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.
...@@ -1591,9 +1573,7 @@ GTEST_API_ AssertionResult DoubleNearPredFormat(const char* expr1, ...@@ -1591,9 +1573,7 @@ GTEST_API_ AssertionResult DoubleNearPredFormat(const char* expr1,
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();
...@@ -1607,11 +1587,9 @@ class GTEST_API_ AssertHelper { ...@@ -1607,11 +1587,9 @@ class GTEST_API_ AssertHelper {
// 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;
...@@ -1681,15 +1659,14 @@ class WithParamInterface { ...@@ -1681,15 +1659,14 @@ class WithParamInterface {
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>
...@@ -1699,8 +1676,7 @@ const T* WithParamInterface<T>::parameter_ = nullptr; ...@@ -1699,8 +1676,7 @@ const T* WithParamInterface<T>::parameter_ = nullptr;
// 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.
...@@ -1731,7 +1707,7 @@ class TestWithParam : public Test, public WithParamInterface<T> { ...@@ -1731,7 +1707,7 @@ class TestWithParam : public Test, public WithParamInterface<T> {
// 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)
...@@ -1746,7 +1722,7 @@ class TestWithParam : public Test, public WithParamInterface<T> { ...@@ -1746,7 +1722,7 @@ class TestWithParam : public Test, public WithParamInterface<T> {
// 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.
...@@ -1755,7 +1731,7 @@ class TestWithParam : public Test, public WithParamInterface<T> { ...@@ -1755,7 +1731,7 @@ class TestWithParam : public Test, public WithParamInterface<T> {
// 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.
...@@ -1783,16 +1759,15 @@ class TestWithParam : public Test, public WithParamInterface<T> { ...@@ -1783,16 +1759,15 @@ class TestWithParam : public Test, public WithParamInterface<T> {
// 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_)
...@@ -1891,27 +1866,27 @@ class TestWithParam : public Test, public WithParamInterface<T> { ...@@ -1891,27 +1866,27 @@ class TestWithParam : public Test, public WithParamInterface<T> {
// 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
...@@ -1936,7 +1911,7 @@ class TestWithParam : public Test, public WithParamInterface<T> { ...@@ -1936,7 +1911,7 @@ class TestWithParam : public Test, public WithParamInterface<T> {
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) \
...@@ -1945,7 +1920,7 @@ class TestWithParam : public Test, public WithParamInterface<T> { ...@@ -1945,7 +1920,7 @@ class TestWithParam : public Test, public WithParamInterface<T> {
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.
...@@ -1962,29 +1937,29 @@ class TestWithParam : public Test, public WithParamInterface<T> { ...@@ -1962,29 +1937,29 @@ class TestWithParam : public Test, public WithParamInterface<T> {
// 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.
...@@ -1998,7 +1973,6 @@ GTEST_API_ AssertionResult FloatLE(const char* expr1, const char* expr2, ...@@ -1998,7 +1973,6 @@ GTEST_API_ AssertionResult FloatLE(const char* expr1, const char* expr2,
GTEST_API_ AssertionResult DoubleLE(const char* expr1, const char* expr2, GTEST_API_ AssertionResult DoubleLE(const char* expr1, const char* expr2,
double val1, double val2); double val1, double val2);
#if GTEST_OS_WINDOWS #if GTEST_OS_WINDOWS
// Macros that test for HRESULT failure and success, these are only useful // Macros that test for HRESULT failure and success, these are only useful
...@@ -2010,17 +1984,17 @@ GTEST_API_ AssertionResult DoubleLE(const char* expr1, const char* expr2, ...@@ -2010,17 +1984,17 @@ GTEST_API_ AssertionResult DoubleLE(const char* expr1, const char* expr2,
// 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
...@@ -2035,9 +2009,9 @@ GTEST_API_ AssertionResult DoubleLE(const char* expr1, const char* expr2, ...@@ -2035,9 +2009,9 @@ GTEST_API_ AssertionResult DoubleLE(const char* expr1, const char* expr2,
// 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
...@@ -2099,9 +2073,9 @@ class GTEST_API_ ScopedTrace { ...@@ -2099,9 +2073,9 @@ class GTEST_API_ ScopedTrace {
// 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
...@@ -2199,7 +2173,7 @@ constexpr bool StaticAssertTypeEq() noexcept { ...@@ -2199,7 +2173,7 @@ constexpr bool StaticAssertTypeEq() noexcept {
// 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)\ #define GTEST_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>())
#if !GTEST_DONT_DEFINE_TEST_F #if !GTEST_DONT_DEFINE_TEST_F
...@@ -2211,7 +2185,7 @@ constexpr bool StaticAssertTypeEq() noexcept { ...@@ -2211,7 +2185,7 @@ constexpr bool StaticAssertTypeEq() noexcept {
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.
...@@ -2307,9 +2281,7 @@ TestInfo* RegisterTest(const char* test_suite_name, const char* test_name, ...@@ -2307,9 +2281,7 @@ TestInfo* RegisterTest(const char* test_suite_name, const char* test_name,
// 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
......
...@@ -74,22 +74,18 @@ namespace testing { ...@@ -74,22 +74,18 @@ namespace testing {
// GTEST_ASSERT_ is the basic statement to which all of the assertions // GTEST_ASSERT_ is the basic statement to which all of the assertions
// in this file reduce. Don't use this in your code. // in this file reduce. Don't use this in your code.
#define GTEST_ASSERT_(expression, on_failure) \ #define GTEST_ASSERT_(expression, on_failure) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if (const ::testing::AssertionResult gtest_ar = (expression)) \ if (const ::testing::AssertionResult gtest_ar = (expression)) \
; \ ; \
else \ else \
on_failure(gtest_ar.failure_message()) on_failure(gtest_ar.failure_message())
// Helper function for implementing {EXPECT|ASSERT}_PRED1. Don't use // Helper function for implementing {EXPECT|ASSERT}_PRED1. Don't use
// this in your code. // this in your code.
template <typename Pred, template <typename Pred, typename T1>
typename T1> AssertionResult AssertPred1Helper(const char* pred_text, const char* e1,
AssertionResult AssertPred1Helper(const char* pred_text, Pred pred, const T1& v1) {
const char* e1,
Pred pred,
const T1& v1) {
if (pred(v1)) return AssertionSuccess(); if (pred(v1)) return AssertionSuccess();
return AssertionFailure() return AssertionFailure()
...@@ -100,40 +96,27 @@ AssertionResult AssertPred1Helper(const char* pred_text, ...@@ -100,40 +96,27 @@ AssertionResult AssertPred1Helper(const char* pred_text,
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT1. // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT1.
// Don't use this in your code. // Don't use this in your code.
#define GTEST_PRED_FORMAT1_(pred_format, v1, on_failure)\ #define GTEST_PRED_FORMAT1_(pred_format, v1, on_failure) \
GTEST_ASSERT_(pred_format(#v1, v1), \ GTEST_ASSERT_(pred_format(#v1, v1), on_failure)
on_failure)
// Internal macro for implementing {EXPECT|ASSERT}_PRED1. Don't use // Internal macro for implementing {EXPECT|ASSERT}_PRED1. Don't use
// this in your code. // this in your code.
#define GTEST_PRED1_(pred, v1, on_failure)\ #define GTEST_PRED1_(pred, v1, on_failure) \
GTEST_ASSERT_(::testing::AssertPred1Helper(#pred, \ GTEST_ASSERT_(::testing::AssertPred1Helper(#pred, #v1, pred, v1), on_failure)
#v1, \
pred, \
v1), on_failure)
// Unary predicate assertion macros. // Unary predicate assertion macros.
#define EXPECT_PRED_FORMAT1(pred_format, v1) \ #define EXPECT_PRED_FORMAT1(pred_format, v1) \
GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_NONFATAL_FAILURE_) GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_NONFATAL_FAILURE_)
#define EXPECT_PRED1(pred, v1) \ #define EXPECT_PRED1(pred, v1) GTEST_PRED1_(pred, v1, GTEST_NONFATAL_FAILURE_)
GTEST_PRED1_(pred, v1, GTEST_NONFATAL_FAILURE_)
#define ASSERT_PRED_FORMAT1(pred_format, v1) \ #define ASSERT_PRED_FORMAT1(pred_format, v1) \
GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_FATAL_FAILURE_) GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_FATAL_FAILURE_)
#define ASSERT_PRED1(pred, v1) \ #define ASSERT_PRED1(pred, v1) GTEST_PRED1_(pred, v1, GTEST_FATAL_FAILURE_)
GTEST_PRED1_(pred, v1, GTEST_FATAL_FAILURE_)
// Helper function for implementing {EXPECT|ASSERT}_PRED2. Don't use // Helper function for implementing {EXPECT|ASSERT}_PRED2. Don't use
// this in your code. // this in your code.
template <typename Pred, template <typename Pred, typename T1, typename T2>
typename T1, AssertionResult AssertPred2Helper(const char* pred_text, const char* e1,
typename T2> const char* e2, Pred pred, const T1& v1,
AssertionResult AssertPred2Helper(const char* pred_text,
const char* e1,
const char* e2,
Pred pred,
const T1& v1,
const T2& v2) { const T2& v2) {
if (pred(v1, v2)) return AssertionSuccess(); if (pred(v1, v2)) return AssertionSuccess();
...@@ -147,19 +130,14 @@ AssertionResult AssertPred2Helper(const char* pred_text, ...@@ -147,19 +130,14 @@ AssertionResult AssertPred2Helper(const char* pred_text,
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT2. // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT2.
// Don't use this in your code. // Don't use this in your code.
#define GTEST_PRED_FORMAT2_(pred_format, v1, v2, on_failure)\ #define GTEST_PRED_FORMAT2_(pred_format, v1, v2, on_failure) \
GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2), \ GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2), on_failure)
on_failure)
// Internal macro for implementing {EXPECT|ASSERT}_PRED2. Don't use // Internal macro for implementing {EXPECT|ASSERT}_PRED2. Don't use
// this in your code. // this in your code.
#define GTEST_PRED2_(pred, v1, v2, on_failure)\ #define GTEST_PRED2_(pred, v1, v2, on_failure) \
GTEST_ASSERT_(::testing::AssertPred2Helper(#pred, \ GTEST_ASSERT_(::testing::AssertPred2Helper(#pred, #v1, #v2, pred, v1, v2), \
#v1, \ on_failure)
#v2, \
pred, \
v1, \
v2), on_failure)
// Binary predicate assertion macros. // Binary predicate assertion macros.
#define EXPECT_PRED_FORMAT2(pred_format, v1, v2) \ #define EXPECT_PRED_FORMAT2(pred_format, v1, v2) \
...@@ -171,22 +149,12 @@ AssertionResult AssertPred2Helper(const char* pred_text, ...@@ -171,22 +149,12 @@ AssertionResult AssertPred2Helper(const char* pred_text,
#define ASSERT_PRED2(pred, v1, v2) \ #define ASSERT_PRED2(pred, v1, v2) \
GTEST_PRED2_(pred, v1, v2, GTEST_FATAL_FAILURE_) GTEST_PRED2_(pred, v1, v2, GTEST_FATAL_FAILURE_)
// Helper function for implementing {EXPECT|ASSERT}_PRED3. Don't use // Helper function for implementing {EXPECT|ASSERT}_PRED3. Don't use
// this in your code. // this in your code.
template <typename Pred, template <typename Pred, typename T1, typename T2, typename T3>
typename T1, AssertionResult AssertPred3Helper(const char* pred_text, const char* e1,
typename T2, const char* e2, const char* e3, Pred pred,
typename T3> const T1& v1, const T2& v2, const T3& v3) {
AssertionResult AssertPred3Helper(const char* pred_text,
const char* e1,
const char* e2,
const char* e3,
Pred pred,
const T1& v1,
const T2& v2,
const T3& v3) {
if (pred(v1, v2, v3)) return AssertionSuccess(); if (pred(v1, v2, v3)) return AssertionSuccess();
return AssertionFailure() return AssertionFailure()
...@@ -200,21 +168,15 @@ AssertionResult AssertPred3Helper(const char* pred_text, ...@@ -200,21 +168,15 @@ AssertionResult AssertPred3Helper(const char* pred_text,
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT3. // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT3.
// Don't use this in your code. // Don't use this in your code.
#define GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, on_failure)\ #define GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, on_failure) \
GTEST_ASSERT_(pred_format(#v1, #v2, #v3, v1, v2, v3), \ GTEST_ASSERT_(pred_format(#v1, #v2, #v3, v1, v2, v3), on_failure)
on_failure)
// Internal macro for implementing {EXPECT|ASSERT}_PRED3. Don't use // Internal macro for implementing {EXPECT|ASSERT}_PRED3. Don't use
// this in your code. // this in your code.
#define GTEST_PRED3_(pred, v1, v2, v3, on_failure)\ #define GTEST_PRED3_(pred, v1, v2, v3, on_failure) \
GTEST_ASSERT_(::testing::AssertPred3Helper(#pred, \ GTEST_ASSERT_( \
#v1, \ ::testing::AssertPred3Helper(#pred, #v1, #v2, #v3, pred, v1, v2, v3), \
#v2, \ on_failure)
#v3, \
pred, \
v1, \
v2, \
v3), on_failure)
// Ternary predicate assertion macros. // Ternary predicate assertion macros.
#define EXPECT_PRED_FORMAT3(pred_format, v1, v2, v3) \ #define EXPECT_PRED_FORMAT3(pred_format, v1, v2, v3) \
...@@ -226,25 +188,13 @@ AssertionResult AssertPred3Helper(const char* pred_text, ...@@ -226,25 +188,13 @@ AssertionResult AssertPred3Helper(const char* pred_text,
#define ASSERT_PRED3(pred, v1, v2, v3) \ #define ASSERT_PRED3(pred, v1, v2, v3) \
GTEST_PRED3_(pred, v1, v2, v3, GTEST_FATAL_FAILURE_) GTEST_PRED3_(pred, v1, v2, v3, GTEST_FATAL_FAILURE_)
// Helper function for implementing {EXPECT|ASSERT}_PRED4. Don't use // Helper function for implementing {EXPECT|ASSERT}_PRED4. Don't use
// this in your code. // this in your code.
template <typename Pred, template <typename Pred, typename T1, typename T2, typename T3, typename T4>
typename T1, AssertionResult AssertPred4Helper(const char* pred_text, const char* e1,
typename T2, const char* e2, const char* e3,
typename T3, const char* e4, Pred pred, const T1& v1,
typename T4> const T2& v2, const T3& v3, const T4& v4) {
AssertionResult AssertPred4Helper(const char* pred_text,
const char* e1,
const char* e2,
const char* e3,
const char* e4,
Pred pred,
const T1& v1,
const T2& v2,
const T3& v3,
const T4& v4) {
if (pred(v1, v2, v3, v4)) return AssertionSuccess(); if (pred(v1, v2, v3, v4)) return AssertionSuccess();
return AssertionFailure() return AssertionFailure()
...@@ -259,23 +209,15 @@ AssertionResult AssertPred4Helper(const char* pred_text, ...@@ -259,23 +209,15 @@ AssertionResult AssertPred4Helper(const char* pred_text,
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT4. // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT4.
// Don't use this in your code. // Don't use this in your code.
#define GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, on_failure)\ #define GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, on_failure) \
GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, v1, v2, v3, v4), \ GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, v1, v2, v3, v4), on_failure)
on_failure)
// Internal macro for implementing {EXPECT|ASSERT}_PRED4. Don't use // Internal macro for implementing {EXPECT|ASSERT}_PRED4. Don't use
// this in your code. // this in your code.
#define GTEST_PRED4_(pred, v1, v2, v3, v4, on_failure)\ #define GTEST_PRED4_(pred, v1, v2, v3, v4, on_failure) \
GTEST_ASSERT_(::testing::AssertPred4Helper(#pred, \ GTEST_ASSERT_(::testing::AssertPred4Helper(#pred, #v1, #v2, #v3, #v4, pred, \
#v1, \ v1, v2, v3, v4), \
#v2, \ on_failure)
#v3, \
#v4, \
pred, \
v1, \
v2, \
v3, \
v4), on_failure)
// 4-ary predicate assertion macros. // 4-ary predicate assertion macros.
#define EXPECT_PRED_FORMAT4(pred_format, v1, v2, v3, v4) \ #define EXPECT_PRED_FORMAT4(pred_format, v1, v2, v3, v4) \
...@@ -287,28 +229,15 @@ AssertionResult AssertPred4Helper(const char* pred_text, ...@@ -287,28 +229,15 @@ AssertionResult AssertPred4Helper(const char* pred_text,
#define ASSERT_PRED4(pred, v1, v2, v3, v4) \ #define ASSERT_PRED4(pred, v1, v2, v3, v4) \
GTEST_PRED4_(pred, v1, v2, v3, v4, GTEST_FATAL_FAILURE_) GTEST_PRED4_(pred, v1, v2, v3, v4, GTEST_FATAL_FAILURE_)
// Helper function for implementing {EXPECT|ASSERT}_PRED5. Don't use // Helper function for implementing {EXPECT|ASSERT}_PRED5. Don't use
// this in your code. // this in your code.
template <typename Pred, template <typename Pred, typename T1, typename T2, typename T3, typename T4,
typename T1,
typename T2,
typename T3,
typename T4,
typename T5> typename T5>
AssertionResult AssertPred5Helper(const char* pred_text, AssertionResult AssertPred5Helper(const char* pred_text, const char* e1,
const char* e1, const char* e2, const char* e3,
const char* e2, const char* e4, const char* e5, Pred pred,
const char* e3, const T1& v1, const T2& v2, const T3& v3,
const char* e4, const T4& v4, const T5& v5) {
const char* e5,
Pred pred,
const T1& v1,
const T2& v2,
const T3& v3,
const T4& v4,
const T5& v5) {
if (pred(v1, v2, v3, v4, v5)) return AssertionSuccess(); if (pred(v1, v2, v3, v4, v5)) return AssertionSuccess();
return AssertionFailure() return AssertionFailure()
...@@ -324,25 +253,16 @@ AssertionResult AssertPred5Helper(const char* pred_text, ...@@ -324,25 +253,16 @@ AssertionResult AssertPred5Helper(const char* pred_text,
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT5. // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT5.
// Don't use this in your code. // Don't use this in your code.
#define GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, on_failure)\ #define GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, on_failure) \
GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, #v5, v1, v2, v3, v4, v5), \ GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, #v5, v1, v2, v3, v4, v5), \
on_failure) on_failure)
// Internal macro for implementing {EXPECT|ASSERT}_PRED5. Don't use // Internal macro for implementing {EXPECT|ASSERT}_PRED5. Don't use
// this in your code. // this in your code.
#define GTEST_PRED5_(pred, v1, v2, v3, v4, v5, on_failure)\ #define GTEST_PRED5_(pred, v1, v2, v3, v4, v5, on_failure) \
GTEST_ASSERT_(::testing::AssertPred5Helper(#pred, \ GTEST_ASSERT_(::testing::AssertPred5Helper(#pred, #v1, #v2, #v3, #v4, #v5, \
#v1, \ pred, v1, v2, v3, v4, v5), \
#v2, \ on_failure)
#v3, \
#v4, \
#v5, \
pred, \
v1, \
v2, \
v3, \
v4, \
v5), on_failure)
// 5-ary predicate assertion macros. // 5-ary predicate assertion macros.
#define EXPECT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5) \ #define EXPECT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5) \
...@@ -354,8 +274,6 @@ AssertionResult AssertPred5Helper(const char* pred_text, ...@@ -354,8 +274,6 @@ AssertionResult AssertPred5Helper(const char* pred_text,
#define ASSERT_PRED5(pred, v1, v2, v3, v4, v5) \ #define ASSERT_PRED5(pred, v1, v2, v3, v4, v5) \
GTEST_PRED5_(pred, v1, v2, v3, v4, v5, GTEST_FATAL_FAILURE_) GTEST_PRED5_(pred, v1, v2, v3, v4, v5, GTEST_FATAL_FAILURE_)
} // namespace testing } // namespace testing
#endif // GOOGLETEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_ #endif // GOOGLETEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
// Note: The test class must be in the same namespace as the class being tested. // Note: The test class must be in the same namespace as the class being tested.
// For example, putting MyClassTest in an anonymous namespace will not work. // For example, putting MyClassTest in an anonymous namespace will not work.
#define FRIEND_TEST(test_case_name, test_name)\ #define FRIEND_TEST(test_case_name, test_name) \
friend class test_case_name##_##test_name##_Test friend class test_case_name##_##test_name##_Test
#endif // GOOGLETEST_INCLUDE_GTEST_GTEST_PROD_H_ #endif // GOOGLETEST_INCLUDE_GTEST_GTEST_PROD_H_
...@@ -39,12 +39,13 @@ ...@@ -39,12 +39,13 @@
#ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_ #ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_
#define GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_ #define GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_
#include "gtest/gtest-matchers.h"
#include "gtest/internal/gtest-internal.h"
#include <stdio.h> #include <stdio.h>
#include <memory> #include <memory>
#include "gtest/gtest-matchers.h"
#include "gtest/internal/gtest-internal.h"
GTEST_DECLARE_string_(internal_run_death_test); GTEST_DECLARE_string_(internal_run_death_test);
namespace testing { namespace testing {
...@@ -86,13 +87,14 @@ class GTEST_API_ DeathTest { ...@@ -86,13 +87,14 @@ class GTEST_API_ DeathTest {
static bool Create(const char* statement, Matcher<const std::string&> matcher, static bool Create(const char* statement, Matcher<const std::string&> matcher,
const char* file, int line, DeathTest** test); const char* file, int line, DeathTest** test);
DeathTest(); DeathTest();
virtual ~DeathTest() { } virtual ~DeathTest() {}
// A helper class that aborts a death test when it's deleted. // A helper class that aborts a death test when it's deleted.
class ReturnSentinel { class ReturnSentinel {
public: public:
explicit ReturnSentinel(DeathTest* test) : test_(test) { } explicit ReturnSentinel(DeathTest* test) : test_(test) {}
~ReturnSentinel() { test_->Abort(TEST_ENCOUNTERED_RETURN_STATEMENT); } ~ReturnSentinel() { test_->Abort(TEST_ENCOUNTERED_RETURN_STATEMENT); }
private: private:
DeathTest* const test_; DeathTest* const test_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(ReturnSentinel); GTEST_DISALLOW_COPY_AND_ASSIGN_(ReturnSentinel);
...@@ -148,7 +150,7 @@ GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 ...@@ -148,7 +150,7 @@ GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
// Factory interface for death tests. May be mocked out for testing. // Factory interface for death tests. May be mocked out for testing.
class DeathTestFactory { class DeathTestFactory {
public: public:
virtual ~DeathTestFactory() { } virtual ~DeathTestFactory() {}
virtual bool Create(const char* statement, virtual bool Create(const char* statement,
Matcher<const std::string&> matcher, const char* file, Matcher<const std::string&> matcher, const char* file,
int line, DeathTest** test) = 0; int line, DeathTest** test) = 0;
...@@ -189,28 +191,28 @@ inline Matcher<const ::std::string&> MakeDeathTestMatcher( ...@@ -189,28 +191,28 @@ inline Matcher<const ::std::string&> MakeDeathTestMatcher(
// Traps C++ exceptions escaping statement and reports them as test // Traps C++ exceptions escaping statement and reports them as test
// failures. Note that trapping SEH exceptions is not implemented here. // failures. Note that trapping SEH exceptions is not implemented here.
# if GTEST_HAS_EXCEPTIONS #if GTEST_HAS_EXCEPTIONS
# define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \ #define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \
try { \ try { \
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
} catch (const ::std::exception& gtest_exception) { \ } catch (const ::std::exception& gtest_exception) { \
fprintf(\ fprintf( \
stderr, \ stderr, \
"\n%s: Caught std::exception-derived exception escaping the " \ "\n%s: Caught std::exception-derived exception escaping the " \
"death test statement. Exception message: %s\n", \ "death test statement. Exception message: %s\n", \
::testing::internal::FormatFileLocation(__FILE__, __LINE__).c_str(), \ ::testing::internal::FormatFileLocation(__FILE__, __LINE__).c_str(), \
gtest_exception.what()); \ gtest_exception.what()); \
fflush(stderr); \ fflush(stderr); \
death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION); \ death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION); \
} catch (...) { \ } catch (...) { \
death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION); \ death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION); \
} }
# else #else
# define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \ #define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement)
# endif #endif
// This macro is for implementing ASSERT_DEATH*, EXPECT_DEATH*, // This macro is for implementing ASSERT_DEATH*, EXPECT_DEATH*,
// ASSERT_EXIT*, and EXPECT_EXIT*. // ASSERT_EXIT*, and EXPECT_EXIT*.
...@@ -266,16 +268,12 @@ inline Matcher<const ::std::string&> MakeDeathTestMatcher( ...@@ -266,16 +268,12 @@ inline Matcher<const ::std::string&> MakeDeathTestMatcher(
// RUN_ALL_TESTS was called. // RUN_ALL_TESTS was called.
class InternalRunDeathTestFlag { class InternalRunDeathTestFlag {
public: public:
InternalRunDeathTestFlag(const std::string& a_file, InternalRunDeathTestFlag(const std::string& a_file, int a_line, int an_index,
int a_line,
int an_index,
int a_write_fd) int a_write_fd)
: file_(a_file), line_(a_line), index_(an_index), : file_(a_file), line_(a_line), index_(an_index), write_fd_(a_write_fd) {}
write_fd_(a_write_fd) {}
~InternalRunDeathTestFlag() { ~InternalRunDeathTestFlag() {
if (write_fd_ >= 0) if (write_fd_ >= 0) posix::Close(write_fd_);
posix::Close(write_fd_);
} }
const std::string& file() const { return file_; } const std::string& file() const { return file_; }
......
...@@ -63,8 +63,8 @@ namespace internal { ...@@ -63,8 +63,8 @@ namespace internal {
class GTEST_API_ FilePath { class GTEST_API_ FilePath {
public: public:
FilePath() : pathname_("") { } FilePath() : pathname_("") {}
FilePath(const FilePath& rhs) : pathname_(rhs.pathname_) { } FilePath(const FilePath& rhs) : pathname_(rhs.pathname_) {}
explicit FilePath(const std::string& pathname) : pathname_(pathname) { explicit FilePath(const std::string& pathname) : pathname_(pathname) {
Normalize(); Normalize();
...@@ -75,9 +75,7 @@ class GTEST_API_ FilePath { ...@@ -75,9 +75,7 @@ class GTEST_API_ FilePath {
return *this; return *this;
} }
void Set(const FilePath& rhs) { void Set(const FilePath& rhs) { pathname_ = rhs.pathname_; }
pathname_ = rhs.pathname_;
}
const std::string& string() const { return pathname_; } const std::string& string() const { return pathname_; }
const char* c_str() const { return pathname_.c_str(); } const char* c_str() const { return pathname_.c_str(); }
...@@ -90,8 +88,7 @@ class GTEST_API_ FilePath { ...@@ -90,8 +88,7 @@ class GTEST_API_ FilePath {
// than zero (e.g., 12), returns "dir/test_12.xml". // than zero (e.g., 12), returns "dir/test_12.xml".
// On Windows platform, uses \ as the separator rather than /. // On Windows platform, uses \ as the separator rather than /.
static FilePath MakeFileName(const FilePath& directory, static FilePath MakeFileName(const FilePath& directory,
const FilePath& base_name, const FilePath& base_name, int number,
int number,
const char* extension); const char* extension);
// Given directory = "dir", relative_path = "test.xml", // Given directory = "dir", relative_path = "test.xml",
......
...@@ -42,19 +42,20 @@ ...@@ -42,19 +42,20 @@
#include "gtest/internal/gtest-port.h" #include "gtest/internal/gtest-port.h"
#if GTEST_OS_LINUX #if GTEST_OS_LINUX
# include <stdlib.h> #include <stdlib.h>
# include <sys/types.h> #include <sys/types.h>
# include <sys/wait.h> #include <sys/wait.h>
# include <unistd.h> #include <unistd.h>
#endif // GTEST_OS_LINUX #endif // GTEST_OS_LINUX
#if GTEST_HAS_EXCEPTIONS #if GTEST_HAS_EXCEPTIONS
# include <stdexcept> #include <stdexcept>
#endif #endif
#include <ctype.h> #include <ctype.h>
#include <float.h> #include <float.h>
#include <string.h> #include <string.h>
#include <cstdint> #include <cstdint>
#include <iomanip> #include <iomanip>
#include <limits> #include <limits>
...@@ -78,7 +79,7 @@ ...@@ -78,7 +79,7 @@
// the current line number. For more details, see // the current line number. For more details, see
// http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.6 // http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.6
#define GTEST_CONCAT_TOKEN_(foo, bar) GTEST_CONCAT_TOKEN_IMPL_(foo, bar) #define GTEST_CONCAT_TOKEN_(foo, bar) GTEST_CONCAT_TOKEN_IMPL_(foo, bar)
#define GTEST_CONCAT_TOKEN_IMPL_(foo, bar) foo ## bar #define GTEST_CONCAT_TOKEN_IMPL_(foo, bar) foo##bar
// Stringifies its argument. // Stringifies its argument.
// Work around a bug in visual studio which doesn't accept code like this: // Work around a bug in visual studio which doesn't accept code like this:
...@@ -100,21 +101,21 @@ namespace testing { ...@@ -100,21 +101,21 @@ namespace testing {
// Forward declarations. // Forward declarations.
class AssertionResult; // Result of an assertion. class AssertionResult; // Result of an assertion.
class Message; // Represents a failure message. class Message; // Represents a failure message.
class Test; // Represents a test. class Test; // Represents a test.
class TestInfo; // Information about a test. class TestInfo; // Information about a test.
class TestPartResult; // Result of a test part. class TestPartResult; // Result of a test part.
class UnitTest; // A collection of test suites. class UnitTest; // A collection of test suites.
template <typename T> template <typename T>
::std::string PrintToString(const T& value); ::std::string PrintToString(const T& value);
namespace internal { namespace internal {
struct TraceInfo; // Information about a trace point. struct TraceInfo; // Information about a trace point.
class TestInfoImpl; // Opaque implementation of TestInfo class TestInfoImpl; // Opaque implementation of TestInfo
class UnitTestImpl; // Opaque implementation of UnitTest class UnitTestImpl; // Opaque implementation of UnitTest
// The text used in failure messages to indicate the start of the // The text used in failure messages to indicate the start of the
// stack trace. // stack trace.
...@@ -123,6 +124,7 @@ GTEST_API_ extern const char kStackTraceMarker[]; ...@@ -123,6 +124,7 @@ GTEST_API_ extern const char kStackTraceMarker[];
// An IgnoredValue object can be implicitly constructed from ANY value. // An IgnoredValue object can be implicitly constructed from ANY value.
class IgnoredValue { class IgnoredValue {
struct Sink {}; struct Sink {};
public: public:
// This constructor template allows any value to be implicitly // This constructor template allows any value to be implicitly
// converted to IgnoredValue. The object has no data member and // converted to IgnoredValue. The object has no data member and
...@@ -138,13 +140,13 @@ class IgnoredValue { ...@@ -138,13 +140,13 @@ class IgnoredValue {
}; };
// Appends the user-supplied message to the Google-Test-generated message. // Appends the user-supplied message to the Google-Test-generated message.
GTEST_API_ std::string AppendUserMessage( GTEST_API_ std::string AppendUserMessage(const std::string& gtest_msg,
const std::string& gtest_msg, const Message& user_msg); const Message& user_msg);
#if GTEST_HAS_EXCEPTIONS #if GTEST_HAS_EXCEPTIONS
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4275 \ GTEST_DISABLE_MSC_WARNINGS_PUSH_(
/* an exported class was derived from a class that was not exported */) 4275 /* an exported class was derived from a class that was not exported */)
// This exception is thrown by (and only by) a failed Google Test // This exception is thrown by (and only by) a failed Google Test
// assertion when GTEST_FLAG(throw_on_failure) is true (if exceptions // assertion when GTEST_FLAG(throw_on_failure) is true (if exceptions
...@@ -214,10 +216,8 @@ GTEST_API_ AssertionResult EqFailure(const char* expected_expression, ...@@ -214,10 +216,8 @@ GTEST_API_ AssertionResult EqFailure(const char* expected_expression,
// Constructs a failure message for Boolean assertions such as EXPECT_TRUE. // Constructs a failure message for Boolean assertions such as EXPECT_TRUE.
GTEST_API_ std::string GetBoolAssertionFailureMessage( GTEST_API_ std::string GetBoolAssertionFailureMessage(
const AssertionResult& assertion_result, const AssertionResult& assertion_result, const char* expression_text,
const char* expression_text, const char* actual_predicate_value, const char* expected_predicate_value);
const char* actual_predicate_value,
const char* expected_predicate_value);
// This template class represents an IEEE floating-point number // This template class represents an IEEE floating-point number
// (either single-precision or double-precision, depending on the // (either single-precision or double-precision, depending on the
...@@ -258,11 +258,11 @@ class FloatingPoint { ...@@ -258,11 +258,11 @@ class FloatingPoint {
// Constants. // Constants.
// # of bits in a number. // # of bits in a number.
static const size_t kBitCount = 8*sizeof(RawType); static const size_t kBitCount = 8 * sizeof(RawType);
// # of fraction bits in a number. // # of fraction bits in a number.
static const size_t kFractionBitCount = static const size_t kFractionBitCount =
std::numeric_limits<RawType>::digits - 1; std::numeric_limits<RawType>::digits - 1;
// # of exponent bits in a number. // # of exponent bits in a number.
static const size_t kExponentBitCount = kBitCount - 1 - kFractionBitCount; static const size_t kExponentBitCount = kBitCount - 1 - kFractionBitCount;
...@@ -271,8 +271,8 @@ class FloatingPoint { ...@@ -271,8 +271,8 @@ class FloatingPoint {
static const Bits kSignBitMask = static_cast<Bits>(1) << (kBitCount - 1); static const Bits kSignBitMask = static_cast<Bits>(1) << (kBitCount - 1);
// The mask for the fraction bits. // The mask for the fraction bits.
static const Bits kFractionBitMask = static const Bits kFractionBitMask = ~static_cast<Bits>(0) >>
~static_cast<Bits>(0) >> (kExponentBitCount + 1); (kExponentBitCount + 1);
// The mask for the exponent bits. // The mask for the exponent bits.
static const Bits kExponentBitMask = ~(kSignBitMask | kFractionBitMask); static const Bits kExponentBitMask = ~(kSignBitMask | kFractionBitMask);
...@@ -311,9 +311,7 @@ class FloatingPoint { ...@@ -311,9 +311,7 @@ class FloatingPoint {
} }
// Returns the floating-point number that represent positive infinity. // Returns the floating-point number that represent positive infinity.
static RawType Infinity() { static RawType Infinity() { return ReinterpretBits(kExponentBitMask); }
return ReinterpretBits(kExponentBitMask);
}
// Returns the maximum representable finite floating-point number. // Returns the maximum representable finite floating-point number.
static RawType Max(); static RawType Max();
...@@ -321,7 +319,7 @@ class FloatingPoint { ...@@ -321,7 +319,7 @@ class FloatingPoint {
// Non-static methods // Non-static methods
// Returns the bits that represents this number. // Returns the bits that represents this number.
const Bits &bits() const { return u_.bits_; } const Bits& bits() const { return u_.bits_; }
// Returns the exponent bits of this number. // Returns the exponent bits of this number.
Bits exponent_bits() const { return kExponentBitMask & u_.bits_; } Bits exponent_bits() const { return kExponentBitMask & u_.bits_; }
...@@ -350,8 +348,8 @@ class FloatingPoint { ...@@ -350,8 +348,8 @@ class FloatingPoint {
// a NAN must return false. // a NAN must return false.
if (is_nan() || rhs.is_nan()) return false; if (is_nan() || rhs.is_nan()) return false;
return DistanceBetweenSignAndMagnitudeNumbers(u_.bits_, rhs.u_.bits_) return DistanceBetweenSignAndMagnitudeNumbers(u_.bits_, rhs.u_.bits_) <=
<= kMaxUlps; kMaxUlps;
} }
private: private:
...@@ -376,7 +374,7 @@ class FloatingPoint { ...@@ -376,7 +374,7 @@ class FloatingPoint {
// //
// Read http://en.wikipedia.org/wiki/Signed_number_representations // Read http://en.wikipedia.org/wiki/Signed_number_representations
// for more details on signed number representations. // for more details on signed number representations.
static Bits SignAndMagnitudeToBiased(const Bits &sam) { static Bits SignAndMagnitudeToBiased(const Bits& sam) {
if (kSignBitMask & sam) { if (kSignBitMask & sam) {
// sam represents a negative number. // sam represents a negative number.
return ~sam + 1; return ~sam + 1;
...@@ -388,8 +386,8 @@ class FloatingPoint { ...@@ -388,8 +386,8 @@ class FloatingPoint {
// Given two numbers in the sign-and-magnitude representation, // Given two numbers in the sign-and-magnitude representation,
// returns the distance between them as an unsigned number. // returns the distance between them as an unsigned number.
static Bits DistanceBetweenSignAndMagnitudeNumbers(const Bits &sam1, static Bits DistanceBetweenSignAndMagnitudeNumbers(const Bits& sam1,
const Bits &sam2) { const Bits& sam2) {
const Bits biased1 = SignAndMagnitudeToBiased(sam1); const Bits biased1 = SignAndMagnitudeToBiased(sam1);
const Bits biased2 = SignAndMagnitudeToBiased(sam2); const Bits biased2 = SignAndMagnitudeToBiased(sam2);
return (biased1 >= biased2) ? (biased1 - biased2) : (biased2 - biased1); return (biased1 >= biased2) ? (biased1 - biased2) : (biased2 - biased1);
...@@ -401,9 +399,13 @@ class FloatingPoint { ...@@ -401,9 +399,13 @@ class FloatingPoint {
// We cannot use std::numeric_limits<T>::max() as it clashes with the max() // We cannot use std::numeric_limits<T>::max() as it clashes with the max()
// macro defined by <windows.h>. // macro defined by <windows.h>.
template <> template <>
inline float FloatingPoint<float>::Max() { return FLT_MAX; } inline float FloatingPoint<float>::Max() {
return FLT_MAX;
}
template <> template <>
inline double FloatingPoint<double>::Max() { return DBL_MAX; } inline double FloatingPoint<double>::Max() {
return DBL_MAX;
}
// Typedefs the instances of the FloatingPoint template class that we // Typedefs the instances of the FloatingPoint template class that we
// care to use. // care to use.
...@@ -656,7 +658,8 @@ inline const char* SkipComma(const char* str) { ...@@ -656,7 +658,8 @@ inline const char* SkipComma(const char* str) {
if (comma == nullptr) { if (comma == nullptr) {
return nullptr; return nullptr;
} }
while (IsSpace(*(++comma))) {} while (IsSpace(*(++comma))) {
}
return comma; return comma;
} }
...@@ -670,7 +673,7 @@ inline std::string GetPrefixUntilComma(const char* str) { ...@@ -670,7 +673,7 @@ inline std::string GetPrefixUntilComma(const char* str) {
// Splits a given string on a given delimiter, populating a given // Splits a given string on a given delimiter, populating a given
// vector with the fields. // vector with the fields.
void SplitString(const ::std::string& str, char delimiter, void SplitString(const ::std::string& str, char delimiter,
::std::vector< ::std::string>* dest); ::std::vector<::std::string>* dest);
// The default argument to the template below for the case when the user does // The default argument to the template below for the case when the user does
// not provide a name generator. // not provide a name generator.
...@@ -783,13 +786,13 @@ class TypeParameterizedTestSuite { ...@@ -783,13 +786,13 @@ class TypeParameterizedTestSuite {
const std::vector<std::string>& type_names = const std::vector<std::string>& type_names =
GenerateNames<DefaultNameGenerator, Types>()) { GenerateNames<DefaultNameGenerator, Types>()) {
RegisterTypeParameterizedTestSuiteInstantiation(case_name); RegisterTypeParameterizedTestSuiteInstantiation(case_name);
std::string test_name = StripTrailingSpaces( std::string test_name =
GetPrefixUntilComma(test_names)); StripTrailingSpaces(GetPrefixUntilComma(test_names));
if (!state->TestExists(test_name)) { if (!state->TestExists(test_name)) {
fprintf(stderr, "Failed to get code location for test %s.%s at %s.", fprintf(stderr, "Failed to get code location for test %s.%s at %s.",
case_name, test_name.c_str(), case_name, test_name.c_str(),
FormatFileLocation(code_location.file.c_str(), FormatFileLocation(code_location.file.c_str(), code_location.line)
code_location.line).c_str()); .c_str());
fflush(stderr); fflush(stderr);
posix::Abort(); posix::Abort();
} }
...@@ -833,8 +836,8 @@ class TypeParameterizedTestSuite<Fixture, internal::None, Types> { ...@@ -833,8 +836,8 @@ class TypeParameterizedTestSuite<Fixture, internal::None, Types> {
// For example, if Foo() calls Bar(), which in turn calls // For example, if Foo() calls Bar(), which in turn calls
// GetCurrentOsStackTraceExceptTop(..., 1), Foo() will be included in // GetCurrentOsStackTraceExceptTop(..., 1), Foo() will be included in
// the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't. // the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't.
GTEST_API_ std::string GetCurrentOsStackTraceExceptTop( GTEST_API_ std::string GetCurrentOsStackTraceExceptTop(UnitTest* unit_test,
UnitTest* unit_test, int skip_count); int skip_count);
// Helpers for suppressing warnings on unreachable code or constant // Helpers for suppressing warnings on unreachable code or constant
// condition. // condition.
...@@ -956,7 +959,9 @@ IsContainer IsContainerTest(int /* dummy */) { ...@@ -956,7 +959,9 @@ IsContainer IsContainerTest(int /* dummy */) {
typedef char IsNotContainer; typedef char IsNotContainer;
template <class C> template <class C>
IsNotContainer IsContainerTest(long /* dummy */) { return '\0'; } IsNotContainer IsContainerTest(long /* dummy */) {
return '\0';
}
// Trait to detect whether a type T is a hash table. // Trait to detect whether a type T is a hash table.
// The heuristic used is that the type contains an inner type `hasher` and does // The heuristic used is that the type contains an inner type `hasher` and does
...@@ -1019,11 +1024,13 @@ bool ArrayEq(const T* lhs, size_t size, const U* rhs); ...@@ -1019,11 +1024,13 @@ bool ArrayEq(const T* lhs, size_t size, const U* rhs);
// This generic version is used when k is 0. // This generic version is used when k is 0.
template <typename T, typename U> template <typename T, typename U>
inline bool ArrayEq(const T& lhs, const U& rhs) { return lhs == rhs; } inline bool ArrayEq(const T& lhs, const U& rhs) {
return lhs == rhs;
}
// This overload is used when k >= 1. // This overload is used when k >= 1.
template <typename T, typename U, size_t N> template <typename T, typename U, size_t N>
inline bool ArrayEq(const T(&lhs)[N], const U(&rhs)[N]) { inline bool ArrayEq(const T (&lhs)[N], const U (&rhs)[N]) {
return internal::ArrayEq(lhs, N, rhs); return internal::ArrayEq(lhs, N, rhs);
} }
...@@ -1033,8 +1040,7 @@ inline bool ArrayEq(const T(&lhs)[N], const U(&rhs)[N]) { ...@@ -1033,8 +1040,7 @@ inline bool ArrayEq(const T(&lhs)[N], const U(&rhs)[N]) {
template <typename T, typename U> template <typename T, typename U>
bool ArrayEq(const T* lhs, size_t size, const U* rhs) { bool ArrayEq(const T* lhs, size_t size, const U* rhs) {
for (size_t i = 0; i != size; i++) { for (size_t i = 0; i != size; i++) {
if (!internal::ArrayEq(lhs[i], rhs[i])) if (!internal::ArrayEq(lhs[i], rhs[i])) return false;
return false;
} }
return true; return true;
} }
...@@ -1044,8 +1050,7 @@ bool ArrayEq(const T* lhs, size_t size, const U* rhs) { ...@@ -1044,8 +1050,7 @@ bool ArrayEq(const T* lhs, size_t size, const U* rhs) {
template <typename Iter, typename Element> template <typename Iter, typename Element>
Iter ArrayAwareFind(Iter begin, Iter end, const Element& elem) { Iter ArrayAwareFind(Iter begin, Iter end, const Element& elem) {
for (Iter it = begin; it != end; ++it) { for (Iter it = begin; it != end; ++it) {
if (internal::ArrayEq(*it, elem)) if (internal::ArrayEq(*it, elem)) return it;
return it;
} }
return end; return end;
} }
...@@ -1059,11 +1064,13 @@ void CopyArray(const T* from, size_t size, U* to); ...@@ -1059,11 +1064,13 @@ void CopyArray(const T* from, size_t size, U* to);
// This generic version is used when k is 0. // This generic version is used when k is 0.
template <typename T, typename U> template <typename T, typename U>
inline void CopyArray(const T& from, U* to) { *to = from; } inline void CopyArray(const T& from, U* to) {
*to = from;
}
// This overload is used when k >= 1. // This overload is used when k >= 1.
template <typename T, typename U, size_t N> template <typename T, typename U, size_t N>
inline void CopyArray(const T(&from)[N], U(*to)[N]) { inline void CopyArray(const T (&from)[N], U (*to)[N]) {
internal::CopyArray(from, N, *to); internal::CopyArray(from, N, *to);
} }
...@@ -1116,8 +1123,7 @@ class NativeArray { ...@@ -1116,8 +1123,7 @@ class NativeArray {
} }
~NativeArray() { ~NativeArray() {
if (clone_ != &NativeArray::InitRef) if (clone_ != &NativeArray::InitRef) delete[] array_;
delete[] array_;
} }
// STL-style container methods. // STL-style container methods.
...@@ -1125,8 +1131,7 @@ class NativeArray { ...@@ -1125,8 +1131,7 @@ class NativeArray {
const_iterator begin() const { return array_; } const_iterator begin() const { return array_; }
const_iterator end() const { return array_ + size_; } const_iterator end() const { return array_ + size_; }
bool operator==(const NativeArray& rhs) const { bool operator==(const NativeArray& rhs) const {
return size() == rhs.size() && return size() == rhs.size() && ArrayEq(begin(), size(), rhs.begin());
ArrayEq(begin(), size(), rhs.begin());
} }
private: private:
...@@ -1337,9 +1342,9 @@ struct tuple_size<testing::internal::FlatTuple<Ts...>> ...@@ -1337,9 +1342,9 @@ struct tuple_size<testing::internal::FlatTuple<Ts...>>
#endif #endif
} // namespace std } // namespace std
#define GTEST_MESSAGE_AT_(file, line, message, result_type) \ #define GTEST_MESSAGE_AT_(file, line, message, result_type) \
::testing::internal::AssertHelper(result_type, file, line, message) \ ::testing::internal::AssertHelper(result_type, file, line, message) = \
= ::testing::Message() ::testing::Message()
#define GTEST_MESSAGE_(message, result_type) \ #define GTEST_MESSAGE_(message, result_type) \
GTEST_MESSAGE_AT_(__FILE__, __LINE__, message, result_type) GTEST_MESSAGE_AT_(__FILE__, __LINE__, message, result_type)
...@@ -1460,66 +1465,69 @@ class NeverThrown { ...@@ -1460,66 +1465,69 @@ class NeverThrown {
#endif // GTEST_HAS_EXCEPTIONS #endif // GTEST_HAS_EXCEPTIONS
#define GTEST_TEST_NO_THROW_(statement, fail) \ #define GTEST_TEST_NO_THROW_(statement, fail) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if (::testing::internal::TrueWithString gtest_msg{}) { \ if (::testing::internal::TrueWithString gtest_msg{}) { \
try { \ try { \
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
} \ } \
GTEST_TEST_NO_THROW_CATCH_STD_EXCEPTION_() \ GTEST_TEST_NO_THROW_CATCH_STD_EXCEPTION_() \
catch (...) { \ catch (...) { \
gtest_msg.value = "it throws."; \ gtest_msg.value = "it throws."; \
goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \ goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \
} \ } \
} else \ } else \
GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__): \ GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__) \
fail(("Expected: " #statement " doesn't throw an exception.\n" \ : fail(("Expected: " #statement " doesn't throw an exception.\n" \
" Actual: " + gtest_msg.value).c_str()) " Actual: " + \
gtest_msg.value) \
#define GTEST_TEST_ANY_THROW_(statement, fail) \ .c_str())
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if (::testing::internal::AlwaysTrue()) { \ #define GTEST_TEST_ANY_THROW_(statement, fail) \
bool gtest_caught_any = false; \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
try { \ if (::testing::internal::AlwaysTrue()) { \
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ bool gtest_caught_any = false; \
} \ try { \
catch (...) { \ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
gtest_caught_any = true; \ } catch (...) { \
} \ gtest_caught_any = true; \
if (!gtest_caught_any) { \ } \
if (!gtest_caught_any) { \
goto GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__); \ goto GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__); \
} \ } \
} else \ } else \
GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__): \ GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__) \
fail("Expected: " #statement " throws an exception.\n" \ : fail("Expected: " #statement \
" Actual: it doesn't.") " throws an exception.\n" \
" Actual: it doesn't.")
// Implements Boolean test assertions such as EXPECT_TRUE. expression can be // Implements Boolean test assertions such as EXPECT_TRUE. expression can be
// either a boolean expression or an AssertionResult. text is a textual // either a boolean expression or an AssertionResult. text is a textual
// representation of expression as it was passed into the EXPECT_TRUE. // representation of expression as it was passed into the EXPECT_TRUE.
#define GTEST_TEST_BOOLEAN_(expression, text, actual, expected, fail) \ #define GTEST_TEST_BOOLEAN_(expression, text, actual, expected, fail) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if (const ::testing::AssertionResult gtest_ar_ = \ if (const ::testing::AssertionResult gtest_ar_ = \
::testing::AssertionResult(expression)) \ ::testing::AssertionResult(expression)) \
; \ ; \
else \ else \
fail(::testing::internal::GetBoolAssertionFailureMessage(\ fail(::testing::internal::GetBoolAssertionFailureMessage( \
gtest_ar_, text, #actual, #expected).c_str()) gtest_ar_, text, #actual, #expected) \
.c_str())
#define GTEST_TEST_NO_FATAL_FAILURE_(statement, fail) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ #define GTEST_TEST_NO_FATAL_FAILURE_(statement, fail) \
if (::testing::internal::AlwaysTrue()) { \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if (::testing::internal::AlwaysTrue()) { \
::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_checker; \ ::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_checker; \
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
if (gtest_fatal_failure_checker.has_new_fatal_failure()) { \ if (gtest_fatal_failure_checker.has_new_fatal_failure()) { \
goto GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__); \ goto GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__); \
} \ } \
} else \ } else \
GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__): \ GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__) \
fail("Expected: " #statement " doesn't generate new fatal " \ : fail("Expected: " #statement \
"failures in the current thread.\n" \ " doesn't generate new fatal " \
" Actual: it does.") "failures in the current thread.\n" \
" Actual: it does.")
// Expands to the name of the class that implements the given test. // Expands to the name of the class that implements the given test.
#define GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \ #define GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \
......
...@@ -47,19 +47,18 @@ ...@@ -47,19 +47,18 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "gtest/internal/gtest-internal.h"
#include "gtest/internal/gtest-port.h"
#include "gtest/gtest-printers.h" #include "gtest/gtest-printers.h"
#include "gtest/gtest-test-part.h" #include "gtest/gtest-test-part.h"
#include "gtest/internal/gtest-internal.h"
#include "gtest/internal/gtest-port.h"
namespace testing { namespace testing {
// Input to a parameterized test name generator, describing a test parameter. // Input to a parameterized test name generator, describing a test parameter.
// Consists of the parameter value and the integer parameter index. // Consists of the parameter value and the integer parameter index.
template <class ParamType> template <class ParamType>
struct TestParamInfo { struct TestParamInfo {
TestParamInfo(const ParamType& a_param, size_t an_index) : TestParamInfo(const ParamType& a_param, size_t an_index)
param(a_param), : param(a_param), index(an_index) {}
index(an_index) {}
ParamType param; ParamType param;
size_t index; size_t index;
}; };
...@@ -85,8 +84,10 @@ namespace internal { ...@@ -85,8 +84,10 @@ namespace internal {
GTEST_API_ void ReportInvalidTestSuiteType(const char* test_suite_name, GTEST_API_ void ReportInvalidTestSuiteType(const char* test_suite_name,
CodeLocation code_location); CodeLocation code_location);
template <typename> class ParamGeneratorInterface; template <typename>
template <typename> class ParamGenerator; class ParamGeneratorInterface;
template <typename>
class ParamGenerator;
// Interface for iterating over elements provided by an implementation // Interface for iterating over elements provided by an implementation
// of ParamGeneratorInterface<T>. // of ParamGeneratorInterface<T>.
...@@ -130,8 +131,7 @@ class ParamIterator { ...@@ -130,8 +131,7 @@ class ParamIterator {
// ParamIterator assumes ownership of the impl_ pointer. // ParamIterator assumes ownership of the impl_ pointer.
ParamIterator(const ParamIterator& other) : impl_(other.impl_->Clone()) {} ParamIterator(const ParamIterator& other) : impl_(other.impl_->Clone()) {}
ParamIterator& operator=(const ParamIterator& other) { ParamIterator& operator=(const ParamIterator& other) {
if (this != &other) if (this != &other) impl_.reset(other.impl_->Clone());
impl_.reset(other.impl_->Clone());
return *this; return *this;
} }
...@@ -158,7 +158,7 @@ class ParamIterator { ...@@ -158,7 +158,7 @@ class ParamIterator {
private: private:
friend class ParamGenerator<T>; friend class ParamGenerator<T>;
explicit ParamIterator(ParamIteratorInterface<T>* impl) : impl_(impl) {} explicit ParamIterator(ParamIteratorInterface<T>* impl) : impl_(impl) {}
std::unique_ptr<ParamIteratorInterface<T> > impl_; std::unique_ptr<ParamIteratorInterface<T>> impl_;
}; };
// ParamGeneratorInterface<T> is the binary interface to access generators // ParamGeneratorInterface<T> is the binary interface to access generators
...@@ -180,7 +180,7 @@ class ParamGeneratorInterface { ...@@ -180,7 +180,7 @@ class ParamGeneratorInterface {
// This class implements copy initialization semantics and the contained // This class implements copy initialization semantics and the contained
// ParamGeneratorInterface<T> instance is shared among all copies // ParamGeneratorInterface<T> instance is shared among all copies
// of the original object. This is possible because that instance is immutable. // of the original object. This is possible because that instance is immutable.
template<typename T> template <typename T>
class ParamGenerator { class ParamGenerator {
public: public:
typedef ParamIterator<T> iterator; typedef ParamIterator<T> iterator;
...@@ -197,7 +197,7 @@ class ParamGenerator { ...@@ -197,7 +197,7 @@ class ParamGenerator {
iterator end() const { return iterator(impl_->End()); } iterator end() const { return iterator(impl_->End()); }
private: private:
std::shared_ptr<const ParamGeneratorInterface<T> > impl_; std::shared_ptr<const ParamGeneratorInterface<T>> impl_;
}; };
// Generates values from a range of two comparable values. Can be used to // Generates values from a range of two comparable values. Can be used to
...@@ -208,8 +208,10 @@ template <typename T, typename IncrementT> ...@@ -208,8 +208,10 @@ template <typename T, typename IncrementT>
class RangeGenerator : public ParamGeneratorInterface<T> { class RangeGenerator : public ParamGeneratorInterface<T> {
public: public:
RangeGenerator(T begin, T end, IncrementT step) RangeGenerator(T begin, T end, IncrementT step)
: begin_(begin), end_(end), : begin_(begin),
step_(step), end_index_(CalculateEndIndex(begin, end, step)) {} end_(end),
step_(step),
end_index_(CalculateEndIndex(begin, end, step)) {}
~RangeGenerator() override {} ~RangeGenerator() override {}
ParamIteratorInterface<T>* Begin() const override { ParamIteratorInterface<T>* Begin() const override {
...@@ -252,7 +254,9 @@ class RangeGenerator : public ParamGeneratorInterface<T> { ...@@ -252,7 +254,9 @@ class RangeGenerator : public ParamGeneratorInterface<T> {
private: private:
Iterator(const Iterator& other) Iterator(const Iterator& other)
: ParamIteratorInterface<T>(), : ParamIteratorInterface<T>(),
base_(other.base_), value_(other.value_), index_(other.index_), base_(other.base_),
value_(other.value_),
index_(other.index_),
step_(other.step_) {} step_(other.step_) {}
// No implementation - assignment is unsupported. // No implementation - assignment is unsupported.
...@@ -264,12 +268,10 @@ class RangeGenerator : public ParamGeneratorInterface<T> { ...@@ -264,12 +268,10 @@ class RangeGenerator : public ParamGeneratorInterface<T> {
const IncrementT step_; const IncrementT step_;
}; // class RangeGenerator::Iterator }; // class RangeGenerator::Iterator
static int CalculateEndIndex(const T& begin, static int CalculateEndIndex(const T& begin, const T& end,
const T& end,
const IncrementT& step) { const IncrementT& step) {
int end_index = 0; int end_index = 0;
for (T i = begin; i < end; i = static_cast<T>(i + step)) for (T i = begin; i < end; i = static_cast<T>(i + step)) end_index++;
end_index++;
return end_index; return end_index;
} }
...@@ -284,7 +286,6 @@ class RangeGenerator : public ParamGeneratorInterface<T> { ...@@ -284,7 +286,6 @@ class RangeGenerator : public ParamGeneratorInterface<T> {
const int end_index_; const int end_index_;
}; // class RangeGenerator }; // class RangeGenerator
// Generates values from a pair of STL-style iterators. Used in the // Generates values from a pair of STL-style iterators. Used in the
// ValuesIn() function. The elements are copied from the source range // ValuesIn() function. The elements are copied from the source range
// since the source can be located on the stack, and the generator // since the source can be located on the stack, and the generator
...@@ -342,13 +343,13 @@ class ValuesInIteratorRangeGenerator : public ParamGeneratorInterface<T> { ...@@ -342,13 +343,13 @@ class ValuesInIteratorRangeGenerator : public ParamGeneratorInterface<T> {
<< "The program attempted to compare iterators " << "The program attempted to compare iterators "
<< "from different generators." << std::endl; << "from different generators." << std::endl;
return iterator_ == return iterator_ ==
CheckedDowncastToActualType<const Iterator>(&other)->iterator_; CheckedDowncastToActualType<const Iterator>(&other)->iterator_;
} }
private: private:
Iterator(const Iterator& other) Iterator(const Iterator& other)
// The explicit constructor call suppresses a false warning // The explicit constructor call suppresses a false warning
// emitted by gcc when supplied with the -Wextra option. // emitted by gcc when supplied with the -Wextra option.
: ParamIteratorInterface<T>(), : ParamIteratorInterface<T>(),
base_(other.base_), base_(other.base_),
iterator_(other.iterator_) {} iterator_(other.iterator_) {}
...@@ -395,8 +396,8 @@ template <class TestClass> ...@@ -395,8 +396,8 @@ template <class TestClass>
class ParameterizedTestFactory : public TestFactoryBase { class ParameterizedTestFactory : public TestFactoryBase {
public: public:
typedef typename TestClass::ParamType ParamType; typedef typename TestClass::ParamType ParamType;
explicit ParameterizedTestFactory(ParamType parameter) : explicit ParameterizedTestFactory(ParamType parameter)
parameter_(parameter) {} : parameter_(parameter) {}
Test* CreateTest() override { Test* CreateTest() override {
TestClass::SetParam(&parameter_); TestClass::SetParam(&parameter_);
return new TestClass(); return new TestClass();
...@@ -548,8 +549,8 @@ class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase { ...@@ -548,8 +549,8 @@ class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase {
test_it != tests_.end(); ++test_it) { test_it != tests_.end(); ++test_it) {
std::shared_ptr<TestInfo> test_info = *test_it; std::shared_ptr<TestInfo> test_info = *test_it;
for (typename InstantiationContainer::iterator gen_it = for (typename InstantiationContainer::iterator gen_it =
instantiations_.begin(); gen_it != instantiations_.end(); instantiations_.begin();
++gen_it) { gen_it != instantiations_.end(); ++gen_it) {
const std::string& instantiation_name = gen_it->name; const std::string& instantiation_name = gen_it->name;
ParamGenerator<ParamType> generator((*gen_it->generator)()); ParamGenerator<ParamType> generator((*gen_it->generator)());
ParamNameGeneratorFunc* name_func = gen_it->name_func; ParamNameGeneratorFunc* name_func = gen_it->name_func;
...@@ -557,7 +558,7 @@ class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase { ...@@ -557,7 +558,7 @@ class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase {
int line = gen_it->line; int line = gen_it->line;
std::string test_suite_name; std::string test_suite_name;
if ( !instantiation_name.empty() ) if (!instantiation_name.empty())
test_suite_name = instantiation_name + "/"; test_suite_name = instantiation_name + "/";
test_suite_name += test_info->test_suite_base_name; test_suite_name += test_info->test_suite_base_name;
...@@ -570,17 +571,16 @@ class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase { ...@@ -570,17 +571,16 @@ class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase {
Message test_name_stream; Message test_name_stream;
std::string param_name = name_func( std::string param_name =
TestParamInfo<ParamType>(*param_it, i)); name_func(TestParamInfo<ParamType>(*param_it, i));
GTEST_CHECK_(IsValidParamName(param_name)) GTEST_CHECK_(IsValidParamName(param_name))
<< "Parameterized test name '" << param_name << "Parameterized test name '" << param_name
<< "' is invalid, in " << file << "' is invalid, in " << file << " line " << line << std::endl;
<< " line " << line << std::endl;
GTEST_CHECK_(test_param_names.count(param_name) == 0) GTEST_CHECK_(test_param_names.count(param_name) == 0)
<< "Duplicate parameterized test name '" << param_name << "Duplicate parameterized test name '" << param_name << "', in "
<< "', in " << file << " line " << line << std::endl; << file << " line " << line << std::endl;
test_param_names.insert(param_name); test_param_names.insert(param_name);
...@@ -597,15 +597,15 @@ class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase { ...@@ -597,15 +597,15 @@ class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase {
SuiteApiResolver<TestSuite>::GetTearDownCaseOrSuite(file, line), SuiteApiResolver<TestSuite>::GetTearDownCaseOrSuite(file, line),
test_info->test_meta_factory->CreateTestFactory(*param_it)); test_info->test_meta_factory->CreateTestFactory(*param_it));
} // for param_it } // for param_it
} // for gen_it } // for gen_it
} // for test_it } // for test_it
if (!generated_instantiations) { if (!generated_instantiations) {
// There are no generaotrs, or they all generate nothing ... // There are no generaotrs, or they all generate nothing ...
InsertSyntheticTestCase(GetTestSuiteName(), code_location_, InsertSyntheticTestCase(GetTestSuiteName(), code_location_,
!tests_.empty()); !tests_.empty());
} }
} // RegisterTests } // RegisterTests
private: private:
// LocalTestInfo structure keeps information about a single test registered // LocalTestInfo structure keeps information about a single test registered
...@@ -621,42 +621,39 @@ class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase { ...@@ -621,42 +621,39 @@ class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase {
const std::string test_suite_base_name; const std::string test_suite_base_name;
const std::string test_base_name; const std::string test_base_name;
const std::unique_ptr<TestMetaFactoryBase<ParamType> > test_meta_factory; const std::unique_ptr<TestMetaFactoryBase<ParamType>> test_meta_factory;
const CodeLocation code_location; const CodeLocation code_location;
}; };
using TestInfoContainer = ::std::vector<std::shared_ptr<TestInfo> >; using TestInfoContainer = ::std::vector<std::shared_ptr<TestInfo>>;
// Records data received from INSTANTIATE_TEST_SUITE_P macros: // Records data received from INSTANTIATE_TEST_SUITE_P macros:
// <Instantiation name, Sequence generator creation function, // <Instantiation name, Sequence generator creation function,
// Name generator function, Source file, Source line> // Name generator function, Source file, Source line>
struct InstantiationInfo { struct InstantiationInfo {
InstantiationInfo(const std::string &name_in, InstantiationInfo(const std::string& name_in,
GeneratorCreationFunc* generator_in, GeneratorCreationFunc* generator_in,
ParamNameGeneratorFunc* name_func_in, ParamNameGeneratorFunc* name_func_in, const char* file_in,
const char* file_in, int line_in)
int line_in) : name(name_in),
: name(name_in), generator(generator_in),
generator(generator_in), name_func(name_func_in),
name_func(name_func_in), file(file_in),
file(file_in), line(line_in) {}
line(line_in) {}
std::string name;
std::string name; GeneratorCreationFunc* generator;
GeneratorCreationFunc* generator; ParamNameGeneratorFunc* name_func;
ParamNameGeneratorFunc* name_func; const char* file;
const char* file; int line;
int line;
}; };
typedef ::std::vector<InstantiationInfo> InstantiationContainer; typedef ::std::vector<InstantiationInfo> InstantiationContainer;
static bool IsValidParamName(const std::string& name) { static bool IsValidParamName(const std::string& name) {
// Check for empty string // Check for empty string
if (name.empty()) if (name.empty()) return false;
return false;
// Check for invalid characters // Check for invalid characters
for (std::string::size_type index = 0; index < name.size(); ++index) { for (std::string::size_type index = 0; index < name.size(); ++index) {
if (!IsAlNum(name[index]) && name[index] != '_') if (!IsAlNum(name[index]) && name[index] != '_') return false;
return false;
} }
return true; return true;
...@@ -710,7 +707,7 @@ class ParameterizedTestSuiteRegistry { ...@@ -710,7 +707,7 @@ class ParameterizedTestSuiteRegistry {
// type we are looking for, so we downcast it to that type // type we are looking for, so we downcast it to that type
// without further checks. // without further checks.
typed_test_info = CheckedDowncastToActualType< typed_test_info = CheckedDowncastToActualType<
ParameterizedTestSuiteInfo<TestSuite> >(test_suite_info); ParameterizedTestSuiteInfo<TestSuite>>(test_suite_info);
} }
break; break;
} }
...@@ -837,7 +834,8 @@ class CartesianProductGenerator ...@@ -837,7 +834,8 @@ class CartesianProductGenerator
: public ParamIteratorInterface<ParamType> { : public ParamIteratorInterface<ParamType> {
public: public:
IteratorImpl(const ParamGeneratorInterface<ParamType>* base, IteratorImpl(const ParamGeneratorInterface<ParamType>* base,
const std::tuple<ParamGenerator<T>...>& generators, bool is_end) const std::tuple<ParamGenerator<T>...>& generators,
bool is_end)
: base_(base), : base_(base),
begin_(std::get<I>(generators).begin()...), begin_(std::get<I>(generators).begin()...),
end_(std::get<I>(generators).end()...), end_(std::get<I>(generators).end()...),
......
...@@ -37,72 +37,72 @@ ...@@ -37,72 +37,72 @@
// Determines the platform on which Google Test is compiled. // Determines the platform on which Google Test is compiled.
#ifdef __CYGWIN__ #ifdef __CYGWIN__
# define GTEST_OS_CYGWIN 1 #define GTEST_OS_CYGWIN 1
# elif defined(__MINGW__) || defined(__MINGW32__) || defined(__MINGW64__) #elif defined(__MINGW__) || defined(__MINGW32__) || defined(__MINGW64__)
# define GTEST_OS_WINDOWS_MINGW 1 #define GTEST_OS_WINDOWS_MINGW 1
# define GTEST_OS_WINDOWS 1 #define GTEST_OS_WINDOWS 1
#elif defined _WIN32 #elif defined _WIN32
# define GTEST_OS_WINDOWS 1 #define GTEST_OS_WINDOWS 1
# ifdef _WIN32_WCE #ifdef _WIN32_WCE
# define GTEST_OS_WINDOWS_MOBILE 1 #define GTEST_OS_WINDOWS_MOBILE 1
# elif defined(WINAPI_FAMILY) #elif defined(WINAPI_FAMILY)
# include <winapifamily.h> #include <winapifamily.h>
# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
# define GTEST_OS_WINDOWS_DESKTOP 1 #define GTEST_OS_WINDOWS_DESKTOP 1
# elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP) #elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP)
# define GTEST_OS_WINDOWS_PHONE 1 #define GTEST_OS_WINDOWS_PHONE 1
# elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) #elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
# define GTEST_OS_WINDOWS_RT 1 #define GTEST_OS_WINDOWS_RT 1
# elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_TV_TITLE) #elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_TV_TITLE)
# define GTEST_OS_WINDOWS_PHONE 1 #define GTEST_OS_WINDOWS_PHONE 1
# define GTEST_OS_WINDOWS_TV_TITLE 1 #define GTEST_OS_WINDOWS_TV_TITLE 1
# else #else
// WINAPI_FAMILY defined but no known partition matched. // WINAPI_FAMILY defined but no known partition matched.
// Default to desktop. // Default to desktop.
# define GTEST_OS_WINDOWS_DESKTOP 1 #define GTEST_OS_WINDOWS_DESKTOP 1
# endif #endif
# else #else
# define GTEST_OS_WINDOWS_DESKTOP 1 #define GTEST_OS_WINDOWS_DESKTOP 1
# endif // _WIN32_WCE #endif // _WIN32_WCE
#elif defined __OS2__ #elif defined __OS2__
# define GTEST_OS_OS2 1 #define GTEST_OS_OS2 1
#elif defined __APPLE__ #elif defined __APPLE__
# define GTEST_OS_MAC 1 #define GTEST_OS_MAC 1
# include <TargetConditionals.h> #include <TargetConditionals.h>
# if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
# define GTEST_OS_IOS 1 #define GTEST_OS_IOS 1
# endif #endif
#elif defined __DragonFly__ #elif defined __DragonFly__
# define GTEST_OS_DRAGONFLY 1 #define GTEST_OS_DRAGONFLY 1
#elif defined __FreeBSD__ #elif defined __FreeBSD__
# define GTEST_OS_FREEBSD 1 #define GTEST_OS_FREEBSD 1
#elif defined __Fuchsia__ #elif defined __Fuchsia__
# define GTEST_OS_FUCHSIA 1 #define GTEST_OS_FUCHSIA 1
#elif defined(__GNU__) #elif defined(__GNU__)
# define GTEST_OS_GNU_HURD 1 #define GTEST_OS_GNU_HURD 1
#elif defined(__GLIBC__) && defined(__FreeBSD_kernel__) #elif defined(__GLIBC__) && defined(__FreeBSD_kernel__)
# define GTEST_OS_GNU_KFREEBSD 1 #define GTEST_OS_GNU_KFREEBSD 1
#elif defined __linux__ #elif defined __linux__
# define GTEST_OS_LINUX 1 #define GTEST_OS_LINUX 1
# if defined __ANDROID__ #if defined __ANDROID__
# define GTEST_OS_LINUX_ANDROID 1 #define GTEST_OS_LINUX_ANDROID 1
# endif #endif
#elif defined __MVS__ #elif defined __MVS__
# define GTEST_OS_ZOS 1 #define GTEST_OS_ZOS 1
#elif defined(__sun) && defined(__SVR4) #elif defined(__sun) && defined(__SVR4)
# define GTEST_OS_SOLARIS 1 #define GTEST_OS_SOLARIS 1
#elif defined(_AIX) #elif defined(_AIX)
# define GTEST_OS_AIX 1 #define GTEST_OS_AIX 1
#elif defined(__hpux) #elif defined(__hpux)
# define GTEST_OS_HPUX 1 #define GTEST_OS_HPUX 1
#elif defined __native_client__ #elif defined __native_client__
# define GTEST_OS_NACL 1 #define GTEST_OS_NACL 1
#elif defined __NetBSD__ #elif defined __NetBSD__
# define GTEST_OS_NETBSD 1 #define GTEST_OS_NETBSD 1
#elif defined __OpenBSD__ #elif defined __OpenBSD__
# define GTEST_OS_OPENBSD 1 #define GTEST_OS_OPENBSD 1
#elif defined __QNX__ #elif defined __QNX__
# define GTEST_OS_QNX 1 #define GTEST_OS_QNX 1
#elif defined(__HAIKU__) #elif defined(__HAIKU__)
#define GTEST_OS_HAIKU 1 #define GTEST_OS_HAIKU 1
#elif defined ESP8266 #elif defined ESP8266
......
...@@ -275,36 +275,36 @@ ...@@ -275,36 +275,36 @@
#include <vector> #include <vector>
#ifndef _WIN32_WCE #ifndef _WIN32_WCE
# include <sys/types.h> #include <sys/stat.h>
# include <sys/stat.h> #include <sys/types.h>
#endif // !_WIN32_WCE #endif // !_WIN32_WCE
#if defined __APPLE__ #if defined __APPLE__
# include <AvailabilityMacros.h> #include <AvailabilityMacros.h>
# include <TargetConditionals.h> #include <TargetConditionals.h>
#endif #endif
#include "gtest/internal/custom/gtest-port.h" #include "gtest/internal/custom/gtest-port.h"
#include "gtest/internal/gtest-port-arch.h" #include "gtest/internal/gtest-port-arch.h"
#if !defined(GTEST_DEV_EMAIL_) #if !defined(GTEST_DEV_EMAIL_)
# define GTEST_DEV_EMAIL_ "googletestframework@@googlegroups.com" #define GTEST_DEV_EMAIL_ "googletestframework@@googlegroups.com"
# define GTEST_FLAG_PREFIX_ "gtest_" #define GTEST_FLAG_PREFIX_ "gtest_"
# define GTEST_FLAG_PREFIX_DASH_ "gtest-" #define GTEST_FLAG_PREFIX_DASH_ "gtest-"
# define GTEST_FLAG_PREFIX_UPPER_ "GTEST_" #define GTEST_FLAG_PREFIX_UPPER_ "GTEST_"
# define GTEST_NAME_ "Google Test" #define GTEST_NAME_ "Google Test"
# define GTEST_PROJECT_URL_ "https://github.com/google/googletest/" #define GTEST_PROJECT_URL_ "https://github.com/google/googletest/"
#endif // !defined(GTEST_DEV_EMAIL_) #endif // !defined(GTEST_DEV_EMAIL_)
#if !defined(GTEST_INIT_GOOGLE_TEST_NAME_) #if !defined(GTEST_INIT_GOOGLE_TEST_NAME_)
# define GTEST_INIT_GOOGLE_TEST_NAME_ "testing::InitGoogleTest" #define GTEST_INIT_GOOGLE_TEST_NAME_ "testing::InitGoogleTest"
#endif // !defined(GTEST_INIT_GOOGLE_TEST_NAME_) #endif // !defined(GTEST_INIT_GOOGLE_TEST_NAME_)
// Determines the version of gcc that is used to compile this. // Determines the version of gcc that is used to compile this.
#ifdef __GNUC__ #ifdef __GNUC__
// 40302 means version 4.3.2. // 40302 means version 4.3.2.
# define GTEST_GCC_VER_ \ #define GTEST_GCC_VER_ \
(__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__) (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#endif // __GNUC__ #endif // __GNUC__
// Macros for disabling Microsoft Visual C++ warnings. // Macros for disabling Microsoft Visual C++ warnings.
...@@ -313,41 +313,37 @@ ...@@ -313,41 +313,37 @@
// /* code that triggers warnings C4800 and C4385 */ // /* code that triggers warnings C4800 and C4385 */
// GTEST_DISABLE_MSC_WARNINGS_POP_() // GTEST_DISABLE_MSC_WARNINGS_POP_()
#if defined(_MSC_VER) #if defined(_MSC_VER)
# define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings) \ #define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings) \
__pragma(warning(push)) \ __pragma(warning(push)) __pragma(warning(disable : warnings))
__pragma(warning(disable: warnings)) #define GTEST_DISABLE_MSC_WARNINGS_POP_() __pragma(warning(pop))
# define GTEST_DISABLE_MSC_WARNINGS_POP_() \
__pragma(warning(pop))
#else #else
// Not all compilers are MSVC // Not all compilers are MSVC
# define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings) #define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
# define GTEST_DISABLE_MSC_WARNINGS_POP_() #define GTEST_DISABLE_MSC_WARNINGS_POP_()
#endif #endif
// Clang on Windows does not understand MSVC's pragma warning. // Clang on Windows does not understand MSVC's pragma warning.
// We need clang-specific way to disable function deprecation warning. // We need clang-specific way to disable function deprecation warning.
#ifdef __clang__ #ifdef __clang__
# define GTEST_DISABLE_MSC_DEPRECATED_PUSH_() \ #define GTEST_DISABLE_MSC_DEPRECATED_PUSH_() \
_Pragma("clang diagnostic push") \ _Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") \ _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") \
_Pragma("clang diagnostic ignored \"-Wdeprecated-implementations\"") _Pragma("clang diagnostic ignored \"-Wdeprecated-implementations\"")
#define GTEST_DISABLE_MSC_DEPRECATED_POP_() \ #define GTEST_DISABLE_MSC_DEPRECATED_POP_() _Pragma("clang diagnostic pop")
_Pragma("clang diagnostic pop")
#else #else
# define GTEST_DISABLE_MSC_DEPRECATED_PUSH_() \ #define GTEST_DISABLE_MSC_DEPRECATED_PUSH_() \
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996) GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996)
# define GTEST_DISABLE_MSC_DEPRECATED_POP_() \ #define GTEST_DISABLE_MSC_DEPRECATED_POP_() GTEST_DISABLE_MSC_WARNINGS_POP_()
GTEST_DISABLE_MSC_WARNINGS_POP_()
#endif #endif
// Brings in definitions for functions used in the testing::internal::posix // Brings in definitions for functions used in the testing::internal::posix
// namespace (read, write, close, chdir, isatty, stat). We do not currently // namespace (read, write, close, chdir, isatty, stat). We do not currently
// use them on Windows Mobile. // use them on Windows Mobile.
#if GTEST_OS_WINDOWS #if GTEST_OS_WINDOWS
# if !GTEST_OS_WINDOWS_MOBILE #if !GTEST_OS_WINDOWS_MOBILE
# include <direct.h> #include <direct.h>
# include <io.h> #include <io.h>
# endif #endif
// In order to avoid having to include <windows.h>, use forward declaration // In order to avoid having to include <windows.h>, use forward declaration
#if GTEST_OS_WINDOWS_MINGW && !defined(__MINGW64_VERSION_MAJOR) #if GTEST_OS_WINDOWS_MINGW && !defined(__MINGW64_VERSION_MAJOR)
// MinGW defined _CRITICAL_SECTION and _RTL_CRITICAL_SECTION as two // MinGW defined _CRITICAL_SECTION and _RTL_CRITICAL_SECTION as two
...@@ -367,24 +363,24 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -367,24 +363,24 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
// This assumes that non-Windows OSes provide unistd.h. For OSes where this // This assumes that non-Windows OSes provide unistd.h. For OSes where this
// is not the case, we need to include headers that provide the functions // is not the case, we need to include headers that provide the functions
// mentioned above. // mentioned above.
# include <unistd.h> #include <strings.h>
# include <strings.h> #include <unistd.h>
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
#if GTEST_OS_LINUX_ANDROID #if GTEST_OS_LINUX_ANDROID
// Used to define __ANDROID_API__ matching the target NDK API level. // Used to define __ANDROID_API__ matching the target NDK API level.
# include <android/api-level.h> // NOLINT #include <android/api-level.h> // NOLINT
#endif #endif
// Defines this to true if and only if Google Test can use POSIX regular // Defines this to true if and only if Google Test can use POSIX regular
// expressions. // expressions.
#ifndef GTEST_HAS_POSIX_RE #ifndef GTEST_HAS_POSIX_RE
# if GTEST_OS_LINUX_ANDROID #if GTEST_OS_LINUX_ANDROID
// On Android, <regex.h> is only available starting with Gingerbread. // On Android, <regex.h> is only available starting with Gingerbread.
# define GTEST_HAS_POSIX_RE (__ANDROID_API__ >= 9) #define GTEST_HAS_POSIX_RE (__ANDROID_API__ >= 9)
# else #else
#define GTEST_HAS_POSIX_RE (!GTEST_OS_WINDOWS && !GTEST_OS_XTENSA) #define GTEST_HAS_POSIX_RE (!GTEST_OS_WINDOWS && !GTEST_OS_XTENSA)
# endif #endif
#endif #endif
#if GTEST_USES_PCRE #if GTEST_USES_PCRE
...@@ -396,39 +392,39 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -396,39 +392,39 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
// won't compile otherwise. We can #include it here as we already // won't compile otherwise. We can #include it here as we already
// included <stdlib.h>, which is guaranteed to define size_t through // included <stdlib.h>, which is guaranteed to define size_t through
// <stddef.h>. // <stddef.h>.
# include <regex.h> // NOLINT #include <regex.h> // NOLINT
# define GTEST_USES_POSIX_RE 1 #define GTEST_USES_POSIX_RE 1
#elif GTEST_OS_WINDOWS #elif GTEST_OS_WINDOWS
// <regex.h> is not available on Windows. Use our own simple regex // <regex.h> is not available on Windows. Use our own simple regex
// implementation instead. // implementation instead.
# define GTEST_USES_SIMPLE_RE 1 #define GTEST_USES_SIMPLE_RE 1
#else #else
// <regex.h> may not be available on this platform. Use our own // <regex.h> may not be available on this platform. Use our own
// simple regex implementation instead. // simple regex implementation instead.
# define GTEST_USES_SIMPLE_RE 1 #define GTEST_USES_SIMPLE_RE 1
#endif // GTEST_USES_PCRE #endif // GTEST_USES_PCRE
#ifndef GTEST_HAS_EXCEPTIONS #ifndef GTEST_HAS_EXCEPTIONS
// The user didn't tell us whether exceptions are enabled, so we need // The user didn't tell us whether exceptions are enabled, so we need
// to figure it out. // to figure it out.
# if defined(_MSC_VER) && defined(_CPPUNWIND) #if defined(_MSC_VER) && defined(_CPPUNWIND)
// MSVC defines _CPPUNWIND to 1 if and only if exceptions are enabled. // MSVC defines _CPPUNWIND to 1 if and only if exceptions are enabled.
# define GTEST_HAS_EXCEPTIONS 1 #define GTEST_HAS_EXCEPTIONS 1
# elif defined(__BORLANDC__) #elif defined(__BORLANDC__)
// C++Builder's implementation of the STL uses the _HAS_EXCEPTIONS // C++Builder's implementation of the STL uses the _HAS_EXCEPTIONS
// macro to enable exceptions, so we'll do the same. // macro to enable exceptions, so we'll do the same.
// Assumes that exceptions are enabled by default. // Assumes that exceptions are enabled by default.
# ifndef _HAS_EXCEPTIONS #ifndef _HAS_EXCEPTIONS
# define _HAS_EXCEPTIONS 1 #define _HAS_EXCEPTIONS 1
# endif // _HAS_EXCEPTIONS #endif // _HAS_EXCEPTIONS
# define GTEST_HAS_EXCEPTIONS _HAS_EXCEPTIONS #define GTEST_HAS_EXCEPTIONS _HAS_EXCEPTIONS
# elif defined(__clang__) #elif defined(__clang__)
// clang defines __EXCEPTIONS if and only if exceptions are enabled before clang // clang defines __EXCEPTIONS if and only if exceptions are enabled before clang
// 220714, but if and only if cleanups are enabled after that. In Obj-C++ files, // 220714, but if and only if cleanups are enabled after that. In Obj-C++ files,
// there can be cleanups for ObjC exceptions which also need cleanups, even if // there can be cleanups for ObjC exceptions which also need cleanups, even if
...@@ -437,27 +433,27 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -437,27 +433,27 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
// cleanups prior to that. To reliably check for C++ exception availability with // cleanups prior to that. To reliably check for C++ exception availability with
// clang, check for // clang, check for
// __EXCEPTIONS && __has_feature(cxx_exceptions). // __EXCEPTIONS && __has_feature(cxx_exceptions).
# define GTEST_HAS_EXCEPTIONS (__EXCEPTIONS && __has_feature(cxx_exceptions)) #define GTEST_HAS_EXCEPTIONS (__EXCEPTIONS && __has_feature(cxx_exceptions))
# elif defined(__GNUC__) && __EXCEPTIONS #elif defined(__GNUC__) && __EXCEPTIONS
// gcc defines __EXCEPTIONS to 1 if and only if exceptions are enabled. // gcc defines __EXCEPTIONS to 1 if and only if exceptions are enabled.
# define GTEST_HAS_EXCEPTIONS 1 #define GTEST_HAS_EXCEPTIONS 1
# elif defined(__SUNPRO_CC) #elif defined(__SUNPRO_CC)
// Sun Pro CC supports exceptions. However, there is no compile-time way of // Sun Pro CC supports exceptions. However, there is no compile-time way of
// detecting whether they are enabled or not. Therefore, we assume that // detecting whether they are enabled or not. Therefore, we assume that
// they are enabled unless the user tells us otherwise. // they are enabled unless the user tells us otherwise.
# define GTEST_HAS_EXCEPTIONS 1 #define GTEST_HAS_EXCEPTIONS 1
# elif defined(__IBMCPP__) && __EXCEPTIONS #elif defined(__IBMCPP__) && __EXCEPTIONS
// xlC defines __EXCEPTIONS to 1 if and only if exceptions are enabled. // xlC defines __EXCEPTIONS to 1 if and only if exceptions are enabled.
# define GTEST_HAS_EXCEPTIONS 1 #define GTEST_HAS_EXCEPTIONS 1
# elif defined(__HP_aCC) #elif defined(__HP_aCC)
// Exception handling is in effect by default in HP aCC compiler. It has to // Exception handling is in effect by default in HP aCC compiler. It has to
// be turned of by +noeh compiler option if desired. // be turned of by +noeh compiler option if desired.
# define GTEST_HAS_EXCEPTIONS 1 #define GTEST_HAS_EXCEPTIONS 1
# else #else
// For other compilers, we assume exceptions are disabled to be // For other compilers, we assume exceptions are disabled to be
// conservative. // conservative.
# define GTEST_HAS_EXCEPTIONS 0 #define GTEST_HAS_EXCEPTIONS 0
# endif // defined(_MSC_VER) || defined(__BORLANDC__) #endif // defined(_MSC_VER) || defined(__BORLANDC__)
#endif // GTEST_HAS_EXCEPTIONS #endif // GTEST_HAS_EXCEPTIONS
#ifndef GTEST_HAS_STD_WSTRING #ifndef GTEST_HAS_STD_WSTRING
...@@ -477,63 +473,62 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -477,63 +473,62 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
// The user didn't tell us whether RTTI is enabled, so we need to // The user didn't tell us whether RTTI is enabled, so we need to
// figure it out. // figure it out.
# ifdef _MSC_VER #ifdef _MSC_VER
#ifdef _CPPRTTI // MSVC defines this macro if and only if RTTI is enabled. #ifdef _CPPRTTI // MSVC defines this macro if and only if RTTI is enabled.
# define GTEST_HAS_RTTI 1 #define GTEST_HAS_RTTI 1
# else #else
# define GTEST_HAS_RTTI 0 #define GTEST_HAS_RTTI 0
# endif #endif
// Starting with version 4.3.2, gcc defines __GXX_RTTI if and only if RTTI is // Starting with version 4.3.2, gcc defines __GXX_RTTI if and only if RTTI is
// enabled. // enabled.
# elif defined(__GNUC__) #elif defined(__GNUC__)
# ifdef __GXX_RTTI #ifdef __GXX_RTTI
// When building against STLport with the Android NDK and with // When building against STLport with the Android NDK and with
// -frtti -fno-exceptions, the build fails at link time with undefined // -frtti -fno-exceptions, the build fails at link time with undefined
// references to __cxa_bad_typeid. Note sure if STL or toolchain bug, // references to __cxa_bad_typeid. Note sure if STL or toolchain bug,
// so disable RTTI when detected. // so disable RTTI when detected.
# if GTEST_OS_LINUX_ANDROID && defined(_STLPORT_MAJOR) && \ #if GTEST_OS_LINUX_ANDROID && defined(_STLPORT_MAJOR) && !defined(__EXCEPTIONS)
!defined(__EXCEPTIONS) #define GTEST_HAS_RTTI 0
# define GTEST_HAS_RTTI 0 #else
# else #define GTEST_HAS_RTTI 1
# define GTEST_HAS_RTTI 1 #endif // GTEST_OS_LINUX_ANDROID && __STLPORT_MAJOR && !__EXCEPTIONS
# endif // GTEST_OS_LINUX_ANDROID && __STLPORT_MAJOR && !__EXCEPTIONS #else
# else #define GTEST_HAS_RTTI 0
# define GTEST_HAS_RTTI 0 #endif // __GXX_RTTI
# endif // __GXX_RTTI
// Clang defines __GXX_RTTI starting with version 3.0, but its manual recommends // Clang defines __GXX_RTTI starting with version 3.0, but its manual recommends
// using has_feature instead. has_feature(cxx_rtti) is supported since 2.7, the // using has_feature instead. has_feature(cxx_rtti) is supported since 2.7, the
// first version with C++ support. // first version with C++ support.
# elif defined(__clang__) #elif defined(__clang__)
# define GTEST_HAS_RTTI __has_feature(cxx_rtti) #define GTEST_HAS_RTTI __has_feature(cxx_rtti)
// Starting with version 9.0 IBM Visual Age defines __RTTI_ALL__ to 1 if // Starting with version 9.0 IBM Visual Age defines __RTTI_ALL__ to 1 if
// both the typeid and dynamic_cast features are present. // both the typeid and dynamic_cast features are present.
# elif defined(__IBMCPP__) && (__IBMCPP__ >= 900) #elif defined(__IBMCPP__) && (__IBMCPP__ >= 900)
# ifdef __RTTI_ALL__ #ifdef __RTTI_ALL__
# define GTEST_HAS_RTTI 1 #define GTEST_HAS_RTTI 1
# else #else
# define GTEST_HAS_RTTI 0 #define GTEST_HAS_RTTI 0
# endif #endif
# else #else
// For all other compilers, we assume RTTI is enabled. // For all other compilers, we assume RTTI is enabled.
# define GTEST_HAS_RTTI 1 #define GTEST_HAS_RTTI 1
# endif // _MSC_VER #endif // _MSC_VER
#endif // GTEST_HAS_RTTI #endif // GTEST_HAS_RTTI
// It's this header's responsibility to #include <typeinfo> when RTTI // It's this header's responsibility to #include <typeinfo> when RTTI
// is enabled. // is enabled.
#if GTEST_HAS_RTTI #if GTEST_HAS_RTTI
# include <typeinfo> #include <typeinfo>
#endif #endif
// Determines whether Google Test can use the pthreads library. // Determines whether Google Test can use the pthreads library.
...@@ -553,10 +548,10 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -553,10 +548,10 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
#if GTEST_HAS_PTHREAD #if GTEST_HAS_PTHREAD
// gtest-port.h guarantees to #include <pthread.h> when GTEST_HAS_PTHREAD is // gtest-port.h guarantees to #include <pthread.h> when GTEST_HAS_PTHREAD is
// true. // true.
# include <pthread.h> // NOLINT #include <pthread.h> // NOLINT
// For timespec and nanosleep, used below. // For timespec and nanosleep, used below.
# include <time.h> // NOLINT #include <time.h> // NOLINT
#endif #endif
// Determines whether clone(2) is supported. // Determines whether clone(2) is supported.
...@@ -566,24 +561,23 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -566,24 +561,23 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
#ifndef GTEST_HAS_CLONE #ifndef GTEST_HAS_CLONE
// The user didn't tell us, so we need to figure it out. // The user didn't tell us, so we need to figure it out.
# if GTEST_OS_LINUX && !defined(__ia64__) #if GTEST_OS_LINUX && !defined(__ia64__)
# if GTEST_OS_LINUX_ANDROID #if GTEST_OS_LINUX_ANDROID
// On Android, clone() became available at different API levels for each 32-bit // On Android, clone() became available at different API levels for each 32-bit
// architecture. // architecture.
# if defined(__LP64__) || \ #if defined(__LP64__) || (defined(__arm__) && __ANDROID_API__ >= 9) || \
(defined(__arm__) && __ANDROID_API__ >= 9) || \ (defined(__mips__) && __ANDROID_API__ >= 12) || \
(defined(__mips__) && __ANDROID_API__ >= 12) || \ (defined(__i386__) && __ANDROID_API__ >= 17)
(defined(__i386__) && __ANDROID_API__ >= 17) #define GTEST_HAS_CLONE 1
# define GTEST_HAS_CLONE 1 #else
# else #define GTEST_HAS_CLONE 0
# define GTEST_HAS_CLONE 0 #endif
# endif #else
# else #define GTEST_HAS_CLONE 1
# define GTEST_HAS_CLONE 1 #endif
# endif #else
# else #define GTEST_HAS_CLONE 0
# define GTEST_HAS_CLONE 0 #endif // GTEST_OS_LINUX && !defined(__ia64__)
# endif // GTEST_OS_LINUX && !defined(__ia64__)
#endif // GTEST_HAS_CLONE #endif // GTEST_HAS_CLONE
...@@ -594,10 +588,10 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -594,10 +588,10 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
// platforms except known mobile ones. // platforms except known mobile ones.
#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \ #if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \
GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 || GTEST_OS_XTENSA GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 || GTEST_OS_XTENSA
# define GTEST_HAS_STREAM_REDIRECTION 0 #define GTEST_HAS_STREAM_REDIRECTION 0
# else #else
# define GTEST_HAS_STREAM_REDIRECTION 1 #define GTEST_HAS_STREAM_REDIRECTION 1
# endif // !GTEST_OS_WINDOWS_MOBILE #endif // !GTEST_OS_WINDOWS_MOBILE
#endif // GTEST_HAS_STREAM_REDIRECTION #endif // GTEST_HAS_STREAM_REDIRECTION
// Determines whether to support death tests. // Determines whether to support death tests.
...@@ -609,7 +603,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -609,7 +603,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
GTEST_OS_FREEBSD || GTEST_OS_NETBSD || GTEST_OS_FUCHSIA || \ GTEST_OS_FREEBSD || GTEST_OS_NETBSD || GTEST_OS_FUCHSIA || \
GTEST_OS_DRAGONFLY || GTEST_OS_GNU_KFREEBSD || GTEST_OS_HAIKU || \ GTEST_OS_DRAGONFLY || GTEST_OS_GNU_KFREEBSD || GTEST_OS_HAIKU || \
GTEST_OS_GNU_HURD) GTEST_OS_GNU_HURD)
# define GTEST_HAS_DEATH_TEST 1 #define GTEST_HAS_DEATH_TEST 1
#endif #endif
// Determines whether to support type-driven tests. // Determines whether to support type-driven tests.
...@@ -618,8 +612,8 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -618,8 +612,8 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
// Sun Pro CC, IBM Visual Age, and HP aCC support. // Sun Pro CC, IBM Visual Age, and HP aCC support.
#if defined(__GNUC__) || defined(_MSC_VER) || defined(__SUNPRO_CC) || \ #if defined(__GNUC__) || defined(_MSC_VER) || defined(__SUNPRO_CC) || \
defined(__IBMCPP__) || defined(__HP_aCC) defined(__IBMCPP__) || defined(__HP_aCC)
# define GTEST_HAS_TYPED_TEST 1 #define GTEST_HAS_TYPED_TEST 1
# define GTEST_HAS_TYPED_TEST_P 1 #define GTEST_HAS_TYPED_TEST_P 1
#endif #endif
// Determines whether the system compiler uses UTF-16 for encoding wide strings. // Determines whether the system compiler uses UTF-16 for encoding wide strings.
...@@ -630,7 +624,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -630,7 +624,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
#if GTEST_OS_LINUX || GTEST_OS_GNU_KFREEBSD || GTEST_OS_DRAGONFLY || \ #if GTEST_OS_LINUX || GTEST_OS_GNU_KFREEBSD || GTEST_OS_DRAGONFLY || \
GTEST_OS_FREEBSD || GTEST_OS_NETBSD || GTEST_OS_OPENBSD || \ GTEST_OS_FREEBSD || GTEST_OS_NETBSD || GTEST_OS_OPENBSD || \
GTEST_OS_GNU_HURD GTEST_OS_GNU_HURD
# define GTEST_CAN_STREAM_RESULTS_ 1 #define GTEST_CAN_STREAM_RESULTS_ 1
#endif #endif
// Defines some utility macros. // Defines some utility macros.
...@@ -644,9 +638,12 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -644,9 +638,12 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
// //
// The "switch (0) case 0:" idiom is used to suppress this. // The "switch (0) case 0:" idiom is used to suppress this.
#ifdef __INTEL_COMPILER #ifdef __INTEL_COMPILER
# define GTEST_AMBIGUOUS_ELSE_BLOCKER_ #define GTEST_AMBIGUOUS_ELSE_BLOCKER_
#else #else
# define GTEST_AMBIGUOUS_ELSE_BLOCKER_ switch (0) case 0: default: // NOLINT #define GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
switch (0) \
case 0: \
default: // NOLINT
#endif #endif
// Use this annotation at the end of a struct/class definition to // Use this annotation at the end of a struct/class definition to
...@@ -661,31 +658,31 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -661,31 +658,31 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
// Also use it after a variable or parameter declaration to tell the // Also use it after a variable or parameter declaration to tell the
// compiler the variable/parameter does not have to be used. // compiler the variable/parameter does not have to be used.
#if defined(__GNUC__) && !defined(COMPILER_ICC) #if defined(__GNUC__) && !defined(COMPILER_ICC)
# define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused)) #define GTEST_ATTRIBUTE_UNUSED_ __attribute__((unused))
#elif defined(__clang__) #elif defined(__clang__)
# if __has_attribute(unused) #if __has_attribute(unused)
# define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused)) #define GTEST_ATTRIBUTE_UNUSED_ __attribute__((unused))
# endif #endif
#endif #endif
#ifndef GTEST_ATTRIBUTE_UNUSED_ #ifndef GTEST_ATTRIBUTE_UNUSED_
# define GTEST_ATTRIBUTE_UNUSED_ #define GTEST_ATTRIBUTE_UNUSED_
#endif #endif
// Use this annotation before a function that takes a printf format string. // Use this annotation before a function that takes a printf format string.
#if (defined(__GNUC__) || defined(__clang__)) && !defined(COMPILER_ICC) #if (defined(__GNUC__) || defined(__clang__)) && !defined(COMPILER_ICC)
# if defined(__MINGW_PRINTF_FORMAT) #if defined(__MINGW_PRINTF_FORMAT)
// MinGW has two different printf implementations. Ensure the format macro // MinGW has two different printf implementations. Ensure the format macro
// matches the selected implementation. See // matches the selected implementation. See
// https://sourceforge.net/p/mingw-w64/wiki2/gnu%20printf/. // https://sourceforge.net/p/mingw-w64/wiki2/gnu%20printf/.
# define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) \ #define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) \
__attribute__((__format__(__MINGW_PRINTF_FORMAT, string_index, \ __attribute__(( \
first_to_check))) __format__(__MINGW_PRINTF_FORMAT, string_index, first_to_check)))
# else #else
# define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) \ #define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) \
__attribute__((__format__(__printf__, string_index, first_to_check))) __attribute__((__format__(__printf__, string_index, first_to_check)))
# endif #endif
#else #else
# define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) #define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check)
#endif #endif
// A macro to disallow copy constructor and operator= // A macro to disallow copy constructor and operator=
...@@ -708,9 +705,9 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -708,9 +705,9 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
// //
// Sprocket* AllocateSprocket() GTEST_MUST_USE_RESULT_; // Sprocket* AllocateSprocket() GTEST_MUST_USE_RESULT_;
#if defined(__GNUC__) && !defined(COMPILER_ICC) #if defined(__GNUC__) && !defined(COMPILER_ICC)
# define GTEST_MUST_USE_RESULT_ __attribute__ ((warn_unused_result)) #define GTEST_MUST_USE_RESULT_ __attribute__((warn_unused_result))
#else #else
# define GTEST_MUST_USE_RESULT_ #define GTEST_MUST_USE_RESULT_
#endif // __GNUC__ && !COMPILER_ICC #endif // __GNUC__ && !COMPILER_ICC
// MS C++ compiler emits warning when a conditional expression is compile time // MS C++ compiler emits warning when a conditional expression is compile time
...@@ -721,10 +718,9 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -721,10 +718,9 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
// while (true) { // while (true) {
// GTEST_INTENTIONAL_CONST_COND_POP_() // GTEST_INTENTIONAL_CONST_COND_POP_()
// } // }
# define GTEST_INTENTIONAL_CONST_COND_PUSH_() \ #define GTEST_INTENTIONAL_CONST_COND_PUSH_() \
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4127) GTEST_DISABLE_MSC_WARNINGS_PUSH_(4127)
# define GTEST_INTENTIONAL_CONST_COND_POP_() \ #define GTEST_INTENTIONAL_CONST_COND_POP_() GTEST_DISABLE_MSC_WARNINGS_POP_()
GTEST_DISABLE_MSC_WARNINGS_POP_()
// Determine whether the compiler supports Microsoft's Structured Exception // Determine whether the compiler supports Microsoft's Structured Exception
// Handling. This is supported by several Windows compilers but generally // Handling. This is supported by several Windows compilers but generally
...@@ -732,13 +728,13 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -732,13 +728,13 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
#ifndef GTEST_HAS_SEH #ifndef GTEST_HAS_SEH
// The user didn't tell us, so we need to figure it out. // The user didn't tell us, so we need to figure it out.
# if defined(_MSC_VER) || defined(__BORLANDC__) #if defined(_MSC_VER) || defined(__BORLANDC__)
// These two compilers are known to support SEH. // These two compilers are known to support SEH.
# define GTEST_HAS_SEH 1 #define GTEST_HAS_SEH 1
# else #else
// Assume no SEH. // Assume no SEH.
# define GTEST_HAS_SEH 0 #define GTEST_HAS_SEH 0
# endif #endif
#endif // GTEST_HAS_SEH #endif // GTEST_HAS_SEH
...@@ -754,8 +750,8 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -754,8 +750,8 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
#if GTEST_IS_THREADSAFE #if GTEST_IS_THREADSAFE
// Some platforms don't support including these threading related headers. // Some platforms don't support including these threading related headers.
#include <condition_variable> // NOLINT #include <condition_variable> // NOLINT
#include <mutex> // NOLINT #include <mutex> // NOLINT
#endif // GTEST_IS_THREADSAFE #endif // GTEST_IS_THREADSAFE
// GTEST_API_ qualifies all symbols that must be exported. The definitions below // GTEST_API_ qualifies all symbols that must be exported. The definitions below
// are guarded by #ifndef to give embedders a chance to define GTEST_API_ in // are guarded by #ifndef to give embedders a chance to define GTEST_API_ in
...@@ -763,30 +759,30 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -763,30 +759,30 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
#ifndef GTEST_API_ #ifndef GTEST_API_
#ifdef _MSC_VER #ifdef _MSC_VER
# if GTEST_LINKED_AS_SHARED_LIBRARY #if GTEST_LINKED_AS_SHARED_LIBRARY
# define GTEST_API_ __declspec(dllimport) #define GTEST_API_ __declspec(dllimport)
# elif GTEST_CREATE_SHARED_LIBRARY #elif GTEST_CREATE_SHARED_LIBRARY
# define GTEST_API_ __declspec(dllexport) #define GTEST_API_ __declspec(dllexport)
# endif #endif
#elif __GNUC__ >= 4 || defined(__clang__) #elif __GNUC__ >= 4 || defined(__clang__)
# define GTEST_API_ __attribute__((visibility ("default"))) #define GTEST_API_ __attribute__((visibility("default")))
#endif // _MSC_VER #endif // _MSC_VER
#endif // GTEST_API_ #endif // GTEST_API_
#ifndef GTEST_API_ #ifndef GTEST_API_
# define GTEST_API_ #define GTEST_API_
#endif // GTEST_API_ #endif // GTEST_API_
#ifndef GTEST_DEFAULT_DEATH_TEST_STYLE #ifndef GTEST_DEFAULT_DEATH_TEST_STYLE
# define GTEST_DEFAULT_DEATH_TEST_STYLE "fast" #define GTEST_DEFAULT_DEATH_TEST_STYLE "fast"
#endif // GTEST_DEFAULT_DEATH_TEST_STYLE #endif // GTEST_DEFAULT_DEATH_TEST_STYLE
#ifdef __GNUC__ #ifdef __GNUC__
// Ask the compiler to never inline a given function. // Ask the compiler to never inline a given function.
# define GTEST_NO_INLINE_ __attribute__((noinline)) #define GTEST_NO_INLINE_ __attribute__((noinline))
#else #else
# define GTEST_NO_INLINE_ #define GTEST_NO_INLINE_
#endif #endif
#if defined(__clang__) #if defined(__clang__)
...@@ -805,60 +801,58 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -805,60 +801,58 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
// _LIBCPP_VERSION is defined by the libc++ library from the LLVM project. // _LIBCPP_VERSION is defined by the libc++ library from the LLVM project.
#if !defined(GTEST_HAS_CXXABI_H_) #if !defined(GTEST_HAS_CXXABI_H_)
# if defined(__GLIBCXX__) || (defined(_LIBCPP_VERSION) && !defined(_MSC_VER)) #if defined(__GLIBCXX__) || (defined(_LIBCPP_VERSION) && !defined(_MSC_VER))
# define GTEST_HAS_CXXABI_H_ 1 #define GTEST_HAS_CXXABI_H_ 1
# else #else
# define GTEST_HAS_CXXABI_H_ 0 #define GTEST_HAS_CXXABI_H_ 0
# endif #endif
#endif #endif
// A function level attribute to disable checking for use of uninitialized // A function level attribute to disable checking for use of uninitialized
// memory when built with MemorySanitizer. // memory when built with MemorySanitizer.
#if defined(__clang__) #if defined(__clang__)
# if __has_feature(memory_sanitizer) #if __has_feature(memory_sanitizer)
# define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ \ #define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ __attribute__((no_sanitize_memory))
__attribute__((no_sanitize_memory)) #else
# else #define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_
# define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ #endif // __has_feature(memory_sanitizer)
# endif // __has_feature(memory_sanitizer)
#else #else
# define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ #define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_
#endif // __clang__ #endif // __clang__
// A function level attribute to disable AddressSanitizer instrumentation. // A function level attribute to disable AddressSanitizer instrumentation.
#if defined(__clang__) #if defined(__clang__)
# if __has_feature(address_sanitizer) #if __has_feature(address_sanitizer)
# define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ \ #define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ \
__attribute__((no_sanitize_address)) __attribute__((no_sanitize_address))
# else
# define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
# endif // __has_feature(address_sanitizer)
#else #else
# define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ #define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
#endif // __has_feature(address_sanitizer)
#else
#define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
#endif // __clang__ #endif // __clang__
// A function level attribute to disable HWAddressSanitizer instrumentation. // A function level attribute to disable HWAddressSanitizer instrumentation.
#if defined(__clang__) #if defined(__clang__)
# if __has_feature(hwaddress_sanitizer) #if __has_feature(hwaddress_sanitizer)
# define GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_ \ #define GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_ \
__attribute__((no_sanitize("hwaddress"))) __attribute__((no_sanitize("hwaddress")))
# else #else
# define GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_ #define GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_
# endif // __has_feature(hwaddress_sanitizer) #endif // __has_feature(hwaddress_sanitizer)
#else #else
# define GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_ #define GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_
#endif // __clang__ #endif // __clang__
// A function level attribute to disable ThreadSanitizer instrumentation. // A function level attribute to disable ThreadSanitizer instrumentation.
#if defined(__clang__) #if defined(__clang__)
# if __has_feature(thread_sanitizer) #if __has_feature(thread_sanitizer)
# define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ \ #define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ __attribute__((no_sanitize_thread))
__attribute__((no_sanitize_thread))
# else
# define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_
# endif // __has_feature(thread_sanitizer)
#else #else
# define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ #define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_
#endif // __has_feature(thread_sanitizer)
#else
#define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_
#endif // __clang__ #endif // __clang__
namespace testing { namespace testing {
...@@ -937,16 +931,16 @@ class GTEST_API_ RE { ...@@ -937,16 +931,16 @@ class GTEST_API_ RE {
const char* pattern_; const char* pattern_;
bool is_valid_; bool is_valid_;
# if GTEST_USES_POSIX_RE #if GTEST_USES_POSIX_RE
regex_t full_regex_; // For FullMatch(). regex_t full_regex_; // For FullMatch().
regex_t partial_regex_; // For PartialMatch(). regex_t partial_regex_; // For PartialMatch().
# else // GTEST_USES_SIMPLE_RE #else // GTEST_USES_SIMPLE_RE
const char* full_pattern_; // For FullMatch(); const char* full_pattern_; // For FullMatch();
# endif #endif
}; };
#endif // GTEST_USES_PCRE #endif // GTEST_USES_PCRE
...@@ -967,12 +961,7 @@ GTEST_API_ ::std::string FormatCompilerIndependentFileLocation(const char* file, ...@@ -967,12 +961,7 @@ GTEST_API_ ::std::string FormatCompilerIndependentFileLocation(const char* file,
// LogToStderr() - directs all log messages to stderr. // LogToStderr() - directs all log messages to stderr.
// FlushInfoLog() - flushes informational log messages. // FlushInfoLog() - flushes informational log messages.
enum GTestLogSeverity { enum GTestLogSeverity { GTEST_INFO, GTEST_WARNING, GTEST_ERROR, GTEST_FATAL };
GTEST_INFO,
GTEST_WARNING,
GTEST_ERROR,
GTEST_FATAL
};
// Formats log entry severity, provides a stream object for streaming the // Formats log entry severity, provides a stream object for streaming the
// log message, and terminates the message with a newline when going out of // log message, and terminates the message with a newline when going out of
...@@ -994,9 +983,10 @@ class GTEST_API_ GTestLog { ...@@ -994,9 +983,10 @@ class GTEST_API_ GTestLog {
#if !defined(GTEST_LOG_) #if !defined(GTEST_LOG_)
# define GTEST_LOG_(severity) \ #define GTEST_LOG_(severity) \
::testing::internal::GTestLog(::testing::internal::GTEST_##severity, \ ::testing::internal::GTestLog(::testing::internal::GTEST_##severity, \
__FILE__, __LINE__).GetStream() __FILE__, __LINE__) \
.GetStream()
inline void LogToStderr() {} inline void LogToStderr() {}
inline void FlushInfoLog() { fflush(nullptr); } inline void FlushInfoLog() { fflush(nullptr); }
...@@ -1018,12 +1008,12 @@ inline void FlushInfoLog() { fflush(nullptr); } ...@@ -1018,12 +1008,12 @@ inline void FlushInfoLog() { fflush(nullptr); }
// condition itself, plus additional message streamed into it, if any, // condition itself, plus additional message streamed into it, if any,
// and then it aborts the program. It aborts the program irrespective of // and then it aborts the program. It aborts the program irrespective of
// whether it is built in the debug mode or not. // whether it is built in the debug mode or not.
# define GTEST_CHECK_(condition) \ #define GTEST_CHECK_(condition) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if (::testing::internal::IsTrue(condition)) \ if (::testing::internal::IsTrue(condition)) \
; \ ; \
else \ else \
GTEST_LOG_(FATAL) << "Condition " #condition " failed. " GTEST_LOG_(FATAL) << "Condition " #condition " failed. "
#endif // !defined(GTEST_CHECK_) #endif // !defined(GTEST_CHECK_)
// An all-mode assert to verify that the given POSIX-style function // An all-mode assert to verify that the given POSIX-style function
...@@ -1032,9 +1022,8 @@ inline void FlushInfoLog() { fflush(nullptr); } ...@@ -1032,9 +1022,8 @@ inline void FlushInfoLog() { fflush(nullptr); }
// in {} if you need to use it as the only statement in an 'if' // in {} if you need to use it as the only statement in an 'if'
// branch. // branch.
#define GTEST_CHECK_POSIX_SUCCESS_(posix_call) \ #define GTEST_CHECK_POSIX_SUCCESS_(posix_call) \
if (const int gtest_error = (posix_call)) \ if (const int gtest_error = (posix_call)) \
GTEST_LOG_(FATAL) << #posix_call << "failed with error " \ GTEST_LOG_(FATAL) << #posix_call << "failed with error " << gtest_error
<< gtest_error
// Transforms "T" into "const T&" according to standard reference collapsing // Transforms "T" into "const T&" according to standard reference collapsing
// rules (this is only needed as a backport for C++98 compilers that do not // rules (this is only needed as a backport for C++98 compilers that do not
...@@ -1048,9 +1037,13 @@ inline void FlushInfoLog() { fflush(nullptr); } ...@@ -1048,9 +1037,13 @@ inline void FlushInfoLog() { fflush(nullptr); }
// Note that the non-const reference will not have "const" added. This is // Note that the non-const reference will not have "const" added. This is
// standard, and necessary so that "T" can always bind to "const T&". // standard, and necessary so that "T" can always bind to "const T&".
template <typename T> template <typename T>
struct ConstRef { typedef const T& type; }; struct ConstRef {
typedef const T& type;
};
template <typename T> template <typename T>
struct ConstRef<T&> { typedef T& type; }; struct ConstRef<T&> {
typedef T& type;
};
// The argument T must depend on some template parameters. // The argument T must depend on some template parameters.
#define GTEST_REFERENCE_TO_CONST_(T) \ #define GTEST_REFERENCE_TO_CONST_(T) \
...@@ -1076,8 +1069,10 @@ struct ConstRef<T&> { typedef T& type; }; ...@@ -1076,8 +1069,10 @@ struct ConstRef<T&> { typedef T& type; };
// This relatively ugly name is intentional. It prevents clashes with // This relatively ugly name is intentional. It prevents clashes with
// similar functions users may have (e.g., implicit_cast). The internal // similar functions users may have (e.g., implicit_cast). The internal
// namespace alone is not enough because the function can be found by ADL. // namespace alone is not enough because the function can be found by ADL.
template<typename To> template <typename To>
inline To ImplicitCast_(To x) { return x; } inline To ImplicitCast_(To x) {
return x;
}
// When you upcast (that is, cast a pointer from type Foo to type // When you upcast (that is, cast a pointer from type Foo to type
// SuperclassOfFoo), it's fine to use ImplicitCast_<>, since upcasts // SuperclassOfFoo), it's fine to use ImplicitCast_<>, since upcasts
...@@ -1100,17 +1095,17 @@ inline To ImplicitCast_(To x) { return x; } ...@@ -1100,17 +1095,17 @@ inline To ImplicitCast_(To x) { return x; }
// This relatively ugly name is intentional. It prevents clashes with // This relatively ugly name is intentional. It prevents clashes with
// similar functions users may have (e.g., down_cast). The internal // similar functions users may have (e.g., down_cast). The internal
// namespace alone is not enough because the function can be found by ADL. // namespace alone is not enough because the function can be found by ADL.
template<typename To, typename From> // use like this: DownCast_<T*>(foo); template <typename To, typename From> // use like this: DownCast_<T*>(foo);
inline To DownCast_(From* f) { // so we only accept pointers inline To DownCast_(From* f) { // so we only accept pointers
// Ensures that To is a sub-type of From *. This test is here only // Ensures that To is a sub-type of From *. This test is here only
// for compile-time type checking, and has no overhead in an // for compile-time type checking, and has no overhead in an
// optimized build at run-time, as it will be optimized away // optimized build at run-time, as it will be optimized away
// completely. // completely.
GTEST_INTENTIONAL_CONST_COND_PUSH_() GTEST_INTENTIONAL_CONST_COND_PUSH_()
if (false) { if (false) {
GTEST_INTENTIONAL_CONST_COND_POP_() GTEST_INTENTIONAL_CONST_COND_POP_()
const To to = nullptr; const To to = nullptr;
::testing::internal::ImplicitCast_<From*>(to); ::testing::internal::ImplicitCast_<From*>(to);
} }
#if GTEST_HAS_RTTI #if GTEST_HAS_RTTI
...@@ -1176,7 +1171,7 @@ void ClearInjectableArgvs(); ...@@ -1176,7 +1171,7 @@ void ClearInjectableArgvs();
// Defines synchronization primitives. // Defines synchronization primitives.
#if GTEST_IS_THREADSAFE #if GTEST_IS_THREADSAFE
# if GTEST_OS_WINDOWS #if GTEST_OS_WINDOWS
// Provides leak-safe Windows kernel handle ownership. // Provides leak-safe Windows kernel handle ownership.
// Used in death tests and in threading support. // Used in death tests and in threading support.
class GTEST_API_ AutoHandle { class GTEST_API_ AutoHandle {
...@@ -1205,13 +1200,13 @@ class GTEST_API_ AutoHandle { ...@@ -1205,13 +1200,13 @@ class GTEST_API_ AutoHandle {
GTEST_DISALLOW_COPY_AND_ASSIGN_(AutoHandle); GTEST_DISALLOW_COPY_AND_ASSIGN_(AutoHandle);
}; };
# endif #endif
# if GTEST_HAS_NOTIFICATION_ #if GTEST_HAS_NOTIFICATION_
// Notification has already been imported into the namespace. // Notification has already been imported into the namespace.
// Nothing to do here. // Nothing to do here.
# else #else
// Allows a controller thread to pause execution of newly created // Allows a controller thread to pause execution of newly created
// threads until notified. Instances of this class must be created // threads until notified. Instances of this class must be created
// and destroyed in the controller thread. // and destroyed in the controller thread.
...@@ -1245,12 +1240,12 @@ class GTEST_API_ Notification { ...@@ -1245,12 +1240,12 @@ class GTEST_API_ Notification {
std::condition_variable cv_; std::condition_variable cv_;
bool notified_; bool notified_;
}; };
# endif // GTEST_HAS_NOTIFICATION_ #endif // GTEST_HAS_NOTIFICATION_
// On MinGW, we can have both GTEST_OS_WINDOWS and GTEST_HAS_PTHREAD // On MinGW, we can have both GTEST_OS_WINDOWS and GTEST_HAS_PTHREAD
// defined, but we don't want to use MinGW's pthreads implementation, which // defined, but we don't want to use MinGW's pthreads implementation, which
// has conformance problems with some versions of the POSIX standard. // has conformance problems with some versions of the POSIX standard.
# if GTEST_HAS_PTHREAD && !GTEST_OS_WINDOWS_MINGW #if GTEST_HAS_PTHREAD && !GTEST_OS_WINDOWS_MINGW
// As a C-function, ThreadFuncWithCLinkage cannot be templated itself. // As a C-function, ThreadFuncWithCLinkage cannot be templated itself.
// Consequently, it cannot select a correct instantiation of ThreadWithParam // Consequently, it cannot select a correct instantiation of ThreadWithParam
...@@ -1328,14 +1323,14 @@ class ThreadWithParam : public ThreadWithParamBase { ...@@ -1328,14 +1323,14 @@ class ThreadWithParam : public ThreadWithParamBase {
GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadWithParam); GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadWithParam);
}; };
# endif // !GTEST_OS_WINDOWS && GTEST_HAS_PTHREAD || #endif // !GTEST_OS_WINDOWS && GTEST_HAS_PTHREAD ||
// GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ // GTEST_HAS_MUTEX_AND_THREAD_LOCAL_
# if GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ #if GTEST_HAS_MUTEX_AND_THREAD_LOCAL_
// Mutex and ThreadLocal have already been imported into the namespace. // Mutex and ThreadLocal have already been imported into the namespace.
// Nothing to do here. // Nothing to do here.
# elif GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT #elif GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
// Mutex implements mutex on Windows platforms. It is used in conjunction // Mutex implements mutex on Windows platforms. It is used in conjunction
// with class MutexLock: // with class MutexLock:
...@@ -1392,11 +1387,11 @@ class GTEST_API_ Mutex { ...@@ -1392,11 +1387,11 @@ class GTEST_API_ Mutex {
GTEST_DISALLOW_COPY_AND_ASSIGN_(Mutex); GTEST_DISALLOW_COPY_AND_ASSIGN_(Mutex);
}; };
# define GTEST_DECLARE_STATIC_MUTEX_(mutex) \ #define GTEST_DECLARE_STATIC_MUTEX_(mutex) \
extern ::testing::internal::Mutex mutex extern ::testing::internal::Mutex mutex
# define GTEST_DEFINE_STATIC_MUTEX_(mutex) \ #define GTEST_DEFINE_STATIC_MUTEX_(mutex) \
::testing::internal::Mutex mutex(::testing::internal::Mutex::kStaticMutex) ::testing::internal::Mutex mutex(::testing::internal::Mutex::kStaticMutex)
// We cannot name this class MutexLock because the ctor declaration would // We cannot name this class MutexLock because the ctor declaration would
// conflict with a macro named MutexLock, which is defined on some // conflict with a macro named MutexLock, which is defined on some
...@@ -1405,8 +1400,7 @@ class GTEST_API_ Mutex { ...@@ -1405,8 +1400,7 @@ class GTEST_API_ Mutex {
// "MutexLock l(&mu)". Hence the typedef trick below. // "MutexLock l(&mu)". Hence the typedef trick below.
class GTestMutexLock { class GTestMutexLock {
public: public:
explicit GTestMutexLock(Mutex* mutex) explicit GTestMutexLock(Mutex* mutex) : mutex_(mutex) { mutex_->Lock(); }
: mutex_(mutex) { mutex_->Lock(); }
~GTestMutexLock() { mutex_->Unlock(); } ~GTestMutexLock() { mutex_->Unlock(); }
...@@ -1469,7 +1463,7 @@ class GTEST_API_ ThreadWithParamBase { ...@@ -1469,7 +1463,7 @@ class GTEST_API_ ThreadWithParamBase {
virtual void Run() = 0; virtual void Run() = 0;
}; };
ThreadWithParamBase(Runnable *runnable, Notification* thread_can_start); ThreadWithParamBase(Runnable* runnable, Notification* thread_can_start);
virtual ~ThreadWithParamBase(); virtual ~ThreadWithParamBase();
private: private:
...@@ -1483,21 +1477,15 @@ class ThreadWithParam : public ThreadWithParamBase { ...@@ -1483,21 +1477,15 @@ class ThreadWithParam : public ThreadWithParamBase {
typedef void UserThreadFunc(T); typedef void UserThreadFunc(T);
ThreadWithParam(UserThreadFunc* func, T param, Notification* thread_can_start) ThreadWithParam(UserThreadFunc* func, T param, Notification* thread_can_start)
: ThreadWithParamBase(new RunnableImpl(func, param), thread_can_start) { : ThreadWithParamBase(new RunnableImpl(func, param), thread_can_start) {}
}
virtual ~ThreadWithParam() {} virtual ~ThreadWithParam() {}
private: private:
class RunnableImpl : public Runnable { class RunnableImpl : public Runnable {
public: public:
RunnableImpl(UserThreadFunc* func, T param) RunnableImpl(UserThreadFunc* func, T param) : func_(func), param_(param) {}
: func_(func),
param_(param) {
}
virtual ~RunnableImpl() {} virtual ~RunnableImpl() {}
virtual void Run() { virtual void Run() { func_(param_); }
func_(param_);
}
private: private:
UserThreadFunc* const func_; UserThreadFunc* const func_;
...@@ -1565,10 +1553,10 @@ class ThreadLocal : public ThreadLocalBase { ...@@ -1565,10 +1553,10 @@ class ThreadLocal : public ThreadLocalBase {
GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolder); GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolder);
}; };
T* GetOrCreateValue() const { T* GetOrCreateValue() const {
return static_cast<ValueHolder*>( return static_cast<ValueHolder*>(
ThreadLocalRegistry::GetValueOnCurrentThread(this))->pointer(); ThreadLocalRegistry::GetValueOnCurrentThread(this))
->pointer();
} }
virtual ThreadLocalValueHolderBase* NewValueForCurrentThread() const { virtual ThreadLocalValueHolderBase* NewValueForCurrentThread() const {
...@@ -1612,7 +1600,7 @@ class ThreadLocal : public ThreadLocalBase { ...@@ -1612,7 +1600,7 @@ class ThreadLocal : public ThreadLocalBase {
GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocal); GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocal);
}; };
# elif GTEST_HAS_PTHREAD #elif GTEST_HAS_PTHREAD
// MutexBase and Mutex implement mutex on pthreads-based platforms. // MutexBase and Mutex implement mutex on pthreads-based platforms.
class MutexBase { class MutexBase {
...@@ -1659,8 +1647,8 @@ class MutexBase { ...@@ -1659,8 +1647,8 @@ class MutexBase {
}; };
// Forward-declares a static mutex. // Forward-declares a static mutex.
# define GTEST_DECLARE_STATIC_MUTEX_(mutex) \ #define GTEST_DECLARE_STATIC_MUTEX_(mutex) \
extern ::testing::internal::MutexBase mutex extern ::testing::internal::MutexBase mutex
// Defines and statically (i.e. at link time) initializes a static mutex. // Defines and statically (i.e. at link time) initializes a static mutex.
// The initialization list here does not explicitly initialize each field, // The initialization list here does not explicitly initialize each field,
...@@ -1679,9 +1667,7 @@ class Mutex : public MutexBase { ...@@ -1679,9 +1667,7 @@ class Mutex : public MutexBase {
GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, nullptr)); GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, nullptr));
has_owner_ = false; has_owner_ = false;
} }
~Mutex() { ~Mutex() { GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_destroy(&mutex_)); }
GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_destroy(&mutex_));
}
private: private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(Mutex); GTEST_DISALLOW_COPY_AND_ASSIGN_(Mutex);
...@@ -1694,8 +1680,7 @@ class Mutex : public MutexBase { ...@@ -1694,8 +1680,7 @@ class Mutex : public MutexBase {
// "MutexLock l(&mu)". Hence the typedef trick below. // "MutexLock l(&mu)". Hence the typedef trick below.
class GTestMutexLock { class GTestMutexLock {
public: public:
explicit GTestMutexLock(MutexBase* mutex) explicit GTestMutexLock(MutexBase* mutex) : mutex_(mutex) { mutex_->Lock(); }
: mutex_(mutex) { mutex_->Lock(); }
~GTestMutexLock() { mutex_->Unlock(); } ~GTestMutexLock() { mutex_->Unlock(); }
...@@ -1823,7 +1808,7 @@ class GTEST_API_ ThreadLocal { ...@@ -1823,7 +1808,7 @@ class GTEST_API_ ThreadLocal {
GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocal); GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocal);
}; };
# endif // GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ #endif // GTEST_HAS_MUTEX_AND_THREAD_LOCAL_
#else // GTEST_IS_THREADSAFE #else // GTEST_IS_THREADSAFE
...@@ -1840,10 +1825,10 @@ class Mutex { ...@@ -1840,10 +1825,10 @@ class Mutex {
void AssertHeld() const {} void AssertHeld() const {}
}; };
# define GTEST_DECLARE_STATIC_MUTEX_(mutex) \ #define GTEST_DECLARE_STATIC_MUTEX_(mutex) \
extern ::testing::internal::Mutex mutex extern ::testing::internal::Mutex mutex
# define GTEST_DEFINE_STATIC_MUTEX_(mutex) ::testing::internal::Mutex mutex #define GTEST_DEFINE_STATIC_MUTEX_(mutex) ::testing::internal::Mutex mutex
// We cannot name this class MutexLock because the ctor declaration would // We cannot name this class MutexLock because the ctor declaration would
// conflict with a macro named MutexLock, which is defined on some // conflict with a macro named MutexLock, which is defined on some
...@@ -1866,6 +1851,7 @@ class GTEST_API_ ThreadLocal { ...@@ -1866,6 +1851,7 @@ class GTEST_API_ ThreadLocal {
const T* pointer() const { return &value_; } const T* pointer() const { return &value_; }
const T& get() const { return value_; } const T& get() const { return value_; }
void set(const T& value) { value_ = value; } void set(const T& value) { value_ = value; }
private: private:
T value_; T value_;
}; };
...@@ -1877,11 +1863,11 @@ class GTEST_API_ ThreadLocal { ...@@ -1877,11 +1863,11 @@ class GTEST_API_ ThreadLocal {
GTEST_API_ size_t GetThreadCount(); GTEST_API_ size_t GetThreadCount();
#if GTEST_OS_WINDOWS #if GTEST_OS_WINDOWS
# define GTEST_PATH_SEP_ "\\" #define GTEST_PATH_SEP_ "\\"
# define GTEST_HAS_ALT_PATH_SEP_ 1 #define GTEST_HAS_ALT_PATH_SEP_ 1
#else #else
# define GTEST_PATH_SEP_ "/" #define GTEST_PATH_SEP_ "/"
# define GTEST_HAS_ALT_PATH_SEP_ 0 #define GTEST_HAS_ALT_PATH_SEP_ 0
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
// Utilities for char. // Utilities for char.
...@@ -1939,8 +1925,7 @@ inline char ToUpper(char ch) { ...@@ -1939,8 +1925,7 @@ inline char ToUpper(char ch) {
inline std::string StripTrailingSpaces(std::string str) { inline std::string StripTrailingSpaces(std::string str) {
std::string::iterator it = str.end(); std::string::iterator it = str.end();
while (it != str.begin() && IsSpace(*--it)) while (it != str.begin() && IsSpace(*--it)) it = str.erase(it);
it = str.erase(it);
return str; return str;
} }
...@@ -1958,36 +1943,34 @@ namespace posix { ...@@ -1958,36 +1943,34 @@ namespace posix {
typedef struct _stat StatStruct; typedef struct _stat StatStruct;
# ifdef __BORLANDC__ #ifdef __BORLANDC__
inline int DoIsATTY(int fd) { return isatty(fd); } inline int DoIsATTY(int fd) { return isatty(fd); }
inline int StrCaseCmp(const char* s1, const char* s2) { inline int StrCaseCmp(const char* s1, const char* s2) {
return stricmp(s1, s2); return stricmp(s1, s2);
} }
inline char* StrDup(const char* src) { return strdup(src); } inline char* StrDup(const char* src) { return strdup(src); }
# else // !__BORLANDC__ #else // !__BORLANDC__
# if GTEST_OS_WINDOWS_MOBILE #if GTEST_OS_WINDOWS_MOBILE
inline int DoIsATTY(int /* fd */) { return 0; } inline int DoIsATTY(int /* fd */) { return 0; }
# else #else
inline int DoIsATTY(int fd) { return _isatty(fd); } inline int DoIsATTY(int fd) { return _isatty(fd); }
# endif // GTEST_OS_WINDOWS_MOBILE #endif // GTEST_OS_WINDOWS_MOBILE
inline int StrCaseCmp(const char* s1, const char* s2) { inline int StrCaseCmp(const char* s1, const char* s2) {
return _stricmp(s1, s2); return _stricmp(s1, s2);
} }
inline char* StrDup(const char* src) { return _strdup(src); } inline char* StrDup(const char* src) { return _strdup(src); }
# endif // __BORLANDC__ #endif // __BORLANDC__
# if GTEST_OS_WINDOWS_MOBILE #if GTEST_OS_WINDOWS_MOBILE
inline int FileNo(FILE* file) { return reinterpret_cast<int>(_fileno(file)); } inline int FileNo(FILE* file) { return reinterpret_cast<int>(_fileno(file)); }
// Stat(), RmDir(), and IsDir() are not needed on Windows CE at this // Stat(), RmDir(), and IsDir() are not needed on Windows CE at this
// time and thus not defined there. // time and thus not defined there.
# else #else
inline int FileNo(FILE* file) { return _fileno(file); } inline int FileNo(FILE* file) { return _fileno(file); }
inline int Stat(const char* path, StatStruct* buf) { return _stat(path, buf); } inline int Stat(const char* path, StatStruct* buf) { return _stat(path, buf); }
inline int RmDir(const char* dir) { return _rmdir(dir); } inline int RmDir(const char* dir) { return _rmdir(dir); }
inline bool IsDir(const StatStruct& st) { inline bool IsDir(const StatStruct& st) { return (_S_IFDIR & st.st_mode) != 0; }
return (_S_IFDIR & st.st_mode) != 0; #endif // GTEST_OS_WINDOWS_MOBILE
}
# endif // GTEST_OS_WINDOWS_MOBILE
#elif GTEST_OS_ESP8266 #elif GTEST_OS_ESP8266
typedef struct stat StatStruct; typedef struct stat StatStruct;
...@@ -2051,12 +2034,12 @@ inline FILE* FOpen(const char* path, const char* mode) { ...@@ -2051,12 +2034,12 @@ inline FILE* FOpen(const char* path, const char* mode) {
std::wstring wide_path = converter.from_bytes(path); std::wstring wide_path = converter.from_bytes(path);
std::wstring wide_mode = converter.from_bytes(mode); std::wstring wide_mode = converter.from_bytes(mode);
return _wfopen(wide_path.c_str(), wide_mode.c_str()); return _wfopen(wide_path.c_str(), wide_mode.c_str());
#else // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW #else // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW
return fopen(path, mode); return fopen(path, mode);
#endif // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW #endif // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW
} }
#if !GTEST_OS_WINDOWS_MOBILE #if !GTEST_OS_WINDOWS_MOBILE
inline FILE *FReopen(const char* path, const char* mode, FILE* stream) { inline FILE* FReopen(const char* path, const char* mode, FILE* stream) {
return freopen(path, mode, stream); return freopen(path, mode, stream);
} }
inline FILE* FDOpen(int fd, const char* mode) { return fdopen(fd, mode); } inline FILE* FDOpen(int fd, const char* mode) { return fdopen(fd, mode); }
...@@ -2108,13 +2091,13 @@ GTEST_DISABLE_MSC_DEPRECATED_POP_() ...@@ -2108,13 +2091,13 @@ GTEST_DISABLE_MSC_DEPRECATED_POP_()
// snprintf is a variadic function. // snprintf is a variadic function.
#if _MSC_VER && !GTEST_OS_WINDOWS_MOBILE #if _MSC_VER && !GTEST_OS_WINDOWS_MOBILE
// MSVC 2005 and above support variadic macros. // MSVC 2005 and above support variadic macros.
# define GTEST_SNPRINTF_(buffer, size, format, ...) \ #define GTEST_SNPRINTF_(buffer, size, format, ...) \
_snprintf_s(buffer, size, size, format, __VA_ARGS__) _snprintf_s(buffer, size, size, format, __VA_ARGS__)
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
// Windows CE does not define _snprintf_s // Windows CE does not define _snprintf_s
# define GTEST_SNPRINTF_ _snprintf #define GTEST_SNPRINTF_ _snprintf
#else #else
# define GTEST_SNPRINTF_ snprintf #define GTEST_SNPRINTF_ snprintf
#endif #endif
// The biggest signed integer type the compiler supports. // The biggest signed integer type the compiler supports.
...@@ -2174,43 +2157,49 @@ using TimeInMillis = int64_t; // Represents time in milliseconds. ...@@ -2174,43 +2157,49 @@ using TimeInMillis = int64_t; // Represents time in milliseconds.
// Macro for referencing flags. // Macro for referencing flags.
#if !defined(GTEST_FLAG) #if !defined(GTEST_FLAG)
# define GTEST_FLAG(name) FLAGS_gtest_##name #define GTEST_FLAG(name) FLAGS_gtest_##name
#endif // !defined(GTEST_FLAG) #endif // !defined(GTEST_FLAG)
#if !defined(GTEST_USE_OWN_FLAGFILE_FLAG_) #if !defined(GTEST_USE_OWN_FLAGFILE_FLAG_)
# define GTEST_USE_OWN_FLAGFILE_FLAG_ 1 #define GTEST_USE_OWN_FLAGFILE_FLAG_ 1
#endif // !defined(GTEST_USE_OWN_FLAGFILE_FLAG_) #endif // !defined(GTEST_USE_OWN_FLAGFILE_FLAG_)
#if !defined(GTEST_DECLARE_bool_) #if !defined(GTEST_DECLARE_bool_)
# define GTEST_FLAG_SAVER_ ::testing::internal::GTestFlagSaver #define GTEST_FLAG_SAVER_ ::testing::internal::GTestFlagSaver
// Macros for declaring flags. // Macros for declaring flags.
#define GTEST_DECLARE_bool_(name) \ #define GTEST_DECLARE_bool_(name) \
namespace testing { \ namespace testing { \
GTEST_API_ extern bool GTEST_FLAG(name); \ GTEST_API_ extern bool GTEST_FLAG(name); \
} static_assert(true, "no-op to require trailing semicolon") } \
static_assert(true, "no-op to require trailing semicolon")
#define GTEST_DECLARE_int32_(name) \ #define GTEST_DECLARE_int32_(name) \
namespace testing { \ namespace testing { \
GTEST_API_ extern std::int32_t GTEST_FLAG(name); \ GTEST_API_ extern std::int32_t GTEST_FLAG(name); \
} static_assert(true, "no-op to require trailing semicolon") } \
static_assert(true, "no-op to require trailing semicolon")
#define GTEST_DECLARE_string_(name) \ #define GTEST_DECLARE_string_(name) \
namespace testing { \ namespace testing { \
GTEST_API_ extern ::std::string GTEST_FLAG(name); \ GTEST_API_ extern ::std::string GTEST_FLAG(name); \
} static_assert(true, "no-op to require trailing semicolon") } \
static_assert(true, "no-op to require trailing semicolon")
// Macros for defining flags. // Macros for defining flags.
#define GTEST_DEFINE_bool_(name, default_val, doc) \ #define GTEST_DEFINE_bool_(name, default_val, doc) \
namespace testing { \ namespace testing { \
GTEST_API_ bool GTEST_FLAG(name) = (default_val); \ GTEST_API_ bool GTEST_FLAG(name) = (default_val); \
} static_assert(true, "no-op to require trailing semicolon") } \
static_assert(true, "no-op to require trailing semicolon")
#define GTEST_DEFINE_int32_(name, default_val, doc) \ #define GTEST_DEFINE_int32_(name, default_val, doc) \
namespace testing { \ namespace testing { \
GTEST_API_ std::int32_t GTEST_FLAG(name) = (default_val); \ GTEST_API_ std::int32_t GTEST_FLAG(name) = (default_val); \
} static_assert(true, "no-op to require trailing semicolon") } \
static_assert(true, "no-op to require trailing semicolon")
#define GTEST_DEFINE_string_(name, default_val, doc) \ #define GTEST_DEFINE_string_(name, default_val, doc) \
namespace testing { \ namespace testing { \
GTEST_API_ ::std::string GTEST_FLAG(name) = (default_val); \ GTEST_API_ ::std::string GTEST_FLAG(name) = (default_val); \
} static_assert(true, "no-op to require trailing semicolon") } \
static_assert(true, "no-op to require trailing semicolon")
#endif // !defined(GTEST_DECLARE_bool_) #endif // !defined(GTEST_DECLARE_bool_)
...@@ -2221,8 +2210,8 @@ using TimeInMillis = int64_t; // Represents time in milliseconds. ...@@ -2221,8 +2210,8 @@ using TimeInMillis = int64_t; // Represents time in milliseconds.
// Thread annotations // Thread annotations
#if !defined(GTEST_EXCLUSIVE_LOCK_REQUIRED_) #if !defined(GTEST_EXCLUSIVE_LOCK_REQUIRED_)
# define GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks) #define GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks)
# define GTEST_LOCK_EXCLUDED_(locks) #define GTEST_LOCK_EXCLUDED_(locks)
#endif // !defined(GTEST_EXCLUSIVE_LOCK_REQUIRED_) #endif // !defined(GTEST_EXCLUSIVE_LOCK_REQUIRED_)
// Parses 'str' for a 32-bit signed integer. If successful, writes the result // Parses 'str' for a 32-bit signed integer. If successful, writes the result
...@@ -2324,7 +2313,7 @@ inline ::std::nullopt_t Nullopt() { return ::std::nullopt; } ...@@ -2324,7 +2313,7 @@ inline ::std::nullopt_t Nullopt() { return ::std::nullopt; }
#if GTEST_HAS_ABSL #if GTEST_HAS_ABSL
// Always use absl::string_view for Matcher<> specializations if googletest // Always use absl::string_view for Matcher<> specializations if googletest
// is built with absl support. // is built with absl support.
# define GTEST_INTERNAL_HAS_STRING_VIEW 1 #define GTEST_INTERNAL_HAS_STRING_VIEW 1
#include "absl/strings/string_view.h" #include "absl/strings/string_view.h"
namespace testing { namespace testing {
namespace internal { namespace internal {
...@@ -2332,11 +2321,11 @@ using StringView = ::absl::string_view; ...@@ -2332,11 +2321,11 @@ using StringView = ::absl::string_view;
} // namespace internal } // namespace internal
} // namespace testing } // namespace testing
#else #else
# ifdef __has_include #ifdef __has_include
# if __has_include(<string_view>) && __cplusplus >= 201703L #if __has_include(<string_view>) && __cplusplus >= 201703L
// Otherwise for C++17 and higher use std::string_view for Matcher<> // Otherwise for C++17 and higher use std::string_view for Matcher<>
// specializations. // specializations.
# define GTEST_INTERNAL_HAS_STRING_VIEW 1 #define GTEST_INTERNAL_HAS_STRING_VIEW 1
#include <string_view> #include <string_view>
namespace testing { namespace testing {
namespace internal { namespace internal {
...@@ -2345,8 +2334,8 @@ using StringView = ::std::string_view; ...@@ -2345,8 +2334,8 @@ using StringView = ::std::string_view;
} // namespace testing } // namespace testing
// The case where absl is configured NOT to alias std::string_view is not // The case where absl is configured NOT to alias std::string_view is not
// supported. // supported.
# endif // __has_include(<string_view>) && __cplusplus >= 201703L #endif // __has_include(<string_view>) && __cplusplus >= 201703L
# endif // __has_include #endif // __has_include
#endif // GTEST_HAS_ABSL #endif // GTEST_HAS_ABSL
#if GTEST_HAS_ABSL #if GTEST_HAS_ABSL
...@@ -2373,7 +2362,8 @@ template <typename... T> ...@@ -2373,7 +2362,8 @@ template <typename... T>
using Variant = ::std::variant<T...>; using Variant = ::std::variant<T...>;
} // namespace internal } // namespace internal
} // namespace testing } // namespace testing
// The case where absl is configured NOT to alias std::variant is not supported. // The case where absl is configured NOT to alias std::variant is not
// supported.
#endif // __has_include(<variant>) && __cplusplus >= 201703L #endif // __has_include(<variant>) && __cplusplus >= 201703L
#endif // __has_include #endif // __has_include
#endif // GTEST_HAS_ABSL #endif // GTEST_HAS_ABSL
......
...@@ -45,10 +45,11 @@ ...@@ -45,10 +45,11 @@
#ifdef __BORLANDC__ #ifdef __BORLANDC__
// string.h is not guaranteed to provide strcpy on C++ Builder. // string.h is not guaranteed to provide strcpy on C++ Builder.
# include <mem.h> #include <mem.h>
#endif #endif
#include <string.h> #include <string.h>
#include <cstdint> #include <cstdint>
#include <string> #include <string>
...@@ -125,8 +126,7 @@ class GTEST_API_ String { ...@@ -125,8 +126,7 @@ class GTEST_API_ String {
// Unlike strcasecmp(), this function can handle NULL argument(s). // Unlike strcasecmp(), this function can handle NULL argument(s).
// A NULL C string is considered different to any non-NULL C string, // A NULL C string is considered different to any non-NULL C string,
// including the empty string. // including the empty string.
static bool CaseInsensitiveCStringEquals(const char* lhs, static bool CaseInsensitiveCStringEquals(const char* lhs, const char* rhs);
const char* rhs);
// Compares two wide C strings, ignoring case. Returns true if and only if // Compares two wide C strings, ignoring case. Returns true if and only if
// they have the same content. // they have the same content.
...@@ -145,8 +145,8 @@ class GTEST_API_ String { ...@@ -145,8 +145,8 @@ class GTEST_API_ String {
// Returns true if and only if the given string ends with the given suffix, // Returns true if and only if the given string ends with the given suffix,
// ignoring case. Any string is considered to end with an empty suffix. // ignoring case. Any string is considered to end with an empty suffix.
static bool EndsWithCaseInsensitive( static bool EndsWithCaseInsensitive(const std::string& str,
const std::string& str, const std::string& suffix); const std::string& suffix);
// Formats an int value as "%02d". // Formats an int value as "%02d".
static std::string FormatIntWidth2(int value); // "%02d" for width == 2 static std::string FormatIntWidth2(int value); // "%02d" for width == 2
...@@ -165,7 +165,7 @@ class GTEST_API_ String { ...@@ -165,7 +165,7 @@ class GTEST_API_ String {
private: private:
String(); // Not meant to be instantiated. String(); // Not meant to be instantiated.
}; // class String }; // class String
// Gets the content of the stringstream's buffer as an std::string. Each '\0' // Gets the content of the stringstream's buffer as an std::string. Each '\0'
// character in the buffer is replaced with "\\0". // character in the buffer is replaced with "\\0".
......
...@@ -41,11 +41,11 @@ ...@@ -41,11 +41,11 @@
// #ifdef __GNUC__ is too general here. It is possible to use gcc without using // #ifdef __GNUC__ is too general here. It is possible to use gcc without using
// libstdc++ (which is where cxxabi.h comes from). // libstdc++ (which is where cxxabi.h comes from).
# if GTEST_HAS_CXXABI_H_ #if GTEST_HAS_CXXABI_H_
# include <cxxabi.h> #include <cxxabi.h>
# elif defined(__HP_aCC) #elif defined(__HP_aCC)
# include <acxx_demangle.h> #include <acxx_demangle.h>
# endif // GTEST_HASH_CXXABI_H_ #endif // GTEST_HASH_CXXABI_H_
namespace testing { namespace testing {
namespace internal { namespace internal {
...@@ -103,7 +103,9 @@ std::string GetTypeName() { ...@@ -103,7 +103,9 @@ std::string GetTypeName() {
// A unique type indicating an empty node // A unique type indicating an empty node
struct None {}; struct None {};
# define GTEST_TEMPLATE_ template <typename T> class #define GTEST_TEMPLATE_ \
template <typename T> \
class
// The template "selector" struct TemplateSel<Tmpl> is used to // The template "selector" struct TemplateSel<Tmpl> is used to
// represent Tmpl, which must be a class template with one type // represent Tmpl, which must be a class template with one type
...@@ -121,8 +123,7 @@ struct TemplateSel { ...@@ -121,8 +123,7 @@ struct TemplateSel {
}; };
}; };
# define GTEST_BIND_(TmplSel, T) \ #define GTEST_BIND_(TmplSel, T) TmplSel::template Bind<T>::type
TmplSel::template Bind<T>::type
template <GTEST_TEMPLATE_ Head_, GTEST_TEMPLATE_... Tail_> template <GTEST_TEMPLATE_ Head_, GTEST_TEMPLATE_... Tail_>
struct Templates { struct Templates {
......
...@@ -27,8 +27,6 @@ ...@@ -27,8 +27,6 @@
// (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.
// This provides interface PrimeTable that determines whether a number is a // This provides interface PrimeTable that determines whether a number is a
// prime and determines a next prime number. This interface is used // prime and determines a next prime number. This interface is used
// in Google Test samples demonstrating use of parameterized tests. // in Google Test samples demonstrating use of parameterized tests.
...@@ -57,7 +55,7 @@ class OnTheFlyPrimeTable : public PrimeTable { ...@@ -57,7 +55,7 @@ class OnTheFlyPrimeTable : public PrimeTable {
bool IsPrime(int n) const override { bool IsPrime(int n) const override {
if (n <= 1) return false; if (n <= 1) return false;
for (int i = 2; i*i <= n; i++) { for (int i = 2; i * i <= n; i++) {
// n is divisible by an integer other than 1 and itself. // n is divisible by an integer other than 1 and itself.
if ((n % i) == 0) return false; if ((n % i) == 0) return false;
} }
...@@ -104,13 +102,13 @@ class PreCalculatedPrimeTable : public PrimeTable { ...@@ -104,13 +102,13 @@ class PreCalculatedPrimeTable : public PrimeTable {
// Checks every candidate for prime number (we know that 2 is the only even // Checks every candidate for prime number (we know that 2 is the only even
// prime). // prime).
for (int i = 2; i*i <= max; i += i%2+1) { for (int i = 2; i * i <= max; i += i % 2 + 1) {
if (!is_prime_[i]) continue; if (!is_prime_[i]) continue;
// Marks all multiples of i (except i itself) as non-prime. // Marks all multiples of i (except i itself) as non-prime.
// We are starting here from i-th multiplier, because all smaller // We are starting here from i-th multiplier, because all smaller
// complex numbers were already marked. // complex numbers were already marked.
for (int j = i*i; j <= max; j += i) { for (int j = i * i; j <= max; j += i) {
is_prime_[j] = false; is_prime_[j] = false;
} }
} }
......
...@@ -52,9 +52,9 @@ bool IsPrime(int n) { ...@@ -52,9 +52,9 @@ bool IsPrime(int n) {
// Now, we have that n is odd and n >= 3. // Now, we have that n is odd and n >= 3.
// Try to divide n by every odd number i, starting from 3 // Try to divide n by every odd number i, starting from 3
for (int i = 3; ; i += 2) { for (int i = 3;; i += 2) {
// We only have to try i up to the square root of n // We only have to try i up to the square root of n
if (i > n/i) break; if (i > n / i) break;
// Now, we have i <= n/i < n. // Now, we have i <= n/i < n.
// If n is divisible by i, n is not prime. // If n is divisible by i, n is not prime.
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
// (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.
// This sample shows how to use Google Test listener API to implement // This sample shows how to use Google Test listener API to implement
// a primitive leak checker. // a primitive leak checker.
...@@ -104,14 +103,15 @@ TEST(ListenersTest, LeaksWater) { ...@@ -104,14 +103,15 @@ TEST(ListenersTest, LeaksWater) {
} }
} // namespace } // namespace
int main(int argc, char **argv) { int main(int argc, char** argv) {
InitGoogleTest(&argc, argv); InitGoogleTest(&argc, argv);
bool check_for_leaks = false; bool check_for_leaks = false;
if (argc > 1 && strcmp(argv[1], "--check_for_leaks") == 0 ) if (argc > 1 && strcmp(argv[1], "--check_for_leaks") == 0)
check_for_leaks = true; check_for_leaks = true;
else else
printf("%s\n", "Run this program with --check_for_leaks to enable " printf("%s\n",
"Run this program with --check_for_leaks to enable "
"custom leak checking in the tests."); "custom leak checking in the tests.");
// If we are given the --check_for_leaks command line flag, installs the // If we are given the --check_for_leaks command line flag, installs the
......
...@@ -34,14 +34,15 @@ ...@@ -34,14 +34,15 @@
// //
// Writing a unit test using Google C++ testing framework is easy as 1-2-3: // Writing a unit test using Google C++ testing framework is easy as 1-2-3:
// Step 1. Include necessary header files such that the stuff your // Step 1. Include necessary header files such that the stuff your
// test logic needs is declared. // test logic needs is declared.
// //
// Don't forget gtest.h, which declares the testing framework. // Don't forget gtest.h, which declares the testing framework.
#include <limits.h>
#include "sample1.h" #include "sample1.h"
#include <limits.h>
#include "gtest/gtest.h" #include "gtest/gtest.h"
namespace { namespace {
...@@ -69,7 +70,6 @@ namespace { ...@@ -69,7 +70,6 @@ namespace {
// //
// </TechnicalDetails> // </TechnicalDetails>
// Tests Factorial(). // Tests Factorial().
// Tests factorial of negative numbers. // Tests factorial of negative numbers.
...@@ -97,9 +97,7 @@ TEST(FactorialTest, Negative) { ...@@ -97,9 +97,7 @@ TEST(FactorialTest, Negative) {
} }
// Tests factorial of 0. // Tests factorial of 0.
TEST(FactorialTest, Zero) { TEST(FactorialTest, Zero) { EXPECT_EQ(1, Factorial(0)); }
EXPECT_EQ(1, Factorial(0));
}
// Tests factorial of positive numbers. // Tests factorial of positive numbers.
TEST(FactorialTest, Positive) { TEST(FactorialTest, Positive) {
...@@ -109,7 +107,6 @@ TEST(FactorialTest, Positive) { ...@@ -109,7 +107,6 @@ TEST(FactorialTest, Positive) {
EXPECT_EQ(40320, Factorial(8)); EXPECT_EQ(40320, Factorial(8));
} }
// Tests IsPrime() // Tests IsPrime()
// Tests negative input. // Tests negative input.
......
...@@ -38,7 +38,7 @@ const char* MyString::CloneCString(const char* a_c_string) { ...@@ -38,7 +38,7 @@ const char* MyString::CloneCString(const char* a_c_string) {
if (a_c_string == nullptr) return nullptr; if (a_c_string == nullptr) return nullptr;
const size_t len = strlen(a_c_string); const size_t len = strlen(a_c_string);
char* const clone = new char[ len + 1 ]; char* const clone = new char[len + 1];
memcpy(clone, a_c_string, len + 1); memcpy(clone, a_c_string, len + 1);
return clone; return clone;
......
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
#include <string.h> #include <string.h>
// A simple string class. // A simple string class.
class MyString { class MyString {
private: private:
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
// needed. // needed.
#include "sample2.h" #include "sample2.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
namespace { namespace {
// In this example, we test the MyString class (a simple string). // In this example, we test the MyString class (a simple string).
...@@ -77,8 +78,7 @@ const char kHelloString[] = "Hello, world!"; ...@@ -77,8 +78,7 @@ const char kHelloString[] = "Hello, world!";
TEST(MyString, ConstructorFromCString) { TEST(MyString, ConstructorFromCString) {
const MyString s(kHelloString); const MyString s(kHelloString);
EXPECT_EQ(0, strcmp(s.c_string(), kHelloString)); EXPECT_EQ(0, strcmp(s.c_string(), kHelloString));
EXPECT_EQ(sizeof(kHelloString)/sizeof(kHelloString[0]) - 1, EXPECT_EQ(sizeof(kHelloString) / sizeof(kHelloString[0]) - 1, s.Length());
s.Length());
} }
// Tests the copy c'tor. // Tests the copy c'tor.
......
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
#include <stddef.h> #include <stddef.h>
// Queue is a simple queue implemented as a singled-linked list. // Queue is a simple queue implemented as a singled-linked list.
// //
// The element type must support copy constructor. // The element type must support copy constructor.
...@@ -62,7 +61,7 @@ class QueueNode { ...@@ -62,7 +61,7 @@ class QueueNode {
: element_(an_element), next_(nullptr) {} : element_(an_element), next_(nullptr) {}
// We disable the default assignment operator and copy c'tor. // We disable the default assignment operator and copy c'tor.
const QueueNode& operator = (const QueueNode&); const QueueNode& operator=(const QueueNode&);
QueueNode(const QueueNode&); QueueNode(const QueueNode&);
E element_; E element_;
...@@ -84,7 +83,7 @@ class Queue { ...@@ -84,7 +83,7 @@ class Queue {
// 1. Deletes every node. // 1. Deletes every node.
QueueNode<E>* node = head_; QueueNode<E>* node = head_;
QueueNode<E>* next = node->next(); QueueNode<E>* next = node->next();
for (; ;) { for (;;) {
delete node; delete node;
node = next; node = next;
if (node == nullptr) break; if (node == nullptr) break;
...@@ -162,11 +161,11 @@ class Queue { ...@@ -162,11 +161,11 @@ class Queue {
private: private:
QueueNode<E>* head_; // The first node of the queue. QueueNode<E>* head_; // The first node of the queue.
QueueNode<E>* last_; // The last node of the queue. QueueNode<E>* last_; // The last node of the queue.
size_t size_; // The number of elements in the queue. size_t size_; // The number of elements in the queue.
// We disallow copying a queue. // We disallow copying a queue.
Queue(const Queue&); Queue(const Queue&);
const Queue& operator = (const Queue&); const Queue& operator=(const Queue&);
}; };
#endif // GOOGLETEST_SAMPLES_SAMPLE3_INL_H_ #endif // GOOGLETEST_SAMPLES_SAMPLE3_INL_H_
...@@ -67,7 +67,6 @@ namespace { ...@@ -67,7 +67,6 @@ namespace {
class QueueTestSmpl3 : public testing::Test { class QueueTestSmpl3 : public testing::Test {
protected: // You should make the members protected s.t. they can be protected: // You should make the members protected s.t. they can be
// accessed from sub-classes. // accessed from sub-classes.
// virtual void SetUp() will be called before each test is run. You // virtual void SetUp() will be called before each test is run. You
// should define it if you need to initialize the variables. // should define it if you need to initialize the variables.
// Otherwise, this can be skipped. // Otherwise, this can be skipped.
...@@ -85,15 +84,13 @@ class QueueTestSmpl3 : public testing::Test { ...@@ -85,15 +84,13 @@ class QueueTestSmpl3 : public testing::Test {
// } // }
// A helper function that some test uses. // A helper function that some test uses.
static int Double(int n) { static int Double(int n) { return 2 * n; }
return 2*n;
}
// A helper function for testing Queue::Map(). // A helper function for testing Queue::Map().
void MapTester(const Queue<int> * q) { void MapTester(const Queue<int>* q) {
// Creates a new queue, where each element is twice as big as the // Creates a new queue, where each element is twice as big as the
// corresponding one in q. // corresponding one in q.
const Queue<int> * const new_q = q->Map(Double); const Queue<int>* const new_q = q->Map(Double);
// Verifies that the new queue has the same size as q. // Verifies that the new queue has the same size as q.
ASSERT_EQ(q->Size(), new_q->Size()); ASSERT_EQ(q->Size(), new_q->Size());
...@@ -124,7 +121,7 @@ TEST_F(QueueTestSmpl3, DefaultConstructor) { ...@@ -124,7 +121,7 @@ TEST_F(QueueTestSmpl3, DefaultConstructor) {
// Tests Dequeue(). // Tests Dequeue().
TEST_F(QueueTestSmpl3, Dequeue) { TEST_F(QueueTestSmpl3, Dequeue) {
int * n = q0_.Dequeue(); int* n = q0_.Dequeue();
EXPECT_TRUE(n == nullptr); EXPECT_TRUE(n == nullptr);
n = q1_.Dequeue(); n = q1_.Dequeue();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment