39 TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) {
67 #include <type_traits>
68 #include <unordered_set>
77 #if GTEST_CAN_STREAM_RESULTS_
79 class StreamingListenerTest :
public Test {
81 class FakeSocketWriter :
public StreamingListener::AbstractSocketWriter {
84 void Send(
const std::string& message)
override { output_ += message; }
89 StreamingListenerTest()
90 : fake_sock_writer_(new FakeSocketWriter),
91 streamer_(fake_sock_writer_),
92 test_info_obj_(
"FooTest",
"Bar", nullptr, nullptr,
93 CodeLocation(__FILE__, __LINE__), nullptr, nullptr) {}
96 std::string* output() {
return &(fake_sock_writer_->output_); }
98 FakeSocketWriter*
const fake_sock_writer_;
99 StreamingListener streamer_;
104 TEST_F(StreamingListenerTest, OnTestProgramEnd) {
106 streamer_.OnTestProgramEnd(unit_test_);
107 EXPECT_EQ(
"event=TestProgramEnd&passed=1\n", *output());
110 TEST_F(StreamingListenerTest, OnTestIterationEnd) {
112 streamer_.OnTestIterationEnd(unit_test_, 42);
113 EXPECT_EQ(
"event=TestIterationEnd&passed=1&elapsed_time=0ms\n", *output());
116 TEST_F(StreamingListenerTest, OnTestCaseStart) {
118 streamer_.OnTestCaseStart(TestCase(
"FooTest",
"Bar",
nullptr,
nullptr));
119 EXPECT_EQ(
"event=TestCaseStart&name=FooTest\n", *output());
122 TEST_F(StreamingListenerTest, OnTestCaseEnd) {
124 streamer_.OnTestCaseEnd(TestCase(
"FooTest",
"Bar",
nullptr,
nullptr));
125 EXPECT_EQ(
"event=TestCaseEnd&passed=1&elapsed_time=0ms\n", *output());
128 TEST_F(StreamingListenerTest, OnTestStart) {
130 streamer_.OnTestStart(test_info_obj_);
131 EXPECT_EQ(
"event=TestStart&name=Bar\n", *output());
134 TEST_F(StreamingListenerTest, OnTestEnd) {
136 streamer_.OnTestEnd(test_info_obj_);
137 EXPECT_EQ(
"event=TestEnd&passed=1&elapsed_time=0ms\n", *output());
140 TEST_F(StreamingListenerTest, OnTestPartResult) {
142 streamer_.OnTestPartResult(TestPartResult(
143 TestPartResult::kFatalFailure,
"foo.cc", 42,
"failed=\n&%"));
147 "event=TestPartResult&file=foo.cc&line=42&message=failed%3D%0A%26%25\n",
151 #endif // GTEST_CAN_STREAM_RESULTS_
195 using testing::AssertionResult;
222 using testing::ScopedFakeTestPartResultReporter;
225 using testing::TestCase;
228 using testing::TestPartResult;
229 using testing::TestPartResultArray;
241 using testing::internal::CountIf;
244 using testing::internal::ForEach;
247 using testing::internal::GTestFlagSaver;
249 using testing::internal::GetElementOr;
250 using testing::internal::GetNextRandomSeed;
251 using testing::internal::GetRandomSeedFromFlag;
255 using testing::internal::GetUnitTestImpl;
262 using testing::internal::OsStackTraceGetter;
263 using testing::internal::OsStackTraceGetterInterface;
270 using testing::internal::Shuffle;
271 using testing::internal::ShuffleRange;
276 using testing::internal::TestResultAccessor;
277 using testing::internal::UnitTestImpl;
282 using testing::internal::kMaxRandomSeed;
284 using testing::kMaxStackTraceDepth;
286 #if GTEST_HAS_STREAM_REDIRECTION
291 #if GTEST_IS_THREADSAFE
292 using testing::internal::ThreadWithParam;
301 for (
size_t i = 0;
i < vector.size();
i++) {
302 os << vector[
i] <<
" ";
311 TEST(GetRandomSeedFromFlagTest, HandlesZero) {
312 const int seed = GetRandomSeedFromFlag(0);
314 EXPECT_LE(seed, static_cast<int>(kMaxRandomSeed));
317 TEST(GetRandomSeedFromFlagTest, PreservesValidSeed) {
320 EXPECT_EQ(kMaxRandomSeed - 1, GetRandomSeedFromFlag(kMaxRandomSeed - 1));
321 EXPECT_EQ(static_cast<int>(kMaxRandomSeed),
322 GetRandomSeedFromFlag(kMaxRandomSeed));
325 TEST(GetRandomSeedFromFlagTest, NormalizesInvalidSeed) {
326 const int seed1 = GetRandomSeedFromFlag(-1);
328 EXPECT_LE(seed1, static_cast<int>(kMaxRandomSeed));
330 const int seed2 = GetRandomSeedFromFlag(kMaxRandomSeed + 1);
332 EXPECT_LE(seed2, static_cast<int>(kMaxRandomSeed));
335 TEST(GetNextRandomSeedTest, WorksForValidInput) {
338 EXPECT_EQ(static_cast<int>(kMaxRandomSeed),
339 GetNextRandomSeed(kMaxRandomSeed - 1));
340 EXPECT_EQ(1, GetNextRandomSeed(kMaxRandomSeed));
348 static void ClearCurrentTestPartResults() {
349 TestResultAccessor::ClearTestPartResults(
350 GetUnitTestImpl()->current_test_result());
355 TEST(GetTypeIdTest, ReturnsSameValueForSameType) {
356 EXPECT_EQ(GetTypeId<int>(), GetTypeId<int>());
357 EXPECT_EQ(GetTypeId<Test>(), GetTypeId<Test>());
360 class SubClassOfTest :
public Test {};
361 class AnotherSubClassOfTest :
public Test {};
363 TEST(GetTypeIdTest, ReturnsDifferentValuesForDifferentTypes) {
364 EXPECT_NE(GetTypeId<int>(), GetTypeId<const int>());
365 EXPECT_NE(GetTypeId<int>(), GetTypeId<char>());
369 EXPECT_NE(GetTypeId<AnotherSubClassOfTest>(), GetTypeId<SubClassOfTest>());
374 TEST(GetTestTypeIdTest, ReturnsTheSameValueInsideOrOutsideOfGoogleTest) {
405 TEST(FormatTimeInMillisAsSecondsTest, FormatsZero) {
409 TEST(FormatTimeInMillisAsSecondsTest, FormatsPositiveNumber) {
417 TEST(FormatTimeInMillisAsSecondsTest, FormatsNegativeNumber) {
431 class FormatEpochTimeInMillisAsIso8601Test :
public Test {
439 void SetUp()
override {
444 saved_tz_ = strdup(getenv("TZ"));
450 SetTimeZone("UTC+00");
453 void TearDown()
override {
454 SetTimeZone(saved_tz_);
455 free(const_cast<char*>(saved_tz_));
459 static void SetTimeZone(
const char* time_zone) {
463 #if _MSC_VER || GTEST_OS_WINDOWS_MINGW
466 const std::string env_var =
467 std::string(
"TZ=") + (time_zone ? time_zone :
"");
468 _putenv(env_var.c_str());
474 setenv((
"TZ"), time_zone, 1);
482 const char* saved_tz_;
485 const TimeInMillis FormatEpochTimeInMillisAsIso8601Test::kMillisPerSec;
487 TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsTwoDigitSegments) {
492 TEST_F(FormatEpochTimeInMillisAsIso8601Test, MillisecondsDoNotAffectResult) {
494 "2011-10-31T18:52:42",
498 TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsLeadingZeroes) {
503 TEST_F(FormatEpochTimeInMillisAsIso8601Test, Prints24HourTime) {
508 TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsEpochStart) {
514 # pragma option push -w-ccc -w-rch
519 TEST(NullLiteralTest, LHSAllowsNullLiterals) {
520 EXPECT_EQ(0, static_cast<void*>(
nullptr));
521 ASSERT_EQ(0, static_cast<void*>(
nullptr));
522 EXPECT_EQ(NULL, static_cast<void*>(
nullptr));
523 ASSERT_EQ(NULL, static_cast<void*>(
nullptr));
524 EXPECT_EQ(
nullptr, static_cast<void*>(
nullptr));
525 ASSERT_EQ(
nullptr, static_cast<void*>(
nullptr));
527 const int*
const p =
nullptr;
536 struct ConvertToAll {
537 template <
typename T>
543 struct ConvertToPointer {
545 operator T*()
const {
550 struct ConvertToAllButNoPointers {
551 template <
typename T,
561 TEST(NullLiteralTest, ImplicitConversion) {
562 EXPECT_EQ(ConvertToPointer{},
static_cast<void*
>(
nullptr));
563 #if !defined(__GNUC__) || defined(__clang__)
565 EXPECT_EQ(ConvertToAll{},
static_cast<void*
>(
nullptr));
572 #pragma clang diagnostic push
573 #if __has_warning("-Wzero-as-null-pointer-constant")
574 #pragma clang diagnostic error "-Wzero-as-null-pointer-constant"
578 TEST(NullLiteralTest, NoConversionNoWarning) {
586 #pragma clang diagnostic pop
598 TEST(CodePointToUtf8Test, CanEncodeNul) {
603 TEST(CodePointToUtf8Test, CanEncodeAscii) {
612 TEST(CodePointToUtf8Test, CanEncode8To11Bits) {
626 TEST(CodePointToUtf8Test, CanEncode12To16Bits) {
636 #if !GTEST_WIDE_STRING_USES_UTF16_
643 TEST(CodePointToUtf8Test, CanEncode17To21Bits) {
655 TEST(CodePointToUtf8Test, CanEncodeInvalidCodePoint) {
659 #endif // !GTEST_WIDE_STRING_USES_UTF16_
664 TEST(WideStringToUtf8Test, CanEncodeNul) {
670 TEST(WideStringToUtf8Test, CanEncodeAscii) {
679 TEST(WideStringToUtf8Test, CanEncode8To11Bits) {
685 const wchar_t s[] = { 0x576,
'\0' };
692 TEST(WideStringToUtf8Test, CanEncode12To16Bits) {
694 const wchar_t s1[] = { 0x8D3,
'\0' };
699 const wchar_t s2[] = { 0xC74D,
'\0' };
705 TEST(WideStringToUtf8Test, StopsOnNulCharacter) {
711 TEST(WideStringToUtf8Test, StopsWhenLengthLimitReached) {
715 #if !GTEST_WIDE_STRING_USES_UTF16_
719 TEST(WideStringToUtf8Test, CanEncode17To21Bits) {
730 TEST(WideStringToUtf8Test, CanEncodeInvalidCodePoint) {
734 #else // !GTEST_WIDE_STRING_USES_UTF16_
737 TEST(WideStringToUtf8Test, CanEncodeValidUtf16SUrrogatePairs) {
738 const wchar_t s[] = { 0xD801, 0xDC00,
'\0' };
744 TEST(WideStringToUtf8Test, CanEncodeInvalidUtf16SurrogatePair) {
746 const wchar_t s1[] = { 0xD800,
'\0' };
749 const wchar_t s2[] = { 0xD800,
'M',
'\0' };
752 const wchar_t s3[] = { 0xDC00,
'P',
'Q',
'R',
'\0' };
755 #endif // !GTEST_WIDE_STRING_USES_UTF16_
758 #if !GTEST_WIDE_STRING_USES_UTF16_
759 TEST(WideStringToUtf8Test, ConcatenatesCodepointsCorrectly) {
760 const wchar_t s[] = { 0x108634, 0xC74D,
'\n', 0x576, 0x8D3, 0x108634,
'\0'};
771 TEST(WideStringToUtf8Test, ConcatenatesCodepointsCorrectly) {
772 const wchar_t s[] = { 0xC74D,
'\n', 0x576, 0x8D3,
'\0'};
774 "\xEC\x9D\x8D" "\n" "\xD5\xB6" "\xE0\xA3\x93",
777 #endif // !GTEST_WIDE_STRING_USES_UTF16_
781 TEST(RandomDeathTest, GeneratesCrashesOnInvalidRange) {
785 "Cannot generate a number in the range \\[0, 0\\)");
788 "Generation of a number in \\[0, 2147483649\\) was requested, "
789 "but this can only generate numbers in \\[0, 2147483648\\)");
792 TEST(RandomTest, GeneratesNumbersWithinRange) {
793 constexpr uint32_t kRange = 10000;
795 for (
int i = 0;
i < 10;
i++) {
796 EXPECT_LT(random.Generate(kRange), kRange) <<
" for iteration " <<
i;
800 for (
int i = 0;
i < 10;
i++) {
801 EXPECT_LT(random2.Generate(kRange), kRange) <<
" for iteration " <<
i;
805 TEST(RandomTest, RepeatsWhenReseeded) {
806 constexpr
int kSeed = 123;
807 constexpr
int kArraySize = 10;
808 constexpr uint32_t kRange = 10000;
809 uint32_t values[kArraySize];
812 for (
int i = 0;
i < kArraySize;
i++) {
813 values[
i] = random.Generate(kRange);
816 random.Reseed(kSeed);
817 for (
int i = 0;
i < kArraySize;
i++) {
818 EXPECT_EQ(values[
i], random.Generate(kRange)) <<
" for iteration " << i;
826 static bool IsPositive(
int n) {
return n > 0; }
828 TEST(ContainerUtilityTest, CountIf) {
844 static int g_sum = 0;
845 static void Accumulate(
int n) { g_sum += n; }
847 TEST(ContainerUtilityTest, ForEach) {
850 ForEach(v, Accumulate);
855 ForEach(v, Accumulate);
861 ForEach(v, Accumulate);
866 TEST(ContainerUtilityTest, GetElementOr) {
874 EXPECT_EQ(
'x', GetElementOr(a, -2,
'x'));
878 TEST(ContainerUtilityDeathTest, ShuffleRange) {
886 ShuffleRange(&random, -1, 1, &a),
887 "Invalid shuffle range start -1: must be in range \\[0, 3\\]");
889 ShuffleRange(&random, 4, 4, &a),
890 "Invalid shuffle range start 4: must be in range \\[0, 3\\]");
892 ShuffleRange(&random, 3, 2, &a),
893 "Invalid shuffle range finish 2: must be in range \\[3, 3\\]");
895 ShuffleRange(&random, 3, 4, &a),
896 "Invalid shuffle range finish 4: must be in range \\[3, 3\\]");
899 class VectorShuffleTest :
public Test {
901 static const size_t kVectorSize = 20;
903 VectorShuffleTest() : random_(1) {
904 for (
int i = 0; i < static_cast<int>(kVectorSize);
i++) {
905 vector_.push_back(
i);
910 if (kVectorSize != vector.size()) {
914 bool found_in_vector[kVectorSize] = {
false };
915 for (
size_t i = 0;
i < vector.size();
i++) {
916 const int e = vector[
i];
917 if (e < 0 || e >= static_cast<int>(kVectorSize) || found_in_vector[e]) {
920 found_in_vector[e] =
true;
928 static bool VectorIsNotCorrupt(
const TestingVector& vector) {
929 return !VectorIsCorrupt(vector);
932 static bool RangeIsShuffled(
const TestingVector& vector,
int begin,
int end) {
933 for (
int i = begin;
i < end;
i++) {
934 if (
i != vector[static_cast<size_t>(
i)]) {
941 static bool RangeIsUnshuffled(
943 return !RangeIsShuffled(vector, begin, end);
947 return RangeIsShuffled(vector, 0, static_cast<int>(vector.size()));
950 static bool VectorIsUnshuffled(
const TestingVector& vector) {
951 return !VectorIsShuffled(vector);
958 const size_t VectorShuffleTest::kVectorSize;
960 TEST_F(VectorShuffleTest, HandlesEmptyRange) {
962 ShuffleRange(&random_, 0, 0, &vector_);
967 ShuffleRange(&random_, kVectorSize/2, kVectorSize/2, &vector_);
972 ShuffleRange(&random_, kVectorSize - 1, kVectorSize - 1, &vector_);
977 ShuffleRange(&random_, kVectorSize, kVectorSize, &vector_);
982 TEST_F(VectorShuffleTest, HandlesRangeOfSizeOne) {
984 ShuffleRange(&random_, 0, 1, &vector_);
989 ShuffleRange(&random_, kVectorSize/2, kVectorSize/2 + 1, &vector_);
994 ShuffleRange(&random_, kVectorSize - 1, kVectorSize, &vector_);
1002 TEST_F(VectorShuffleTest, ShufflesEntireVector) {
1003 Shuffle(&random_, &vector_);
1010 EXPECT_NE(static_cast<int>(kVectorSize - 1), vector_[kVectorSize - 1]);
1013 TEST_F(VectorShuffleTest, ShufflesStartOfVector) {
1014 const int kRangeSize = kVectorSize/2;
1016 ShuffleRange(&random_, 0, kRangeSize, &vector_);
1021 static_cast<int>(kVectorSize));
1024 TEST_F(VectorShuffleTest, ShufflesEndOfVector) {
1025 const int kRangeSize = kVectorSize / 2;
1026 ShuffleRange(&random_, kRangeSize, kVectorSize, &vector_);
1029 EXPECT_PRED3(RangeIsUnshuffled, vector_, 0, kRangeSize);
1031 static_cast<int>(kVectorSize));
1034 TEST_F(VectorShuffleTest, ShufflesMiddleOfVector) {
1035 const int kRangeSize =
static_cast<int>(kVectorSize) / 3;
1036 ShuffleRange(&random_, kRangeSize, 2*kRangeSize, &vector_);
1039 EXPECT_PRED3(RangeIsUnshuffled, vector_, 0, kRangeSize);
1040 EXPECT_PRED3(RangeIsShuffled, vector_, kRangeSize, 2*kRangeSize);
1041 EXPECT_PRED3(RangeIsUnshuffled, vector_, 2 * kRangeSize,
1042 static_cast<int>(kVectorSize));
1045 TEST_F(VectorShuffleTest, ShufflesRepeatably) {
1047 for (
size_t i = 0;
i < kVectorSize;
i++) {
1048 vector2.push_back(static_cast<int>(
i));
1051 random_.Reseed(1234);
1052 Shuffle(&random_, &vector_);
1053 random_.Reseed(1234);
1054 Shuffle(&random_, &vector2);
1059 for (
size_t i = 0;
i < kVectorSize;
i++) {
1060 EXPECT_EQ(vector_[
i], vector2[i]) <<
" where i is " <<
i;
1066 TEST(AssertHelperTest, AssertHelperIsSmall) {
1073 TEST(StringTest, EndsWithCaseInsensitive) {
1074 EXPECT_TRUE(String::EndsWithCaseInsensitive(
"foobar",
"BAR"));
1075 EXPECT_TRUE(String::EndsWithCaseInsensitive(
"foobaR",
"bar"));
1076 EXPECT_TRUE(String::EndsWithCaseInsensitive(
"foobar",
""));
1077 EXPECT_TRUE(String::EndsWithCaseInsensitive(
"",
""));
1079 EXPECT_FALSE(String::EndsWithCaseInsensitive(
"Foobar",
"foo"));
1080 EXPECT_FALSE(String::EndsWithCaseInsensitive(
"foobar",
"Foo"));
1081 EXPECT_FALSE(String::EndsWithCaseInsensitive(
"",
"foo"));
1087 static const wchar_t*
const kNull =
nullptr;
1090 TEST(StringTest, CaseInsensitiveWideCStringEquals) {
1091 EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(
nullptr,
nullptr));
1092 EXPECT_FALSE(String::CaseInsensitiveWideCStringEquals(kNull, L
""));
1093 EXPECT_FALSE(String::CaseInsensitiveWideCStringEquals(L
"", kNull));
1094 EXPECT_FALSE(String::CaseInsensitiveWideCStringEquals(kNull, L
"foobar"));
1095 EXPECT_FALSE(String::CaseInsensitiveWideCStringEquals(L
"foobar", kNull));
1096 EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(L
"foobar", L
"foobar"));
1097 EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(L
"foobar", L
"FOOBAR"));
1098 EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(L
"FOOBAR", L
"foobar"));
1101 #if GTEST_OS_WINDOWS
1104 TEST(StringTest, ShowWideCString) {
1106 String::ShowWideCString(NULL).c_str());
1107 EXPECT_STREQ(
"", String::ShowWideCString(L
"").c_str());
1108 EXPECT_STREQ(
"foo", String::ShowWideCString(L
"foo").c_str());
1111 # if GTEST_OS_WINDOWS_MOBILE
1112 TEST(StringTest, AnsiAndUtf16Null) {
1113 EXPECT_EQ(NULL, String::AnsiToUtf16(NULL));
1114 EXPECT_EQ(NULL, String::Utf16ToAnsi(NULL));
1117 TEST(StringTest, AnsiAndUtf16ConvertBasic) {
1118 const char* ansi = String::Utf16ToAnsi(L
"str");
1121 const WCHAR* utf16 = String::AnsiToUtf16(
"str");
1122 EXPECT_EQ(0, wcsncmp(L
"str", utf16, 3));
1126 TEST(StringTest, AnsiAndUtf16ConvertPathChars) {
1127 const char* ansi = String::Utf16ToAnsi(L
".:\\ \"*?");
1130 const WCHAR* utf16 = String::AnsiToUtf16(
".:\\ \"*?");
1131 EXPECT_EQ(0, wcsncmp(L
".:\\ \"*?", utf16, 3));
1134 # endif // GTEST_OS_WINDOWS_MOBILE
1136 #endif // GTEST_OS_WINDOWS
1139 TEST(TestPropertyTest, StringValue) {
1146 TEST(TestPropertyTest, ReplaceStringValue) {
1149 property.SetValue(
"2");
1156 static void AddFatalFailure() {
1157 FAIL() <<
"Expected fatal failure.";
1160 static void AddNonfatalFailure() {
1164 class ScopedFakeTestPartResultReporterTest :
public Test {
1170 static void AddFailure(FailureMode failure) {
1171 if (failure == FATAL_FAILURE) {
1174 AddNonfatalFailure();
1181 TEST_F(ScopedFakeTestPartResultReporterTest, InterceptsTestFailures) {
1182 TestPartResultArray results;
1184 ScopedFakeTestPartResultReporter reporter(
1185 ScopedFakeTestPartResultReporter::INTERCEPT_ONLY_CURRENT_THREAD,
1187 AddFailure(NONFATAL_FAILURE);
1188 AddFailure(FATAL_FAILURE);
1192 EXPECT_TRUE(results.GetTestPartResult(0).nonfatally_failed());
1193 EXPECT_TRUE(results.GetTestPartResult(1).fatally_failed());
1196 TEST_F(ScopedFakeTestPartResultReporterTest, DeprecatedConstructor) {
1197 TestPartResultArray results;
1200 ScopedFakeTestPartResultReporter reporter(&results);
1201 AddFailure(NONFATAL_FAILURE);
1206 #if GTEST_IS_THREADSAFE
1208 class ScopedFakeTestPartResultReporterWithThreadsTest
1209 :
public ScopedFakeTestPartResultReporterTest {
1211 static void AddFailureInOtherThread(FailureMode failure) {
1212 ThreadWithParam<FailureMode> thread(&AddFailure, failure,
nullptr);
1217 TEST_F(ScopedFakeTestPartResultReporterWithThreadsTest,
1218 InterceptsTestFailuresInAllThreads) {
1219 TestPartResultArray results;
1221 ScopedFakeTestPartResultReporter reporter(
1222 ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS, &results);
1223 AddFailure(NONFATAL_FAILURE);
1224 AddFailure(FATAL_FAILURE);
1225 AddFailureInOtherThread(NONFATAL_FAILURE);
1226 AddFailureInOtherThread(FATAL_FAILURE);
1230 EXPECT_TRUE(results.GetTestPartResult(0).nonfatally_failed());
1231 EXPECT_TRUE(results.GetTestPartResult(1).fatally_failed());
1232 EXPECT_TRUE(results.GetTestPartResult(2).nonfatally_failed());
1233 EXPECT_TRUE(results.GetTestPartResult(3).fatally_failed());
1236 #endif // GTEST_IS_THREADSAFE
1242 typedef ScopedFakeTestPartResultReporterTest ExpectFatalFailureTest;
1244 TEST_F(ExpectFatalFailureTest, CatchesFatalFaliure) {
1248 TEST_F(ExpectFatalFailureTest, AcceptsStdStringObject) {
1250 ::std::string(
"Expected fatal failure."));
1253 TEST_F(ExpectFatalFailureTest, CatchesFatalFailureOnAllThreads) {
1257 "Expected fatal failure.");
1262 # pragma option push -w-ccc
1268 int NonVoidFunction() {
1274 TEST_F(ExpectFatalFailureTest, CanBeUsedInNonVoidFunction) {
1281 void DoesNotAbortHelper(
bool* aborted) {
1293 TEST_F(ExpectFatalFailureTest, DoesNotAbort) {
1294 bool aborted =
true;
1295 DoesNotAbortHelper(&aborted);
1303 static int global_var = 0;
1304 #define GTEST_USE_UNPROTECTED_COMMA_ global_var++, global_var++
1306 TEST_F(ExpectFatalFailureTest, AcceptsMacroThatExpandsToUnprotectedComma) {
1307 #ifndef __BORLANDC__
1323 typedef ScopedFakeTestPartResultReporterTest ExpectNonfatalFailureTest;
1325 TEST_F(ExpectNonfatalFailureTest, CatchesNonfatalFailure) {
1327 "Expected non-fatal failure.");
1330 TEST_F(ExpectNonfatalFailureTest, AcceptsStdStringObject) {
1332 ::std::string(
"Expected non-fatal failure."));
1335 TEST_F(ExpectNonfatalFailureTest, CatchesNonfatalFailureOnAllThreads) {
1339 "Expected non-fatal failure.");
1345 TEST_F(ExpectNonfatalFailureTest, AcceptsMacroThatExpandsToUnprotectedComma) {
1348 AddNonfatalFailure();
1353 AddNonfatalFailure();
1357 #if GTEST_IS_THREADSAFE
1359 typedef ScopedFakeTestPartResultReporterWithThreadsTest
1360 ExpectFailureWithThreadsTest;
1362 TEST_F(ExpectFailureWithThreadsTest, ExpectFatalFailureOnAllThreads) {
1364 "Expected fatal failure.");
1367 TEST_F(ExpectFailureWithThreadsTest, ExpectNonFatalFailureOnAllThreads) {
1369 AddFailureInOtherThread(NONFATAL_FAILURE),
"Expected non-fatal failure.");
1372 #endif // GTEST_IS_THREADSAFE
1376 TEST(TestPropertyTest, ConstructorWorks) {
1382 TEST(TestPropertyTest, SetValue) {
1385 property.SetValue(
"value_2");
1393 class TestResultTest :
public Test {
1395 typedef std::vector<TestPartResult> TPRVector;
1398 TestPartResult * pr1, * pr2;
1403 void SetUp()
override {
1405 pr1 =
new TestPartResult(TestPartResult::kSuccess,
1411 pr2 =
new TestPartResult(TestPartResult::kFatalFailure,
1425 TPRVector* results1 =
const_cast<TPRVector*
>(
1426 &TestResultAccessor::test_part_results(*r1));
1427 TPRVector* results2 =
const_cast<TPRVector*
>(
1428 &TestResultAccessor::test_part_results(*r2));
1433 results1->push_back(*pr1);
1436 results2->push_back(*pr1);
1437 results2->push_back(*pr2);
1440 void TearDown()
override {
1450 static void CompareTestPartResult(
const TestPartResult&
expected,
1451 const TestPartResult& actual) {
1452 EXPECT_EQ(expected.type(), actual.type());
1453 EXPECT_STREQ(expected.file_name(), actual.file_name());
1454 EXPECT_EQ(expected.line_number(), actual.line_number());
1457 EXPECT_EQ(expected.passed(), actual.passed());
1458 EXPECT_EQ(expected.failed(), actual.failed());
1459 EXPECT_EQ(expected.nonfatally_failed(), actual.nonfatally_failed());
1460 EXPECT_EQ(expected.fatally_failed(), actual.fatally_failed());
1465 TEST_F(TestResultTest, total_part_count) {
1472 TEST_F(TestResultTest, Passed) {
1479 TEST_F(TestResultTest, Failed) {
1487 typedef TestResultTest TestResultDeathTest;
1489 TEST_F(TestResultDeathTest, GetTestPartResult) {
1490 CompareTestPartResult(*pr1, r2->GetTestPartResult(0));
1491 CompareTestPartResult(*pr2, r2->GetTestPartResult(1));
1497 TEST(TestResultPropertyTest, NoPropertiesFoundWhenNoneAreAdded) {
1503 TEST(TestResultPropertyTest, OnePropertyFoundWhenAdded) {
1506 TestResultAccessor::RecordProperty(&test_result,
"testcase", property);
1514 TEST(TestResultPropertyTest, MultiplePropertiesFoundWhenAdded) {
1518 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_1);
1519 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_2);
1531 TEST(TestResultPropertyTest, OverridesValuesForDuplicateKeys) {
1537 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_1_1);
1538 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_2_1);
1539 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_1_2);
1540 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_2_2);
1553 TEST(TestResultPropertyTest, GetTestProperty) {
1558 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_1);
1559 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_2);
1560 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_3);
1591 class GTestFlagSaverTest :
public Test {
1596 static void SetUpTestSuite() {
1597 saver_ =
new GTestFlagSaver;
1613 GTEST_FLAG(stack_trace_depth) = kMaxStackTraceDepth;
1620 static void TearDownTestSuite() {
1627 void VerifyAndModifyFlags() {
1661 GTEST_FLAG(stream_result_to) =
"localhost:1234";
1667 static GTestFlagSaver* saver_;
1670 GTestFlagSaver* GTestFlagSaverTest::saver_ =
nullptr;
1676 TEST_F(GTestFlagSaverTest, ModifyGTestFlags) {
1677 VerifyAndModifyFlags();
1682 TEST_F(GTestFlagSaverTest, VerifyGTestFlags) {
1683 VerifyAndModifyFlags();
1689 static void SetEnv(
const char* name,
const char*
value) {
1690 #if GTEST_OS_WINDOWS_MOBILE
1693 #elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9)
1697 static std::map<std::string, std::string*> added_env;
1701 std::string *prev_env = NULL;
1702 if (added_env.find(name) != added_env.end()) {
1703 prev_env = added_env[name];
1705 added_env[name] =
new std::string(
1706 (
Message() << name <<
"=" << value).GetString());
1711 putenv(const_cast<char*>(added_env[name]->c_str()));
1713 #elif GTEST_OS_WINDOWS // If we are on Windows proper.
1714 _putenv((
Message() << name <<
"=" << value).GetString().c_str());
1716 if (*value ==
'\0') {
1719 setenv(name, value, 1);
1721 #endif // GTEST_OS_WINDOWS_MOBILE
1724 #if !GTEST_OS_WINDOWS_MOBILE
1733 TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenVariableIsNotSet) {
1738 # if !defined(GTEST_GET_INT32_FROM_ENV_)
1742 TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenValueOverflows) {
1743 printf(
"(expecting 2 warnings)\n");
1754 TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenValueIsInvalid) {
1755 printf(
"(expecting 2 warnings)\n");
1764 # endif // !defined(GTEST_GET_INT32_FROM_ENV_)
1769 TEST(Int32FromGTestEnvTest, ParsesAndReturnsValidValue) {
1776 #endif // !GTEST_OS_WINDOWS_MOBILE
1782 TEST(ParseInt32FlagTest, ReturnsFalseForInvalidFlag) {
1783 int32_t value = 123;
1793 TEST(ParseInt32FlagTest, ReturnsDefaultWhenValueOverflows) {
1794 printf(
"(expecting 2 warnings)\n");
1796 int32_t value = 123;
1807 TEST(ParseInt32FlagTest, ReturnsDefaultWhenValueIsInvalid) {
1808 printf(
"(expecting 2 warnings)\n");
1810 int32_t value = 123;
1821 TEST(ParseInt32FlagTest, ParsesAndReturnsValidValue) {
1822 int32_t value = 123;
1834 #if !GTEST_OS_WINDOWS_MOBILE
1835 TEST(Int32FromEnvOrDieTest, ParsesAndReturnsValidValue) {
1842 #endif // !GTEST_OS_WINDOWS_MOBILE
1846 TEST(Int32FromEnvOrDieDeathTest, AbortsOnFailure) {
1855 TEST(Int32FromEnvOrDieDeathTest, AbortsOnInt32Overflow) {
1864 TEST(ShouldRunTestOnShardTest, IsPartitionWhenThereIsOneShard) {
1874 void SetUp()
override {
1879 void TearDown()
override {
1880 SetEnv(index_var_,
"");
1881 SetEnv(total_var_,
"");
1884 const char* index_var_;
1885 const char* total_var_;
1890 TEST_F(ShouldShardTest, ReturnsFalseWhenNeitherEnvVarIsSet) {
1891 SetEnv(index_var_,
"");
1892 SetEnv(total_var_,
"");
1899 TEST_F(ShouldShardTest, ReturnsFalseWhenTotalShardIsOne) {
1900 SetEnv(index_var_,
"0");
1901 SetEnv(total_var_,
"1");
1909 #if !GTEST_OS_WINDOWS_MOBILE
1910 TEST_F(ShouldShardTest, WorksWhenShardEnvVarsAreValid) {
1911 SetEnv(index_var_,
"4");
1912 SetEnv(total_var_,
"22");
1916 SetEnv(index_var_,
"8");
1917 SetEnv(total_var_,
"9");
1921 SetEnv(index_var_,
"0");
1922 SetEnv(total_var_,
"9");
1926 #endif // !GTEST_OS_WINDOWS_MOBILE
1930 typedef ShouldShardTest ShouldShardDeathTest;
1932 TEST_F(ShouldShardDeathTest, AbortsWhenShardingEnvVarsAreInvalid) {
1933 SetEnv(index_var_,
"4");
1934 SetEnv(total_var_,
"4");
1937 SetEnv(index_var_,
"4");
1938 SetEnv(total_var_,
"-2");
1941 SetEnv(index_var_,
"5");
1942 SetEnv(total_var_,
"");
1945 SetEnv(index_var_,
"");
1946 SetEnv(total_var_,
"5");
1952 TEST(ShouldRunTestOnShardTest, IsPartitionWhenThereAreFiveShards) {
1954 const int num_tests = 17;
1955 const int num_shards = 5;
1958 for (
int test_id = 0; test_id < num_tests; test_id++) {
1959 int prev_selected_shard_index = -1;
1960 for (
int shard_index = 0; shard_index < num_shards; shard_index++) {
1962 if (prev_selected_shard_index < 0) {
1963 prev_selected_shard_index = shard_index;
1965 ADD_FAILURE() <<
"Shard " << prev_selected_shard_index <<
" and "
1966 << shard_index <<
" are both selected to run test " << test_id;
1974 for (
int shard_index = 0; shard_index < num_shards; shard_index++) {
1975 int num_tests_on_shard = 0;
1976 for (
int test_id = 0; test_id < num_tests; test_id++) {
1977 num_tests_on_shard +=
1980 EXPECT_GE(num_tests_on_shard, num_tests / num_shards);
1994 TEST(UnitTestTest, CanGetOriginalWorkingDir) {
1995 ASSERT_TRUE(UnitTest::GetInstance()->original_working_dir() !=
nullptr);
1996 EXPECT_STRNE(UnitTest::GetInstance()->original_working_dir(),
"");
1999 TEST(UnitTestTest, ReturnsPlausibleTimestamp) {
2000 EXPECT_LT(0, UnitTest::GetInstance()->start_timestamp());
2007 void ExpectNonFatalFailureRecordingPropertyWithReservedKey(
2008 const TestResult& test_result,
const char* key) {
2011 <<
"' recorded unexpectedly.";
2014 void ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2018 ExpectNonFatalFailureRecordingPropertyWithReservedKey(*test_info->
result(),
2022 void ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2027 ExpectNonFatalFailureRecordingPropertyWithReservedKey(
2031 void ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2033 ExpectNonFatalFailureRecordingPropertyWithReservedKey(
2034 UnitTest::GetInstance()->ad_hoc_test_result(), key);
2040 class UnitTestRecordPropertyTest :
2043 static void SetUpTestSuite() {
2044 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2046 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2048 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2050 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2052 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2054 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2057 Test::RecordProperty(
"test_case_key_1",
"1");
2060 UnitTest::GetInstance()->current_test_suite();
2073 TEST_F(UnitTestRecordPropertyTest, OnePropertyFoundWhenAdded) {
2074 UnitTestRecordProperty(
"key_1",
"1");
2076 ASSERT_EQ(1, unit_test_.ad_hoc_test_result().test_property_count());
2079 unit_test_.ad_hoc_test_result().GetTestProperty(0).key());
2081 unit_test_.ad_hoc_test_result().GetTestProperty(0).value());
2085 TEST_F(UnitTestRecordPropertyTest, MultiplePropertiesFoundWhenAdded) {
2086 UnitTestRecordProperty(
"key_1",
"1");
2087 UnitTestRecordProperty(
"key_2",
"2");
2089 ASSERT_EQ(2, unit_test_.ad_hoc_test_result().test_property_count());
2092 unit_test_.ad_hoc_test_result().GetTestProperty(0).key());
2093 EXPECT_STREQ(
"1", unit_test_.ad_hoc_test_result().GetTestProperty(0).value());
2096 unit_test_.ad_hoc_test_result().GetTestProperty(1).key());
2097 EXPECT_STREQ(
"2", unit_test_.ad_hoc_test_result().GetTestProperty(1).value());
2101 TEST_F(UnitTestRecordPropertyTest, OverridesValuesForDuplicateKeys) {
2102 UnitTestRecordProperty(
"key_1",
"1");
2103 UnitTestRecordProperty(
"key_2",
"2");
2104 UnitTestRecordProperty(
"key_1",
"12");
2105 UnitTestRecordProperty(
"key_2",
"22");
2107 ASSERT_EQ(2, unit_test_.ad_hoc_test_result().test_property_count());
2110 unit_test_.ad_hoc_test_result().GetTestProperty(0).key());
2112 unit_test_.ad_hoc_test_result().GetTestProperty(0).value());
2115 unit_test_.ad_hoc_test_result().GetTestProperty(1).key());
2117 unit_test_.ad_hoc_test_result().GetTestProperty(1).value());
2120 TEST_F(UnitTestRecordPropertyTest,
2121 AddFailureInsideTestsWhenUsingTestSuiteReservedKeys) {
2122 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2124 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2126 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2128 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2130 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2132 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2136 TEST_F(UnitTestRecordPropertyTest,
2137 AddRecordWithReservedKeysGeneratesCorrectPropertyList) {
2139 Test::RecordProperty(
"name",
"1"),
2140 "'classname', 'name', 'status', 'time', 'type_param', 'value_param',"
2141 " 'file', and 'line' are reserved");
2144 class UnitTestRecordPropertyTestEnvironment :
public Environment {
2146 void TearDown()
override {
2147 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2149 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2151 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2153 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2155 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2157 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2159 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2161 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2179 bool IsEven(
int n) {
2180 return (n % 2) == 0;
2184 struct IsEvenFunctor {
2185 bool operator()(
int n) {
return IsEven(n); }
2190 AssertionResult AssertIsEven(
const char* expr,
int n) {
2196 msg << expr <<
" evaluates to " << n <<
", which is not even.";
2202 AssertionResult ResultIsEven(
int n) {
2212 AssertionResult ResultIsEvenNoExplanation(
int n) {
2221 struct AssertIsEvenFunctor {
2222 AssertionResult operator()(
const char* expr,
int n) {
2223 return AssertIsEven(expr, n);
2228 bool SumIsEven2(
int n1,
int n2) {
2229 return IsEven(n1 + n2);
2234 struct SumIsEven3Functor {
2235 bool operator()(
int n1,
int n2,
int n3) {
2236 return IsEven(n1 + n2 + n3);
2242 AssertionResult AssertSumIsEven4(
2243 const char* e1,
const char* e2,
const char* e3,
const char* e4,
2244 int n1,
int n2,
int n3,
int n4) {
2245 const int sum = n1 + n2 + n3 + n4;
2251 msg << e1 <<
" + " << e2 <<
" + " << e3 <<
" + " << e4
2252 <<
" (" << n1 <<
" + " << n2 <<
" + " << n3 <<
" + " << n4
2253 <<
") evaluates to " << sum <<
", which is not even.";
2259 struct AssertSumIsEven5Functor {
2260 AssertionResult operator()(
2261 const char* e1,
const char* e2,
const char* e3,
const char* e4,
2262 const char* e5,
int n1,
int n2,
int n3,
int n4,
int n5) {
2263 const int sum = n1 + n2 + n3 + n4 + n5;
2269 msg << e1 <<
" + " << e2 <<
" + " << e3 <<
" + " << e4 <<
" + " << e5
2271 << n1 <<
" + " << n2 <<
" + " << n3 <<
" + " << n4 <<
" + " << n5
2272 <<
") evaluates to " << sum <<
", which is not even.";
2281 TEST(Pred1Test, WithoutFormat) {
2283 EXPECT_PRED1(IsEvenFunctor(), 2) <<
"This failure is UNEXPECTED!";
2288 EXPECT_PRED1(IsEven, 5) <<
"This failure is expected.";
2289 },
"This failure is expected.");
2291 "evaluates to false");
2295 TEST(Pred1Test, WithFormat) {
2299 <<
"This failure is UNEXPECTED!";
2304 "n evaluates to 5, which is not even.");
2307 },
"This failure is expected.");
2312 TEST(Pred1Test, SingleEvaluationOnFailure) {
2316 EXPECT_EQ(1, n) <<
"The argument is not evaluated exactly once.";
2321 <<
"This failure is expected.";
2322 },
"This failure is expected.");
2323 EXPECT_EQ(2, n) <<
"The argument is not evaluated exactly once.";
2330 TEST(PredTest, WithoutFormat) {
2332 ASSERT_PRED2(SumIsEven2, 2, 4) <<
"This failure is UNEXPECTED!";
2339 EXPECT_PRED2(SumIsEven2, n1, n2) <<
"This failure is expected.";
2340 },
"This failure is expected.");
2343 },
"evaluates to false");
2347 TEST(PredTest, WithFormat) {
2350 "This failure is UNEXPECTED!";
2360 },
"evaluates to 13, which is not even.");
2363 <<
"This failure is expected.";
2364 },
"This failure is expected.");
2369 TEST(PredTest, SingleEvaluationOnFailure) {
2374 EXPECT_EQ(1, n1) <<
"Argument 1 is not evaluated exactly once.";
2375 EXPECT_EQ(1, n2) <<
"Argument 2 is not evaluated exactly once.";
2383 n1++, n2++, n3++, n4++, n5++)
2384 <<
"This failure is UNEXPECTED!";
2385 EXPECT_EQ(1, n1) <<
"Argument 1 is not evaluated exactly once.";
2386 EXPECT_EQ(1, n2) <<
"Argument 2 is not evaluated exactly once.";
2387 EXPECT_EQ(1, n3) <<
"Argument 3 is not evaluated exactly once.";
2388 EXPECT_EQ(1, n4) <<
"Argument 4 is not evaluated exactly once.";
2389 EXPECT_EQ(1, n5) <<
"Argument 5 is not evaluated exactly once.";
2395 <<
"This failure is expected.";
2396 },
"This failure is expected.");
2397 EXPECT_EQ(1, n1) <<
"Argument 1 is not evaluated exactly once.";
2398 EXPECT_EQ(1, n2) <<
"Argument 2 is not evaluated exactly once.";
2399 EXPECT_EQ(1, n3) <<
"Argument 3 is not evaluated exactly once.";
2402 n1 = n2 = n3 = n4 = 0;
2405 },
"evaluates to 1, which is not even.");
2406 EXPECT_EQ(1, n1) <<
"Argument 1 is not evaluated exactly once.";
2407 EXPECT_EQ(1, n2) <<
"Argument 2 is not evaluated exactly once.";
2408 EXPECT_EQ(1, n3) <<
"Argument 3 is not evaluated exactly once.";
2409 EXPECT_EQ(1, n4) <<
"Argument 4 is not evaluated exactly once.";
2413 TEST(PredTest, ExpectPredEvalFailure) {
2414 std::set<int> set_a = {2, 1, 3, 4, 5};
2415 std::set<int> set_b = {0, 4, 8};
2416 const auto compare_sets = [] (std::set<int>, std::set<int>) {
return false; };
2419 "compare_sets(set_a, set_b) evaluates to false, where\nset_a evaluates "
2420 "to { 1, 2, 3, 4, 5 }\nset_b evaluates to { 0, 4, 8 }");
2426 bool IsPositive(
double x) {
2430 template <
typename T>
2431 bool IsNegative(
T x) {
2435 template <
typename T1,
typename T2>
2436 bool GreaterThan(
T1 x1,
T2 x2) {
2442 TEST(PredicateAssertionTest, AcceptsOverloadedFunction) {
2450 TEST(PredicateAssertionTest, AcceptsTemplateFunction) {
2461 AssertionResult IsPositiveFormat(
const char* ,
int n) {
2466 AssertionResult IsPositiveFormat(
const char* ,
double x) {
2471 template <
typename T>
2472 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) {
2503 const char *
const p1 =
"good";
2507 const char p2[] =
"good";
2511 " \"bad\"\n \"good\"");
2515 TEST(StringAssertionTest, ASSERT_STREQ_Null) {
2516 ASSERT_STREQ(static_cast<const char*>(
nullptr),
nullptr);
2521 TEST(StringAssertionTest, ASSERT_STREQ_Null2) {
2535 "\"Hi\" vs \"Hi\"");
2562 TEST(StringAssertionTest, STREQ_Wide) {
2564 ASSERT_STREQ(static_cast<const wchar_t*>(
nullptr),
nullptr);
2585 EXPECT_STREQ(L
"abc\x8119", L
"abc\x8121") <<
"Expected failure";
2586 },
"Expected failure");
2590 TEST(StringAssertionTest, STRNE_Wide) {
2594 EXPECT_STRNE(static_cast<const wchar_t*>(
nullptr),
nullptr);
2617 ASSERT_STRNE(L
"abc\x8119", L
"abc\x8120") <<
"This shouldn't happen";
2624 TEST(IsSubstringTest, ReturnsCorrectResultForCString) {
2635 TEST(IsSubstringTest, ReturnsCorrectResultForWideCString) {
2641 IsSubstring(
"",
"", static_cast<const wchar_t*>(
nullptr),
nullptr));
2647 TEST(IsSubstringTest, GeneratesCorrectMessageForCString) {
2649 " Actual: \"needle\"\n"
2650 "Expected: a substring of haystack_expr\n"
2651 "Which is: \"haystack\"",
2653 "needle",
"haystack").failure_message());
2658 TEST(IsSubstringTest, ReturnsCorrectResultsForStdString) {
2663 #if GTEST_HAS_STD_WSTRING
2666 TEST(IsSubstringTest, ReturnsCorrectResultForStdWstring) {
2673 TEST(IsSubstringTest, GeneratesCorrectMessageForWstring) {
2675 " Actual: L\"needle\"\n"
2676 "Expected: a substring of haystack_expr\n"
2677 "Which is: L\"haystack\"",
2679 "needle_expr",
"haystack_expr",
2680 ::std::wstring(L
"needle"), L
"haystack").failure_message());
2683 #endif // GTEST_HAS_STD_WSTRING
2689 TEST(IsNotSubstringTest, ReturnsCorrectResultForCString) {
2696 TEST(IsNotSubstringTest, ReturnsCorrectResultForWideCString) {
2703 TEST(IsNotSubstringTest, GeneratesCorrectMessageForWideCString) {
2705 " Actual: L\"needle\"\n"
2706 "Expected: not a substring of haystack_expr\n"
2707 "Which is: L\"two needles\"",
2709 "needle_expr",
"haystack_expr",
2710 L
"needle", L
"two needles").failure_message());
2715 TEST(IsNotSubstringTest, ReturnsCorrectResultsForStdString) {
2722 TEST(IsNotSubstringTest, GeneratesCorrectMessageForStdString) {
2724 " Actual: \"needle\"\n"
2725 "Expected: not a substring of haystack_expr\n"
2726 "Which is: \"two needles\"",
2728 "needle_expr",
"haystack_expr",
2729 ::std::string(
"needle"),
"two needles").failure_message());
2732 #if GTEST_HAS_STD_WSTRING
2736 TEST(IsNotSubstringTest, ReturnsCorrectResultForStdWstring) {
2738 IsNotSubstring(
"",
"", ::std::wstring(L
"needle"), L
"two needles"));
2742 #endif // GTEST_HAS_STD_WSTRING
2746 template <
typename RawType>
2747 class FloatingPointTest :
public Test {
2751 RawType close_to_positive_zero;
2752 RawType close_to_negative_zero;
2753 RawType further_from_negative_zero;
2755 RawType close_to_one;
2756 RawType further_from_one;
2759 RawType close_to_infinity;
2760 RawType further_from_infinity;
2767 typedef typename Floating::Bits Bits;
2769 void SetUp()
override {
2770 const size_t max_ulps = Floating::kMaxUlps;
2773 const Bits zero_bits = Floating(0).
bits();
2776 values_.close_to_positive_zero = Floating::ReinterpretBits(
2777 zero_bits + max_ulps/2);
2778 values_.close_to_negative_zero = -Floating::ReinterpretBits(
2779 zero_bits + max_ulps - max_ulps/2);
2780 values_.further_from_negative_zero = -Floating::ReinterpretBits(
2781 zero_bits + max_ulps + 1 - max_ulps/2);
2784 const Bits one_bits = Floating(1).bits();
2787 values_.close_to_one = Floating::ReinterpretBits(one_bits + max_ulps);
2788 values_.further_from_one = Floating::ReinterpretBits(
2789 one_bits + max_ulps + 1);
2792 values_.infinity = Floating::Infinity();
2795 const Bits infinity_bits = Floating(values_.infinity).bits();
2798 values_.close_to_infinity = Floating::ReinterpretBits(
2799 infinity_bits - max_ulps);
2800 values_.further_from_infinity = Floating::ReinterpretBits(
2801 infinity_bits - max_ulps - 1);
2806 values_.nan1 = Floating::ReinterpretBits(Floating::kExponentBitMask
2807 | (static_cast<Bits>(1) << (Floating::kFractionBitCount - 1)) | 1);
2808 values_.nan2 = Floating::ReinterpretBits(Floating::kExponentBitMask
2809 | (static_cast<Bits>(1) << (Floating::kFractionBitCount - 1)) | 200);
2813 EXPECT_EQ(
sizeof(RawType),
sizeof(Bits));
2816 static TestValues values_;
2819 template <
typename RawType>
2820 typename FloatingPointTest<RawType>::TestValues
2821 FloatingPointTest<RawType>::values_;
2824 typedef FloatingPointTest<float> FloatTest;
2827 TEST_F(FloatTest, Size) {
2832 TEST_F(FloatTest, Zeros) {
2845 TEST_F(FloatTest, AlmostZeros) {
2852 static const FloatTest::TestValues& v = this->values_;
2860 v.further_from_negative_zero);
2861 },
"v.further_from_negative_zero");
2865 TEST_F(FloatTest, SmallDiff) {
2868 "values_.further_from_one");
2872 TEST_F(FloatTest, LargeDiff) {
2881 TEST_F(FloatTest, Infinity) {
2885 "-values_.infinity");
2901 static const FloatTest::TestValues& v = this->values_;
2915 TEST_F(FloatTest, Reflexive) {
2922 TEST_F(FloatTest, Commutative) {
2936 "The difference between 1.0f and 1.5f is 0.5, "
2937 "which exceeds 0.25f");
2945 "The difference between 1.0f and 1.5f is 0.5, "
2946 "which exceeds 0.25f");
2950 TEST_F(FloatTest, FloatLESucceeds) {
2959 TEST_F(FloatTest, FloatLEFails) {
2962 "(2.0f) <= (1.0f)");
2967 },
"(values_.further_from_one) <= (1.0f)");
2971 },
"(values_.nan1) <= (values_.infinity)");
2974 },
"(-values_.infinity) <= (values_.nan1)");
2977 },
"(values_.nan1) <= (values_.nan1)");
2981 typedef FloatingPointTest<double> DoubleTest;
2984 TEST_F(DoubleTest, Size) {
2989 TEST_F(DoubleTest, Zeros) {
3002 TEST_F(DoubleTest, AlmostZeros) {
3009 static const DoubleTest::TestValues& v = this->values_;
3017 v.further_from_negative_zero);
3018 },
"v.further_from_negative_zero");
3022 TEST_F(DoubleTest, SmallDiff) {
3025 "values_.further_from_one");
3029 TEST_F(DoubleTest, LargeDiff) {
3038 TEST_F(DoubleTest, Infinity) {
3042 "-values_.infinity");
3051 TEST_F(DoubleTest, NaN) {
3052 static const DoubleTest::TestValues& v = this->values_;
3064 TEST_F(DoubleTest, Reflexive) {
3071 TEST_F(DoubleTest, Commutative) {
3085 "The difference between 1.0 and 1.5 is 0.5, "
3086 "which exceeds 0.25");
3094 "The difference between 1.0 and 1.5 is 0.5, "
3095 "which exceeds 0.25");
3099 TEST_F(DoubleTest, DoubleLESucceeds) {
3108 TEST_F(DoubleTest, DoubleLEFails) {
3116 },
"(values_.further_from_one) <= (1.0)");
3120 },
"(values_.nan1) <= (values_.infinity)");
3123 },
" (-values_.infinity) <= (values_.nan1)");
3126 },
"(values_.nan1) <= (values_.nan1)");
3136 FAIL() <<
"Unexpected failure: Disabled test should not be run.";
3147 TEST(DISABLED_TestSuite, TestShouldNotRun) {
3148 FAIL() <<
"Unexpected failure: Test in disabled test case should not be run.";
3153 TEST(DISABLED_TestSuite, DISABLED_TestShouldNotRun) {
3154 FAIL() <<
"Unexpected failure: Test in disabled test case should not be run.";
3159 class DisabledTestsTest :
public Test {
3161 static void SetUpTestSuite() {
3162 FAIL() <<
"Unexpected failure: All tests disabled in test case. "
3163 "SetUpTestSuite() should not be called.";
3166 static void TearDownTestSuite() {
3167 FAIL() <<
"Unexpected failure: All tests disabled in test case. "
3168 "TearDownTestSuite() should not be called.";
3172 TEST_F(DisabledTestsTest, DISABLED_TestShouldNotRun_1) {
3173 FAIL() <<
"Unexpected failure: Disabled test should not be run.";
3176 TEST_F(DisabledTestsTest, DISABLED_TestShouldNotRun_2) {
3177 FAIL() <<
"Unexpected failure: Disabled test should not be run.";
3182 #if GTEST_HAS_TYPED_TEST
3184 template <
typename T>
3192 FAIL() <<
"Unexpected failure: Disabled typed test should not run.";
3195 template <
typename T>
3196 class DISABLED_TypedTest :
public Test {
3201 TYPED_TEST(DISABLED_TypedTest, ShouldNotRun) {
3202 FAIL() <<
"Unexpected failure: Disabled typed test should not run.";
3205 #endif // GTEST_HAS_TYPED_TEST
3209 #if GTEST_HAS_TYPED_TEST_P
3211 template <
typename T>
3212 class TypedTestP :
public Test {
3218 FAIL() <<
"Unexpected failure: "
3219 <<
"Disabled type-parameterized test should not run.";
3226 template <
typename T>
3227 class DISABLED_TypedTestP :
public Test {
3233 FAIL() <<
"Unexpected failure: "
3234 <<
"Disabled type-parameterized test should not run.";
3241 #endif // GTEST_HAS_TYPED_TEST_P
3245 class SingleEvaluationTest :
public Test {
3250 static void CompareAndIncrementCharPtrs() {
3256 static void CompareAndIncrementInts() {
3261 SingleEvaluationTest() {
3268 static const char*
const s1_;
3269 static const char*
const s2_;
3270 static const char* p1_;
3271 static const char* p2_;
3277 const char*
const SingleEvaluationTest::s1_ =
"01234";
3278 const char*
const SingleEvaluationTest::s2_ =
"abcde";
3279 const char* SingleEvaluationTest::p1_;
3280 const char* SingleEvaluationTest::p2_;
3281 int SingleEvaluationTest::a_;
3282 int SingleEvaluationTest::b_;
3286 TEST_F(SingleEvaluationTest, FailedASSERT_STREQ) {
3294 TEST_F(SingleEvaluationTest, ASSERT_STR) {
3309 TEST_F(SingleEvaluationTest, FailedASSERT_NE) {
3311 "(a_++) != (b_++)");
3317 TEST_F(SingleEvaluationTest, OtherCases) {
3346 #if GTEST_HAS_EXCEPTIONS
3350 #define ERROR_DESC "std::runtime_error"
3352 #else // GTEST_HAS_RTTI
3354 #define ERROR_DESC "an std::exception-derived error"
3356 #endif // GTEST_HAS_RTTI
3358 void ThrowAnInteger() {
3361 void ThrowRuntimeError(
const char* what) {
3362 throw std::runtime_error(what);
3366 TEST_F(SingleEvaluationTest, ExceptionTests) {
3378 }, bool),
"throws a different type");
3384 ThrowRuntimeError(
"A description");
3385 }, bool),
"throws " ERROR_DESC
" with description \"A description\"");
3415 #endif // GTEST_HAS_EXCEPTIONS
3418 class NoFatalFailureTest :
public Test {
3421 void FailsNonFatal() {
3425 FAIL() <<
"some fatal failure";
3428 void DoAssertNoFatalFailureOnFails() {
3433 void DoExpectNoFatalFailureOnFails() {
3439 TEST_F(NoFatalFailureTest, NoFailure) {
3444 TEST_F(NoFatalFailureTest, NonFatalIsNoFailure) {
3447 "some non-fatal failure");
3450 "some non-fatal failure");
3453 TEST_F(NoFatalFailureTest, AssertNoFatalFailureOnFatalFailure) {
3454 TestPartResultArray gtest_failures;
3456 ScopedFakeTestPartResultReporter gtest_reporter(>est_failures);
3457 DoAssertNoFatalFailureOnFails();
3460 EXPECT_EQ(TestPartResult::kFatalFailure,
3461 gtest_failures.GetTestPartResult(0).type());
3462 EXPECT_EQ(TestPartResult::kFatalFailure,
3463 gtest_failures.GetTestPartResult(1).type());
3465 gtest_failures.GetTestPartResult(0).message());
3467 gtest_failures.GetTestPartResult(1).message());
3470 TEST_F(NoFatalFailureTest, ExpectNoFatalFailureOnFatalFailure) {
3471 TestPartResultArray gtest_failures;
3473 ScopedFakeTestPartResultReporter gtest_reporter(>est_failures);
3474 DoExpectNoFatalFailureOnFails();
3477 EXPECT_EQ(TestPartResult::kFatalFailure,
3478 gtest_failures.GetTestPartResult(0).type());
3479 EXPECT_EQ(TestPartResult::kNonFatalFailure,
3480 gtest_failures.GetTestPartResult(1).type());
3481 EXPECT_EQ(TestPartResult::kNonFatalFailure,
3482 gtest_failures.GetTestPartResult(2).type());
3484 gtest_failures.GetTestPartResult(0).message());
3486 gtest_failures.GetTestPartResult(1).message());
3488 gtest_failures.GetTestPartResult(2).message());
3491 TEST_F(NoFatalFailureTest, MessageIsStreamable) {
3492 TestPartResultArray gtest_failures;
3494 ScopedFakeTestPartResultReporter gtest_reporter(>est_failures);
3498 EXPECT_EQ(TestPartResult::kNonFatalFailure,
3499 gtest_failures.GetTestPartResult(0).type());
3500 EXPECT_EQ(TestPartResult::kNonFatalFailure,
3501 gtest_failures.GetTestPartResult(1).type());
3503 gtest_failures.GetTestPartResult(0).message());
3505 gtest_failures.GetTestPartResult(1).message());
3510 std::string EditsToString(
const std::vector<EditType>& edits) {
3512 for (
size_t i = 0;
i < edits.size(); ++
i) {
3513 static const char kEdits[] =
" +-/";
3514 out.append(1, kEdits[edits[
i]]);
3519 std::vector<size_t> CharsToIndices(
const std::string& str) {
3520 std::vector<size_t> out;
3521 for (
size_t i = 0;
i < str.size(); ++
i) {
3522 out.push_back(static_cast<size_t>(str[
i]));
3527 std::vector<std::string> CharsToLines(
const std::string& str) {
3528 std::vector<std::string> out;
3529 for (
size_t i = 0;
i < str.size(); ++
i) {
3530 out.push_back(str.substr(
i, 1));
3535 TEST(EditDistance, TestSuites) {
3540 const char* expected_edits;
3541 const char* expected_diff;
3543 static const Case kCases[] = {
3545 {__LINE__,
"A",
"A",
" ",
""},
3546 {__LINE__,
"ABCDE",
"ABCDE",
" ",
""},
3548 {__LINE__,
"X",
"XA",
" +",
"@@ +1,2 @@\n X\n+A\n"},
3549 {__LINE__,
"X",
"XABCD",
" ++++",
"@@ +1,5 @@\n X\n+A\n+B\n+C\n+D\n"},
3551 {__LINE__,
"XA",
"X",
" -",
"@@ -1,2 @@\n X\n-A\n"},
3552 {__LINE__,
"XABCD",
"X",
" ----",
"@@ -1,5 @@\n X\n-A\n-B\n-C\n-D\n"},
3554 {__LINE__,
"A",
"a",
"/",
"@@ -1,1 +1,1 @@\n-A\n+a\n"},
3555 {__LINE__,
"ABCD",
"abcd",
"////",
3556 "@@ -1,4 +1,4 @@\n-A\n-B\n-C\n-D\n+a\n+b\n+c\n+d\n"},
3558 {__LINE__,
"ABCDEFGH",
"ABXEGH1",
" -/ - +",
3559 "@@ -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"},
3560 {__LINE__,
"AAAABCCCC",
"ABABCDCDC",
"- / + / ",
3561 "@@ -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"},
3562 {__LINE__,
"ABCDE",
"BCDCD",
"- +/",
3563 "@@ -1,5 +1,5 @@\n-A\n B\n C\n D\n-E\n+C\n+D\n"},
3564 {__LINE__,
"ABCDEFGHIJKL",
"BCDCDEFGJKLJK",
"- ++ -- ++",
3565 "@@ -1,4 +1,5 @@\n-A\n B\n+C\n+D\n C\n D\n"
3566 "@@ -6,7 +7,7 @@\n F\n G\n-H\n-I\n J\n K\n L\n+J\n+K\n"},
3568 for (
const Case*
c = kCases;
c->left; ++
c) {
3571 CharsToIndices(
c->right))))
3572 <<
"Left <" <<
c->left <<
"> Right <" <<
c->right <<
"> Edits <"
3574 CharsToIndices(
c->left), CharsToIndices(
c->right))) <<
">";
3576 CharsToLines(
c->right)))
3577 <<
"Left <" <<
c->left <<
"> Right <" <<
c->right <<
"> Diff <"
3585 const std::string foo_val(
"5"), bar_val(
"6");
3586 const std::string msg1(
3587 EqFailure(
"foo",
"bar", foo_val, bar_val,
false)
3588 .failure_message());
3590 "Expected equality of these values:\n"
3597 const std::string msg2(
3598 EqFailure(
"foo",
"6", foo_val, bar_val,
false)
3599 .failure_message());
3601 "Expected equality of these values:\n"
3607 const std::string msg3(
3608 EqFailure(
"5",
"bar", foo_val, bar_val,
false)
3609 .failure_message());
3611 "Expected equality of these values:\n"
3617 const std::string msg4(
3618 EqFailure(
"5",
"6", foo_val, bar_val,
false).failure_message());
3620 "Expected equality of these values:\n"
3625 const std::string msg5(
3627 std::string(
"\"x\""), std::string(
"\"y\""),
3628 true).failure_message());
3630 "Expected equality of these values:\n"
3632 " Which is: \"x\"\n"
3634 " Which is: \"y\"\n"
3639 TEST(AssertionTest, EqFailureWithDiff) {
3640 const std::string left(
3641 "1\\n2XXX\\n3\\n5\\n6\\n7\\n8\\n9\\n10\\n11\\n12XXX\\n13\\n14\\n15");
3642 const std::string right(
3643 "1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n11\\n12\\n13\\n14");
3644 const std::string msg1(
3645 EqFailure(
"left",
"right", left, right,
false).failure_message());
3647 "Expected equality of these values:\n"
3650 "1\\n2XXX\\n3\\n5\\n6\\n7\\n8\\n9\\n10\\n11\\n12XXX\\n13\\n14\\n15\n"
3652 " Which is: 1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n11\\n12\\n13\\n14\n"
3653 "With diff:\n@@ -1,5 +1,6 @@\n 1\n-2XXX\n+2\n 3\n+4\n 5\n 6\n"
3654 "@@ -7,8 +8,6 @@\n 8\n 9\n-10\n 11\n-12XXX\n+12\n 13\n 14\n-15\n",
3660 const std::string
foo(
"foo");
3673 # pragma option push -w-ccc -w-rch
3684 TEST(AssertionTest, AssertTrueWithAssertionResult) {
3686 #ifndef __BORLANDC__
3689 "Value of: ResultIsEven(3)\n"
3690 " Actual: false (3 is odd)\n"
3695 "Value of: ResultIsEvenNoExplanation(3)\n"
3696 " Actual: false (3 is odd)\n"
3710 TEST(AssertionTest, AssertFalseWithAssertionResult) {
3712 #ifndef __BORLANDC__
3715 "Value of: ResultIsEven(2)\n"
3716 " Actual: true (2 is even)\n"
3721 "Value of: ResultIsEvenNoExplanation(2)\n"
3734 TEST(ExpectTest, ASSERT_EQ_Double) {
3747 "Expected equality of these values:\n"
3754 TEST(AssertionTest, ASSERT_EQ_NULL) {
3756 const char*
p =
nullptr;
3768 TEST(ExpectTest, ASSERT_EQ_0) {
3783 "Expected: ('a') != ('a'), "
3784 "actual: 'a' (97, 0x61) vs 'a' (97, 0x61)");
3792 "Expected: (2) <= (0), actual: 2 vs 0");
3799 "Expected: (2) < (2), actual: 2 vs 2");
3807 "Expected: (2) >= (3), actual: 2 vs 3");
3814 "Expected: (2) > (2), actual: 2 vs 2");
3817 #if GTEST_HAS_EXCEPTIONS
3819 void ThrowNothing() {}
3825 # ifndef __BORLANDC__
3830 "Expected: ThrowAnInteger() throws an exception of type bool.\n"
3831 " Actual: it throws a different type.");
3833 ASSERT_THROW(ThrowRuntimeError(
"A description"), std::logic_error),
3834 "Expected: ThrowRuntimeError(\"A description\") "
3835 "throws an exception of type std::logic_error.\n "
3836 "Actual: it throws " ERROR_DESC
" "
3837 "with description \"A description\".");
3842 "Expected: ThrowNothing() throws an exception of type bool.\n"
3843 " Actual: it throws nothing.");
3850 "Expected: ThrowAnInteger() doesn't throw an exception."
3851 "\n Actual: it throws.");
3853 "Expected: ThrowRuntimeError(\"A description\") "
3854 "doesn't throw an exception.\n "
3855 "Actual: it throws " ERROR_DESC
" "
3856 "with description \"A description\".");
3864 "Expected: ThrowNothing() throws an exception.\n"
3865 " Actual: it doesn't.");
3868 #endif // GTEST_HAS_EXCEPTIONS
3872 TEST(AssertionTest, AssertPrecedence) {
3874 bool false_value =
false;
3884 TEST(AssertionTest, NonFixtureSubroutine) {
3886 " x\n Which is: 2");
3892 explicit Uncopyable(
int a_value) :
value_(a_value) {}
3895 bool operator==(
const Uncopyable& rhs)
const {
3896 return value() == rhs.value();
3901 Uncopyable(
const Uncopyable&);
3906 ::std::ostream&
operator<<(::std::ostream& os,
const Uncopyable& value) {
3907 return os << value.value();
3911 bool IsPositiveUncopyable(
const Uncopyable& x) {
3912 return x.value() > 0;
3916 void TestAssertNonPositive() {
3921 void TestAssertEqualsUncopyable() {
3928 TEST(AssertionTest, AssertWorksWithUncopyableObject) {
3933 "IsPositiveUncopyable(y) evaluates to false, where\ny evaluates to -1");
3935 "Expected equality of these values:\n"
3936 " x\n Which is: 5\n y\n Which is: -1");
3940 TEST(AssertionTest, ExpectWorksWithUncopyableObject) {
3945 "IsPositiveUncopyable(y) evaluates to false, where\ny evaluates to -1");
3948 "Expected equality of these values:\n"
3949 " x\n Which is: 5\n y\n Which is: -1");
3965 #if !defined(__SUNPRO_CC) && !defined(__HP_aCC)
3988 # endif // GTEST_OS_LINUX
3996 EXPECT_EQ(static_cast<int>(kCaseA), static_cast<int>(kCaseB));
3998 # endif // GTEST_OS_LINUX
4007 "(kCaseA) >= (kCaseB)");
4018 # ifndef __BORLANDC__
4022 " kCaseB\n Which is: ");
4031 #endif // !GTEST_OS_MAC && !defined(__SUNPRO_CC)
4033 #if GTEST_OS_WINDOWS
4035 static HRESULT UnexpectedHRESULTFailure() {
4036 return E_UNEXPECTED;
4039 static HRESULT OkHRESULTSuccess() {
4043 static HRESULT FalseHRESULTSuccess() {
4051 TEST(HRESULTAssertionTest, EXPECT_HRESULT_SUCCEEDED) {
4052 EXPECT_HRESULT_SUCCEEDED(S_OK);
4053 EXPECT_HRESULT_SUCCEEDED(S_FALSE);
4056 "Expected: (UnexpectedHRESULTFailure()) succeeds.\n"
4057 " Actual: 0x8000FFFF");
4060 TEST(HRESULTAssertionTest, ASSERT_HRESULT_SUCCEEDED) {
4061 ASSERT_HRESULT_SUCCEEDED(S_OK);
4062 ASSERT_HRESULT_SUCCEEDED(S_FALSE);
4065 "Expected: (UnexpectedHRESULTFailure()) succeeds.\n"
4066 " Actual: 0x8000FFFF");
4069 TEST(HRESULTAssertionTest, EXPECT_HRESULT_FAILED) {
4070 EXPECT_HRESULT_FAILED(E_UNEXPECTED);
4073 "Expected: (OkHRESULTSuccess()) fails.\n"
4076 "Expected: (FalseHRESULTSuccess()) fails.\n"
4080 TEST(HRESULTAssertionTest, ASSERT_HRESULT_FAILED) {
4081 ASSERT_HRESULT_FAILED(E_UNEXPECTED);
4083 # ifndef __BORLANDC__
4087 "Expected: (OkHRESULTSuccess()) fails.\n"
4092 "Expected: (FalseHRESULTSuccess()) fails.\n"
4097 TEST(HRESULTAssertionTest, Streaming) {
4098 EXPECT_HRESULT_SUCCEEDED(S_OK) <<
"unexpected failure";
4099 ASSERT_HRESULT_SUCCEEDED(S_OK) <<
"unexpected failure";
4100 EXPECT_HRESULT_FAILED(E_UNEXPECTED) <<
"unexpected failure";
4101 ASSERT_HRESULT_FAILED(E_UNEXPECTED) <<
"unexpected failure";
4104 EXPECT_HRESULT_SUCCEEDED(E_UNEXPECTED) <<
"expected failure",
4105 "expected failure");
4107 # ifndef __BORLANDC__
4111 ASSERT_HRESULT_SUCCEEDED(E_UNEXPECTED) <<
"expected failure",
4112 "expected failure");
4116 EXPECT_HRESULT_FAILED(S_OK) <<
"expected failure",
4117 "expected failure");
4120 ASSERT_HRESULT_FAILED(S_OK) <<
"expected failure",
4121 "expected failure");
4124 #endif // GTEST_OS_WINDOWS
4128 # pragma option push -w-ccc -w-rch
4132 TEST(AssertionSyntaxTest, BasicAssertionsBehavesLikeSingleStatement) {
4134 ASSERT_TRUE(
false) <<
"This should never be executed; "
4135 "It's a compilation test only.";
4151 #if GTEST_HAS_EXCEPTIONS
4154 TEST(ExpectThrowTest, DoesNotGenerateUnreachableCodeWarning) {
4166 TEST(ExpectThrowTest, DoesNotGenerateDuplicateCatchClauseWarning) {
4170 TEST(AssertionSyntaxTest, ExceptionAssertionsBehavesLikeSingleStatement) {
4195 #endif // GTEST_HAS_EXCEPTIONS
4197 TEST(AssertionSyntaxTest, NoFatalFailureAssertionsBehavesLikeSingleStatement) {
4200 <<
"It's a compilation test only.";
4221 TEST(AssertionSyntaxTest, WorksWithSwitch) {
4231 EXPECT_FALSE(
false) <<
"EXPECT_FALSE failed in switch case";
4238 ASSERT_EQ(1, 1) <<
"ASSERT_EQ failed in default switch handler";
4246 #if GTEST_HAS_EXCEPTIONS
4248 void ThrowAString() {
4249 throw "std::string";
4254 TEST(AssertionSyntaxTest, WorksWithConst) {
4260 #endif // GTEST_HAS_EXCEPTIONS
4270 EXPECT_EQ(2, GetUnitTestImpl()->current_test_result()->total_part_count());
4274 TEST(SuccessfulAssertionTest, EXPECT) {
4276 EXPECT_EQ(0, GetUnitTestImpl()->current_test_result()->total_part_count());
4280 TEST(SuccessfulAssertionTest, EXPECT_STR) {
4282 EXPECT_EQ(0, GetUnitTestImpl()->current_test_result()->total_part_count());
4286 TEST(SuccessfulAssertionTest, ASSERT) {
4288 EXPECT_EQ(0, GetUnitTestImpl()->current_test_result()->total_part_count());
4292 TEST(SuccessfulAssertionTest, ASSERT_STR) {
4294 EXPECT_EQ(0, GetUnitTestImpl()->current_test_result()->total_part_count());
4303 TEST(AssertionWithMessageTest, EXPECT) {
4304 EXPECT_EQ(1, 1) <<
"This should succeed.";
4306 "Expected failure #1");
4307 EXPECT_LE(1, 2) <<
"This should succeed.";
4309 "Expected failure #2.");
4310 EXPECT_GE(1, 0) <<
"This should succeed.";
4312 "Expected failure #3.");
4316 "Expected failure #4.");
4319 "Expected failure #5.");
4323 "Expected failure #6.");
4324 EXPECT_NEAR(1, 1.1, 0.2) <<
"This should succeed.";
4327 TEST(AssertionWithMessageTest, ASSERT) {
4328 ASSERT_EQ(1, 1) <<
"This should succeed.";
4329 ASSERT_NE(1, 2) <<
"This should succeed.";
4330 ASSERT_LE(1, 2) <<
"This should succeed.";
4331 ASSERT_LT(1, 2) <<
"This should succeed.";
4332 ASSERT_GE(1, 0) <<
"This should succeed.";
4334 "Expected failure.");
4337 TEST(AssertionWithMessageTest, ASSERT_STR) {
4342 "Expected failure.");
4345 TEST(AssertionWithMessageTest, ASSERT_FLOATING) {
4356 ASSERT_FALSE(
true) <<
"Expected failure: " << 2 <<
" > " << 1
4357 <<
" evaluates to " <<
true;
4358 },
"Expected failure");
4362 TEST(AssertionWithMessageTest,
FAIL) {
4369 SUCCEED() <<
"Success == " << 1;
4378 ASSERT_TRUE(
false) <<
static_cast<const char*
>(
nullptr)
4379 << static_cast<char*>(
nullptr);
4384 #if GTEST_OS_WINDOWS
4386 TEST(AssertionWithMessageTest, WideStringMessage) {
4388 EXPECT_TRUE(
false) << L
"This failure is expected.\x8119";
4389 },
"This failure is expected.");
4392 << L
"expected too.\x8120";
4393 },
"This failure is expected too.");
4395 #endif // GTEST_OS_WINDOWS
4401 "Intentional failure #1.");
4403 "Intentional failure #2.");
4414 TEST(ExpectTest, ExpectTrueWithAssertionResult) {
4417 "Value of: ResultIsEven(3)\n"
4418 " Actual: false (3 is odd)\n"
4422 "Value of: ResultIsEvenNoExplanation(3)\n"
4423 " Actual: false (3 is odd)\n"
4432 "Intentional failure #1.");
4434 "Intentional failure #2.");
4444 TEST(ExpectTest, ExpectFalseWithAssertionResult) {
4447 "Value of: ResultIsEven(2)\n"
4448 " Actual: true (2 is even)\n"
4452 "Value of: ResultIsEvenNoExplanation(2)\n"
4466 "Expected equality of these values:\n"
4477 TEST(ExpectTest, EXPECT_EQ_Double) {
4487 TEST(ExpectTest, EXPECT_EQ_NULL) {
4489 const char* p =
nullptr;
4501 TEST(ExpectTest, EXPECT_EQ_0) {
4517 "Expected: ('a') != ('a'), "
4518 "actual: 'a' (97, 0x61) vs 'a' (97, 0x61)");
4521 char*
const p0 =
nullptr;
4528 void* pv1 = (
void*)0x1234;
4529 char*
const p1 =
reinterpret_cast<char*
>(pv1);
4539 "Expected: (2) <= (0), actual: 2 vs 0");
4548 "Expected: (2) < (2), actual: 2 vs 2");
4558 "Expected: (2) >= (3), actual: 2 vs 3");
4567 "Expected: (2) > (2), actual: 2 vs 2");
4572 #if GTEST_HAS_EXCEPTIONS
4578 "Expected: ThrowAnInteger() throws an exception of "
4579 "type bool.\n Actual: it throws a different type.");
4582 "Expected: ThrowRuntimeError(\"A description\") "
4583 "throws an exception of type std::logic_error.\n "
4584 "Actual: it throws " ERROR_DESC
" "
4585 "with description \"A description\".");
4588 "Expected: ThrowNothing() throws an exception of type bool.\n"
4589 " Actual: it throws nothing.");
4596 "Expected: ThrowAnInteger() doesn't throw an "
4597 "exception.\n Actual: it throws.");
4599 "Expected: ThrowRuntimeError(\"A description\") "
4600 "doesn't throw an exception.\n "
4601 "Actual: it throws " ERROR_DESC
" "
4602 "with description \"A description\".");
4610 "Expected: ThrowNothing() throws an exception.\n"
4611 " Actual: it doesn't.");
4614 #endif // GTEST_HAS_EXCEPTIONS
4617 TEST(ExpectTest, ExpectPrecedence) {
4620 " true && false\n Which is: false");
4627 TEST(StreamableToStringTest, Scalar) {
4632 TEST(StreamableToStringTest, Pointer) {
4639 TEST(StreamableToStringTest, NullPointer) {
4645 TEST(StreamableToStringTest, CString) {
4650 TEST(StreamableToStringTest, NullCString) {
4658 TEST(StreamableTest,
string) {
4659 static const std::string str(
4660 "This failure message is a std::string, and is expected.");
4667 TEST(StreamableTest, stringWithEmbeddedNUL) {
4668 static const char char_array_with_nul[] =
4669 "Here's a NUL\0 and some more string";
4670 static const std::string string_with_nul(char_array_with_nul,
4671 sizeof(char_array_with_nul)
4674 "Here's a NUL\\0 and some more string");
4678 TEST(StreamableTest, NULChar) {
4680 FAIL() <<
"A NUL" <<
'\0' <<
" and some more string";
4681 },
"A NUL\\0 and some more string");
4685 TEST(StreamableTest,
int) {
4695 TEST(StreamableTest, NullCharPtr) {
4701 TEST(StreamableTest, BasicIoManip) {
4703 FAIL() <<
"Line 1." << std::endl
4704 <<
"A NUL char " << std::ends << std::flush <<
" in line 2.";
4705 },
"Line 1.\nA NUL char \\0 in line 2.");
4710 void AddFailureHelper(
bool* aborted) {
4718 bool aborted =
true;
4720 "Intentional failure.");
4744 "Intentional failure.");
4763 SUCCEED() <<
"Explicit success.";
4777 bool false_value =
false;
4779 },
" false_value\n Which is: false\n true");
4783 TEST(EqAssertionTest, Int) {
4790 TEST(EqAssertionTest, Time_T) {
4792 static_cast<time_t>(0));
4794 static_cast<time_t>(1234)),
4801 const char ch =
'b';
4803 " ch\n Which is: 'b'");
4805 " ch\n Which is: 'b'");
4809 TEST(EqAssertionTest, WideChar) {
4813 "Expected equality of these values:\n"
4815 " Which is: L'\0' (0, 0x0)\n"
4817 " Which is: L'x' (120, 0x78)");
4819 static wchar_t wchar;
4825 " wchar\n Which is: L'");
4829 TEST(EqAssertionTest, StdString) {
4832 ASSERT_EQ(
"Test", ::std::string(
"Test"));
4835 static const ::std::string str1(
"A * in the middle");
4836 static const ::std::string str2(str1);
4845 char*
const p1 =
const_cast<char*
>(
"foo");
4851 static ::std::string str3(str1);
4854 " str3\n Which is: \"A \\0 in the middle\"");
4857 #if GTEST_HAS_STD_WSTRING
4860 TEST(EqAssertionTest, StdWideString) {
4862 const ::std::wstring wstr1(L
"A * in the middle");
4863 const ::std::wstring wstr2(wstr1);
4868 const wchar_t kTestX8119[] = {
'T',
'e',
's',
't', 0x8119,
'\0' };
4869 EXPECT_EQ(::std::wstring(kTestX8119), kTestX8119);
4873 const wchar_t kTestX8120[] = {
'T',
'e',
's',
't', 0x8120,
'\0' };
4875 EXPECT_EQ(::std::wstring(kTestX8119), kTestX8120);
4880 ::std::wstring wstr3(wstr1);
4881 wstr3.at(2) = L
'\0';
4888 ASSERT_EQ(const_cast<wchar_t*>(L
"foo"), ::std::wstring(L
"bar"));
4892 #endif // GTEST_HAS_STD_WSTRING
4895 TEST(EqAssertionTest, CharPointer) {
4896 char*
const p0 =
nullptr;
4901 void* pv1 = (
void*)0x1234;
4902 void* pv2 = (
void*)0xABC0;
4903 char*
const p1 =
reinterpret_cast<char*
>(pv1);
4904 char*
const p2 =
reinterpret_cast<char*
>(pv2);
4912 reinterpret_cast<char*>(0xABC0)),
4917 TEST(EqAssertionTest, WideCharPointer) {
4918 wchar_t*
const p0 =
nullptr;
4923 void* pv1 = (
void*)0x1234;
4924 void* pv2 = (
void*)0xABC0;
4925 wchar_t*
const p1 =
reinterpret_cast<wchar_t*
>(pv1);
4926 wchar_t*
const p2 =
reinterpret_cast<wchar_t*
>(pv2);
4933 void* pv3 = (
void*)0x1234;
4934 void* pv4 = (
void*)0xABC0;
4935 const wchar_t* p3 =
reinterpret_cast<const wchar_t*
>(pv3);
4936 const wchar_t* p4 =
reinterpret_cast<const wchar_t*
>(pv4);
4942 TEST(EqAssertionTest, OtherPointer) {
4943 ASSERT_EQ(static_cast<const int*>(
nullptr), static_cast<const int*>(
nullptr));
4945 reinterpret_cast<const int*>(0x1234)),
4950 class UnprintableChar {
4952 explicit UnprintableChar(
char ch) : char_(ch) {}
4954 bool operator==(
const UnprintableChar& rhs)
const {
4955 return char_ == rhs.char_;
4957 bool operator!=(
const UnprintableChar& rhs)
const {
4958 return char_ != rhs.char_;
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 {
4967 return char_ > rhs.char_;
4969 bool operator>=(
const UnprintableChar& rhs)
const {
4970 return char_ >= rhs.char_;
4979 TEST(ComparisonAssertionTest, AcceptsUnprintableArgs) {
4980 const UnprintableChar
x(
'x'),
y(
'y');
4996 #ifndef __BORLANDC__
4999 "1-byte object <78>");
5001 "1-byte object <78>");
5004 "1-byte object <79>");
5006 "1-byte object <78>");
5008 "1-byte object <79>");
5020 int Bar()
const {
return 1; }
5035 class FRIEND_TEST_Test2 :
public Test {
5052 class TestLifeCycleTest :
public Test {
5056 TestLifeCycleTest() { count_++; }
5060 ~TestLifeCycleTest()
override { count_--; }
5063 int count()
const {
return count_; }
5069 int TestLifeCycleTest::count_ = 0;
5072 TEST_F(TestLifeCycleTest, Test1) {
5079 TEST_F(TestLifeCycleTest, Test2) {
5090 TEST(AssertionResultTest, CopyConstructorWorksWhenNotOptimied) {
5094 AssertionResult r2 = r1;
5099 AssertionResult r3 = r1;
5100 EXPECT_EQ(static_cast<bool>(r3), static_cast<bool>(r1));
5106 TEST(AssertionResultTest, ConstructionWorks) {
5129 TEST(AssertionResultTest, NegationWorks) {
5139 TEST(AssertionResultTest, StreamingWorks) {
5141 r <<
"abc" <<
'd' << 0 <<
true;
5145 TEST(AssertionResultTest, CanStreamOstreamManipulators) {
5147 r <<
"Data" << std::endl << std::flush << std::ends <<
"Will be visible";
5153 TEST(AssertionResultTest, ConstructibleFromContextuallyConvertibleToBool) {
5154 struct ExplicitlyConvertibleToBool {
5155 explicit operator bool()
const {
return value; }
5158 ExplicitlyConvertibleToBool v1 = {
false};
5159 ExplicitlyConvertibleToBool v2 = {
true};
5165 operator AssertionResult()
const {
return AssertionResult(
true); }
5168 TEST(AssertionResultTest, ConstructibleFromImplicitlyConvertible) {
5184 return os << val.x();
5187 const Base* pointer) {
5188 return os <<
"(" << pointer->x() <<
")";
5191 TEST(MessageTest, CanStreamUserTypeInGlobalNameSpace) {
5202 class MyTypeInUnnamedNameSpace :
public Base {
5204 explicit MyTypeInUnnamedNameSpace(
int an_x): Base(an_x) {}
5207 const MyTypeInUnnamedNameSpace&
val) {
5208 return os << val.x();
5211 const MyTypeInUnnamedNameSpace* pointer) {
5212 return os <<
"(" << pointer->x() <<
")";
5216 TEST(MessageTest, CanStreamUserTypeInUnnamedNameSpace) {
5218 MyTypeInUnnamedNameSpace
a(1);
5226 namespace namespace1 {
5233 return os << val.x();
5237 return os <<
"(" << pointer->x() <<
")";
5241 TEST(MessageTest, CanStreamUserTypeInUserNameSpace) {
5251 namespace namespace2 {
5259 return os << val.x();
5263 return os <<
"(" << pointer->x() <<
")";
5266 TEST(MessageTest, CanStreamUserTypeInUserNameSpaceWithStreamOperatorInGlobal) {
5277 char*
const p1 =
nullptr;
5278 unsigned char*
const p2 =
nullptr;
5280 double* p4 =
nullptr;
5284 msg << p1 << p2 << p3 << p4 << p5 << p6;
5292 const wchar_t* const_wstr =
nullptr;
5294 (
Message() << const_wstr).GetString().c_str());
5297 wchar_t* wstr =
nullptr;
5299 (
Message() << wstr).GetString().c_str());
5302 const_wstr = L
"abc\x8119";
5304 (
Message() << const_wstr).GetString().c_str());
5307 wstr =
const_cast<wchar_t*
>(const_wstr);
5309 (
Message() << wstr).GetString().c_str());
5322 GetUnitTestImpl()->GetTestSuite(
"TestInfoTest",
"",
nullptr,
nullptr);
5326 if (strcmp(test_name, test_info->
name()) == 0)
5334 return test_info->
result();
5340 const TestInfo*
const test_info = GetTestInfo(
"Names");
5348 const TestInfo*
const test_info = GetTestInfo(
"result");
5351 ASSERT_EQ(0, GetTestResult(test_info)->total_part_count());
5354 ASSERT_EQ(0, GetTestResult(test_info)->total_part_count());
5357 #define VERIFY_CODE_LOCATION \
5358 const int expected_line = __LINE__ - 1; \
5359 const TestInfo* const test_info = GetUnitTestImpl()->current_test_info(); \
5360 ASSERT_TRUE(test_info); \
5361 EXPECT_STREQ(__FILE__, test_info->file()); \
5362 EXPECT_EQ(expected_line, test_info->line())
5364 TEST(CodeLocationForTEST, Verify) {
5384 template <
typename T>
5394 template <
typename T>
5408 #undef VERIFY_CODE_LOCATION
5412 #ifndef REMOVE_LEGACY_TEST_CASEAPI
5418 printf(
"Setting up the test case . . .\n");
5435 printf(
"Tearing down the test case . . .\n");
5471 #endif // REMOVE_LEGACY_TEST_CASEAPI
5479 printf(
"Setting up the test suite . . .\n");
5496 printf(
"Tearing down the test suite . . .\n");
5725 GTEST_FLAG(stack_trace_depth) = kMaxStackTraceDepth;
5731 template <
typename CharType>
5733 CharType** array2) {
5734 ASSERT_EQ(size1, size2) <<
" Array sizes different.";
5736 for (
int i = 0;
i != size1;
i++) {
5766 template <
typename CharType>
5768 int argc2,
const CharType** argv2,
5769 const Flags& expected,
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) {
5802 expected_help_fragment, captured_stdout);
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, \
5815 expected, should_print_help)
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",
"--gtest_filter",
nullptr};
5856 const char* argv[] = {
"foo.exe",
"--gtest_filter=",
nullptr};
5858 const char* argv2[] = {
"foo.exe",
nullptr};
5865 const char* argv[] = {
"foo.exe",
"--gtest_filter=abc",
nullptr};
5867 const char* argv2[] = {
"foo.exe",
nullptr};
5874 const char* argv[] = {
"foo.exe",
"--gtest_break_on_failure",
nullptr};
5876 const char* argv2[] = {
"foo.exe",
nullptr};
5883 const char* argv[] = {
"foo.exe",
"--gtest_break_on_failure=0",
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};
5901 const char* argv[] = {
"foo.exe",
"--gtest_break_on_failure=F",
nullptr};
5903 const char* argv2[] = {
"foo.exe",
nullptr};
5911 const char* argv[] = {
"foo.exe",
"--gtest_break_on_failure=1",
nullptr};
5913 const char* argv2[] = {
"foo.exe",
nullptr};
5920 const char* argv[] = {
"foo.exe",
"--gtest_catch_exceptions",
nullptr};
5922 const char* argv2[] = {
"foo.exe",
nullptr};
5929 const char* argv[] = {
"foo.exe",
"--gtest_death_test_use_fork",
nullptr};
5931 const char* argv2[] = {
"foo.exe",
nullptr};
5939 const char* argv[] = {
"foo.exe",
"--gtest_filter=a",
"--gtest_filter=b",
5942 const char* argv2[] = {
"foo.exe",
nullptr};
5949 const char* argv[] = {
"foo.exe",
"--gtest_break_on_failure",
5951 "--gtest_filter=b",
nullptr};
5953 const char* argv2[] = {
"foo.exe",
"bar",
nullptr};
5963 const char* argv[] = {
"foo.exe",
"--gtest_list_tests",
nullptr};
5965 const char* argv2[] = {
"foo.exe",
nullptr};
5972 const char* argv[] = {
"foo.exe",
"--gtest_list_tests=1",
nullptr};
5974 const char* argv2[] = {
"foo.exe",
nullptr};
5981 const char* argv[] = {
"foo.exe",
"--gtest_list_tests=0",
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_list_tests=F",
nullptr};
6001 const char* argv2[] = {
"foo.exe",
nullptr};
6008 const char* argv[] = {
"foo.exe",
"--gtest_output",
nullptr};
6010 const char* argv2[] = {
"foo.exe",
"--gtest_output",
nullptr};
6017 const char* argv[] = {
"foo.exe",
"--gtest_output=xml",
nullptr};
6019 const char* argv2[] = {
"foo.exe",
nullptr};
6026 const char* argv[] = {
"foo.exe",
"--gtest_output=xml:file",
nullptr};
6028 const char* argv2[] = {
"foo.exe",
nullptr};
6035 const char* argv[] = {
"foo.exe",
"--gtest_output=xml:directory/path/",
6038 const char* argv2[] = {
"foo.exe",
nullptr};
6046 const char* argv[] = {
"foo.exe",
"--gtest_brief",
nullptr};
6048 const char* argv2[] = {
"foo.exe",
nullptr};
6055 const char* argv[] = {
"foo.exe",
"--gtest_brief=1",
nullptr};
6057 const char* argv2[] = {
"foo.exe",
nullptr};
6064 const char* argv[] = {
"foo.exe",
"--gtest_brief=0",
nullptr};
6066 const char* argv2[] = {
"foo.exe",
nullptr};
6073 const char* argv[] = {
"foo.exe",
"--gtest_print_time",
nullptr};
6075 const char* argv2[] = {
"foo.exe",
nullptr};
6082 const char* argv[] = {
"foo.exe",
"--gtest_print_time=1",
nullptr};
6084 const char* argv2[] = {
"foo.exe",
nullptr};
6091 const char* argv[] = {
"foo.exe",
"--gtest_print_time=0",
nullptr};
6093 const char* argv2[] = {
"foo.exe",
nullptr};
6100 const char* argv[] = {
"foo.exe",
"--gtest_print_time=f",
nullptr};
6102 const char* argv2[] = {
"foo.exe",
nullptr};
6109 const char* argv[] = {
"foo.exe",
"--gtest_print_time=F",
nullptr};
6111 const char* argv2[] = {
"foo.exe",
nullptr};
6118 const char* argv[] = {
"foo.exe",
"--gtest_random_seed=1000",
nullptr};
6120 const char* argv2[] = {
"foo.exe",
nullptr};
6127 const char* argv[] = {
"foo.exe",
"--gtest_repeat=1000",
nullptr};
6129 const char* argv2[] = {
"foo.exe",
nullptr};
6136 const char* argv[] = {
"foo.exe",
"--gtest_also_run_disabled_tests",
nullptr};
6138 const char* argv2[] = {
"foo.exe",
nullptr};
6146 const char* argv[] = {
"foo.exe",
"--gtest_also_run_disabled_tests=1",
6149 const char* argv2[] = {
"foo.exe",
nullptr};
6157 const char* argv[] = {
"foo.exe",
"--gtest_also_run_disabled_tests=0",
6160 const char* argv2[] = {
"foo.exe",
nullptr};
6168 const char* argv[] = {
"foo.exe",
"--gtest_shuffle",
nullptr};
6170 const char* argv2[] = {
"foo.exe",
nullptr};
6177 const char* argv[] = {
"foo.exe",
"--gtest_shuffle=0",
nullptr};
6179 const char* argv2[] = {
"foo.exe",
nullptr};
6186 const char* argv[] = {
"foo.exe",
"--gtest_shuffle=1",
nullptr};
6188 const char* argv2[] = {
"foo.exe",
nullptr};
6195 const char* argv[] = {
"foo.exe",
"--gtest_stack_trace_depth=5",
nullptr};
6197 const char* argv2[] = {
"foo.exe",
nullptr};
6203 const char* argv[] = {
"foo.exe",
"--gtest_stream_result_to=localhost:1234",
6206 const char* argv2[] = {
"foo.exe",
nullptr};
6214 const char* argv[] = {
"foo.exe",
"--gtest_throw_on_failure",
nullptr};
6216 const char* argv2[] = {
"foo.exe",
nullptr};
6223 const char* argv[] = {
"foo.exe",
"--gtest_throw_on_failure=0",
nullptr};
6225 const char* argv2[] = {
"foo.exe",
nullptr};
6233 const char* argv[] = {
"foo.exe",
"--gtest_throw_on_failure=1",
nullptr};
6235 const char* argv2[] = {
"foo.exe",
nullptr};
6240 # if GTEST_OS_WINDOWS
6242 TEST_F(ParseFlagsTest, WideStrings) {
6243 const wchar_t* argv[] = {
6245 L
"--gtest_filter=Foo*",
6246 L
"--gtest_list_tests=1",
6247 L
"--gtest_break_on_failure",
6248 L
"--non_gtest_flag",
6252 const wchar_t* argv2[] = {
6254 L
"--non_gtest_flag",
6258 Flags expected_flags;
6259 expected_flags.break_on_failure =
true;
6260 expected_flags.filter =
"Foo*";
6261 expected_flags.list_tests =
true;
6265 # endif // GTEST_OS_WINDOWS
6267 #if GTEST_USE_OWN_FLAGFILE_FLAG_
6268 class FlagfileTest :
public ParseFlagsTest {
6270 void SetUp()
override {
6280 void TearDown()
override {
6285 internal::FilePath CreateFlagfile(
const char* contents) {
6286 internal::FilePath file_path(internal::FilePath::GenerateUniqueFileName(
6289 fprintf(f,
"%s", contents);
6299 TEST_F(FlagfileTest, Empty) {
6300 internal::FilePath flagfile_path(CreateFlagfile(
""));
6301 std::string flagfile_flag =
6304 const char* argv[] = {
"foo.exe", flagfile_flag.c_str(),
nullptr};
6306 const char* argv2[] = {
"foo.exe",
nullptr};
6312 TEST_F(FlagfileTest, FilterNonEmpty) {
6313 internal::FilePath flagfile_path(CreateFlagfile(
6315 std::string flagfile_flag =
6318 const char* argv[] = {
"foo.exe", flagfile_flag.c_str(),
nullptr};
6320 const char* argv2[] = {
"foo.exe",
nullptr};
6326 TEST_F(FlagfileTest, SeveralFlags) {
6327 internal::FilePath flagfile_path(CreateFlagfile(
6331 std::string flagfile_flag =
6334 const char* argv[] = {
"foo.exe", flagfile_flag.c_str(),
nullptr};
6336 const char* argv2[] = {
"foo.exe",
nullptr};
6338 Flags expected_flags;
6339 expected_flags.break_on_failure =
true;
6340 expected_flags.filter =
"abc";
6341 expected_flags.list_tests =
true;
6345 #endif // GTEST_USE_OWN_FLAGFILE_FLAG_
6357 <<
"There should be no tests running at this point.";
6366 <<
"There should be no tests running at this point.";
6376 <<
"There is a test running so we should have a valid TestInfo.";
6378 <<
"Expected the name of the currently running test case.";
6380 <<
"Expected the name of the currently running test.";
6391 <<
"There is a test running so we should have a valid TestInfo.";
6393 <<
"Expected the name of the currently running test case.";
6395 <<
"Expected the name of the currently running test.";
6403 namespace my_namespace {
6420 TEST(NestedTestingNamespaceTest, Success) {
6421 EXPECT_EQ(1, 1) <<
"This shouldn't fail.";
6425 TEST(NestedTestingNamespaceTest, Failure) {
6427 "This failure is expected.");
6439 void SetUp()
override { Test::SetUp(); }
6445 TEST(StreamingAssertionsTest, Unconditional) {
6446 SUCCEED() <<
"expected success";
6448 "expected failure");
6450 "expected failure");
6455 # pragma option push -w-ccc -w-rch
6458 TEST(StreamingAssertionsTest, Truth) {
6462 "expected failure");
6464 "expected failure");
6467 TEST(StreamingAssertionsTest, Truth2) {
6471 "expected failure");
6473 "expected failure");
6481 TEST(StreamingAssertionsTest, IntegerEquals) {
6482 EXPECT_EQ(1, 1) <<
"unexpected failure";
6483 ASSERT_EQ(1, 1) <<
"unexpected failure";
6485 "expected failure");
6487 "expected failure");
6490 TEST(StreamingAssertionsTest, IntegerLessThan) {
6491 EXPECT_LT(1, 2) <<
"unexpected failure";
6492 ASSERT_LT(1, 2) <<
"unexpected failure";
6494 "expected failure");
6496 "expected failure");
6499 TEST(StreamingAssertionsTest, StringsEqual) {
6503 "expected failure");
6505 "expected failure");
6508 TEST(StreamingAssertionsTest, StringsNotEqual) {
6512 "expected failure");
6514 "expected failure");
6517 TEST(StreamingAssertionsTest, StringsEqualIgnoringCase) {
6521 "expected failure");
6523 "expected failure");
6526 TEST(StreamingAssertionsTest, StringNotEqualIgnoringCase) {
6530 "expected failure");
6532 "expected failure");
6535 TEST(StreamingAssertionsTest, FloatingPointEquals) {
6539 "expected failure");
6541 "expected failure");
6544 #if GTEST_HAS_EXCEPTIONS
6546 TEST(StreamingAssertionsTest, Throw) {
6547 EXPECT_THROW(ThrowAnInteger(),
int) <<
"unexpected failure";
6548 ASSERT_THROW(ThrowAnInteger(),
int) <<
"unexpected failure";
6550 "expected failure",
"expected failure");
6552 "expected failure",
"expected failure");
6555 TEST(StreamingAssertionsTest, NoThrow) {
6559 "expected failure",
"expected failure");
6561 "expected failure",
"expected failure");
6564 TEST(StreamingAssertionsTest, AnyThrow) {
6568 "expected failure",
"expected failure");
6570 "expected failure",
"expected failure");
6573 #endif // GTEST_HAS_EXCEPTIONS
6577 TEST(ColoredOutputTest, UsesColorsWhenGTestColorFlagIsYes) {
6580 SetEnv(
"TERM",
"xterm");
6584 SetEnv(
"TERM",
"dumb");
6589 TEST(ColoredOutputTest, UsesColorsWhenGTestColorFlagIsAliasOfYes) {
6590 SetEnv(
"TERM",
"dumb");
6602 TEST(ColoredOutputTest, UsesNoColorWhenGTestColorFlagIsNo) {
6605 SetEnv(
"TERM",
"xterm");
6609 SetEnv(
"TERM",
"dumb");
6614 TEST(ColoredOutputTest, UsesNoColorWhenGTestColorFlagIsInvalid) {
6615 SetEnv(
"TERM",
"xterm");
6627 TEST(ColoredOutputTest, UsesColorsWhenStdoutIsTty) {
6630 SetEnv(
"TERM",
"xterm");
6635 TEST(ColoredOutputTest, UsesColorsWhenTermSupportsColors) {
6638 #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW
6641 SetEnv(
"TERM",
"dumb");
6647 SetEnv(
"TERM",
"xterm");
6653 SetEnv(
"TERM",
"dumb");
6656 SetEnv(
"TERM",
"emacs");
6659 SetEnv(
"TERM",
"vt100");
6662 SetEnv(
"TERM",
"xterm-mono");
6665 SetEnv(
"TERM",
"xterm");
6668 SetEnv(
"TERM",
"xterm-color");
6671 SetEnv(
"TERM",
"xterm-256color");
6674 SetEnv(
"TERM",
"screen");
6677 SetEnv(
"TERM",
"screen-256color");
6680 SetEnv(
"TERM",
"tmux");
6683 SetEnv(
"TERM",
"tmux-256color");
6686 SetEnv(
"TERM",
"rxvt-unicode");
6689 SetEnv(
"TERM",
"rxvt-unicode-256color");
6692 SetEnv(
"TERM",
"linux");
6695 SetEnv(
"TERM",
"cygwin");
6697 #endif // GTEST_OS_WINDOWS
6703 static bool dummy2 GTEST_ATTRIBUTE_UNUSED_ =
6704 StaticAssertTypeEq<const int, const int>();
6708 template <
typename T>
6714 TEST(StaticAssertTypeEqTest, WorksInClass) {
6722 TEST(StaticAssertTypeEqTest, CompilesForEqualTypes) {
6723 StaticAssertTypeEq<int, IntAlias>();
6724 StaticAssertTypeEq<int*, IntAlias*>();
6727 TEST(HasNonfatalFailureTest, ReturnsFalseWhenThereIsNoFailure) {
6733 TEST(HasNonfatalFailureTest, ReturnsFalseWhenThereIsOnlyFatalFailure) {
6735 const bool has_nonfatal_failure = HasNonfatalFailure();
6736 ClearCurrentTestPartResults();
6740 TEST(HasNonfatalFailureTest, ReturnsTrueWhenThereIsNonfatalFailure) {
6742 const bool has_nonfatal_failure = HasNonfatalFailure();
6743 ClearCurrentTestPartResults();
6747 TEST(HasNonfatalFailureTest, ReturnsTrueWhenThereAreFatalAndNonfatalFailures) {
6750 const bool has_nonfatal_failure = HasNonfatalFailure();
6751 ClearCurrentTestPartResults();
6760 TEST(HasNonfatalFailureTest, WorksOutsideOfTestBody) {
6764 TEST(HasNonfatalFailureTest, WorksOutsideOfTestBody2) {
6767 ClearCurrentTestPartResults();
6771 TEST(HasFailureTest, ReturnsFalseWhenThereIsNoFailure) {
6775 TEST(HasFailureTest, ReturnsTrueWhenThereIsFatalFailure) {
6777 const bool has_failure = HasFailure();
6778 ClearCurrentTestPartResults();
6782 TEST(HasFailureTest, ReturnsTrueWhenThereIsNonfatalFailure) {
6784 const bool has_failure = HasFailure();
6785 ClearCurrentTestPartResults();
6789 TEST(HasFailureTest, ReturnsTrueWhenThereAreFatalAndNonfatalFailures) {
6792 const bool has_failure = HasFailure();
6793 ClearCurrentTestPartResults();
6800 TEST(HasFailureTest, WorksOutsideOfTestBody) {
6804 TEST(HasFailureTest, WorksOutsideOfTestBody2) {
6807 ClearCurrentTestPartResults();
6834 TEST(TestEventListenersTest, ConstructionWorks) {
6837 EXPECT_TRUE(TestEventListenersAccessor::GetRepeater(&listeners) !=
nullptr);
6844 TEST(TestEventListenersTest, DestructionWorks) {
6845 bool default_result_printer_is_destroyed =
false;
6846 bool default_xml_printer_is_destroyed =
false;
6847 bool extra_listener_is_destroyed =
false;
6849 new TestListener(
nullptr, &default_result_printer_is_destroyed);
6851 new TestListener(
nullptr, &default_xml_printer_is_destroyed);
6853 new TestListener(
nullptr, &extra_listener_is_destroyed);
6857 TestEventListenersAccessor::SetDefaultResultPrinter(&listeners,
6858 default_result_printer);
6859 TestEventListenersAccessor::SetDefaultXmlGenerator(&listeners,
6860 default_xml_printer);
6861 listeners.
Append(extra_listener);
6870 TEST(TestEventListenersTest, Append) {
6871 int on_start_counter = 0;
6872 bool is_destroyed =
false;
6876 listeners.
Append(listener);
6877 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
6878 *UnitTest::GetInstance());
6914 message <<
id_ <<
"." << method;
6924 TEST(EventListenerTest, AppendKeepsOrder) {
6925 std::vector<std::string> vec;
6931 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
6932 *UnitTest::GetInstance());
6934 EXPECT_STREQ(
"1st.OnTestProgramStart", vec[0].c_str());
6935 EXPECT_STREQ(
"2nd.OnTestProgramStart", vec[1].c_str());
6936 EXPECT_STREQ(
"3rd.OnTestProgramStart", vec[2].c_str());
6939 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramEnd(
6940 *UnitTest::GetInstance());
6947 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestIterationStart(
6948 *UnitTest::GetInstance(), 0);
6950 EXPECT_STREQ(
"1st.OnTestIterationStart", vec[0].c_str());
6951 EXPECT_STREQ(
"2nd.OnTestIterationStart", vec[1].c_str());
6952 EXPECT_STREQ(
"3rd.OnTestIterationStart", vec[2].c_str());
6955 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestIterationEnd(
6956 *UnitTest::GetInstance(), 0);
6958 EXPECT_STREQ(
"3rd.OnTestIterationEnd", vec[0].c_str());
6959 EXPECT_STREQ(
"2nd.OnTestIterationEnd", vec[1].c_str());
6960 EXPECT_STREQ(
"1st.OnTestIterationEnd", vec[2].c_str());
6965 TEST(TestEventListenersTest, Release) {
6966 int on_start_counter = 0;
6967 bool is_destroyed =
false;
6974 listeners.
Append(listener);
6976 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
6977 *UnitTest::GetInstance());
6986 TEST(EventListenerTest, SuppressEventForwarding) {
6987 int on_start_counter = 0;
6991 listeners.
Append(listener);
6992 ASSERT_TRUE(TestEventListenersAccessor::EventForwardingEnabled(listeners));
6993 TestEventListenersAccessor::SuppressEventForwarding(&listeners);
6994 ASSERT_FALSE(TestEventListenersAccessor::EventForwardingEnabled(listeners));
6995 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
6996 *UnitTest::GetInstance());
7002 TEST(EventListenerDeathTest, EventsNotForwardedInDeathTestSubprecesses) {
7004 GTEST_CHECK_(TestEventListenersAccessor::EventForwardingEnabled(
7005 *GetUnitTestImpl()->listeners())) <<
"expected failure";},
7006 "expected failure");
7012 TEST(EventListenerTest, default_result_printer) {
7013 int on_start_counter = 0;
7014 bool is_destroyed =
false;
7018 TestEventListenersAccessor::SetDefaultResultPrinter(&listeners, listener);
7022 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
7023 *UnitTest::GetInstance());
7029 TestEventListenersAccessor::SetDefaultResultPrinter(&listeners,
nullptr);
7036 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
7037 *UnitTest::GetInstance());
7043 TEST(EventListenerTest, RemovingDefaultResultPrinterWorks) {
7044 int on_start_counter = 0;
7045 bool is_destroyed =
false;
7052 TestEventListenersAccessor::SetDefaultResultPrinter(&listeners, listener);
7059 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
7060 *UnitTest::GetInstance());
7071 TEST(EventListenerTest, default_xml_generator) {
7072 int on_start_counter = 0;
7073 bool is_destroyed =
false;
7077 TestEventListenersAccessor::SetDefaultXmlGenerator(&listeners, listener);
7081 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
7082 *UnitTest::GetInstance());
7088 TestEventListenersAccessor::SetDefaultXmlGenerator(&listeners,
nullptr);
7095 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
7096 *UnitTest::GetInstance());
7102 TEST(EventListenerTest, RemovingDefaultXmlGeneratorWorks) {
7103 int on_start_counter = 0;
7104 bool is_destroyed =
false;
7111 TestEventListenersAccessor::SetDefaultXmlGenerator(&listeners, listener);
7118 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
7119 *UnitTest::GetInstance());
7137 "An expected failure");
7143 "An expected failure");
7145 "An expected failure");
7150 "An expected failure");
7155 "An expected failure");
7159 "An expected failure");
7161 "An expected failure");
7166 "An expected failure");
7170 "An expected failure");
7172 "An expected failure");
7182 TEST(IsAProtocolMessageTest, ValueIsCompileTimeConstant) {
7190 TEST(IsAProtocolMessageTest, ValueIsTrueWhenTypeIsAProtocolMessage) {
7196 TEST(IsAProtocolMessageTest, ValueIsFalseWhenTypeIsNotAProtocolMessage) {
7203 template <
typename T1,
typename T2>
7206 "GTEST_REMOVE_REFERENCE_AND_CONST_ failed.");
7209 TEST(RemoveReferenceToConstTest, Works) {
7210 TestGTestRemoveReferenceAndConst<int, int>();
7211 TestGTestRemoveReferenceAndConst<double, double&>();
7212 TestGTestRemoveReferenceAndConst<char, const char>();
7213 TestGTestRemoveReferenceAndConst<char, const char&>();
7214 TestGTestRemoveReferenceAndConst<const char*, const char*>();
7219 template <
typename T1,
typename T2>
7222 "GTEST_REFERENCE_TO_CONST_ failed.");
7225 TEST(GTestReferenceToConstTest, Works) {
7226 TestGTestReferenceToConst<const char&, char>();
7227 TestGTestReferenceToConst<const int&, const int>();
7228 TestGTestReferenceToConst<const double&, double>();
7229 TestGTestReferenceToConst<const std::string&, const std::string&>();
7237 TEST(IsContainerTestTest, WorksForNonContainer) {
7243 TEST(IsContainerTestTest, WorksForContainer) {
7265 TEST(IsContainerTestTest, ConstOnlyContainer) {
7267 sizeof(IsContainerTest<ConstOnlyContainerWithPointerIterator>(0)));
7269 sizeof(IsContainerTest<ConstOnlyContainerWithClassIterator>(0)));
7289 TEST(ArrayEqTest, WorksForDegeneratedArrays) {
7294 TEST(ArrayEqTest, WorksForOneDimensionalArrays) {
7296 const int a[] = { 0, 1 };
7297 long b[] = { 0, 1 };
7306 TEST(ArrayEqTest, WorksForTwoDimensionalArrays) {
7307 const char a[][3] = {
"hi",
"lo" };
7308 const char b[][3] = {
"hi",
"lo" };
7309 const char c[][3] = {
"hi",
"li" };
7320 TEST(ArrayAwareFindTest, WorksForOneDimensionalArray) {
7321 const char a[] =
"hello";
7326 TEST(ArrayAwareFindTest, WorksForTwoDimensionalArray) {
7327 int a[][2] = { { 0, 1 }, { 2, 3 }, { 4, 5 } };
7328 const int b[2] = { 2, 3 };
7331 const int c[2] = { 6, 7 };
7337 TEST(CopyArrayTest, WorksForDegeneratedArrays) {
7343 TEST(CopyArrayTest, WorksForOneDimensionalArrays) {
7344 const char a[3] =
"hi";
7346 #ifndef __BORLANDC__ // C++Builder cannot compile some array size deductions.
7356 TEST(CopyArrayTest, WorksForTwoDimensionalArrays) {
7357 const int a[2][3] = { { 0, 1, 2 }, { 3, 4, 5 } };
7359 #ifndef __BORLANDC__ // C++Builder cannot compile some array size deductions.
7371 TEST(NativeArrayTest, ConstructorFromArrayWorks) {
7372 const int a[3] = { 0, 1, 2 };
7378 TEST(NativeArrayTest, CreatesAndDeletesCopyOfArrayWhenAskedTo) {
7379 typedef int Array[2];
7380 Array* a =
new Array[1];
7393 TEST(NativeArrayTest, TypeMembersAreCorrect) {
7394 StaticAssertTypeEq<char, NativeArray<char>::value_type>();
7395 StaticAssertTypeEq<int[2], NativeArray<int[2]>::value_type>();
7397 StaticAssertTypeEq<const char*, NativeArray<char>::const_iterator>();
7398 StaticAssertTypeEq<const bool(*)[2], NativeArray<bool[2]>::const_iterator>();
7401 TEST(NativeArrayTest, MethodsWork) {
7402 const int a[3] = { 0, 1, 2 };
7421 const int b1[3] = { 0, 1, 1 };
7422 const int b2[4] = { 0, 1, 2, 3 };
7427 TEST(NativeArrayTest, WorksForTwoDimensionalArray) {
7428 const char a[2][3] = {
"hi",
"lo" };
7435 TEST(IndexSequence, MakeIndexSequence) {
7441 (std::is_same<IndexSequence<0>, MakeIndexSequence<1>::type>::value));
7443 (std::is_same<IndexSequence<0, 1>, MakeIndexSequence<2>::type>::value));
7445 std::is_same<IndexSequence<0, 1, 2>, MakeIndexSequence<3>::type>::value));
7447 (std::is_base_of<IndexSequence<0, 1, 2>, MakeIndexSequence<3>>::value));
7454 (std::is_same<
int, ElemFromList<0, int, double, char>::type>::value));
7456 (std::is_same<
double, ElemFromList<1, int, double, char>::type>::value));
7458 (std::is_same<
char, ElemFromList<2, int, double, char>::type>::value));
7460 std::is_same<
char, ElemFromList<7,
int,
int,
int,
int,
int,
int,
int,
7461 char,
int,
int,
int,
int>::type>::value));
7468 FlatTuple<int, double, const char*> tuple = {};
7473 tuple = FlatTuple<int, double, const char*>(7, 3.2,
"Foo");
7476 EXPECT_EQ(std::string(
"Foo"), tuple.Get<2>());
7478 tuple.Get<1>() = 5.1;
7488 #define GTEST_FLAT_TUPLE_INT8 int, int, int, int, int, int, int, int,
7489 #define GTEST_FLAT_TUPLE_INT16 GTEST_FLAT_TUPLE_INT8 GTEST_FLAT_TUPLE_INT8
7490 #define GTEST_FLAT_TUPLE_INT32 GTEST_FLAT_TUPLE_INT16 GTEST_FLAT_TUPLE_INT16
7491 #define GTEST_FLAT_TUPLE_INT64 GTEST_FLAT_TUPLE_INT32 GTEST_FLAT_TUPLE_INT32
7492 #define GTEST_FLAT_TUPLE_INT128 GTEST_FLAT_TUPLE_INT64 GTEST_FLAT_TUPLE_INT64
7493 #define GTEST_FLAT_TUPLE_INT256 GTEST_FLAT_TUPLE_INT128 GTEST_FLAT_TUPLE_INT128
7497 FlatTuple<GTEST_FLAT_TUPLE_INT256 int> tuple;
7500 tuple.Get<99>() = 17;
7501 tuple.Get<256>() = 1000;
7509 TEST(SkipPrefixTest, SkipsWhenPrefixMatches) {
7510 const char*
const str =
"hello";
7512 const char* p = str;
7521 TEST(SkipPrefixTest, DoesNotSkipWhenPrefixDoesNotMatch) {
7522 const char*
const str =
"world";
7524 const char* p = str;
7534 TEST(AdHocTestResultTest, AdHocTestResultForUnitTestDoesNotShowFailure) {
7547 "DynamicUnitTestFixture",
"DynamicTest",
"TYPE",
"VALUE", __FILE__,
7552 for (
int i = 0;
i < unittest->total_test_suite_count(); ++
i) {
7553 auto* tests = unittest->GetTestSuite(
i);
7554 if (tests->name() != std::string(
"DynamicUnitTestFixture"))
continue;
7555 for (
int j = 0; j < tests->total_test_count(); ++j) {
7556 if (tests->GetTestInfo(j)->name() != std::string(
"DynamicTest"))
continue;
7558 EXPECT_STREQ(tests->GetTestInfo(j)->value_param(),
"VALUE");
7559 EXPECT_STREQ(tests->GetTestInfo(j)->type_param(),
"TYPE");
7564 FAIL() <<
"Didn't find the test!";
void SetDefaultResultPrinter(TestEventListener *listener)
const int & operator*() const
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)
#define EXPECT_STRCASEEQ(s1, s2)
#define EXPECT_STRNE(s1, s2)
const TestInfo * GetTestInfo(int i) const
#define EXPECT_PRED_FORMAT2(pred_format, v1, v2)
GTEST_API_ std::string GetCurrentOsStackTraceExceptTop(UnitTest *unit_test, int skip_count)
std::string FormatEpochTimeInMillisAsIso8601(TimeInMillis ms)
#define ASSERT_LE(val1, val2)
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)
static bool dummy1 GTEST_ATTRIBUTE_UNUSED_
IsContainer IsContainerTest(int)
#define ASSERT_PRED3(pred, v1, v2, v3)
#define EXPECT_LE(val1, val2)
#define GTEST_DISABLE_MSC_WARNINGS_POP_()
#define ASSERT_NE(val1, val2)
static Flags Output(const char *output)
TEST_F(TestInfoTest, Names)
#define EXPECT_NE(val1, val2)
#define VERIFY_CODE_LOCATION
StaticAssertTypeEqTestHelper()
#define ASSERT_GE(val1, val2)
static const TestResult * GetTestResult(const TestInfo *test_info)
#define ASSERT_PRED1(pred, v1)
bool ShouldUseColor(bool stdout_is_tty)
void OnTestIterationStart(const UnitTest &, int) override
static void CheckFlags(const Flags &expected)
TestEventListener * Release(TestEventListener *listener)
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()
void SuppressEventForwarding()
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)
std::string FormatTimeInMillisAsSeconds(TimeInMillis ms)
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)
void Append(TestEventListener *listener)
static void FailFatally()
internal::ProxyTypeList< Ts...> Types
GTEST_API_ void CaptureStdout()
static Flags StackTraceDepth(int32_t stack_trace_depth)
#define EXPECT_ANY_THROW(statement)
const ElemFromList< I, T...>::type & Get() const
std::ostream & operator<<(std::ostream &os, const Message &sb)
INSTANTIATE_TYPED_TEST_SUITE_P(My, CodeLocationForTYPEDTESTP, int)
#define EXPECT_LT(val1, val2)
#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)
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)
TEST_F(ListenerTest, DoesFoo)
const_iterator begin() const
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)
GTEST_DISALLOW_COPY_AND_ASSIGN_(SequenceTestingListener)
const char * name() const
bool ShouldShard(const char *total_shards_env, const char *shard_index_env, bool in_subprocess_for_death_test)
#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
#define GTEST_COMPILE_ASSERT_(expr, msg)
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)
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)
const TypeId kTestTypeIdInGoogleTest
TEST(GTestEnvVarTest, Dummy)
void OnTestProgramEnd(const UnitTest &) override
GTEST_API_ bool AlwaysTrue()
ADVar foo(double d, ADVar x, ADVar y)
const_iterator end() const
std::vector< std::string > * vector_
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 const uint32_t kMaxRange
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)
FilePath GetCurrentExecutableName()
TimeInMillis GetTimeInMillis()
INSTANTIATE_TEST_SUITE_P(, CodeLocationForTESTP, Values(0))
MyTypeInNameSpace1(int an_x)
int32_t Int32FromEnvOrDie(const char *var, int32_t default_val)
static Flags FailFast(bool fail_fast)
TYPED_TEST_P(CodeLocationForTYPEDTESTP, Verify)
bool ParseInt32Flag(const char *str, const char *flag, int32_t *value)
const char * test_case_name() const
const TestInfo * current_test_info() const GTEST_LOCK_EXCLUDED_(mutex_)
std::string WideStringToUtf8(const wchar_t *str, int num_chars)
bool EventForwardingEnabled() const
static Flags Shuffle(bool shuffle)
int test_property_count() const
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)
#define ASSERT_NEAR(val1, val2, abs_error)
static void SetUpTestSuite()
#define EXPECT_PRED_FORMAT1(pred_format, v1)
static Flags ThrowOnFailure(bool throw_on_failure)
static Flags Filter(const char *filter)
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.
const Bits & bits() const
#define EXPECT_EQ(val1, val2)
#define ASSERT_GT(val1, val2)
void ParseGoogleTestFlagsOnly(int *argc, char **argv)
#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)
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)
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)
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)
#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_
#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]