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
...@@ -39,42 +39,42 @@ ...@@ -39,42 +39,42 @@
// This macro defines 10 dummy tests. // This macro defines 10 dummy tests.
#define TEN_TESTS_(test_case_name) \ #define TEN_TESTS_(test_case_name) \
TEST(test_case_name, T0) {} \ TEST(test_case_name, T0) {} \
TEST(test_case_name, T1) {} \ TEST(test_case_name, T1) {} \
TEST(test_case_name, T2) {} \ TEST(test_case_name, T2) {} \
TEST(test_case_name, T3) {} \ TEST(test_case_name, T3) {} \
TEST(test_case_name, T4) {} \ TEST(test_case_name, T4) {} \
TEST(test_case_name, T5) {} \ TEST(test_case_name, T5) {} \
TEST(test_case_name, T6) {} \ TEST(test_case_name, T6) {} \
TEST(test_case_name, T7) {} \ TEST(test_case_name, T7) {} \
TEST(test_case_name, T8) {} \ TEST(test_case_name, T8) {} \
TEST(test_case_name, T9) {} TEST(test_case_name, T9) {}
// This macro defines 100 dummy tests. // This macro defines 100 dummy tests.
#define HUNDRED_TESTS_(test_case_name_prefix) \ #define HUNDRED_TESTS_(test_case_name_prefix) \
TEN_TESTS_(test_case_name_prefix ## 0) \ TEN_TESTS_(test_case_name_prefix##0) \
TEN_TESTS_(test_case_name_prefix ## 1) \ TEN_TESTS_(test_case_name_prefix##1) \
TEN_TESTS_(test_case_name_prefix ## 2) \ TEN_TESTS_(test_case_name_prefix##2) \
TEN_TESTS_(test_case_name_prefix ## 3) \ TEN_TESTS_(test_case_name_prefix##3) \
TEN_TESTS_(test_case_name_prefix ## 4) \ TEN_TESTS_(test_case_name_prefix##4) \
TEN_TESTS_(test_case_name_prefix ## 5) \ TEN_TESTS_(test_case_name_prefix##5) \
TEN_TESTS_(test_case_name_prefix ## 6) \ TEN_TESTS_(test_case_name_prefix##6) \
TEN_TESTS_(test_case_name_prefix ## 7) \ TEN_TESTS_(test_case_name_prefix##7) \
TEN_TESTS_(test_case_name_prefix ## 8) \ TEN_TESTS_(test_case_name_prefix##8) \
TEN_TESTS_(test_case_name_prefix ## 9) TEN_TESTS_(test_case_name_prefix##9)
// This macro defines 1000 dummy tests. // This macro defines 1000 dummy tests.
#define THOUSAND_TESTS_(test_case_name_prefix) \ #define THOUSAND_TESTS_(test_case_name_prefix) \
HUNDRED_TESTS_(test_case_name_prefix ## 0) \ HUNDRED_TESTS_(test_case_name_prefix##0) \
HUNDRED_TESTS_(test_case_name_prefix ## 1) \ HUNDRED_TESTS_(test_case_name_prefix##1) \
HUNDRED_TESTS_(test_case_name_prefix ## 2) \ HUNDRED_TESTS_(test_case_name_prefix##2) \
HUNDRED_TESTS_(test_case_name_prefix ## 3) \ HUNDRED_TESTS_(test_case_name_prefix##3) \
HUNDRED_TESTS_(test_case_name_prefix ## 4) \ HUNDRED_TESTS_(test_case_name_prefix##4) \
HUNDRED_TESTS_(test_case_name_prefix ## 5) \ HUNDRED_TESTS_(test_case_name_prefix##5) \
HUNDRED_TESTS_(test_case_name_prefix ## 6) \ HUNDRED_TESTS_(test_case_name_prefix##6) \
HUNDRED_TESTS_(test_case_name_prefix ## 7) \ HUNDRED_TESTS_(test_case_name_prefix##7) \
HUNDRED_TESTS_(test_case_name_prefix ## 8) \ HUNDRED_TESTS_(test_case_name_prefix##8) \
HUNDRED_TESTS_(test_case_name_prefix ## 9) HUNDRED_TESTS_(test_case_name_prefix##9)
// Ensures that we can define 1000 TEST()s in the same translation // Ensures that we can define 1000 TEST()s in the same translation
// unit. // unit.
......
...@@ -27,7 +27,6 @@ ...@@ -27,7 +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 program is meant to be run by gtest_test_filter_test.py. Do not run // This program is meant to be run by gtest_test_filter_test.py. Do not run
// it directly. // it directly.
......
...@@ -27,16 +27,16 @@ ...@@ -27,16 +27,16 @@
// (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.
// Tests Google Test's throw-on-failure mode with exceptions enabled. // Tests Google Test's throw-on-failure mode with exceptions enabled.
#include "gtest/gtest.h"
#include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdexcept> #include <stdexcept>
#include "gtest/gtest.h"
// Prints the given failure message and exits the program with // Prints the given failure message and exits the program with
// non-zero. We use this instead of a Google Test assertion to // non-zero. We use this instead of a Google Test assertion to
// indicate a failure, as the latter is been tested and cannot be // indicate a failure, as the latter is been tested and cannot be
...@@ -55,14 +55,14 @@ void TestFailureThrowsRuntimeError() { ...@@ -55,14 +55,14 @@ void TestFailureThrowsRuntimeError() {
// A successful assertion shouldn't throw. // A successful assertion shouldn't throw.
try { try {
EXPECT_EQ(3, 3); EXPECT_EQ(3, 3);
} catch(...) { } catch (...) {
Fail("A successful assertion wrongfully threw."); Fail("A successful assertion wrongfully threw.");
} }
// A failed assertion should throw a subclass of std::runtime_error. // A failed assertion should throw a subclass of std::runtime_error.
try { try {
EXPECT_EQ(2, 3) << "Expected failure"; EXPECT_EQ(2, 3) << "Expected failure";
} catch(const std::runtime_error& e) { } catch (const std::runtime_error& e) {
if (strstr(e.what(), "Expected failure") != nullptr) return; if (strstr(e.what(), "Expected failure") != nullptr) return;
printf("%s", printf("%s",
...@@ -70,7 +70,7 @@ void TestFailureThrowsRuntimeError() { ...@@ -70,7 +70,7 @@ void TestFailureThrowsRuntimeError() {
"but the message is incorrect. Instead of containing \"Expected " "but the message is incorrect. Instead of containing \"Expected "
"failure\", it is:\n"); "failure\", it is:\n");
Fail(e.what()); Fail(e.what());
} catch(...) { } catch (...) {
Fail("A failed assertion threw the wrong type of exception."); Fail("A failed assertion threw the wrong type of exception.");
} }
Fail("A failed assertion should've thrown but didn't."); Fail("A failed assertion should've thrown but didn't.");
......
...@@ -137,8 +137,8 @@ TEST_F(StreamingListenerTest, OnTestEnd) { ...@@ -137,8 +137,8 @@ TEST_F(StreamingListenerTest, OnTestEnd) {
TEST_F(StreamingListenerTest, OnTestPartResult) { TEST_F(StreamingListenerTest, OnTestPartResult) {
*output() = ""; *output() = "";
streamer_.OnTestPartResult(TestPartResult( streamer_.OnTestPartResult(TestPartResult(TestPartResult::kFatalFailure,
TestPartResult::kFatalFailure, "foo.cc", 42, "failed=\n&%")); "foo.cc", 42, "failed=\n&%"));
// Meta characters in the failure message should be properly escaped. // Meta characters in the failure message should be properly escaped.
EXPECT_EQ( EXPECT_EQ(
...@@ -272,11 +272,9 @@ using testing::internal::GetCapturedStdout; ...@@ -272,11 +272,9 @@ using testing::internal::GetCapturedStdout;
using testing::internal::ThreadWithParam; using testing::internal::ThreadWithParam;
#endif #endif
class TestingVector : public std::vector<int> { class TestingVector : public std::vector<int> {};
};
::std::ostream& operator<<(::std::ostream& os, ::std::ostream& operator<<(::std::ostream& os, const TestingVector& vector) {
const TestingVector& vector) {
os << "{ "; os << "{ ";
for (size_t i = 0; i < vector.size(); i++) { for (size_t i = 0; i < vector.size(); i++) {
os << vector[i] << " "; os << vector[i] << " ";
...@@ -420,8 +418,7 @@ class FormatEpochTimeInMillisAsIso8601Test : public Test { ...@@ -420,8 +418,7 @@ class FormatEpochTimeInMillisAsIso8601Test : public Test {
saved_tz_ = nullptr; saved_tz_ = nullptr;
GTEST_DISABLE_MSC_DEPRECATED_PUSH_(/* getenv, strdup: deprecated */) GTEST_DISABLE_MSC_DEPRECATED_PUSH_(/* getenv, strdup: deprecated */)
if (getenv("TZ")) if (getenv("TZ")) saved_tz_ = strdup(getenv("TZ"));
saved_tz_ = strdup(getenv("TZ"));
GTEST_DISABLE_MSC_DEPRECATED_POP_() GTEST_DISABLE_MSC_DEPRECATED_POP_()
// Set up the time zone for FormatEpochTimeInMillisAsIso8601 to use. We // Set up the time zone for FormatEpochTimeInMillisAsIso8601 to use. We
...@@ -476,9 +473,8 @@ TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsTwoDigitSegments) { ...@@ -476,9 +473,8 @@ TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsTwoDigitSegments) {
} }
TEST_F(FormatEpochTimeInMillisAsIso8601Test, IncludesMillisecondsAfterDot) { TEST_F(FormatEpochTimeInMillisAsIso8601Test, IncludesMillisecondsAfterDot) {
EXPECT_EQ( EXPECT_EQ("2011-10-31T18:52:42.234",
"2011-10-31T18:52:42.234", FormatEpochTimeInMillisAsIso8601(1320087162 * kMillisPerSec + 234));
FormatEpochTimeInMillisAsIso8601(1320087162 * kMillisPerSec + 234));
} }
TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsLeadingZeroes) { TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsLeadingZeroes) {
...@@ -495,10 +491,10 @@ TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsEpochStart) { ...@@ -495,10 +491,10 @@ TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsEpochStart) {
EXPECT_EQ("1970-01-01T00:00:00.000", FormatEpochTimeInMillisAsIso8601(0)); EXPECT_EQ("1970-01-01T00:00:00.000", FormatEpochTimeInMillisAsIso8601(0));
} }
# ifdef __BORLANDC__ #ifdef __BORLANDC__
// Silences warnings: "Condition is always true", "Unreachable code" // Silences warnings: "Condition is always true", "Unreachable code"
# pragma option push -w-ccc -w-rch #pragma option push -w-ccc -w-rch
# endif #endif
// Tests that the LHS of EXPECT_EQ or ASSERT_EQ can be used as a null literal // Tests that the LHS of EXPECT_EQ or ASSERT_EQ can be used as a null literal
// when the RHS is a pointer type. // when the RHS is a pointer type.
...@@ -572,10 +568,10 @@ TEST(NullLiteralTest, NoConversionNoWarning) { ...@@ -572,10 +568,10 @@ TEST(NullLiteralTest, NoConversionNoWarning) {
#pragma clang diagnostic pop #pragma clang diagnostic pop
#endif #endif
# ifdef __BORLANDC__ #ifdef __BORLANDC__
// Restores warnings after previous "#pragma option push" suppressed them. // Restores warnings after previous "#pragma option push" suppressed them.
# pragma option pop #pragma option pop
# endif #endif
// //
// Tests CodePointToUtf8(). // Tests CodePointToUtf8().
...@@ -603,20 +599,17 @@ TEST(CodePointToUtf8Test, CanEncode8To11Bits) { ...@@ -603,20 +599,17 @@ TEST(CodePointToUtf8Test, CanEncode8To11Bits) {
// Some compilers (e.g., GCC on MinGW) cannot handle non-ASCII codepoints // Some compilers (e.g., GCC on MinGW) cannot handle non-ASCII codepoints
// in wide strings and wide chars. In order to accommodate them, we have to // in wide strings and wide chars. In order to accommodate them, we have to
// introduce such character constants as integers. // introduce such character constants as integers.
EXPECT_EQ("\xD5\xB6", EXPECT_EQ("\xD5\xB6", CodePointToUtf8(static_cast<wchar_t>(0x576)));
CodePointToUtf8(static_cast<wchar_t>(0x576)));
} }
// Tests that Unicode code-points that have 12 to 16 bits are encoded // Tests that Unicode code-points that have 12 to 16 bits are encoded
// as 1110xxxx 10xxxxxx 10xxxxxx. // as 1110xxxx 10xxxxxx 10xxxxxx.
TEST(CodePointToUtf8Test, CanEncode12To16Bits) { TEST(CodePointToUtf8Test, CanEncode12To16Bits) {
// 0000 1000 1101 0011 => 1110-0000 10-100011 10-010011 // 0000 1000 1101 0011 => 1110-0000 10-100011 10-010011
EXPECT_EQ("\xE0\xA3\x93", EXPECT_EQ("\xE0\xA3\x93", CodePointToUtf8(static_cast<wchar_t>(0x8D3)));
CodePointToUtf8(static_cast<wchar_t>(0x8D3)));
// 1100 0111 0100 1101 => 1110-1100 10-011101 10-001101 // 1100 0111 0100 1101 => 1110-1100 10-011101 10-001101
EXPECT_EQ("\xEC\x9D\x8D", EXPECT_EQ("\xEC\x9D\x8D", CodePointToUtf8(static_cast<wchar_t>(0xC74D)));
CodePointToUtf8(static_cast<wchar_t>(0xC74D)));
} }
#if !GTEST_WIDE_STRING_USES_UTF16_ #if !GTEST_WIDE_STRING_USES_UTF16_
...@@ -668,7 +661,7 @@ TEST(WideStringToUtf8Test, CanEncode8To11Bits) { ...@@ -668,7 +661,7 @@ TEST(WideStringToUtf8Test, CanEncode8To11Bits) {
EXPECT_STREQ("\xC3\x93", WideStringToUtf8(L"\xD3", -1).c_str()); EXPECT_STREQ("\xC3\x93", WideStringToUtf8(L"\xD3", -1).c_str());
// 101 0111 0110 => 110-10101 10-110110 // 101 0111 0110 => 110-10101 10-110110
const wchar_t s[] = { 0x576, '\0' }; const wchar_t s[] = {0x576, '\0'};
EXPECT_STREQ("\xD5\xB6", WideStringToUtf8(s, 1).c_str()); EXPECT_STREQ("\xD5\xB6", WideStringToUtf8(s, 1).c_str());
EXPECT_STREQ("\xD5\xB6", WideStringToUtf8(s, -1).c_str()); EXPECT_STREQ("\xD5\xB6", WideStringToUtf8(s, -1).c_str());
} }
...@@ -677,12 +670,12 @@ TEST(WideStringToUtf8Test, CanEncode8To11Bits) { ...@@ -677,12 +670,12 @@ TEST(WideStringToUtf8Test, CanEncode8To11Bits) {
// as 1110xxxx 10xxxxxx 10xxxxxx. // as 1110xxxx 10xxxxxx 10xxxxxx.
TEST(WideStringToUtf8Test, CanEncode12To16Bits) { TEST(WideStringToUtf8Test, CanEncode12To16Bits) {
// 0000 1000 1101 0011 => 1110-0000 10-100011 10-010011 // 0000 1000 1101 0011 => 1110-0000 10-100011 10-010011
const wchar_t s1[] = { 0x8D3, '\0' }; const wchar_t s1[] = {0x8D3, '\0'};
EXPECT_STREQ("\xE0\xA3\x93", WideStringToUtf8(s1, 1).c_str()); EXPECT_STREQ("\xE0\xA3\x93", WideStringToUtf8(s1, 1).c_str());
EXPECT_STREQ("\xE0\xA3\x93", WideStringToUtf8(s1, -1).c_str()); EXPECT_STREQ("\xE0\xA3\x93", WideStringToUtf8(s1, -1).c_str());
// 1100 0111 0100 1101 => 1110-1100 10-011101 10-001101 // 1100 0111 0100 1101 => 1110-1100 10-011101 10-001101
const wchar_t s2[] = { 0xC74D, '\0' }; const wchar_t s2[] = {0xC74D, '\0'};
EXPECT_STREQ("\xEC\x9D\x8D", WideStringToUtf8(s2, 1).c_str()); EXPECT_STREQ("\xEC\x9D\x8D", WideStringToUtf8(s2, 1).c_str());
EXPECT_STREQ("\xEC\x9D\x8D", WideStringToUtf8(s2, -1).c_str()); EXPECT_STREQ("\xEC\x9D\x8D", WideStringToUtf8(s2, -1).c_str());
} }
...@@ -717,11 +710,11 @@ TEST(WideStringToUtf8Test, CanEncodeInvalidCodePoint) { ...@@ -717,11 +710,11 @@ TEST(WideStringToUtf8Test, CanEncodeInvalidCodePoint) {
EXPECT_STREQ("(Invalid Unicode 0xABCDFF)", EXPECT_STREQ("(Invalid Unicode 0xABCDFF)",
WideStringToUtf8(L"\xABCDFF", -1).c_str()); WideStringToUtf8(L"\xABCDFF", -1).c_str());
} }
#else // !GTEST_WIDE_STRING_USES_UTF16_ #else // !GTEST_WIDE_STRING_USES_UTF16_
// Tests that surrogate pairs are encoded correctly on the systems using // Tests that surrogate pairs are encoded correctly on the systems using
// UTF-16 encoding in the wide strings. // UTF-16 encoding in the wide strings.
TEST(WideStringToUtf8Test, CanEncodeValidUtf16SUrrogatePairs) { TEST(WideStringToUtf8Test, CanEncodeValidUtf16SUrrogatePairs) {
const wchar_t s[] = { 0xD801, 0xDC00, '\0' }; const wchar_t s[] = {0xD801, 0xDC00, '\0'};
EXPECT_STREQ("\xF0\x90\x90\x80", WideStringToUtf8(s, -1).c_str()); EXPECT_STREQ("\xF0\x90\x90\x80", WideStringToUtf8(s, -1).c_str());
} }
...@@ -729,13 +722,13 @@ TEST(WideStringToUtf8Test, CanEncodeValidUtf16SUrrogatePairs) { ...@@ -729,13 +722,13 @@ TEST(WideStringToUtf8Test, CanEncodeValidUtf16SUrrogatePairs) {
// generates the expected result. // generates the expected result.
TEST(WideStringToUtf8Test, CanEncodeInvalidUtf16SurrogatePair) { TEST(WideStringToUtf8Test, CanEncodeInvalidUtf16SurrogatePair) {
// Leading surrogate is at the end of the string. // Leading surrogate is at the end of the string.
const wchar_t s1[] = { 0xD800, '\0' }; const wchar_t s1[] = {0xD800, '\0'};
EXPECT_STREQ("\xED\xA0\x80", WideStringToUtf8(s1, -1).c_str()); EXPECT_STREQ("\xED\xA0\x80", WideStringToUtf8(s1, -1).c_str());
// Leading surrogate is not followed by the trailing surrogate. // Leading surrogate is not followed by the trailing surrogate.
const wchar_t s2[] = { 0xD800, 'M', '\0' }; const wchar_t s2[] = {0xD800, 'M', '\0'};
EXPECT_STREQ("\xED\xA0\x80M", WideStringToUtf8(s2, -1).c_str()); EXPECT_STREQ("\xED\xA0\x80M", WideStringToUtf8(s2, -1).c_str());
// Trailing surrogate appearas without a leading surrogate. // Trailing surrogate appearas without a leading surrogate.
const wchar_t s3[] = { 0xDC00, 'P', 'Q', 'R', '\0' }; const wchar_t s3[] = {0xDC00, 'P', 'Q', 'R', '\0'};
EXPECT_STREQ("\xED\xB0\x80PQR", WideStringToUtf8(s3, -1).c_str()); EXPECT_STREQ("\xED\xB0\x80PQR", WideStringToUtf8(s3, -1).c_str());
} }
#endif // !GTEST_WIDE_STRING_USES_UTF16_ #endif // !GTEST_WIDE_STRING_USES_UTF16_
...@@ -743,21 +736,24 @@ TEST(WideStringToUtf8Test, CanEncodeInvalidUtf16SurrogatePair) { ...@@ -743,21 +736,24 @@ TEST(WideStringToUtf8Test, CanEncodeInvalidUtf16SurrogatePair) {
// Tests that codepoint concatenation works correctly. // Tests that codepoint concatenation works correctly.
#if !GTEST_WIDE_STRING_USES_UTF16_ #if !GTEST_WIDE_STRING_USES_UTF16_
TEST(WideStringToUtf8Test, ConcatenatesCodepointsCorrectly) { TEST(WideStringToUtf8Test, ConcatenatesCodepointsCorrectly) {
const wchar_t s[] = { 0x108634, 0xC74D, '\n', 0x576, 0x8D3, 0x108634, '\0'}; const wchar_t s[] = {0x108634, 0xC74D, '\n', 0x576, 0x8D3, 0x108634, '\0'};
EXPECT_STREQ( EXPECT_STREQ(
"\xF4\x88\x98\xB4" "\xF4\x88\x98\xB4"
"\xEC\x9D\x8D" "\xEC\x9D\x8D"
"\n" "\n"
"\xD5\xB6" "\xD5\xB6"
"\xE0\xA3\x93" "\xE0\xA3\x93"
"\xF4\x88\x98\xB4", "\xF4\x88\x98\xB4",
WideStringToUtf8(s, -1).c_str()); WideStringToUtf8(s, -1).c_str());
} }
#else #else
TEST(WideStringToUtf8Test, ConcatenatesCodepointsCorrectly) { TEST(WideStringToUtf8Test, ConcatenatesCodepointsCorrectly) {
const wchar_t s[] = { 0xC74D, '\n', 0x576, 0x8D3, '\0'}; const wchar_t s[] = {0xC74D, '\n', 0x576, 0x8D3, '\0'};
EXPECT_STREQ( EXPECT_STREQ(
"\xEC\x9D\x8D" "\n" "\xD5\xB6" "\xE0\xA3\x93", "\xEC\x9D\x8D"
"\n"
"\xD5\xB6"
"\xE0\xA3\x93",
WideStringToUtf8(s, -1).c_str()); WideStringToUtf8(s, -1).c_str());
} }
#endif // !GTEST_WIDE_STRING_USES_UTF16_ #endif // !GTEST_WIDE_STRING_USES_UTF16_
...@@ -766,9 +762,8 @@ TEST(WideStringToUtf8Test, ConcatenatesCodepointsCorrectly) { ...@@ -766,9 +762,8 @@ TEST(WideStringToUtf8Test, ConcatenatesCodepointsCorrectly) {
TEST(RandomDeathTest, GeneratesCrashesOnInvalidRange) { TEST(RandomDeathTest, GeneratesCrashesOnInvalidRange) {
testing::internal::Random random(42); testing::internal::Random random(42);
EXPECT_DEATH_IF_SUPPORTED( EXPECT_DEATH_IF_SUPPORTED(random.Generate(0),
random.Generate(0), "Cannot generate a number in the range \\[0, 0\\)");
"Cannot generate a number in the range \\[0, 0\\)");
EXPECT_DEATH_IF_SUPPORTED( EXPECT_DEATH_IF_SUPPORTED(
random.Generate(testing::internal::Random::kMaxRange + 1), random.Generate(testing::internal::Random::kMaxRange + 1),
"Generation of a number in \\[0, 2147483649\\) was requested, " "Generation of a number in \\[0, 2147483649\\) was requested, "
...@@ -897,7 +892,7 @@ class VectorShuffleTest : public Test { ...@@ -897,7 +892,7 @@ class VectorShuffleTest : public Test {
return true; return true;
} }
bool found_in_vector[kVectorSize] = { false }; bool found_in_vector[kVectorSize] = {false};
for (size_t i = 0; i < vector.size(); i++) { for (size_t i = 0; i < vector.size(); i++) {
const int e = vector[i]; const int e = vector[i];
if (e < 0 || e >= static_cast<int>(kVectorSize) || found_in_vector[e]) { if (e < 0 || e >= static_cast<int>(kVectorSize) || found_in_vector[e]) {
...@@ -924,8 +919,8 @@ class VectorShuffleTest : public Test { ...@@ -924,8 +919,8 @@ class VectorShuffleTest : public Test {
return false; return false;
} }
static bool RangeIsUnshuffled( static bool RangeIsUnshuffled(const TestingVector& vector, int begin,
const TestingVector& vector, int begin, int end) { int end) {
return !RangeIsShuffled(vector, begin, end); return !RangeIsShuffled(vector, begin, end);
} }
...@@ -950,7 +945,7 @@ TEST_F(VectorShuffleTest, HandlesEmptyRange) { ...@@ -950,7 +945,7 @@ TEST_F(VectorShuffleTest, HandlesEmptyRange) {
ASSERT_PRED1(VectorIsUnshuffled, vector_); ASSERT_PRED1(VectorIsUnshuffled, vector_);
// ...in the middle... // ...in the middle...
ShuffleRange(&random_, kVectorSize/2, kVectorSize/2, &vector_); ShuffleRange(&random_, kVectorSize / 2, kVectorSize / 2, &vector_);
ASSERT_PRED1(VectorIsNotCorrupt, vector_); ASSERT_PRED1(VectorIsNotCorrupt, vector_);
ASSERT_PRED1(VectorIsUnshuffled, vector_); ASSERT_PRED1(VectorIsUnshuffled, vector_);
...@@ -972,7 +967,7 @@ TEST_F(VectorShuffleTest, HandlesRangeOfSizeOne) { ...@@ -972,7 +967,7 @@ TEST_F(VectorShuffleTest, HandlesRangeOfSizeOne) {
ASSERT_PRED1(VectorIsUnshuffled, vector_); ASSERT_PRED1(VectorIsUnshuffled, vector_);
// ...in the middle... // ...in the middle...
ShuffleRange(&random_, kVectorSize/2, kVectorSize/2 + 1, &vector_); ShuffleRange(&random_, kVectorSize / 2, kVectorSize / 2 + 1, &vector_);
ASSERT_PRED1(VectorIsNotCorrupt, vector_); ASSERT_PRED1(VectorIsNotCorrupt, vector_);
ASSERT_PRED1(VectorIsUnshuffled, vector_); ASSERT_PRED1(VectorIsUnshuffled, vector_);
...@@ -997,7 +992,7 @@ TEST_F(VectorShuffleTest, ShufflesEntireVector) { ...@@ -997,7 +992,7 @@ TEST_F(VectorShuffleTest, ShufflesEntireVector) {
} }
TEST_F(VectorShuffleTest, ShufflesStartOfVector) { TEST_F(VectorShuffleTest, ShufflesStartOfVector) {
const int kRangeSize = kVectorSize/2; const int kRangeSize = kVectorSize / 2;
ShuffleRange(&random_, 0, kRangeSize, &vector_); ShuffleRange(&random_, 0, kRangeSize, &vector_);
...@@ -1019,11 +1014,11 @@ TEST_F(VectorShuffleTest, ShufflesEndOfVector) { ...@@ -1019,11 +1014,11 @@ TEST_F(VectorShuffleTest, ShufflesEndOfVector) {
TEST_F(VectorShuffleTest, ShufflesMiddleOfVector) { TEST_F(VectorShuffleTest, ShufflesMiddleOfVector) {
const int kRangeSize = static_cast<int>(kVectorSize) / 3; const int kRangeSize = static_cast<int>(kVectorSize) / 3;
ShuffleRange(&random_, kRangeSize, 2*kRangeSize, &vector_); ShuffleRange(&random_, kRangeSize, 2 * kRangeSize, &vector_);
ASSERT_PRED1(VectorIsNotCorrupt, vector_); ASSERT_PRED1(VectorIsNotCorrupt, vector_);
EXPECT_PRED3(RangeIsUnshuffled, vector_, 0, kRangeSize); EXPECT_PRED3(RangeIsUnshuffled, vector_, 0, kRangeSize);
EXPECT_PRED3(RangeIsShuffled, vector_, kRangeSize, 2*kRangeSize); EXPECT_PRED3(RangeIsShuffled, vector_, kRangeSize, 2 * kRangeSize);
EXPECT_PRED3(RangeIsUnshuffled, vector_, 2 * kRangeSize, EXPECT_PRED3(RangeIsUnshuffled, vector_, 2 * kRangeSize,
static_cast<int>(kVectorSize)); static_cast<int>(kVectorSize));
} }
...@@ -1088,13 +1083,12 @@ TEST(StringTest, CaseInsensitiveWideCStringEquals) { ...@@ -1088,13 +1083,12 @@ TEST(StringTest, CaseInsensitiveWideCStringEquals) {
// Tests String::ShowWideCString(). // Tests String::ShowWideCString().
TEST(StringTest, ShowWideCString) { TEST(StringTest, ShowWideCString) {
EXPECT_STREQ("(null)", EXPECT_STREQ("(null)", String::ShowWideCString(NULL).c_str());
String::ShowWideCString(NULL).c_str());
EXPECT_STREQ("", String::ShowWideCString(L"").c_str()); EXPECT_STREQ("", String::ShowWideCString(L"").c_str());
EXPECT_STREQ("foo", String::ShowWideCString(L"foo").c_str()); EXPECT_STREQ("foo", String::ShowWideCString(L"foo").c_str());
} }
# if GTEST_OS_WINDOWS_MOBILE #if GTEST_OS_WINDOWS_MOBILE
TEST(StringTest, AnsiAndUtf16Null) { TEST(StringTest, AnsiAndUtf16Null) {
EXPECT_EQ(NULL, String::AnsiToUtf16(NULL)); EXPECT_EQ(NULL, String::AnsiToUtf16(NULL));
EXPECT_EQ(NULL, String::Utf16ToAnsi(NULL)); EXPECT_EQ(NULL, String::Utf16ToAnsi(NULL));
...@@ -1103,21 +1097,21 @@ TEST(StringTest, AnsiAndUtf16Null) { ...@@ -1103,21 +1097,21 @@ TEST(StringTest, AnsiAndUtf16Null) {
TEST(StringTest, AnsiAndUtf16ConvertBasic) { TEST(StringTest, AnsiAndUtf16ConvertBasic) {
const char* ansi = String::Utf16ToAnsi(L"str"); const char* ansi = String::Utf16ToAnsi(L"str");
EXPECT_STREQ("str", ansi); EXPECT_STREQ("str", ansi);
delete [] ansi; delete[] ansi;
const WCHAR* utf16 = String::AnsiToUtf16("str"); const WCHAR* utf16 = String::AnsiToUtf16("str");
EXPECT_EQ(0, wcsncmp(L"str", utf16, 3)); EXPECT_EQ(0, wcsncmp(L"str", utf16, 3));
delete [] utf16; delete[] utf16;
} }
TEST(StringTest, AnsiAndUtf16ConvertPathChars) { TEST(StringTest, AnsiAndUtf16ConvertPathChars) {
const char* ansi = String::Utf16ToAnsi(L".:\\ \"*?"); const char* ansi = String::Utf16ToAnsi(L".:\\ \"*?");
EXPECT_STREQ(".:\\ \"*?", ansi); EXPECT_STREQ(".:\\ \"*?", ansi);
delete [] ansi; delete[] ansi;
const WCHAR* utf16 = String::AnsiToUtf16(".:\\ \"*?"); const WCHAR* utf16 = String::AnsiToUtf16(".:\\ \"*?");
EXPECT_EQ(0, wcsncmp(L".:\\ \"*?", utf16, 3)); EXPECT_EQ(0, wcsncmp(L".:\\ \"*?", utf16, 3));
delete [] utf16; delete[] utf16;
} }
# endif // GTEST_OS_WINDOWS_MOBILE #endif // GTEST_OS_WINDOWS_MOBILE
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
...@@ -1139,9 +1133,7 @@ TEST(TestPropertyTest, ReplaceStringValue) { ...@@ -1139,9 +1133,7 @@ TEST(TestPropertyTest, ReplaceStringValue) {
// AddFatalFailure() and AddNonfatalFailure() must be stand-alone // AddFatalFailure() and AddNonfatalFailure() must be stand-alone
// functions (i.e. their definitions cannot be inlined at the call // functions (i.e. their definitions cannot be inlined at the call
// sites), or C++Builder won't compile the code. // sites), or C++Builder won't compile the code.
static void AddFatalFailure() { static void AddFatalFailure() { FAIL() << "Expected fatal failure."; }
FAIL() << "Expected fatal failure.";
}
static void AddNonfatalFailure() { static void AddNonfatalFailure() {
ADD_FAILURE() << "Expected non-fatal failure."; ADD_FAILURE() << "Expected non-fatal failure.";
...@@ -1149,10 +1141,7 @@ static void AddNonfatalFailure() { ...@@ -1149,10 +1141,7 @@ static void AddNonfatalFailure() {
class ScopedFakeTestPartResultReporterTest : public Test { class ScopedFakeTestPartResultReporterTest : public Test {
public: // Must be public and not protected due to a bug in g++ 3.4.2. public: // Must be public and not protected due to a bug in g++ 3.4.2.
enum FailureMode { enum FailureMode { FATAL_FAILURE, NONFATAL_FAILURE };
FATAL_FAILURE,
NONFATAL_FAILURE
};
static void AddFailure(FailureMode failure) { static void AddFailure(FailureMode failure) {
if (failure == FATAL_FAILURE) { if (failure == FATAL_FAILURE) {
AddFatalFailure(); AddFatalFailure();
...@@ -1192,7 +1181,7 @@ TEST_F(ScopedFakeTestPartResultReporterTest, DeprecatedConstructor) { ...@@ -1192,7 +1181,7 @@ TEST_F(ScopedFakeTestPartResultReporterTest, DeprecatedConstructor) {
#if GTEST_IS_THREADSAFE #if GTEST_IS_THREADSAFE
class ScopedFakeTestPartResultReporterWithThreadsTest class ScopedFakeTestPartResultReporterWithThreadsTest
: public ScopedFakeTestPartResultReporterTest { : public ScopedFakeTestPartResultReporterTest {
protected: protected:
static void AddFailureInOtherThread(FailureMode failure) { static void AddFailureInOtherThread(FailureMode failure) {
ThreadWithParam<FailureMode> thread(&AddFailure, failure, nullptr); ThreadWithParam<FailureMode> thread(&AddFailure, failure, nullptr);
...@@ -1245,7 +1234,7 @@ TEST_F(ExpectFatalFailureTest, CatchesFatalFailureOnAllThreads) { ...@@ -1245,7 +1234,7 @@ TEST_F(ExpectFatalFailureTest, CatchesFatalFailureOnAllThreads) {
#ifdef __BORLANDC__ #ifdef __BORLANDC__
// Silences warnings: "Condition is always true" // Silences warnings: "Condition is always true"
# pragma option push -w-ccc #pragma option push -w-ccc
#endif #endif
// Tests that EXPECT_FATAL_FAILURE() can be used in a non-void // Tests that EXPECT_FATAL_FAILURE() can be used in a non-void
...@@ -1273,7 +1262,7 @@ void DoesNotAbortHelper(bool* aborted) { ...@@ -1273,7 +1262,7 @@ void DoesNotAbortHelper(bool* aborted) {
#ifdef __BORLANDC__ #ifdef __BORLANDC__
// Restores warnings after previous "#pragma option push" suppressed them. // Restores warnings after previous "#pragma option push" suppressed them.
# pragma option pop #pragma option pop
#endif #endif
TEST_F(ExpectFatalFailureTest, DoesNotAbort) { TEST_F(ExpectFatalFailureTest, DoesNotAbort) {
...@@ -1292,16 +1281,20 @@ static int global_var = 0; ...@@ -1292,16 +1281,20 @@ static int global_var = 0;
TEST_F(ExpectFatalFailureTest, AcceptsMacroThatExpandsToUnprotectedComma) { TEST_F(ExpectFatalFailureTest, AcceptsMacroThatExpandsToUnprotectedComma) {
#ifndef __BORLANDC__ #ifndef __BORLANDC__
// ICE's in C++Builder. // ICE's in C++Builder.
EXPECT_FATAL_FAILURE({ EXPECT_FATAL_FAILURE(
GTEST_USE_UNPROTECTED_COMMA_; {
AddFatalFailure(); GTEST_USE_UNPROTECTED_COMMA_;
}, ""); AddFatalFailure();
},
"");
#endif #endif
EXPECT_FATAL_FAILURE_ON_ALL_THREADS({ EXPECT_FATAL_FAILURE_ON_ALL_THREADS(
GTEST_USE_UNPROTECTED_COMMA_; {
AddFatalFailure(); GTEST_USE_UNPROTECTED_COMMA_;
}, ""); AddFatalFailure();
},
"");
} }
// Tests EXPECT_NONFATAL_FAILURE{,ON_ALL_THREADS}. // Tests EXPECT_NONFATAL_FAILURE{,ON_ALL_THREADS}.
...@@ -1309,8 +1302,7 @@ TEST_F(ExpectFatalFailureTest, AcceptsMacroThatExpandsToUnprotectedComma) { ...@@ -1309,8 +1302,7 @@ TEST_F(ExpectFatalFailureTest, AcceptsMacroThatExpandsToUnprotectedComma) {
typedef ScopedFakeTestPartResultReporterTest ExpectNonfatalFailureTest; typedef ScopedFakeTestPartResultReporterTest ExpectNonfatalFailureTest;
TEST_F(ExpectNonfatalFailureTest, CatchesNonfatalFailure) { TEST_F(ExpectNonfatalFailureTest, CatchesNonfatalFailure) {
EXPECT_NONFATAL_FAILURE(AddNonfatalFailure(), EXPECT_NONFATAL_FAILURE(AddNonfatalFailure(), "Expected non-fatal failure.");
"Expected non-fatal failure.");
} }
TEST_F(ExpectNonfatalFailureTest, AcceptsStdStringObject) { TEST_F(ExpectNonfatalFailureTest, AcceptsStdStringObject) {
...@@ -1329,15 +1321,19 @@ TEST_F(ExpectNonfatalFailureTest, CatchesNonfatalFailureOnAllThreads) { ...@@ -1329,15 +1321,19 @@ TEST_F(ExpectNonfatalFailureTest, CatchesNonfatalFailureOnAllThreads) {
// statement that contains a macro which expands to code containing an // statement that contains a macro which expands to code containing an
// unprotected comma. // unprotected comma.
TEST_F(ExpectNonfatalFailureTest, AcceptsMacroThatExpandsToUnprotectedComma) { TEST_F(ExpectNonfatalFailureTest, AcceptsMacroThatExpandsToUnprotectedComma) {
EXPECT_NONFATAL_FAILURE({ EXPECT_NONFATAL_FAILURE(
GTEST_USE_UNPROTECTED_COMMA_; {
AddNonfatalFailure(); GTEST_USE_UNPROTECTED_COMMA_;
}, ""); AddNonfatalFailure();
},
"");
EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS({ EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(
GTEST_USE_UNPROTECTED_COMMA_; {
AddNonfatalFailure(); GTEST_USE_UNPROTECTED_COMMA_;
}, ""); AddNonfatalFailure();
},
"");
} }
#if GTEST_IS_THREADSAFE #if GTEST_IS_THREADSAFE
...@@ -1381,21 +1377,18 @@ class TestResultTest : public Test { ...@@ -1381,21 +1377,18 @@ class TestResultTest : public Test {
typedef std::vector<TestPartResult> TPRVector; typedef std::vector<TestPartResult> TPRVector;
// We make use of 2 TestPartResult objects, // We make use of 2 TestPartResult objects,
TestPartResult * pr1, * pr2; TestPartResult *pr1, *pr2;
// ... and 3 TestResult objects. // ... and 3 TestResult objects.
TestResult * r0, * r1, * r2; TestResult *r0, *r1, *r2;
void SetUp() override { void SetUp() override {
// pr1 is for success. // pr1 is for success.
pr1 = new TestPartResult(TestPartResult::kSuccess, pr1 = new TestPartResult(TestPartResult::kSuccess, "foo/bar.cc", 10,
"foo/bar.cc",
10,
"Success!"); "Success!");
// pr2 is for fatal failure. // pr2 is for fatal failure.
pr2 = new TestPartResult(TestPartResult::kFatalFailure, pr2 = new TestPartResult(TestPartResult::kFatalFailure, "foo/bar.cc",
"foo/bar.cc",
-1, // This line number means "unknown" -1, // This line number means "unknown"
"Failure!"); "Failure!");
...@@ -1408,10 +1401,10 @@ class TestResultTest : public Test { ...@@ -1408,10 +1401,10 @@ class TestResultTest : public Test {
// state, in particular the TestPartResult vector it holds. // state, in particular the TestPartResult vector it holds.
// test_part_results() returns a const reference to this vector. // test_part_results() returns a const reference to this vector.
// We cast it to a non-const object s.t. it can be modified // We cast it to a non-const object s.t. it can be modified
TPRVector* results1 = const_cast<TPRVector*>( TPRVector* results1 =
&TestResultAccessor::test_part_results(*r1)); const_cast<TPRVector*>(&TestResultAccessor::test_part_results(*r1));
TPRVector* results2 = const_cast<TPRVector*>( TPRVector* results2 =
&TestResultAccessor::test_part_results(*r2)); const_cast<TPRVector*>(&TestResultAccessor::test_part_results(*r2));
// r0 is an empty TestResult. // r0 is an empty TestResult.
...@@ -1662,15 +1655,11 @@ GTestFlagSaver* GTestFlagSaverTest::saver_ = nullptr; ...@@ -1662,15 +1655,11 @@ GTestFlagSaver* GTestFlagSaverTest::saver_ = nullptr;
// tests are designed to work regardless of their order. // tests are designed to work regardless of their order.
// Modifies the Google Test flags in the test body. // Modifies the Google Test flags in the test body.
TEST_F(GTestFlagSaverTest, ModifyGTestFlags) { TEST_F(GTestFlagSaverTest, ModifyGTestFlags) { VerifyAndModifyFlags(); }
VerifyAndModifyFlags();
}
// Verifies that the Google Test flags in the body of the previous test were // Verifies that the Google Test flags in the body of the previous test were
// restored to their original values. // restored to their original values.
TEST_F(GTestFlagSaverTest, VerifyGTestFlags) { TEST_F(GTestFlagSaverTest, VerifyGTestFlags) { VerifyAndModifyFlags(); }
VerifyAndModifyFlags();
}
// Sets an environment variable with the given name to the given // Sets an environment variable with the given name to the given
// value. If the value argument is "", unsets the environment // value. If the value argument is "", unsets the environment
...@@ -1687,12 +1676,12 @@ static void SetEnv(const char* name, const char* value) { ...@@ -1687,12 +1676,12 @@ static void SetEnv(const char* name, const char* value) {
// Because putenv stores a pointer to the string buffer, we can't delete the // Because putenv stores a pointer to the string buffer, we can't delete the
// previous string (if present) until after it's replaced. // previous string (if present) until after it's replaced.
std::string *prev_env = NULL; std::string* prev_env = NULL;
if (added_env.find(name) != added_env.end()) { if (added_env.find(name) != added_env.end()) {
prev_env = added_env[name]; prev_env = added_env[name];
} }
added_env[name] = new std::string( added_env[name] =
(Message() << name << "=" << value).GetString()); new std::string((Message() << name << "=" << value).GetString());
// The standard signature of putenv accepts a 'char*' argument. Other // The standard signature of putenv accepts a 'char*' argument. Other
// implementations, like C++Builder's, accept a 'const char*'. // implementations, like C++Builder's, accept a 'const char*'.
...@@ -1724,7 +1713,7 @@ TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenVariableIsNotSet) { ...@@ -1724,7 +1713,7 @@ TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenVariableIsNotSet) {
EXPECT_EQ(10, Int32FromGTestEnv("temp", 10)); EXPECT_EQ(10, Int32FromGTestEnv("temp", 10));
} }
# if !defined(GTEST_GET_INT32_FROM_ENV_) #if !defined(GTEST_GET_INT32_FROM_ENV_)
// Tests that Int32FromGTestEnv() returns the default value when the // Tests that Int32FromGTestEnv() returns the default value when the
// environment variable overflows as an Int32. // environment variable overflows as an Int32.
...@@ -1750,7 +1739,7 @@ TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenValueIsInvalid) { ...@@ -1750,7 +1739,7 @@ TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenValueIsInvalid) {
EXPECT_EQ(50, Int32FromGTestEnv("temp", 50)); EXPECT_EQ(50, Int32FromGTestEnv("temp", 50));
} }
# endif // !defined(GTEST_GET_INT32_FROM_ENV_) #endif // !defined(GTEST_GET_INT32_FROM_ENV_)
// Tests that Int32FromGTestEnv() parses and returns the value of the // Tests that Int32FromGTestEnv() parses and returns the value of the
// environment variable when it represents a valid decimal integer in // environment variable when it represents a valid decimal integer in
...@@ -1834,8 +1823,7 @@ TEST(Int32FromEnvOrDieTest, ParsesAndReturnsValidValue) { ...@@ -1834,8 +1823,7 @@ TEST(Int32FromEnvOrDieTest, ParsesAndReturnsValidValue) {
TEST(Int32FromEnvOrDieDeathTest, AbortsOnFailure) { TEST(Int32FromEnvOrDieDeathTest, AbortsOnFailure) {
SetEnv(GTEST_FLAG_PREFIX_UPPER_ "VAR", "xxx"); SetEnv(GTEST_FLAG_PREFIX_UPPER_ "VAR", "xxx");
EXPECT_DEATH_IF_SUPPORTED( EXPECT_DEATH_IF_SUPPORTED(
Int32FromEnvOrDie(GTEST_FLAG_PREFIX_UPPER_ "VAR", 123), Int32FromEnvOrDie(GTEST_FLAG_PREFIX_UPPER_ "VAR", 123), ".*");
".*");
} }
// Tests that Int32FromEnvOrDie() aborts with an error message // Tests that Int32FromEnvOrDie() aborts with an error message
...@@ -1843,8 +1831,7 @@ TEST(Int32FromEnvOrDieDeathTest, AbortsOnFailure) { ...@@ -1843,8 +1831,7 @@ TEST(Int32FromEnvOrDieDeathTest, AbortsOnFailure) {
TEST(Int32FromEnvOrDieDeathTest, AbortsOnInt32Overflow) { TEST(Int32FromEnvOrDieDeathTest, AbortsOnInt32Overflow) {
SetEnv(GTEST_FLAG_PREFIX_UPPER_ "VAR", "1234567891234567891234"); SetEnv(GTEST_FLAG_PREFIX_UPPER_ "VAR", "1234567891234567891234");
EXPECT_DEATH_IF_SUPPORTED( EXPECT_DEATH_IF_SUPPORTED(
Int32FromEnvOrDie(GTEST_FLAG_PREFIX_UPPER_ "VAR", 123), Int32FromEnvOrDie(GTEST_FLAG_PREFIX_UPPER_ "VAR", 123), ".*");
".*");
} }
// Tests that ShouldRunTestOnShard() selects all tests // Tests that ShouldRunTestOnShard() selects all tests
...@@ -1951,7 +1938,8 @@ TEST(ShouldRunTestOnShardTest, IsPartitionWhenThereAreFiveShards) { ...@@ -1951,7 +1938,8 @@ TEST(ShouldRunTestOnShardTest, IsPartitionWhenThereAreFiveShards) {
prev_selected_shard_index = shard_index; prev_selected_shard_index = shard_index;
} else { } else {
ADD_FAILURE() << "Shard " << prev_selected_shard_index << " and " ADD_FAILURE() << "Shard " << prev_selected_shard_index << " and "
<< shard_index << " are both selected to run test " << test_id; << shard_index << " are both selected to run test "
<< test_id;
} }
} }
} }
...@@ -1963,7 +1951,7 @@ TEST(ShouldRunTestOnShardTest, IsPartitionWhenThereAreFiveShards) { ...@@ -1963,7 +1951,7 @@ TEST(ShouldRunTestOnShardTest, IsPartitionWhenThereAreFiveShards) {
int num_tests_on_shard = 0; int num_tests_on_shard = 0;
for (int test_id = 0; test_id < num_tests; test_id++) { for (int test_id = 0; test_id < num_tests; test_id++) {
num_tests_on_shard += num_tests_on_shard +=
ShouldRunTestOnShard(num_shards, shard_index, test_id); ShouldRunTestOnShard(num_shards, shard_index, test_id);
} }
EXPECT_GE(num_tests_on_shard, num_tests / num_shards); EXPECT_GE(num_tests_on_shard, num_tests / num_shards);
} }
...@@ -1995,8 +1983,8 @@ TEST(UnitTestTest, ReturnsPlausibleTimestamp) { ...@@ -1995,8 +1983,8 @@ TEST(UnitTestTest, ReturnsPlausibleTimestamp) {
void ExpectNonFatalFailureRecordingPropertyWithReservedKey( void ExpectNonFatalFailureRecordingPropertyWithReservedKey(
const TestResult& test_result, const char* key) { const TestResult& test_result, const char* key) {
EXPECT_NONFATAL_FAILURE(Test::RecordProperty(key, "1"), "Reserved key"); EXPECT_NONFATAL_FAILURE(Test::RecordProperty(key, "1"), "Reserved key");
ASSERT_EQ(0, test_result.test_property_count()) << "Property for key '" << key ASSERT_EQ(0, test_result.test_property_count())
<< "' recorded unexpectedly."; << "Property for key '" << key << "' recorded unexpectedly.";
} }
void ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest( void ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
...@@ -2025,8 +2013,8 @@ void ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite( ...@@ -2025,8 +2013,8 @@ void ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
// Tests that property recording functions in UnitTest outside of tests // Tests that property recording functions in UnitTest outside of tests
// functions correctly. Creating a separate instance of UnitTest ensures it // functions correctly. Creating a separate instance of UnitTest ensures it
// is in a state similar to the UnitTest's singleton's between tests. // is in a state similar to the UnitTest's singleton's between tests.
class UnitTestRecordPropertyTest : class UnitTestRecordPropertyTest
public testing::internal::UnitTestRecordPropertyTestHelper { : public testing::internal::UnitTestRecordPropertyTestHelper {
public: public:
static void SetUpTestSuite() { static void SetUpTestSuite() {
ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite( ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
...@@ -2065,8 +2053,7 @@ TEST_F(UnitTestRecordPropertyTest, OnePropertyFoundWhenAdded) { ...@@ -2065,8 +2053,7 @@ TEST_F(UnitTestRecordPropertyTest, OnePropertyFoundWhenAdded) {
EXPECT_STREQ("key_1", EXPECT_STREQ("key_1",
unit_test_.ad_hoc_test_result().GetTestProperty(0).key()); unit_test_.ad_hoc_test_result().GetTestProperty(0).key());
EXPECT_STREQ("1", EXPECT_STREQ("1", unit_test_.ad_hoc_test_result().GetTestProperty(0).value());
unit_test_.ad_hoc_test_result().GetTestProperty(0).value());
} }
// Tests TestResult has multiple properties when added. // Tests TestResult has multiple properties when added.
...@@ -2107,16 +2094,13 @@ TEST_F(UnitTestRecordPropertyTest, OverridesValuesForDuplicateKeys) { ...@@ -2107,16 +2094,13 @@ TEST_F(UnitTestRecordPropertyTest, OverridesValuesForDuplicateKeys) {
TEST_F(UnitTestRecordPropertyTest, TEST_F(UnitTestRecordPropertyTest,
AddFailureInsideTestsWhenUsingTestSuiteReservedKeys) { AddFailureInsideTestsWhenUsingTestSuiteReservedKeys) {
ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest( ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest("name");
"name");
ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest( ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
"value_param"); "value_param");
ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest( ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
"type_param"); "type_param");
ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest( ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest("status");
"status"); ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest("time");
ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
"time");
ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest( ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
"classname"); "classname");
} }
...@@ -2164,9 +2148,7 @@ static Environment* record_property_env GTEST_ATTRIBUTE_UNUSED_ = ...@@ -2164,9 +2148,7 @@ static Environment* record_property_env GTEST_ATTRIBUTE_UNUSED_ =
// First, some predicates and predicate-formatters needed by the tests. // First, some predicates and predicate-formatters needed by the tests.
// Returns true if and only if the argument is an even number. // Returns true if and only if the argument is an even number.
bool IsEven(int n) { bool IsEven(int n) { return (n % 2) == 0; }
return (n % 2) == 0;
}
// A functor that returns true if and only if the argument is an even number. // A functor that returns true if and only if the argument is an even number.
struct IsEvenFunctor { struct IsEvenFunctor {
...@@ -2213,41 +2195,37 @@ struct AssertIsEvenFunctor { ...@@ -2213,41 +2195,37 @@ struct AssertIsEvenFunctor {
}; };
// Returns true if and only if the sum of the arguments is an even number. // Returns true if and only if the sum of the arguments is an even number.
bool SumIsEven2(int n1, int n2) { bool SumIsEven2(int n1, int n2) { return IsEven(n1 + n2); }
return IsEven(n1 + n2);
}
// A functor that returns true if and only if the sum of the arguments is an // A functor that returns true if and only if the sum of the arguments is an
// even number. // even number.
struct SumIsEven3Functor { struct SumIsEven3Functor {
bool operator()(int n1, int n2, int n3) { bool operator()(int n1, int n2, int n3) { return IsEven(n1 + n2 + n3); }
return IsEven(n1 + n2 + n3);
}
}; };
// A predicate-formatter function that asserts the sum of the // A predicate-formatter function that asserts the sum of the
// arguments is an even number. // arguments is an even number.
AssertionResult AssertSumIsEven4( AssertionResult AssertSumIsEven4(const char* e1, const char* e2, const char* e3,
const char* e1, const char* e2, const char* e3, const char* e4, const char* e4, int n1, int n2, int n3,
int n1, int n2, int n3, int n4) { int n4) {
const int sum = n1 + n2 + n3 + n4; const int sum = n1 + n2 + n3 + n4;
if (IsEven(sum)) { if (IsEven(sum)) {
return AssertionSuccess(); return AssertionSuccess();
} }
Message msg; Message msg;
msg << e1 << " + " << e2 << " + " << e3 << " + " << e4 msg << e1 << " + " << e2 << " + " << e3 << " + " << e4 << " (" << n1 << " + "
<< " (" << n1 << " + " << n2 << " + " << n3 << " + " << n4 << n2 << " + " << n3 << " + " << n4 << ") evaluates to " << sum
<< ") evaluates to " << sum << ", which is not even."; << ", which is not even.";
return AssertionFailure(msg); return AssertionFailure(msg);
} }
// A predicate-formatter functor that asserts the sum of the arguments // A predicate-formatter functor that asserts the sum of the arguments
// is an even number. // is an even number.
struct AssertSumIsEven5Functor { struct AssertSumIsEven5Functor {
AssertionResult operator()( AssertionResult operator()(const char* e1, const char* e2, const char* e3,
const char* e1, const char* e2, const char* e3, const char* e4, const char* e4, const char* e5, int n1, int n2,
const char* e5, int n1, int n2, int n3, int n4, int n5) { int n3, int n4, int n5) {
const int sum = n1 + n2 + n3 + n4 + n5; const int sum = n1 + n2 + n3 + n4 + n5;
if (IsEven(sum)) { if (IsEven(sum)) {
return AssertionSuccess(); return AssertionSuccess();
...@@ -2255,14 +2233,12 @@ struct AssertSumIsEven5Functor { ...@@ -2255,14 +2233,12 @@ struct AssertSumIsEven5Functor {
Message msg; Message msg;
msg << e1 << " + " << e2 << " + " << e3 << " + " << e4 << " + " << e5 msg << e1 << " + " << e2 << " + " << e3 << " + " << e4 << " + " << e5
<< " (" << " (" << n1 << " + " << n2 << " + " << n3 << " + " << n4 << " + "
<< n1 << " + " << n2 << " + " << n3 << " + " << n4 << " + " << n5 << n5 << ") evaluates to " << sum << ", which is not even.";
<< ") evaluates to " << sum << ", which is not even.";
return AssertionFailure(msg); return AssertionFailure(msg);
} }
}; };
// Tests unary predicate assertions. // Tests unary predicate assertions.
// Tests unary predicate assertions that don't use a custom formatter. // Tests unary predicate assertions that don't use a custom formatter.
...@@ -2272,11 +2248,12 @@ TEST(Pred1Test, WithoutFormat) { ...@@ -2272,11 +2248,12 @@ TEST(Pred1Test, WithoutFormat) {
ASSERT_PRED1(IsEven, 4); ASSERT_PRED1(IsEven, 4);
// Failure cases. // Failure cases.
EXPECT_NONFATAL_FAILURE({ // NOLINT EXPECT_NONFATAL_FAILURE(
EXPECT_PRED1(IsEven, 5) << "This failure is expected."; { // NOLINT
}, "This failure is expected."); EXPECT_PRED1(IsEven, 5) << "This failure is expected.";
EXPECT_FATAL_FAILURE(ASSERT_PRED1(IsEvenFunctor(), 5), },
"evaluates to false"); "This failure is expected.");
EXPECT_FATAL_FAILURE(ASSERT_PRED1(IsEvenFunctor(), 5), "evaluates to false");
} }
// Tests unary predicate assertions that use a custom formatter. // Tests unary predicate assertions that use a custom formatter.
...@@ -2284,15 +2261,17 @@ TEST(Pred1Test, WithFormat) { ...@@ -2284,15 +2261,17 @@ TEST(Pred1Test, WithFormat) {
// Success cases. // Success cases.
EXPECT_PRED_FORMAT1(AssertIsEven, 2); EXPECT_PRED_FORMAT1(AssertIsEven, 2);
ASSERT_PRED_FORMAT1(AssertIsEvenFunctor(), 4) ASSERT_PRED_FORMAT1(AssertIsEvenFunctor(), 4)
<< "This failure is UNEXPECTED!"; << "This failure is UNEXPECTED!";
// Failure cases. // Failure cases.
const int n = 5; const int n = 5;
EXPECT_NONFATAL_FAILURE(EXPECT_PRED_FORMAT1(AssertIsEvenFunctor(), n), EXPECT_NONFATAL_FAILURE(EXPECT_PRED_FORMAT1(AssertIsEvenFunctor(), n),
"n evaluates to 5, which is not even."); "n evaluates to 5, which is not even.");
EXPECT_FATAL_FAILURE({ // NOLINT EXPECT_FATAL_FAILURE(
ASSERT_PRED_FORMAT1(AssertIsEven, 5) << "This failure is expected."; { // NOLINT
}, "This failure is expected."); ASSERT_PRED_FORMAT1(AssertIsEven, 5) << "This failure is expected.";
},
"This failure is expected.");
} }
// Tests that unary predicate assertions evaluates their arguments // Tests that unary predicate assertions evaluates their arguments
...@@ -2304,14 +2283,15 @@ TEST(Pred1Test, SingleEvaluationOnFailure) { ...@@ -2304,14 +2283,15 @@ TEST(Pred1Test, SingleEvaluationOnFailure) {
EXPECT_EQ(1, n) << "The argument is not evaluated exactly once."; EXPECT_EQ(1, n) << "The argument is not evaluated exactly once.";
// A failure case. // A failure case.
EXPECT_FATAL_FAILURE({ // NOLINT EXPECT_FATAL_FAILURE(
ASSERT_PRED_FORMAT1(AssertIsEvenFunctor(), n++) { // NOLINT
<< "This failure is expected."; ASSERT_PRED_FORMAT1(AssertIsEvenFunctor(), n++)
}, "This failure is expected."); << "This failure is expected.";
},
"This failure is expected.");
EXPECT_EQ(2, n) << "The argument is not evaluated exactly once."; EXPECT_EQ(2, n) << "The argument is not evaluated exactly once.";
} }
// Tests predicate assertions whose arity is >= 2. // Tests predicate assertions whose arity is >= 2.
// Tests predicate assertions that don't use a custom formatter. // Tests predicate assertions that don't use a custom formatter.
...@@ -2323,19 +2303,23 @@ TEST(PredTest, WithoutFormat) { ...@@ -2323,19 +2303,23 @@ TEST(PredTest, WithoutFormat) {
// Failure cases. // Failure cases.
const int n1 = 1; const int n1 = 1;
const int n2 = 2; const int n2 = 2;
EXPECT_NONFATAL_FAILURE({ // NOLINT EXPECT_NONFATAL_FAILURE(
EXPECT_PRED2(SumIsEven2, n1, n2) << "This failure is expected."; { // NOLINT
}, "This failure is expected."); EXPECT_PRED2(SumIsEven2, n1, n2) << "This failure is expected.";
EXPECT_FATAL_FAILURE({ // NOLINT },
ASSERT_PRED3(SumIsEven3Functor(), 1, 2, 4); "This failure is expected.");
}, "evaluates to false"); EXPECT_FATAL_FAILURE(
{ // NOLINT
ASSERT_PRED3(SumIsEven3Functor(), 1, 2, 4);
},
"evaluates to false");
} }
// Tests predicate assertions that use a custom formatter. // Tests predicate assertions that use a custom formatter.
TEST(PredTest, WithFormat) { TEST(PredTest, WithFormat) {
// Success cases. // Success cases.
ASSERT_PRED_FORMAT4(AssertSumIsEven4, 4, 6, 8, 10) << ASSERT_PRED_FORMAT4(AssertSumIsEven4, 4, 6, 8, 10)
"This failure is UNEXPECTED!"; << "This failure is UNEXPECTED!";
EXPECT_PRED_FORMAT5(AssertSumIsEven5Functor(), 2, 4, 6, 8, 10); EXPECT_PRED_FORMAT5(AssertSumIsEven5Functor(), 2, 4, 6, 8, 10);
// Failure cases. // Failure cases.
...@@ -2343,13 +2327,17 @@ TEST(PredTest, WithFormat) { ...@@ -2343,13 +2327,17 @@ TEST(PredTest, WithFormat) {
const int n2 = 2; const int n2 = 2;
const int n3 = 4; const int n3 = 4;
const int n4 = 6; const int n4 = 6;
EXPECT_NONFATAL_FAILURE({ // NOLINT EXPECT_NONFATAL_FAILURE(
EXPECT_PRED_FORMAT4(AssertSumIsEven4, n1, n2, n3, n4); { // NOLINT
}, "evaluates to 13, which is not even."); EXPECT_PRED_FORMAT4(AssertSumIsEven4, n1, n2, n3, n4);
EXPECT_FATAL_FAILURE({ // NOLINT },
ASSERT_PRED_FORMAT5(AssertSumIsEven5Functor(), 1, 2, 4, 6, 8) "evaluates to 13, which is not even.");
<< "This failure is expected."; EXPECT_FATAL_FAILURE(
}, "This failure is expected."); { // NOLINT
ASSERT_PRED_FORMAT5(AssertSumIsEven5Functor(), 1, 2, 4, 6, 8)
<< "This failure is expected.";
},
"This failure is expected.");
} }
// Tests that predicate assertions evaluates their arguments // Tests that predicate assertions evaluates their arguments
...@@ -2367,9 +2355,8 @@ TEST(PredTest, SingleEvaluationOnFailure) { ...@@ -2367,9 +2355,8 @@ TEST(PredTest, SingleEvaluationOnFailure) {
int n3 = 0; int n3 = 0;
int n4 = 0; int n4 = 0;
int n5 = 0; int n5 = 0;
ASSERT_PRED_FORMAT5(AssertSumIsEven5Functor(), ASSERT_PRED_FORMAT5(AssertSumIsEven5Functor(), n1++, n2++, n3++, n4++, n5++)
n1++, n2++, n3++, n4++, n5++) << "This failure is UNEXPECTED!";
<< "This failure is UNEXPECTED!";
EXPECT_EQ(1, n1) << "Argument 1 is not evaluated exactly once."; EXPECT_EQ(1, n1) << "Argument 1 is not evaluated exactly once.";
EXPECT_EQ(1, n2) << "Argument 2 is not evaluated exactly once."; EXPECT_EQ(1, n2) << "Argument 2 is not evaluated exactly once.";
EXPECT_EQ(1, n3) << "Argument 3 is not evaluated exactly once."; EXPECT_EQ(1, n3) << "Argument 3 is not evaluated exactly once.";
...@@ -2378,19 +2365,23 @@ TEST(PredTest, SingleEvaluationOnFailure) { ...@@ -2378,19 +2365,23 @@ TEST(PredTest, SingleEvaluationOnFailure) {
// A failure case. // A failure case.
n1 = n2 = n3 = 0; n1 = n2 = n3 = 0;
EXPECT_NONFATAL_FAILURE({ // NOLINT EXPECT_NONFATAL_FAILURE(
EXPECT_PRED3(SumIsEven3Functor(), ++n1, n2++, n3++) { // NOLINT
<< "This failure is expected."; EXPECT_PRED3(SumIsEven3Functor(), ++n1, n2++, n3++)
}, "This failure is expected."); << "This failure is expected.";
},
"This failure is expected.");
EXPECT_EQ(1, n1) << "Argument 1 is not evaluated exactly once."; EXPECT_EQ(1, n1) << "Argument 1 is not evaluated exactly once.";
EXPECT_EQ(1, n2) << "Argument 2 is not evaluated exactly once."; EXPECT_EQ(1, n2) << "Argument 2 is not evaluated exactly once.";
EXPECT_EQ(1, n3) << "Argument 3 is not evaluated exactly once."; EXPECT_EQ(1, n3) << "Argument 3 is not evaluated exactly once.";
// Another failure case. // Another failure case.
n1 = n2 = n3 = n4 = 0; n1 = n2 = n3 = n4 = 0;
EXPECT_NONFATAL_FAILURE({ // NOLINT EXPECT_NONFATAL_FAILURE(
EXPECT_PRED_FORMAT4(AssertSumIsEven4, ++n1, n2++, n3++, n4++); { // NOLINT
}, "evaluates to 1, which is not even."); EXPECT_PRED_FORMAT4(AssertSumIsEven4, ++n1, n2++, n3++, n4++);
},
"evaluates to 1, which is not even.");
EXPECT_EQ(1, n1) << "Argument 1 is not evaluated exactly once."; EXPECT_EQ(1, n1) << "Argument 1 is not evaluated exactly once.";
EXPECT_EQ(1, n2) << "Argument 2 is not evaluated exactly once."; EXPECT_EQ(1, n2) << "Argument 2 is not evaluated exactly once.";
EXPECT_EQ(1, n3) << "Argument 3 is not evaluated exactly once."; EXPECT_EQ(1, n3) << "Argument 3 is not evaluated exactly once.";
...@@ -2401,7 +2392,7 @@ TEST(PredTest, SingleEvaluationOnFailure) { ...@@ -2401,7 +2392,7 @@ TEST(PredTest, SingleEvaluationOnFailure) {
TEST(PredTest, ExpectPredEvalFailure) { TEST(PredTest, ExpectPredEvalFailure) {
std::set<int> set_a = {2, 1, 3, 4, 5}; std::set<int> set_a = {2, 1, 3, 4, 5};
std::set<int> set_b = {0, 4, 8}; std::set<int> set_b = {0, 4, 8};
const auto compare_sets = [] (std::set<int>, std::set<int>) { return false; }; const auto compare_sets = [](std::set<int>, std::set<int>) { return false; };
EXPECT_NONFATAL_FAILURE( EXPECT_NONFATAL_FAILURE(
EXPECT_PRED2(compare_sets, set_a, set_b), EXPECT_PRED2(compare_sets, set_a, set_b),
"compare_sets(set_a, set_b) evaluates to false, where\nset_a evaluates " "compare_sets(set_a, set_b) evaluates to false, where\nset_a evaluates "
...@@ -2411,9 +2402,7 @@ TEST(PredTest, ExpectPredEvalFailure) { ...@@ -2411,9 +2402,7 @@ TEST(PredTest, ExpectPredEvalFailure) {
// Some helper functions for testing using overloaded/template // Some helper functions for testing using overloaded/template
// functions with ASSERT_PREDn and EXPECT_PREDn. // functions with ASSERT_PREDn and EXPECT_PREDn.
bool IsPositive(double x) { bool IsPositive(double x) { return x > 0; }
return x > 0;
}
template <typename T> template <typename T>
bool IsNegative(T x) { bool IsNegative(T x) {
...@@ -2429,7 +2418,7 @@ bool GreaterThan(T1 x1, T2 x2) { ...@@ -2429,7 +2418,7 @@ bool GreaterThan(T1 x1, T2 x2) {
// their types are explicitly specified. // their types are explicitly specified.
TEST(PredicateAssertionTest, AcceptsOverloadedFunction) { TEST(PredicateAssertionTest, AcceptsOverloadedFunction) {
// C++Builder requires C-style casts rather than static_cast. // C++Builder requires C-style casts rather than static_cast.
EXPECT_PRED1((bool (*)(int))(IsPositive), 5); // NOLINT EXPECT_PRED1((bool (*)(int))(IsPositive), 5); // NOLINT
ASSERT_PRED1((bool (*)(double))(IsPositive), 6.0); // NOLINT ASSERT_PRED1((bool (*)(double))(IsPositive), 6.0); // NOLINT
} }
...@@ -2442,31 +2431,27 @@ TEST(PredicateAssertionTest, AcceptsTemplateFunction) { ...@@ -2442,31 +2431,27 @@ TEST(PredicateAssertionTest, AcceptsTemplateFunction) {
ASSERT_PRED2((GreaterThan<int, int>), 5, 0); ASSERT_PRED2((GreaterThan<int, int>), 5, 0);
} }
// Some helper functions for testing using overloaded/template // Some helper functions for testing using overloaded/template
// functions with ASSERT_PRED_FORMATn and EXPECT_PRED_FORMATn. // functions with ASSERT_PRED_FORMATn and EXPECT_PRED_FORMATn.
AssertionResult IsPositiveFormat(const char* /* expr */, int n) { AssertionResult IsPositiveFormat(const char* /* expr */, int n) {
return n > 0 ? AssertionSuccess() : return n > 0 ? AssertionSuccess() : AssertionFailure(Message() << "Failure");
AssertionFailure(Message() << "Failure");
} }
AssertionResult IsPositiveFormat(const char* /* expr */, double x) { AssertionResult IsPositiveFormat(const char* /* expr */, double x) {
return x > 0 ? AssertionSuccess() : return x > 0 ? AssertionSuccess() : AssertionFailure(Message() << "Failure");
AssertionFailure(Message() << "Failure");
} }
template <typename T> template <typename T>
AssertionResult IsNegativeFormat(const char* /* expr */, T x) { AssertionResult IsNegativeFormat(const char* /* expr */, T x) {
return x < 0 ? AssertionSuccess() : return x < 0 ? AssertionSuccess() : AssertionFailure(Message() << "Failure");
AssertionFailure(Message() << "Failure");
} }
template <typename T1, typename T2> template <typename T1, typename T2>
AssertionResult EqualsFormat(const char* /* expr1 */, const char* /* expr2 */, AssertionResult EqualsFormat(const char* /* expr1 */, const char* /* expr2 */,
const T1& x1, const T2& x2) { const T1& x1, const T2& x2) {
return x1 == x2 ? AssertionSuccess() : return x1 == x2 ? AssertionSuccess()
AssertionFailure(Message() << "Failure"); : AssertionFailure(Message() << "Failure");
} }
// Tests that overloaded functions can be used in *_PRED_FORMAT* // Tests that overloaded functions can be used in *_PRED_FORMAT*
...@@ -2483,20 +2468,18 @@ TEST(PredicateFormatAssertionTest, AcceptsTemplateFunction) { ...@@ -2483,20 +2468,18 @@ TEST(PredicateFormatAssertionTest, AcceptsTemplateFunction) {
ASSERT_PRED_FORMAT2(EqualsFormat, 3, 3); ASSERT_PRED_FORMAT2(EqualsFormat, 3, 3);
} }
// Tests string assertions. // Tests string assertions.
// Tests ASSERT_STREQ with non-NULL arguments. // Tests ASSERT_STREQ with non-NULL arguments.
TEST(StringAssertionTest, ASSERT_STREQ) { TEST(StringAssertionTest, ASSERT_STREQ) {
const char * const p1 = "good"; const char* const p1 = "good";
ASSERT_STREQ(p1, p1); ASSERT_STREQ(p1, p1);
// Let p2 have the same content as p1, but be at a different address. // Let p2 have the same content as p1, but be at a different address.
const char p2[] = "good"; const char p2[] = "good";
ASSERT_STREQ(p1, p2); ASSERT_STREQ(p1, p2);
EXPECT_FATAL_FAILURE(ASSERT_STREQ("bad", "good"), EXPECT_FATAL_FAILURE(ASSERT_STREQ("bad", "good"), " \"bad\"\n \"good\"");
" \"bad\"\n \"good\"");
} }
// Tests ASSERT_STREQ with NULL arguments. // Tests ASSERT_STREQ with NULL arguments.
...@@ -2519,8 +2502,7 @@ TEST(StringAssertionTest, ASSERT_STRNE) { ...@@ -2519,8 +2502,7 @@ TEST(StringAssertionTest, ASSERT_STRNE) {
ASSERT_STRNE(nullptr, ""); ASSERT_STRNE(nullptr, "");
ASSERT_STRNE("", "Hi"); ASSERT_STRNE("", "Hi");
ASSERT_STRNE("Hi", ""); ASSERT_STRNE("Hi", "");
EXPECT_FATAL_FAILURE(ASSERT_STRNE("Hi", "Hi"), EXPECT_FATAL_FAILURE(ASSERT_STRNE("Hi", "Hi"), "\"Hi\" vs \"Hi\"");
"\"Hi\" vs \"Hi\"");
} }
// Tests ASSERT_STRCASEEQ. // Tests ASSERT_STRCASEEQ.
...@@ -2529,8 +2511,7 @@ TEST(StringAssertionTest, ASSERT_STRCASEEQ) { ...@@ -2529,8 +2511,7 @@ TEST(StringAssertionTest, ASSERT_STRCASEEQ) {
ASSERT_STRCASEEQ(static_cast<const char*>(nullptr), nullptr); ASSERT_STRCASEEQ(static_cast<const char*>(nullptr), nullptr);
ASSERT_STRCASEEQ("", ""); ASSERT_STRCASEEQ("", "");
EXPECT_FATAL_FAILURE(ASSERT_STRCASEEQ("Hi", "hi2"), EXPECT_FATAL_FAILURE(ASSERT_STRCASEEQ("Hi", "hi2"), "Ignoring case");
"Ignoring case");
} }
// Tests ASSERT_STRCASENE. // Tests ASSERT_STRCASENE.
...@@ -2542,8 +2523,7 @@ TEST(StringAssertionTest, ASSERT_STRCASENE) { ...@@ -2542,8 +2523,7 @@ TEST(StringAssertionTest, ASSERT_STRCASENE) {
ASSERT_STRCASENE(nullptr, ""); ASSERT_STRCASENE(nullptr, "");
ASSERT_STRCASENE("", "Hi"); ASSERT_STRCASENE("", "Hi");
ASSERT_STRCASENE("Hi", ""); ASSERT_STRCASENE("Hi", "");
EXPECT_FATAL_FAILURE(ASSERT_STRCASENE("Hi", "hi"), EXPECT_FATAL_FAILURE(ASSERT_STRCASENE("Hi", "hi"), "(ignoring case)");
"(ignoring case)");
} }
// Tests *_STREQ on wide strings. // Tests *_STREQ on wide strings.
...@@ -2561,17 +2541,17 @@ TEST(StringAssertionTest, STREQ_Wide) { ...@@ -2561,17 +2541,17 @@ TEST(StringAssertionTest, STREQ_Wide) {
EXPECT_STREQ(L"Hi", L"Hi"); EXPECT_STREQ(L"Hi", L"Hi");
// Unequal strings. // Unequal strings.
EXPECT_NONFATAL_FAILURE(EXPECT_STREQ(L"abc", L"Abc"), EXPECT_NONFATAL_FAILURE(EXPECT_STREQ(L"abc", L"Abc"), "Abc");
"Abc");
// Strings containing wide characters. // Strings containing wide characters.
EXPECT_NONFATAL_FAILURE(EXPECT_STREQ(L"abc\x8119", L"abc\x8120"), EXPECT_NONFATAL_FAILURE(EXPECT_STREQ(L"abc\x8119", L"abc\x8120"), "abc");
"abc");
// The streaming variation. // The streaming variation.
EXPECT_NONFATAL_FAILURE({ // NOLINT EXPECT_NONFATAL_FAILURE(
EXPECT_STREQ(L"abc\x8119", L"abc\x8121") << "Expected failure"; { // NOLINT
}, "Expected failure"); EXPECT_STREQ(L"abc\x8119", L"abc\x8121") << "Expected failure";
},
"Expected failure");
} }
// Tests *_STRNE on wide strings. // Tests *_STRNE on wide strings.
...@@ -2584,22 +2564,19 @@ TEST(StringAssertionTest, STRNE_Wide) { ...@@ -2584,22 +2564,19 @@ TEST(StringAssertionTest, STRNE_Wide) {
""); "");
// Empty strings. // Empty strings.
EXPECT_NONFATAL_FAILURE(EXPECT_STRNE(L"", L""), EXPECT_NONFATAL_FAILURE(EXPECT_STRNE(L"", L""), "L\"\"");
"L\"\"");
// Non-null vs NULL. // Non-null vs NULL.
ASSERT_STRNE(L"non-null", nullptr); ASSERT_STRNE(L"non-null", nullptr);
// Equal strings. // Equal strings.
EXPECT_NONFATAL_FAILURE(EXPECT_STRNE(L"Hi", L"Hi"), EXPECT_NONFATAL_FAILURE(EXPECT_STRNE(L"Hi", L"Hi"), "L\"Hi\"");
"L\"Hi\"");
// Unequal strings. // Unequal strings.
EXPECT_STRNE(L"abc", L"Abc"); EXPECT_STRNE(L"abc", L"Abc");
// Strings containing wide characters. // Strings containing wide characters.
EXPECT_NONFATAL_FAILURE(EXPECT_STRNE(L"abc\x8119", L"abc\x8119"), EXPECT_NONFATAL_FAILURE(EXPECT_STRNE(L"abc\x8119", L"abc\x8119"), "abc");
"abc");
// The streaming variation. // The streaming variation.
ASSERT_STRNE(L"abc\x8119", L"abc\x8120") << "This shouldn't happen"; ASSERT_STRNE(L"abc\x8119", L"abc\x8120") << "This shouldn't happen";
...@@ -2633,12 +2610,13 @@ TEST(IsSubstringTest, ReturnsCorrectResultForWideCString) { ...@@ -2633,12 +2610,13 @@ TEST(IsSubstringTest, ReturnsCorrectResultForWideCString) {
// Tests that IsSubstring() generates the correct message when the input // Tests that IsSubstring() generates the correct message when the input
// argument type is const char*. // argument type is const char*.
TEST(IsSubstringTest, GeneratesCorrectMessageForCString) { TEST(IsSubstringTest, GeneratesCorrectMessageForCString) {
EXPECT_STREQ("Value of: needle_expr\n" EXPECT_STREQ(
" Actual: \"needle\"\n" "Value of: needle_expr\n"
"Expected: a substring of haystack_expr\n" " Actual: \"needle\"\n"
"Which is: \"haystack\"", "Expected: a substring of haystack_expr\n"
IsSubstring("needle_expr", "haystack_expr", "Which is: \"haystack\"",
"needle", "haystack").failure_message()); IsSubstring("needle_expr", "haystack_expr", "needle", "haystack")
.failure_message());
} }
// Tests that IsSubstring returns the correct result when the input // Tests that IsSubstring returns the correct result when the input
...@@ -2659,13 +2637,14 @@ TEST(IsSubstringTest, ReturnsCorrectResultForStdWstring) { ...@@ -2659,13 +2637,14 @@ TEST(IsSubstringTest, ReturnsCorrectResultForStdWstring) {
// Tests that IsSubstring() generates the correct message when the input // Tests that IsSubstring() generates the correct message when the input
// argument type is ::std::wstring. // argument type is ::std::wstring.
TEST(IsSubstringTest, GeneratesCorrectMessageForWstring) { TEST(IsSubstringTest, GeneratesCorrectMessageForWstring) {
EXPECT_STREQ("Value of: needle_expr\n" EXPECT_STREQ(
" Actual: L\"needle\"\n" "Value of: needle_expr\n"
"Expected: a substring of haystack_expr\n" " Actual: L\"needle\"\n"
"Which is: L\"haystack\"", "Expected: a substring of haystack_expr\n"
IsSubstring( "Which is: L\"haystack\"",
"needle_expr", "haystack_expr", IsSubstring("needle_expr", "haystack_expr", ::std::wstring(L"needle"),
::std::wstring(L"needle"), L"haystack").failure_message()); L"haystack")
.failure_message());
} }
#endif // GTEST_HAS_STD_WSTRING #endif // GTEST_HAS_STD_WSTRING
...@@ -2689,13 +2668,13 @@ TEST(IsNotSubstringTest, ReturnsCorrectResultForWideCString) { ...@@ -2689,13 +2668,13 @@ TEST(IsNotSubstringTest, ReturnsCorrectResultForWideCString) {
// Tests that IsNotSubstring() generates the correct message when the input // Tests that IsNotSubstring() generates the correct message when the input
// argument type is const wchar_t*. // argument type is const wchar_t*.
TEST(IsNotSubstringTest, GeneratesCorrectMessageForWideCString) { TEST(IsNotSubstringTest, GeneratesCorrectMessageForWideCString) {
EXPECT_STREQ("Value of: needle_expr\n" EXPECT_STREQ(
" Actual: L\"needle\"\n" "Value of: needle_expr\n"
"Expected: not a substring of haystack_expr\n" " Actual: L\"needle\"\n"
"Which is: L\"two needles\"", "Expected: not a substring of haystack_expr\n"
IsNotSubstring( "Which is: L\"two needles\"",
"needle_expr", "haystack_expr", IsNotSubstring("needle_expr", "haystack_expr", L"needle", L"two needles")
L"needle", L"two needles").failure_message()); .failure_message());
} }
// Tests that IsNotSubstring returns the correct result when the input // Tests that IsNotSubstring returns the correct result when the input
...@@ -2708,13 +2687,14 @@ TEST(IsNotSubstringTest, ReturnsCorrectResultsForStdString) { ...@@ -2708,13 +2687,14 @@ TEST(IsNotSubstringTest, ReturnsCorrectResultsForStdString) {
// Tests that IsNotSubstring() generates the correct message when the input // Tests that IsNotSubstring() generates the correct message when the input
// argument type is ::std::string. // argument type is ::std::string.
TEST(IsNotSubstringTest, GeneratesCorrectMessageForStdString) { TEST(IsNotSubstringTest, GeneratesCorrectMessageForStdString) {
EXPECT_STREQ("Value of: needle_expr\n" EXPECT_STREQ(
" Actual: \"needle\"\n" "Value of: needle_expr\n"
"Expected: not a substring of haystack_expr\n" " Actual: \"needle\"\n"
"Which is: \"two needles\"", "Expected: not a substring of haystack_expr\n"
IsNotSubstring( "Which is: \"two needles\"",
"needle_expr", "haystack_expr", IsNotSubstring("needle_expr", "haystack_expr", ::std::string("needle"),
::std::string("needle"), "two needles").failure_message()); "two needles")
.failure_message());
} }
#if GTEST_HAS_STD_WSTRING #if GTEST_HAS_STD_WSTRING
...@@ -2761,20 +2741,20 @@ class FloatingPointTest : public Test { ...@@ -2761,20 +2741,20 @@ class FloatingPointTest : public Test {
const Bits zero_bits = Floating(0).bits(); const Bits zero_bits = Floating(0).bits();
// Makes some numbers close to 0.0. // Makes some numbers close to 0.0.
values_.close_to_positive_zero = Floating::ReinterpretBits( values_.close_to_positive_zero =
zero_bits + max_ulps/2); Floating::ReinterpretBits(zero_bits + max_ulps / 2);
values_.close_to_negative_zero = -Floating::ReinterpretBits( values_.close_to_negative_zero =
zero_bits + max_ulps - max_ulps/2); -Floating::ReinterpretBits(zero_bits + max_ulps - max_ulps / 2);
values_.further_from_negative_zero = -Floating::ReinterpretBits( values_.further_from_negative_zero =
zero_bits + max_ulps + 1 - max_ulps/2); -Floating::ReinterpretBits(zero_bits + max_ulps + 1 - max_ulps / 2);
// The bits that represent 1.0. // The bits that represent 1.0.
const Bits one_bits = Floating(1).bits(); const Bits one_bits = Floating(1).bits();
// Makes some numbers close to 1.0. // Makes some numbers close to 1.0.
values_.close_to_one = Floating::ReinterpretBits(one_bits + max_ulps); values_.close_to_one = Floating::ReinterpretBits(one_bits + max_ulps);
values_.further_from_one = Floating::ReinterpretBits( values_.further_from_one =
one_bits + max_ulps + 1); Floating::ReinterpretBits(one_bits + max_ulps + 1);
// +infinity. // +infinity.
values_.infinity = Floating::Infinity(); values_.infinity = Floating::Infinity();
...@@ -2783,23 +2763,23 @@ class FloatingPointTest : public Test { ...@@ -2783,23 +2763,23 @@ class FloatingPointTest : public Test {
const Bits infinity_bits = Floating(values_.infinity).bits(); const Bits infinity_bits = Floating(values_.infinity).bits();
// Makes some numbers close to infinity. // Makes some numbers close to infinity.
values_.close_to_infinity = Floating::ReinterpretBits( values_.close_to_infinity =
infinity_bits - max_ulps); Floating::ReinterpretBits(infinity_bits - max_ulps);
values_.further_from_infinity = Floating::ReinterpretBits( values_.further_from_infinity =
infinity_bits - max_ulps - 1); Floating::ReinterpretBits(infinity_bits - max_ulps - 1);
// Makes some NAN's. Sets the most significant bit of the fraction so that // Makes some NAN's. Sets the most significant bit of the fraction so that
// our NaN's are quiet; trying to process a signaling NaN would raise an // our NaN's are quiet; trying to process a signaling NaN would raise an
// exception if our environment enables floating point exceptions. // exception if our environment enables floating point exceptions.
values_.nan1 = Floating::ReinterpretBits(Floating::kExponentBitMask values_.nan1 = Floating::ReinterpretBits(
| (static_cast<Bits>(1) << (Floating::kFractionBitCount - 1)) | 1); Floating::kExponentBitMask |
values_.nan2 = Floating::ReinterpretBits(Floating::kExponentBitMask (static_cast<Bits>(1) << (Floating::kFractionBitCount - 1)) | 1);
| (static_cast<Bits>(1) << (Floating::kFractionBitCount - 1)) | 200); values_.nan2 = Floating::ReinterpretBits(
Floating::kExponentBitMask |
(static_cast<Bits>(1) << (Floating::kFractionBitCount - 1)) | 200);
} }
void TestSize() { void TestSize() { EXPECT_EQ(sizeof(RawType), sizeof(Bits)); }
EXPECT_EQ(sizeof(RawType), sizeof(Bits));
}
static TestValues values_; static TestValues values_;
}; };
...@@ -2812,17 +2792,13 @@ typename FloatingPointTest<RawType>::TestValues ...@@ -2812,17 +2792,13 @@ typename FloatingPointTest<RawType>::TestValues
typedef FloatingPointTest<float> FloatTest; typedef FloatingPointTest<float> FloatTest;
// Tests that the size of Float::Bits matches the size of float. // Tests that the size of Float::Bits matches the size of float.
TEST_F(FloatTest, Size) { TEST_F(FloatTest, Size) { TestSize(); }
TestSize();
}
// Tests comparing with +0 and -0. // Tests comparing with +0 and -0.
TEST_F(FloatTest, Zeros) { TEST_F(FloatTest, Zeros) {
EXPECT_FLOAT_EQ(0.0, -0.0); EXPECT_FLOAT_EQ(0.0, -0.0);
EXPECT_NONFATAL_FAILURE(EXPECT_FLOAT_EQ(-0.0, 1.0), EXPECT_NONFATAL_FAILURE(EXPECT_FLOAT_EQ(-0.0, 1.0), "1.0");
"1.0"); EXPECT_FATAL_FAILURE(ASSERT_FLOAT_EQ(0.0, 1.5), "1.5");
EXPECT_FATAL_FAILURE(ASSERT_FLOAT_EQ(0.0, 1.5),
"1.5");
} }
// Tests comparing numbers close to 0. // Tests comparing numbers close to 0.
...@@ -2843,10 +2819,11 @@ TEST_F(FloatTest, AlmostZeros) { ...@@ -2843,10 +2819,11 @@ TEST_F(FloatTest, AlmostZeros) {
EXPECT_FLOAT_EQ(-0.0, v.close_to_negative_zero); EXPECT_FLOAT_EQ(-0.0, v.close_to_negative_zero);
EXPECT_FLOAT_EQ(v.close_to_positive_zero, v.close_to_negative_zero); EXPECT_FLOAT_EQ(v.close_to_positive_zero, v.close_to_negative_zero);
EXPECT_FATAL_FAILURE({ // NOLINT EXPECT_FATAL_FAILURE(
ASSERT_FLOAT_EQ(v.close_to_positive_zero, { // NOLINT
v.further_from_negative_zero); ASSERT_FLOAT_EQ(v.close_to_positive_zero, v.further_from_negative_zero);
}, "v.further_from_negative_zero"); },
"v.further_from_negative_zero");
} }
// Tests comparing numbers close to each other. // Tests comparing numbers close to each other.
...@@ -2858,8 +2835,7 @@ TEST_F(FloatTest, SmallDiff) { ...@@ -2858,8 +2835,7 @@ TEST_F(FloatTest, SmallDiff) {
// Tests comparing numbers far apart. // Tests comparing numbers far apart.
TEST_F(FloatTest, LargeDiff) { TEST_F(FloatTest, LargeDiff) {
EXPECT_NONFATAL_FAILURE(EXPECT_FLOAT_EQ(2.5, 3.0), EXPECT_NONFATAL_FAILURE(EXPECT_FLOAT_EQ(2.5, 3.0), "3.0");
"3.0");
} }
// Tests comparing with infinity. // Tests comparing with infinity.
...@@ -2888,15 +2864,11 @@ TEST_F(FloatTest, NaN) { ...@@ -2888,15 +2864,11 @@ TEST_F(FloatTest, NaN) {
// (parentheses). // (parentheses).
static const FloatTest::TestValues& v = this->values_; static const FloatTest::TestValues& v = this->values_;
EXPECT_NONFATAL_FAILURE(EXPECT_FLOAT_EQ(v.nan1, v.nan1), EXPECT_NONFATAL_FAILURE(EXPECT_FLOAT_EQ(v.nan1, v.nan1), "v.nan1");
"v.nan1"); EXPECT_NONFATAL_FAILURE(EXPECT_FLOAT_EQ(v.nan1, v.nan2), "v.nan2");
EXPECT_NONFATAL_FAILURE(EXPECT_FLOAT_EQ(v.nan1, v.nan2), EXPECT_NONFATAL_FAILURE(EXPECT_FLOAT_EQ(1.0, v.nan1), "v.nan1");
"v.nan2");
EXPECT_NONFATAL_FAILURE(EXPECT_FLOAT_EQ(1.0, v.nan1),
"v.nan1");
EXPECT_FATAL_FAILURE(ASSERT_FLOAT_EQ(v.nan1, v.infinity), EXPECT_FATAL_FAILURE(ASSERT_FLOAT_EQ(v.nan1, v.infinity), "v.infinity");
"v.infinity");
} }
// Tests that *_FLOAT_EQ are reflexive. // Tests that *_FLOAT_EQ are reflexive.
...@@ -2950,36 +2922,40 @@ TEST_F(FloatTest, FloatLEFails) { ...@@ -2950,36 +2922,40 @@ TEST_F(FloatTest, FloatLEFails) {
"(2.0f) <= (1.0f)"); "(2.0f) <= (1.0f)");
// or by a small yet non-negligible margin, // or by a small yet non-negligible margin,
EXPECT_NONFATAL_FAILURE({ // NOLINT EXPECT_NONFATAL_FAILURE(
EXPECT_PRED_FORMAT2(FloatLE, values_.further_from_one, 1.0f); { // NOLINT
}, "(values_.further_from_one) <= (1.0f)"); EXPECT_PRED_FORMAT2(FloatLE, values_.further_from_one, 1.0f);
},
"(values_.further_from_one) <= (1.0f)");
EXPECT_NONFATAL_FAILURE({ // NOLINT EXPECT_NONFATAL_FAILURE(
EXPECT_PRED_FORMAT2(FloatLE, values_.nan1, values_.infinity); { // NOLINT
}, "(values_.nan1) <= (values_.infinity)"); EXPECT_PRED_FORMAT2(FloatLE, values_.nan1, values_.infinity);
EXPECT_NONFATAL_FAILURE({ // NOLINT },
EXPECT_PRED_FORMAT2(FloatLE, -values_.infinity, values_.nan1); "(values_.nan1) <= (values_.infinity)");
}, "(-values_.infinity) <= (values_.nan1)"); EXPECT_NONFATAL_FAILURE(
EXPECT_FATAL_FAILURE({ // NOLINT { // NOLINT
ASSERT_PRED_FORMAT2(FloatLE, values_.nan1, values_.nan1); EXPECT_PRED_FORMAT2(FloatLE, -values_.infinity, values_.nan1);
}, "(values_.nan1) <= (values_.nan1)"); },
"(-values_.infinity) <= (values_.nan1)");
EXPECT_FATAL_FAILURE(
{ // NOLINT
ASSERT_PRED_FORMAT2(FloatLE, values_.nan1, values_.nan1);
},
"(values_.nan1) <= (values_.nan1)");
} }
// Instantiates FloatingPointTest for testing *_DOUBLE_EQ. // Instantiates FloatingPointTest for testing *_DOUBLE_EQ.
typedef FloatingPointTest<double> DoubleTest; typedef FloatingPointTest<double> DoubleTest;
// Tests that the size of Double::Bits matches the size of double. // Tests that the size of Double::Bits matches the size of double.
TEST_F(DoubleTest, Size) { TEST_F(DoubleTest, Size) { TestSize(); }
TestSize();
}
// Tests comparing with +0 and -0. // Tests comparing with +0 and -0.
TEST_F(DoubleTest, Zeros) { TEST_F(DoubleTest, Zeros) {
EXPECT_DOUBLE_EQ(0.0, -0.0); EXPECT_DOUBLE_EQ(0.0, -0.0);
EXPECT_NONFATAL_FAILURE(EXPECT_DOUBLE_EQ(-0.0, 1.0), EXPECT_NONFATAL_FAILURE(EXPECT_DOUBLE_EQ(-0.0, 1.0), "1.0");
"1.0"); EXPECT_FATAL_FAILURE(ASSERT_DOUBLE_EQ(0.0, 1.0), "1.0");
EXPECT_FATAL_FAILURE(ASSERT_DOUBLE_EQ(0.0, 1.0),
"1.0");
} }
// Tests comparing numbers close to 0. // Tests comparing numbers close to 0.
...@@ -3000,10 +2976,12 @@ TEST_F(DoubleTest, AlmostZeros) { ...@@ -3000,10 +2976,12 @@ TEST_F(DoubleTest, AlmostZeros) {
EXPECT_DOUBLE_EQ(-0.0, v.close_to_negative_zero); EXPECT_DOUBLE_EQ(-0.0, v.close_to_negative_zero);
EXPECT_DOUBLE_EQ(v.close_to_positive_zero, v.close_to_negative_zero); EXPECT_DOUBLE_EQ(v.close_to_positive_zero, v.close_to_negative_zero);
EXPECT_FATAL_FAILURE({ // NOLINT EXPECT_FATAL_FAILURE(
ASSERT_DOUBLE_EQ(v.close_to_positive_zero, { // NOLINT
v.further_from_negative_zero); ASSERT_DOUBLE_EQ(v.close_to_positive_zero,
}, "v.further_from_negative_zero"); v.further_from_negative_zero);
},
"v.further_from_negative_zero");
} }
// Tests comparing numbers close to each other. // Tests comparing numbers close to each other.
...@@ -3015,8 +2993,7 @@ TEST_F(DoubleTest, SmallDiff) { ...@@ -3015,8 +2993,7 @@ TEST_F(DoubleTest, SmallDiff) {
// Tests comparing numbers far apart. // Tests comparing numbers far apart.
TEST_F(DoubleTest, LargeDiff) { TEST_F(DoubleTest, LargeDiff) {
EXPECT_NONFATAL_FAILURE(EXPECT_DOUBLE_EQ(2.0, 3.0), EXPECT_NONFATAL_FAILURE(EXPECT_DOUBLE_EQ(2.0, 3.0), "3.0");
"3.0");
} }
// Tests comparing with infinity. // Tests comparing with infinity.
...@@ -3040,12 +3017,10 @@ TEST_F(DoubleTest, NaN) { ...@@ -3040,12 +3017,10 @@ TEST_F(DoubleTest, NaN) {
static const DoubleTest::TestValues& v = this->values_; static const DoubleTest::TestValues& v = this->values_;
// Nokia's STLport crashes if we try to output infinity or NaN. // Nokia's STLport crashes if we try to output infinity or NaN.
EXPECT_NONFATAL_FAILURE(EXPECT_DOUBLE_EQ(v.nan1, v.nan1), EXPECT_NONFATAL_FAILURE(EXPECT_DOUBLE_EQ(v.nan1, v.nan1), "v.nan1");
"v.nan1");
EXPECT_NONFATAL_FAILURE(EXPECT_DOUBLE_EQ(v.nan1, v.nan2), "v.nan2"); EXPECT_NONFATAL_FAILURE(EXPECT_DOUBLE_EQ(v.nan1, v.nan2), "v.nan2");
EXPECT_NONFATAL_FAILURE(EXPECT_DOUBLE_EQ(1.0, v.nan1), "v.nan1"); EXPECT_NONFATAL_FAILURE(EXPECT_DOUBLE_EQ(1.0, v.nan1), "v.nan1");
EXPECT_FATAL_FAILURE(ASSERT_DOUBLE_EQ(v.nan1, v.infinity), EXPECT_FATAL_FAILURE(ASSERT_DOUBLE_EQ(v.nan1, v.infinity), "v.infinity");
"v.infinity");
} }
// Tests that *_DOUBLE_EQ are reflexive. // Tests that *_DOUBLE_EQ are reflexive.
...@@ -3106,22 +3081,29 @@ TEST_F(DoubleTest, DoubleLEFails) { ...@@ -3106,22 +3081,29 @@ TEST_F(DoubleTest, DoubleLEFails) {
"(2.0) <= (1.0)"); "(2.0) <= (1.0)");
// or by a small yet non-negligible margin, // or by a small yet non-negligible margin,
EXPECT_NONFATAL_FAILURE({ // NOLINT EXPECT_NONFATAL_FAILURE(
EXPECT_PRED_FORMAT2(DoubleLE, values_.further_from_one, 1.0); { // NOLINT
}, "(values_.further_from_one) <= (1.0)"); EXPECT_PRED_FORMAT2(DoubleLE, values_.further_from_one, 1.0);
},
"(values_.further_from_one) <= (1.0)");
EXPECT_NONFATAL_FAILURE({ // NOLINT EXPECT_NONFATAL_FAILURE(
EXPECT_PRED_FORMAT2(DoubleLE, values_.nan1, values_.infinity); { // NOLINT
}, "(values_.nan1) <= (values_.infinity)"); EXPECT_PRED_FORMAT2(DoubleLE, values_.nan1, values_.infinity);
EXPECT_NONFATAL_FAILURE({ // NOLINT },
EXPECT_PRED_FORMAT2(DoubleLE, -values_.infinity, values_.nan1); "(values_.nan1) <= (values_.infinity)");
}, " (-values_.infinity) <= (values_.nan1)"); EXPECT_NONFATAL_FAILURE(
EXPECT_FATAL_FAILURE({ // NOLINT { // NOLINT
ASSERT_PRED_FORMAT2(DoubleLE, values_.nan1, values_.nan1); EXPECT_PRED_FORMAT2(DoubleLE, -values_.infinity, values_.nan1);
}, "(values_.nan1) <= (values_.nan1)"); },
" (-values_.infinity) <= (values_.nan1)");
EXPECT_FATAL_FAILURE(
{ // NOLINT
ASSERT_PRED_FORMAT2(DoubleLE, values_.nan1, values_.nan1);
},
"(values_.nan1) <= (values_.nan1)");
} }
// Verifies that a test or test case whose name starts with DISABLED_ is // Verifies that a test or test case whose name starts with DISABLED_ is
// not run. // not run.
...@@ -3133,9 +3115,7 @@ TEST(DisabledTest, DISABLED_TestShouldNotRun) { ...@@ -3133,9 +3115,7 @@ TEST(DisabledTest, DISABLED_TestShouldNotRun) {
// A test whose name does not start with DISABLED_. // A test whose name does not start with DISABLED_.
// Should run. // Should run.
TEST(DisabledTest, NotDISABLED_TestShouldRun) { TEST(DisabledTest, NotDISABLED_TestShouldRun) { EXPECT_EQ(1, 1); }
EXPECT_EQ(1, 1);
}
// A test case whose name starts with DISABLED_. // A test case whose name starts with DISABLED_.
// Should not run. // Should not run.
...@@ -3175,8 +3155,7 @@ TEST_F(DisabledTestsTest, DISABLED_TestShouldNotRun_2) { ...@@ -3175,8 +3155,7 @@ TEST_F(DisabledTestsTest, DISABLED_TestShouldNotRun_2) {
// Tests that disabled typed tests aren't run. // Tests that disabled typed tests aren't run.
template <typename T> template <typename T>
class TypedTest : public Test { class TypedTest : public Test {};
};
typedef testing::Types<int, double> NumericTypes; typedef testing::Types<int, double> NumericTypes;
TYPED_TEST_SUITE(TypedTest, NumericTypes); TYPED_TEST_SUITE(TypedTest, NumericTypes);
...@@ -3186,8 +3165,7 @@ TYPED_TEST(TypedTest, DISABLED_ShouldNotRun) { ...@@ -3186,8 +3165,7 @@ TYPED_TEST(TypedTest, DISABLED_ShouldNotRun) {
} }
template <typename T> template <typename T>
class DISABLED_TypedTest : public Test { class DISABLED_TypedTest : public Test {};
};
TYPED_TEST_SUITE(DISABLED_TypedTest, NumericTypes); TYPED_TEST_SUITE(DISABLED_TypedTest, NumericTypes);
...@@ -3198,8 +3176,7 @@ TYPED_TEST(DISABLED_TypedTest, ShouldNotRun) { ...@@ -3198,8 +3176,7 @@ TYPED_TEST(DISABLED_TypedTest, ShouldNotRun) {
// Tests that disabled type-parameterized tests aren't run. // Tests that disabled type-parameterized tests aren't run.
template <typename T> template <typename T>
class TypedTestP : public Test { class TypedTestP : public Test {};
};
TYPED_TEST_SUITE_P(TypedTestP); TYPED_TEST_SUITE_P(TypedTestP);
...@@ -3213,8 +3190,7 @@ REGISTER_TYPED_TEST_SUITE_P(TypedTestP, DISABLED_ShouldNotRun); ...@@ -3213,8 +3190,7 @@ REGISTER_TYPED_TEST_SUITE_P(TypedTestP, DISABLED_ShouldNotRun);
INSTANTIATE_TYPED_TEST_SUITE_P(My, TypedTestP, NumericTypes); INSTANTIATE_TYPED_TEST_SUITE_P(My, TypedTestP, NumericTypes);
template <typename T> template <typename T>
class DISABLED_TypedTestP : public Test { class DISABLED_TypedTestP : public Test {};
};
TYPED_TEST_SUITE_P(DISABLED_TypedTestP); TYPED_TEST_SUITE_P(DISABLED_TypedTestP);
...@@ -3234,15 +3210,11 @@ class SingleEvaluationTest : public Test { ...@@ -3234,15 +3210,11 @@ class SingleEvaluationTest : public Test {
// This helper function is needed by the FailedASSERT_STREQ test // This helper function is needed by the FailedASSERT_STREQ test
// below. It's public to work around C++Builder's bug with scoping local // below. It's public to work around C++Builder's bug with scoping local
// classes. // classes.
static void CompareAndIncrementCharPtrs() { static void CompareAndIncrementCharPtrs() { ASSERT_STREQ(p1_++, p2_++); }
ASSERT_STREQ(p1_++, p2_++);
}
// This helper function is needed by the FailedASSERT_NE test below. It's // This helper function is needed by the FailedASSERT_NE test below. It's
// public to work around C++Builder's bug with scoping local classes. // public to work around C++Builder's bug with scoping local classes.
static void CompareAndIncrementInts() { static void CompareAndIncrementInts() { ASSERT_NE(a_++, b_++); }
ASSERT_NE(a_++, b_++);
}
protected: protected:
SingleEvaluationTest() { SingleEvaluationTest() {
...@@ -3285,8 +3257,7 @@ TEST_F(SingleEvaluationTest, ASSERT_STR) { ...@@ -3285,8 +3257,7 @@ TEST_F(SingleEvaluationTest, ASSERT_STR) {
EXPECT_EQ(s2_ + 1, p2_); EXPECT_EQ(s2_ + 1, p2_);
// failed EXPECT_STRCASEEQ // failed EXPECT_STRCASEEQ
EXPECT_NONFATAL_FAILURE(EXPECT_STRCASEEQ(p1_++, p2_++), EXPECT_NONFATAL_FAILURE(EXPECT_STRCASEEQ(p1_++, p2_++), "Ignoring case");
"Ignoring case");
EXPECT_EQ(s1_ + 2, p1_); EXPECT_EQ(s1_ + 2, p1_);
EXPECT_EQ(s2_ + 2, p2_); EXPECT_EQ(s2_ + 2, p2_);
} }
...@@ -3346,34 +3317,39 @@ TEST_F(SingleEvaluationTest, OtherCases) { ...@@ -3346,34 +3317,39 @@ TEST_F(SingleEvaluationTest, OtherCases) {
#endif // GTEST_HAS_RTTI #endif // GTEST_HAS_RTTI
void ThrowAnInteger() { void ThrowAnInteger() { throw 1; }
throw 1; void ThrowRuntimeError(const char* what) { throw std::runtime_error(what); }
}
void ThrowRuntimeError(const char* what) {
throw std::runtime_error(what);
}
// Tests that assertion arguments are evaluated exactly once. // Tests that assertion arguments are evaluated exactly once.
TEST_F(SingleEvaluationTest, ExceptionTests) { TEST_F(SingleEvaluationTest, ExceptionTests) {
// successful EXPECT_THROW // successful EXPECT_THROW
EXPECT_THROW({ // NOLINT EXPECT_THROW(
a_++; { // NOLINT
ThrowAnInteger(); a_++;
}, int); ThrowAnInteger();
},
int);
EXPECT_EQ(1, a_); EXPECT_EQ(1, a_);
// failed EXPECT_THROW, throws different // failed EXPECT_THROW, throws different
EXPECT_NONFATAL_FAILURE(EXPECT_THROW({ // NOLINT EXPECT_NONFATAL_FAILURE(EXPECT_THROW(
a_++; { // NOLINT
ThrowAnInteger(); a_++;
}, bool), "throws a different type"); ThrowAnInteger();
},
bool),
"throws a different type");
EXPECT_EQ(2, a_); EXPECT_EQ(2, a_);
// failed EXPECT_THROW, throws runtime error // failed EXPECT_THROW, throws runtime error
EXPECT_NONFATAL_FAILURE(EXPECT_THROW({ // NOLINT EXPECT_NONFATAL_FAILURE(EXPECT_THROW(
a_++; { // NOLINT
ThrowRuntimeError("A description"); a_++;
}, bool), "throws " ERROR_DESC " with description \"A description\""); ThrowRuntimeError("A description");
},
bool),
"throws " ERROR_DESC
" with description \"A description\"");
EXPECT_EQ(3, a_); EXPECT_EQ(3, a_);
// failed EXPECT_THROW, throws nothing // failed EXPECT_THROW, throws nothing
...@@ -3386,9 +3362,10 @@ TEST_F(SingleEvaluationTest, ExceptionTests) { ...@@ -3386,9 +3362,10 @@ TEST_F(SingleEvaluationTest, ExceptionTests) {
// failed EXPECT_NO_THROW // failed EXPECT_NO_THROW
EXPECT_NONFATAL_FAILURE(EXPECT_NO_THROW({ // NOLINT EXPECT_NONFATAL_FAILURE(EXPECT_NO_THROW({ // NOLINT
a_++; a_++;
ThrowAnInteger(); ThrowAnInteger();
}), "it throws"); }),
"it throws");
EXPECT_EQ(6, a_); EXPECT_EQ(6, a_);
// successful EXPECT_ANY_THROW // successful EXPECT_ANY_THROW
...@@ -3409,12 +3386,8 @@ TEST_F(SingleEvaluationTest, ExceptionTests) { ...@@ -3409,12 +3386,8 @@ TEST_F(SingleEvaluationTest, ExceptionTests) {
class NoFatalFailureTest : public Test { class NoFatalFailureTest : public Test {
protected: protected:
void Succeeds() {} void Succeeds() {}
void FailsNonFatal() { void FailsNonFatal() { ADD_FAILURE() << "some non-fatal failure"; }
ADD_FAILURE() << "some non-fatal failure"; void Fails() { FAIL() << "some fatal failure"; }
}
void Fails() {
FAIL() << "some fatal failure";
}
void DoAssertNoFatalFailureOnFails() { void DoAssertNoFatalFailureOnFails() {
ASSERT_NO_FATAL_FAILURE(Fails()); ASSERT_NO_FATAL_FAILURE(Fails());
...@@ -3433,12 +3406,10 @@ TEST_F(NoFatalFailureTest, NoFailure) { ...@@ -3433,12 +3406,10 @@ TEST_F(NoFatalFailureTest, NoFailure) {
} }
TEST_F(NoFatalFailureTest, NonFatalIsNoFailure) { TEST_F(NoFatalFailureTest, NonFatalIsNoFailure) {
EXPECT_NONFATAL_FAILURE( EXPECT_NONFATAL_FAILURE(EXPECT_NO_FATAL_FAILURE(FailsNonFatal()),
EXPECT_NO_FATAL_FAILURE(FailsNonFatal()), "some non-fatal failure");
"some non-fatal failure"); EXPECT_NONFATAL_FAILURE(ASSERT_NO_FATAL_FAILURE(FailsNonFatal()),
EXPECT_NONFATAL_FAILURE( "some non-fatal failure");
ASSERT_NO_FATAL_FAILURE(FailsNonFatal()),
"some non-fatal failure");
} }
TEST_F(NoFatalFailureTest, AssertNoFatalFailureOnFatalFailure) { TEST_F(NoFatalFailureTest, AssertNoFatalFailureOnFatalFailure) {
...@@ -3561,8 +3532,9 @@ TEST(EditDistance, TestSuites) { ...@@ -3561,8 +3532,9 @@ TEST(EditDistance, TestSuites) {
EditsToString(CalculateOptimalEdits(CharsToIndices(c->left), EditsToString(CalculateOptimalEdits(CharsToIndices(c->left),
CharsToIndices(c->right)))) CharsToIndices(c->right))))
<< "Left <" << c->left << "> Right <" << c->right << "> Edits <" << "Left <" << c->left << "> Right <" << c->right << "> Edits <"
<< EditsToString(CalculateOptimalEdits( << EditsToString(CalculateOptimalEdits(CharsToIndices(c->left),
CharsToIndices(c->left), CharsToIndices(c->right))) << ">"; CharsToIndices(c->right)))
<< ">";
EXPECT_TRUE(c->expected_diff == CreateUnifiedDiff(CharsToLines(c->left), EXPECT_TRUE(c->expected_diff == CreateUnifiedDiff(CharsToLines(c->left),
CharsToLines(c->right))) CharsToLines(c->right)))
<< "Left <" << c->left << "> Right <" << c->right << "> Diff <" << "Left <" << c->left << "> Right <" << c->right << "> Diff <"
...@@ -3575,8 +3547,7 @@ TEST(EditDistance, TestSuites) { ...@@ -3575,8 +3547,7 @@ TEST(EditDistance, TestSuites) {
TEST(AssertionTest, EqFailure) { TEST(AssertionTest, EqFailure) {
const std::string foo_val("5"), bar_val("6"); const std::string foo_val("5"), bar_val("6");
const std::string msg1( const std::string msg1(
EqFailure("foo", "bar", foo_val, bar_val, false) EqFailure("foo", "bar", foo_val, bar_val, false).failure_message());
.failure_message());
EXPECT_STREQ( EXPECT_STREQ(
"Expected equality of these values:\n" "Expected equality of these values:\n"
" foo\n" " foo\n"
...@@ -3586,8 +3557,7 @@ TEST(AssertionTest, EqFailure) { ...@@ -3586,8 +3557,7 @@ TEST(AssertionTest, EqFailure) {
msg1.c_str()); msg1.c_str());
const std::string msg2( const std::string msg2(
EqFailure("foo", "6", foo_val, bar_val, false) EqFailure("foo", "6", foo_val, bar_val, false).failure_message());
.failure_message());
EXPECT_STREQ( EXPECT_STREQ(
"Expected equality of these values:\n" "Expected equality of these values:\n"
" foo\n" " foo\n"
...@@ -3596,8 +3566,7 @@ TEST(AssertionTest, EqFailure) { ...@@ -3596,8 +3566,7 @@ TEST(AssertionTest, EqFailure) {
msg2.c_str()); msg2.c_str());
const std::string msg3( const std::string msg3(
EqFailure("5", "bar", foo_val, bar_val, false) EqFailure("5", "bar", foo_val, bar_val, false).failure_message());
.failure_message());
EXPECT_STREQ( EXPECT_STREQ(
"Expected equality of these values:\n" "Expected equality of these values:\n"
" 5\n" " 5\n"
...@@ -3614,9 +3583,8 @@ TEST(AssertionTest, EqFailure) { ...@@ -3614,9 +3583,8 @@ TEST(AssertionTest, EqFailure) {
msg4.c_str()); msg4.c_str());
const std::string msg5( const std::string msg5(
EqFailure("foo", "bar", EqFailure("foo", "bar", std::string("\"x\""), std::string("\"y\""), true)
std::string("\"x\""), std::string("\"y\""), .failure_message());
true).failure_message());
EXPECT_STREQ( EXPECT_STREQ(
"Expected equality of these values:\n" "Expected equality of these values:\n"
" foo\n" " foo\n"
...@@ -3651,24 +3619,21 @@ TEST(AssertionTest, AppendUserMessage) { ...@@ -3651,24 +3619,21 @@ TEST(AssertionTest, AppendUserMessage) {
const std::string foo("foo"); const std::string foo("foo");
Message msg; Message msg;
EXPECT_STREQ("foo", EXPECT_STREQ("foo", AppendUserMessage(foo, msg).c_str());
AppendUserMessage(foo, msg).c_str());
msg << "bar"; msg << "bar";
EXPECT_STREQ("foo\nbar", EXPECT_STREQ("foo\nbar", AppendUserMessage(foo, msg).c_str());
AppendUserMessage(foo, msg).c_str());
} }
#ifdef __BORLANDC__ #ifdef __BORLANDC__
// Silences warnings: "Condition is always true", "Unreachable code" // Silences warnings: "Condition is always true", "Unreachable code"
# pragma option push -w-ccc -w-rch #pragma option push -w-ccc -w-rch
#endif #endif
// Tests ASSERT_TRUE. // Tests ASSERT_TRUE.
TEST(AssertionTest, ASSERT_TRUE) { TEST(AssertionTest, ASSERT_TRUE) {
ASSERT_TRUE(2 > 1); // NOLINT ASSERT_TRUE(2 > 1); // NOLINT
EXPECT_FATAL_FAILURE(ASSERT_TRUE(2 < 1), EXPECT_FATAL_FAILURE(ASSERT_TRUE(2 < 1), "2 < 1");
"2 < 1");
} }
// Tests ASSERT_TRUE(predicate) for predicates returning AssertionResult. // Tests ASSERT_TRUE(predicate) for predicates returning AssertionResult.
...@@ -3716,7 +3681,7 @@ TEST(AssertionTest, AssertFalseWithAssertionResult) { ...@@ -3716,7 +3681,7 @@ TEST(AssertionTest, AssertFalseWithAssertionResult) {
#ifdef __BORLANDC__ #ifdef __BORLANDC__
// Restores warnings after previous "#pragma option push" suppressed them // Restores warnings after previous "#pragma option push" suppressed them
# pragma option pop #pragma option pop
#endif #endif
// Tests using ASSERT_EQ on double values. The purpose is to make // Tests using ASSERT_EQ on double values. The purpose is to make
...@@ -3727,18 +3692,19 @@ TEST(ExpectTest, ASSERT_EQ_Double) { ...@@ -3727,18 +3692,19 @@ TEST(ExpectTest, ASSERT_EQ_Double) {
ASSERT_EQ(5.6, 5.6); ASSERT_EQ(5.6, 5.6);
// A failure. // A failure.
EXPECT_FATAL_FAILURE(ASSERT_EQ(5.1, 5.2), EXPECT_FATAL_FAILURE(ASSERT_EQ(5.1, 5.2), "5.1");
"5.1");
} }
// Tests ASSERT_EQ. // Tests ASSERT_EQ.
TEST(AssertionTest, ASSERT_EQ) { TEST(AssertionTest, ASSERT_EQ) {
ASSERT_EQ(5, 2 + 3); ASSERT_EQ(5, 2 + 3);
// clang-format off
EXPECT_FATAL_FAILURE(ASSERT_EQ(5, 2*3), EXPECT_FATAL_FAILURE(ASSERT_EQ(5, 2*3),
"Expected equality of these values:\n" "Expected equality of these values:\n"
" 5\n" " 5\n"
" 2*3\n" " 2*3\n"
" Which is: 6"); " Which is: 6");
// clang-format on
} }
// Tests ASSERT_EQ(NULL, pointer). // Tests ASSERT_EQ(NULL, pointer).
...@@ -3763,8 +3729,7 @@ TEST(ExpectTest, ASSERT_EQ_0) { ...@@ -3763,8 +3729,7 @@ TEST(ExpectTest, ASSERT_EQ_0) {
ASSERT_EQ(0, n); ASSERT_EQ(0, n);
// A failure. // A failure.
EXPECT_FATAL_FAILURE(ASSERT_EQ(0, 5.6), EXPECT_FATAL_FAILURE(ASSERT_EQ(0, 5.6), " 0\n 5.6");
" 0\n 5.6");
} }
// Tests ASSERT_NE. // Tests ASSERT_NE.
...@@ -3779,30 +3744,26 @@ TEST(AssertionTest, ASSERT_NE) { ...@@ -3779,30 +3744,26 @@ TEST(AssertionTest, ASSERT_NE) {
TEST(AssertionTest, ASSERT_LE) { TEST(AssertionTest, ASSERT_LE) {
ASSERT_LE(2, 3); ASSERT_LE(2, 3);
ASSERT_LE(2, 2); ASSERT_LE(2, 2);
EXPECT_FATAL_FAILURE(ASSERT_LE(2, 0), EXPECT_FATAL_FAILURE(ASSERT_LE(2, 0), "Expected: (2) <= (0), actual: 2 vs 0");
"Expected: (2) <= (0), actual: 2 vs 0");
} }
// Tests ASSERT_LT. // Tests ASSERT_LT.
TEST(AssertionTest, ASSERT_LT) { TEST(AssertionTest, ASSERT_LT) {
ASSERT_LT(2, 3); ASSERT_LT(2, 3);
EXPECT_FATAL_FAILURE(ASSERT_LT(2, 2), EXPECT_FATAL_FAILURE(ASSERT_LT(2, 2), "Expected: (2) < (2), actual: 2 vs 2");
"Expected: (2) < (2), actual: 2 vs 2");
} }
// Tests ASSERT_GE. // Tests ASSERT_GE.
TEST(AssertionTest, ASSERT_GE) { TEST(AssertionTest, ASSERT_GE) {
ASSERT_GE(2, 1); ASSERT_GE(2, 1);
ASSERT_GE(2, 2); ASSERT_GE(2, 2);
EXPECT_FATAL_FAILURE(ASSERT_GE(2, 3), EXPECT_FATAL_FAILURE(ASSERT_GE(2, 3), "Expected: (2) >= (3), actual: 2 vs 3");
"Expected: (2) >= (3), actual: 2 vs 3");
} }
// Tests ASSERT_GT. // Tests ASSERT_GT.
TEST(AssertionTest, ASSERT_GT) { TEST(AssertionTest, ASSERT_GT) {
ASSERT_GT(2, 1); ASSERT_GT(2, 1);
EXPECT_FATAL_FAILURE(ASSERT_GT(2, 2), EXPECT_FATAL_FAILURE(ASSERT_GT(2, 2), "Expected: (2) > (2), actual: 2 vs 2");
"Expected: (2) > (2), actual: 2 vs 2");
} }
#if GTEST_HAS_EXCEPTIONS #if GTEST_HAS_EXCEPTIONS
...@@ -3813,7 +3774,7 @@ void ThrowNothing() {} ...@@ -3813,7 +3774,7 @@ void ThrowNothing() {}
TEST(AssertionTest, ASSERT_THROW) { TEST(AssertionTest, ASSERT_THROW) {
ASSERT_THROW(ThrowAnInteger(), int); ASSERT_THROW(ThrowAnInteger(), int);
# ifndef __BORLANDC__ #ifndef __BORLANDC__
// ICE's in C++Builder 2007 and 2009. // ICE's in C++Builder 2007 and 2009.
EXPECT_FATAL_FAILURE( EXPECT_FATAL_FAILURE(
...@@ -3824,9 +3785,10 @@ TEST(AssertionTest, ASSERT_THROW) { ...@@ -3824,9 +3785,10 @@ TEST(AssertionTest, ASSERT_THROW) {
ASSERT_THROW(ThrowRuntimeError("A description"), std::logic_error), ASSERT_THROW(ThrowRuntimeError("A description"), std::logic_error),
"Expected: ThrowRuntimeError(\"A description\") " "Expected: ThrowRuntimeError(\"A description\") "
"throws an exception of type std::logic_error.\n " "throws an exception of type std::logic_error.\n "
"Actual: it throws " ERROR_DESC " " "Actual: it throws " ERROR_DESC
" "
"with description \"A description\"."); "with description \"A description\".");
# endif #endif
EXPECT_FATAL_FAILURE( EXPECT_FATAL_FAILURE(
ASSERT_THROW(ThrowNothing(), bool), ASSERT_THROW(ThrowNothing(), bool),
...@@ -3843,17 +3805,17 @@ TEST(AssertionTest, ASSERT_NO_THROW) { ...@@ -3843,17 +3805,17 @@ TEST(AssertionTest, ASSERT_NO_THROW) {
EXPECT_FATAL_FAILURE(ASSERT_NO_THROW(ThrowRuntimeError("A description")), EXPECT_FATAL_FAILURE(ASSERT_NO_THROW(ThrowRuntimeError("A description")),
"Expected: ThrowRuntimeError(\"A description\") " "Expected: ThrowRuntimeError(\"A description\") "
"doesn't throw an exception.\n " "doesn't throw an exception.\n "
"Actual: it throws " ERROR_DESC " " "Actual: it throws " ERROR_DESC
" "
"with description \"A description\"."); "with description \"A description\".");
} }
// Tests ASSERT_ANY_THROW. // Tests ASSERT_ANY_THROW.
TEST(AssertionTest, ASSERT_ANY_THROW) { TEST(AssertionTest, ASSERT_ANY_THROW) {
ASSERT_ANY_THROW(ThrowAnInteger()); ASSERT_ANY_THROW(ThrowAnInteger());
EXPECT_FATAL_FAILURE( EXPECT_FATAL_FAILURE(ASSERT_ANY_THROW(ThrowNothing()),
ASSERT_ANY_THROW(ThrowNothing()), "Expected: ThrowNothing() throws an exception.\n"
"Expected: ThrowNothing() throws an exception.\n" " Actual: it doesn't.");
" Actual: it doesn't.");
} }
#endif // GTEST_HAS_EXCEPTIONS #endif // GTEST_HAS_EXCEPTIONS
...@@ -3867,14 +3829,11 @@ TEST(AssertionTest, AssertPrecedence) { ...@@ -3867,14 +3829,11 @@ TEST(AssertionTest, AssertPrecedence) {
} }
// A subroutine used by the following test. // A subroutine used by the following test.
void TestEq1(int x) { void TestEq1(int x) { ASSERT_EQ(1, x); }
ASSERT_EQ(1, x);
}
// Tests calling a test subroutine that's not part of a fixture. // Tests calling a test subroutine that's not part of a fixture.
TEST(AssertionTest, NonFixtureSubroutine) { TEST(AssertionTest, NonFixtureSubroutine) {
EXPECT_FATAL_FAILURE(TestEq1(2), EXPECT_FATAL_FAILURE(TestEq1(2), " x\n Which is: 2");
" x\n Which is: 2");
} }
// An uncopyable class. // An uncopyable class.
...@@ -3886,6 +3845,7 @@ class Uncopyable { ...@@ -3886,6 +3845,7 @@ class Uncopyable {
bool operator==(const Uncopyable& rhs) const { bool operator==(const Uncopyable& rhs) const {
return value() == rhs.value(); return value() == rhs.value();
} }
private: private:
// This constructor deliberately has no implementation, as we don't // This constructor deliberately has no implementation, as we don't
// want this class to be copyable. // want this class to be copyable.
...@@ -3898,10 +3858,7 @@ class Uncopyable { ...@@ -3898,10 +3858,7 @@ class Uncopyable {
return os << value.value(); return os << value.value();
} }
bool IsPositiveUncopyable(const Uncopyable& x) { return x.value() > 0; }
bool IsPositiveUncopyable(const Uncopyable& x) {
return x.value() > 0;
}
// A subroutine used by the following test. // A subroutine used by the following test.
void TestAssertNonPositive() { void TestAssertNonPositive() {
...@@ -3920,8 +3877,9 @@ TEST(AssertionTest, AssertWorksWithUncopyableObject) { ...@@ -3920,8 +3877,9 @@ TEST(AssertionTest, AssertWorksWithUncopyableObject) {
Uncopyable x(5); Uncopyable x(5);
ASSERT_PRED1(IsPositiveUncopyable, x); ASSERT_PRED1(IsPositiveUncopyable, x);
ASSERT_EQ(x, x); ASSERT_EQ(x, x);
EXPECT_FATAL_FAILURE(TestAssertNonPositive(), EXPECT_FATAL_FAILURE(
"IsPositiveUncopyable(y) evaluates to false, where\ny evaluates to -1"); TestAssertNonPositive(),
"IsPositiveUncopyable(y) evaluates to false, where\ny evaluates to -1");
EXPECT_FATAL_FAILURE(TestAssertEqualsUncopyable(), EXPECT_FATAL_FAILURE(TestAssertEqualsUncopyable(),
"Expected equality of these values:\n" "Expected equality of these values:\n"
" x\n Which is: 5\n y\n Which is: -1"); " x\n Which is: 5\n y\n Which is: -1");
...@@ -3932,18 +3890,16 @@ TEST(AssertionTest, ExpectWorksWithUncopyableObject) { ...@@ -3932,18 +3890,16 @@ TEST(AssertionTest, ExpectWorksWithUncopyableObject) {
Uncopyable x(5); Uncopyable x(5);
EXPECT_PRED1(IsPositiveUncopyable, x); EXPECT_PRED1(IsPositiveUncopyable, x);
Uncopyable y(-1); Uncopyable y(-1);
EXPECT_NONFATAL_FAILURE(EXPECT_PRED1(IsPositiveUncopyable, y), EXPECT_NONFATAL_FAILURE(
"IsPositiveUncopyable(y) evaluates to false, where\ny evaluates to -1"); EXPECT_PRED1(IsPositiveUncopyable, y),
"IsPositiveUncopyable(y) evaluates to false, where\ny evaluates to -1");
EXPECT_EQ(x, x); EXPECT_EQ(x, x);
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(x, y), EXPECT_NONFATAL_FAILURE(EXPECT_EQ(x, y),
"Expected equality of these values:\n" "Expected equality of these values:\n"
" x\n Which is: 5\n y\n Which is: -1"); " x\n Which is: 5\n y\n Which is: -1");
} }
enum NamedEnum { enum NamedEnum { kE1 = 0, kE2 = 1 };
kE1 = 0,
kE2 = 1
};
TEST(AssertionTest, NamedEnum) { TEST(AssertionTest, NamedEnum) {
EXPECT_EQ(kE1, kE1); EXPECT_EQ(kE1, kE1);
...@@ -3959,7 +3915,7 @@ TEST(AssertionTest, NamedEnum) { ...@@ -3959,7 +3915,7 @@ TEST(AssertionTest, NamedEnum) {
enum { enum {
kCaseA = -1, kCaseA = -1,
# if GTEST_OS_LINUX #if GTEST_OS_LINUX
// We want to test the case where the size of the anonymous enum is // We want to test the case where the size of the anonymous enum is
// larger than sizeof(int), to make sure our implementation of the // larger than sizeof(int), to make sure our implementation of the
...@@ -3972,21 +3928,21 @@ enum { ...@@ -3972,21 +3928,21 @@ enum {
// assertions. // assertions.
kCaseB = testing::internal::kMaxBiggestInt, kCaseB = testing::internal::kMaxBiggestInt,
# else #else
kCaseB = INT_MAX, kCaseB = INT_MAX,
# endif // GTEST_OS_LINUX #endif // GTEST_OS_LINUX
kCaseC = 42 kCaseC = 42
}; };
TEST(AssertionTest, AnonymousEnum) { TEST(AssertionTest, AnonymousEnum) {
# if GTEST_OS_LINUX #if GTEST_OS_LINUX
EXPECT_EQ(static_cast<int>(kCaseA), static_cast<int>(kCaseB)); EXPECT_EQ(static_cast<int>(kCaseA), static_cast<int>(kCaseB));
# endif // GTEST_OS_LINUX #endif // GTEST_OS_LINUX
EXPECT_EQ(kCaseA, kCaseA); EXPECT_EQ(kCaseA, kCaseA);
EXPECT_NE(kCaseA, kCaseB); EXPECT_NE(kCaseA, kCaseB);
...@@ -3994,10 +3950,8 @@ TEST(AssertionTest, AnonymousEnum) { ...@@ -3994,10 +3950,8 @@ TEST(AssertionTest, AnonymousEnum) {
EXPECT_LE(kCaseA, kCaseB); EXPECT_LE(kCaseA, kCaseB);
EXPECT_GT(kCaseB, kCaseA); EXPECT_GT(kCaseB, kCaseA);
EXPECT_GE(kCaseA, kCaseA); EXPECT_GE(kCaseA, kCaseA);
EXPECT_NONFATAL_FAILURE(EXPECT_GE(kCaseA, kCaseB), EXPECT_NONFATAL_FAILURE(EXPECT_GE(kCaseA, kCaseB), "(kCaseA) >= (kCaseB)");
"(kCaseA) >= (kCaseB)"); EXPECT_NONFATAL_FAILURE(EXPECT_GE(kCaseA, kCaseC), "-1 vs 42");
EXPECT_NONFATAL_FAILURE(EXPECT_GE(kCaseA, kCaseC),
"-1 vs 42");
ASSERT_EQ(kCaseA, kCaseA); ASSERT_EQ(kCaseA, kCaseA);
ASSERT_NE(kCaseA, kCaseB); ASSERT_NE(kCaseA, kCaseB);
...@@ -4006,34 +3960,25 @@ TEST(AssertionTest, AnonymousEnum) { ...@@ -4006,34 +3960,25 @@ TEST(AssertionTest, AnonymousEnum) {
ASSERT_GT(kCaseB, kCaseA); ASSERT_GT(kCaseB, kCaseA);
ASSERT_GE(kCaseA, kCaseA); ASSERT_GE(kCaseA, kCaseA);
# ifndef __BORLANDC__ #ifndef __BORLANDC__
// ICE's in C++Builder. // ICE's in C++Builder.
EXPECT_FATAL_FAILURE(ASSERT_EQ(kCaseA, kCaseB), EXPECT_FATAL_FAILURE(ASSERT_EQ(kCaseA, kCaseB), " kCaseB\n Which is: ");
" kCaseB\n Which is: "); EXPECT_FATAL_FAILURE(ASSERT_EQ(kCaseA, kCaseC), "\n Which is: 42");
EXPECT_FATAL_FAILURE(ASSERT_EQ(kCaseA, kCaseC), #endif
"\n Which is: 42");
# endif
EXPECT_FATAL_FAILURE(ASSERT_EQ(kCaseA, kCaseC), EXPECT_FATAL_FAILURE(ASSERT_EQ(kCaseA, kCaseC), "\n Which is: -1");
"\n Which is: -1");
} }
#endif // !GTEST_OS_MAC && !defined(__SUNPRO_CC) #endif // !GTEST_OS_MAC && !defined(__SUNPRO_CC)
#if GTEST_OS_WINDOWS #if GTEST_OS_WINDOWS
static HRESULT UnexpectedHRESULTFailure() { static HRESULT UnexpectedHRESULTFailure() { return E_UNEXPECTED; }
return E_UNEXPECTED;
}
static HRESULT OkHRESULTSuccess() { static HRESULT OkHRESULTSuccess() { return S_OK; }
return S_OK;
}
static HRESULT FalseHRESULTSuccess() { static HRESULT FalseHRESULTSuccess() { return S_FALSE; }
return S_FALSE;
}
// HRESULT assertion tests test both zero and non-zero // HRESULT assertion tests test both zero and non-zero
// success codes as well as failure message for each. // success codes as well as failure message for each.
...@@ -4044,8 +3989,8 @@ TEST(HRESULTAssertionTest, EXPECT_HRESULT_SUCCEEDED) { ...@@ -4044,8 +3989,8 @@ TEST(HRESULTAssertionTest, EXPECT_HRESULT_SUCCEEDED) {
EXPECT_HRESULT_SUCCEEDED(S_FALSE); EXPECT_HRESULT_SUCCEEDED(S_FALSE);
EXPECT_NONFATAL_FAILURE(EXPECT_HRESULT_SUCCEEDED(UnexpectedHRESULTFailure()), EXPECT_NONFATAL_FAILURE(EXPECT_HRESULT_SUCCEEDED(UnexpectedHRESULTFailure()),
"Expected: (UnexpectedHRESULTFailure()) succeeds.\n" "Expected: (UnexpectedHRESULTFailure()) succeeds.\n"
" Actual: 0x8000FFFF"); " Actual: 0x8000FFFF");
} }
TEST(HRESULTAssertionTest, ASSERT_HRESULT_SUCCEEDED) { TEST(HRESULTAssertionTest, ASSERT_HRESULT_SUCCEEDED) {
...@@ -4053,35 +3998,35 @@ TEST(HRESULTAssertionTest, ASSERT_HRESULT_SUCCEEDED) { ...@@ -4053,35 +3998,35 @@ TEST(HRESULTAssertionTest, ASSERT_HRESULT_SUCCEEDED) {
ASSERT_HRESULT_SUCCEEDED(S_FALSE); ASSERT_HRESULT_SUCCEEDED(S_FALSE);
EXPECT_FATAL_FAILURE(ASSERT_HRESULT_SUCCEEDED(UnexpectedHRESULTFailure()), EXPECT_FATAL_FAILURE(ASSERT_HRESULT_SUCCEEDED(UnexpectedHRESULTFailure()),
"Expected: (UnexpectedHRESULTFailure()) succeeds.\n" "Expected: (UnexpectedHRESULTFailure()) succeeds.\n"
" Actual: 0x8000FFFF"); " Actual: 0x8000FFFF");
} }
TEST(HRESULTAssertionTest, EXPECT_HRESULT_FAILED) { TEST(HRESULTAssertionTest, EXPECT_HRESULT_FAILED) {
EXPECT_HRESULT_FAILED(E_UNEXPECTED); EXPECT_HRESULT_FAILED(E_UNEXPECTED);
EXPECT_NONFATAL_FAILURE(EXPECT_HRESULT_FAILED(OkHRESULTSuccess()), EXPECT_NONFATAL_FAILURE(EXPECT_HRESULT_FAILED(OkHRESULTSuccess()),
"Expected: (OkHRESULTSuccess()) fails.\n" "Expected: (OkHRESULTSuccess()) fails.\n"
" Actual: 0x0"); " Actual: 0x0");
EXPECT_NONFATAL_FAILURE(EXPECT_HRESULT_FAILED(FalseHRESULTSuccess()), EXPECT_NONFATAL_FAILURE(EXPECT_HRESULT_FAILED(FalseHRESULTSuccess()),
"Expected: (FalseHRESULTSuccess()) fails.\n" "Expected: (FalseHRESULTSuccess()) fails.\n"
" Actual: 0x1"); " Actual: 0x1");
} }
TEST(HRESULTAssertionTest, ASSERT_HRESULT_FAILED) { TEST(HRESULTAssertionTest, ASSERT_HRESULT_FAILED) {
ASSERT_HRESULT_FAILED(E_UNEXPECTED); ASSERT_HRESULT_FAILED(E_UNEXPECTED);
# ifndef __BORLANDC__ #ifndef __BORLANDC__
// ICE's in C++Builder 2007 and 2009. // ICE's in C++Builder 2007 and 2009.
EXPECT_FATAL_FAILURE(ASSERT_HRESULT_FAILED(OkHRESULTSuccess()), EXPECT_FATAL_FAILURE(ASSERT_HRESULT_FAILED(OkHRESULTSuccess()),
"Expected: (OkHRESULTSuccess()) fails.\n" "Expected: (OkHRESULTSuccess()) fails.\n"
" Actual: 0x0"); " Actual: 0x0");
# endif #endif
EXPECT_FATAL_FAILURE(ASSERT_HRESULT_FAILED(FalseHRESULTSuccess()), EXPECT_FATAL_FAILURE(ASSERT_HRESULT_FAILED(FalseHRESULTSuccess()),
"Expected: (FalseHRESULTSuccess()) fails.\n" "Expected: (FalseHRESULTSuccess()) fails.\n"
" Actual: 0x1"); " Actual: 0x1");
} }
// Tests that streaming to the HRESULT macros works. // Tests that streaming to the HRESULT macros works.
...@@ -4091,25 +4036,23 @@ TEST(HRESULTAssertionTest, Streaming) { ...@@ -4091,25 +4036,23 @@ TEST(HRESULTAssertionTest, Streaming) {
EXPECT_HRESULT_FAILED(E_UNEXPECTED) << "unexpected failure"; EXPECT_HRESULT_FAILED(E_UNEXPECTED) << "unexpected failure";
ASSERT_HRESULT_FAILED(E_UNEXPECTED) << "unexpected failure"; ASSERT_HRESULT_FAILED(E_UNEXPECTED) << "unexpected failure";
EXPECT_NONFATAL_FAILURE( EXPECT_NONFATAL_FAILURE(EXPECT_HRESULT_SUCCEEDED(E_UNEXPECTED)
EXPECT_HRESULT_SUCCEEDED(E_UNEXPECTED) << "expected failure", << "expected failure",
"expected failure"); "expected failure");
# ifndef __BORLANDC__ #ifndef __BORLANDC__
// ICE's in C++Builder 2007 and 2009. // ICE's in C++Builder 2007 and 2009.
EXPECT_FATAL_FAILURE( EXPECT_FATAL_FAILURE(ASSERT_HRESULT_SUCCEEDED(E_UNEXPECTED)
ASSERT_HRESULT_SUCCEEDED(E_UNEXPECTED) << "expected failure", << "expected failure",
"expected failure"); "expected failure");
# endif #endif
EXPECT_NONFATAL_FAILURE( EXPECT_NONFATAL_FAILURE(EXPECT_HRESULT_FAILED(S_OK) << "expected failure",
EXPECT_HRESULT_FAILED(S_OK) << "expected failure", "expected failure");
"expected failure");
EXPECT_FATAL_FAILURE( EXPECT_FATAL_FAILURE(ASSERT_HRESULT_FAILED(S_OK) << "expected failure",
ASSERT_HRESULT_FAILED(S_OK) << "expected failure", "expected failure");
"expected failure");
} }
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
...@@ -4132,8 +4075,7 @@ TEST(AssertionSyntaxTest, BasicAssertionsBehavesLikeSingleStatement) { ...@@ -4132,8 +4075,7 @@ TEST(AssertionSyntaxTest, BasicAssertionsBehavesLikeSingleStatement) {
else else
; // NOLINT ; // NOLINT
if (AlwaysFalse()) if (AlwaysFalse()) ASSERT_LT(1, 3);
ASSERT_LT(1, 3);
if (AlwaysFalse()) if (AlwaysFalse())
; // NOLINT ; // NOLINT
...@@ -4171,24 +4113,21 @@ TEST(ExpectThrowTest, DoesNotGenerateDuplicateCatchClauseWarning) { ...@@ -4171,24 +4113,21 @@ TEST(ExpectThrowTest, DoesNotGenerateDuplicateCatchClauseWarning) {
#pragma GCC diagnostic ignored "-Wpragmas" #pragma GCC diagnostic ignored "-Wpragmas"
#endif #endif
TEST(AssertionSyntaxTest, ExceptionAssertionsBehavesLikeSingleStatement) { TEST(AssertionSyntaxTest, ExceptionAssertionsBehavesLikeSingleStatement) {
if (AlwaysFalse()) if (AlwaysFalse()) EXPECT_THROW(ThrowNothing(), bool);
EXPECT_THROW(ThrowNothing(), bool);
if (AlwaysTrue()) if (AlwaysTrue())
EXPECT_THROW(ThrowAnInteger(), int); EXPECT_THROW(ThrowAnInteger(), int);
else else
; // NOLINT ; // NOLINT
if (AlwaysFalse()) if (AlwaysFalse()) EXPECT_NO_THROW(ThrowAnInteger());
EXPECT_NO_THROW(ThrowAnInteger());
if (AlwaysTrue()) if (AlwaysTrue())
EXPECT_NO_THROW(ThrowNothing()); EXPECT_NO_THROW(ThrowNothing());
else else
; // NOLINT ; // NOLINT
if (AlwaysFalse()) if (AlwaysFalse()) EXPECT_ANY_THROW(ThrowNothing());
EXPECT_ANY_THROW(ThrowNothing());
if (AlwaysTrue()) if (AlwaysTrue())
EXPECT_ANY_THROW(ThrowAnInteger()); EXPECT_ANY_THROW(ThrowAnInteger());
...@@ -4244,8 +4183,8 @@ TEST(AssertionSyntaxTest, WorksWithSwitch) { ...@@ -4244,8 +4183,8 @@ TEST(AssertionSyntaxTest, WorksWithSwitch) {
} }
switch (0) switch (0)
case 0: case 0:
EXPECT_FALSE(false) << "EXPECT_FALSE failed in switch case"; EXPECT_FALSE(false) << "EXPECT_FALSE failed in switch case";
// Binary assertions are implemented using a different code path // Binary assertions are implemented using a different code path
// than the Boolean assertions. Hence we test them separately. // than the Boolean assertions. Hence we test them separately.
...@@ -4256,22 +4195,20 @@ TEST(AssertionSyntaxTest, WorksWithSwitch) { ...@@ -4256,22 +4195,20 @@ TEST(AssertionSyntaxTest, WorksWithSwitch) {
} }
switch (0) switch (0)
case 0: case 0:
EXPECT_NE(1, 2); EXPECT_NE(1, 2);
} }
#if GTEST_HAS_EXCEPTIONS #if GTEST_HAS_EXCEPTIONS
void ThrowAString() { void ThrowAString() { throw "std::string"; }
throw "std::string";
}
// Test that the exception assertion macros compile and work with const // Test that the exception assertion macros compile and work with const
// type qualifier. // type qualifier.
TEST(AssertionSyntaxTest, WorksWithConst) { TEST(AssertionSyntaxTest, WorksWithConst) {
ASSERT_THROW(ThrowAString(), const char*); ASSERT_THROW(ThrowAString(), const char*);
EXPECT_THROW(ThrowAString(), const char*); EXPECT_THROW(ThrowAString(), const char*);
} }
#endif // GTEST_HAS_EXCEPTIONS #endif // GTEST_HAS_EXCEPTIONS
...@@ -4369,22 +4306,19 @@ TEST(AssertionWithMessageTest, ASSERT_FLOATING) { ...@@ -4369,22 +4306,19 @@ TEST(AssertionWithMessageTest, ASSERT_FLOATING) {
// Tests using ASSERT_FALSE with a streamed message. // Tests using ASSERT_FALSE with a streamed message.
TEST(AssertionWithMessageTest, ASSERT_FALSE) { TEST(AssertionWithMessageTest, ASSERT_FALSE) {
ASSERT_FALSE(false) << "This shouldn't fail."; ASSERT_FALSE(false) << "This shouldn't fail.";
EXPECT_FATAL_FAILURE({ // NOLINT EXPECT_FATAL_FAILURE(
ASSERT_FALSE(true) << "Expected failure: " << 2 << " > " << 1 { // NOLINT
<< " evaluates to " << true; ASSERT_FALSE(true) << "Expected failure: " << 2 << " > " << 1
}, "Expected failure"); << " evaluates to " << true;
},
"Expected failure");
} }
// Tests using FAIL with a streamed message. // Tests using FAIL with a streamed message.
TEST(AssertionWithMessageTest, FAIL) { TEST(AssertionWithMessageTest, FAIL) { EXPECT_FATAL_FAILURE(FAIL() << 0, "0"); }
EXPECT_FATAL_FAILURE(FAIL() << 0,
"0");
}
// Tests using SUCCEED with a streamed message. // Tests using SUCCEED with a streamed message.
TEST(AssertionWithMessageTest, SUCCEED) { TEST(AssertionWithMessageTest, SUCCEED) { SUCCEED() << "Success == " << 1; }
SUCCEED() << "Success == " << 1;
}
// Tests using ASSERT_TRUE with a streamed message. // Tests using ASSERT_TRUE with a streamed message.
TEST(AssertionWithMessageTest, ASSERT_TRUE) { TEST(AssertionWithMessageTest, ASSERT_TRUE) {
...@@ -4401,13 +4335,16 @@ TEST(AssertionWithMessageTest, ASSERT_TRUE) { ...@@ -4401,13 +4335,16 @@ TEST(AssertionWithMessageTest, ASSERT_TRUE) {
#if GTEST_OS_WINDOWS #if GTEST_OS_WINDOWS
// Tests using wide strings in assertion messages. // Tests using wide strings in assertion messages.
TEST(AssertionWithMessageTest, WideStringMessage) { TEST(AssertionWithMessageTest, WideStringMessage) {
EXPECT_NONFATAL_FAILURE({ // NOLINT EXPECT_NONFATAL_FAILURE(
EXPECT_TRUE(false) << L"This failure is expected.\x8119"; { // NOLINT
}, "This failure is expected."); EXPECT_TRUE(false) << L"This failure is expected.\x8119";
EXPECT_FATAL_FAILURE({ // NOLINT },
ASSERT_EQ(1, 2) << "This failure is " "This failure is expected.");
<< L"expected too.\x8120"; EXPECT_FATAL_FAILURE(
}, "This failure is expected too."); { // NOLINT
ASSERT_EQ(1, 2) << "This failure is " << L"expected too.\x8120";
},
"This failure is expected too.");
} }
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
...@@ -4423,8 +4360,7 @@ TEST(ExpectTest, EXPECT_TRUE) { ...@@ -4423,8 +4360,7 @@ TEST(ExpectTest, EXPECT_TRUE) {
"Value of: 2 < 1\n" "Value of: 2 < 1\n"
" Actual: false\n" " Actual: false\n"
"Expected: true"); "Expected: true");
EXPECT_NONFATAL_FAILURE(EXPECT_TRUE(2 > 3), EXPECT_NONFATAL_FAILURE(EXPECT_TRUE(2 > 3), "2 > 3");
"2 > 3");
} }
// Tests EXPECT_TRUE(predicate) for predicates returning AssertionResult. // Tests EXPECT_TRUE(predicate) for predicates returning AssertionResult.
...@@ -4453,8 +4389,7 @@ TEST(ExpectTest, EXPECT_FALSE) { ...@@ -4453,8 +4389,7 @@ TEST(ExpectTest, EXPECT_FALSE) {
"Value of: 2 > 1\n" "Value of: 2 > 1\n"
" Actual: true\n" " Actual: true\n"
"Expected: false"); "Expected: false");
EXPECT_NONFATAL_FAILURE(EXPECT_FALSE(2 < 3), EXPECT_NONFATAL_FAILURE(EXPECT_FALSE(2 < 3), "2 < 3");
"2 < 3");
} }
// Tests EXPECT_FALSE(predicate) for predicates returning AssertionResult. // Tests EXPECT_FALSE(predicate) for predicates returning AssertionResult.
...@@ -4473,19 +4408,20 @@ TEST(ExpectTest, ExpectFalseWithAssertionResult) { ...@@ -4473,19 +4408,20 @@ TEST(ExpectTest, ExpectFalseWithAssertionResult) {
#ifdef __BORLANDC__ #ifdef __BORLANDC__
// Restores warnings after previous "#pragma option push" suppressed them // Restores warnings after previous "#pragma option push" suppressed them
# pragma option pop #pragma option pop
#endif #endif
// Tests EXPECT_EQ. // Tests EXPECT_EQ.
TEST(ExpectTest, EXPECT_EQ) { TEST(ExpectTest, EXPECT_EQ) {
EXPECT_EQ(5, 2 + 3); EXPECT_EQ(5, 2 + 3);
// clang-format off
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(5, 2*3), EXPECT_NONFATAL_FAILURE(EXPECT_EQ(5, 2*3),
"Expected equality of these values:\n" "Expected equality of these values:\n"
" 5\n" " 5\n"
" 2*3\n" " 2*3\n"
" Which is: 6"); " Which is: 6");
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(5, 2 - 3), EXPECT_NONFATAL_FAILURE(EXPECT_EQ(5, 2 - 3), "2 - 3");
"2 - 3"); // clang-format on
} }
// Tests using EXPECT_EQ on double values. The purpose is to make // Tests using EXPECT_EQ on double values. The purpose is to make
...@@ -4496,8 +4432,7 @@ TEST(ExpectTest, EXPECT_EQ_Double) { ...@@ -4496,8 +4432,7 @@ TEST(ExpectTest, EXPECT_EQ_Double) {
EXPECT_EQ(5.6, 5.6); EXPECT_EQ(5.6, 5.6);
// A failure. // A failure.
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(5.1, 5.2), EXPECT_NONFATAL_FAILURE(EXPECT_EQ(5.1, 5.2), "5.1");
"5.1");
} }
// Tests EXPECT_EQ(NULL, pointer). // Tests EXPECT_EQ(NULL, pointer).
...@@ -4522,8 +4457,7 @@ TEST(ExpectTest, EXPECT_EQ_0) { ...@@ -4522,8 +4457,7 @@ TEST(ExpectTest, EXPECT_EQ_0) {
EXPECT_EQ(0, n); EXPECT_EQ(0, n);
// A failure. // A failure.
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(0, 5.6), EXPECT_NONFATAL_FAILURE(EXPECT_EQ(0, 5.6), " 0\n 5.6");
" 0\n 5.6");
} }
// Tests EXPECT_NE. // Tests EXPECT_NE.
...@@ -4533,19 +4467,16 @@ TEST(ExpectTest, EXPECT_NE) { ...@@ -4533,19 +4467,16 @@ TEST(ExpectTest, EXPECT_NE) {
EXPECT_NONFATAL_FAILURE(EXPECT_NE('a', 'a'), EXPECT_NONFATAL_FAILURE(EXPECT_NE('a', 'a'),
"Expected: ('a') != ('a'), " "Expected: ('a') != ('a'), "
"actual: 'a' (97, 0x61) vs 'a' (97, 0x61)"); "actual: 'a' (97, 0x61) vs 'a' (97, 0x61)");
EXPECT_NONFATAL_FAILURE(EXPECT_NE(2, 2), EXPECT_NONFATAL_FAILURE(EXPECT_NE(2, 2), "2");
"2");
char* const p0 = nullptr; char* const p0 = nullptr;
EXPECT_NONFATAL_FAILURE(EXPECT_NE(p0, p0), EXPECT_NONFATAL_FAILURE(EXPECT_NE(p0, p0), "p0");
"p0");
// Only way to get the Nokia compiler to compile the cast // Only way to get the Nokia compiler to compile the cast
// is to have a separate void* variable first. Putting // is to have a separate void* variable first. Putting
// the two casts on the same line doesn't work, neither does // the two casts on the same line doesn't work, neither does
// a direct C-style to char*. // a direct C-style to char*.
void* pv1 = (void*)0x1234; // NOLINT void* pv1 = (void*)0x1234; // NOLINT
char* const p1 = reinterpret_cast<char*>(pv1); char* const p1 = reinterpret_cast<char*>(pv1);
EXPECT_NONFATAL_FAILURE(EXPECT_NE(p1, p1), EXPECT_NONFATAL_FAILURE(EXPECT_NE(p1, p1), "p1");
"p1");
} }
// Tests EXPECT_LE. // Tests EXPECT_LE.
...@@ -4554,8 +4485,7 @@ TEST(ExpectTest, EXPECT_LE) { ...@@ -4554,8 +4485,7 @@ TEST(ExpectTest, EXPECT_LE) {
EXPECT_LE(2, 2); EXPECT_LE(2, 2);
EXPECT_NONFATAL_FAILURE(EXPECT_LE(2, 0), EXPECT_NONFATAL_FAILURE(EXPECT_LE(2, 0),
"Expected: (2) <= (0), actual: 2 vs 0"); "Expected: (2) <= (0), actual: 2 vs 0");
EXPECT_NONFATAL_FAILURE(EXPECT_LE(1.1, 0.9), EXPECT_NONFATAL_FAILURE(EXPECT_LE(1.1, 0.9), "(1.1) <= (0.9)");
"(1.1) <= (0.9)");
} }
// Tests EXPECT_LT. // Tests EXPECT_LT.
...@@ -4563,8 +4493,7 @@ TEST(ExpectTest, EXPECT_LT) { ...@@ -4563,8 +4493,7 @@ TEST(ExpectTest, EXPECT_LT) {
EXPECT_LT(2, 3); EXPECT_LT(2, 3);
EXPECT_NONFATAL_FAILURE(EXPECT_LT(2, 2), EXPECT_NONFATAL_FAILURE(EXPECT_LT(2, 2),
"Expected: (2) < (2), actual: 2 vs 2"); "Expected: (2) < (2), actual: 2 vs 2");
EXPECT_NONFATAL_FAILURE(EXPECT_LT(2, 1), EXPECT_NONFATAL_FAILURE(EXPECT_LT(2, 1), "(2) < (1)");
"(2) < (1)");
} }
// Tests EXPECT_GE. // Tests EXPECT_GE.
...@@ -4573,8 +4502,7 @@ TEST(ExpectTest, EXPECT_GE) { ...@@ -4573,8 +4502,7 @@ TEST(ExpectTest, EXPECT_GE) {
EXPECT_GE(2, 2); EXPECT_GE(2, 2);
EXPECT_NONFATAL_FAILURE(EXPECT_GE(2, 3), EXPECT_NONFATAL_FAILURE(EXPECT_GE(2, 3),
"Expected: (2) >= (3), actual: 2 vs 3"); "Expected: (2) >= (3), actual: 2 vs 3");
EXPECT_NONFATAL_FAILURE(EXPECT_GE(0.9, 1.1), EXPECT_NONFATAL_FAILURE(EXPECT_GE(0.9, 1.1), "(0.9) >= (1.1)");
"(0.9) >= (1.1)");
} }
// Tests EXPECT_GT. // Tests EXPECT_GT.
...@@ -4582,8 +4510,7 @@ TEST(ExpectTest, EXPECT_GT) { ...@@ -4582,8 +4510,7 @@ TEST(ExpectTest, EXPECT_GT) {
EXPECT_GT(2, 1); EXPECT_GT(2, 1);
EXPECT_NONFATAL_FAILURE(EXPECT_GT(2, 2), EXPECT_NONFATAL_FAILURE(EXPECT_GT(2, 2),
"Expected: (2) > (2), actual: 2 vs 2"); "Expected: (2) > (2), actual: 2 vs 2");
EXPECT_NONFATAL_FAILURE(EXPECT_GT(2, 3), EXPECT_NONFATAL_FAILURE(EXPECT_GT(2, 3), "(2) > (3)");
"(2) > (3)");
} }
#if GTEST_HAS_EXCEPTIONS #if GTEST_HAS_EXCEPTIONS
...@@ -4594,12 +4521,13 @@ TEST(ExpectTest, EXPECT_THROW) { ...@@ -4594,12 +4521,13 @@ TEST(ExpectTest, EXPECT_THROW) {
EXPECT_NONFATAL_FAILURE(EXPECT_THROW(ThrowAnInteger(), bool), EXPECT_NONFATAL_FAILURE(EXPECT_THROW(ThrowAnInteger(), bool),
"Expected: ThrowAnInteger() throws an exception of " "Expected: ThrowAnInteger() throws an exception of "
"type bool.\n Actual: it throws a different type."); "type bool.\n Actual: it throws a different type.");
EXPECT_NONFATAL_FAILURE(EXPECT_THROW(ThrowRuntimeError("A description"), EXPECT_NONFATAL_FAILURE(
std::logic_error), EXPECT_THROW(ThrowRuntimeError("A description"), std::logic_error),
"Expected: ThrowRuntimeError(\"A description\") " "Expected: ThrowRuntimeError(\"A description\") "
"throws an exception of type std::logic_error.\n " "throws an exception of type std::logic_error.\n "
"Actual: it throws " ERROR_DESC " " "Actual: it throws " ERROR_DESC
"with description \"A description\"."); " "
"with description \"A description\".");
EXPECT_NONFATAL_FAILURE( EXPECT_NONFATAL_FAILURE(
EXPECT_THROW(ThrowNothing(), bool), EXPECT_THROW(ThrowNothing(), bool),
"Expected: ThrowNothing() throws an exception of type bool.\n" "Expected: ThrowNothing() throws an exception of type bool.\n"
...@@ -4615,17 +4543,17 @@ TEST(ExpectTest, EXPECT_NO_THROW) { ...@@ -4615,17 +4543,17 @@ TEST(ExpectTest, EXPECT_NO_THROW) {
EXPECT_NONFATAL_FAILURE(EXPECT_NO_THROW(ThrowRuntimeError("A description")), EXPECT_NONFATAL_FAILURE(EXPECT_NO_THROW(ThrowRuntimeError("A description")),
"Expected: ThrowRuntimeError(\"A description\") " "Expected: ThrowRuntimeError(\"A description\") "
"doesn't throw an exception.\n " "doesn't throw an exception.\n "
"Actual: it throws " ERROR_DESC " " "Actual: it throws " ERROR_DESC
" "
"with description \"A description\"."); "with description \"A description\".");
} }
// Tests EXPECT_ANY_THROW. // Tests EXPECT_ANY_THROW.
TEST(ExpectTest, EXPECT_ANY_THROW) { TEST(ExpectTest, EXPECT_ANY_THROW) {
EXPECT_ANY_THROW(ThrowAnInteger()); EXPECT_ANY_THROW(ThrowAnInteger());
EXPECT_NONFATAL_FAILURE( EXPECT_NONFATAL_FAILURE(EXPECT_ANY_THROW(ThrowNothing()),
EXPECT_ANY_THROW(ThrowNothing()), "Expected: ThrowNothing() throws an exception.\n"
"Expected: ThrowNothing() throws an exception.\n" " Actual: it doesn't.");
" Actual: it doesn't.");
} }
#endif // GTEST_HAS_EXCEPTIONS #endif // GTEST_HAS_EXCEPTIONS
...@@ -4637,7 +4565,6 @@ TEST(ExpectTest, ExpectPrecedence) { ...@@ -4637,7 +4565,6 @@ TEST(ExpectTest, ExpectPrecedence) {
" true && false\n Which is: false"); " true && false\n Which is: false");
} }
// Tests the StreamableToString() function. // Tests the StreamableToString() function.
// Tests using StreamableToString() on a scalar. // Tests using StreamableToString() on a scalar.
...@@ -4675,8 +4602,7 @@ TEST(StreamableToStringTest, NullCString) { ...@@ -4675,8 +4602,7 @@ TEST(StreamableToStringTest, NullCString) {
TEST(StreamableTest, string) { TEST(StreamableTest, string) {
static const std::string str( static const std::string str(
"This failure message is a std::string, and is expected."); "This failure message is a std::string, and is expected.");
EXPECT_FATAL_FAILURE(FAIL() << str, EXPECT_FATAL_FAILURE(FAIL() << str, str.c_str());
str.c_str());
} }
// Tests that we can output strings containing embedded NULs. // Tests that we can output strings containing embedded NULs.
...@@ -4684,25 +4610,24 @@ TEST(StreamableTest, string) { ...@@ -4684,25 +4610,24 @@ TEST(StreamableTest, string) {
TEST(StreamableTest, stringWithEmbeddedNUL) { TEST(StreamableTest, stringWithEmbeddedNUL) {
static const char char_array_with_nul[] = static const char char_array_with_nul[] =
"Here's a NUL\0 and some more string"; "Here's a NUL\0 and some more string";
static const std::string string_with_nul(char_array_with_nul, static const std::string string_with_nul(
sizeof(char_array_with_nul) char_array_with_nul,
- 1); // drops the trailing NUL sizeof(char_array_with_nul) - 1); // drops the trailing NUL
EXPECT_FATAL_FAILURE(FAIL() << string_with_nul, EXPECT_FATAL_FAILURE(FAIL() << string_with_nul,
"Here's a NUL\\0 and some more string"); "Here's a NUL\\0 and some more string");
} }
// Tests that we can output a NUL char. // Tests that we can output a NUL char.
TEST(StreamableTest, NULChar) { TEST(StreamableTest, NULChar) {
EXPECT_FATAL_FAILURE({ // NOLINT EXPECT_FATAL_FAILURE(
FAIL() << "A NUL" << '\0' << " and some more string"; { // NOLINT
}, "A NUL\\0 and some more string"); FAIL() << "A NUL" << '\0' << " and some more string";
},
"A NUL\\0 and some more string");
} }
// Tests using int as an assertion message. // Tests using int as an assertion message.
TEST(StreamableTest, int) { TEST(StreamableTest, int) { EXPECT_FATAL_FAILURE(FAIL() << 900913, "900913"); }
EXPECT_FATAL_FAILURE(FAIL() << 900913,
"900913");
}
// Tests using NULL char pointer as an assertion message. // Tests using NULL char pointer as an assertion message.
// //
...@@ -4716,10 +4641,12 @@ TEST(StreamableTest, NullCharPtr) { ...@@ -4716,10 +4641,12 @@ TEST(StreamableTest, NullCharPtr) {
// Tests that basic IO manipulators (endl, ends, and flush) can be // Tests that basic IO manipulators (endl, ends, and flush) can be
// streamed to testing::Message. // streamed to testing::Message.
TEST(StreamableTest, BasicIoManip) { TEST(StreamableTest, BasicIoManip) {
EXPECT_FATAL_FAILURE({ // NOLINT EXPECT_FATAL_FAILURE(
FAIL() << "Line 1." << std::endl { // NOLINT
<< "A NUL char " << std::ends << std::flush << " in line 2."; FAIL() << "Line 1." << std::endl
}, "Line 1.\nA NUL char \\0 in line 2."); << "A NUL char " << std::ends << std::flush << " in line 2.";
},
"Line 1.\nA NUL char \\0 in line 2.");
} }
// Tests the macros that haven't been covered so far. // Tests the macros that haven't been covered so far.
...@@ -4733,8 +4660,7 @@ void AddFailureHelper(bool* aborted) { ...@@ -4733,8 +4660,7 @@ void AddFailureHelper(bool* aborted) {
// Tests ADD_FAILURE. // Tests ADD_FAILURE.
TEST(MacroTest, ADD_FAILURE) { TEST(MacroTest, ADD_FAILURE) {
bool aborted = true; bool aborted = true;
EXPECT_NONFATAL_FAILURE(AddFailureHelper(&aborted), EXPECT_NONFATAL_FAILURE(AddFailureHelper(&aborted), "Intentional failure.");
"Intentional failure.");
EXPECT_FALSE(aborted); EXPECT_FALSE(aborted);
} }
...@@ -4755,8 +4681,7 @@ TEST(MacroTest, ADD_FAILURE_AT) { ...@@ -4755,8 +4681,7 @@ TEST(MacroTest, ADD_FAILURE_AT) {
// Tests FAIL. // Tests FAIL.
TEST(MacroTest, FAIL) { TEST(MacroTest, FAIL) {
EXPECT_FATAL_FAILURE(FAIL(), EXPECT_FATAL_FAILURE(FAIL(), "Failed");
"Failed");
EXPECT_FATAL_FAILURE(FAIL() << "Intentional failure.", EXPECT_FATAL_FAILURE(FAIL() << "Intentional failure.",
"Intentional failure."); "Intentional failure.");
} }
...@@ -4789,37 +4714,34 @@ TEST(MacroTest, SUCCEED) { ...@@ -4789,37 +4714,34 @@ TEST(MacroTest, SUCCEED) {
// Tests using bool values in {EXPECT|ASSERT}_EQ. // Tests using bool values in {EXPECT|ASSERT}_EQ.
TEST(EqAssertionTest, Bool) { TEST(EqAssertionTest, Bool) {
EXPECT_EQ(true, true); EXPECT_EQ(true, true);
EXPECT_FATAL_FAILURE({ EXPECT_FATAL_FAILURE(
bool false_value = false; {
ASSERT_EQ(false_value, true); bool false_value = false;
}, " false_value\n Which is: false\n true"); ASSERT_EQ(false_value, true);
},
" false_value\n Which is: false\n true");
} }
// Tests using int values in {EXPECT|ASSERT}_EQ. // Tests using int values in {EXPECT|ASSERT}_EQ.
TEST(EqAssertionTest, Int) { TEST(EqAssertionTest, Int) {
ASSERT_EQ(32, 32); ASSERT_EQ(32, 32);
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(32, 33), EXPECT_NONFATAL_FAILURE(EXPECT_EQ(32, 33), " 32\n 33");
" 32\n 33");
} }
// Tests using time_t values in {EXPECT|ASSERT}_EQ. // Tests using time_t values in {EXPECT|ASSERT}_EQ.
TEST(EqAssertionTest, Time_T) { TEST(EqAssertionTest, Time_T) {
EXPECT_EQ(static_cast<time_t>(0), EXPECT_EQ(static_cast<time_t>(0), static_cast<time_t>(0));
static_cast<time_t>(0)); EXPECT_FATAL_FAILURE(
EXPECT_FATAL_FAILURE(ASSERT_EQ(static_cast<time_t>(0), ASSERT_EQ(static_cast<time_t>(0), static_cast<time_t>(1234)), "1234");
static_cast<time_t>(1234)),
"1234");
} }
// Tests using char values in {EXPECT|ASSERT}_EQ. // Tests using char values in {EXPECT|ASSERT}_EQ.
TEST(EqAssertionTest, Char) { TEST(EqAssertionTest, Char) {
ASSERT_EQ('z', 'z'); ASSERT_EQ('z', 'z');
const char ch = 'b'; const char ch = 'b';
EXPECT_NONFATAL_FAILURE(EXPECT_EQ('\0', ch), EXPECT_NONFATAL_FAILURE(EXPECT_EQ('\0', ch), " ch\n Which is: 'b'");
" ch\n Which is: 'b'"); EXPECT_NONFATAL_FAILURE(EXPECT_EQ('a', ch), " ch\n Which is: 'b'");
EXPECT_NONFATAL_FAILURE(EXPECT_EQ('a', ch),
" ch\n Which is: 'b'");
} }
// Tests using wchar_t values in {EXPECT|ASSERT}_EQ. // Tests using wchar_t values in {EXPECT|ASSERT}_EQ.
...@@ -4835,8 +4757,7 @@ TEST(EqAssertionTest, WideChar) { ...@@ -4835,8 +4757,7 @@ TEST(EqAssertionTest, WideChar) {
static wchar_t wchar; static wchar_t wchar;
wchar = L'b'; wchar = L'b';
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(L'a', wchar), EXPECT_NONFATAL_FAILURE(EXPECT_EQ(L'a', wchar), "wchar");
"wchar");
wchar = 0x8119; wchar = 0x8119;
EXPECT_FATAL_FAILURE(ASSERT_EQ(static_cast<wchar_t>(0x8120), wchar), EXPECT_FATAL_FAILURE(ASSERT_EQ(static_cast<wchar_t>(0x8120), wchar),
" wchar\n Which is: L'"); " wchar\n Which is: L'");
...@@ -4855,13 +4776,11 @@ TEST(EqAssertionTest, StdString) { ...@@ -4855,13 +4776,11 @@ TEST(EqAssertionTest, StdString) {
// Compares a const char* to an std::string that has different // Compares a const char* to an std::string that has different
// content // content
EXPECT_NONFATAL_FAILURE(EXPECT_EQ("Test", ::std::string("test")), EXPECT_NONFATAL_FAILURE(EXPECT_EQ("Test", ::std::string("test")), "\"test\"");
"\"test\"");
// Compares an std::string to a char* that has different content. // Compares an std::string to a char* that has different content.
char* const p1 = const_cast<char*>("foo"); char* const p1 = const_cast<char*>("foo");
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(::std::string("bar"), p1), EXPECT_NONFATAL_FAILURE(EXPECT_EQ(::std::string("bar"), p1), "p1");
"p1");
// Compares two std::strings that have different contents, one of // Compares two std::strings that have different contents, one of
// which having a NUL character in the middle. This should fail. // which having a NUL character in the middle. This should fail.
...@@ -4882,28 +4801,31 @@ TEST(EqAssertionTest, StdWideString) { ...@@ -4882,28 +4801,31 @@ TEST(EqAssertionTest, StdWideString) {
// Compares an std::wstring to a const wchar_t* that has identical // Compares an std::wstring to a const wchar_t* that has identical
// content. // content.
const wchar_t kTestX8119[] = { 'T', 'e', 's', 't', 0x8119, '\0' }; const wchar_t kTestX8119[] = {'T', 'e', 's', 't', 0x8119, '\0'};
EXPECT_EQ(::std::wstring(kTestX8119), kTestX8119); EXPECT_EQ(::std::wstring(kTestX8119), kTestX8119);
// Compares an std::wstring to a const wchar_t* that has different // Compares an std::wstring to a const wchar_t* that has different
// content. // content.
const wchar_t kTestX8120[] = { 'T', 'e', 's', 't', 0x8120, '\0' }; const wchar_t kTestX8120[] = {'T', 'e', 's', 't', 0x8120, '\0'};
EXPECT_NONFATAL_FAILURE({ // NOLINT EXPECT_NONFATAL_FAILURE(
EXPECT_EQ(::std::wstring(kTestX8119), kTestX8120); { // NOLINT
}, "kTestX8120"); EXPECT_EQ(::std::wstring(kTestX8119), kTestX8120);
},
"kTestX8120");
// Compares two std::wstrings that have different contents, one of // Compares two std::wstrings that have different contents, one of
// which having a NUL character in the middle. // which having a NUL character in the middle.
::std::wstring wstr3(wstr1); ::std::wstring wstr3(wstr1);
wstr3.at(2) = L'\0'; wstr3.at(2) = L'\0';
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(wstr1, wstr3), EXPECT_NONFATAL_FAILURE(EXPECT_EQ(wstr1, wstr3), "wstr3");
"wstr3");
// Compares a wchar_t* to an std::wstring that has different // Compares a wchar_t* to an std::wstring that has different
// content. // content.
EXPECT_FATAL_FAILURE({ // NOLINT EXPECT_FATAL_FAILURE(
ASSERT_EQ(const_cast<wchar_t*>(L"foo"), ::std::wstring(L"bar")); { // NOLINT
}, ""); ASSERT_EQ(const_cast<wchar_t*>(L"foo"), ::std::wstring(L"bar"));
},
"");
} }
#endif // GTEST_HAS_STD_WSTRING #endif // GTEST_HAS_STD_WSTRING
...@@ -4921,10 +4843,8 @@ TEST(EqAssertionTest, CharPointer) { ...@@ -4921,10 +4843,8 @@ TEST(EqAssertionTest, CharPointer) {
char* const p2 = reinterpret_cast<char*>(pv2); char* const p2 = reinterpret_cast<char*>(pv2);
ASSERT_EQ(p1, p1); ASSERT_EQ(p1, p1);
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(p0, p2), EXPECT_NONFATAL_FAILURE(EXPECT_EQ(p0, p2), " p2\n Which is:");
" p2\n Which is:"); EXPECT_NONFATAL_FAILURE(EXPECT_EQ(p1, p2), " p2\n Which is:");
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(p1, p2),
" p2\n Which is:");
EXPECT_FATAL_FAILURE(ASSERT_EQ(reinterpret_cast<char*>(0x1234), EXPECT_FATAL_FAILURE(ASSERT_EQ(reinterpret_cast<char*>(0x1234),
reinterpret_cast<char*>(0xABC0)), reinterpret_cast<char*>(0xABC0)),
"ABC0"); "ABC0");
...@@ -4943,16 +4863,13 @@ TEST(EqAssertionTest, WideCharPointer) { ...@@ -4943,16 +4863,13 @@ TEST(EqAssertionTest, WideCharPointer) {
wchar_t* const p2 = reinterpret_cast<wchar_t*>(pv2); wchar_t* const p2 = reinterpret_cast<wchar_t*>(pv2);
EXPECT_EQ(p0, p0); EXPECT_EQ(p0, p0);
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(p0, p2), EXPECT_NONFATAL_FAILURE(EXPECT_EQ(p0, p2), " p2\n Which is:");
" p2\n Which is:"); EXPECT_NONFATAL_FAILURE(EXPECT_EQ(p1, p2), " p2\n Which is:");
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(p1, p2),
" p2\n Which is:");
void* pv3 = (void*)0x1234; // NOLINT void* pv3 = (void*)0x1234; // NOLINT
void* pv4 = (void*)0xABC0; // NOLINT void* pv4 = (void*)0xABC0; // NOLINT
const wchar_t* p3 = reinterpret_cast<const wchar_t*>(pv3); const wchar_t* p3 = reinterpret_cast<const wchar_t*>(pv3);
const wchar_t* p4 = reinterpret_cast<const wchar_t*>(pv4); const wchar_t* p4 = reinterpret_cast<const wchar_t*>(pv4);
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(p3, p4), EXPECT_NONFATAL_FAILURE(EXPECT_EQ(p3, p4), "p4");
"p4");
} }
// Tests using other types of pointers in {EXPECT|ASSERT}_EQ. // Tests using other types of pointers in {EXPECT|ASSERT}_EQ.
...@@ -4974,15 +4891,11 @@ class UnprintableChar { ...@@ -4974,15 +4891,11 @@ class UnprintableChar {
bool operator!=(const UnprintableChar& rhs) const { bool operator!=(const UnprintableChar& rhs) const {
return char_ != rhs.char_; return char_ != rhs.char_;
} }
bool operator<(const UnprintableChar& rhs) const { bool operator<(const UnprintableChar& rhs) const { return char_ < rhs.char_; }
return char_ < rhs.char_;
}
bool operator<=(const UnprintableChar& rhs) const { bool operator<=(const UnprintableChar& rhs) const {
return char_ <= rhs.char_; return char_ <= rhs.char_;
} }
bool operator>(const UnprintableChar& rhs) const { bool operator>(const UnprintableChar& rhs) const { return char_ > rhs.char_; }
return char_ > rhs.char_;
}
bool operator>=(const UnprintableChar& rhs) const { bool operator>=(const UnprintableChar& rhs) const {
return char_ >= rhs.char_; return char_ >= rhs.char_;
} }
...@@ -5044,9 +4957,7 @@ class Foo { ...@@ -5044,9 +4957,7 @@ class Foo {
// Tests that the FRIEND_TEST declaration allows a TEST to access a // Tests that the FRIEND_TEST declaration allows a TEST to access a
// class's private members. This should compile. // class's private members. This should compile.
TEST(FRIEND_TEST_Test, TEST) { TEST(FRIEND_TEST_Test, TEST) { ASSERT_EQ(1, Foo().Bar()); }
ASSERT_EQ(1, Foo().Bar());
}
// The fixture needed to test using FRIEND_TEST with TEST_F. // The fixture needed to test using FRIEND_TEST with TEST_F.
class FRIEND_TEST_Test2 : public Test { class FRIEND_TEST_Test2 : public Test {
...@@ -5056,9 +4967,7 @@ class FRIEND_TEST_Test2 : public Test { ...@@ -5056,9 +4967,7 @@ class FRIEND_TEST_Test2 : public Test {
// Tests that the FRIEND_TEST declaration allows a TEST_F to access a // Tests that the FRIEND_TEST declaration allows a TEST_F to access a
// class's private members. This should compile. // class's private members. This should compile.
TEST_F(FRIEND_TEST_Test2, TEST_F) { TEST_F(FRIEND_TEST_Test2, TEST_F) { ASSERT_EQ(1, foo.Bar()); }
ASSERT_EQ(1, foo.Bar());
}
// Tests the life cycle of Test objects. // Tests the life cycle of Test objects.
...@@ -5193,15 +5102,14 @@ class Base { ...@@ -5193,15 +5102,14 @@ class Base {
public: public:
explicit Base(int an_x) : x_(an_x) {} explicit Base(int an_x) : x_(an_x) {}
int x() const { return x_; } int x() const { return x_; }
private: private:
int x_; int x_;
}; };
std::ostream& operator<<(std::ostream& os, std::ostream& operator<<(std::ostream& os, const Base& val) {
const Base& val) {
return os << val.x(); return os << val.x();
} }
std::ostream& operator<<(std::ostream& os, std::ostream& operator<<(std::ostream& os, const Base* pointer) {
const Base* pointer) {
return os << "(" << pointer->x() << ")"; return os << "(" << pointer->x() << ")";
} }
...@@ -5218,7 +5126,7 @@ TEST(MessageTest, CanStreamUserTypeInGlobalNameSpace) { ...@@ -5218,7 +5126,7 @@ TEST(MessageTest, CanStreamUserTypeInGlobalNameSpace) {
namespace { namespace {
class MyTypeInUnnamedNameSpace : public Base { class MyTypeInUnnamedNameSpace : public Base {
public: public:
explicit MyTypeInUnnamedNameSpace(int an_x): Base(an_x) {} explicit MyTypeInUnnamedNameSpace(int an_x) : Base(an_x) {}
}; };
std::ostream& operator<<(std::ostream& os, std::ostream& operator<<(std::ostream& os,
const MyTypeInUnnamedNameSpace& val) { const MyTypeInUnnamedNameSpace& val) {
...@@ -5243,14 +5151,12 @@ TEST(MessageTest, CanStreamUserTypeInUnnamedNameSpace) { ...@@ -5243,14 +5151,12 @@ TEST(MessageTest, CanStreamUserTypeInUnnamedNameSpace) {
namespace namespace1 { namespace namespace1 {
class MyTypeInNameSpace1 : public Base { class MyTypeInNameSpace1 : public Base {
public: public:
explicit MyTypeInNameSpace1(int an_x): Base(an_x) {} explicit MyTypeInNameSpace1(int an_x) : Base(an_x) {}
}; };
std::ostream& operator<<(std::ostream& os, std::ostream& operator<<(std::ostream& os, const MyTypeInNameSpace1& val) {
const MyTypeInNameSpace1& val) {
return os << val.x(); return os << val.x();
} }
std::ostream& operator<<(std::ostream& os, std::ostream& operator<<(std::ostream& os, const MyTypeInNameSpace1* pointer) {
const MyTypeInNameSpace1* pointer) {
return os << "(" << pointer->x() << ")"; return os << "(" << pointer->x() << ")";
} }
} // namespace namespace1 } // namespace namespace1
...@@ -5268,7 +5174,7 @@ TEST(MessageTest, CanStreamUserTypeInUserNameSpace) { ...@@ -5268,7 +5174,7 @@ TEST(MessageTest, CanStreamUserTypeInUserNameSpace) {
namespace namespace2 { namespace namespace2 {
class MyTypeInNameSpace2 : public ::Base { class MyTypeInNameSpace2 : public ::Base {
public: public:
explicit MyTypeInNameSpace2(int an_x): Base(an_x) {} explicit MyTypeInNameSpace2(int an_x) : Base(an_x) {}
}; };
} // namespace namespace2 } // namespace namespace2
std::ostream& operator<<(std::ostream& os, std::ostream& operator<<(std::ostream& os,
...@@ -5299,21 +5205,18 @@ TEST(MessageTest, NullPointers) { ...@@ -5299,21 +5205,18 @@ TEST(MessageTest, NullPointers) {
Message* p6 = nullptr; Message* p6 = nullptr;
msg << p1 << p2 << p3 << p4 << p5 << p6; msg << p1 << p2 << p3 << p4 << p5 << p6;
ASSERT_STREQ("(null)(null)(null)(null)(null)(null)", ASSERT_STREQ("(null)(null)(null)(null)(null)(null)", msg.GetString().c_str());
msg.GetString().c_str());
} }
// Tests streaming wide strings to testing::Message. // Tests streaming wide strings to testing::Message.
TEST(MessageTest, WideStrings) { TEST(MessageTest, WideStrings) {
// Streams a NULL of type const wchar_t*. // Streams a NULL of type const wchar_t*.
const wchar_t* const_wstr = nullptr; const wchar_t* const_wstr = nullptr;
EXPECT_STREQ("(null)", EXPECT_STREQ("(null)", (Message() << const_wstr).GetString().c_str());
(Message() << const_wstr).GetString().c_str());
// Streams a NULL of type wchar_t*. // Streams a NULL of type wchar_t*.
wchar_t* wstr = nullptr; wchar_t* wstr = nullptr;
EXPECT_STREQ("(null)", EXPECT_STREQ("(null)", (Message() << wstr).GetString().c_str());
(Message() << wstr).GetString().c_str());
// Streams a non-NULL of type const wchar_t*. // Streams a non-NULL of type const wchar_t*.
const_wstr = L"abc\x8119"; const_wstr = L"abc\x8119";
...@@ -5322,11 +5225,9 @@ TEST(MessageTest, WideStrings) { ...@@ -5322,11 +5225,9 @@ TEST(MessageTest, WideStrings) {
// Streams a non-NULL of type wchar_t*. // Streams a non-NULL of type wchar_t*.
wstr = const_cast<wchar_t*>(const_wstr); wstr = const_cast<wchar_t*>(const_wstr);
EXPECT_STREQ("abc\xe8\x84\x99", EXPECT_STREQ("abc\xe8\x84\x99", (Message() << wstr).GetString().c_str());
(Message() << wstr).GetString().c_str());
} }
// This line tests that we can define tests in the testing namespace. // This line tests that we can define tests in the testing namespace.
namespace testing { namespace testing {
...@@ -5340,14 +5241,12 @@ class TestInfoTest : public Test { ...@@ -5340,14 +5241,12 @@ class TestInfoTest : public Test {
for (int i = 0; i < test_suite->total_test_count(); ++i) { for (int i = 0; i < test_suite->total_test_count(); ++i) {
const TestInfo* const test_info = test_suite->GetTestInfo(i); const TestInfo* const test_info = test_suite->GetTestInfo(i);
if (strcmp(test_name, test_info->name()) == 0) if (strcmp(test_name, test_info->name()) == 0) return test_info;
return test_info;
} }
return nullptr; return nullptr;
} }
static const TestResult* GetTestResult( static const TestResult* GetTestResult(const TestInfo* test_info) {
const TestInfo* test_info) {
return test_info->result(); return test_info->result();
} }
}; };
...@@ -5371,26 +5270,25 @@ TEST_F(TestInfoTest, result) { ...@@ -5371,26 +5270,25 @@ TEST_F(TestInfoTest, result) {
ASSERT_EQ(0, GetTestResult(test_info)->total_part_count()); ASSERT_EQ(0, GetTestResult(test_info)->total_part_count());
} }
#define VERIFY_CODE_LOCATION \ #define VERIFY_CODE_LOCATION \
const int expected_line = __LINE__ - 1; \ const int expected_line = __LINE__ - 1; \
const TestInfo* const test_info = GetUnitTestImpl()->current_test_info(); \ const TestInfo* const test_info = GetUnitTestImpl()->current_test_info(); \
ASSERT_TRUE(test_info); \ ASSERT_TRUE(test_info); \
EXPECT_STREQ(__FILE__, test_info->file()); \ EXPECT_STREQ(__FILE__, test_info->file()); \
EXPECT_EQ(expected_line, test_info->line()) EXPECT_EQ(expected_line, test_info->line())
// clang-format off
TEST(CodeLocationForTEST, Verify) { TEST(CodeLocationForTEST, Verify) {
VERIFY_CODE_LOCATION; VERIFY_CODE_LOCATION;
} }
class CodeLocationForTESTF : public Test { class CodeLocationForTESTF : public Test {};
};
TEST_F(CodeLocationForTESTF, Verify) { TEST_F(CodeLocationForTESTF, Verify) {
VERIFY_CODE_LOCATION; VERIFY_CODE_LOCATION;
} }
class CodeLocationForTESTP : public TestWithParam<int> { class CodeLocationForTESTP : public TestWithParam<int> {};
};
TEST_P(CodeLocationForTESTP, Verify) { TEST_P(CodeLocationForTESTP, Verify) {
VERIFY_CODE_LOCATION; VERIFY_CODE_LOCATION;
...@@ -5399,8 +5297,7 @@ TEST_P(CodeLocationForTESTP, Verify) { ...@@ -5399,8 +5297,7 @@ TEST_P(CodeLocationForTESTP, Verify) {
INSTANTIATE_TEST_SUITE_P(, CodeLocationForTESTP, Values(0)); INSTANTIATE_TEST_SUITE_P(, CodeLocationForTESTP, Values(0));
template <typename T> template <typename T>
class CodeLocationForTYPEDTEST : public Test { class CodeLocationForTYPEDTEST : public Test {};
};
TYPED_TEST_SUITE(CodeLocationForTYPEDTEST, int); TYPED_TEST_SUITE(CodeLocationForTYPEDTEST, int);
...@@ -5409,8 +5306,7 @@ TYPED_TEST(CodeLocationForTYPEDTEST, Verify) { ...@@ -5409,8 +5306,7 @@ TYPED_TEST(CodeLocationForTYPEDTEST, Verify) {
} }
template <typename T> template <typename T>
class CodeLocationForTYPEDTESTP : public Test { class CodeLocationForTYPEDTESTP : public Test {};
};
TYPED_TEST_SUITE_P(CodeLocationForTYPEDTESTP); TYPED_TEST_SUITE_P(CodeLocationForTYPEDTESTP);
...@@ -5423,6 +5319,7 @@ REGISTER_TYPED_TEST_SUITE_P(CodeLocationForTYPEDTESTP, Verify); ...@@ -5423,6 +5319,7 @@ REGISTER_TYPED_TEST_SUITE_P(CodeLocationForTYPEDTESTP, Verify);
INSTANTIATE_TYPED_TEST_SUITE_P(My, CodeLocationForTYPEDTESTP, int); INSTANTIATE_TYPED_TEST_SUITE_P(My, CodeLocationForTYPEDTESTP, int);
#undef VERIFY_CODE_LOCATION #undef VERIFY_CODE_LOCATION
// clang-format on
// Tests setting up and tearing down a test case. // Tests setting up and tearing down a test case.
// Legacy API is deprecated but still available // Legacy API is deprecated but still available
...@@ -5482,9 +5379,7 @@ const char* SetUpTestCaseTest::shared_resource_ = nullptr; ...@@ -5482,9 +5379,7 @@ const char* SetUpTestCaseTest::shared_resource_ = nullptr;
TEST_F(SetUpTestCaseTest, Test1) { EXPECT_STRNE(nullptr, shared_resource_); } TEST_F(SetUpTestCaseTest, Test1) { EXPECT_STRNE(nullptr, shared_resource_); }
// Another test that uses the shared resource. // Another test that uses the shared resource.
TEST_F(SetUpTestCaseTest, Test2) { TEST_F(SetUpTestCaseTest, Test2) { EXPECT_STREQ("123", shared_resource_); }
EXPECT_STREQ("123", shared_resource_);
}
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
// Tests SetupTestSuite/TearDown TestSuite // Tests SetupTestSuite/TearDown TestSuite
...@@ -5797,22 +5692,22 @@ class ParseFlagsTest : public Test { ...@@ -5797,22 +5692,22 @@ class ParseFlagsTest : public Test {
// verifies that the flag values are expected and that the // verifies that the flag values are expected and that the
// recognized flags are removed from the command line. // recognized flags are removed from the command line.
template <typename CharType> template <typename CharType>
static void TestParsingFlags(int argc1, const CharType** argv1, static void TestParsingFlags(int argc1, const CharType** argv1, int argc2,
int argc2, const CharType** argv2, const CharType** argv2, const Flags& expected,
const Flags& expected, bool should_print_help) { bool should_print_help) {
const bool saved_help_flag = ::testing::internal::g_help_flag; const bool saved_help_flag = ::testing::internal::g_help_flag;
::testing::internal::g_help_flag = false; ::testing::internal::g_help_flag = false;
# if GTEST_HAS_STREAM_REDIRECTION #if GTEST_HAS_STREAM_REDIRECTION
CaptureStdout(); CaptureStdout();
# endif #endif
// Parses the command line. // Parses the command line.
internal::ParseGoogleTestFlagsOnly(&argc1, const_cast<CharType**>(argv1)); internal::ParseGoogleTestFlagsOnly(&argc1, const_cast<CharType**>(argv1));
# if GTEST_HAS_STREAM_REDIRECTION #if GTEST_HAS_STREAM_REDIRECTION
const std::string captured_stdout = GetCapturedStdout(); const std::string captured_stdout = GetCapturedStdout();
# endif #endif
// Verifies the flag values. // Verifies the flag values.
CheckFlags(expected); CheckFlags(expected);
...@@ -5825,16 +5720,16 @@ class ParseFlagsTest : public Test { ...@@ -5825,16 +5720,16 @@ class ParseFlagsTest : public Test {
// help message for the flags it recognizes. // help message for the flags it recognizes.
EXPECT_EQ(should_print_help, ::testing::internal::g_help_flag); EXPECT_EQ(should_print_help, ::testing::internal::g_help_flag);
# if GTEST_HAS_STREAM_REDIRECTION #if GTEST_HAS_STREAM_REDIRECTION
const char* const expected_help_fragment = const char* const expected_help_fragment =
"This program contains tests written using"; "This program contains tests written using";
if (should_print_help) { if (should_print_help) {
EXPECT_PRED_FORMAT2(IsSubstring, expected_help_fragment, captured_stdout); EXPECT_PRED_FORMAT2(IsSubstring, expected_help_fragment, captured_stdout);
} else { } else {
EXPECT_PRED_FORMAT2(IsNotSubstring, EXPECT_PRED_FORMAT2(IsNotSubstring, expected_help_fragment,
expected_help_fragment, captured_stdout); captured_stdout);
} }
# endif // GTEST_HAS_STREAM_REDIRECTION #endif // GTEST_HAS_STREAM_REDIRECTION
::testing::internal::g_help_flag = saved_help_flag; ::testing::internal::g_help_flag = saved_help_flag;
} }
...@@ -5842,10 +5737,10 @@ class ParseFlagsTest : public Test { ...@@ -5842,10 +5737,10 @@ class ParseFlagsTest : public Test {
// This macro wraps TestParsingFlags s.t. the user doesn't need // This macro wraps TestParsingFlags s.t. the user doesn't need
// to specify the array sizes. // to specify the array sizes.
# define GTEST_TEST_PARSING_FLAGS_(argv1, argv2, expected, should_print_help) \ #define GTEST_TEST_PARSING_FLAGS_(argv1, argv2, expected, should_print_help) \
TestParsingFlags(sizeof(argv1)/sizeof(*argv1) - 1, argv1, \ TestParsingFlags(sizeof(argv1) / sizeof(*argv1) - 1, argv1, \
sizeof(argv2)/sizeof(*argv2) - 1, argv2, \ sizeof(argv2) / sizeof(*argv2) - 1, argv2, expected, \
expected, should_print_help) should_print_help)
}; };
// Tests parsing an empty command line. // Tests parsing an empty command line.
...@@ -6070,8 +5965,8 @@ TEST_F(ParseFlagsTest, OutputXmlDirectory) { ...@@ -6070,8 +5965,8 @@ TEST_F(ParseFlagsTest, OutputXmlDirectory) {
const char* argv2[] = {"foo.exe", nullptr}; const char* argv2[] = {"foo.exe", nullptr};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Output("xml:directory/path/"),
Flags::Output("xml:directory/path/"), false); false);
} }
// Tests having a --gtest_brief flag // Tests having a --gtest_brief flag
...@@ -6252,8 +6147,8 @@ TEST_F(ParseFlagsTest, StreamResultTo) { ...@@ -6252,8 +6147,8 @@ TEST_F(ParseFlagsTest, StreamResultTo) {
const char* argv2[] = {"foo.exe", nullptr}; const char* argv2[] = {"foo.exe", nullptr};
GTEST_TEST_PARSING_FLAGS_( GTEST_TEST_PARSING_FLAGS_(argv, argv2,
argv, argv2, Flags::StreamResultTo("localhost:1234"), false); Flags::StreamResultTo("localhost:1234"), false);
} }
// Tests parsing --gtest_throw_on_failure. // Tests parsing --gtest_throw_on_failure.
...@@ -6284,23 +6179,17 @@ TEST_F(ParseFlagsTest, ThrowOnFailureTrue) { ...@@ -6284,23 +6179,17 @@ TEST_F(ParseFlagsTest, ThrowOnFailureTrue) {
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::ThrowOnFailure(true), false); GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::ThrowOnFailure(true), false);
} }
# if GTEST_OS_WINDOWS #if GTEST_OS_WINDOWS
// Tests parsing wide strings. // Tests parsing wide strings.
TEST_F(ParseFlagsTest, WideStrings) { TEST_F(ParseFlagsTest, WideStrings) {
const wchar_t* argv[] = { const wchar_t* argv[] = {L"foo.exe",
L"foo.exe", L"--gtest_filter=Foo*",
L"--gtest_filter=Foo*", L"--gtest_list_tests=1",
L"--gtest_list_tests=1", L"--gtest_break_on_failure",
L"--gtest_break_on_failure", L"--non_gtest_flag",
L"--non_gtest_flag", NULL};
NULL
};
const wchar_t* argv2[] = { const wchar_t* argv2[] = {L"foo.exe", L"--non_gtest_flag", NULL};
L"foo.exe",
L"--non_gtest_flag",
NULL
};
Flags expected_flags; Flags expected_flags;
expected_flags.break_on_failure = true; expected_flags.break_on_failure = true;
...@@ -6309,7 +6198,7 @@ TEST_F(ParseFlagsTest, WideStrings) { ...@@ -6309,7 +6198,7 @@ TEST_F(ParseFlagsTest, WideStrings) {
GTEST_TEST_PARSING_FLAGS_(argv, argv2, expected_flags, false); GTEST_TEST_PARSING_FLAGS_(argv, argv2, expected_flags, false);
} }
# endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
#if GTEST_USE_OWN_FLAGFILE_FLAG_ #if GTEST_USE_OWN_FLAGFILE_FLAG_
class FlagfileTest : public ParseFlagsTest { class FlagfileTest : public ParseFlagsTest {
...@@ -6357,8 +6246,8 @@ TEST_F(FlagfileTest, Empty) { ...@@ -6357,8 +6246,8 @@ TEST_F(FlagfileTest, Empty) {
// Tests passing a non-empty --gtest_filter flag via --gtest_flagfile. // Tests passing a non-empty --gtest_filter flag via --gtest_flagfile.
TEST_F(FlagfileTest, FilterNonEmpty) { TEST_F(FlagfileTest, FilterNonEmpty) {
internal::FilePath flagfile_path(CreateFlagfile( internal::FilePath flagfile_path(
"--" GTEST_FLAG_PREFIX_ "filter=abc")); CreateFlagfile("--" GTEST_FLAG_PREFIX_ "filter=abc"));
std::string flagfile_flag = std::string flagfile_flag =
std::string("--" GTEST_FLAG_PREFIX_ "flagfile=") + flagfile_path.c_str(); std::string("--" GTEST_FLAG_PREFIX_ "flagfile=") + flagfile_path.c_str();
...@@ -6371,10 +6260,10 @@ TEST_F(FlagfileTest, FilterNonEmpty) { ...@@ -6371,10 +6260,10 @@ TEST_F(FlagfileTest, FilterNonEmpty) {
// Tests passing several flags via --gtest_flagfile. // Tests passing several flags via --gtest_flagfile.
TEST_F(FlagfileTest, SeveralFlags) { TEST_F(FlagfileTest, SeveralFlags) {
internal::FilePath flagfile_path(CreateFlagfile( internal::FilePath flagfile_path(
"--" GTEST_FLAG_PREFIX_ "filter=abc\n" CreateFlagfile("--" GTEST_FLAG_PREFIX_ "filter=abc\n"
"--" GTEST_FLAG_PREFIX_ "break_on_failure\n" "--" GTEST_FLAG_PREFIX_ "break_on_failure\n"
"--" GTEST_FLAG_PREFIX_ "list_tests")); "--" GTEST_FLAG_PREFIX_ "list_tests"));
std::string flagfile_flag = std::string flagfile_flag =
std::string("--" GTEST_FLAG_PREFIX_ "flagfile=") + flagfile_path.c_str(); std::string("--" GTEST_FLAG_PREFIX_ "flagfile=") + flagfile_path.c_str();
...@@ -6398,8 +6287,7 @@ class CurrentTestInfoTest : public Test { ...@@ -6398,8 +6287,7 @@ class CurrentTestInfoTest : public Test {
// the test case is run. // the test case is run.
static void SetUpTestSuite() { static void SetUpTestSuite() {
// There should be no tests running at this point. // There should be no tests running at this point.
const TestInfo* test_info = const TestInfo* test_info = UnitTest::GetInstance()->current_test_info();
UnitTest::GetInstance()->current_test_info();
EXPECT_TRUE(test_info == nullptr) EXPECT_TRUE(test_info == nullptr)
<< "There should be no tests running at this point."; << "There should be no tests running at this point.";
} }
...@@ -6407,8 +6295,7 @@ class CurrentTestInfoTest : public Test { ...@@ -6407,8 +6295,7 @@ class CurrentTestInfoTest : public Test {
// Tests that current_test_info() returns NULL after the last test in // Tests that current_test_info() returns NULL after the last test in
// the test case has run. // the test case has run.
static void TearDownTestSuite() { static void TearDownTestSuite() {
const TestInfo* test_info = const TestInfo* test_info = UnitTest::GetInstance()->current_test_info();
UnitTest::GetInstance()->current_test_info();
EXPECT_TRUE(test_info == nullptr) EXPECT_TRUE(test_info == nullptr)
<< "There should be no tests running at this point."; << "There should be no tests running at this point.";
} }
...@@ -6417,8 +6304,7 @@ class CurrentTestInfoTest : public Test { ...@@ -6417,8 +6304,7 @@ class CurrentTestInfoTest : public Test {
// Tests that current_test_info() returns TestInfo for currently running // Tests that current_test_info() returns TestInfo for currently running
// test by checking the expected test name against the actual one. // test by checking the expected test name against the actual one.
TEST_F(CurrentTestInfoTest, WorksForFirstTestInATestSuite) { TEST_F(CurrentTestInfoTest, WorksForFirstTestInATestSuite) {
const TestInfo* test_info = const TestInfo* test_info = UnitTest::GetInstance()->current_test_info();
UnitTest::GetInstance()->current_test_info();
ASSERT_TRUE(nullptr != test_info) ASSERT_TRUE(nullptr != test_info)
<< "There is a test running so we should have a valid TestInfo."; << "There is a test running so we should have a valid TestInfo.";
EXPECT_STREQ("CurrentTestInfoTest", test_info->test_suite_name()) EXPECT_STREQ("CurrentTestInfoTest", test_info->test_suite_name())
...@@ -6432,8 +6318,7 @@ TEST_F(CurrentTestInfoTest, WorksForFirstTestInATestSuite) { ...@@ -6432,8 +6318,7 @@ TEST_F(CurrentTestInfoTest, WorksForFirstTestInATestSuite) {
// use this test to see that the TestInfo object actually changed from // use this test to see that the TestInfo object actually changed from
// the previous invocation. // the previous invocation.
TEST_F(CurrentTestInfoTest, WorksForSecondTestInATestSuite) { TEST_F(CurrentTestInfoTest, WorksForSecondTestInATestSuite) {
const TestInfo* test_info = const TestInfo* test_info = UnitTest::GetInstance()->current_test_info();
UnitTest::GetInstance()->current_test_info();
ASSERT_TRUE(nullptr != test_info) ASSERT_TRUE(nullptr != test_info)
<< "There is a test running so we should have a valid TestInfo."; << "There is a test running so we should have a valid TestInfo.";
EXPECT_STREQ("CurrentTestInfoTest", test_info->test_suite_name()) EXPECT_STREQ("CurrentTestInfoTest", test_info->test_suite_name())
...@@ -6444,7 +6329,6 @@ TEST_F(CurrentTestInfoTest, WorksForSecondTestInATestSuite) { ...@@ -6444,7 +6329,6 @@ TEST_F(CurrentTestInfoTest, WorksForSecondTestInATestSuite) {
} // namespace testing } // namespace testing
// These two lines test that we can define tests in a namespace that // These two lines test that we can define tests in a namespace that
// has the name "testing" and is nested in another namespace. // has the name "testing" and is nested in another namespace.
namespace my_namespace { namespace my_namespace {
...@@ -6493,13 +6377,12 @@ TEST(StreamingAssertionsTest, Unconditional) { ...@@ -6493,13 +6377,12 @@ TEST(StreamingAssertionsTest, Unconditional) {
SUCCEED() << "expected success"; SUCCEED() << "expected success";
EXPECT_NONFATAL_FAILURE(ADD_FAILURE() << "expected failure", EXPECT_NONFATAL_FAILURE(ADD_FAILURE() << "expected failure",
"expected failure"); "expected failure");
EXPECT_FATAL_FAILURE(FAIL() << "expected failure", EXPECT_FATAL_FAILURE(FAIL() << "expected failure", "expected failure");
"expected failure");
} }
#ifdef __BORLANDC__ #ifdef __BORLANDC__
// Silences warnings: "Condition is always true", "Unreachable code" // Silences warnings: "Condition is always true", "Unreachable code"
# pragma option push -w-ccc -w-rch #pragma option push -w-ccc -w-rch
#endif #endif
TEST(StreamingAssertionsTest, Truth) { TEST(StreamingAssertionsTest, Truth) {
...@@ -6522,7 +6405,7 @@ TEST(StreamingAssertionsTest, Truth2) { ...@@ -6522,7 +6405,7 @@ TEST(StreamingAssertionsTest, Truth2) {
#ifdef __BORLANDC__ #ifdef __BORLANDC__
// Restores warnings after previous "#pragma option push" suppressed them // Restores warnings after previous "#pragma option push" suppressed them
# pragma option pop #pragma option pop
#endif #endif
TEST(StreamingAssertionsTest, IntegerEquals) { TEST(StreamingAssertionsTest, IntegerEquals) {
...@@ -6593,28 +6476,32 @@ TEST(StreamingAssertionsTest, FloatingPointEquals) { ...@@ -6593,28 +6476,32 @@ TEST(StreamingAssertionsTest, FloatingPointEquals) {
TEST(StreamingAssertionsTest, Throw) { TEST(StreamingAssertionsTest, Throw) {
EXPECT_THROW(ThrowAnInteger(), int) << "unexpected failure"; EXPECT_THROW(ThrowAnInteger(), int) << "unexpected failure";
ASSERT_THROW(ThrowAnInteger(), int) << "unexpected failure"; ASSERT_THROW(ThrowAnInteger(), int) << "unexpected failure";
EXPECT_NONFATAL_FAILURE(EXPECT_THROW(ThrowAnInteger(), bool) << EXPECT_NONFATAL_FAILURE(EXPECT_THROW(ThrowAnInteger(), bool)
"expected failure", "expected failure"); << "expected failure",
EXPECT_FATAL_FAILURE(ASSERT_THROW(ThrowAnInteger(), bool) << "expected failure");
"expected failure", "expected failure"); EXPECT_FATAL_FAILURE(ASSERT_THROW(ThrowAnInteger(), bool)
<< "expected failure",
"expected failure");
} }
TEST(StreamingAssertionsTest, NoThrow) { TEST(StreamingAssertionsTest, NoThrow) {
EXPECT_NO_THROW(ThrowNothing()) << "unexpected failure"; EXPECT_NO_THROW(ThrowNothing()) << "unexpected failure";
ASSERT_NO_THROW(ThrowNothing()) << "unexpected failure"; ASSERT_NO_THROW(ThrowNothing()) << "unexpected failure";
EXPECT_NONFATAL_FAILURE(EXPECT_NO_THROW(ThrowAnInteger()) << EXPECT_NONFATAL_FAILURE(EXPECT_NO_THROW(ThrowAnInteger())
"expected failure", "expected failure"); << "expected failure",
EXPECT_FATAL_FAILURE(ASSERT_NO_THROW(ThrowAnInteger()) << "expected failure");
"expected failure", "expected failure"); EXPECT_FATAL_FAILURE(ASSERT_NO_THROW(ThrowAnInteger()) << "expected failure",
"expected failure");
} }
TEST(StreamingAssertionsTest, AnyThrow) { TEST(StreamingAssertionsTest, AnyThrow) {
EXPECT_ANY_THROW(ThrowAnInteger()) << "unexpected failure"; EXPECT_ANY_THROW(ThrowAnInteger()) << "unexpected failure";
ASSERT_ANY_THROW(ThrowAnInteger()) << "unexpected failure"; ASSERT_ANY_THROW(ThrowAnInteger()) << "unexpected failure";
EXPECT_NONFATAL_FAILURE(EXPECT_ANY_THROW(ThrowNothing()) << EXPECT_NONFATAL_FAILURE(EXPECT_ANY_THROW(ThrowNothing())
"expected failure", "expected failure"); << "expected failure",
EXPECT_FATAL_FAILURE(ASSERT_ANY_THROW(ThrowNothing()) << "expected failure");
"expected failure", "expected failure"); EXPECT_FATAL_FAILURE(ASSERT_ANY_THROW(ThrowNothing()) << "expected failure",
"expected failure");
} }
#endif // GTEST_HAS_EXCEPTIONS #endif // GTEST_HAS_EXCEPTIONS
...@@ -6624,12 +6511,12 @@ TEST(StreamingAssertionsTest, AnyThrow) { ...@@ -6624,12 +6511,12 @@ TEST(StreamingAssertionsTest, AnyThrow) {
TEST(ColoredOutputTest, UsesColorsWhenGTestColorFlagIsYes) { TEST(ColoredOutputTest, UsesColorsWhenGTestColorFlagIsYes) {
GTEST_FLAG_SET(color, "yes"); GTEST_FLAG_SET(color, "yes");
SetEnv("TERM", "xterm"); // TERM supports colors. SetEnv("TERM", "xterm"); // TERM supports colors.
EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY. EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY.
EXPECT_TRUE(ShouldUseColor(false)); // Stdout is not a TTY. EXPECT_TRUE(ShouldUseColor(false)); // Stdout is not a TTY.
SetEnv("TERM", "dumb"); // TERM doesn't support colors. SetEnv("TERM", "dumb"); // TERM doesn't support colors.
EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY. EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY.
EXPECT_TRUE(ShouldUseColor(false)); // Stdout is not a TTY. EXPECT_TRUE(ShouldUseColor(false)); // Stdout is not a TTY.
} }
...@@ -6649,12 +6536,12 @@ TEST(ColoredOutputTest, UsesColorsWhenGTestColorFlagIsAliasOfYes) { ...@@ -6649,12 +6536,12 @@ TEST(ColoredOutputTest, UsesColorsWhenGTestColorFlagIsAliasOfYes) {
TEST(ColoredOutputTest, UsesNoColorWhenGTestColorFlagIsNo) { TEST(ColoredOutputTest, UsesNoColorWhenGTestColorFlagIsNo) {
GTEST_FLAG_SET(color, "no"); GTEST_FLAG_SET(color, "no");
SetEnv("TERM", "xterm"); // TERM supports colors. SetEnv("TERM", "xterm"); // TERM supports colors.
EXPECT_FALSE(ShouldUseColor(true)); // Stdout is a TTY. EXPECT_FALSE(ShouldUseColor(true)); // Stdout is a TTY.
EXPECT_FALSE(ShouldUseColor(false)); // Stdout is not a TTY. EXPECT_FALSE(ShouldUseColor(false)); // Stdout is not a TTY.
SetEnv("TERM", "dumb"); // TERM doesn't support colors. SetEnv("TERM", "dumb"); // TERM doesn't support colors.
EXPECT_FALSE(ShouldUseColor(true)); // Stdout is a TTY. EXPECT_FALSE(ShouldUseColor(true)); // Stdout is a TTY.
EXPECT_FALSE(ShouldUseColor(false)); // Stdout is not a TTY. EXPECT_FALSE(ShouldUseColor(false)); // Stdout is not a TTY.
} }
...@@ -6674,7 +6561,7 @@ TEST(ColoredOutputTest, UsesNoColorWhenGTestColorFlagIsInvalid) { ...@@ -6674,7 +6561,7 @@ TEST(ColoredOutputTest, UsesNoColorWhenGTestColorFlagIsInvalid) {
TEST(ColoredOutputTest, UsesColorsWhenStdoutIsTty) { TEST(ColoredOutputTest, UsesColorsWhenStdoutIsTty) {
GTEST_FLAG_SET(color, "auto"); GTEST_FLAG_SET(color, "auto");
SetEnv("TERM", "xterm"); // TERM supports colors. SetEnv("TERM", "xterm"); // TERM supports colors.
EXPECT_FALSE(ShouldUseColor(false)); // Stdout is not a TTY. EXPECT_FALSE(ShouldUseColor(false)); // Stdout is not a TTY.
EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY. EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY.
} }
...@@ -6697,49 +6584,49 @@ TEST(ColoredOutputTest, UsesColorsWhenTermSupportsColors) { ...@@ -6697,49 +6584,49 @@ TEST(ColoredOutputTest, UsesColorsWhenTermSupportsColors) {
// On non-Windows platforms, we rely on TERM to determine if the // On non-Windows platforms, we rely on TERM to determine if the
// terminal supports colors. // terminal supports colors.
SetEnv("TERM", "dumb"); // TERM doesn't support colors. SetEnv("TERM", "dumb"); // TERM doesn't support colors.
EXPECT_FALSE(ShouldUseColor(true)); // Stdout is a TTY. EXPECT_FALSE(ShouldUseColor(true)); // Stdout is a TTY.
SetEnv("TERM", "emacs"); // TERM doesn't support colors. SetEnv("TERM", "emacs"); // TERM doesn't support colors.
EXPECT_FALSE(ShouldUseColor(true)); // Stdout is a TTY. EXPECT_FALSE(ShouldUseColor(true)); // Stdout is a TTY.
SetEnv("TERM", "vt100"); // TERM doesn't support colors. SetEnv("TERM", "vt100"); // TERM doesn't support colors.
EXPECT_FALSE(ShouldUseColor(true)); // Stdout is a TTY. EXPECT_FALSE(ShouldUseColor(true)); // Stdout is a TTY.
SetEnv("TERM", "xterm-mono"); // TERM doesn't support colors. SetEnv("TERM", "xterm-mono"); // TERM doesn't support colors.
EXPECT_FALSE(ShouldUseColor(true)); // Stdout is a TTY. EXPECT_FALSE(ShouldUseColor(true)); // Stdout is a TTY.
SetEnv("TERM", "xterm"); // TERM supports colors. SetEnv("TERM", "xterm"); // TERM supports colors.
EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY. EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY.
SetEnv("TERM", "xterm-color"); // TERM supports colors. SetEnv("TERM", "xterm-color"); // TERM supports colors.
EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY. EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY.
SetEnv("TERM", "xterm-256color"); // TERM supports colors. SetEnv("TERM", "xterm-256color"); // TERM supports colors.
EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY. EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY.
SetEnv("TERM", "screen"); // TERM supports colors. SetEnv("TERM", "screen"); // TERM supports colors.
EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY. EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY.
SetEnv("TERM", "screen-256color"); // TERM supports colors. SetEnv("TERM", "screen-256color"); // TERM supports colors.
EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY. EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY.
SetEnv("TERM", "tmux"); // TERM supports colors. SetEnv("TERM", "tmux"); // TERM supports colors.
EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY. EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY.
SetEnv("TERM", "tmux-256color"); // TERM supports colors. SetEnv("TERM", "tmux-256color"); // TERM supports colors.
EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY. EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY.
SetEnv("TERM", "rxvt-unicode"); // TERM supports colors. SetEnv("TERM", "rxvt-unicode"); // TERM supports colors.
EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY. EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY.
SetEnv("TERM", "rxvt-unicode-256color"); // TERM supports colors. SetEnv("TERM", "rxvt-unicode-256color"); // TERM supports colors.
EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY. EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY.
SetEnv("TERM", "linux"); // TERM supports colors. SetEnv("TERM", "linux"); // TERM supports colors.
EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY. EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY.
SetEnv("TERM", "cygwin"); // TERM supports colors. SetEnv("TERM", "cygwin"); // TERM supports colors.
EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY. EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY.
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
} }
...@@ -6859,12 +6746,10 @@ class TestListener : public EmptyTestEventListener { ...@@ -6859,12 +6746,10 @@ class TestListener : public EmptyTestEventListener {
public: public:
TestListener() : on_start_counter_(nullptr), is_destroyed_(nullptr) {} TestListener() : on_start_counter_(nullptr), is_destroyed_(nullptr) {}
TestListener(int* on_start_counter, bool* is_destroyed) TestListener(int* on_start_counter, bool* is_destroyed)
: on_start_counter_(on_start_counter), : on_start_counter_(on_start_counter), is_destroyed_(is_destroyed) {}
is_destroyed_(is_destroyed) {}
~TestListener() override { ~TestListener() override {
if (is_destroyed_) if (is_destroyed_) *is_destroyed_ = true;
*is_destroyed_ = true;
} }
protected: protected:
...@@ -6921,8 +6806,8 @@ TEST(TestEventListenersTest, Append) { ...@@ -6921,8 +6806,8 @@ TEST(TestEventListenersTest, Append) {
{ {
TestEventListeners listeners; TestEventListeners listeners;
listeners.Append(listener); listeners.Append(listener);
TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart( TestEventListenersAccessor::GetRepeater(&listeners)
*UnitTest::GetInstance()); ->OnTestProgramStart(*UnitTest::GetInstance());
EXPECT_EQ(1, on_start_counter); EXPECT_EQ(1, on_start_counter);
} }
EXPECT_TRUE(is_destroyed); EXPECT_TRUE(is_destroyed);
...@@ -6975,32 +6860,32 @@ TEST(EventListenerTest, AppendKeepsOrder) { ...@@ -6975,32 +6860,32 @@ TEST(EventListenerTest, AppendKeepsOrder) {
listeners.Append(new SequenceTestingListener(&vec, "2nd")); listeners.Append(new SequenceTestingListener(&vec, "2nd"));
listeners.Append(new SequenceTestingListener(&vec, "3rd")); listeners.Append(new SequenceTestingListener(&vec, "3rd"));
TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart( TestEventListenersAccessor::GetRepeater(&listeners)
*UnitTest::GetInstance()); ->OnTestProgramStart(*UnitTest::GetInstance());
ASSERT_EQ(3U, vec.size()); ASSERT_EQ(3U, vec.size());
EXPECT_STREQ("1st.OnTestProgramStart", vec[0].c_str()); EXPECT_STREQ("1st.OnTestProgramStart", vec[0].c_str());
EXPECT_STREQ("2nd.OnTestProgramStart", vec[1].c_str()); EXPECT_STREQ("2nd.OnTestProgramStart", vec[1].c_str());
EXPECT_STREQ("3rd.OnTestProgramStart", vec[2].c_str()); EXPECT_STREQ("3rd.OnTestProgramStart", vec[2].c_str());
vec.clear(); vec.clear();
TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramEnd( TestEventListenersAccessor::GetRepeater(&listeners)
*UnitTest::GetInstance()); ->OnTestProgramEnd(*UnitTest::GetInstance());
ASSERT_EQ(3U, vec.size()); ASSERT_EQ(3U, vec.size());
EXPECT_STREQ("3rd.OnTestProgramEnd", vec[0].c_str()); EXPECT_STREQ("3rd.OnTestProgramEnd", vec[0].c_str());
EXPECT_STREQ("2nd.OnTestProgramEnd", vec[1].c_str()); EXPECT_STREQ("2nd.OnTestProgramEnd", vec[1].c_str());
EXPECT_STREQ("1st.OnTestProgramEnd", vec[2].c_str()); EXPECT_STREQ("1st.OnTestProgramEnd", vec[2].c_str());
vec.clear(); vec.clear();
TestEventListenersAccessor::GetRepeater(&listeners)->OnTestIterationStart( TestEventListenersAccessor::GetRepeater(&listeners)
*UnitTest::GetInstance(), 0); ->OnTestIterationStart(*UnitTest::GetInstance(), 0);
ASSERT_EQ(3U, vec.size()); ASSERT_EQ(3U, vec.size());
EXPECT_STREQ("1st.OnTestIterationStart", vec[0].c_str()); EXPECT_STREQ("1st.OnTestIterationStart", vec[0].c_str());
EXPECT_STREQ("2nd.OnTestIterationStart", vec[1].c_str()); EXPECT_STREQ("2nd.OnTestIterationStart", vec[1].c_str());
EXPECT_STREQ("3rd.OnTestIterationStart", vec[2].c_str()); EXPECT_STREQ("3rd.OnTestIterationStart", vec[2].c_str());
vec.clear(); vec.clear();
TestEventListenersAccessor::GetRepeater(&listeners)->OnTestIterationEnd( TestEventListenersAccessor::GetRepeater(&listeners)
*UnitTest::GetInstance(), 0); ->OnTestIterationEnd(*UnitTest::GetInstance(), 0);
ASSERT_EQ(3U, vec.size()); ASSERT_EQ(3U, vec.size());
EXPECT_STREQ("3rd.OnTestIterationEnd", vec[0].c_str()); EXPECT_STREQ("3rd.OnTestIterationEnd", vec[0].c_str());
EXPECT_STREQ("2nd.OnTestIterationEnd", vec[1].c_str()); EXPECT_STREQ("2nd.OnTestIterationEnd", vec[1].c_str());
...@@ -7020,8 +6905,8 @@ TEST(TestEventListenersTest, Release) { ...@@ -7020,8 +6905,8 @@ TEST(TestEventListenersTest, Release) {
TestEventListeners listeners; TestEventListeners listeners;
listeners.Append(listener); listeners.Append(listener);
EXPECT_EQ(listener, listeners.Release(listener)); EXPECT_EQ(listener, listeners.Release(listener));
TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart( TestEventListenersAccessor::GetRepeater(&listeners)
*UnitTest::GetInstance()); ->OnTestProgramStart(*UnitTest::GetInstance());
EXPECT_TRUE(listeners.Release(listener) == nullptr); EXPECT_TRUE(listeners.Release(listener) == nullptr);
} }
EXPECT_EQ(0, on_start_counter); EXPECT_EQ(0, on_start_counter);
...@@ -7039,17 +6924,20 @@ TEST(EventListenerTest, SuppressEventForwarding) { ...@@ -7039,17 +6924,20 @@ TEST(EventListenerTest, SuppressEventForwarding) {
ASSERT_TRUE(TestEventListenersAccessor::EventForwardingEnabled(listeners)); ASSERT_TRUE(TestEventListenersAccessor::EventForwardingEnabled(listeners));
TestEventListenersAccessor::SuppressEventForwarding(&listeners); TestEventListenersAccessor::SuppressEventForwarding(&listeners);
ASSERT_FALSE(TestEventListenersAccessor::EventForwardingEnabled(listeners)); ASSERT_FALSE(TestEventListenersAccessor::EventForwardingEnabled(listeners));
TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart( TestEventListenersAccessor::GetRepeater(&listeners)
*UnitTest::GetInstance()); ->OnTestProgramStart(*UnitTest::GetInstance());
EXPECT_EQ(0, on_start_counter); EXPECT_EQ(0, on_start_counter);
} }
// Tests that events generated by Google Test are not forwarded in // Tests that events generated by Google Test are not forwarded in
// death test subprocesses. // death test subprocesses.
TEST(EventListenerDeathTest, EventsNotForwardedInDeathTestSubprecesses) { TEST(EventListenerDeathTest, EventsNotForwardedInDeathTestSubprecesses) {
EXPECT_DEATH_IF_SUPPORTED({ EXPECT_DEATH_IF_SUPPORTED(
GTEST_CHECK_(TestEventListenersAccessor::EventForwardingEnabled( {
*GetUnitTestImpl()->listeners())) << "expected failure";}, GTEST_CHECK_(TestEventListenersAccessor::EventForwardingEnabled(
*GetUnitTestImpl()->listeners()))
<< "expected failure";
},
"expected failure"); "expected failure");
} }
...@@ -7066,8 +6954,8 @@ TEST(EventListenerTest, default_result_printer) { ...@@ -7066,8 +6954,8 @@ TEST(EventListenerTest, default_result_printer) {
EXPECT_EQ(listener, listeners.default_result_printer()); EXPECT_EQ(listener, listeners.default_result_printer());
TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart( TestEventListenersAccessor::GetRepeater(&listeners)
*UnitTest::GetInstance()); ->OnTestProgramStart(*UnitTest::GetInstance());
EXPECT_EQ(1, on_start_counter); EXPECT_EQ(1, on_start_counter);
...@@ -7080,8 +6968,8 @@ TEST(EventListenerTest, default_result_printer) { ...@@ -7080,8 +6968,8 @@ TEST(EventListenerTest, default_result_printer) {
// After broadcasting an event the counter is still the same, indicating // After broadcasting an event the counter is still the same, indicating
// the listener is not in the list anymore. // the listener is not in the list anymore.
TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart( TestEventListenersAccessor::GetRepeater(&listeners)
*UnitTest::GetInstance()); ->OnTestProgramStart(*UnitTest::GetInstance());
EXPECT_EQ(1, on_start_counter); EXPECT_EQ(1, on_start_counter);
} }
...@@ -7103,8 +6991,8 @@ TEST(EventListenerTest, RemovingDefaultResultPrinterWorks) { ...@@ -7103,8 +6991,8 @@ TEST(EventListenerTest, RemovingDefaultResultPrinterWorks) {
EXPECT_FALSE(is_destroyed); EXPECT_FALSE(is_destroyed);
// Broadcasting events now should not affect default_result_printer. // Broadcasting events now should not affect default_result_printer.
TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart( TestEventListenersAccessor::GetRepeater(&listeners)
*UnitTest::GetInstance()); ->OnTestProgramStart(*UnitTest::GetInstance());
EXPECT_EQ(0, on_start_counter); EXPECT_EQ(0, on_start_counter);
} }
// Destroying the list should not affect the listener now, too. // Destroying the list should not affect the listener now, too.
...@@ -7125,8 +7013,8 @@ TEST(EventListenerTest, default_xml_generator) { ...@@ -7125,8 +7013,8 @@ TEST(EventListenerTest, default_xml_generator) {
EXPECT_EQ(listener, listeners.default_xml_generator()); EXPECT_EQ(listener, listeners.default_xml_generator());
TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart( TestEventListenersAccessor::GetRepeater(&listeners)
*UnitTest::GetInstance()); ->OnTestProgramStart(*UnitTest::GetInstance());
EXPECT_EQ(1, on_start_counter); EXPECT_EQ(1, on_start_counter);
...@@ -7139,8 +7027,8 @@ TEST(EventListenerTest, default_xml_generator) { ...@@ -7139,8 +7027,8 @@ TEST(EventListenerTest, default_xml_generator) {
// After broadcasting an event the counter is still the same, indicating // After broadcasting an event the counter is still the same, indicating
// the listener is not in the list anymore. // the listener is not in the list anymore.
TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart( TestEventListenersAccessor::GetRepeater(&listeners)
*UnitTest::GetInstance()); ->OnTestProgramStart(*UnitTest::GetInstance());
EXPECT_EQ(1, on_start_counter); EXPECT_EQ(1, on_start_counter);
} }
...@@ -7162,8 +7050,8 @@ TEST(EventListenerTest, RemovingDefaultXmlGeneratorWorks) { ...@@ -7162,8 +7050,8 @@ TEST(EventListenerTest, RemovingDefaultXmlGeneratorWorks) {
EXPECT_FALSE(is_destroyed); EXPECT_FALSE(is_destroyed);
// Broadcasting events now should not affect default_xml_generator. // Broadcasting events now should not affect default_xml_generator.
TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart( TestEventListenersAccessor::GetRepeater(&listeners)
*UnitTest::GetInstance()); ->OnTestProgramStart(*UnitTest::GetInstance());
EXPECT_EQ(0, on_start_counter); EXPECT_EQ(0, on_start_counter);
} }
// Destroying the list should not affect the listener now, too. // Destroying the list should not affect the listener now, too.
...@@ -7323,7 +7211,6 @@ TEST(GTestReferenceToConstTest, Works) { ...@@ -7323,7 +7211,6 @@ TEST(GTestReferenceToConstTest, Works) {
TestGTestReferenceToConst<const std::string&, const std::string&>(); TestGTestReferenceToConst<const std::string&, const std::string&>();
} }
// Tests IsContainerTest. // Tests IsContainerTest.
class NonContainer {}; class NonContainer {};
...@@ -7335,10 +7222,9 @@ TEST(IsContainerTestTest, WorksForNonContainer) { ...@@ -7335,10 +7222,9 @@ TEST(IsContainerTestTest, WorksForNonContainer) {
} }
TEST(IsContainerTestTest, WorksForContainer) { TEST(IsContainerTestTest, WorksForContainer) {
EXPECT_EQ(sizeof(IsContainer), sizeof(IsContainerTest<std::vector<bool>>(0)));
EXPECT_EQ(sizeof(IsContainer), EXPECT_EQ(sizeof(IsContainer),
sizeof(IsContainerTest<std::vector<bool> >(0))); sizeof(IsContainerTest<std::map<int, double>>(0)));
EXPECT_EQ(sizeof(IsContainer),
sizeof(IsContainerTest<std::map<int, double> >(0)));
} }
struct ConstOnlyContainerWithPointerIterator { struct ConstOnlyContainerWithPointerIterator {
...@@ -7387,8 +7273,8 @@ TEST(ArrayEqTest, WorksForDegeneratedArrays) { ...@@ -7387,8 +7273,8 @@ TEST(ArrayEqTest, WorksForDegeneratedArrays) {
TEST(ArrayEqTest, WorksForOneDimensionalArrays) { TEST(ArrayEqTest, WorksForOneDimensionalArrays) {
// Note that a and b are distinct but compatible types. // Note that a and b are distinct but compatible types.
const int a[] = { 0, 1 }; const int a[] = {0, 1};
long b[] = { 0, 1 }; long b[] = {0, 1};
EXPECT_TRUE(ArrayEq(a, b)); EXPECT_TRUE(ArrayEq(a, b));
EXPECT_TRUE(ArrayEq(a, 2, b)); EXPECT_TRUE(ArrayEq(a, 2, b));
...@@ -7398,9 +7284,9 @@ TEST(ArrayEqTest, WorksForOneDimensionalArrays) { ...@@ -7398,9 +7284,9 @@ TEST(ArrayEqTest, WorksForOneDimensionalArrays) {
} }
TEST(ArrayEqTest, WorksForTwoDimensionalArrays) { TEST(ArrayEqTest, WorksForTwoDimensionalArrays) {
const char a[][3] = { "hi", "lo" }; const char a[][3] = {"hi", "lo"};
const char b[][3] = { "hi", "lo" }; const char b[][3] = {"hi", "lo"};
const char c[][3] = { "hi", "li" }; const char c[][3] = {"hi", "li"};
EXPECT_TRUE(ArrayEq(a, b)); EXPECT_TRUE(ArrayEq(a, b));
EXPECT_TRUE(ArrayEq(a, 2, b)); EXPECT_TRUE(ArrayEq(a, 2, b));
...@@ -7418,11 +7304,11 @@ TEST(ArrayAwareFindTest, WorksForOneDimensionalArray) { ...@@ -7418,11 +7304,11 @@ TEST(ArrayAwareFindTest, WorksForOneDimensionalArray) {
} }
TEST(ArrayAwareFindTest, WorksForTwoDimensionalArray) { TEST(ArrayAwareFindTest, WorksForTwoDimensionalArray) {
int a[][2] = { { 0, 1 }, { 2, 3 }, { 4, 5 } }; int a[][2] = {{0, 1}, {2, 3}, {4, 5}};
const int b[2] = { 2, 3 }; const int b[2] = {2, 3};
EXPECT_EQ(a + 1, ArrayAwareFind(a, a + 3, b)); EXPECT_EQ(a + 1, ArrayAwareFind(a, a + 3, b));
const int c[2] = { 6, 7 }; const int c[2] = {6, 7};
EXPECT_EQ(a + 3, ArrayAwareFind(a, a + 3, c)); EXPECT_EQ(a + 3, ArrayAwareFind(a, a + 3, c));
} }
...@@ -7448,7 +7334,7 @@ TEST(CopyArrayTest, WorksForOneDimensionalArrays) { ...@@ -7448,7 +7334,7 @@ TEST(CopyArrayTest, WorksForOneDimensionalArrays) {
} }
TEST(CopyArrayTest, WorksForTwoDimensionalArrays) { TEST(CopyArrayTest, WorksForTwoDimensionalArrays) {
const int a[2][3] = { { 0, 1, 2 }, { 3, 4, 5 } }; const int a[2][3] = {{0, 1, 2}, {3, 4, 5}};
int b[2][3]; int b[2][3];
#ifndef __BORLANDC__ // C++Builder cannot compile some array size deductions. #ifndef __BORLANDC__ // C++Builder cannot compile some array size deductions.
CopyArray(a, &b); CopyArray(a, &b);
...@@ -7463,7 +7349,7 @@ TEST(CopyArrayTest, WorksForTwoDimensionalArrays) { ...@@ -7463,7 +7349,7 @@ TEST(CopyArrayTest, WorksForTwoDimensionalArrays) {
// Tests NativeArray. // Tests NativeArray.
TEST(NativeArrayTest, ConstructorFromArrayWorks) { TEST(NativeArrayTest, ConstructorFromArrayWorks) {
const int a[3] = { 0, 1, 2 }; const int a[3] = {0, 1, 2};
NativeArray<int> na(a, 3, RelationToSourceReference()); NativeArray<int> na(a, 3, RelationToSourceReference());
EXPECT_EQ(3U, na.size()); EXPECT_EQ(3U, na.size());
EXPECT_EQ(a, na.begin()); EXPECT_EQ(a, na.begin());
...@@ -7493,7 +7379,7 @@ TEST(NativeArrayTest, TypeMembersAreCorrect) { ...@@ -7493,7 +7379,7 @@ TEST(NativeArrayTest, TypeMembersAreCorrect) {
} }
TEST(NativeArrayTest, MethodsWork) { TEST(NativeArrayTest, MethodsWork) {
const int a[3] = { 0, 1, 2 }; const int a[3] = {0, 1, 2};
NativeArray<int> na(a, 3, RelationToSourceCopy()); NativeArray<int> na(a, 3, RelationToSourceCopy());
ASSERT_EQ(3U, na.size()); ASSERT_EQ(3U, na.size());
EXPECT_EQ(3, na.end() - na.begin()); EXPECT_EQ(3, na.end() - na.begin());
...@@ -7512,14 +7398,14 @@ TEST(NativeArrayTest, MethodsWork) { ...@@ -7512,14 +7398,14 @@ TEST(NativeArrayTest, MethodsWork) {
NativeArray<int> na2(a, 3, RelationToSourceReference()); NativeArray<int> na2(a, 3, RelationToSourceReference());
EXPECT_TRUE(na == na2); EXPECT_TRUE(na == na2);
const int b1[3] = { 0, 1, 1 }; const int b1[3] = {0, 1, 1};
const int b2[4] = { 0, 1, 2, 3 }; const int b2[4] = {0, 1, 2, 3};
EXPECT_FALSE(na == NativeArray<int>(b1, 3, RelationToSourceReference())); EXPECT_FALSE(na == NativeArray<int>(b1, 3, RelationToSourceReference()));
EXPECT_FALSE(na == NativeArray<int>(b2, 4, RelationToSourceCopy())); EXPECT_FALSE(na == NativeArray<int>(b2, 4, RelationToSourceCopy()));
} }
TEST(NativeArrayTest, WorksForTwoDimensionalArray) { TEST(NativeArrayTest, WorksForTwoDimensionalArray) {
const char a[2][3] = { "hi", "lo" }; const char a[2][3] = {"hi", "lo"};
NativeArray<char[3]> na(a, 2, RelationToSourceReference()); NativeArray<char[3]> na(a, 2, RelationToSourceReference());
ASSERT_EQ(2U, na.size()); ASSERT_EQ(2U, na.size());
EXPECT_EQ(a, na.begin()); EXPECT_EQ(a, na.begin());
......
...@@ -35,18 +35,18 @@ ...@@ -35,18 +35,18 @@
// //
// This program will be invoked from a Python unit test. Don't run it // This program will be invoked from a Python unit test. Don't run it
// directly. // directly.
// clang-format off
#include "gtest/gtest.h" #include "gtest/gtest.h"
using ::testing::InitGoogleTest; using ::testing::InitGoogleTest;
using ::testing::Test;
using ::testing::TestEventListeners; using ::testing::TestEventListeners;
using ::testing::TestWithParam; using ::testing::TestWithParam;
using ::testing::UnitTest; using ::testing::UnitTest;
using ::testing::Test;
using ::testing::Values; using ::testing::Values;
class SuccessfulTest : public Test { class SuccessfulTest : public Test {};
};
TEST_F(SuccessfulTest, Succeeds) { TEST_F(SuccessfulTest, Succeeds) {
SUCCEED() << "This is a success."; SUCCEED() << "This is a success.";
...@@ -191,3 +191,5 @@ int main(int argc, char** argv) { ...@@ -191,3 +191,5 @@ int main(int argc, char** argv) {
testing::Test::RecordProperty("ad_hoc_property", "42"); testing::Test::RecordProperty("ad_hoc_property", "42");
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
} }
// clang-format on
...@@ -46,6 +46,7 @@ class PrivateCode { ...@@ -46,6 +46,7 @@ class PrivateCode {
PrivateCode(); PrivateCode();
int x() const { return x_; } int x() const { return x_; }
private: private:
void set_x(int an_x) { x_ = an_x; } void set_x(int an_x) { x_ = an_x; }
int x_; int x_;
......
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