39 TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) {
68 #include <type_traits>
69 #include <unordered_set>
87 static_assert(
sizeof(decltype(std::declval<ConvertibleGlobalType&>()
89 "error in operator<< overload resolution");
94 #if GTEST_CAN_STREAM_RESULTS_
96 class StreamingListenerTest :
public Test {
98 class FakeSocketWriter :
public StreamingListener::AbstractSocketWriter {
101 void Send(
const std::string& message)
override { output_ += message; }
106 StreamingListenerTest()
107 : fake_sock_writer_(new FakeSocketWriter),
108 streamer_(fake_sock_writer_),
109 test_info_obj_(
"FooTest",
"Bar", nullptr, nullptr,
110 CodeLocation(__FILE__, __LINE__), nullptr, nullptr) {}
113 std::string* output() {
return &(fake_sock_writer_->output_); }
115 FakeSocketWriter*
const fake_sock_writer_;
116 StreamingListener streamer_;
121 TEST_F(StreamingListenerTest, OnTestProgramEnd) {
123 streamer_.OnTestProgramEnd(unit_test_);
124 EXPECT_EQ(
"event=TestProgramEnd&passed=1\n", *output());
127 TEST_F(StreamingListenerTest, OnTestIterationEnd) {
129 streamer_.OnTestIterationEnd(unit_test_, 42);
130 EXPECT_EQ(
"event=TestIterationEnd&passed=1&elapsed_time=0ms\n", *output());
133 TEST_F(StreamingListenerTest, OnTestSuiteStart) {
135 streamer_.OnTestSuiteStart(TestSuite(
"FooTest",
"Bar",
nullptr,
nullptr));
136 EXPECT_EQ(
"event=TestCaseStart&name=FooTest\n", *output());
139 TEST_F(StreamingListenerTest, OnTestSuiteEnd) {
141 streamer_.OnTestSuiteEnd(TestSuite(
"FooTest",
"Bar",
nullptr,
nullptr));
142 EXPECT_EQ(
"event=TestCaseEnd&passed=1&elapsed_time=0ms\n", *output());
145 TEST_F(StreamingListenerTest, OnTestStart) {
147 streamer_.OnTestStart(test_info_obj_);
148 EXPECT_EQ(
"event=TestStart&name=Bar\n", *output());
151 TEST_F(StreamingListenerTest, OnTestEnd) {
153 streamer_.OnTestEnd(test_info_obj_);
154 EXPECT_EQ(
"event=TestEnd&passed=1&elapsed_time=0ms\n", *output());
157 TEST_F(StreamingListenerTest, OnTestPartResult) {
159 streamer_.OnTestPartResult(TestPartResult(TestPartResult::kFatalFailure,
160 "foo.cc", 42,
"failed=\n&%"));
164 "event=TestPartResult&file=foo.cc&line=42&message=failed%3D%0A%26%25\n",
168 #endif // GTEST_CAN_STREAM_RESULTS_
212 using testing::AssertionResult;
222 using testing::ScopedFakeTestPartResultReporter;
227 using testing::TestPartResult;
228 using testing::TestPartResultArray;
280 #if GTEST_HAS_STREAM_REDIRECTION
285 #ifdef GTEST_IS_THREADSAFE
286 using testing::internal::ThreadWithParam;
293 for (
size_t i = 0;
i < vector.size();
i++) {
294 os << vector[
i] <<
" ";
303 TEST(GetRandomSeedFromFlagTest, HandlesZero) {
309 TEST(GetRandomSeedFromFlagTest, PreservesValidSeed) {
317 TEST(GetRandomSeedFromFlagTest, NormalizesInvalidSeed) {
327 TEST(GetNextRandomSeedTest, WorksForValidInput) {
340 static void ClearCurrentTestPartResults() {
341 TestResultAccessor::ClearTestPartResults(
347 TEST(GetTypeIdTest, ReturnsSameValueForSameType) {
348 EXPECT_EQ(GetTypeId<int>(), GetTypeId<int>());
349 EXPECT_EQ(GetTypeId<Test>(), GetTypeId<Test>());
352 class SubClassOfTest :
public Test {};
353 class AnotherSubClassOfTest :
public Test {};
355 TEST(GetTypeIdTest, ReturnsDifferentValuesForDifferentTypes) {
356 EXPECT_NE(GetTypeId<int>(), GetTypeId<const int>());
357 EXPECT_NE(GetTypeId<int>(), GetTypeId<char>());
361 EXPECT_NE(GetTypeId<AnotherSubClassOfTest>(), GetTypeId<SubClassOfTest>());
366 TEST(GetTestTypeIdTest, ReturnsTheSameValueInsideOrOutsideOfGoogleTest) {
397 TEST(FormatTimeInMillisAsSecondsTest, FormatsZero) {
401 TEST(FormatTimeInMillisAsSecondsTest, FormatsPositiveNumber) {
413 TEST(FormatTimeInMillisAsSecondsTest, FormatsNegativeNumber) {
427 #if !defined(__EMSCRIPTEN__)
434 class FormatEpochTimeInMillisAsIso8601Test :
public Test {
442 void SetUp()
override {
446 if (const
char* tz = getenv("TZ")) {
447 saved_tz_ = std::make_unique<std::string>(tz);
453 SetTimeZone("UTC+00");
456 void TearDown()
override {
457 SetTimeZone(saved_tz_ !=
nullptr ? saved_tz_->c_str() :
nullptr);
461 static void SetTimeZone(
const char* time_zone) {
465 #if defined(_MSC_VER) || defined(GTEST_OS_WINDOWS_MINGW)
468 const std::string env_var =
469 std::string(
"TZ=") + (time_zone ? time_zone :
"");
470 _putenv(env_var.c_str());
475 #if defined(GTEST_OS_LINUX_ANDROID) && __ANDROID_API__ < 21
478 setenv(
"TZ",
"UTC", 1);
482 setenv((
"TZ"), time_zone, 1);
490 std::unique_ptr<std::string> saved_tz_;
493 const TimeInMillis FormatEpochTimeInMillisAsIso8601Test::kMillisPerSec;
495 TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsTwoDigitSegments) {
500 TEST_F(FormatEpochTimeInMillisAsIso8601Test, IncludesMillisecondsAfterDot) {
505 TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsLeadingZeroes) {
510 TEST_F(FormatEpochTimeInMillisAsIso8601Test, Prints24HourTime) {
515 TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsEpochStart) {
519 #endif // __EMSCRIPTEN__
523 #pragma option push -w-ccc -w-rch
528 TEST(NullLiteralTest, LHSAllowsNullLiterals) {
529 EXPECT_EQ(0, static_cast<void*>(
nullptr));
530 ASSERT_EQ(0, static_cast<void*>(
nullptr));
531 EXPECT_EQ(NULL, static_cast<void*>(
nullptr));
532 ASSERT_EQ(NULL, static_cast<void*>(
nullptr));
533 EXPECT_EQ(
nullptr, static_cast<void*>(
nullptr));
534 ASSERT_EQ(
nullptr, static_cast<void*>(
nullptr));
536 const int*
const p =
nullptr;
545 struct ConvertToAll {
546 template <
typename T>
552 struct ConvertToPointer {
554 operator T*()
const {
559 struct ConvertToAllButNoPointers {
560 template <
typename T,
570 TEST(NullLiteralTest, ImplicitConversion) {
571 EXPECT_EQ(ConvertToPointer{},
static_cast<void*
>(
nullptr));
572 #if !defined(__GNUC__) || defined(__clang__)
574 EXPECT_EQ(ConvertToAll{},
static_cast<void*
>(
nullptr));
581 #pragma clang diagnostic push
582 #if __has_warning("-Wzero-as-null-pointer-constant")
583 #pragma clang diagnostic error "-Wzero-as-null-pointer-constant"
587 TEST(NullLiteralTest, NoConversionNoWarning) {
595 #pragma clang diagnostic pop
607 TEST(CodePointToUtf8Test, CanEncodeNul) {
612 TEST(CodePointToUtf8Test, CanEncodeAscii) {
621 TEST(CodePointToUtf8Test, CanEncode8To11Bits) {
634 TEST(CodePointToUtf8Test, CanEncode12To16Bits) {
642 #if !GTEST_WIDE_STRING_USES_UTF16_
649 TEST(CodePointToUtf8Test, CanEncode17To21Bits) {
661 TEST(CodePointToUtf8Test, CanEncodeInvalidCodePoint) {
665 #endif // !GTEST_WIDE_STRING_USES_UTF16_
670 TEST(WideStringToUtf8Test, CanEncodeNul) {
676 TEST(WideStringToUtf8Test, CanEncodeAscii) {
685 TEST(WideStringToUtf8Test, CanEncode8To11Bits) {
691 const wchar_t s[] = {0x576,
'\0'};
698 TEST(WideStringToUtf8Test, CanEncode12To16Bits) {
700 const wchar_t s1[] = {0x8D3,
'\0'};
705 const wchar_t s2[] = {0xC74D,
'\0'};
711 TEST(WideStringToUtf8Test, StopsOnNulCharacter) {
717 TEST(WideStringToUtf8Test, StopsWhenLengthLimitReached) {
721 #if !GTEST_WIDE_STRING_USES_UTF16_
725 TEST(WideStringToUtf8Test, CanEncode17To21Bits) {
736 TEST(WideStringToUtf8Test, CanEncodeInvalidCodePoint) {
740 #else // !GTEST_WIDE_STRING_USES_UTF16_
743 TEST(WideStringToUtf8Test, CanEncodeValidUtf16SUrrogatePairs) {
744 const wchar_t s[] = {0xD801, 0xDC00,
'\0'};
750 TEST(WideStringToUtf8Test, CanEncodeInvalidUtf16SurrogatePair) {
752 const wchar_t s1[] = {0xD800,
'\0'};
755 const wchar_t s2[] = {0xD800,
'M',
'\0'};
758 const wchar_t s3[] = {0xDC00,
'P',
'Q',
'R',
'\0'};
761 #endif // !GTEST_WIDE_STRING_USES_UTF16_
764 #if !GTEST_WIDE_STRING_USES_UTF16_
765 TEST(WideStringToUtf8Test, ConcatenatesCodepointsCorrectly) {
766 const wchar_t s[] = {0x108634, 0xC74D,
'\n', 0x576, 0x8D3, 0x108634,
'\0'};
777 TEST(WideStringToUtf8Test, ConcatenatesCodepointsCorrectly) {
778 const wchar_t s[] = {0xC74D,
'\n', 0x576, 0x8D3,
'\0'};
786 #endif // !GTEST_WIDE_STRING_USES_UTF16_
790 TEST(RandomDeathTest, GeneratesCrashesOnInvalidRange) {
793 "Cannot generate a number in the range \\[0, 0\\)");
796 "Generation of a number in \\[0, 2147483649\\) was requested, "
797 "but this can only generate numbers in \\[0, 2147483648\\)");
800 TEST(RandomTest, GeneratesNumbersWithinRange) {
801 constexpr uint32_t kRange = 10000;
803 for (
int i = 0;
i < 10;
i++) {
804 EXPECT_LT(random.Generate(kRange), kRange) <<
" for iteration " <<
i;
808 for (
int i = 0;
i < 10;
i++) {
809 EXPECT_LT(random2.Generate(kRange), kRange) <<
" for iteration " <<
i;
813 TEST(RandomTest, RepeatsWhenReseeded) {
814 constexpr
int kSeed = 123;
815 constexpr
int kArraySize = 10;
816 constexpr uint32_t kRange = 10000;
817 uint32_t values[kArraySize];
820 for (
int i = 0;
i < kArraySize;
i++) {
821 values[
i] = random.Generate(kRange);
824 random.Reseed(kSeed);
825 for (
int i = 0;
i < kArraySize;
i++) {
826 EXPECT_EQ(values[
i], random.Generate(kRange)) <<
" for iteration " << i;
834 static bool IsPositive(
int n) {
return n > 0; }
852 static int g_sum = 0;
853 static void Accumulate(
int n) { g_sum += n; }
895 "Invalid shuffle range start -1: must be in range \\[0, 3\\]");
898 "Invalid shuffle range start 4: must be in range \\[0, 3\\]");
901 "Invalid shuffle range finish 2: must be in range \\[3, 3\\]");
904 "Invalid shuffle range finish 4: must be in range \\[3, 3\\]");
907 class VectorShuffleTest :
public Test {
909 static const size_t kVectorSize = 20;
911 VectorShuffleTest() : random_(1) {
912 for (
int i = 0; i < static_cast<int>(kVectorSize);
i++) {
913 vector_.push_back(
i);
918 if (kVectorSize != vector.size()) {
922 bool found_in_vector[kVectorSize] = {
false};
923 for (
size_t i = 0;
i < vector.size();
i++) {
924 const int e = vector[
i];
925 if (e < 0 || e >= static_cast<int>(kVectorSize) || found_in_vector[e]) {
928 found_in_vector[e] =
true;
936 static bool VectorIsNotCorrupt(
const TestingVector& vector) {
937 return !VectorIsCorrupt(vector);
940 static bool RangeIsShuffled(
const TestingVector& vector,
int begin,
int end) {
941 for (
int i = begin;
i < end;
i++) {
942 if (
i != vector[static_cast<size_t>(
i)]) {
949 static bool RangeIsUnshuffled(
const TestingVector& vector,
int begin,
951 return !RangeIsShuffled(vector, begin, end);
955 return RangeIsShuffled(vector, 0, static_cast<int>(vector.size()));
958 static bool VectorIsUnshuffled(
const TestingVector& vector) {
959 return !VectorIsShuffled(vector);
966 const size_t VectorShuffleTest::kVectorSize;
968 TEST_F(VectorShuffleTest, HandlesEmptyRange) {
975 ShuffleRange(&random_, kVectorSize / 2, kVectorSize / 2, &vector_);
980 ShuffleRange(&random_, kVectorSize - 1, kVectorSize - 1, &vector_);
985 ShuffleRange(&random_, kVectorSize, kVectorSize, &vector_);
990 TEST_F(VectorShuffleTest, HandlesRangeOfSizeOne) {
997 ShuffleRange(&random_, kVectorSize / 2, kVectorSize / 2 + 1, &vector_);
1002 ShuffleRange(&random_, kVectorSize - 1, kVectorSize, &vector_);
1010 TEST_F(VectorShuffleTest, ShufflesEntireVector) {
1018 EXPECT_NE(static_cast<int>(kVectorSize - 1), vector_[kVectorSize - 1]);
1021 TEST_F(VectorShuffleTest, ShufflesStartOfVector) {
1022 const int kRangeSize = kVectorSize / 2;
1029 static_cast<int>(kVectorSize));
1032 TEST_F(VectorShuffleTest, ShufflesEndOfVector) {
1033 const int kRangeSize = kVectorSize / 2;
1034 ShuffleRange(&random_, kRangeSize, kVectorSize, &vector_);
1037 EXPECT_PRED3(RangeIsUnshuffled, vector_, 0, kRangeSize);
1039 static_cast<int>(kVectorSize));
1042 TEST_F(VectorShuffleTest, ShufflesMiddleOfVector) {
1043 const int kRangeSize =
static_cast<int>(kVectorSize) / 3;
1044 ShuffleRange(&random_, kRangeSize, 2 * kRangeSize, &vector_);
1047 EXPECT_PRED3(RangeIsUnshuffled, vector_, 0, kRangeSize);
1048 EXPECT_PRED3(RangeIsShuffled, vector_, kRangeSize, 2 * kRangeSize);
1049 EXPECT_PRED3(RangeIsUnshuffled, vector_, 2 * kRangeSize,
1050 static_cast<int>(kVectorSize));
1053 TEST_F(VectorShuffleTest, ShufflesRepeatably) {
1055 for (
size_t i = 0;
i < kVectorSize;
i++) {
1056 vector2.push_back(static_cast<int>(
i));
1059 random_.Reseed(1234);
1061 random_.Reseed(1234);
1067 for (
size_t i = 0;
i < kVectorSize;
i++) {
1068 EXPECT_EQ(vector_[
i], vector2[i]) <<
" where i is " <<
i;
1074 TEST(AssertHelperTest, AssertHelperIsSmall) {
1081 TEST(StringTest, EndsWithCaseInsensitive) {
1082 EXPECT_TRUE(String::EndsWithCaseInsensitive(
"foobar",
"BAR"));
1083 EXPECT_TRUE(String::EndsWithCaseInsensitive(
"foobaR",
"bar"));
1084 EXPECT_TRUE(String::EndsWithCaseInsensitive(
"foobar",
""));
1085 EXPECT_TRUE(String::EndsWithCaseInsensitive(
"",
""));
1087 EXPECT_FALSE(String::EndsWithCaseInsensitive(
"Foobar",
"foo"));
1088 EXPECT_FALSE(String::EndsWithCaseInsensitive(
"foobar",
"Foo"));
1089 EXPECT_FALSE(String::EndsWithCaseInsensitive(
"",
"foo"));
1095 static const wchar_t*
const kNull =
nullptr;
1098 TEST(StringTest, CaseInsensitiveWideCStringEquals) {
1099 EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(
nullptr,
nullptr));
1100 EXPECT_FALSE(String::CaseInsensitiveWideCStringEquals(kNull, L
""));
1101 EXPECT_FALSE(String::CaseInsensitiveWideCStringEquals(L
"", kNull));
1102 EXPECT_FALSE(String::CaseInsensitiveWideCStringEquals(kNull, L
"foobar"));
1103 EXPECT_FALSE(String::CaseInsensitiveWideCStringEquals(L
"foobar", kNull));
1104 EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(L
"foobar", L
"foobar"));
1105 EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(L
"foobar", L
"FOOBAR"));
1106 EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(L
"FOOBAR", L
"foobar"));
1109 #ifdef GTEST_OS_WINDOWS
1112 TEST(StringTest, ShowWideCString) {
1113 EXPECT_STREQ(
"(null)", String::ShowWideCString(NULL).c_str());
1114 EXPECT_STREQ(
"", String::ShowWideCString(L
"").c_str());
1115 EXPECT_STREQ(
"foo", String::ShowWideCString(L
"foo").c_str());
1118 #ifdef GTEST_OS_WINDOWS_MOBILE
1119 TEST(StringTest, AnsiAndUtf16Null) {
1120 EXPECT_EQ(NULL, String::AnsiToUtf16(NULL));
1121 EXPECT_EQ(NULL, String::Utf16ToAnsi(NULL));
1124 TEST(StringTest, AnsiAndUtf16ConvertBasic) {
1125 const char* ansi = String::Utf16ToAnsi(L
"str");
1128 const WCHAR* utf16 = String::AnsiToUtf16(
"str");
1129 EXPECT_EQ(0, wcsncmp(L
"str", utf16, 3));
1133 TEST(StringTest, AnsiAndUtf16ConvertPathChars) {
1134 const char* ansi = String::Utf16ToAnsi(L
".:\\ \"*?");
1137 const WCHAR* utf16 = String::AnsiToUtf16(
".:\\ \"*?");
1138 EXPECT_EQ(0, wcsncmp(L
".:\\ \"*?", utf16, 3));
1141 #endif // GTEST_OS_WINDOWS_MOBILE
1143 #endif // GTEST_OS_WINDOWS
1146 TEST(TestPropertyTest, StringValue) {
1153 TEST(TestPropertyTest, ReplaceStringValue) {
1156 property.SetValue(
"2");
1163 static void AddFatalFailure() {
FAIL() <<
"Expected fatal failure."; }
1165 static void AddNonfatalFailure() {
1169 class ScopedFakeTestPartResultReporterTest :
public Test {
1171 enum FailureMode { FATAL_FAILURE, NONFATAL_FAILURE };
1172 static void AddFailure(FailureMode failure) {
1173 if (failure == FATAL_FAILURE) {
1176 AddNonfatalFailure();
1183 TEST_F(ScopedFakeTestPartResultReporterTest, InterceptsTestFailures) {
1184 TestPartResultArray results;
1186 ScopedFakeTestPartResultReporter reporter(
1187 ScopedFakeTestPartResultReporter::INTERCEPT_ONLY_CURRENT_THREAD,
1189 AddFailure(NONFATAL_FAILURE);
1190 AddFailure(FATAL_FAILURE);
1194 EXPECT_TRUE(results.GetTestPartResult(0).nonfatally_failed());
1195 EXPECT_TRUE(results.GetTestPartResult(1).fatally_failed());
1198 TEST_F(ScopedFakeTestPartResultReporterTest, DeprecatedConstructor) {
1199 TestPartResultArray results;
1202 ScopedFakeTestPartResultReporter reporter(&results);
1203 AddFailure(NONFATAL_FAILURE);
1208 #ifdef GTEST_IS_THREADSAFE
1210 class ScopedFakeTestPartResultReporterWithThreadsTest
1211 :
public ScopedFakeTestPartResultReporterTest {
1213 static void AddFailureInOtherThread(FailureMode failure) {
1214 ThreadWithParam<FailureMode> thread(&AddFailure, failure,
nullptr);
1219 TEST_F(ScopedFakeTestPartResultReporterWithThreadsTest,
1220 InterceptsTestFailuresInAllThreads) {
1221 TestPartResultArray results;
1223 ScopedFakeTestPartResultReporter reporter(
1224 ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS, &results);
1225 AddFailure(NONFATAL_FAILURE);
1226 AddFailure(FATAL_FAILURE);
1227 AddFailureInOtherThread(NONFATAL_FAILURE);
1228 AddFailureInOtherThread(FATAL_FAILURE);
1232 EXPECT_TRUE(results.GetTestPartResult(0).nonfatally_failed());
1233 EXPECT_TRUE(results.GetTestPartResult(1).fatally_failed());
1234 EXPECT_TRUE(results.GetTestPartResult(2).nonfatally_failed());
1235 EXPECT_TRUE(results.GetTestPartResult(3).fatally_failed());
1238 #endif // GTEST_IS_THREADSAFE
1244 typedef ScopedFakeTestPartResultReporterTest ExpectFatalFailureTest;
1246 TEST_F(ExpectFatalFailureTest, CatchesFatalFaliure) {
1250 TEST_F(ExpectFatalFailureTest, AcceptsStdStringObject) {
1252 ::std::string(
"Expected fatal failure."));
1255 TEST_F(ExpectFatalFailureTest, CatchesFatalFailureOnAllThreads) {
1259 "Expected fatal failure.");
1264 #pragma option push -w-ccc
1270 int NonVoidFunction() {
1276 TEST_F(ExpectFatalFailureTest, CanBeUsedInNonVoidFunction) {
1283 void DoesNotAbortHelper(
bool* aborted) {
1295 TEST_F(ExpectFatalFailureTest, DoesNotAbort) {
1296 bool aborted =
true;
1297 DoesNotAbortHelper(&aborted);
1305 static int global_var = 0;
1306 #define GTEST_USE_UNPROTECTED_COMMA_ global_var++, global_var++
1308 TEST_F(ExpectFatalFailureTest, AcceptsMacroThatExpandsToUnprotectedComma) {
1309 #ifndef __BORLANDC__
1329 typedef ScopedFakeTestPartResultReporterTest ExpectNonfatalFailureTest;
1331 TEST_F(ExpectNonfatalFailureTest, CatchesNonfatalFailure) {
1335 TEST_F(ExpectNonfatalFailureTest, AcceptsStdStringObject) {
1337 ::std::string(
"Expected non-fatal failure."));
1340 TEST_F(ExpectNonfatalFailureTest, CatchesNonfatalFailureOnAllThreads) {
1344 "Expected non-fatal failure.");
1350 TEST_F(ExpectNonfatalFailureTest, AcceptsMacroThatExpandsToUnprotectedComma) {
1354 AddNonfatalFailure();
1361 AddNonfatalFailure();
1366 #ifdef GTEST_IS_THREADSAFE
1368 typedef ScopedFakeTestPartResultReporterWithThreadsTest
1369 ExpectFailureWithThreadsTest;
1371 TEST_F(ExpectFailureWithThreadsTest, ExpectFatalFailureOnAllThreads) {
1373 "Expected fatal failure.");
1376 TEST_F(ExpectFailureWithThreadsTest, ExpectNonFatalFailureOnAllThreads) {
1378 AddFailureInOtherThread(NONFATAL_FAILURE),
"Expected non-fatal failure.");
1381 #endif // GTEST_IS_THREADSAFE
1385 TEST(TestPropertyTest, ConstructorWorks) {
1391 TEST(TestPropertyTest, SetValue) {
1394 property.SetValue(
"value_2");
1402 class TestResultTest :
public Test {
1404 typedef std::vector<TestPartResult> TPRVector;
1407 TestPartResult *pr1, *pr2;
1412 void SetUp()
override {
1414 pr1 =
new TestPartResult(TestPartResult::kSuccess,
"foo/bar.cc", 10,
1418 pr2 =
new TestPartResult(TestPartResult::kFatalFailure,
"foo/bar.cc",
1431 TPRVector* results1 =
1432 const_cast<TPRVector*
>(&TestResultAccessor::test_part_results(*r1));
1433 TPRVector* results2 =
1434 const_cast<TPRVector*
>(&TestResultAccessor::test_part_results(*r2));
1439 results1->push_back(*pr1);
1442 results2->push_back(*pr1);
1443 results2->push_back(*pr2);
1446 void TearDown()
override {
1456 static void CompareTestPartResult(
const TestPartResult&
expected,
1457 const TestPartResult& actual) {
1458 EXPECT_EQ(expected.type(), actual.type());
1459 EXPECT_STREQ(expected.file_name(), actual.file_name());
1460 EXPECT_EQ(expected.line_number(), actual.line_number());
1463 EXPECT_EQ(expected.passed(), actual.passed());
1464 EXPECT_EQ(expected.failed(), actual.failed());
1465 EXPECT_EQ(expected.nonfatally_failed(), actual.nonfatally_failed());
1466 EXPECT_EQ(expected.fatally_failed(), actual.fatally_failed());
1471 TEST_F(TestResultTest, total_part_count) {
1478 TEST_F(TestResultTest, Passed) {
1485 TEST_F(TestResultTest, Failed) {
1493 typedef TestResultTest TestResultDeathTest;
1495 TEST_F(TestResultDeathTest, GetTestPartResult) {
1496 CompareTestPartResult(*pr1, r2->GetTestPartResult(0));
1497 CompareTestPartResult(*pr2, r2->GetTestPartResult(1));
1503 TEST(TestResultPropertyTest, NoPropertiesFoundWhenNoneAreAdded) {
1509 TEST(TestResultPropertyTest, OnePropertyFoundWhenAdded) {
1512 TestResultAccessor::RecordProperty(&test_result,
"testcase", property);
1520 TEST(TestResultPropertyTest, MultiplePropertiesFoundWhenAdded) {
1524 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_1);
1525 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_2);
1537 TEST(TestResultPropertyTest, OverridesValuesForDuplicateKeys) {
1543 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_1_1);
1544 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_2_1);
1545 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_1_2);
1546 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_2_2);
1559 TEST(TestResultPropertyTest, GetTestProperty) {
1564 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_1);
1565 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_2);
1566 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_3);
1597 class GTestFlagSaverTest :
public Test {
1602 static void SetUpTestSuite() {
1627 static void TearDownTestSuite() {
1634 void VerifyAndModifyFlags() {
1685 TEST_F(GTestFlagSaverTest, ModifyGTestFlags) { VerifyAndModifyFlags(); }
1689 TEST_F(GTestFlagSaverTest, VerifyGTestFlags) { VerifyAndModifyFlags(); }
1694 static void SetEnv(
const char* name,
const char*
value) {
1695 #ifdef GTEST_OS_WINDOWS_MOBILE
1698 #elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9)
1702 static std::map<std::string, std::string*> added_env;
1706 std::string* prev_env = NULL;
1707 if (added_env.find(name) != added_env.end()) {
1708 prev_env = added_env[name];
1711 new std::string((
Message() << name <<
"=" << value).GetString());
1716 putenv(const_cast<char*>(added_env[name]->c_str()));
1718 #elif defined(GTEST_OS_WINDOWS) // If we are on Windows proper.
1719 _putenv((
Message() << name <<
"=" << value).GetString().c_str());
1721 if (*value ==
'\0') {
1724 setenv(name, value, 1);
1726 #endif // GTEST_OS_WINDOWS_MOBILE
1729 #ifndef GTEST_OS_WINDOWS_MOBILE
1738 TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenVariableIsNotSet) {
1743 #if !defined(GTEST_GET_INT32_FROM_ENV_)
1747 TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenValueOverflows) {
1748 printf(
"(expecting 2 warnings)\n");
1759 TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenValueIsInvalid) {
1760 printf(
"(expecting 2 warnings)\n");
1769 #endif // !defined(GTEST_GET_INT32_FROM_ENV_)
1774 TEST(Int32FromGTestEnvTest, ParsesAndReturnsValidValue) {
1781 #endif // !GTEST_OS_WINDOWS_MOBILE
1787 TEST(ParseInt32FlagTest, ReturnsFalseForInvalidFlag) {
1788 int32_t value = 123;
1798 TEST(ParseInt32FlagTest, ReturnsDefaultWhenValueOverflows) {
1799 printf(
"(expecting 2 warnings)\n");
1801 int32_t value = 123;
1812 TEST(ParseInt32FlagTest, ReturnsDefaultWhenValueIsInvalid) {
1813 printf(
"(expecting 2 warnings)\n");
1815 int32_t value = 123;
1826 TEST(ParseInt32FlagTest, ParsesAndReturnsValidValue) {
1827 int32_t value = 123;
1838 #ifndef GTEST_OS_WINDOWS_MOBILE
1839 TEST(Int32FromEnvOrDieTest, ParsesAndReturnsValidValue) {
1846 #endif // !GTEST_OS_WINDOWS_MOBILE
1850 TEST(Int32FromEnvOrDieDeathTest, AbortsOnFailure) {
1858 TEST(Int32FromEnvOrDieDeathTest, AbortsOnInt32Overflow) {
1866 TEST(ShouldRunTestOnShardTest, IsPartitionWhenThereIsOneShard) {
1876 void SetUp()
override {
1881 void TearDown()
override {
1882 SetEnv(index_var_,
"");
1883 SetEnv(total_var_,
"");
1886 const char* index_var_;
1887 const char* total_var_;
1892 TEST_F(ShouldShardTest, ReturnsFalseWhenNeitherEnvVarIsSet) {
1893 SetEnv(index_var_,
"");
1894 SetEnv(total_var_,
"");
1901 TEST_F(ShouldShardTest, ReturnsFalseWhenTotalShardIsOne) {
1902 SetEnv(index_var_,
"0");
1903 SetEnv(total_var_,
"1");
1911 #ifndef GTEST_OS_WINDOWS_MOBILE
1912 TEST_F(ShouldShardTest, WorksWhenShardEnvVarsAreValid) {
1913 SetEnv(index_var_,
"4");
1914 SetEnv(total_var_,
"22");
1918 SetEnv(index_var_,
"8");
1919 SetEnv(total_var_,
"9");
1923 SetEnv(index_var_,
"0");
1924 SetEnv(total_var_,
"9");
1928 #endif // !GTEST_OS_WINDOWS_MOBILE
1932 typedef ShouldShardTest ShouldShardDeathTest;
1934 TEST_F(ShouldShardDeathTest, AbortsWhenShardingEnvVarsAreInvalid) {
1935 SetEnv(index_var_,
"4");
1936 SetEnv(total_var_,
"4");
1939 SetEnv(index_var_,
"4");
1940 SetEnv(total_var_,
"-2");
1943 SetEnv(index_var_,
"5");
1944 SetEnv(total_var_,
"");
1947 SetEnv(index_var_,
"");
1948 SetEnv(total_var_,
"5");
1954 TEST(ShouldRunTestOnShardTest, IsPartitionWhenThereAreFiveShards) {
1956 const int num_tests = 17;
1957 const int num_shards = 5;
1960 for (
int test_id = 0; test_id < num_tests; test_id++) {
1961 int prev_selected_shard_index = -1;
1962 for (
int shard_index = 0; shard_index < num_shards; shard_index++) {
1964 if (prev_selected_shard_index < 0) {
1965 prev_selected_shard_index = shard_index;
1967 ADD_FAILURE() <<
"Shard " << prev_selected_shard_index <<
" and "
1968 << shard_index <<
" are both selected to run test "
1977 for (
int shard_index = 0; shard_index < num_shards; shard_index++) {
1978 int num_tests_on_shard = 0;
1979 for (
int test_id = 0; test_id < num_tests; test_id++) {
1980 num_tests_on_shard +=
1983 EXPECT_GE(num_tests_on_shard, num_tests / num_shards);
1997 TEST(UnitTestTest, CanGetOriginalWorkingDir) {
1998 ASSERT_TRUE(UnitTest::GetInstance()->original_working_dir() !=
nullptr);
1999 EXPECT_STRNE(UnitTest::GetInstance()->original_working_dir(),
"");
2002 TEST(UnitTestTest, ReturnsPlausibleTimestamp) {
2003 EXPECT_LT(0, UnitTest::GetInstance()->start_timestamp());
2010 void ExpectNonFatalFailureRecordingPropertyWithReservedKey(
2011 const TestResult& test_result,
const char* key) {
2014 <<
"Property for key '" << key <<
"' recorded unexpectedly.";
2017 void ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2021 ExpectNonFatalFailureRecordingPropertyWithReservedKey(*test_info->
result(),
2025 void ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2030 ExpectNonFatalFailureRecordingPropertyWithReservedKey(
2034 void ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2036 ExpectNonFatalFailureRecordingPropertyWithReservedKey(
2037 UnitTest::GetInstance()->ad_hoc_test_result(), key);
2043 class UnitTestRecordPropertyTest
2046 static void SetUpTestSuite() {
2047 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2049 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2051 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2053 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2055 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2057 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2060 Test::RecordProperty(
"test_case_key_1",
"1");
2063 UnitTest::GetInstance()->current_test_suite();
2076 TEST_F(UnitTestRecordPropertyTest, OnePropertyFoundWhenAdded) {
2077 UnitTestRecordProperty(
"key_1",
"1");
2079 ASSERT_EQ(1, unit_test_.ad_hoc_test_result().test_property_count());
2082 unit_test_.ad_hoc_test_result().GetTestProperty(0).key());
2083 EXPECT_STREQ(
"1", unit_test_.ad_hoc_test_result().GetTestProperty(0).value());
2087 TEST_F(UnitTestRecordPropertyTest, MultiplePropertiesFoundWhenAdded) {
2088 UnitTestRecordProperty(
"key_1",
"1");
2089 UnitTestRecordProperty(
"key_2",
"2");
2091 ASSERT_EQ(2, unit_test_.ad_hoc_test_result().test_property_count());
2094 unit_test_.ad_hoc_test_result().GetTestProperty(0).key());
2095 EXPECT_STREQ(
"1", unit_test_.ad_hoc_test_result().GetTestProperty(0).value());
2098 unit_test_.ad_hoc_test_result().GetTestProperty(1).key());
2099 EXPECT_STREQ(
"2", unit_test_.ad_hoc_test_result().GetTestProperty(1).value());
2103 TEST_F(UnitTestRecordPropertyTest, OverridesValuesForDuplicateKeys) {
2104 UnitTestRecordProperty(
"key_1",
"1");
2105 UnitTestRecordProperty(
"key_2",
"2");
2106 UnitTestRecordProperty(
"key_1",
"12");
2107 UnitTestRecordProperty(
"key_2",
"22");
2109 ASSERT_EQ(2, unit_test_.ad_hoc_test_result().test_property_count());
2112 unit_test_.ad_hoc_test_result().GetTestProperty(0).key());
2114 unit_test_.ad_hoc_test_result().GetTestProperty(0).value());
2117 unit_test_.ad_hoc_test_result().GetTestProperty(1).key());
2119 unit_test_.ad_hoc_test_result().GetTestProperty(1).value());
2122 TEST_F(UnitTestRecordPropertyTest,
2123 AddFailureInsideTestsWhenUsingTestSuiteReservedKeys) {
2124 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
"name");
2125 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2127 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2129 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
"status");
2130 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
"time");
2131 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2135 TEST_F(UnitTestRecordPropertyTest,
2136 AddRecordWithReservedKeysGeneratesCorrectPropertyList) {
2138 Test::RecordProperty(
"name",
"1"),
2139 "'classname', 'name', 'status', 'time', 'type_param', 'value_param',"
2140 " 'file', and 'line' are reserved");
2143 class UnitTestRecordPropertyTestEnvironment :
public Environment {
2145 void TearDown()
override {
2146 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2148 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2150 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2152 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2154 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2156 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2158 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2160 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2178 bool IsEven(
int n) {
return (n % 2) == 0; }
2181 struct IsEvenFunctor {
2182 bool operator()(
int n) {
return IsEven(n); }
2187 AssertionResult AssertIsEven(
const char* expr,
int n) {
2193 msg << expr <<
" evaluates to " << n <<
", which is not even.";
2199 AssertionResult ResultIsEven(
int n) {
2209 AssertionResult ResultIsEvenNoExplanation(
int n) {
2218 struct AssertIsEvenFunctor {
2219 AssertionResult operator()(
const char* expr,
int n) {
2220 return AssertIsEven(expr, n);
2225 bool SumIsEven2(
int n1,
int n2) {
return IsEven(n1 + n2); }
2229 struct SumIsEven3Functor {
2230 bool operator()(
int n1,
int n2,
int n3) {
return IsEven(n1 + n2 + n3); }
2235 AssertionResult AssertSumIsEven4(
const char* e1,
const char* e2,
const char* e3,
2236 const char* e4,
int n1,
int n2,
int n3,
2238 const int sum = n1 + n2 + n3 + n4;
2244 msg << e1 <<
" + " << e2 <<
" + " << e3 <<
" + " << e4 <<
" (" << n1 <<
" + "
2245 << n2 <<
" + " << n3 <<
" + " << n4 <<
") evaluates to " << sum
2246 <<
", which is not even.";
2252 struct AssertSumIsEven5Functor {
2253 AssertionResult operator()(
const char* e1,
const char* e2,
const char* e3,
2254 const char* e4,
const char* e5,
int n1,
int n2,
2255 int n3,
int n4,
int n5) {
2256 const int sum = n1 + n2 + n3 + n4 + n5;
2262 msg << e1 <<
" + " << e2 <<
" + " << e3 <<
" + " << e4 <<
" + " << e5
2263 <<
" (" << n1 <<
" + " << n2 <<
" + " << n3 <<
" + " << n4 <<
" + "
2264 << n5 <<
") evaluates to " << sum <<
", which is not even.";
2272 TEST(Pred1Test, WithoutFormat) {
2274 EXPECT_PRED1(IsEvenFunctor(), 2) <<
"This failure is UNEXPECTED!";
2280 EXPECT_PRED1(IsEven, 5) <<
"This failure is expected.";
2282 "This failure is expected.");
2287 TEST(Pred1Test, WithFormat) {
2291 <<
"This failure is UNEXPECTED!";
2296 "n evaluates to 5, which is not even.");
2301 "This failure is expected.");
2306 TEST(Pred1Test, SingleEvaluationOnFailure) {
2310 EXPECT_EQ(1, n) <<
"The argument is not evaluated exactly once.";
2316 <<
"This failure is expected.";
2318 "This failure is expected.");
2319 EXPECT_EQ(2, n) <<
"The argument is not evaluated exactly once.";
2325 TEST(PredTest, WithoutFormat) {
2327 ASSERT_PRED2(SumIsEven2, 2, 4) <<
"This failure is UNEXPECTED!";
2335 EXPECT_PRED2(SumIsEven2, n1, n2) <<
"This failure is expected.";
2337 "This failure is expected.");
2342 "evaluates to false");
2346 TEST(PredTest, WithFormat) {
2349 <<
"This failure is UNEXPECTED!";
2361 "evaluates to 13, which is not even.");
2365 <<
"This failure is expected.";
2367 "This failure is expected.");
2372 TEST(PredTest, SingleEvaluationOnFailure) {
2377 EXPECT_EQ(1, n1) <<
"Argument 1 is not evaluated exactly once.";
2378 EXPECT_EQ(1, n2) <<
"Argument 2 is not evaluated exactly once.";
2386 <<
"This failure is UNEXPECTED!";
2387 EXPECT_EQ(1, n1) <<
"Argument 1 is not evaluated exactly once.";
2388 EXPECT_EQ(1, n2) <<
"Argument 2 is not evaluated exactly once.";
2389 EXPECT_EQ(1, n3) <<
"Argument 3 is not evaluated exactly once.";
2390 EXPECT_EQ(1, n4) <<
"Argument 4 is not evaluated exactly once.";
2391 EXPECT_EQ(1, n5) <<
"Argument 5 is not evaluated exactly once.";
2398 <<
"This failure is expected.";
2400 "This failure is expected.");
2401 EXPECT_EQ(1, n1) <<
"Argument 1 is not evaluated exactly once.";
2402 EXPECT_EQ(1, n2) <<
"Argument 2 is not evaluated exactly once.";
2403 EXPECT_EQ(1, n3) <<
"Argument 3 is not evaluated exactly once.";
2406 n1 = n2 = n3 = n4 = 0;
2411 "evaluates to 1, which is not even.");
2412 EXPECT_EQ(1, n1) <<
"Argument 1 is not evaluated exactly once.";
2413 EXPECT_EQ(1, n2) <<
"Argument 2 is not evaluated exactly once.";
2414 EXPECT_EQ(1, n3) <<
"Argument 3 is not evaluated exactly once.";
2415 EXPECT_EQ(1, n4) <<
"Argument 4 is not evaluated exactly once.";
2419 TEST(PredTest, ExpectPredEvalFailure) {
2420 std::set<int> set_a = {2, 1, 3, 4, 5};
2421 std::set<int> set_b = {0, 4, 8};
2422 const auto compare_sets = [](std::set<int>, std::set<int>) {
return false; };
2425 "compare_sets(set_a, set_b) evaluates to false, where\nset_a evaluates "
2426 "to { 1, 2, 3, 4, 5 }\nset_b evaluates to { 0, 4, 8 }");
2432 bool IsPositive(
double x) {
return x > 0; }
2434 template <
typename T>
2435 bool IsNegative(
T x) {
2439 template <
typename T1,
typename T2>
2440 bool GreaterThan(
T1 x1,
T2 x2) {
2446 TEST(PredicateAssertionTest, AcceptsOverloadedFunction) {
2454 TEST(PredicateAssertionTest, AcceptsTemplateFunction) {
2464 AssertionResult IsPositiveFormat(
const char* ,
int n) {
2468 AssertionResult IsPositiveFormat(
const char* ,
double x) {
2472 template <
typename T>
2473 AssertionResult IsNegativeFormat(
const char* ,
T x) {
2477 template <
typename T1,
typename T2>
2478 AssertionResult EqualsFormat(
const char* ,
const char* ,
2479 const T1& x1,
const T2& x2) {
2486 TEST(PredicateFormatAssertionTest, AcceptsOverloadedFunction) {
2493 TEST(PredicateFormatAssertionTest, AcceptsTemplateFunction) {
2502 const char*
const p1 =
"good";
2506 const char p2[] =
"good";
2513 TEST(StringAssertionTest, ASSERT_STREQ_Null) {
2514 ASSERT_STREQ(static_cast<const char*>(
nullptr),
nullptr);
2519 TEST(StringAssertionTest, ASSERT_STREQ_Null2) {
2557 TEST(StringAssertionTest, STREQ_Wide) {
2559 ASSERT_STREQ(static_cast<const wchar_t*>(
nullptr),
nullptr);
2579 EXPECT_STREQ(L
"abc\x8119", L
"abc\x8121") <<
"Expected failure";
2581 "Expected failure");
2585 TEST(StringAssertionTest, STRNE_Wide) {
2589 EXPECT_STRNE(static_cast<const wchar_t*>(
nullptr),
nullptr);
2609 ASSERT_STRNE(L
"abc\x8119", L
"abc\x8120") <<
"This shouldn't happen";
2616 TEST(IsSubstringTest, ReturnsCorrectResultForCString) {
2627 TEST(IsSubstringTest, ReturnsCorrectResultForWideCString) {
2633 IsSubstring(
"",
"", static_cast<const wchar_t*>(
nullptr),
nullptr));
2639 TEST(IsSubstringTest, GeneratesCorrectMessageForCString) {
2641 "Value of: needle_expr\n"
2642 " Actual: \"needle\"\n"
2643 "Expected: a substring of haystack_expr\n"
2644 "Which is: \"haystack\"",
2645 IsSubstring(
"needle_expr",
"haystack_expr",
"needle",
"haystack")
2646 .failure_message());
2651 TEST(IsSubstringTest, ReturnsCorrectResultsForStdString) {
2656 #if GTEST_HAS_STD_WSTRING
2659 TEST(IsSubstringTest, ReturnsCorrectResultForStdWstring) {
2666 TEST(IsSubstringTest, GeneratesCorrectMessageForWstring) {
2668 "Value of: needle_expr\n"
2669 " Actual: L\"needle\"\n"
2670 "Expected: a substring of haystack_expr\n"
2671 "Which is: L\"haystack\"",
2672 IsSubstring(
"needle_expr",
"haystack_expr", ::std::wstring(L
"needle"),
2674 .failure_message());
2677 #endif // GTEST_HAS_STD_WSTRING
2683 TEST(IsNotSubstringTest, ReturnsCorrectResultForCString) {
2690 TEST(IsNotSubstringTest, ReturnsCorrectResultForWideCString) {
2697 TEST(IsNotSubstringTest, GeneratesCorrectMessageForWideCString) {
2699 "Value of: needle_expr\n"
2700 " Actual: L\"needle\"\n"
2701 "Expected: not a substring of haystack_expr\n"
2702 "Which is: L\"two needles\"",
2703 IsNotSubstring(
"needle_expr",
"haystack_expr", L
"needle", L
"two needles")
2704 .failure_message());
2709 TEST(IsNotSubstringTest, ReturnsCorrectResultsForStdString) {
2716 TEST(IsNotSubstringTest, GeneratesCorrectMessageForStdString) {
2718 "Value of: needle_expr\n"
2719 " Actual: \"needle\"\n"
2720 "Expected: not a substring of haystack_expr\n"
2721 "Which is: \"two needles\"",
2722 IsNotSubstring(
"needle_expr",
"haystack_expr", ::std::string(
"needle"),
2724 .failure_message());
2727 #if GTEST_HAS_STD_WSTRING
2731 TEST(IsNotSubstringTest, ReturnsCorrectResultForStdWstring) {
2733 IsNotSubstring(
"",
"", ::std::wstring(L
"needle"), L
"two needles"));
2737 #endif // GTEST_HAS_STD_WSTRING
2741 template <
typename RawType>
2742 class FloatingPointTest :
public Test {
2746 RawType close_to_positive_zero;
2747 RawType close_to_negative_zero;
2748 RawType further_from_negative_zero;
2750 RawType close_to_one;
2751 RawType further_from_one;
2754 RawType close_to_infinity;
2755 RawType further_from_infinity;
2762 typedef typename Floating::Bits Bits;
2764 void SetUp()
override {
2765 const uint32_t max_ulps = Floating::kMaxUlps;
2768 const Bits zero_bits = Floating(0).
bits();
2771 values_.close_to_positive_zero =
2772 Floating::ReinterpretBits(zero_bits + max_ulps / 2);
2773 values_.close_to_negative_zero =
2774 -Floating::ReinterpretBits(zero_bits + max_ulps - max_ulps / 2);
2775 values_.further_from_negative_zero =
2776 -Floating::ReinterpretBits(zero_bits + max_ulps + 1 - max_ulps / 2);
2779 const Bits one_bits = Floating(1).bits();
2782 values_.close_to_one = Floating::ReinterpretBits(one_bits + max_ulps);
2783 values_.further_from_one =
2784 Floating::ReinterpretBits(one_bits + max_ulps + 1);
2787 values_.infinity = Floating::Infinity();
2790 const Bits infinity_bits = Floating(values_.infinity).bits();
2793 values_.close_to_infinity =
2794 Floating::ReinterpretBits(infinity_bits - max_ulps);
2795 values_.further_from_infinity =
2796 Floating::ReinterpretBits(infinity_bits - max_ulps - 1);
2801 values_.nan1 = Floating::ReinterpretBits(
2802 Floating::kExponentBitMask |
2803 (static_cast<Bits>(1) << (Floating::kFractionBitCount - 1)) | 1);
2804 values_.nan2 = Floating::ReinterpretBits(
2805 Floating::kExponentBitMask |
2806 (static_cast<Bits>(1) << (Floating::kFractionBitCount - 1)) | 200);
2809 void TestSize() {
EXPECT_EQ(
sizeof(RawType),
sizeof(Bits)); }
2811 static TestValues values_;
2814 template <
typename RawType>
2815 typename FloatingPointTest<RawType>::TestValues
2816 FloatingPointTest<RawType>::values_;
2819 typedef FloatingPointTest<float> FloatTest;
2822 TEST_F(FloatTest, Size) { TestSize(); }
2825 TEST_F(FloatTest, Zeros) {
2836 TEST_F(FloatTest, AlmostZeros) {
2843 static const FloatTest::TestValues& v = this->values_;
2851 ASSERT_FLOAT_EQ(v.close_to_positive_zero, v.further_from_negative_zero);
2853 "v.further_from_negative_zero");
2857 TEST_F(FloatTest, SmallDiff) {
2860 "values_.further_from_one");
2864 TEST_F(FloatTest, LargeDiff) {
2872 TEST_F(FloatTest, Infinity) {
2878 "-values_.infinity");
2894 static const FloatTest::TestValues& v = this->values_;
2909 TEST_F(FloatTest, Reflexive) {
2916 TEST_F(FloatTest, Commutative) {
2927 static const FloatTest::TestValues& v = this->values_;
2937 "The difference between 1.0f and 1.5f is 0.5, "
2938 "which exceeds 0.25f");
2940 "The difference between v.infinity and -v.infinity "
2941 "is inf, which exceeds 0.0f");
2943 "The difference between -v.infinity and v.infinity "
2944 "is inf, which exceeds 0.0f");
2946 EXPECT_NEAR(v.infinity, v.close_to_infinity, v.further_from_infinity),
2947 "The difference between v.infinity and v.close_to_infinity is inf, which "
2948 "exceeds v.further_from_infinity");
2956 "The difference between 1.0f and 1.5f is 0.5, "
2957 "which exceeds 0.25f");
2961 TEST_F(FloatTest, FloatLESucceeds) {
2970 TEST_F(FloatTest, FloatLEFails) {
2973 "(2.0f) <= (1.0f)");
2980 "(values_.further_from_one) <= (1.0f)");
2986 "(values_.nan1) <= (values_.infinity)");
2991 "(-values_.infinity) <= (values_.nan1)");
2996 "(values_.nan1) <= (values_.nan1)");
3000 typedef FloatingPointTest<double> DoubleTest;
3003 TEST_F(DoubleTest, Size) { TestSize(); }
3006 TEST_F(DoubleTest, Zeros) {
3017 TEST_F(DoubleTest, AlmostZeros) {
3024 static const DoubleTest::TestValues& v = this->values_;
3033 v.further_from_negative_zero);
3035 "v.further_from_negative_zero");
3039 TEST_F(DoubleTest, SmallDiff) {
3042 "values_.further_from_one");
3046 TEST_F(DoubleTest, LargeDiff) {
3054 TEST_F(DoubleTest, Infinity) {
3060 "-values_.infinity");
3069 TEST_F(DoubleTest, NaN) {
3070 static const DoubleTest::TestValues& v = this->values_;
3086 TEST_F(DoubleTest, Reflexive) {
3093 TEST_F(DoubleTest, Commutative) {
3104 static const DoubleTest::TestValues& v = this->values_;
3114 "The difference between 1.0 and 1.5 is 0.5, "
3115 "which exceeds 0.25");
3117 "The difference between v.infinity and -v.infinity "
3118 "is inf, which exceeds 0.0");
3120 "The difference between -v.infinity and v.infinity "
3121 "is inf, which exceeds 0.0");
3123 EXPECT_NEAR(v.infinity, v.close_to_infinity, v.further_from_infinity),
3124 "The difference between v.infinity and v.close_to_infinity is inf, which "
3125 "exceeds v.further_from_infinity");
3129 EXPECT_NEAR(4.2934311416234112e+18, 4.2934311416234107e+18, 1.0),
3130 "The abs_error parameter 1.0 evaluates to 1 which is smaller than the "
3131 "minimum distance between doubles for numbers of this magnitude which is "
3140 "The difference between 1.0 and 1.5 is 0.5, "
3141 "which exceeds 0.25");
3145 TEST_F(DoubleTest, DoubleLESucceeds) {
3154 TEST_F(DoubleTest, DoubleLEFails) {
3164 "(values_.further_from_one) <= (1.0)");
3170 "(values_.nan1) <= (values_.infinity)");
3175 " (-values_.infinity) <= (values_.nan1)");
3180 "(values_.nan1) <= (values_.nan1)");
3189 FAIL() <<
"Unexpected failure: Disabled test should not be run.";
3198 TEST(DISABLED_TestSuite, TestShouldNotRun) {
3199 FAIL() <<
"Unexpected failure: Test in disabled test case should not be run.";
3204 TEST(DISABLED_TestSuite, DISABLED_TestShouldNotRun) {
3205 FAIL() <<
"Unexpected failure: Test in disabled test case should not be run.";
3210 class DisabledTestsTest :
public Test {
3212 static void SetUpTestSuite() {
3213 FAIL() <<
"Unexpected failure: All tests disabled in test case. "
3214 "SetUpTestSuite() should not be called.";
3217 static void TearDownTestSuite() {
3218 FAIL() <<
"Unexpected failure: All tests disabled in test case. "
3219 "TearDownTestSuite() should not be called.";
3223 TEST_F(DisabledTestsTest, DISABLED_TestShouldNotRun_1) {
3224 FAIL() <<
"Unexpected failure: Disabled test should not be run.";
3227 TEST_F(DisabledTestsTest, DISABLED_TestShouldNotRun_2) {
3228 FAIL() <<
"Unexpected failure: Disabled test should not be run.";
3233 template <
typename T>
3240 FAIL() <<
"Unexpected failure: Disabled typed test should not run.";
3243 template <
typename T>
3244 class DISABLED_TypedTest :
public Test {};
3248 TYPED_TEST(DISABLED_TypedTest, ShouldNotRun) {
3249 FAIL() <<
"Unexpected failure: Disabled typed test should not run.";
3254 template <
typename T>
3260 FAIL() <<
"Unexpected failure: "
3261 <<
"Disabled type-parameterized test should not run.";
3268 template <
typename T>
3269 class DISABLED_TypedTestP :
public Test {};
3274 FAIL() <<
"Unexpected failure: "
3275 <<
"Disabled type-parameterized test should not run.";
3284 class SingleEvaluationTest :
public Test {
3289 static void CompareAndIncrementCharPtrs() {
ASSERT_STREQ(p1_++, p2_++); }
3293 static void CompareAndIncrementInts() {
ASSERT_NE(
a_++,
b_++); }
3296 SingleEvaluationTest() {
3303 static const char*
const s1_;
3304 static const char*
const s2_;
3305 static const char* p1_;
3306 static const char* p2_;
3312 const char*
const SingleEvaluationTest::s1_ =
"01234";
3313 const char*
const SingleEvaluationTest::s2_ =
"abcde";
3314 const char* SingleEvaluationTest::p1_;
3315 const char* SingleEvaluationTest::p2_;
3321 TEST_F(SingleEvaluationTest, FailedASSERT_STREQ) {
3329 TEST_F(SingleEvaluationTest, ASSERT_STR) {
3343 TEST_F(SingleEvaluationTest, FailedASSERT_NE) {
3345 "(a_++) != (b_++)");
3351 TEST_F(SingleEvaluationTest, OtherCases) {
3380 #if GTEST_HAS_EXCEPTIONS
3384 #define ERROR_DESC "std::runtime_error"
3386 #else // GTEST_HAS_RTTI
3388 #define ERROR_DESC "an std::exception-derived error"
3390 #endif // GTEST_HAS_RTTI
3392 void ThrowAnInteger() {
throw 1; }
3393 void ThrowRuntimeError(
const char* what) {
throw std::runtime_error(what); }
3396 TEST_F(SingleEvaluationTest, ExceptionTests) {
3413 "throws a different type");
3420 ThrowRuntimeError(
"A description");
3423 "throws " ERROR_DESC
3424 " with description \"A description\"");
3455 #endif // GTEST_HAS_EXCEPTIONS
3458 class NoFatalFailureTest :
public Test {
3461 void FailsNonFatal() {
ADD_FAILURE() <<
"some non-fatal failure"; }
3462 void Fails() {
FAIL() <<
"some fatal failure"; }
3464 void DoAssertNoFatalFailureOnFails() {
3469 void DoExpectNoFatalFailureOnFails() {
3475 TEST_F(NoFatalFailureTest, NoFailure) {
3480 TEST_F(NoFatalFailureTest, NonFatalIsNoFailure) {
3482 "some non-fatal failure");
3484 "some non-fatal failure");
3487 TEST_F(NoFatalFailureTest, AssertNoFatalFailureOnFatalFailure) {
3488 TestPartResultArray gtest_failures;
3490 ScopedFakeTestPartResultReporter gtest_reporter(>est_failures);
3491 DoAssertNoFatalFailureOnFails();
3494 EXPECT_EQ(TestPartResult::kFatalFailure,
3495 gtest_failures.GetTestPartResult(0).type());
3496 EXPECT_EQ(TestPartResult::kFatalFailure,
3497 gtest_failures.GetTestPartResult(1).type());
3499 gtest_failures.GetTestPartResult(0).message());
3501 gtest_failures.GetTestPartResult(1).message());
3504 TEST_F(NoFatalFailureTest, ExpectNoFatalFailureOnFatalFailure) {
3505 TestPartResultArray gtest_failures;
3507 ScopedFakeTestPartResultReporter gtest_reporter(>est_failures);
3508 DoExpectNoFatalFailureOnFails();
3511 EXPECT_EQ(TestPartResult::kFatalFailure,
3512 gtest_failures.GetTestPartResult(0).type());
3513 EXPECT_EQ(TestPartResult::kNonFatalFailure,
3514 gtest_failures.GetTestPartResult(1).type());
3515 EXPECT_EQ(TestPartResult::kNonFatalFailure,
3516 gtest_failures.GetTestPartResult(2).type());
3518 gtest_failures.GetTestPartResult(0).message());
3520 gtest_failures.GetTestPartResult(1).message());
3522 gtest_failures.GetTestPartResult(2).message());
3525 TEST_F(NoFatalFailureTest, MessageIsStreamable) {
3526 TestPartResultArray gtest_failures;
3528 ScopedFakeTestPartResultReporter gtest_reporter(>est_failures);
3532 EXPECT_EQ(TestPartResult::kFatalFailure,
3533 gtest_failures.GetTestPartResult(0).type());
3534 EXPECT_EQ(TestPartResult::kNonFatalFailure,
3535 gtest_failures.GetTestPartResult(1).type());
3537 gtest_failures.GetTestPartResult(0).message());
3539 gtest_failures.GetTestPartResult(1).message());
3544 std::string EditsToString(
const std::vector<EditType>& edits) {
3546 for (
size_t i = 0;
i < edits.size(); ++
i) {
3547 static const char kEdits[] =
" +-/";
3548 out.append(1, kEdits[edits[
i]]);
3553 std::vector<size_t> CharsToIndices(
const std::string& str) {
3554 std::vector<size_t> out;
3555 for (
size_t i = 0;
i < str.size(); ++
i) {
3556 out.push_back(static_cast<size_t>(str[
i]));
3561 std::vector<std::string> CharsToLines(
const std::string& str) {
3562 std::vector<std::string> out;
3563 for (
size_t i = 0;
i < str.size(); ++
i) {
3564 out.push_back(str.substr(
i, 1));
3569 TEST(EditDistance, TestSuites) {
3574 const char* expected_edits;
3575 const char* expected_diff;
3577 static const Case kCases[] = {
3579 {__LINE__,
"A",
"A",
" ",
""},
3580 {__LINE__,
"ABCDE",
"ABCDE",
" ",
""},
3582 {__LINE__,
"X",
"XA",
" +",
"@@ +1,2 @@\n X\n+A\n"},
3583 {__LINE__,
"X",
"XABCD",
" ++++",
"@@ +1,5 @@\n X\n+A\n+B\n+C\n+D\n"},
3585 {__LINE__,
"XA",
"X",
" -",
"@@ -1,2 @@\n X\n-A\n"},
3586 {__LINE__,
"XABCD",
"X",
" ----",
"@@ -1,5 @@\n X\n-A\n-B\n-C\n-D\n"},
3588 {__LINE__,
"A",
"a",
"/",
"@@ -1,1 +1,1 @@\n-A\n+a\n"},
3589 {__LINE__,
"ABCD",
"abcd",
"////",
3590 "@@ -1,4 +1,4 @@\n-A\n-B\n-C\n-D\n+a\n+b\n+c\n+d\n"},
3592 {__LINE__,
"ABCDEFGH",
"ABXEGH1",
" -/ - +",
3593 "@@ -1,8 +1,7 @@\n A\n B\n-C\n-D\n+X\n E\n-F\n G\n H\n+1\n"},
3594 {__LINE__,
"AAAABCCCC",
"ABABCDCDC",
"- / + / ",
3595 "@@ -1,9 +1,9 @@\n-A\n A\n-A\n+B\n A\n B\n C\n+D\n C\n-C\n+D\n C\n"},
3596 {__LINE__,
"ABCDE",
"BCDCD",
"- +/",
3597 "@@ -1,5 +1,5 @@\n-A\n B\n C\n D\n-E\n+C\n+D\n"},
3598 {__LINE__,
"ABCDEFGHIJKL",
"BCDCDEFGJKLJK",
"- ++ -- ++",
3599 "@@ -1,4 +1,5 @@\n-A\n B\n+C\n+D\n C\n D\n"
3600 "@@ -6,7 +7,7 @@\n F\n G\n-H\n-I\n J\n K\n L\n+J\n+K\n"},
3602 for (
const Case*
c = kCases;
c->left; ++
c) {
3605 CharsToIndices(
c->right))))
3606 <<
"Left <" <<
c->left <<
"> Right <" <<
c->right <<
"> Edits <"
3608 CharsToIndices(
c->right)))
3611 CharsToLines(
c->right)))
3612 <<
"Left <" <<
c->left <<
"> Right <" <<
c->right <<
"> Diff <"
3620 const std::string foo_val(
"5"), bar_val(
"6");
3621 const std::string msg1(
3622 EqFailure(
"foo",
"bar", foo_val, bar_val,
false).failure_message());
3624 "Expected equality of these values:\n"
3631 const std::string msg2(
3632 EqFailure(
"foo",
"6", foo_val, bar_val,
false).failure_message());
3634 "Expected equality of these values:\n"
3640 const std::string msg3(
3641 EqFailure(
"5",
"bar", foo_val, bar_val,
false).failure_message());
3643 "Expected equality of these values:\n"
3649 const std::string msg4(
3650 EqFailure(
"5",
"6", foo_val, bar_val,
false).failure_message());
3652 "Expected equality of these values:\n"
3657 const std::string msg5(
3658 EqFailure(
"foo",
"bar", std::string(
"\"x\""), std::string(
"\"y\""),
true)
3659 .failure_message());
3661 "Expected equality of these values:\n"
3663 " Which is: \"x\"\n"
3665 " Which is: \"y\"\n"
3670 TEST(AssertionTest, EqFailureWithDiff) {
3671 const std::string left(
3672 "1\\n2XXX\\n3\\n5\\n6\\n7\\n8\\n9\\n10\\n11\\n12XXX\\n13\\n14\\n15");
3673 const std::string right(
3674 "1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n11\\n12\\n13\\n14");
3675 const std::string msg1(
3676 EqFailure(
"left",
"right", left, right,
false).failure_message());
3678 "Expected equality of these values:\n"
3681 "1\\n2XXX\\n3\\n5\\n6\\n7\\n8\\n9\\n10\\n11\\n12XXX\\n13\\n14\\n15\n"
3683 " Which is: 1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n11\\n12\\n13\\n14\n"
3684 "With diff:\n@@ -1,5 +1,6 @@\n 1\n-2XXX\n+2\n 3\n+4\n 5\n 6\n"
3685 "@@ -7,8 +8,6 @@\n 8\n 9\n-10\n 11\n-12XXX\n+12\n 13\n 14\n-15\n",
3691 const std::string
foo(
"foo");
3702 #pragma option push -w-ccc -w-rch
3712 TEST(AssertionTest, AssertTrueWithAssertionResult) {
3714 #ifndef __BORLANDC__
3717 "Value of: ResultIsEven(3)\n"
3718 " Actual: false (3 is odd)\n"
3723 "Value of: ResultIsEvenNoExplanation(3)\n"
3724 " Actual: false (3 is odd)\n"
3738 TEST(AssertionTest, AssertFalseWithAssertionResult) {
3740 #ifndef __BORLANDC__
3743 "Value of: ResultIsEven(2)\n"
3744 " Actual: true (2 is even)\n"
3749 "Value of: ResultIsEvenNoExplanation(2)\n"
3762 TEST(ExpectTest, ASSERT_EQ_Double) {
3775 "Expected equality of these values:\n"
3783 TEST(AssertionTest, ASSERT_EQ_NULL) {
3785 const char*
p =
nullptr;
3797 TEST(ExpectTest, ASSERT_EQ_0) {
3811 "Expected: ('a') != ('a'), "
3812 "actual: 'a' (97, 0x61) vs 'a' (97, 0x61)");
3841 #if GTEST_HAS_EXCEPTIONS
3843 void ThrowNothing() {}
3849 #ifndef __BORLANDC__
3854 "Expected: ThrowAnInteger() throws an exception of type bool.\n"
3855 " Actual: it throws a different type.");
3857 ASSERT_THROW(ThrowRuntimeError(
"A description"), std::logic_error),
3858 "Expected: ThrowRuntimeError(\"A description\") "
3859 "throws an exception of type std::logic_error.\n "
3860 "Actual: it throws " ERROR_DESC
3862 "with description \"A description\".");
3867 "Expected: ThrowNothing() throws an exception of type bool.\n"
3868 " Actual: it throws nothing.");
3875 "Expected: ThrowAnInteger() doesn't throw an exception."
3876 "\n Actual: it throws.");
3878 "Expected: ThrowRuntimeError(\"A description\") "
3879 "doesn't throw an exception.\n "
3880 "Actual: it throws " ERROR_DESC
3882 "with description \"A description\".");
3889 "Expected: ThrowNothing() throws an exception.\n"
3890 " Actual: it doesn't.");
3893 #endif // GTEST_HAS_EXCEPTIONS
3897 TEST(AssertionTest, AssertPrecedence) {
3899 bool false_value =
false;
3907 TEST(AssertionTest, NonFixtureSubroutine) {
3914 explicit Uncopyable(
int a_value) :
value_(a_value) {}
3917 bool operator==(
const Uncopyable& rhs)
const {
3918 return value() == rhs.value();
3924 Uncopyable(
const Uncopyable&);
3929 ::std::ostream&
operator<<(::std::ostream& os,
const Uncopyable& value) {
3930 return os << value.value();
3933 bool IsPositiveUncopyable(
const Uncopyable& x) {
return x.value() > 0; }
3936 void TestAssertNonPositive() {
3941 void TestAssertEqualsUncopyable() {
3948 TEST(AssertionTest, AssertWorksWithUncopyableObject) {
3953 TestAssertNonPositive(),
3954 "IsPositiveUncopyable(y) evaluates to false, where\ny evaluates to -1");
3956 "Expected equality of these values:\n"
3957 " x\n Which is: 5\n y\n Which is: -1");
3961 TEST(AssertionTest, ExpectWorksWithUncopyableObject) {
3967 "IsPositiveUncopyable(y) evaluates to false, where\ny evaluates to -1");
3970 "Expected equality of these values:\n"
3971 " x\n Which is: 5\n y\n Which is: -1");
3984 #if !defined(__SUNPRO_CC) && !defined(__HP_aCC)
3990 #ifdef GTEST_OS_LINUX
4007 #endif // GTEST_OS_LINUX
4013 #ifdef GTEST_OS_LINUX
4015 EXPECT_EQ(static_cast<int>(kCaseA), static_cast<int>(kCaseB));
4017 #endif // GTEST_OS_LINUX
4035 #ifndef __BORLANDC__
4045 #endif // !GTEST_OS_MAC && !defined(__SUNPRO_CC)
4047 #ifdef GTEST_OS_WINDOWS
4049 static HRESULT UnexpectedHRESULTFailure() {
return E_UNEXPECTED; }
4051 static HRESULT OkHRESULTSuccess() {
return S_OK; }
4053 static HRESULT FalseHRESULTSuccess() {
return S_FALSE; }
4059 TEST(HRESULTAssertionTest, EXPECT_HRESULT_SUCCEEDED) {
4060 EXPECT_HRESULT_SUCCEEDED(S_OK);
4061 EXPECT_HRESULT_SUCCEEDED(S_FALSE);
4064 "Expected: (UnexpectedHRESULTFailure()) succeeds.\n"
4065 " Actual: 0x8000FFFF");
4068 TEST(HRESULTAssertionTest, ASSERT_HRESULT_SUCCEEDED) {
4069 ASSERT_HRESULT_SUCCEEDED(S_OK);
4070 ASSERT_HRESULT_SUCCEEDED(S_FALSE);
4073 "Expected: (UnexpectedHRESULTFailure()) succeeds.\n"
4074 " Actual: 0x8000FFFF");
4077 TEST(HRESULTAssertionTest, EXPECT_HRESULT_FAILED) {
4078 EXPECT_HRESULT_FAILED(E_UNEXPECTED);
4081 "Expected: (OkHRESULTSuccess()) fails.\n"
4084 "Expected: (FalseHRESULTSuccess()) fails.\n"
4088 TEST(HRESULTAssertionTest, ASSERT_HRESULT_FAILED) {
4089 ASSERT_HRESULT_FAILED(E_UNEXPECTED);
4091 #ifndef __BORLANDC__
4095 "Expected: (OkHRESULTSuccess()) fails.\n"
4100 "Expected: (FalseHRESULTSuccess()) fails.\n"
4105 TEST(HRESULTAssertionTest, Streaming) {
4106 EXPECT_HRESULT_SUCCEEDED(S_OK) <<
"unexpected failure";
4107 ASSERT_HRESULT_SUCCEEDED(S_OK) <<
"unexpected failure";
4108 EXPECT_HRESULT_FAILED(E_UNEXPECTED) <<
"unexpected failure";
4109 ASSERT_HRESULT_FAILED(E_UNEXPECTED) <<
"unexpected failure";
4112 <<
"expected failure",
4113 "expected failure");
4115 #ifndef __BORLANDC__
4119 <<
"expected failure",
4120 "expected failure");
4124 "expected failure");
4127 "expected failure");
4130 #endif // GTEST_OS_WINDOWS
4134 #pragma GCC diagnostic push
4135 #pragma GCC diagnostic ignored "-Wdangling-else"
4136 #pragma GCC diagnostic ignored "-Wempty-body"
4137 #pragma GCC diagnostic ignored "-Wpragmas"
4140 TEST(AssertionSyntaxTest, BasicAssertionsBehavesLikeSingleStatement) {
4142 ASSERT_TRUE(
false) <<
"This should never be executed; "
4143 "It's a compilation test only.";
4158 #pragma GCC diagnostic pop
4161 #if GTEST_HAS_EXCEPTIONS
4164 TEST(ExpectThrowTest, DoesNotGenerateUnreachableCodeWarning) {
4176 TEST(ExpectThrowTest, DoesNotGenerateDuplicateCatchClauseWarning) {
4182 #pragma GCC diagnostic push
4183 #pragma GCC diagnostic ignored "-Wdangling-else"
4184 #pragma GCC diagnostic ignored "-Wempty-body"
4185 #pragma GCC diagnostic ignored "-Wpragmas"
4187 TEST(AssertionSyntaxTest, ExceptionAssertionsBehavesLikeSingleStatement) {
4210 #pragma GCC diagnostic pop
4213 #endif // GTEST_HAS_EXCEPTIONS
4217 #pragma GCC diagnostic push
4218 #pragma GCC diagnostic ignored "-Wdangling-else"
4219 #pragma GCC diagnostic ignored "-Wempty-body"
4220 #pragma GCC diagnostic ignored "-Wpragmas"
4222 TEST(AssertionSyntaxTest, NoFatalFailureAssertionsBehavesLikeSingleStatement) {
4225 <<
"This should never be executed. " <<
"It's a compilation test only.";
4245 #pragma GCC diagnostic pop
4249 TEST(AssertionSyntaxTest, WorksWithSwitch) {
4259 EXPECT_FALSE(
false) <<
"EXPECT_FALSE failed in switch case";
4266 ASSERT_EQ(1, 1) <<
"ASSERT_EQ failed in default switch handler";
4274 #if GTEST_HAS_EXCEPTIONS
4276 void ThrowAString() {
throw "std::string"; }
4280 TEST(AssertionSyntaxTest, WorksWithConst) {
4286 #endif // GTEST_HAS_EXCEPTIONS
4300 TEST(SuccessfulAssertionTest, EXPECT) {
4306 TEST(SuccessfulAssertionTest, EXPECT_STR) {
4312 TEST(SuccessfulAssertionTest, ASSERT) {
4318 TEST(SuccessfulAssertionTest, ASSERT_STR) {
4329 TEST(AssertionWithMessageTest, EXPECT) {
4330 EXPECT_EQ(1, 1) <<
"This should succeed.";
4332 "Expected failure #1");
4333 EXPECT_LE(1, 2) <<
"This should succeed.";
4335 "Expected failure #2.");
4336 EXPECT_GE(1, 0) <<
"This should succeed.";
4338 "Expected failure #3.");
4342 "Expected failure #4.");
4345 "Expected failure #5.");
4349 "Expected failure #6.");
4350 EXPECT_NEAR(1, 1.1, 0.2) <<
"This should succeed.";
4353 TEST(AssertionWithMessageTest, ASSERT) {
4354 ASSERT_EQ(1, 1) <<
"This should succeed.";
4355 ASSERT_NE(1, 2) <<
"This should succeed.";
4356 ASSERT_LE(1, 2) <<
"This should succeed.";
4357 ASSERT_LT(1, 2) <<
"This should succeed.";
4358 ASSERT_GE(1, 0) <<
"This should succeed.";
4360 "Expected failure.");
4363 TEST(AssertionWithMessageTest, ASSERT_STR) {
4368 "Expected failure.");
4371 TEST(AssertionWithMessageTest, ASSERT_FLOATING) {
4383 ASSERT_FALSE(
true) <<
"Expected failure: " << 2 <<
" > " << 1
4384 <<
" evaluates to " <<
true;
4386 "Expected failure");
4401 ASSERT_TRUE(
false) <<
static_cast<const char*
>(
nullptr)
4402 << static_cast<char*>(
nullptr);
4407 #ifdef GTEST_OS_WINDOWS
4409 TEST(AssertionWithMessageTest, WideStringMessage) {
4412 EXPECT_TRUE(
false) << L
"This failure is expected.\x8119";
4414 "This failure is expected.");
4417 ASSERT_EQ(1, 2) <<
"This failure is " << L
"expected too.\x8120";
4419 "This failure is expected too.");
4421 #endif // GTEST_OS_WINDOWS
4427 "Intentional failure #1.");
4429 "Intentional failure #2.");
4439 TEST(ExpectTest, ExpectTrueWithAssertionResult) {
4442 "Value of: ResultIsEven(3)\n"
4443 " Actual: false (3 is odd)\n"
4447 "Value of: ResultIsEvenNoExplanation(3)\n"
4448 " Actual: false (3 is odd)\n"
4457 "Intentional failure #1.");
4459 "Intentional failure #2.");
4468 TEST(ExpectTest, ExpectFalseWithAssertionResult) {
4471 "Value of: ResultIsEven(2)\n"
4472 " Actual: true (2 is even)\n"
4476 "Value of: ResultIsEvenNoExplanation(2)\n"
4491 "Expected equality of these values:\n"
4502 TEST(ExpectTest, EXPECT_EQ_Double) {
4511 TEST(ExpectTest, EXPECT_EQ_NULL) {
4513 const char* p =
nullptr;
4525 TEST(ExpectTest, EXPECT_EQ_0) {
4540 "Expected: ('a') != ('a'), "
4541 "actual: 'a' (97, 0x61) vs 'a' (97, 0x61)");
4543 char*
const p0 =
nullptr;
4549 void* pv1 = (
void*)0x1234;
4550 char*
const p1 =
reinterpret_cast<char*
>(pv1);
4559 "Expected: (2) <= (0), actual: 2 vs 0");
4567 "Expected: (2) < (2), actual: 2 vs 2");
4576 "Expected: (2) >= (3), actual: 2 vs 3");
4584 "Expected: (2) > (2), actual: 2 vs 2");
4588 #if GTEST_HAS_EXCEPTIONS
4594 "Expected: ThrowAnInteger() throws an exception of "
4595 "type bool.\n Actual: it throws a different type.");
4597 EXPECT_THROW(ThrowRuntimeError(
"A description"), std::logic_error),
4598 "Expected: ThrowRuntimeError(\"A description\") "
4599 "throws an exception of type std::logic_error.\n "
4600 "Actual: it throws " ERROR_DESC
4602 "with description \"A description\".");
4605 "Expected: ThrowNothing() throws an exception of type bool.\n"
4606 " Actual: it throws nothing.");
4613 "Expected: ThrowAnInteger() doesn't throw an "
4614 "exception.\n Actual: it throws.");
4616 "Expected: ThrowRuntimeError(\"A description\") "
4617 "doesn't throw an exception.\n "
4618 "Actual: it throws " ERROR_DESC
4620 "with description \"A description\".");
4627 "Expected: ThrowNothing() throws an exception.\n"
4628 " Actual: it doesn't.");
4631 #endif // GTEST_HAS_EXCEPTIONS
4634 TEST(ExpectTest, ExpectPrecedence) {
4637 " true && false\n Which is: false");
4643 TEST(StreamableToStringTest, Scalar) {
4648 TEST(StreamableToStringTest, Pointer) {
4655 TEST(StreamableToStringTest, NullPointer) {
4661 TEST(StreamableToStringTest, CString) {
4666 TEST(StreamableToStringTest, NullCString) {
4674 TEST(StreamableTest,
string) {
4675 static const std::string str(
4676 "This failure message is a std::string, and is expected.");
4682 TEST(StreamableTest, stringWithEmbeddedNUL) {
4683 static const char char_array_with_nul[] =
4684 "Here's a NUL\0 and some more string";
4685 static const std::string string_with_nul(
4686 char_array_with_nul,
4687 sizeof(char_array_with_nul) - 1);
4689 "Here's a NUL\\0 and some more string");
4693 TEST(StreamableTest, NULChar) {
4696 FAIL() <<
"A NUL" <<
'\0' <<
" and some more string";
4698 "A NUL\\0 and some more string");
4709 TEST(StreamableTest, NullCharPtr) {
4715 TEST(StreamableTest, BasicIoManip) {
4718 FAIL() <<
"Line 1." << std::endl
4719 <<
"A NUL char " << std::ends << std::flush <<
" in line 2.";
4721 "Line 1.\nA NUL char \\0 in line 2.");
4726 void AddFailureHelper(
bool* aborted) {
4734 bool aborted =
true;
4758 "Intentional failure.");
4777 SUCCEED() <<
"Explicit success.";
4792 bool false_value =
false;
4795 " false_value\n Which is: false\n true");
4799 TEST(EqAssertionTest, Int) {
4805 TEST(EqAssertionTest, Time_T) {
4806 EXPECT_EQ(static_cast<time_t>(0), static_cast<time_t>(0));
4808 ASSERT_EQ(static_cast<time_t>(0), static_cast<time_t>(1234)),
"1234");
4814 const char ch =
'b';
4820 TEST(EqAssertionTest, WideChar) {
4824 "Expected equality of these values:\n"
4826 " Which is: L'\0' (0, 0x0)\n"
4828 " Which is: L'x' (120, 0x78)");
4830 static wchar_t wchar;
4835 " wchar\n Which is: L'");
4839 TEST(EqAssertionTest, StdString) {
4842 ASSERT_EQ(
"Test", ::std::string(
"Test"));
4845 static const ::std::string str1(
"A * in the middle");
4846 static const ::std::string str2(str1);
4854 char*
const p1 =
const_cast<char*
>(
"foo");
4859 static ::std::string str3(str1);
4862 " str3\n Which is: \"A \\0 in the middle\"");
4865 #if GTEST_HAS_STD_WSTRING
4868 TEST(EqAssertionTest, StdWideString) {
4870 const ::std::wstring wstr1(L
"A * in the middle");
4871 const ::std::wstring wstr2(wstr1);
4876 const wchar_t kTestX8119[] = {
'T',
'e',
's',
't', 0x8119,
'\0'};
4877 EXPECT_EQ(::std::wstring(kTestX8119), kTestX8119);
4881 const wchar_t kTestX8120[] = {
'T',
'e',
's',
't', 0x8120,
'\0'};
4884 EXPECT_EQ(::std::wstring(kTestX8119), kTestX8120);
4890 ::std::wstring wstr3(wstr1);
4891 wstr3.at(2) = L
'\0';
4898 ASSERT_EQ(const_cast<wchar_t*>(L
"foo"), ::std::wstring(L
"bar"));
4903 #endif // GTEST_HAS_STD_WSTRING
4906 TEST(EqAssertionTest, CharPointer) {
4907 char*
const p0 =
nullptr;
4912 void* pv1 = (
void*)0x1234;
4913 void* pv2 = (
void*)0xABC0;
4914 char*
const p1 =
reinterpret_cast<char*
>(pv1);
4915 char*
const p2 =
reinterpret_cast<char*
>(pv2);
4921 reinterpret_cast<char*>(0xABC0)),
4926 TEST(EqAssertionTest, WideCharPointer) {
4927 wchar_t*
const p0 =
nullptr;
4932 void* pv1 = (
void*)0x1234;
4933 void* pv2 = (
void*)0xABC0;
4934 wchar_t*
const p1 =
reinterpret_cast<wchar_t*
>(pv1);
4935 wchar_t*
const p2 =
reinterpret_cast<wchar_t*
>(pv2);
4940 void* pv3 = (
void*)0x1234;
4941 void* pv4 = (
void*)0xABC0;
4942 const wchar_t* p3 =
reinterpret_cast<const wchar_t*
>(pv3);
4943 const wchar_t* p4 =
reinterpret_cast<const wchar_t*
>(pv4);
4948 TEST(EqAssertionTest, OtherPointer) {
4949 ASSERT_EQ(static_cast<const int*>(
nullptr), static_cast<const int*>(
nullptr));
4951 reinterpret_cast<const int*>(0x1234)),
4956 class UnprintableChar {
4958 explicit UnprintableChar(
char ch) : char_(ch) {}
4960 bool operator==(
const UnprintableChar& rhs)
const {
4961 return char_ == rhs.char_;
4963 bool operator!=(
const UnprintableChar& rhs)
const {
4964 return char_ != rhs.char_;
4966 bool operator<(
const UnprintableChar& rhs)
const {
return char_ < rhs.char_; }
4967 bool operator<=(
const UnprintableChar& rhs)
const {
4968 return char_ <= rhs.char_;
4970 bool operator>(
const UnprintableChar& rhs)
const {
return char_ > rhs.char_; }
4971 bool operator>=(
const UnprintableChar& rhs)
const {
4972 return char_ >= rhs.char_;
4981 TEST(ComparisonAssertionTest, AcceptsUnprintableArgs) {
4982 const UnprintableChar
x(
'x'),
y(
'y');
4998 #ifndef __BORLANDC__
5001 "1-byte object <78>");
5003 "1-byte object <78>");
5006 "1-byte object <79>");
5008 "1-byte object <78>");
5010 "1-byte object <79>");
5022 int Bar()
const {
return 1; }
5035 class FRIEND_TEST_Test2 :
public Test {
5050 class TestLifeCycleTest :
public Test {
5054 TestLifeCycleTest() { count_++; }
5058 ~TestLifeCycleTest()
override { count_--; }
5061 int count()
const {
return count_; }
5067 int TestLifeCycleTest::count_ = 0;
5070 TEST_F(TestLifeCycleTest, Test1) {
5077 TEST_F(TestLifeCycleTest, Test2) {
5088 TEST(AssertionResultTest, CopyConstructorWorksWhenNotOptimied) {
5092 AssertionResult r2 = r1;
5097 AssertionResult r3 = r1;
5098 EXPECT_EQ(static_cast<bool>(r3), static_cast<bool>(r1));
5104 TEST(AssertionResultTest, ConstructionWorks) {
5127 TEST(AssertionResultTest, NegationWorks) {
5137 TEST(AssertionResultTest, StreamingWorks) {
5139 r <<
"abc" <<
'd' << 0 <<
true;
5143 TEST(AssertionResultTest, CanStreamOstreamManipulators) {
5145 r <<
"Data" << std::endl << std::flush << std::ends <<
"Will be visible";
5151 TEST(AssertionResultTest, ConstructibleFromContextuallyConvertibleToBool) {
5152 struct ExplicitlyConvertibleToBool {
5153 explicit operator bool()
const {
return value; }
5156 ExplicitlyConvertibleToBool v1 = {
false};
5157 ExplicitlyConvertibleToBool v2 = {
true};
5163 operator AssertionResult()
const {
return AssertionResult(
true); }
5166 TEST(AssertionResultTest, ConstructibleFromImplicitlyConvertible) {
5182 return os << val.
x();
5185 return os <<
"(" << pointer->
x() <<
")";
5188 TEST(MessageTest, CanStreamUserTypeInGlobalNameSpace) {
5199 class MyTypeInUnnamedNameSpace :
public Base {
5201 explicit MyTypeInUnnamedNameSpace(
int an_x) :
Base(an_x) {}
5204 const MyTypeInUnnamedNameSpace&
val) {
5205 return os << val.x();
5208 const MyTypeInUnnamedNameSpace* pointer) {
5209 return os <<
"(" << pointer->x() <<
")";
5213 TEST(MessageTest, CanStreamUserTypeInUnnamedNameSpace) {
5215 MyTypeInUnnamedNameSpace
a(1);
5223 namespace namespace1 {
5229 return os << val.
x();
5232 return os <<
"(" << pointer->
x() <<
")";
5236 TEST(MessageTest, CanStreamUserTypeInUserNameSpace) {
5246 namespace namespace2 {
5254 return os << val.
x();
5258 return os <<
"(" << pointer->
x() <<
")";
5261 TEST(MessageTest, CanStreamUserTypeInUserNameSpaceWithStreamOperatorInGlobal) {
5272 char*
const p1 =
nullptr;
5273 unsigned char*
const p2 =
nullptr;
5275 double* p4 =
nullptr;
5279 msg << p1 << p2 << p3 << p4 << p5 << p6;
5286 const wchar_t* const_wstr =
nullptr;
5290 wchar_t* wstr =
nullptr;
5294 const_wstr = L
"abc\x8119";
5296 (
Message() << const_wstr).GetString().c_str());
5299 wstr =
const_cast<wchar_t*
>(const_wstr);
5316 if (strcmp(test_name, test_info->
name()) == 0)
return test_info;
5322 return test_info->
result();
5328 const TestInfo*
const test_info = GetTestInfo(
"Names");
5336 const TestInfo*
const test_info = GetTestInfo(
"result");
5339 ASSERT_EQ(0, GetTestResult(test_info)->total_part_count());
5342 ASSERT_EQ(0, GetTestResult(test_info)->total_part_count());
5345 #define VERIFY_CODE_LOCATION \
5346 const int expected_line = __LINE__ - 1; \
5347 const TestInfo* const test_info = GetUnitTestImpl()->current_test_info(); \
5348 ASSERT_TRUE(test_info); \
5349 EXPECT_STREQ(__FILE__, test_info->file()); \
5350 EXPECT_EQ(expected_line, test_info->line())
5353 TEST(CodeLocationForTEST, Verify) {
5371 template <
typename T>
5380 template <
typename T>
5393 #undef VERIFY_CODE_LOCATION
5398 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
5404 printf(
"Setting up the test case . . .\n");
5421 printf(
"Tearing down the test case . . .\n");
5455 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
5463 printf(
"Setting up the test suite . . .\n");
5480 printf(
"Tearing down the test suite . . .\n");
5728 template <
typename CharType>
5730 CharType** array2) {
5731 ASSERT_EQ(size1, size2) <<
" Array sizes different.";
5733 for (
int i = 0;
i != size1;
i++) {
5766 template <
typename CharType>
5768 const CharType** argv2,
const Flags& expected,
5769 bool should_print_help) {
5773 #if GTEST_HAS_STREAM_REDIRECTION
5780 #if GTEST_HAS_STREAM_REDIRECTION
5795 #if GTEST_HAS_STREAM_REDIRECTION
5796 const char*
const expected_help_fragment =
5797 "This program contains tests written using";
5798 if (should_print_help) {
5804 #endif // GTEST_HAS_STREAM_REDIRECTION
5812 #define GTEST_TEST_PARSING_FLAGS_(argv1, argv2, expected, should_print_help) \
5813 TestParsingFlags(sizeof(argv1) / sizeof(*argv1) - 1, argv1, \
5814 sizeof(argv2) / sizeof(*argv2) - 1, argv2, expected, \
5820 const char* argv[] = {
nullptr};
5822 const char* argv2[] = {
nullptr};
5829 const char* argv[] = {
"foo.exe",
nullptr};
5831 const char* argv2[] = {
"foo.exe",
nullptr};
5838 const char* argv[] = {
"foo.exe",
"--gtest_fail_fast",
nullptr};
5840 const char* argv2[] = {
"foo.exe",
nullptr};
5847 const char* argv[] = {
"foo.exe",
"--gtest_filter=",
nullptr};
5849 const char* argv2[] = {
"foo.exe",
nullptr};
5856 const char* argv[] = {
"foo.exe",
"--gtest_filter=abc",
nullptr};
5858 const char* argv2[] = {
"foo.exe",
nullptr};
5865 const char* argv[] = {
"foo.exe",
"--gtest_break_on_failure",
nullptr};
5867 const char* argv2[] = {
"foo.exe",
nullptr};
5874 const char* argv[] = {
"foo.exe",
"--gtest_break_on_failure=0",
nullptr};
5876 const char* argv2[] = {
"foo.exe",
nullptr};
5883 const char* argv[] = {
"foo.exe",
"--gtest_break_on_failure=f",
nullptr};
5885 const char* argv2[] = {
"foo.exe",
nullptr};
5892 const char* argv[] = {
"foo.exe",
"--gtest_break_on_failure=F",
nullptr};
5894 const char* argv2[] = {
"foo.exe",
nullptr};
5902 const char* argv[] = {
"foo.exe",
"--gtest_break_on_failure=1",
nullptr};
5904 const char* argv2[] = {
"foo.exe",
nullptr};
5911 const char* argv[] = {
"foo.exe",
"--gtest_catch_exceptions",
nullptr};
5913 const char* argv2[] = {
"foo.exe",
nullptr};
5920 const char* argv[] = {
"foo.exe",
"--gtest_death_test_use_fork",
nullptr};
5922 const char* argv2[] = {
"foo.exe",
nullptr};
5930 const char* argv[] = {
"foo.exe",
"--gtest_filter=a",
"--gtest_filter=b",
5933 const char* argv2[] = {
"foo.exe",
nullptr};
5940 const char* argv[] = {
"foo.exe",
"--gtest_break_on_failure",
5942 "--gtest_filter=b",
nullptr};
5944 const char* argv2[] = {
"foo.exe",
"bar",
nullptr};
5954 const char* argv[] = {
"foo.exe",
"--gtest_list_tests",
nullptr};
5956 const char* argv2[] = {
"foo.exe",
nullptr};
5963 const char* argv[] = {
"foo.exe",
"--gtest_list_tests=1",
nullptr};
5965 const char* argv2[] = {
"foo.exe",
nullptr};
5972 const char* argv[] = {
"foo.exe",
"--gtest_list_tests=0",
nullptr};
5974 const char* argv2[] = {
"foo.exe",
nullptr};
5981 const char* argv[] = {
"foo.exe",
"--gtest_list_tests=f",
nullptr};
5983 const char* argv2[] = {
"foo.exe",
nullptr};
5990 const char* argv[] = {
"foo.exe",
"--gtest_list_tests=F",
nullptr};
5992 const char* argv2[] = {
"foo.exe",
nullptr};
5999 const char* argv[] = {
"foo.exe",
"--gtest_output=xml",
nullptr};
6001 const char* argv2[] = {
"foo.exe",
nullptr};
6008 const char* argv[] = {
"foo.exe",
"--gtest_output=xml:file",
nullptr};
6010 const char* argv2[] = {
"foo.exe",
nullptr};
6017 const char* argv[] = {
"foo.exe",
"--gtest_output=xml:directory/path/",
6020 const char* argv2[] = {
"foo.exe",
nullptr};
6028 const char* argv[] = {
"foo.exe",
"--gtest_brief",
nullptr};
6030 const char* argv2[] = {
"foo.exe",
nullptr};
6037 const char* argv[] = {
"foo.exe",
"--gtest_brief=1",
nullptr};
6039 const char* argv2[] = {
"foo.exe",
nullptr};
6046 const char* argv[] = {
"foo.exe",
"--gtest_brief=0",
nullptr};
6048 const char* argv2[] = {
"foo.exe",
nullptr};
6055 const char* argv[] = {
"foo.exe",
"--gtest_print_time",
nullptr};
6057 const char* argv2[] = {
"foo.exe",
nullptr};
6064 const char* argv[] = {
"foo.exe",
"--gtest_print_time=1",
nullptr};
6066 const char* argv2[] = {
"foo.exe",
nullptr};
6073 const char* argv[] = {
"foo.exe",
"--gtest_print_time=0",
nullptr};
6075 const char* argv2[] = {
"foo.exe",
nullptr};
6082 const char* argv[] = {
"foo.exe",
"--gtest_print_time=f",
nullptr};
6084 const char* argv2[] = {
"foo.exe",
nullptr};
6091 const char* argv[] = {
"foo.exe",
"--gtest_print_time=F",
nullptr};
6093 const char* argv2[] = {
"foo.exe",
nullptr};
6100 const char* argv[] = {
"foo.exe",
"--gtest_random_seed=1000",
nullptr};
6102 const char* argv2[] = {
"foo.exe",
nullptr};
6109 const char* argv[] = {
"foo.exe",
"--gtest_repeat=1000",
nullptr};
6111 const char* argv2[] = {
"foo.exe",
nullptr};
6118 const char* argv[] = {
6120 "--gtest_recreate_environments_when_repeating=0",
6124 const char* argv2[] = {
"foo.exe",
nullptr};
6132 const char* argv[] = {
"foo.exe",
"--gtest_also_run_disabled_tests",
nullptr};
6134 const char* argv2[] = {
"foo.exe",
nullptr};
6142 const char* argv[] = {
"foo.exe",
"--gtest_also_run_disabled_tests=1",
6145 const char* argv2[] = {
"foo.exe",
nullptr};
6153 const char* argv[] = {
"foo.exe",
"--gtest_also_run_disabled_tests=0",
6156 const char* argv2[] = {
"foo.exe",
nullptr};
6164 const char* argv[] = {
"foo.exe",
"--gtest_shuffle",
nullptr};
6166 const char* argv2[] = {
"foo.exe",
nullptr};
6173 const char* argv[] = {
"foo.exe",
"--gtest_shuffle=0",
nullptr};
6175 const char* argv2[] = {
"foo.exe",
nullptr};
6182 const char* argv[] = {
"foo.exe",
"--gtest_shuffle=1",
nullptr};
6184 const char* argv2[] = {
"foo.exe",
nullptr};
6191 const char* argv[] = {
"foo.exe",
"--gtest_stack_trace_depth=5",
nullptr};
6193 const char* argv2[] = {
"foo.exe",
nullptr};
6199 const char* argv[] = {
"foo.exe",
"--gtest_stream_result_to=localhost:1234",
6202 const char* argv2[] = {
"foo.exe",
nullptr};
6210 const char* argv[] = {
"foo.exe",
"--gtest_throw_on_failure",
nullptr};
6212 const char* argv2[] = {
"foo.exe",
nullptr};
6219 const char* argv[] = {
"foo.exe",
"--gtest_throw_on_failure=0",
nullptr};
6221 const char* argv2[] = {
"foo.exe",
nullptr};
6229 const char* argv[] = {
"foo.exe",
"--gtest_throw_on_failure=1",
nullptr};
6231 const char* argv2[] = {
"foo.exe",
nullptr};
6238 const char* argv[] = {
"foo.exe",
"--gtest_filter",
nullptr};
6240 const char* argv2[] = {
"foo.exe",
"--gtest_filter",
nullptr};
6242 #if defined(GTEST_HAS_ABSL) && defined(GTEST_HAS_DEATH_TEST)
6245 testing::ExitedWithCode(1),
6246 "ERROR: Missing the value for the flag 'gtest_filter'");
6247 #elif !defined(GTEST_HAS_ABSL)
6250 static_cast<void>(argv);
6251 static_cast<void>(argv2);
6257 const char* argv[] = {
"foo.exe",
"--gtest_output",
nullptr};
6259 const char* argv2[] = {
"foo.exe",
"--gtest_output",
nullptr};
6261 #if defined(GTEST_HAS_ABSL) && defined(GTEST_HAS_DEATH_TEST)
6264 testing::ExitedWithCode(1),
6265 "ERROR: Missing the value for the flag 'gtest_output'");
6266 #elif !defined(GTEST_HAS_ABSL)
6269 static_cast<void>(argv);
6270 static_cast<void>(argv2);
6274 #ifdef GTEST_HAS_ABSL
6275 TEST_F(ParseFlagsTest, AbseilPositionalFlags) {
6276 const char* argv[] = {
"foo.exe",
"--gtest_throw_on_failure=1",
"--",
6277 "--other_flag",
nullptr};
6282 const char* argv2[] = {
"foo.exe",
"--other_flag",
nullptr};
6289 const char* argv[] = {
"foo.exe",
"--gtest_filter=abcd",
"--other_flag",
6292 const char* argv2[] = {
"foo.exe",
"--other_flag",
nullptr};
6297 #ifdef GTEST_OS_WINDOWS
6299 TEST_F(ParseFlagsTest, WideStrings) {
6300 const wchar_t* argv[] = {L
"foo.exe",
6301 L
"--gtest_filter=Foo*",
6302 L
"--gtest_list_tests=1",
6303 L
"--gtest_break_on_failure",
6304 L
"--non_gtest_flag",
6307 const wchar_t* argv2[] = {L
"foo.exe", L
"--non_gtest_flag", NULL};
6309 Flags expected_flags;
6310 expected_flags.break_on_failure =
true;
6311 expected_flags.filter =
"Foo*";
6312 expected_flags.list_tests =
true;
6316 #endif // GTEST_OS_WINDOWS
6318 #if GTEST_USE_OWN_FLAGFILE_FLAG_
6319 class FlagfileTest :
public ParseFlagsTest {
6321 void SetUp()
override {
6331 void TearDown()
override {
6336 internal::FilePath CreateFlagfile(
const char* contents) {
6337 internal::FilePath file_path(internal::FilePath::GenerateUniqueFileName(
6340 fprintf(f,
"%s", contents);
6350 TEST_F(FlagfileTest, Empty) {
6351 internal::FilePath flagfile_path(CreateFlagfile(
""));
6352 std::string flagfile_flag =
6355 const char* argv[] = {
"foo.exe", flagfile_flag.c_str(),
nullptr};
6357 const char* argv2[] = {
"foo.exe",
nullptr};
6363 TEST_F(FlagfileTest, FilterNonEmpty) {
6364 internal::FilePath flagfile_path(
6366 std::string flagfile_flag =
6369 const char* argv[] = {
"foo.exe", flagfile_flag.c_str(),
nullptr};
6371 const char* argv2[] = {
"foo.exe",
nullptr};
6377 TEST_F(FlagfileTest, SeveralFlags) {
6378 internal::FilePath flagfile_path(
6382 std::string flagfile_flag =
6385 const char* argv[] = {
"foo.exe", flagfile_flag.c_str(),
nullptr};
6387 const char* argv2[] = {
"foo.exe",
nullptr};
6389 Flags expected_flags;
6390 expected_flags.break_on_failure =
true;
6391 expected_flags.filter =
"abc";
6392 expected_flags.list_tests =
true;
6396 #endif // GTEST_USE_OWN_FLAGFILE_FLAG_
6407 <<
"There should be no tests running at this point.";
6415 <<
"There should be no tests running at this point.";
6424 <<
"There is a test running so we should have a valid TestInfo.";
6426 <<
"Expected the name of the currently running test suite.";
6428 <<
"Expected the name of the currently running test.";
6438 <<
"There is a test running so we should have a valid TestInfo.";
6440 <<
"Expected the name of the currently running test suite.";
6442 <<
"Expected the name of the currently running test.";
6449 namespace my_namespace {
6466 TEST(NestedTestingNamespaceTest, Success) {
6467 EXPECT_EQ(1, 1) <<
"This shouldn't fail.";
6471 TEST(NestedTestingNamespaceTest, Failure) {
6473 "This failure is expected.");
6485 void SetUp()
override { Test::SetUp(); }
6491 TEST(StreamingAssertionsTest, Unconditional) {
6492 SUCCEED() <<
"expected success";
6494 "expected failure");
6500 #pragma option push -w-ccc -w-rch
6503 TEST(StreamingAssertionsTest, Truth) {
6507 "expected failure");
6509 "expected failure");
6512 TEST(StreamingAssertionsTest, Truth2) {
6516 "expected failure");
6518 "expected failure");
6526 TEST(StreamingAssertionsTest, IntegerEquals) {
6527 EXPECT_EQ(1, 1) <<
"unexpected failure";
6528 ASSERT_EQ(1, 1) <<
"unexpected failure";
6530 "expected failure");
6532 "expected failure");
6535 TEST(StreamingAssertionsTest, IntegerLessThan) {
6536 EXPECT_LT(1, 2) <<
"unexpected failure";
6537 ASSERT_LT(1, 2) <<
"unexpected failure";
6539 "expected failure");
6541 "expected failure");
6544 TEST(StreamingAssertionsTest, StringsEqual) {
6548 "expected failure");
6550 "expected failure");
6553 TEST(StreamingAssertionsTest, StringsNotEqual) {
6557 "expected failure");
6559 "expected failure");
6562 TEST(StreamingAssertionsTest, StringsEqualIgnoringCase) {
6566 "expected failure");
6568 "expected failure");
6571 TEST(StreamingAssertionsTest, StringNotEqualIgnoringCase) {
6575 "expected failure");
6577 "expected failure");
6580 TEST(StreamingAssertionsTest, FloatingPointEquals) {
6584 "expected failure");
6586 "expected failure");
6589 #if GTEST_HAS_EXCEPTIONS
6591 TEST(StreamingAssertionsTest, Throw) {
6592 EXPECT_THROW(ThrowAnInteger(),
int) <<
"unexpected failure";
6593 ASSERT_THROW(ThrowAnInteger(),
int) <<
"unexpected failure";
6595 <<
"expected failure",
6596 "expected failure");
6598 <<
"expected failure",
6599 "expected failure");
6602 TEST(StreamingAssertionsTest, NoThrow) {
6606 <<
"expected failure",
6607 "expected failure");
6609 "expected failure");
6612 TEST(StreamingAssertionsTest, AnyThrow) {
6616 <<
"expected failure",
6617 "expected failure");
6619 "expected failure");
6622 #endif // GTEST_HAS_EXCEPTIONS
6626 TEST(ColoredOutputTest, UsesColorsWhenGTestColorFlagIsYes) {
6629 SetEnv(
"TERM",
"xterm");
6633 SetEnv(
"TERM",
"dumb");
6638 TEST(ColoredOutputTest, UsesColorsWhenGTestColorFlagIsAliasOfYes) {
6639 SetEnv(
"TERM",
"dumb");
6651 TEST(ColoredOutputTest, UsesNoColorWhenGTestColorFlagIsNo) {
6654 SetEnv(
"TERM",
"xterm");
6658 SetEnv(
"TERM",
"dumb");
6663 TEST(ColoredOutputTest, UsesNoColorWhenGTestColorFlagIsInvalid) {
6664 SetEnv(
"TERM",
"xterm");
6676 TEST(ColoredOutputTest, UsesColorsWhenStdoutIsTty) {
6679 SetEnv(
"TERM",
"xterm");
6684 TEST(ColoredOutputTest, UsesColorsWhenTermSupportsColors) {
6687 #if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_MINGW)
6690 SetEnv(
"TERM",
"dumb");
6696 SetEnv(
"TERM",
"xterm");
6702 SetEnv(
"TERM",
"dumb");
6705 SetEnv(
"TERM",
"emacs");
6708 SetEnv(
"TERM",
"vt100");
6711 SetEnv(
"TERM",
"xterm-mono");
6714 SetEnv(
"TERM",
"xterm");
6717 SetEnv(
"TERM",
"xterm-color");
6720 SetEnv(
"TERM",
"xterm-kitty");
6723 SetEnv(
"TERM",
"alacritty");
6726 SetEnv(
"TERM",
"xterm-256color");
6729 SetEnv(
"TERM",
"screen");
6732 SetEnv(
"TERM",
"screen-256color");
6735 SetEnv(
"TERM",
"tmux");
6738 SetEnv(
"TERM",
"tmux-256color");
6741 SetEnv(
"TERM",
"rxvt-unicode");
6744 SetEnv(
"TERM",
"rxvt-unicode-256color");
6747 SetEnv(
"TERM",
"linux");
6750 SetEnv(
"TERM",
"cygwin");
6752 #endif // GTEST_OS_WINDOWS
6758 StaticAssertTypeEq<bool, bool>();
6760 StaticAssertTypeEq<const int, const int>();
6764 template <
typename T>
6770 TEST(StaticAssertTypeEqTest, WorksInClass) {
6778 TEST(StaticAssertTypeEqTest, CompilesForEqualTypes) {
6779 StaticAssertTypeEq<int, IntAlias>();
6780 StaticAssertTypeEq<int*, IntAlias*>();
6783 TEST(HasNonfatalFailureTest, ReturnsFalseWhenThereIsNoFailure) {
6789 TEST(HasNonfatalFailureTest, ReturnsFalseWhenThereIsOnlyFatalFailure) {
6791 const bool has_nonfatal_failure = HasNonfatalFailure();
6792 ClearCurrentTestPartResults();
6796 TEST(HasNonfatalFailureTest, ReturnsTrueWhenThereIsNonfatalFailure) {
6798 const bool has_nonfatal_failure = HasNonfatalFailure();
6799 ClearCurrentTestPartResults();
6803 TEST(HasNonfatalFailureTest, ReturnsTrueWhenThereAreFatalAndNonfatalFailures) {
6806 const bool has_nonfatal_failure = HasNonfatalFailure();
6807 ClearCurrentTestPartResults();
6816 TEST(HasNonfatalFailureTest, WorksOutsideOfTestBody) {
6820 TEST(HasNonfatalFailureTest, WorksOutsideOfTestBody2) {
6823 ClearCurrentTestPartResults();
6827 TEST(HasFailureTest, ReturnsFalseWhenThereIsNoFailure) {
6831 TEST(HasFailureTest, ReturnsTrueWhenThereIsFatalFailure) {
6833 const bool has_failure = HasFailure();
6834 ClearCurrentTestPartResults();
6838 TEST(HasFailureTest, ReturnsTrueWhenThereIsNonfatalFailure) {
6840 const bool has_failure = HasFailure();
6841 ClearCurrentTestPartResults();
6845 TEST(HasFailureTest, ReturnsTrueWhenThereAreFatalAndNonfatalFailures) {
6848 const bool has_failure = HasFailure();
6849 ClearCurrentTestPartResults();
6856 TEST(HasFailureTest, WorksOutsideOfTestBody) {
6860 TEST(HasFailureTest, WorksOutsideOfTestBody2) {
6863 ClearCurrentTestPartResults();
6888 TEST(TestEventListenersTest, ConstructionWorks) {
6891 EXPECT_TRUE(TestEventListenersAccessor::GetRepeater(&listeners) !=
nullptr);
6898 TEST(TestEventListenersTest, DestructionWorks) {
6899 bool default_result_printer_is_destroyed =
false;
6900 bool default_xml_printer_is_destroyed =
false;
6901 bool extra_listener_is_destroyed =
false;
6903 new TestListener(
nullptr, &default_result_printer_is_destroyed);
6905 new TestListener(
nullptr, &default_xml_printer_is_destroyed);
6907 new TestListener(
nullptr, &extra_listener_is_destroyed);
6911 TestEventListenersAccessor::SetDefaultResultPrinter(&listeners,
6912 default_result_printer);
6913 TestEventListenersAccessor::SetDefaultXmlGenerator(&listeners,
6914 default_xml_printer);
6915 listeners.
Append(extra_listener);
6924 TEST(TestEventListenersTest, Append) {
6925 int on_start_counter = 0;
6926 bool is_destroyed =
false;
6930 listeners.
Append(listener);
6931 TestEventListenersAccessor::GetRepeater(&listeners)
6932 ->OnTestProgramStart(*UnitTest::GetInstance());
6968 message <<
id_ <<
"." << method;
6979 TEST(EventListenerTest, AppendKeepsOrder) {
6980 std::vector<std::string> vec;
6986 TestEventListenersAccessor::GetRepeater(&listeners)
6987 ->OnTestProgramStart(*UnitTest::GetInstance());
6989 EXPECT_STREQ(
"1st.OnTestProgramStart", vec[0].c_str());
6990 EXPECT_STREQ(
"2nd.OnTestProgramStart", vec[1].c_str());
6991 EXPECT_STREQ(
"3rd.OnTestProgramStart", vec[2].c_str());
6994 TestEventListenersAccessor::GetRepeater(&listeners)
6995 ->OnTestProgramEnd(*UnitTest::GetInstance());
7002 TestEventListenersAccessor::GetRepeater(&listeners)
7003 ->OnTestIterationStart(*UnitTest::GetInstance(), 0);
7005 EXPECT_STREQ(
"1st.OnTestIterationStart", vec[0].c_str());
7006 EXPECT_STREQ(
"2nd.OnTestIterationStart", vec[1].c_str());
7007 EXPECT_STREQ(
"3rd.OnTestIterationStart", vec[2].c_str());
7010 TestEventListenersAccessor::GetRepeater(&listeners)
7011 ->OnTestIterationEnd(*UnitTest::GetInstance(), 0);
7013 EXPECT_STREQ(
"3rd.OnTestIterationEnd", vec[0].c_str());
7014 EXPECT_STREQ(
"2nd.OnTestIterationEnd", vec[1].c_str());
7015 EXPECT_STREQ(
"1st.OnTestIterationEnd", vec[2].c_str());
7020 TEST(TestEventListenersTest, Release) {
7021 int on_start_counter = 0;
7022 bool is_destroyed =
false;
7029 listeners.
Append(listener);
7031 TestEventListenersAccessor::GetRepeater(&listeners)
7032 ->OnTestProgramStart(*UnitTest::GetInstance());
7041 TEST(EventListenerTest, SuppressEventForwarding) {
7042 int on_start_counter = 0;
7046 listeners.
Append(listener);
7047 ASSERT_TRUE(TestEventListenersAccessor::EventForwardingEnabled(listeners));
7048 TestEventListenersAccessor::SuppressEventForwarding(&listeners);
7049 ASSERT_FALSE(TestEventListenersAccessor::EventForwardingEnabled(listeners));
7050 TestEventListenersAccessor::GetRepeater(&listeners)
7051 ->OnTestProgramStart(*UnitTest::GetInstance());
7057 TEST(EventListenerDeathTest, EventsNotForwardedInDeathTestSubprocesses) {
7060 GTEST_CHECK_(TestEventListenersAccessor::EventForwardingEnabled(
7062 <<
"expected failure";
7064 "expected failure");
7070 TEST(EventListenerTest, default_result_printer) {
7071 int on_start_counter = 0;
7072 bool is_destroyed =
false;
7076 TestEventListenersAccessor::SetDefaultResultPrinter(&listeners, listener);
7080 TestEventListenersAccessor::GetRepeater(&listeners)
7081 ->OnTestProgramStart(*UnitTest::GetInstance());
7087 TestEventListenersAccessor::SetDefaultResultPrinter(&listeners,
nullptr);
7094 TestEventListenersAccessor::GetRepeater(&listeners)
7095 ->OnTestProgramStart(*UnitTest::GetInstance());
7101 TEST(EventListenerTest, RemovingDefaultResultPrinterWorks) {
7102 int on_start_counter = 0;
7103 bool is_destroyed =
false;
7110 TestEventListenersAccessor::SetDefaultResultPrinter(&listeners, listener);
7117 TestEventListenersAccessor::GetRepeater(&listeners)
7118 ->OnTestProgramStart(*UnitTest::GetInstance());
7129 TEST(EventListenerTest, default_xml_generator) {
7130 int on_start_counter = 0;
7131 bool is_destroyed =
false;
7135 TestEventListenersAccessor::SetDefaultXmlGenerator(&listeners, listener);
7139 TestEventListenersAccessor::GetRepeater(&listeners)
7140 ->OnTestProgramStart(*UnitTest::GetInstance());
7146 TestEventListenersAccessor::SetDefaultXmlGenerator(&listeners,
nullptr);
7153 TestEventListenersAccessor::GetRepeater(&listeners)
7154 ->OnTestProgramStart(*UnitTest::GetInstance());
7160 TEST(EventListenerTest, RemovingDefaultXmlGeneratorWorks) {
7161 int on_start_counter = 0;
7162 bool is_destroyed =
false;
7169 TestEventListenersAccessor::SetDefaultXmlGenerator(&listeners, listener);
7176 TestEventListenersAccessor::GetRepeater(&listeners)
7177 ->OnTestProgramStart(*UnitTest::GetInstance());
7195 "An expected failure");
7201 "An expected failure");
7203 "An expected failure");
7208 "An expected failure");
7213 "An expected failure");
7217 "An expected failure");
7219 "An expected failure");
7224 "An expected failure");
7228 "An expected failure");
7230 "An expected failure");
7260 struct IncompleteType;
7264 TEST(HasDebugStringAndShortDebugStringTest, ValueIsCompileTimeConstant) {
7289 TEST(HasDebugStringAndShortDebugStringTest,
7290 ValueIsTrueWhenTypeHasDebugStringAndShortDebugString) {
7297 TEST(HasDebugStringAndShortDebugStringTest,
7298 ValueIsFalseWhenTypeIsNotAProtocolMessage) {
7306 template <
typename T1,
typename T2>
7309 "GTEST_REMOVE_REFERENCE_AND_CONST_ failed.");
7312 TEST(RemoveReferenceToConstTest, Works) {
7313 TestGTestRemoveReferenceAndConst<int, int>();
7314 TestGTestRemoveReferenceAndConst<double, double&>();
7315 TestGTestRemoveReferenceAndConst<char, const char>();
7316 TestGTestRemoveReferenceAndConst<char, const char&>();
7317 TestGTestRemoveReferenceAndConst<const char*, const char*>();
7322 template <
typename T1,
typename T2>
7325 "GTEST_REFERENCE_TO_CONST_ failed.");
7328 TEST(GTestReferenceToConstTest, Works) {
7329 TestGTestReferenceToConst<const char&, char>();
7330 TestGTestReferenceToConst<const int&, const int>();
7331 TestGTestReferenceToConst<const double&, double>();
7332 TestGTestReferenceToConst<const std::string&, const std::string&>();
7339 TEST(IsContainerTestTest, WorksForNonContainer) {
7345 TEST(IsContainerTestTest, WorksForContainer) {
7366 TEST(IsContainerTestTest, ConstOnlyContainer) {
7368 sizeof(IsContainerTest<ConstOnlyContainerWithPointerIterator>(0)));
7370 sizeof(IsContainerTest<ConstOnlyContainerWithClassIterator>(0)));
7390 TEST(ArrayEqTest, WorksForDegeneratedArrays) {
7395 TEST(ArrayEqTest, WorksForOneDimensionalArrays) {
7397 const int a[] = {0, 1};
7407 TEST(ArrayEqTest, WorksForTwoDimensionalArrays) {
7408 const char a[][3] = {
"hi",
"lo"};
7409 const char b[][3] = {
"hi",
"lo"};
7410 const char c[][3] = {
"hi",
"li"};
7421 TEST(ArrayAwareFindTest, WorksForOneDimensionalArray) {
7422 const char a[] =
"hello";
7427 TEST(ArrayAwareFindTest, WorksForTwoDimensionalArray) {
7428 int a[][2] = {{0, 1}, {2, 3}, {4, 5}};
7429 const int b[2] = {2, 3};
7432 const int c[2] = {6, 7};
7438 TEST(CopyArrayTest, WorksForDegeneratedArrays) {
7444 TEST(CopyArrayTest, WorksForOneDimensionalArrays) {
7445 const char a[3] =
"hi";
7447 #ifndef __BORLANDC__ // C++Builder cannot compile some array size deductions.
7457 TEST(CopyArrayTest, WorksForTwoDimensionalArrays) {
7458 const int a[2][3] = {{0, 1, 2}, {3, 4, 5}};
7460 #ifndef __BORLANDC__ // C++Builder cannot compile some array size deductions.
7472 TEST(NativeArrayTest, ConstructorFromArrayWorks) {
7473 const int a[3] = {0, 1, 2};
7479 TEST(NativeArrayTest, CreatesAndDeletesCopyOfArrayWhenAskedTo) {
7480 typedef int Array[2];
7481 Array* a =
new Array[1];
7494 TEST(NativeArrayTest, TypeMembersAreCorrect) {
7495 StaticAssertTypeEq<char, NativeArray<char>::value_type>();
7496 StaticAssertTypeEq<int[2], NativeArray<int[2]>::value_type>();
7498 StaticAssertTypeEq<const char*, NativeArray<char>::const_iterator>();
7499 StaticAssertTypeEq<const bool(*)[2], NativeArray<bool[2]>::const_iterator>();
7502 TEST(NativeArrayTest, MethodsWork) {
7503 const int a[3] = {0, 1, 2};
7522 const int b1[3] = {0, 1, 1};
7523 const int b2[4] = {0, 1, 2, 3};
7528 TEST(NativeArrayTest, WorksForTwoDimensionalArray) {
7529 const char a[2][3] = {
"hi",
"lo"};
7539 (std::is_same<
int, ElemFromList<0, int, double, char>::type>::value));
7541 (std::is_same<
double, ElemFromList<1, int, double, char>::type>::value));
7543 (std::is_same<
char, ElemFromList<2, int, double, char>::type>::value));
7545 std::is_same<
char, ElemFromList<7,
int,
int,
int,
int,
int,
int,
int,
7546 char,
int,
int,
int,
int>::type>::value));
7553 FlatTuple<int, double, const char*> tuple = {};
7558 tuple = FlatTuple<int, double, const char*>(
7562 EXPECT_EQ(std::string(
"Foo"), tuple.Get<2>());
7564 tuple.Get<1>() = 5.1;
7569 std::string AddIntToString(
int i,
const std::string& s) {
7570 return s + std::to_string(i);
7581 EXPECT_TRUE(tuple.Apply([](
int i,
const std::string& s) ->
bool {
7582 return i == static_cast<int>(s.size());
7586 EXPECT_EQ(tuple.Apply(AddIntToString),
"Hello5");
7589 tuple.Apply([](
int&
i, std::string& s) {
7594 EXPECT_EQ(tuple.Get<1>(),
"HelloHello");
7635 TEST(FlatTuple, ConstructorCalls) {
7640 { FlatTuple<ConstructionCounting> tuple; }
7641 EXPECT_EQ(ConstructionCounting::default_ctor_calls, 1);
7642 EXPECT_EQ(ConstructionCounting::dtor_calls, 1);
7643 EXPECT_EQ(ConstructionCounting::copy_ctor_calls, 0);
7644 EXPECT_EQ(ConstructionCounting::move_ctor_calls, 0);
7645 EXPECT_EQ(ConstructionCounting::copy_assignment_calls, 0);
7646 EXPECT_EQ(ConstructionCounting::move_assignment_calls, 0);
7652 FlatTuple<ConstructionCounting> tuple{
7655 EXPECT_EQ(ConstructionCounting::default_ctor_calls, 1);
7656 EXPECT_EQ(ConstructionCounting::dtor_calls, 2);
7657 EXPECT_EQ(ConstructionCounting::copy_ctor_calls, 1);
7658 EXPECT_EQ(ConstructionCounting::move_ctor_calls, 0);
7659 EXPECT_EQ(ConstructionCounting::copy_assignment_calls, 0);
7660 EXPECT_EQ(ConstructionCounting::move_assignment_calls, 0);
7665 FlatTuple<ConstructionCounting> tuple{
7668 EXPECT_EQ(ConstructionCounting::default_ctor_calls, 1);
7669 EXPECT_EQ(ConstructionCounting::dtor_calls, 2);
7670 EXPECT_EQ(ConstructionCounting::copy_ctor_calls, 0);
7671 EXPECT_EQ(ConstructionCounting::move_ctor_calls, 1);
7672 EXPECT_EQ(ConstructionCounting::copy_assignment_calls, 0);
7673 EXPECT_EQ(ConstructionCounting::move_assignment_calls, 0);
7680 FlatTuple<ConstructionCounting> tuple;
7682 tuple.Get<0>() = elem;
7684 EXPECT_EQ(ConstructionCounting::default_ctor_calls, 2);
7685 EXPECT_EQ(ConstructionCounting::dtor_calls, 2);
7686 EXPECT_EQ(ConstructionCounting::copy_ctor_calls, 0);
7687 EXPECT_EQ(ConstructionCounting::move_ctor_calls, 0);
7688 EXPECT_EQ(ConstructionCounting::copy_assignment_calls, 1);
7689 EXPECT_EQ(ConstructionCounting::move_assignment_calls, 0);
7696 FlatTuple<ConstructionCounting> tuple;
7699 EXPECT_EQ(ConstructionCounting::default_ctor_calls, 2);
7700 EXPECT_EQ(ConstructionCounting::dtor_calls, 2);
7701 EXPECT_EQ(ConstructionCounting::copy_ctor_calls, 0);
7702 EXPECT_EQ(ConstructionCounting::move_ctor_calls, 0);
7703 EXPECT_EQ(ConstructionCounting::copy_assignment_calls, 0);
7704 EXPECT_EQ(ConstructionCounting::move_assignment_calls, 1);
7715 #define GTEST_FLAT_TUPLE_INT8 int, int, int, int, int, int, int, int,
7716 #define GTEST_FLAT_TUPLE_INT16 GTEST_FLAT_TUPLE_INT8 GTEST_FLAT_TUPLE_INT8
7717 #define GTEST_FLAT_TUPLE_INT32 GTEST_FLAT_TUPLE_INT16 GTEST_FLAT_TUPLE_INT16
7718 #define GTEST_FLAT_TUPLE_INT64 GTEST_FLAT_TUPLE_INT32 GTEST_FLAT_TUPLE_INT32
7719 #define GTEST_FLAT_TUPLE_INT128 GTEST_FLAT_TUPLE_INT64 GTEST_FLAT_TUPLE_INT64
7720 #define GTEST_FLAT_TUPLE_INT256 GTEST_FLAT_TUPLE_INT128 GTEST_FLAT_TUPLE_INT128
7724 FlatTuple<GTEST_FLAT_TUPLE_INT256 int> tuple;
7727 tuple.Get<99>() = 17;
7728 tuple.Get<256>() = 1000;
7736 TEST(SkipPrefixTest, SkipsWhenPrefixMatches) {
7737 const char*
const str =
"hello";
7739 const char* p = str;
7748 TEST(SkipPrefixTest, DoesNotSkipWhenPrefixDoesNotMatch) {
7749 const char*
const str =
"world";
7751 const char* p = str;
7761 TEST(AdHocTestResultTest, AdHocTestResultForUnitTestDoesNotShowFailure) {
7774 "DynamicUnitTestFixture",
"DynamicTest",
"TYPE",
"VALUE", __FILE__,
7779 for (
int i = 0;
i < unittest->total_test_suite_count(); ++
i) {
7780 auto* tests = unittest->GetTestSuite(
i);
7781 if (tests->name() != std::string(
"DynamicUnitTestFixture"))
continue;
7782 for (
int j = 0; j < tests->total_test_count(); ++j) {
7783 if (tests->GetTestInfo(j)->name() != std::string(
"DynamicTest"))
continue;
7785 EXPECT_STREQ(tests->GetTestInfo(j)->value_param(),
"VALUE");
7786 EXPECT_STREQ(tests->GetTestInfo(j)->type_param(),
"TYPE");
7791 FAIL() <<
"Didn't find the test!";
7796 TEST(PatternGlobbingTest, MatchesFilterLinearRuntime) {
7797 std::string name(100,
'a');
7798 name.push_back(
'b');
7800 std::string pattern;
7801 for (
int i = 0;
i < 100; ++
i) {
7802 pattern.append(
"a*");
7804 pattern.push_back(
'b');
7810 TEST(PatternGlobbingTest, MatchesFilterWithMultiplePatterns) {
7811 const std::string name =
"aaaa";
7819 TEST(PatternGlobbingTest, MatchesFilterEdgeCases) {
SequenceTestingListener & operator=(const SequenceTestingListener &)=delete
GTEST_API_ bool g_help_flag
void SetDefaultResultPrinter(TestEventListener *listener)
const int & operator*() const
class UnitTestImpl * GetUnitTestImpl()
static int move_assignment_calls
std::ostream & operator<<(std::ostream &os, const MyTypeInNameSpace1 &val)
#define EXPECT_STRCASENE(s1, s2)
void OnTestProgramStart(const UnitTest &) override
static const char * shared_resource_
void OnTestProgramStart(const UnitTest &) override
GTEST_API_ int32_t Int32FromGTestEnv(const char *flag, int32_t default_val)
#define EXPECT_PRED3(pred, v1, v2, v3)
#define EXPECT_DOUBLE_EQ(val1, val2)
static Flags Repeat(int32_t repeat)
static void SuppressEventForwarding(TestEventListeners *listeners)
TYPED_TEST(CodeLocationForTYPEDTEST, Verify)
internal::ValueArray< T...> Values(T...v)
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)
Environment * AddGlobalTestEnvironment(Environment *env)
GTEST_API_ std::string GetCapturedStdout()
static void TearDownTestSuite()
static void AssertStringArrayEq(int size1, CharType **array1, int size2, CharType **array2)
ConstructionCounting & operator=(ConstructionCounting &&) noexcept
const TestSuite * GetTestSuite(int i) const
GTEST_DISABLE_MSC_WARNINGS_POP_() TEST(LinkTest
#define EXPECT_STRCASEEQ(s1, s2)
#define EXPECT_STRNE(s1, s2)
const TestInfo * GetTestInfo(int i) const
#define EXPECT_PRED_FORMAT2(pred_format, v1, v2)
#define ASSERT_LE(val1, val2)
E GetElementOr(const std::vector< E > &v, int i, E default_value)
static Flags DeathTestUseFork(bool death_test_use_fork)
AssertionResult AssertionFailure()
int total_test_count() const
#define GTEST_DISABLE_MSC_DEPRECATED_PUSH_()
#define EXPECT_THROW(statement, expected_exception)
#define EXPECT_NONFATAL_FAILURE(statement, substr)
static void SetUpTestCase()
GTEST_API_ std::vector< EditType > CalculateOptimalEdits(const std::vector< size_t > &left, const std::vector< size_t > &right)
#define ASSERT_THROW(statement, expected_exception)
GTEST_API_ int32_t Int32FromEnvOrDie(const char *env_var, int32_t default_val)
IsContainer IsContainerTest(int)
GTEST_API_ std::string FormatEpochTimeInMillisAsIso8601(TimeInMillis ms)
#define ASSERT_PRED3(pred, v1, v2, v3)
#define EXPECT_LE(val1, val2)
std::string DebugString() const
#define ASSERT_NE(val1, val2)
static Flags Output(const char *output)
TEST_F(TestInfoTest, Names)
#define EXPECT_NE(val1, val2)
#define VERIFY_CODE_LOCATION
int GetNextRandomSeed(int seed)
StaticAssertTypeEqTestHelper()
#define ASSERT_GE(val1, val2)
static const TestResult * GetTestResult(const TestInfo *test_info)
#define ASSERT_PRED1(pred, v1)
std::string ShortDebugString() const
#define GTEST_INTERNAL_ATTRIBUTE_MAYBE_UNUSED
GTEST_API_ bool ShouldUseColor(bool stdout_is_tty)
void OnTestIterationStart(const UnitTest &, int) override
static void CheckFlags(const Flags &expected)
TestEventListener * Release(TestEventListener *listener)
GTEST_API_ bool ShouldRunTestOnShard(int total_shards, int shard_index, int test_id)
MyTypeInNameSpace2(int an_x)
#define TEST_F(test_fixture, test_name)
static void SetUpTestSuite()
TestEventListener * repeater()
bool recreate_environments_when_repeating
void RecordProperty(const std::string &key, const std::string &value)
#define GTEST_TEST_PARSING_FLAGS_(argv1, argv2, expected, should_print_help)
constexpr BiggestInt kMaxBiggestInt
#define EXPECT_GE(val1, val2)
static Flags BreakOnFailure(bool break_on_failure)
#define ADD_FAILURE_AT(file, line)
int32_t stack_trace_depth
#define GTEST_ASSERT_EQ(val1, val2)
#define TEST(test_suite_name, test_name)
#define ASSERT_EQ(val1, val2)
static TestEventListener * GetRepeater(TestEventListeners *listeners)
const_iterator begin() const
TestEventListener * default_xml_generator() const
GTEST_TEST(AlternativeNameTest, Works)
GTEST_API_ bool SkipPrefix(const char *prefix, const char **pstr)
static const TestInfo * GetTestInfo(const char *test_name)
const char * stream_result_to
static Flags AlsoRunDisabledTests(bool also_run_disabled_tests)
#define GTEST_USE_UNPROTECTED_COMMA_
const TestProperty & GetTestProperty(int i) const
static Flags StreamResultTo(const char *stream_result_to)
static int copy_assignment_calls
void Append(TestEventListener *listener)
GTEST_API_ bool ShouldShard(const char *total_shards_str, const char *shard_index_str, bool in_subprocess_for_death_test)
static void FailFatally()
GTEST_API_ void CaptureStdout()
static Flags StackTraceDepth(int32_t stack_trace_depth)
void SuppressEventForwarding(bool)
#define EXPECT_ANY_THROW(statement)
std::ostream & operator<<(std::ostream &os, const Message &sb)
INSTANTIATE_TYPED_TEST_SUITE_P(My, CodeLocationForTYPEDTESTP, int)
#define EXPECT_LT(val1, val2)
std::string ShortDebugString() const
#define EXPECT_FATAL_FAILURE_ON_ALL_THREADS(statement, substr)
#define EXPECT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5)
#define EXPECT_FATAL_FAILURE(statement, substr)
#define GTEST_DISABLE_MSC_DEPRECATED_POP_()
static Flags Brief(bool brief)
#define GTEST_FAIL_AT(file, line)
TEST_P(CodeLocationForTESTP, Verify)
std::string StreamableToString(const T &streamable)
#define EXPECT_NO_FATAL_FAILURE(statement)
static void SetDefaultXmlGenerator(TestEventListeners *listeners, TestEventListener *listener)
GTEST_API_ std::string CodePointToUtf8(uint32_t code_point)
internal::TimeInMillis TimeInMillis
UnitTestRecordPropertyTestHelper()
static bool EventForwardingEnabled(const TestEventListeners &listeners)
void TestGTestReferenceToConst()
bool ArrayEq(const T *lhs, size_t size, const U *rhs)
bool operator!=(const Allocator< T > &a_t, const Allocator< U > &a_u)
std::ostream & operator<<(std::ostream &os, const Expr< T > &xx)
#define EXPECT_PRED1(pred, v1)
#define EXPECT_GT(val1, val2)
std::string CanonicalizeForStdLibVersioning(std::string s)
auto Apply(F &&f, Tuple &&args) -> decltype(ApplyImpl(std::forward< F >(f), std::forward< Tuple >(args), std::make_index_sequence< std::tuple_size< typename std::remove_reference< Tuple >::type >::value >()))
TEST_F(ListenerTest, DoesFoo)
const_iterator begin() const
ConstructionCounting(const ConstructionCounting &)
void OnTestIterationEnd(const UnitTest &, int) override
#define ASSERT_PRED_FORMAT1(pred_format, v1)
const_iterator end() const
GTEST_API_ TypeId GetTestTypeId()
const_iterator & operator++()
#define ASSERT_NO_THROW(statement)
const char * name() const
#define EXPECT_NEAR(val1, val2, abs_error)
#define GTEST_FLAG_PREFIX_UPPER_
expr expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c *expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr2 expr1 expr2 expr1 expr1 expr1 c
static Flags RandomSeed(int32_t random_seed)
#define ASSERT_TRUE(condition)
bool operator>(BigUInt< n > const &a, BigUInt< n > const &b)
AssertionResult AssertionSuccess()
int RmDir(const char *dir)
TestListener(int *on_start_counter, bool *is_destroyed)
#define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
#define GTEST_ASSERT_LT(val1, val2)
#define GTEST_CHECK_(condition)
bool operator>=(BigUInt< n > const &a, BigUInt< n > const &b)
void SetDefaultXmlGenerator(TestEventListener *listener)
std::string DebugString()
const int kMaxStackTraceDepth
bool also_run_disabled_tests
REGISTER_TYPED_TEST_SUITE_P(CodeLocationForTYPEDTESTP, Verify)
#define ASSERT_NO_FATAL_FAILURE(statement)
#define GTEST_REFERENCE_TO_CONST_(T)
#define GTEST_ASSERT_GT(val1, val2)
GTEST_API_ const TypeId kTestTypeIdInGoogleTest
static GTEST_INTERNAL_ATTRIBUTE_MAYBE_UNUSED bool dummy1
TEST(GTestEnvVarTest, Dummy)
void OnTestProgramEnd(const UnitTest &) override
GTEST_API_ bool AlwaysTrue()
ADVar foo(double d, ADVar x, ADVar y)
const_iterator end() const
#define GTEST_FLAG_SET(name, value)
std::vector< std::string > * vector_
static const uint32_t kMaxRange
static int default_ctor_calls
void UnitTestRecordProperty(const char *key, const std::string &value)
#define GTEST_ASSERT_NE(val1, val2)
#define EXPECT_STREQ(s1, s2)
static void SetDefaultResultPrinter(TestEventListeners *listeners, TestEventListener *listener)
static bool HasNonfatalFailureHelper()
std::string GetString() const
GTEST_API_ AssertionResult IsSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
GTEST_API_ TimeInMillis GetTimeInMillis()
INSTANTIATE_TEST_SUITE_P(, CodeLocationForTESTP, Values(0))
MyTypeInNameSpace1(int an_x)
#define GTEST_FLAG_GET(name)
static Flags FailFast(bool fail_fast)
TYPED_TEST_P(CodeLocationForTYPEDTESTP, Verify)
Types< int, long > NumericTypes
static int copy_ctor_calls
const TestInfo * current_test_info() const GTEST_LOCK_EXCLUDED_(mutex_)
GTEST_API_ bool ParseFlag(const char *str, const char *flag, int32_t *value)
static int move_ctor_calls
static Flags RecreateEnvironmentsWhenRepeating(bool recreate_environments_when_repeating)
GTEST_API_ std::string WideStringToUtf8(const wchar_t *str, int num_chars)
bool EventForwardingEnabled() const
static Flags Shuffle(bool shuffle)
int test_property_count() const
void ShuffleRange(internal::Random *random, int begin, int end, std::vector< E > *v)
TEST(NestedTestingNamespaceTest, Success)
FILE * FOpen(const char *path, const char *mode)
GTEST_API_ std::string AppendUserMessage(const std::string >est_msg, const Message &user_msg)
const char * test_suite_name() const
#define ASSERT_NEAR(val1, val2, abs_error)
std::string DebugString() const
static void SetUpTestSuite()
#define EXPECT_PRED_FORMAT1(pred_format, v1)
int CountIf(const Container &c, Predicate predicate)
static Flags ThrowOnFailure(bool throw_on_failure)
static Flags Filter(const char *filter)
ConstructionCounting(ConstructionCounting &&) noexcept
GTEST_API_ AssertionResult EqFailure(const char *expected_expression, const char *actual_expression, const std::string &expected_value, const std::string &actual_value, bool ignoring_case)
static void TearDownTestSuite()
bool operator==(const Handle< T > &h1, const Handle< T > &h2)
Compare two handles.
static GTEST_INTERNAL_ATTRIBUTE_MAYBE_UNUSED bool dummy2
const Bits & bits() const
#define EXPECT_EQ(val1, val2)
#define ASSERT_GT(val1, val2)
GTEST_API_ void ParseGoogleTestFlagsOnly(int *argc, char **argv)
void Shuffle(internal::Random *random, std::vector< E > *v)
GTEST_API_ std::string FormatTimeInMillisAsSeconds(TimeInMillis ms)
#define ASSERT_STRNE(s1, s2)
GTEST_API_ std::string CreateUnifiedDiff(const std::vector< std::string > &left, const std::vector< std::string > &right, size_t context=2)
static const char * shared_resource_
#define ASSERT_PRED_FORMAT4(pred_format, v1, v2, v3, v4)
std::string GetEventDescription(const char *method)
const_iterator end() const
GTEST_API_ AssertionResult DoubleLE(const char *expr1, const char *expr2, double val1, double val2)
#define EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(statement, substr)
#define ASSERT_STRCASENE(s1, s2)
#define EXPECT_FLOAT_EQ(val1, val2)
TYPED_TEST_SUITE(CodeLocationForTYPEDTEST, int)
#define GTEST_ASSERT_GE(val1, val2)
#define FRIEND_TEST(test_case_name, test_name)
const TestResult * result() const
static bool HasFailureHelper()
#define EXPECT_TRUE(condition)
void CopyArray(const T *from, size_t size, U *to)
#define ASSERT_LT(val1, val2)
GTEST_API_ AssertionResult IsNotSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
Factory TestInfo * RegisterTest(const char *test_suite_name, const char *test_name, const char *type_param, const char *value_param, const char *file, int line, Factory factory)
static UnitTest * GetInstance()
TestEventListener * default_result_printer() const
static void TearDownTestCase()
constexpr bool StaticAssertTypeEq() noexcept
Iter ArrayAwareFind(Iter begin, Iter end, const Element &elem)
#define ASSERT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5)
int GetRandomSeedFromFlag(int32_t random_seed_flag)
static Flags CatchExceptions(bool catch_exceptions)
const TestSuite * current_test_suite() const GTEST_LOCK_EXCLUDED_(mutex_)
#define GTEST_ASSERT_LE(val1, val2)
#define EXPECT_NO_THROW(statement)
void ForEach(const Container &c, Functor functor)
int operator<(const ADvari &L, const ADvari &R)
const TestResult & ad_hoc_test_result() const
const char * value() const
#define ASSERT_FLOAT_EQ(val1, val2)
#define EXPECT_FALSE(condition)
SequenceTestingListener(std::vector< std::string > *vector, const char *id)
const TestResult & ad_hoc_test_result() const
#define ASSERT_STREQ(s1, s2)
static Flags ListTests(bool list_tests)
#define ASSERT_PRED2(pred, v1, v2)
#define ASSERT_FALSE(condition)
TYPED_TEST_SUITE_P(CodeLocationForTYPEDTESTP)
static bool MatchesFilter(const std::string &name, const char *filter)
#define EXPECT_PRED2(pred, v1, v2)
const_iterator begin() const
#define ASSERT_ANY_THROW(statement)
static bool HasNonfatalFailure()
bool operator<=(BigUInt< n > const &a, BigUInt< n > const &b)
#define ASSERT_DOUBLE_EQ(val1, val2)
#define GTEST_REMOVE_REFERENCE_AND_CONST_(T)
#define GTEST_FLAG_PREFIX_
ConstructionCounting & operator=(const ConstructionCounting &)
std::string DebugString()
int ShortDebugString() const
#define ASSERT_STRCASEEQ(s1, s2)
void TestGTestRemoveReferenceAndConst()
#define EXPECT_PRED_FORMAT4(pred_format, v1, v2, v3, v4)
static void TestParsingFlags(int argc1, const CharType **argv1, int argc2, const CharType **argv2, const Flags &expected, bool should_print_help)
static Flags PrintTime(bool print_time)
GTEST_API_ AssertionResult FloatLE(const char *expr1, const char *expr2, float val1, float val2)
#define ASSERT_PRED_FORMAT2(pred_format, v1, v2)
GTEST_API_ std::string TempDir()
static ExpectedAnswer expected[4]