39TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) {
69#include <unordered_set>
78#if GTEST_CAN_STREAM_RESULTS_
80class StreamingListenerTest :
public Test {
82 class FakeSocketWriter :
public StreamingListener::AbstractSocketWriter {
85 void Send(
const std::string&
message)
override { output_ +=
message; }
90 StreamingListenerTest()
91 : fake_sock_writer_(new FakeSocketWriter),
92 streamer_(fake_sock_writer_),
93 test_info_obj_(
"FooTest",
"Bar", nullptr, nullptr,
94 CodeLocation(__FILE__, __LINE__), nullptr, nullptr) {}
97 std::string*
output() {
return &(fake_sock_writer_->output_); }
99 FakeSocketWriter*
const fake_sock_writer_;
100 StreamingListener streamer_;
105TEST_F(StreamingListenerTest, OnTestProgramEnd) {
107 streamer_.OnTestProgramEnd(unit_test_);
111TEST_F(StreamingListenerTest, OnTestIterationEnd) {
113 streamer_.OnTestIterationEnd(unit_test_, 42);
114 EXPECT_EQ(
"event=TestIterationEnd&passed=1&elapsed_time=0ms\n", *
output());
117TEST_F(StreamingListenerTest, OnTestCaseStart) {
119 streamer_.OnTestCaseStart(
TestCase(
"FooTest",
"Bar",
nullptr,
nullptr));
123TEST_F(StreamingListenerTest, OnTestCaseEnd) {
125 streamer_.OnTestCaseEnd(
TestCase(
"FooTest",
"Bar",
nullptr,
nullptr));
129TEST_F(StreamingListenerTest, OnTestStart) {
131 streamer_.OnTestStart(test_info_obj_);
135TEST_F(StreamingListenerTest, OnTestEnd) {
137 streamer_.OnTestEnd(test_info_obj_);
141TEST_F(StreamingListenerTest, OnTestPartResult) {
143 streamer_.OnTestPartResult(TestPartResult(
144 TestPartResult::kFatalFailure,
"foo.cc", 42,
"failed=\n&%"));
148 "event=TestPartResult&file=foo.cc&line=42&message=failed%3D%0A%26%25\n",
159 return listeners->repeater();
164 listeners->SetDefaultResultPrinter(listener);
168 listeners->SetDefaultXmlGenerator(listener);
172 return listeners.EventForwardingEnabled();
176 listeners->SuppressEventForwarding();
196using testing::AssertionResult;
222using testing::kMaxStackTraceDepth;
224using testing::ScopedFakeTestPartResultReporter;
229using testing::TestPartResult;
230using testing::TestPartResultArray;
243using testing::internal::CountIf;
246using testing::internal::ForEach;
250using testing::internal::GetElementOr;
251using testing::internal::GetNextRandomSeed;
252using testing::internal::GetRandomSeedFromFlag;
256using testing::internal::GetUnitTestImpl;
257using testing::internal::GTestFlagSaver;
263using testing::internal::kMaxRandomSeed;
266using testing::internal::OsStackTraceGetter;
267using testing::internal::OsStackTraceGetterInterface;
274using testing::internal::Shuffle;
275using testing::internal::ShuffleRange;
280using testing::internal::TestResultAccessor;
281using testing::internal::UnitTestImpl;
287#if GTEST_HAS_STREAM_REDIRECTION
292#if GTEST_IS_THREADSAFE
293using testing::internal::ThreadWithParam;
302 for (
size_t i = 0;
i < vector.size();
i++) {
303 os << vector[
i] <<
" ";
312TEST(GetRandomSeedFromFlagTest, HandlesZero) {
313 const int seed = GetRandomSeedFromFlag(0);
315 EXPECT_LE(seed,
static_cast<int>(kMaxRandomSeed));
318TEST(GetRandomSeedFromFlagTest, PreservesValidSeed) {
321 EXPECT_EQ(kMaxRandomSeed - 1, GetRandomSeedFromFlag(kMaxRandomSeed - 1));
322 EXPECT_EQ(
static_cast<int>(kMaxRandomSeed),
323 GetRandomSeedFromFlag(kMaxRandomSeed));
326TEST(GetRandomSeedFromFlagTest, NormalizesInvalidSeed) {
327 const int seed1 = GetRandomSeedFromFlag(-1);
329 EXPECT_LE(seed1,
static_cast<int>(kMaxRandomSeed));
331 const int seed2 = GetRandomSeedFromFlag(kMaxRandomSeed + 1);
333 EXPECT_LE(seed2,
static_cast<int>(kMaxRandomSeed));
336TEST(GetNextRandomSeedTest, WorksForValidInput) {
339 EXPECT_EQ(
static_cast<int>(kMaxRandomSeed),
340 GetNextRandomSeed(kMaxRandomSeed - 1));
341 EXPECT_EQ(1, GetNextRandomSeed(kMaxRandomSeed));
349static void ClearCurrentTestPartResults() {
350 TestResultAccessor::ClearTestPartResults(
351 GetUnitTestImpl()->current_test_result());
356TEST(GetTypeIdTest, ReturnsSameValueForSameType) {
357 EXPECT_EQ(GetTypeId<int>(), GetTypeId<int>());
358 EXPECT_EQ(GetTypeId<Test>(), GetTypeId<Test>());
361class SubClassOfTest :
public Test {};
362class AnotherSubClassOfTest :
public Test {};
364TEST(GetTypeIdTest, ReturnsDifferentValuesForDifferentTypes) {
365 EXPECT_NE(GetTypeId<int>(), GetTypeId<const int>());
366 EXPECT_NE(GetTypeId<int>(), GetTypeId<char>());
370 EXPECT_NE(GetTypeId<AnotherSubClassOfTest>(), GetTypeId<SubClassOfTest>());
375TEST(GetTestTypeIdTest, ReturnsTheSameValueInsideOrOutsideOfGoogleTest) {
406TEST(FormatTimeInMillisAsSecondsTest, FormatsZero) {
410TEST(FormatTimeInMillisAsSecondsTest, FormatsPositiveNumber) {
418TEST(FormatTimeInMillisAsSecondsTest, FormatsNegativeNumber) {
432class FormatEpochTimeInMillisAsIso8601Test :
public Test {
440 void SetUp()
override {
445 saved_tz_ = strdup(getenv("TZ"));
451 SetTimeZone("UTC+00");
454 void TearDown()
override {
455 SetTimeZone(saved_tz_);
456 free(
const_cast<char*
>(saved_tz_));
460 static void SetTimeZone(
const char* time_zone) {
464#if _MSC_VER || GTEST_OS_WINDOWS_MINGW
467 const std::string env_var =
468 std::string(
"TZ=") + (time_zone ? time_zone :
"");
469 _putenv(env_var.c_str());
475 setenv((
"TZ"), time_zone, 1);
483 const char* saved_tz_;
486const TimeInMillis FormatEpochTimeInMillisAsIso8601Test::kMillisPerSec;
488TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsTwoDigitSegments) {
493TEST_F(FormatEpochTimeInMillisAsIso8601Test, IncludesMillisecondsAfterDot) {
495 "2011-10-31T18:52:42.234",
499TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsLeadingZeroes) {
504TEST_F(FormatEpochTimeInMillisAsIso8601Test, Prints24HourTime) {
509TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsEpochStart) {
515# pragma option push -w-ccc -w-rch
520TEST(NullLiteralTest, LHSAllowsNullLiterals) {
521 EXPECT_EQ(0,
static_cast<void*
>(
nullptr));
522 ASSERT_EQ(0,
static_cast<void*
>(
nullptr));
523 EXPECT_EQ(NULL,
static_cast<void*
>(
nullptr));
524 ASSERT_EQ(NULL,
static_cast<void*
>(
nullptr));
525 EXPECT_EQ(
nullptr,
static_cast<void*
>(
nullptr));
526 ASSERT_EQ(
nullptr,
static_cast<void*
>(
nullptr));
528 const int*
const p =
nullptr;
538 template <
typename T>
544struct ConvertToPointer {
546 operator T*()
const {
551struct ConvertToAllButNoPointers {
552 template <
typename T,
562TEST(NullLiteralTest, ImplicitConversion) {
563 EXPECT_EQ(ConvertToPointer{},
static_cast<void*
>(
nullptr));
564#if !defined(__GNUC__) || defined(__clang__)
566 EXPECT_EQ(ConvertToAll{},
static_cast<void*
>(
nullptr));
573#pragma clang diagnostic push
574#if __has_warning("-Wzero-as-null-pointer-constant")
575#pragma clang diagnostic error "-Wzero-as-null-pointer-constant"
579TEST(NullLiteralTest, NoConversionNoWarning) {
587#pragma clang diagnostic pop
599TEST(CodePointToUtf8Test, CanEncodeNul) {
604TEST(CodePointToUtf8Test, CanEncodeAscii) {
613TEST(CodePointToUtf8Test, CanEncode8To11Bits) {
627TEST(CodePointToUtf8Test, CanEncode12To16Bits) {
637#if !GTEST_WIDE_STRING_USES_UTF16_
644TEST(CodePointToUtf8Test, CanEncode17To21Bits) {
656TEST(CodePointToUtf8Test, CanEncodeInvalidCodePoint) {
665TEST(WideStringToUtf8Test, CanEncodeNul) {
671TEST(WideStringToUtf8Test, CanEncodeAscii) {
680TEST(WideStringToUtf8Test, CanEncode8To11Bits) {
686 const wchar_t s[] = { 0x576,
'\0' };
693TEST(WideStringToUtf8Test, CanEncode12To16Bits) {
695 const wchar_t s1[] = { 0x8D3,
'\0' };
700 const wchar_t s2[] = { 0xC74D,
'\0' };
706TEST(WideStringToUtf8Test, StopsOnNulCharacter) {
712TEST(WideStringToUtf8Test, StopsWhenLengthLimitReached) {
716#if !GTEST_WIDE_STRING_USES_UTF16_
720TEST(WideStringToUtf8Test, CanEncode17To21Bits) {
731TEST(WideStringToUtf8Test, CanEncodeInvalidCodePoint) {
738TEST(WideStringToUtf8Test, CanEncodeValidUtf16SUrrogatePairs) {
739 const wchar_t s[] = { 0xD801, 0xDC00,
'\0' };
745TEST(WideStringToUtf8Test, CanEncodeInvalidUtf16SurrogatePair) {
747 const wchar_t s1[] = { 0xD800,
'\0' };
750 const wchar_t s2[] = { 0xD800,
'M',
'\0' };
753 const wchar_t s3[] = { 0xDC00,
'P',
'Q',
'R',
'\0' };
759#if !GTEST_WIDE_STRING_USES_UTF16_
760TEST(WideStringToUtf8Test, ConcatenatesCodepointsCorrectly) {
761 const wchar_t s[] = { 0x108634, 0xC74D,
'\n', 0x576, 0x8D3, 0x108634,
'\0'};
772TEST(WideStringToUtf8Test, ConcatenatesCodepointsCorrectly) {
773 const wchar_t s[] = { 0xC74D,
'\n', 0x576, 0x8D3,
'\0'};
775 "\xEC\x9D\x8D" "\n" "\xD5\xB6" "\xE0\xA3\x93",
782TEST(RandomDeathTest, GeneratesCrashesOnInvalidRange) {
786 "Cannot generate a number in the range \\[0, 0\\)");
789 "Generation of a number in \\[0, 2147483649\\) was requested, "
790 "but this can only generate numbers in \\[0, 2147483648\\)");
793TEST(RandomTest, GeneratesNumbersWithinRange) {
794 constexpr uint32_t kRange = 10000;
796 for (
int i = 0;
i < 10;
i++) {
797 EXPECT_LT(random.Generate(kRange), kRange) <<
" for iteration " <<
i;
801 for (
int i = 0;
i < 10;
i++) {
802 EXPECT_LT(random2.Generate(kRange), kRange) <<
" for iteration " <<
i;
806TEST(RandomTest, RepeatsWhenReseeded) {
807 constexpr int kSeed = 123;
808 constexpr int kArraySize = 10;
809 constexpr uint32_t kRange = 10000;
810 uint32_t values[kArraySize];
813 for (
int i = 0;
i < kArraySize;
i++) {
814 values[
i] = random.Generate(kRange);
817 random.Reseed(kSeed);
818 for (
int i = 0;
i < kArraySize;
i++) {
819 EXPECT_EQ(values[
i], random.Generate(kRange)) <<
" for iteration " <<
i;
827static bool IsPositive(
int n) {
return n > 0; }
829TEST(ContainerUtilityTest, CountIf) {
846static void Accumulate(
int n) { g_sum += n; }
848TEST(ContainerUtilityTest, ForEach) {
851 ForEach(v, Accumulate);
856 ForEach(v, Accumulate);
862 ForEach(v, Accumulate);
867TEST(ContainerUtilityTest, GetElementOr) {
875 EXPECT_EQ(
'x', GetElementOr(a, -2,
'x'));
879TEST(ContainerUtilityDeathTest, ShuffleRange) {
887 ShuffleRange(&random, -1, 1, &a),
888 "Invalid shuffle range start -1: must be in range \\[0, 3\\]");
890 ShuffleRange(&random, 4, 4, &a),
891 "Invalid shuffle range start 4: must be in range \\[0, 3\\]");
893 ShuffleRange(&random, 3, 2, &a),
894 "Invalid shuffle range finish 2: must be in range \\[3, 3\\]");
896 ShuffleRange(&random, 3, 4, &a),
897 "Invalid shuffle range finish 4: must be in range \\[3, 3\\]");
900class VectorShuffleTest :
public Test {
902 static const size_t kVectorSize = 20;
904 VectorShuffleTest() :
random_(1) {
905 for (
int i = 0; i < static_cast<int>(kVectorSize);
i++) {
906 vector_.push_back(
i);
911 if (kVectorSize != vector.size()) {
915 bool found_in_vector[kVectorSize] = {
false };
916 for (
size_t i = 0;
i < vector.size();
i++) {
917 const int e = vector[
i];
918 if (e < 0 || e >=
static_cast<int>(kVectorSize) || found_in_vector[e]) {
921 found_in_vector[e] =
true;
929 static bool VectorIsNotCorrupt(
const TestingVector& vector) {
930 return !VectorIsCorrupt(vector);
933 static bool RangeIsShuffled(
const TestingVector& vector,
int begin,
int end) {
934 for (
int i = begin;
i < end;
i++) {
935 if (
i != vector[
static_cast<size_t>(
i)]) {
942 static bool RangeIsUnshuffled(
944 return !RangeIsShuffled(vector, begin, end);
948 return RangeIsShuffled(vector, 0,
static_cast<int>(vector.size()));
951 static bool VectorIsUnshuffled(
const TestingVector& vector) {
952 return !VectorIsShuffled(vector);
959const size_t VectorShuffleTest::kVectorSize;
961TEST_F(VectorShuffleTest, HandlesEmptyRange) {
963 ShuffleRange(&
random_, 0, 0, &vector_);
968 ShuffleRange(&
random_, kVectorSize/2, kVectorSize/2, &vector_);
973 ShuffleRange(&
random_, kVectorSize - 1, kVectorSize - 1, &vector_);
978 ShuffleRange(&
random_, kVectorSize, kVectorSize, &vector_);
983TEST_F(VectorShuffleTest, HandlesRangeOfSizeOne) {
985 ShuffleRange(&
random_, 0, 1, &vector_);
990 ShuffleRange(&
random_, kVectorSize/2, kVectorSize/2 + 1, &vector_);
995 ShuffleRange(&
random_, kVectorSize - 1, kVectorSize, &vector_);
1003TEST_F(VectorShuffleTest, ShufflesEntireVector) {
1011 EXPECT_NE(
static_cast<int>(kVectorSize - 1), vector_[kVectorSize - 1]);
1014TEST_F(VectorShuffleTest, ShufflesStartOfVector) {
1015 const int kRangeSize = kVectorSize/2;
1017 ShuffleRange(&
random_, 0, kRangeSize, &vector_);
1022 static_cast<int>(kVectorSize));
1025TEST_F(VectorShuffleTest, ShufflesEndOfVector) {
1026 const int kRangeSize = kVectorSize / 2;
1027 ShuffleRange(&
random_, kRangeSize, kVectorSize, &vector_);
1030 EXPECT_PRED3(RangeIsUnshuffled, vector_, 0, kRangeSize);
1032 static_cast<int>(kVectorSize));
1035TEST_F(VectorShuffleTest, ShufflesMiddleOfVector) {
1036 const int kRangeSize =
static_cast<int>(kVectorSize) / 3;
1037 ShuffleRange(&
random_, kRangeSize, 2*kRangeSize, &vector_);
1040 EXPECT_PRED3(RangeIsUnshuffled, vector_, 0, kRangeSize);
1041 EXPECT_PRED3(RangeIsShuffled, vector_, kRangeSize, 2*kRangeSize);
1042 EXPECT_PRED3(RangeIsUnshuffled, vector_, 2 * kRangeSize,
1043 static_cast<int>(kVectorSize));
1046TEST_F(VectorShuffleTest, ShufflesRepeatably) {
1048 for (
size_t i = 0;
i < kVectorSize;
i++) {
1049 vector2.push_back(
static_cast<int>(
i));
1060 for (
size_t i = 0;
i < kVectorSize;
i++) {
1061 EXPECT_EQ(vector_[
i], vector2[
i]) <<
" where i is " <<
i;
1067TEST(AssertHelperTest, AssertHelperIsSmall) {
1074TEST(StringTest, EndsWithCaseInsensitive) {
1075 EXPECT_TRUE(String::EndsWithCaseInsensitive(
"foobar",
"BAR"));
1076 EXPECT_TRUE(String::EndsWithCaseInsensitive(
"foobaR",
"bar"));
1077 EXPECT_TRUE(String::EndsWithCaseInsensitive(
"foobar",
""));
1078 EXPECT_TRUE(String::EndsWithCaseInsensitive(
"",
""));
1080 EXPECT_FALSE(String::EndsWithCaseInsensitive(
"Foobar",
"foo"));
1081 EXPECT_FALSE(String::EndsWithCaseInsensitive(
"foobar",
"Foo"));
1082 EXPECT_FALSE(String::EndsWithCaseInsensitive(
"",
"foo"));
1088static const wchar_t*
const kNull =
nullptr;
1091TEST(StringTest, CaseInsensitiveWideCStringEquals) {
1092 EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(
nullptr,
nullptr));
1093 EXPECT_FALSE(String::CaseInsensitiveWideCStringEquals(kNull, L
""));
1094 EXPECT_FALSE(String::CaseInsensitiveWideCStringEquals(L
"", kNull));
1095 EXPECT_FALSE(String::CaseInsensitiveWideCStringEquals(kNull, L
"foobar"));
1096 EXPECT_FALSE(String::CaseInsensitiveWideCStringEquals(L
"foobar", kNull));
1097 EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(L
"foobar", L
"foobar"));
1098 EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(L
"foobar", L
"FOOBAR"));
1099 EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(L
"FOOBAR", L
"foobar"));
1105TEST(StringTest, ShowWideCString) {
1107 String::ShowWideCString(NULL).c_str());
1108 EXPECT_STREQ(
"", String::ShowWideCString(L
"").c_str());
1109 EXPECT_STREQ(
"foo", String::ShowWideCString(L
"foo").c_str());
1112# if GTEST_OS_WINDOWS_MOBILE
1113TEST(StringTest, AnsiAndUtf16Null) {
1114 EXPECT_EQ(NULL, String::AnsiToUtf16(NULL));
1115 EXPECT_EQ(NULL, String::Utf16ToAnsi(NULL));
1118TEST(StringTest, AnsiAndUtf16ConvertBasic) {
1119 const char* ansi = String::Utf16ToAnsi(L
"str");
1122 const WCHAR* utf16 = String::AnsiToUtf16(
"str");
1123 EXPECT_EQ(0, wcsncmp(L
"str", utf16, 3));
1127TEST(StringTest, AnsiAndUtf16ConvertPathChars) {
1128 const char* ansi = String::Utf16ToAnsi(L
".:\\ \"*?");
1131 const WCHAR* utf16 = String::AnsiToUtf16(
".:\\ \"*?");
1132 EXPECT_EQ(0, wcsncmp(L
".:\\ \"*?", utf16, 3));
1140TEST(TestPropertyTest, StringValue) {
1147TEST(TestPropertyTest, ReplaceStringValue) {
1150 property.SetValue(
"2");
1157static void AddFatalFailure() {
1158 FAIL() <<
"Expected fatal failure.";
1161static void AddNonfatalFailure() {
1165class ScopedFakeTestPartResultReporterTest :
public Test {
1171 static void AddFailure(FailureMode failure) {
1172 if (failure == FATAL_FAILURE) {
1175 AddNonfatalFailure();
1182TEST_F(ScopedFakeTestPartResultReporterTest, InterceptsTestFailures) {
1183 TestPartResultArray results;
1185 ScopedFakeTestPartResultReporter reporter(
1186 ScopedFakeTestPartResultReporter::INTERCEPT_ONLY_CURRENT_THREAD,
1188 AddFailure(NONFATAL_FAILURE);
1189 AddFailure(FATAL_FAILURE);
1193 EXPECT_TRUE(results.GetTestPartResult(0).nonfatally_failed());
1194 EXPECT_TRUE(results.GetTestPartResult(1).fatally_failed());
1197TEST_F(ScopedFakeTestPartResultReporterTest, DeprecatedConstructor) {
1198 TestPartResultArray results;
1201 ScopedFakeTestPartResultReporter reporter(&results);
1202 AddFailure(NONFATAL_FAILURE);
1207#if GTEST_IS_THREADSAFE
1209class ScopedFakeTestPartResultReporterWithThreadsTest
1210 :
public ScopedFakeTestPartResultReporterTest {
1212 static void AddFailureInOtherThread(FailureMode failure) {
1213 ThreadWithParam<FailureMode> thread(&AddFailure, failure,
nullptr);
1218TEST_F(ScopedFakeTestPartResultReporterWithThreadsTest,
1219 InterceptsTestFailuresInAllThreads) {
1220 TestPartResultArray results;
1222 ScopedFakeTestPartResultReporter reporter(
1223 ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS, &results);
1224 AddFailure(NONFATAL_FAILURE);
1225 AddFailure(FATAL_FAILURE);
1226 AddFailureInOtherThread(NONFATAL_FAILURE);
1227 AddFailureInOtherThread(FATAL_FAILURE);
1231 EXPECT_TRUE(results.GetTestPartResult(0).nonfatally_failed());
1232 EXPECT_TRUE(results.GetTestPartResult(1).fatally_failed());
1233 EXPECT_TRUE(results.GetTestPartResult(2).nonfatally_failed());
1234 EXPECT_TRUE(results.GetTestPartResult(3).fatally_failed());
1243typedef ScopedFakeTestPartResultReporterTest ExpectFatalFailureTest;
1245TEST_F(ExpectFatalFailureTest, CatchesFatalFaliure) {
1249TEST_F(ExpectFatalFailureTest, AcceptsStdStringObject) {
1251 ::std::string(
"Expected fatal failure."));
1254TEST_F(ExpectFatalFailureTest, CatchesFatalFailureOnAllThreads) {
1258 "Expected fatal failure.");
1263# pragma option push -w-ccc
1269int NonVoidFunction() {
1275TEST_F(ExpectFatalFailureTest, CanBeUsedInNonVoidFunction) {
1282void DoesNotAbortHelper(
bool* aborted) {
1294TEST_F(ExpectFatalFailureTest, DoesNotAbort) {
1295 bool aborted =
true;
1296 DoesNotAbortHelper(&aborted);
1304static int global_var = 0;
1305#define GTEST_USE_UNPROTECTED_COMMA_ global_var++, global_var++
1307TEST_F(ExpectFatalFailureTest, AcceptsMacroThatExpandsToUnprotectedComma) {
1324typedef ScopedFakeTestPartResultReporterTest ExpectNonfatalFailureTest;
1326TEST_F(ExpectNonfatalFailureTest, CatchesNonfatalFailure) {
1328 "Expected non-fatal failure.");
1331TEST_F(ExpectNonfatalFailureTest, AcceptsStdStringObject) {
1333 ::std::string(
"Expected non-fatal failure."));
1336TEST_F(ExpectNonfatalFailureTest, CatchesNonfatalFailureOnAllThreads) {
1340 "Expected non-fatal failure.");
1346TEST_F(ExpectNonfatalFailureTest, AcceptsMacroThatExpandsToUnprotectedComma) {
1349 AddNonfatalFailure();
1354 AddNonfatalFailure();
1358#if GTEST_IS_THREADSAFE
1360typedef ScopedFakeTestPartResultReporterWithThreadsTest
1361 ExpectFailureWithThreadsTest;
1363TEST_F(ExpectFailureWithThreadsTest, ExpectFatalFailureOnAllThreads) {
1365 "Expected fatal failure.");
1368TEST_F(ExpectFailureWithThreadsTest, ExpectNonFatalFailureOnAllThreads) {
1370 AddFailureInOtherThread(NONFATAL_FAILURE),
"Expected non-fatal failure.");
1377TEST(TestPropertyTest, ConstructorWorks) {
1383TEST(TestPropertyTest, SetValue) {
1386 property.SetValue(
"value_2");
1394class TestResultTest :
public Test {
1396 typedef std::vector<TestPartResult> TPRVector;
1399 TestPartResult * pr1, * pr2;
1404 void SetUp()
override {
1406 pr1 =
new TestPartResult(TestPartResult::kSuccess,
1412 pr2 =
new TestPartResult(TestPartResult::kFatalFailure,
1426 TPRVector* results1 =
const_cast<TPRVector*
>(
1427 &TestResultAccessor::test_part_results(*r1));
1428 TPRVector* results2 =
const_cast<TPRVector*
>(
1429 &TestResultAccessor::test_part_results(*r2));
1434 results1->push_back(*pr1);
1437 results2->push_back(*pr1);
1438 results2->push_back(*pr2);
1441 void TearDown()
override {
1451 static void CompareTestPartResult(
const TestPartResult& expected,
1452 const TestPartResult& actual) {
1453 EXPECT_EQ(expected.type(), actual.type());
1454 EXPECT_STREQ(expected.file_name(), actual.file_name());
1455 EXPECT_EQ(expected.line_number(), actual.line_number());
1458 EXPECT_EQ(expected.passed(), actual.passed());
1459 EXPECT_EQ(expected.failed(), actual.failed());
1460 EXPECT_EQ(expected.nonfatally_failed(), actual.nonfatally_failed());
1461 EXPECT_EQ(expected.fatally_failed(), actual.fatally_failed());
1466TEST_F(TestResultTest, total_part_count) {
1473TEST_F(TestResultTest, Passed) {
1480TEST_F(TestResultTest, Failed) {
1488typedef TestResultTest TestResultDeathTest;
1490TEST_F(TestResultDeathTest, GetTestPartResult) {
1498TEST(TestResultPropertyTest, NoPropertiesFoundWhenNoneAreAdded) {
1504TEST(TestResultPropertyTest, OnePropertyFoundWhenAdded) {
1507 TestResultAccessor::RecordProperty(&test_result,
"testcase", property);
1515TEST(TestResultPropertyTest, MultiplePropertiesFoundWhenAdded) {
1519 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_1);
1520 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_2);
1532TEST(TestResultPropertyTest, OverridesValuesForDuplicateKeys) {
1538 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_1_1);
1539 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_2_1);
1540 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_1_2);
1541 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_2_2);
1554TEST(TestResultPropertyTest, GetTestProperty) {
1559 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_1);
1560 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_2);
1561 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_3);
1592class GTestFlagSaverTest :
public Test {
1597 static void SetUpTestSuite() {
1598 saver_ =
new GTestFlagSaver;
1614 GTEST_FLAG(stack_trace_depth) = kMaxStackTraceDepth;
1621 static void TearDownTestSuite() {
1628 void VerifyAndModifyFlags() {
1662 GTEST_FLAG(stream_result_to) =
"localhost:1234";
1668 static GTestFlagSaver* saver_;
1671GTestFlagSaver* GTestFlagSaverTest::saver_ =
nullptr;
1677TEST_F(GTestFlagSaverTest, ModifyGTestFlags) {
1678 VerifyAndModifyFlags();
1683TEST_F(GTestFlagSaverTest, VerifyGTestFlags) {
1684 VerifyAndModifyFlags();
1690static void SetEnv(
const char* name,
const char*
value) {
1691#if GTEST_OS_WINDOWS_MOBILE
1694#elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9)
1698 static std::map<std::string, std::string*> added_env;
1702 std::string *prev_env = NULL;
1703 if (added_env.find(name) != added_env.end()) {
1704 prev_env = added_env[name];
1706 added_env[name] =
new std::string(
1712 putenv(
const_cast<char*
>(added_env[name]->c_str()));
1714#elif GTEST_OS_WINDOWS
1715 _putenv((
Message() << name <<
"=" <<
value).GetString().c_str());
1717 if (*
value ==
'\0') {
1720 setenv(name,
value, 1);
1725#if !GTEST_OS_WINDOWS_MOBILE
1734TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenVariableIsNotSet) {
1739# if !defined(GTEST_GET_INT32_FROM_ENV_)
1743TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenValueOverflows) {
1744 printf(
"(expecting 2 warnings)\n");
1755TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenValueIsInvalid) {
1756 printf(
"(expecting 2 warnings)\n");
1770TEST(Int32FromGTestEnvTest, ParsesAndReturnsValidValue) {
1783TEST(ParseInt32FlagTest, ReturnsFalseForInvalidFlag) {
1784 int32_t
value = 123;
1794TEST(ParseInt32FlagTest, ReturnsDefaultWhenValueOverflows) {
1795 printf(
"(expecting 2 warnings)\n");
1797 int32_t
value = 123;
1808TEST(ParseInt32FlagTest, ReturnsDefaultWhenValueIsInvalid) {
1809 printf(
"(expecting 2 warnings)\n");
1811 int32_t
value = 123;
1822TEST(ParseInt32FlagTest, ParsesAndReturnsValidValue) {
1823 int32_t
value = 123;
1835#if !GTEST_OS_WINDOWS_MOBILE
1836TEST(Int32FromEnvOrDieTest, ParsesAndReturnsValidValue) {
1847TEST(Int32FromEnvOrDieDeathTest, AbortsOnFailure) {
1856TEST(Int32FromEnvOrDieDeathTest, AbortsOnInt32Overflow) {
1865TEST(ShouldRunTestOnShardTest, IsPartitionWhenThereIsOneShard) {
1875 void SetUp()
override {
1880 void TearDown()
override {
1881 SetEnv(index_var_,
"");
1882 SetEnv(total_var_,
"");
1885 const char* index_var_;
1886 const char* total_var_;
1891TEST_F(ShouldShardTest, ReturnsFalseWhenNeitherEnvVarIsSet) {
1892 SetEnv(index_var_,
"");
1893 SetEnv(total_var_,
"");
1900TEST_F(ShouldShardTest, ReturnsFalseWhenTotalShardIsOne) {
1901 SetEnv(index_var_,
"0");
1902 SetEnv(total_var_,
"1");
1910#if !GTEST_OS_WINDOWS_MOBILE
1911TEST_F(ShouldShardTest, WorksWhenShardEnvVarsAreValid) {
1912 SetEnv(index_var_,
"4");
1913 SetEnv(total_var_,
"22");
1917 SetEnv(index_var_,
"8");
1918 SetEnv(total_var_,
"9");
1922 SetEnv(index_var_,
"0");
1923 SetEnv(total_var_,
"9");
1931typedef ShouldShardTest ShouldShardDeathTest;
1933TEST_F(ShouldShardDeathTest, AbortsWhenShardingEnvVarsAreInvalid) {
1934 SetEnv(index_var_,
"4");
1935 SetEnv(total_var_,
"4");
1938 SetEnv(index_var_,
"4");
1939 SetEnv(total_var_,
"-2");
1942 SetEnv(index_var_,
"5");
1943 SetEnv(total_var_,
"");
1946 SetEnv(index_var_,
"");
1947 SetEnv(total_var_,
"5");
1953TEST(ShouldRunTestOnShardTest, IsPartitionWhenThereAreFiveShards) {
1955 const int num_tests = 17;
1956 const int num_shards = 5;
1959 for (
int test_id = 0; test_id < num_tests; test_id++) {
1960 int prev_selected_shard_index = -1;
1961 for (
int shard_index = 0; shard_index < num_shards; shard_index++) {
1963 if (prev_selected_shard_index < 0) {
1964 prev_selected_shard_index = shard_index;
1966 ADD_FAILURE() <<
"Shard " << prev_selected_shard_index <<
" and "
1967 << shard_index <<
" are both selected to run test " << test_id;
1975 for (
int shard_index = 0; shard_index < num_shards; shard_index++) {
1976 int num_tests_on_shard = 0;
1977 for (
int test_id = 0; test_id < num_tests; test_id++) {
1978 num_tests_on_shard +=
1981 EXPECT_GE(num_tests_on_shard, num_tests / num_shards);
1995TEST(UnitTestTest, CanGetOriginalWorkingDir) {
1996 ASSERT_TRUE(UnitTest::GetInstance()->original_working_dir() !=
nullptr);
1997 EXPECT_STRNE(UnitTest::GetInstance()->original_working_dir(),
"");
2000TEST(UnitTestTest, ReturnsPlausibleTimestamp) {
2001 EXPECT_LT(0, UnitTest::GetInstance()->start_timestamp());
2008void ExpectNonFatalFailureRecordingPropertyWithReservedKey(
2009 const TestResult& test_result,
const char* key) {
2012 <<
"' recorded unexpectedly.";
2015void ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2019 ExpectNonFatalFailureRecordingPropertyWithReservedKey(*test_info->
result(),
2023void ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2028 ExpectNonFatalFailureRecordingPropertyWithReservedKey(
2032void ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2034 ExpectNonFatalFailureRecordingPropertyWithReservedKey(
2035 UnitTest::GetInstance()->ad_hoc_test_result(), key);
2041class UnitTestRecordPropertyTest :
2044 static void SetUpTestSuite() {
2045 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2047 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2049 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2051 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2053 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2055 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2058 Test::RecordProperty(
"test_case_key_1",
"1");
2061 UnitTest::GetInstance()->current_test_suite();
2074TEST_F(UnitTestRecordPropertyTest, OnePropertyFoundWhenAdded) {
2075 UnitTestRecordProperty(
"key_1",
"1");
2077 ASSERT_EQ(1, unit_test_.ad_hoc_test_result().test_property_count());
2080 unit_test_.ad_hoc_test_result().GetTestProperty(0).key());
2082 unit_test_.ad_hoc_test_result().GetTestProperty(0).value());
2086TEST_F(UnitTestRecordPropertyTest, MultiplePropertiesFoundWhenAdded) {
2087 UnitTestRecordProperty(
"key_1",
"1");
2088 UnitTestRecordProperty(
"key_2",
"2");
2090 ASSERT_EQ(2, unit_test_.ad_hoc_test_result().test_property_count());
2093 unit_test_.ad_hoc_test_result().GetTestProperty(0).key());
2094 EXPECT_STREQ(
"1", unit_test_.ad_hoc_test_result().GetTestProperty(0).value());
2097 unit_test_.ad_hoc_test_result().GetTestProperty(1).key());
2098 EXPECT_STREQ(
"2", unit_test_.ad_hoc_test_result().GetTestProperty(1).value());
2102TEST_F(UnitTestRecordPropertyTest, OverridesValuesForDuplicateKeys) {
2103 UnitTestRecordProperty(
"key_1",
"1");
2104 UnitTestRecordProperty(
"key_2",
"2");
2105 UnitTestRecordProperty(
"key_1",
"12");
2106 UnitTestRecordProperty(
"key_2",
"22");
2108 ASSERT_EQ(2, unit_test_.ad_hoc_test_result().test_property_count());
2111 unit_test_.ad_hoc_test_result().GetTestProperty(0).key());
2113 unit_test_.ad_hoc_test_result().GetTestProperty(0).value());
2116 unit_test_.ad_hoc_test_result().GetTestProperty(1).key());
2118 unit_test_.ad_hoc_test_result().GetTestProperty(1).value());
2121TEST_F(UnitTestRecordPropertyTest,
2122 AddFailureInsideTestsWhenUsingTestSuiteReservedKeys) {
2123 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2125 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2127 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2129 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2131 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2133 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2137TEST_F(UnitTestRecordPropertyTest,
2138 AddRecordWithReservedKeysGeneratesCorrectPropertyList) {
2140 Test::RecordProperty(
"name",
"1"),
2141 "'classname', 'name', 'status', 'time', 'type_param', 'value_param',"
2142 " 'file', and 'line' are reserved");
2145class UnitTestRecordPropertyTestEnvironment :
public Environment {
2147 void TearDown()
override {
2148 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2150 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2152 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2154 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2156 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2158 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2160 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2162 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2181 return (n % 2) == 0;
2185struct IsEvenFunctor {
2186 bool operator()(
int n) {
return IsEven(n); }
2191AssertionResult AssertIsEven(
const char* expr,
int n) {
2197 msg << expr <<
" evaluates to " << n <<
", which is not even.";
2203AssertionResult ResultIsEven(
int n) {
2213AssertionResult ResultIsEvenNoExplanation(
int n) {
2222struct AssertIsEvenFunctor {
2223 AssertionResult operator()(
const char* expr,
int n) {
2224 return AssertIsEven(expr, n);
2229bool SumIsEven2(
int n1,
int n2) {
2230 return IsEven(n1 + n2);
2235struct SumIsEven3Functor {
2236 bool operator()(
int n1,
int n2,
int n3) {
2237 return IsEven(n1 + n2 + n3);
2243AssertionResult AssertSumIsEven4(
2244 const char* e1,
const char* e2,
const char* e3,
const char* e4,
2245 int n1,
int n2,
int n3,
int n4) {
2246 const int sum = n1 + n2 + n3 + n4;
2252 msg << e1 <<
" + " << e2 <<
" + " << e3 <<
" + " << e4
2253 <<
" (" << n1 <<
" + " << n2 <<
" + " << n3 <<
" + " << n4
2254 <<
") evaluates to " << sum <<
", which is not even.";
2260struct AssertSumIsEven5Functor {
2261 AssertionResult operator()(
2262 const char* e1,
const char* e2,
const char* e3,
const char* e4,
2263 const char* e5,
int n1,
int n2,
int n3,
int n4,
int n5) {
2264 const int sum = n1 + n2 + n3 + n4 + n5;
2270 msg << e1 <<
" + " << e2 <<
" + " << e3 <<
" + " << e4 <<
" + " << e5
2272 << n1 <<
" + " << n2 <<
" + " << n3 <<
" + " << n4 <<
" + " << n5
2273 <<
") evaluates to " << sum <<
", which is not even.";
2282TEST(Pred1Test, WithoutFormat) {
2284 EXPECT_PRED1(IsEvenFunctor(), 2) <<
"This failure is UNEXPECTED!";
2289 EXPECT_PRED1(IsEven, 5) <<
"This failure is expected.";
2290 },
"This failure is expected.");
2292 "evaluates to false");
2296TEST(Pred1Test, WithFormat) {
2300 <<
"This failure is UNEXPECTED!";
2305 "n evaluates to 5, which is not even.");
2308 },
"This failure is expected.");
2313TEST(Pred1Test, SingleEvaluationOnFailure) {
2317 EXPECT_EQ(1, n) <<
"The argument is not evaluated exactly once.";
2322 <<
"This failure is expected.";
2323 },
"This failure is expected.");
2324 EXPECT_EQ(2, n) <<
"The argument is not evaluated exactly once.";
2331TEST(PredTest, WithoutFormat) {
2333 ASSERT_PRED2(SumIsEven2, 2, 4) <<
"This failure is UNEXPECTED!";
2340 EXPECT_PRED2(SumIsEven2, n1, n2) <<
"This failure is expected.";
2341 },
"This failure is expected.");
2344 },
"evaluates to false");
2348TEST(PredTest, WithFormat) {
2351 "This failure is UNEXPECTED!";
2361 },
"evaluates to 13, which is not even.");
2364 <<
"This failure is expected.";
2365 },
"This failure is expected.");
2370TEST(PredTest, SingleEvaluationOnFailure) {
2375 EXPECT_EQ(1, n1) <<
"Argument 1 is not evaluated exactly once.";
2376 EXPECT_EQ(1, n2) <<
"Argument 2 is not evaluated exactly once.";
2384 n1++, n2++, n3++, n4++, n5++)
2385 <<
"This failure is UNEXPECTED!";
2386 EXPECT_EQ(1, n1) <<
"Argument 1 is not evaluated exactly once.";
2387 EXPECT_EQ(1, n2) <<
"Argument 2 is not evaluated exactly once.";
2388 EXPECT_EQ(1, n3) <<
"Argument 3 is not evaluated exactly once.";
2389 EXPECT_EQ(1, n4) <<
"Argument 4 is not evaluated exactly once.";
2390 EXPECT_EQ(1, n5) <<
"Argument 5 is not evaluated exactly once.";
2396 <<
"This failure is expected.";
2397 },
"This failure is expected.");
2398 EXPECT_EQ(1, n1) <<
"Argument 1 is not evaluated exactly once.";
2399 EXPECT_EQ(1, n2) <<
"Argument 2 is not evaluated exactly once.";
2400 EXPECT_EQ(1, n3) <<
"Argument 3 is not evaluated exactly once.";
2403 n1 = n2 = n3 = n4 = 0;
2406 },
"evaluates to 1, which is not even.");
2407 EXPECT_EQ(1, n1) <<
"Argument 1 is not evaluated exactly once.";
2408 EXPECT_EQ(1, n2) <<
"Argument 2 is not evaluated exactly once.";
2409 EXPECT_EQ(1, n3) <<
"Argument 3 is not evaluated exactly once.";
2410 EXPECT_EQ(1, n4) <<
"Argument 4 is not evaluated exactly once.";
2414TEST(PredTest, ExpectPredEvalFailure) {
2415 std::set<int> set_a = {2, 1, 3, 4, 5};
2416 std::set<int> set_b = {0, 4, 8};
2417 const auto compare_sets = [] (std::set<int>, std::set<int>) {
return false; };
2420 "compare_sets(set_a, set_b) evaluates to false, where\nset_a evaluates "
2421 "to { 1, 2, 3, 4, 5 }\nset_b evaluates to { 0, 4, 8 }");
2427bool IsPositive(
double x) {
2431template <
typename T>
2432bool IsNegative(T
x) {
2436template <
typename T1,
typename T2>
2437bool GreaterThan(
T1 x1,
T2 x2) {
2443TEST(PredicateAssertionTest, AcceptsOverloadedFunction) {
2451TEST(PredicateAssertionTest, AcceptsTemplateFunction) {
2462AssertionResult IsPositiveFormat(
const char* ,
int n) {
2467AssertionResult IsPositiveFormat(
const char* ,
double x) {
2472template <
typename T>
2473AssertionResult IsNegativeFormat(
const char* , T
x) {
2478template <
typename T1,
typename T2>
2479AssertionResult EqualsFormat(
const char* ,
const char* ,
2480 const T1& x1,
const T2& x2) {
2487TEST(PredicateFormatAssertionTest, AcceptsOverloadedFunction) {
2494TEST(PredicateFormatAssertionTest, AcceptsTemplateFunction) {
2504 const char *
const p1 =
"good";
2508 const char p2[] =
"good";
2512 " \"bad\"\n \"good\"");
2516TEST(StringAssertionTest, ASSERT_STREQ_Null) {
2517 ASSERT_STREQ(
static_cast<const char*
>(
nullptr),
nullptr);
2522TEST(StringAssertionTest, ASSERT_STREQ_Null2) {
2536 "\"Hi\" vs \"Hi\"");
2563TEST(StringAssertionTest, STREQ_Wide) {
2565 ASSERT_STREQ(
static_cast<const wchar_t*
>(
nullptr),
nullptr);
2586 EXPECT_STREQ(L
"abc\x8119", L
"abc\x8121") <<
"Expected failure";
2587 },
"Expected failure");
2591TEST(StringAssertionTest, STRNE_Wide) {
2595 EXPECT_STRNE(
static_cast<const wchar_t*
>(
nullptr),
nullptr);
2618 ASSERT_STRNE(L
"abc\x8119", L
"abc\x8120") <<
"This shouldn't happen";
2625TEST(IsSubstringTest, ReturnsCorrectResultForCString) {
2636TEST(IsSubstringTest, ReturnsCorrectResultForWideCString) {
2642 IsSubstring(
"",
"",
static_cast<const wchar_t*
>(
nullptr),
nullptr));
2648TEST(IsSubstringTest, GeneratesCorrectMessageForCString) {
2650 " Actual: \"needle\"\n"
2651 "Expected: a substring of haystack_expr\n"
2652 "Which is: \"haystack\"",
2654 "needle",
"haystack").failure_message());
2659TEST(IsSubstringTest, ReturnsCorrectResultsForStdString) {
2664#if GTEST_HAS_STD_WSTRING
2667TEST(IsSubstringTest, ReturnsCorrectResultForStdWstring) {
2674TEST(IsSubstringTest, GeneratesCorrectMessageForWstring) {
2676 " Actual: L\"needle\"\n"
2677 "Expected: a substring of haystack_expr\n"
2678 "Which is: L\"haystack\"",
2680 "needle_expr",
"haystack_expr",
2681 ::std::wstring(L
"needle"), L
"haystack").failure_message());
2690TEST(IsNotSubstringTest, ReturnsCorrectResultForCString) {
2697TEST(IsNotSubstringTest, ReturnsCorrectResultForWideCString) {
2704TEST(IsNotSubstringTest, GeneratesCorrectMessageForWideCString) {
2706 " Actual: L\"needle\"\n"
2707 "Expected: not a substring of haystack_expr\n"
2708 "Which is: L\"two needles\"",
2710 "needle_expr",
"haystack_expr",
2711 L
"needle", L
"two needles").failure_message());
2716TEST(IsNotSubstringTest, ReturnsCorrectResultsForStdString) {
2723TEST(IsNotSubstringTest, GeneratesCorrectMessageForStdString) {
2725 " Actual: \"needle\"\n"
2726 "Expected: not a substring of haystack_expr\n"
2727 "Which is: \"two needles\"",
2729 "needle_expr",
"haystack_expr",
2730 ::std::string(
"needle"),
"two needles").failure_message());
2733#if GTEST_HAS_STD_WSTRING
2737TEST(IsNotSubstringTest, ReturnsCorrectResultForStdWstring) {
2739 IsNotSubstring(
"",
"", ::std::wstring(L
"needle"), L
"two needles"));
2747template <
typename RawType>
2748class FloatingPointTest :
public Test {
2752 RawType close_to_positive_zero;
2753 RawType close_to_negative_zero;
2754 RawType further_from_negative_zero;
2756 RawType close_to_one;
2757 RawType further_from_one;
2760 RawType close_to_infinity;
2761 RawType further_from_infinity;
2768 typedef typename Floating::Bits Bits;
2770 void SetUp()
override {
2771 const uint32_t max_ulps = Floating::kMaxUlps;
2774 const Bits zero_bits = Floating(0).
bits();
2777 values_.close_to_positive_zero = Floating::ReinterpretBits(
2778 zero_bits + max_ulps/2);
2779 values_.close_to_negative_zero = -Floating::ReinterpretBits(
2780 zero_bits + max_ulps - max_ulps/2);
2781 values_.further_from_negative_zero = -Floating::ReinterpretBits(
2782 zero_bits + max_ulps + 1 - max_ulps/2);
2785 const Bits one_bits = Floating(1).bits();
2788 values_.close_to_one = Floating::ReinterpretBits(one_bits + max_ulps);
2789 values_.further_from_one = Floating::ReinterpretBits(
2790 one_bits + max_ulps + 1);
2793 values_.infinity = Floating::Infinity();
2796 const Bits infinity_bits = Floating(values_.infinity).bits();
2799 values_.close_to_infinity = Floating::ReinterpretBits(
2800 infinity_bits - max_ulps);
2801 values_.further_from_infinity = Floating::ReinterpretBits(
2802 infinity_bits - max_ulps - 1);
2807 values_.nan1 = Floating::ReinterpretBits(Floating::kExponentBitMask
2808 | (
static_cast<Bits
>(1) << (Floating::kFractionBitCount - 1)) | 1);
2809 values_.nan2 = Floating::ReinterpretBits(Floating::kExponentBitMask
2810 | (
static_cast<Bits
>(1) << (Floating::kFractionBitCount - 1)) | 200);
2814 EXPECT_EQ(
sizeof(RawType),
sizeof(Bits));
2817 static TestValues values_;
2820template <
typename RawType>
2821typename FloatingPointTest<RawType>::TestValues
2822 FloatingPointTest<RawType>::values_;
2825typedef FloatingPointTest<float> FloatTest;
2833TEST_F(FloatTest, Zeros) {
2846TEST_F(FloatTest, AlmostZeros) {
2853 static const FloatTest::TestValues& v = this->values_;
2861 v.further_from_negative_zero);
2862 },
"v.further_from_negative_zero");
2866TEST_F(FloatTest, SmallDiff) {
2869 "values_.further_from_one");
2873TEST_F(FloatTest, LargeDiff) {
2882TEST_F(FloatTest, Infinity) {
2886 "-values_.infinity");
2902 static const FloatTest::TestValues& v = this->values_;
2916TEST_F(FloatTest, Reflexive) {
2923TEST_F(FloatTest, Commutative) {
2937 "The difference between 1.0f and 1.5f is 0.5, "
2938 "which exceeds 0.25f");
2946 "The difference between 1.0f and 1.5f is 0.5, "
2947 "which exceeds 0.25f");
2951TEST_F(FloatTest, FloatLESucceeds) {
2960TEST_F(FloatTest, FloatLEFails) {
2963 "(2.0f) <= (1.0f)");
2968 },
"(values_.further_from_one) <= (1.0f)");
2972 },
"(values_.nan1) <= (values_.infinity)");
2975 },
"(-values_.infinity) <= (values_.nan1)");
2978 },
"(values_.nan1) <= (values_.nan1)");
2982typedef FloatingPointTest<double> DoubleTest;
2985TEST_F(DoubleTest, Size) {
2990TEST_F(DoubleTest, Zeros) {
3003TEST_F(DoubleTest, AlmostZeros) {
3010 static const DoubleTest::TestValues& v = this->values_;
3018 v.further_from_negative_zero);
3019 },
"v.further_from_negative_zero");
3023TEST_F(DoubleTest, SmallDiff) {
3026 "values_.further_from_one");
3030TEST_F(DoubleTest, LargeDiff) {
3039TEST_F(DoubleTest, Infinity) {
3043 "-values_.infinity");
3053 static const DoubleTest::TestValues& v = this->values_;
3065TEST_F(DoubleTest, Reflexive) {
3072TEST_F(DoubleTest, Commutative) {
3086 "The difference between 1.0 and 1.5 is 0.5, "
3087 "which exceeds 0.25");
3091 EXPECT_NEAR(4.2934311416234112e+18, 4.2934311416234107e+18, 1.0),
3092 "The abs_error parameter 1.0 evaluates to 1 which is smaller than the "
3093 "minimum distance between doubles for numbers of this magnitude which is "
3102 "The difference between 1.0 and 1.5 is 0.5, "
3103 "which exceeds 0.25");
3107TEST_F(DoubleTest, DoubleLESucceeds) {
3116TEST_F(DoubleTest, DoubleLEFails) {
3124 },
"(values_.further_from_one) <= (1.0)");
3128 },
"(values_.nan1) <= (values_.infinity)");
3131 },
" (-values_.infinity) <= (values_.nan1)");
3134 },
"(values_.nan1) <= (values_.nan1)");
3144 FAIL() <<
"Unexpected failure: Disabled test should not be run.";
3155TEST(DISABLED_TestSuite, TestShouldNotRun) {
3156 FAIL() <<
"Unexpected failure: Test in disabled test case should not be run.";
3161TEST(DISABLED_TestSuite, DISABLED_TestShouldNotRun) {
3162 FAIL() <<
"Unexpected failure: Test in disabled test case should not be run.";
3167class DisabledTestsTest :
public Test {
3169 static void SetUpTestSuite() {
3170 FAIL() <<
"Unexpected failure: All tests disabled in test case. "
3171 "SetUpTestSuite() should not be called.";
3174 static void TearDownTestSuite() {
3175 FAIL() <<
"Unexpected failure: All tests disabled in test case. "
3176 "TearDownTestSuite() should not be called.";
3180TEST_F(DisabledTestsTest, DISABLED_TestShouldNotRun_1) {
3181 FAIL() <<
"Unexpected failure: Disabled test should not be run.";
3184TEST_F(DisabledTestsTest, DISABLED_TestShouldNotRun_2) {
3185 FAIL() <<
"Unexpected failure: Disabled test should not be run.";
3190template <
typename T>
3198 FAIL() <<
"Unexpected failure: Disabled typed test should not run.";
3201template <
typename T>
3202class DISABLED_TypedTest :
public Test {
3207TYPED_TEST(DISABLED_TypedTest, ShouldNotRun) {
3208 FAIL() <<
"Unexpected failure: Disabled typed test should not run.";
3213template <
typename T>
3220 FAIL() <<
"Unexpected failure: "
3221 <<
"Disabled type-parameterized test should not run.";
3228template <
typename T>
3229class DISABLED_TypedTestP :
public Test {
3235 FAIL() <<
"Unexpected failure: "
3236 <<
"Disabled type-parameterized test should not run.";
3245class 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_;
3277const char*
const SingleEvaluationTest::s1_ =
"01234";
3278const char*
const SingleEvaluationTest::s2_ =
"abcde";
3279const char* SingleEvaluationTest::p1_;
3280const char* SingleEvaluationTest::p2_;
3281int SingleEvaluationTest::a_;
3282int SingleEvaluationTest::b_;
3286TEST_F(SingleEvaluationTest, FailedASSERT_STREQ) {
3294TEST_F(SingleEvaluationTest, ASSERT_STR) {
3309TEST_F(SingleEvaluationTest, FailedASSERT_NE) {
3311 "(a_++) != (b_++)");
3317TEST_F(SingleEvaluationTest, OtherCases) {
3346#if GTEST_HAS_EXCEPTIONS
3351#define ERROR_DESC "class std::runtime_error"
3353#define ERROR_DESC "std::runtime_error"
3358#define ERROR_DESC "an std::exception-derived error"
3362void ThrowAnInteger() {
3365void ThrowRuntimeError(
const char* what) {
3366 throw std::runtime_error(what);
3370TEST_F(SingleEvaluationTest, ExceptionTests) {
3382 }, bool),
"throws a different type");
3388 ThrowRuntimeError(
"A description");
3389 }, bool),
"throws " ERROR_DESC
" with description \"A description\"");
3422class NoFatalFailureTest :
public Test {
3425 void FailsNonFatal() {
3429 FAIL() <<
"some fatal failure";
3432 void DoAssertNoFatalFailureOnFails() {
3437 void DoExpectNoFatalFailureOnFails() {
3443TEST_F(NoFatalFailureTest, NoFailure) {
3448TEST_F(NoFatalFailureTest, NonFatalIsNoFailure) {
3451 "some non-fatal failure");
3454 "some non-fatal failure");
3457TEST_F(NoFatalFailureTest, AssertNoFatalFailureOnFatalFailure) {
3458 TestPartResultArray gtest_failures;
3460 ScopedFakeTestPartResultReporter gtest_reporter(>est_failures);
3461 DoAssertNoFatalFailureOnFails();
3464 EXPECT_EQ(TestPartResult::kFatalFailure,
3465 gtest_failures.GetTestPartResult(0).type());
3466 EXPECT_EQ(TestPartResult::kFatalFailure,
3467 gtest_failures.GetTestPartResult(1).type());
3469 gtest_failures.GetTestPartResult(0).message());
3471 gtest_failures.GetTestPartResult(1).message());
3474TEST_F(NoFatalFailureTest, ExpectNoFatalFailureOnFatalFailure) {
3475 TestPartResultArray gtest_failures;
3477 ScopedFakeTestPartResultReporter gtest_reporter(>est_failures);
3478 DoExpectNoFatalFailureOnFails();
3481 EXPECT_EQ(TestPartResult::kFatalFailure,
3482 gtest_failures.GetTestPartResult(0).type());
3483 EXPECT_EQ(TestPartResult::kNonFatalFailure,
3484 gtest_failures.GetTestPartResult(1).type());
3485 EXPECT_EQ(TestPartResult::kNonFatalFailure,
3486 gtest_failures.GetTestPartResult(2).type());
3488 gtest_failures.GetTestPartResult(0).message());
3490 gtest_failures.GetTestPartResult(1).message());
3492 gtest_failures.GetTestPartResult(2).message());
3495TEST_F(NoFatalFailureTest, MessageIsStreamable) {
3496 TestPartResultArray gtest_failures;
3498 ScopedFakeTestPartResultReporter gtest_reporter(>est_failures);
3502 EXPECT_EQ(TestPartResult::kNonFatalFailure,
3503 gtest_failures.GetTestPartResult(0).type());
3504 EXPECT_EQ(TestPartResult::kNonFatalFailure,
3505 gtest_failures.GetTestPartResult(1).type());
3507 gtest_failures.GetTestPartResult(0).message());
3509 gtest_failures.GetTestPartResult(1).message());
3514std::string EditsToString(
const std::vector<EditType>& edits) {
3516 for (
size_t i = 0;
i < edits.size(); ++
i) {
3517 static const char kEdits[] =
" +-/";
3518 out.append(1, kEdits[edits[
i]]);
3523std::vector<size_t> CharsToIndices(
const std::string& str) {
3524 std::vector<size_t> out;
3525 for (
size_t i = 0;
i < str.size(); ++
i) {
3526 out.push_back(
static_cast<size_t>(str[
i]));
3531std::vector<std::string> CharsToLines(
const std::string& str) {
3532 std::vector<std::string> out;
3533 for (
size_t i = 0;
i < str.size(); ++
i) {
3534 out.push_back(str.substr(
i, 1));
3539TEST(EditDistance, TestSuites) {
3544 const char* expected_edits;
3545 const char* expected_diff;
3547 static const Case kCases[] = {
3549 {__LINE__,
"A",
"A",
" ",
""},
3550 {__LINE__,
"ABCDE",
"ABCDE",
" ",
""},
3552 {__LINE__,
"X",
"XA",
" +",
"@@ +1,2 @@\n X\n+A\n"},
3553 {__LINE__,
"X",
"XABCD",
" ++++",
"@@ +1,5 @@\n X\n+A\n+B\n+C\n+D\n"},
3555 {__LINE__,
"XA",
"X",
" -",
"@@ -1,2 @@\n X\n-A\n"},
3556 {__LINE__,
"XABCD",
"X",
" ----",
"@@ -1,5 @@\n X\n-A\n-B\n-C\n-D\n"},
3558 {__LINE__,
"A",
"a",
"/",
"@@ -1,1 +1,1 @@\n-A\n+a\n"},
3559 {__LINE__,
"ABCD",
"abcd",
"////",
3560 "@@ -1,4 +1,4 @@\n-A\n-B\n-C\n-D\n+a\n+b\n+c\n+d\n"},
3562 {__LINE__,
"ABCDEFGH",
"ABXEGH1",
" -/ - +",
3563 "@@ -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"},
3564 {__LINE__,
"AAAABCCCC",
"ABABCDCDC",
"- / + / ",
3565 "@@ -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"},
3566 {__LINE__,
"ABCDE",
"BCDCD",
"- +/",
3567 "@@ -1,5 +1,5 @@\n-A\n B\n C\n D\n-E\n+C\n+D\n"},
3568 {__LINE__,
"ABCDEFGHIJKL",
"BCDCDEFGJKLJK",
"- ++ -- ++",
3569 "@@ -1,4 +1,5 @@\n-A\n B\n+C\n+D\n C\n D\n"
3570 "@@ -6,7 +7,7 @@\n F\n G\n-H\n-I\n J\n K\n L\n+J\n+K\n"},
3572 for (
const Case* c = kCases; c->left; ++c) {
3575 CharsToIndices(c->right))))
3576 <<
"Left <" << c->left <<
"> Right <" << c->right <<
"> Edits <"
3578 CharsToIndices(c->left), CharsToIndices(c->right))) <<
">";
3580 CharsToLines(c->right)))
3581 <<
"Left <" << c->left <<
"> Right <" << c->right <<
"> Diff <"
3589 const std::string foo_val(
"5"), bar_val(
"6");
3590 const std::string msg1(
3591 EqFailure(
"foo",
"bar", foo_val, bar_val,
false)
3592 .failure_message());
3594 "Expected equality of these values:\n"
3601 const std::string msg2(
3602 EqFailure(
"foo",
"6", foo_val, bar_val,
false)
3603 .failure_message());
3605 "Expected equality of these values:\n"
3611 const std::string msg3(
3612 EqFailure(
"5",
"bar", foo_val, bar_val,
false)
3613 .failure_message());
3615 "Expected equality of these values:\n"
3621 const std::string msg4(
3622 EqFailure(
"5",
"6", foo_val, bar_val,
false).failure_message());
3624 "Expected equality of these values:\n"
3629 const std::string msg5(
3631 std::string(
"\"x\""), std::string(
"\"y\""),
3632 true).failure_message());
3634 "Expected equality of these values:\n"
3636 " Which is: \"x\"\n"
3638 " Which is: \"y\"\n"
3643TEST(AssertionTest, EqFailureWithDiff) {
3644 const std::string left(
3645 "1\\n2XXX\\n3\\n5\\n6\\n7\\n8\\n9\\n10\\n11\\n12XXX\\n13\\n14\\n15");
3646 const std::string right(
3647 "1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n11\\n12\\n13\\n14");
3648 const std::string msg1(
3649 EqFailure(
"left",
"right", left, right,
false).failure_message());
3651 "Expected equality of these values:\n"
3654 "1\\n2XXX\\n3\\n5\\n6\\n7\\n8\\n9\\n10\\n11\\n12XXX\\n13\\n14\\n15\n"
3656 " Which is: 1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n11\\n12\\n13\\n14\n"
3657 "With diff:\n@@ -1,5 +1,6 @@\n 1\n-2XXX\n+2\n 3\n+4\n 5\n 6\n"
3658 "@@ -7,8 +8,6 @@\n 8\n 9\n-10\n 11\n-12XXX\n+12\n 13\n 14\n-15\n",
3664 const std::string
foo(
"foo");
3677# pragma option push -w-ccc -w-rch
3688TEST(AssertionTest, AssertTrueWithAssertionResult) {
3693 "Value of: ResultIsEven(3)\n"
3694 " Actual: false (3 is odd)\n"
3699 "Value of: ResultIsEvenNoExplanation(3)\n"
3700 " Actual: false (3 is odd)\n"
3714TEST(AssertionTest, AssertFalseWithAssertionResult) {
3719 "Value of: ResultIsEven(2)\n"
3720 " Actual: true (2 is even)\n"
3725 "Value of: ResultIsEvenNoExplanation(2)\n"
3738TEST(ExpectTest, ASSERT_EQ_Double) {
3751 "Expected equality of these values:\n"
3758TEST(AssertionTest, ASSERT_EQ_NULL) {
3760 const char*
p =
nullptr;
3772TEST(ExpectTest, ASSERT_EQ_0) {
3787 "Expected: ('a') != ('a'), "
3788 "actual: 'a' (97, 0x61) vs 'a' (97, 0x61)");
3796 "Expected: (2) <= (0), actual: 2 vs 0");
3803 "Expected: (2) < (2), actual: 2 vs 2");
3811 "Expected: (2) >= (3), actual: 2 vs 3");
3818 "Expected: (2) > (2), actual: 2 vs 2");
3821#if GTEST_HAS_EXCEPTIONS
3823void ThrowNothing() {}
3829# ifndef __BORLANDC__
3834 "Expected: ThrowAnInteger() throws an exception of type bool.\n"
3835 " Actual: it throws a different type.");
3837 ASSERT_THROW(ThrowRuntimeError(
"A description"), std::logic_error),
3838 "Expected: ThrowRuntimeError(\"A description\") "
3839 "throws an exception of type std::logic_error.\n "
3840 "Actual: it throws " ERROR_DESC
" "
3841 "with description \"A description\".");
3846 "Expected: ThrowNothing() throws an exception of type bool.\n"
3847 " Actual: it throws nothing.");
3854 "Expected: ThrowAnInteger() doesn't throw an exception."
3855 "\n Actual: it throws.");
3857 "Expected: ThrowRuntimeError(\"A description\") "
3858 "doesn't throw an exception.\n "
3859 "Actual: it throws " ERROR_DESC
" "
3860 "with description \"A description\".");
3868 "Expected: ThrowNothing() throws an exception.\n"
3869 " Actual: it doesn't.");
3876TEST(AssertionTest, AssertPrecedence) {
3878 bool false_value =
false;
3888TEST(AssertionTest, NonFixtureSubroutine) {
3890 " x\n Which is: 2");
3896 explicit Uncopyable(
int a_value) : value_(a_value) {}
3898 int value()
const {
return value_; }
3899 bool operator==(
const Uncopyable& rhs)
const {
3900 return value() == rhs.value();
3905 Uncopyable(
const Uncopyable&);
3910::std::ostream&
operator<<(::std::ostream& os,
const Uncopyable&
value) {
3911 return os <<
value.value();
3915bool IsPositiveUncopyable(
const Uncopyable&
x) {
3916 return x.value() > 0;
3920void TestAssertNonPositive() {
3925void TestAssertEqualsUncopyable() {
3932TEST(AssertionTest, AssertWorksWithUncopyableObject) {
3937 "IsPositiveUncopyable(y) evaluates to false, where\ny evaluates to -1");
3939 "Expected equality of these values:\n"
3940 " x\n Which is: 5\n y\n Which is: -1");
3944TEST(AssertionTest, ExpectWorksWithUncopyableObject) {
3949 "IsPositiveUncopyable(y) evaluates to false, where\ny evaluates to -1");
3952 "Expected equality of these values:\n"
3953 " x\n Which is: 5\n y\n Which is: -1");
3961TEST(AssertionTest, NamedEnum) {
3969#if !defined(__SUNPRO_CC) && !defined(__HP_aCC)
4000 EXPECT_EQ(
static_cast<int>(kCaseA),
static_cast<int>(kCaseB));
4011 "(kCaseA) >= (kCaseB)");
4022# ifndef __BORLANDC__
4026 " kCaseB\n Which is: ");
4039static HRESULT UnexpectedHRESULTFailure() {
4040 return E_UNEXPECTED;
4043static HRESULT OkHRESULTSuccess() {
4047static HRESULT FalseHRESULTSuccess() {
4055TEST(HRESULTAssertionTest, EXPECT_HRESULT_SUCCEEDED) {
4056 EXPECT_HRESULT_SUCCEEDED(S_OK);
4057 EXPECT_HRESULT_SUCCEEDED(S_FALSE);
4060 "Expected: (UnexpectedHRESULTFailure()) succeeds.\n"
4061 " Actual: 0x8000FFFF");
4064TEST(HRESULTAssertionTest, ASSERT_HRESULT_SUCCEEDED) {
4065 ASSERT_HRESULT_SUCCEEDED(S_OK);
4066 ASSERT_HRESULT_SUCCEEDED(S_FALSE);
4069 "Expected: (UnexpectedHRESULTFailure()) succeeds.\n"
4070 " Actual: 0x8000FFFF");
4073TEST(HRESULTAssertionTest, EXPECT_HRESULT_FAILED) {
4074 EXPECT_HRESULT_FAILED(E_UNEXPECTED);
4077 "Expected: (OkHRESULTSuccess()) fails.\n"
4080 "Expected: (FalseHRESULTSuccess()) fails.\n"
4084TEST(HRESULTAssertionTest, ASSERT_HRESULT_FAILED) {
4085 ASSERT_HRESULT_FAILED(E_UNEXPECTED);
4087# ifndef __BORLANDC__
4091 "Expected: (OkHRESULTSuccess()) fails.\n"
4096 "Expected: (FalseHRESULTSuccess()) fails.\n"
4101TEST(HRESULTAssertionTest, Streaming) {
4102 EXPECT_HRESULT_SUCCEEDED(S_OK) <<
"unexpected failure";
4103 ASSERT_HRESULT_SUCCEEDED(S_OK) <<
"unexpected failure";
4104 EXPECT_HRESULT_FAILED(E_UNEXPECTED) <<
"unexpected failure";
4105 ASSERT_HRESULT_FAILED(E_UNEXPECTED) <<
"unexpected failure";
4108 EXPECT_HRESULT_SUCCEEDED(E_UNEXPECTED) <<
"expected failure",
4109 "expected failure");
4111# ifndef __BORLANDC__
4115 ASSERT_HRESULT_SUCCEEDED(E_UNEXPECTED) <<
"expected failure",
4116 "expected failure");
4120 EXPECT_HRESULT_FAILED(S_OK) <<
"expected failure",
4121 "expected failure");
4124 ASSERT_HRESULT_FAILED(S_OK) <<
"expected failure",
4125 "expected failure");
4132#pragma GCC diagnostic push
4133#pragma GCC diagnostic ignored "-Wdangling-else"
4134#pragma GCC diagnostic ignored "-Wempty-body"
4135#pragma GCC diagnostic ignored "-Wpragmas"
4138TEST(AssertionSyntaxTest, BasicAssertionsBehavesLikeSingleStatement) {
4140 ASSERT_TRUE(
false) <<
"This should never be executed; "
4141 "It's a compilation test only.";
4157#pragma GCC diagnostic pop
4160#if GTEST_HAS_EXCEPTIONS
4163TEST(ExpectThrowTest, DoesNotGenerateUnreachableCodeWarning) {
4175TEST(ExpectThrowTest, DoesNotGenerateDuplicateCatchClauseWarning) {
4181#pragma GCC diagnostic push
4182#pragma GCC diagnostic ignored "-Wdangling-else"
4183#pragma GCC diagnostic ignored "-Wempty-body"
4184#pragma GCC diagnostic ignored "-Wpragmas"
4186TEST(AssertionSyntaxTest, ExceptionAssertionsBehavesLikeSingleStatement) {
4212#pragma GCC diagnostic pop
4219#pragma GCC diagnostic push
4220#pragma GCC diagnostic ignored "-Wdangling-else"
4221#pragma GCC diagnostic ignored "-Wempty-body"
4222#pragma GCC diagnostic ignored "-Wpragmas"
4224TEST(AssertionSyntaxTest, NoFatalFailureAssertionsBehavesLikeSingleStatement) {
4227 <<
"It's a compilation test only.";
4247#pragma GCC diagnostic pop
4251TEST(AssertionSyntaxTest, WorksWithSwitch) {
4261 EXPECT_FALSE(
false) <<
"EXPECT_FALSE failed in switch case";
4268 ASSERT_EQ(1, 1) <<
"ASSERT_EQ failed in default switch handler";
4276#if GTEST_HAS_EXCEPTIONS
4278void ThrowAString() {
4279 throw "std::string";
4284TEST(AssertionSyntaxTest, WorksWithConst) {
4300 EXPECT_EQ(2, GetUnitTestImpl()->current_test_result()->total_part_count());
4304TEST(SuccessfulAssertionTest, EXPECT) {
4306 EXPECT_EQ(0, GetUnitTestImpl()->current_test_result()->total_part_count());
4310TEST(SuccessfulAssertionTest, EXPECT_STR) {
4312 EXPECT_EQ(0, GetUnitTestImpl()->current_test_result()->total_part_count());
4316TEST(SuccessfulAssertionTest, ASSERT) {
4318 EXPECT_EQ(0, GetUnitTestImpl()->current_test_result()->total_part_count());
4322TEST(SuccessfulAssertionTest, ASSERT_STR) {
4324 EXPECT_EQ(0, GetUnitTestImpl()->current_test_result()->total_part_count());
4333TEST(AssertionWithMessageTest, EXPECT) {
4334 EXPECT_EQ(1, 1) <<
"This should succeed.";
4336 "Expected failure #1");
4337 EXPECT_LE(1, 2) <<
"This should succeed.";
4339 "Expected failure #2.");
4340 EXPECT_GE(1, 0) <<
"This should succeed.";
4342 "Expected failure #3.");
4346 "Expected failure #4.");
4349 "Expected failure #5.");
4353 "Expected failure #6.");
4354 EXPECT_NEAR(1, 1.1, 0.2) <<
"This should succeed.";
4357TEST(AssertionWithMessageTest, ASSERT) {
4358 ASSERT_EQ(1, 1) <<
"This should succeed.";
4359 ASSERT_NE(1, 2) <<
"This should succeed.";
4360 ASSERT_LE(1, 2) <<
"This should succeed.";
4361 ASSERT_LT(1, 2) <<
"This should succeed.";
4362 ASSERT_GE(1, 0) <<
"This should succeed.";
4364 "Expected failure.");
4367TEST(AssertionWithMessageTest, ASSERT_STR) {
4372 "Expected failure.");
4375TEST(AssertionWithMessageTest, ASSERT_FLOATING) {
4386 ASSERT_FALSE(
true) <<
"Expected failure: " << 2 <<
" > " << 1
4387 <<
" evaluates to " <<
true;
4388 },
"Expected failure");
4392TEST(AssertionWithMessageTest,
FAIL) {
4399 SUCCEED() <<
"Success == " << 1;
4408 ASSERT_TRUE(
false) <<
static_cast<const char*
>(
nullptr)
4409 <<
static_cast<char*
>(
nullptr);
4416TEST(AssertionWithMessageTest, WideStringMessage) {
4418 EXPECT_TRUE(
false) << L
"This failure is expected.\x8119";
4419 },
"This failure is expected.");
4422 << L
"expected too.\x8120";
4423 },
"This failure is expected too.");
4431 "Intentional failure #1.");
4433 "Intentional failure #2.");
4444TEST(ExpectTest, ExpectTrueWithAssertionResult) {
4447 "Value of: ResultIsEven(3)\n"
4448 " Actual: false (3 is odd)\n"
4452 "Value of: ResultIsEvenNoExplanation(3)\n"
4453 " Actual: false (3 is odd)\n"
4462 "Intentional failure #1.");
4464 "Intentional failure #2.");
4474TEST(ExpectTest, ExpectFalseWithAssertionResult) {
4477 "Value of: ResultIsEven(2)\n"
4478 " Actual: true (2 is even)\n"
4482 "Value of: ResultIsEvenNoExplanation(2)\n"
4496 "Expected equality of these values:\n"
4507TEST(ExpectTest, EXPECT_EQ_Double) {
4517TEST(ExpectTest, EXPECT_EQ_NULL) {
4519 const char*
p =
nullptr;
4531TEST(ExpectTest, EXPECT_EQ_0) {
4547 "Expected: ('a') != ('a'), "
4548 "actual: 'a' (97, 0x61) vs 'a' (97, 0x61)");
4551 char*
const p0 =
nullptr;
4558 void* pv1 = (
void*)0x1234;
4559 char*
const p1 =
reinterpret_cast<char*
>(pv1);
4569 "Expected: (2) <= (0), actual: 2 vs 0");
4578 "Expected: (2) < (2), actual: 2 vs 2");
4588 "Expected: (2) >= (3), actual: 2 vs 3");
4597 "Expected: (2) > (2), actual: 2 vs 2");
4602#if GTEST_HAS_EXCEPTIONS
4608 "Expected: ThrowAnInteger() throws an exception of "
4609 "type bool.\n Actual: it throws a different type.");
4612 "Expected: ThrowRuntimeError(\"A description\") "
4613 "throws an exception of type std::logic_error.\n "
4614 "Actual: it throws " ERROR_DESC
" "
4615 "with description \"A description\".");
4618 "Expected: ThrowNothing() throws an exception of type bool.\n"
4619 " Actual: it throws nothing.");
4626 "Expected: ThrowAnInteger() doesn't throw an "
4627 "exception.\n Actual: it throws.");
4629 "Expected: ThrowRuntimeError(\"A description\") "
4630 "doesn't throw an exception.\n "
4631 "Actual: it throws " ERROR_DESC
" "
4632 "with description \"A description\".");
4640 "Expected: ThrowNothing() throws an exception.\n"
4641 " Actual: it doesn't.");
4647TEST(ExpectTest, ExpectPrecedence) {
4650 " true && false\n Which is: false");
4657TEST(StreamableToStringTest, Scalar) {
4662TEST(StreamableToStringTest, Pointer) {
4669TEST(StreamableToStringTest, NullPointer) {
4675TEST(StreamableToStringTest, CString) {
4680TEST(StreamableToStringTest, NullCString) {
4688TEST(StreamableTest,
string) {
4689 static const std::string str(
4690 "This failure message is a std::string, and is expected.");
4697TEST(StreamableTest, stringWithEmbeddedNUL) {
4698 static const char char_array_with_nul[] =
4699 "Here's a NUL\0 and some more string";
4700 static const std::string string_with_nul(char_array_with_nul,
4701 sizeof(char_array_with_nul)
4704 "Here's a NUL\\0 and some more string");
4708TEST(StreamableTest, NULChar) {
4710 FAIL() <<
"A NUL" <<
'\0' <<
" and some more string";
4711 },
"A NUL\\0 and some more string");
4715TEST(StreamableTest,
int) {
4725TEST(StreamableTest, NullCharPtr) {
4731TEST(StreamableTest, BasicIoManip) {
4733 FAIL() <<
"Line 1." << std::endl
4734 <<
"A NUL char " << std::ends << std::flush <<
" in line 2.";
4735 },
"Line 1.\nA NUL char \\0 in line 2.");
4740void AddFailureHelper(
bool* aborted) {
4748 bool aborted =
true;
4750 "Intentional failure.");
4774 "Intentional failure.");
4793 SUCCEED() <<
"Explicit success.";
4807 bool false_value =
false;
4809 },
" false_value\n Which is: false\n true");
4813TEST(EqAssertionTest, Int) {
4820TEST(EqAssertionTest, Time_T) {
4822 static_cast<time_t
>(0));
4824 static_cast<time_t
>(1234)),
4831 const char ch =
'b';
4833 " ch\n Which is: 'b'");
4835 " ch\n Which is: 'b'");
4839TEST(EqAssertionTest, WideChar) {
4843 "Expected equality of these values:\n"
4845 " Which is: L'\0' (0, 0x0)\n"
4847 " Which is: L'x' (120, 0x78)");
4849 static wchar_t wchar;
4855 " wchar\n Which is: L'");
4859TEST(EqAssertionTest, StdString) {
4862 ASSERT_EQ(
"Test", ::std::string(
"Test"));
4865 static const ::std::string str1(
"A * in the middle");
4866 static const ::std::string str2(str1);
4875 char*
const p1 =
const_cast<char*
>(
"foo");
4881 static ::std::string str3(str1);
4884 " str3\n Which is: \"A \\0 in the middle\"");
4887#if GTEST_HAS_STD_WSTRING
4890TEST(EqAssertionTest, StdWideString) {
4892 const ::std::wstring wstr1(L
"A * in the middle");
4893 const ::std::wstring wstr2(wstr1);
4898 const wchar_t kTestX8119[] = {
'T',
'e',
's',
't', 0x8119,
'\0' };
4899 EXPECT_EQ(::std::wstring(kTestX8119), kTestX8119);
4903 const wchar_t kTestX8120[] = {
'T',
'e',
's',
't', 0x8120,
'\0' };
4905 EXPECT_EQ(::std::wstring(kTestX8119), kTestX8120);
4910 ::std::wstring wstr3(wstr1);
4911 wstr3.at(2) = L
'\0';
4918 ASSERT_EQ(
const_cast<wchar_t*
>(L
"foo"), ::std::wstring(L
"bar"));
4925TEST(EqAssertionTest, CharPointer) {
4926 char*
const p0 =
nullptr;
4931 void* pv1 = (
void*)0x1234;
4932 void* pv2 = (
void*)0xABC0;
4933 char*
const p1 =
reinterpret_cast<char*
>(pv1);
4934 char*
const p2 =
reinterpret_cast<char*
>(pv2);
4942 reinterpret_cast<char*
>(0xABC0)),
4947TEST(EqAssertionTest, WideCharPointer) {
4948 wchar_t*
const p0 =
nullptr;
4953 void* pv1 = (
void*)0x1234;
4954 void* pv2 = (
void*)0xABC0;
4955 wchar_t*
const p1 =
reinterpret_cast<wchar_t*
>(pv1);
4956 wchar_t*
const p2 =
reinterpret_cast<wchar_t*
>(pv2);
4963 void* pv3 = (
void*)0x1234;
4964 void* pv4 = (
void*)0xABC0;
4965 const wchar_t* p3 =
reinterpret_cast<const wchar_t*
>(pv3);
4966 const wchar_t* p4 =
reinterpret_cast<const wchar_t*
>(pv4);
4972TEST(EqAssertionTest, OtherPointer) {
4973 ASSERT_EQ(
static_cast<const int*
>(
nullptr),
static_cast<const int*
>(
nullptr));
4975 reinterpret_cast<const int*
>(0x1234)),
4980class UnprintableChar {
4982 explicit UnprintableChar(
char ch) : char_(
ch) {}
4984 bool operator==(
const UnprintableChar& rhs)
const {
4985 return char_ == rhs.char_;
4987 bool operator!=(
const UnprintableChar& rhs)
const {
4988 return char_ != rhs.char_;
4990 bool operator<(
const UnprintableChar& rhs)
const {
4991 return char_ < rhs.char_;
4993 bool operator<=(
const UnprintableChar& rhs)
const {
4994 return char_ <= rhs.char_;
4996 bool operator>(
const UnprintableChar& rhs)
const {
4997 return char_ > rhs.char_;
4999 bool operator>=(
const UnprintableChar& rhs)
const {
5000 return char_ >= rhs.char_;
5009TEST(ComparisonAssertionTest, AcceptsUnprintableArgs) {
5010 const UnprintableChar
x(
'x'),
y(
'y');
5029 "1-byte object <78>");
5031 "1-byte object <78>");
5034 "1-byte object <79>");
5036 "1-byte object <78>");
5038 "1-byte object <79>");
5050 int Bar()
const {
return 1; }
5065class FRIEND_TEST_Test2 :
public Test {
5082class TestLifeCycleTest :
public Test {
5086 TestLifeCycleTest() { count_++; }
5090 ~TestLifeCycleTest()
override { count_--; }
5093 int count()
const {
return count_; }
5099int TestLifeCycleTest::count_ = 0;
5102TEST_F(TestLifeCycleTest, Test1) {
5109TEST_F(TestLifeCycleTest, Test2) {
5120TEST(AssertionResultTest, CopyConstructorWorksWhenNotOptimied) {
5124 AssertionResult r2 = r1;
5129 AssertionResult r3 = r1;
5130 EXPECT_EQ(
static_cast<bool>(r3),
static_cast<bool>(r1));
5136TEST(AssertionResultTest, ConstructionWorks) {
5159TEST(AssertionResultTest, NegationWorks) {
5169TEST(AssertionResultTest, StreamingWorks) {
5171 r <<
"abc" <<
'd' << 0 <<
true;
5175TEST(AssertionResultTest, CanStreamOstreamManipulators) {
5177 r <<
"Data" << std::endl << std::flush << std::ends <<
"Will be visible";
5183TEST(AssertionResultTest, ConstructibleFromContextuallyConvertibleToBool) {
5184 struct ExplicitlyConvertibleToBool {
5185 explicit operator bool()
const {
return value; }
5188 ExplicitlyConvertibleToBool v1 = {
false};
5189 ExplicitlyConvertibleToBool v2 = {
true};
5195 operator AssertionResult()
const {
return AssertionResult(
true); }
5198TEST(AssertionResultTest, ConstructibleFromImplicitlyConvertible) {
5207 explicit Base(
int an_x) : x_(an_x) {}
5208 int x()
const {
return x_; }
5214 return os << val.x();
5217 const Base* pointer) {
5218 return os <<
"(" << pointer->x() <<
")";
5221TEST(MessageTest, CanStreamUserTypeInGlobalNameSpace) {
5232class MyTypeInUnnamedNameSpace :
public Base {
5234 explicit MyTypeInUnnamedNameSpace(
int an_x): Base(an_x) {}
5237 const MyTypeInUnnamedNameSpace& val) {
5238 return os << val.x();
5241 const MyTypeInUnnamedNameSpace* pointer) {
5242 return os <<
"(" << pointer->x() <<
")";
5246TEST(MessageTest, CanStreamUserTypeInUnnamedNameSpace) {
5248 MyTypeInUnnamedNameSpace a(1);
5263 return os << val.x();
5267 return os <<
"(" << pointer->x() <<
")";
5271TEST(MessageTest, CanStreamUserTypeInUserNameSpace) {
5289 return os << val.x();
5293 return os <<
"(" << pointer->x() <<
")";
5296TEST(MessageTest, CanStreamUserTypeInUserNameSpaceWithStreamOperatorInGlobal) {
5307 char*
const p1 =
nullptr;
5308 unsigned char*
const p2 =
nullptr;
5310 double* p4 =
nullptr;
5314 msg << p1 << p2 << p3 << p4 << p5 << p6;
5322 const wchar_t* const_wstr =
nullptr;
5324 (
Message() << const_wstr).GetString().c_str());
5327 wchar_t* wstr =
nullptr;
5329 (
Message() << wstr).GetString().c_str());
5332 const_wstr = L
"abc\x8119";
5334 (
Message() << const_wstr).GetString().c_str());
5337 wstr =
const_cast<wchar_t*
>(const_wstr);
5339 (
Message() << wstr).GetString().c_str());
5352 GetUnitTestImpl()->GetTestSuite(
"TestInfoTest",
"",
nullptr,
nullptr);
5356 if (strcmp(test_name, test_info->
name()) == 0)
5364 return test_info->
result();
5370 const TestInfo*
const test_info = GetTestInfo(
"Names");
5378 const TestInfo*
const test_info = GetTestInfo(
"result");
5381 ASSERT_EQ(0, GetTestResult(test_info)->total_part_count());
5384 ASSERT_EQ(0, GetTestResult(test_info)->total_part_count());
5387#define VERIFY_CODE_LOCATION \
5388 const int expected_line = __LINE__ - 1; \
5389 const TestInfo* const test_info = GetUnitTestImpl()->current_test_info(); \
5390 ASSERT_TRUE(test_info); \
5391 EXPECT_STREQ(__FILE__, test_info->file()); \
5392 EXPECT_EQ(expected_line, test_info->line())
5414template <
typename T>
5424template <
typename T>
5438#undef VERIFY_CODE_LOCATION
5442#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
5448 printf(
"Setting up the test case . . .\n");
5465 printf(
"Tearing down the test case . . .\n");
5509 printf(
"Setting up the test suite . . .\n");
5526 printf(
"Tearing down the test suite . . .\n");
5755 GTEST_FLAG(stack_trace_depth) = kMaxStackTraceDepth;
5761 template <
typename CharType>
5763 CharType** array2) {
5764 ASSERT_EQ(size1, size2) <<
" Array sizes different.";
5766 for (
int i = 0;
i != size1;
i++) {
5796 template <
typename CharType>
5798 int argc2,
const CharType** argv2,
5799 const Flags& expected,
bool should_print_help) {
5803# if GTEST_HAS_STREAM_REDIRECTION
5810# if GTEST_HAS_STREAM_REDIRECTION
5825# if GTEST_HAS_STREAM_REDIRECTION
5826 const char*
const expected_help_fragment =
5827 "This program contains tests written using";
5828 if (should_print_help) {
5832 expected_help_fragment, captured_stdout);
5842# define GTEST_TEST_PARSING_FLAGS_(argv1, argv2, expected, should_print_help) \
5843 TestParsingFlags(sizeof(argv1)/sizeof(*argv1) - 1, argv1, \
5844 sizeof(argv2)/sizeof(*argv2) - 1, argv2, \
5845 expected, should_print_help)
5850 const char* argv[] = {
nullptr};
5852 const char* argv2[] = {
nullptr};
5859 const char* argv[] = {
"foo.exe",
nullptr};
5861 const char* argv2[] = {
"foo.exe",
nullptr};
5868 const char* argv[] = {
"foo.exe",
"--gtest_fail_fast",
nullptr};
5870 const char* argv2[] = {
"foo.exe",
nullptr};
5877 const char* argv[] = {
"foo.exe",
"--gtest_filter",
nullptr};
5879 const char* argv2[] = {
"foo.exe",
"--gtest_filter",
nullptr};
5886 const char* argv[] = {
"foo.exe",
"--gtest_filter=",
nullptr};
5888 const char* argv2[] = {
"foo.exe",
nullptr};
5895 const char* argv[] = {
"foo.exe",
"--gtest_filter=abc",
nullptr};
5897 const char* argv2[] = {
"foo.exe",
nullptr};
5904 const char* argv[] = {
"foo.exe",
"--gtest_break_on_failure",
nullptr};
5906 const char* argv2[] = {
"foo.exe",
nullptr};
5913 const char* argv[] = {
"foo.exe",
"--gtest_break_on_failure=0",
nullptr};
5915 const char* argv2[] = {
"foo.exe",
nullptr};
5922 const char* argv[] = {
"foo.exe",
"--gtest_break_on_failure=f",
nullptr};
5924 const char* argv2[] = {
"foo.exe",
nullptr};
5931 const char* argv[] = {
"foo.exe",
"--gtest_break_on_failure=F",
nullptr};
5933 const char* argv2[] = {
"foo.exe",
nullptr};
5941 const char* argv[] = {
"foo.exe",
"--gtest_break_on_failure=1",
nullptr};
5943 const char* argv2[] = {
"foo.exe",
nullptr};
5950 const char* argv[] = {
"foo.exe",
"--gtest_catch_exceptions",
nullptr};
5952 const char* argv2[] = {
"foo.exe",
nullptr};
5959 const char* argv[] = {
"foo.exe",
"--gtest_death_test_use_fork",
nullptr};
5961 const char* argv2[] = {
"foo.exe",
nullptr};
5969 const char* argv[] = {
"foo.exe",
"--gtest_filter=a",
"--gtest_filter=b",
5972 const char* argv2[] = {
"foo.exe",
nullptr};
5979 const char* argv[] = {
"foo.exe",
"--gtest_break_on_failure",
5981 "--gtest_filter=b",
nullptr};
5983 const char* argv2[] = {
"foo.exe",
"bar",
nullptr};
5993 const char* argv[] = {
"foo.exe",
"--gtest_list_tests",
nullptr};
5995 const char* argv2[] = {
"foo.exe",
nullptr};
6002 const char* argv[] = {
"foo.exe",
"--gtest_list_tests=1",
nullptr};
6004 const char* argv2[] = {
"foo.exe",
nullptr};
6011 const char* argv[] = {
"foo.exe",
"--gtest_list_tests=0",
nullptr};
6013 const char* argv2[] = {
"foo.exe",
nullptr};
6020 const char* argv[] = {
"foo.exe",
"--gtest_list_tests=f",
nullptr};
6022 const char* argv2[] = {
"foo.exe",
nullptr};
6029 const char* argv[] = {
"foo.exe",
"--gtest_list_tests=F",
nullptr};
6031 const char* argv2[] = {
"foo.exe",
nullptr};
6038 const char* argv[] = {
"foo.exe",
"--gtest_output",
nullptr};
6040 const char* argv2[] = {
"foo.exe",
"--gtest_output",
nullptr};
6047 const char* argv[] = {
"foo.exe",
"--gtest_output=xml",
nullptr};
6049 const char* argv2[] = {
"foo.exe",
nullptr};
6056 const char* argv[] = {
"foo.exe",
"--gtest_output=xml:file",
nullptr};
6058 const char* argv2[] = {
"foo.exe",
nullptr};
6065 const char* argv[] = {
"foo.exe",
"--gtest_output=xml:directory/path/",
6068 const char* argv2[] = {
"foo.exe",
nullptr};
6076 const char* argv[] = {
"foo.exe",
"--gtest_brief",
nullptr};
6078 const char* argv2[] = {
"foo.exe",
nullptr};
6085 const char* argv[] = {
"foo.exe",
"--gtest_brief=1",
nullptr};
6087 const char* argv2[] = {
"foo.exe",
nullptr};
6094 const char* argv[] = {
"foo.exe",
"--gtest_brief=0",
nullptr};
6096 const char* argv2[] = {
"foo.exe",
nullptr};
6103 const char* argv[] = {
"foo.exe",
"--gtest_print_time",
nullptr};
6105 const char* argv2[] = {
"foo.exe",
nullptr};
6112 const char* argv[] = {
"foo.exe",
"--gtest_print_time=1",
nullptr};
6114 const char* argv2[] = {
"foo.exe",
nullptr};
6121 const char* argv[] = {
"foo.exe",
"--gtest_print_time=0",
nullptr};
6123 const char* argv2[] = {
"foo.exe",
nullptr};
6130 const char* argv[] = {
"foo.exe",
"--gtest_print_time=f",
nullptr};
6132 const char* argv2[] = {
"foo.exe",
nullptr};
6139 const char* argv[] = {
"foo.exe",
"--gtest_print_time=F",
nullptr};
6141 const char* argv2[] = {
"foo.exe",
nullptr};
6148 const char* argv[] = {
"foo.exe",
"--gtest_random_seed=1000",
nullptr};
6150 const char* argv2[] = {
"foo.exe",
nullptr};
6157 const char* argv[] = {
"foo.exe",
"--gtest_repeat=1000",
nullptr};
6159 const char* argv2[] = {
"foo.exe",
nullptr};
6166 const char* argv[] = {
"foo.exe",
"--gtest_also_run_disabled_tests",
nullptr};
6168 const char* argv2[] = {
"foo.exe",
nullptr};
6176 const char* argv[] = {
"foo.exe",
"--gtest_also_run_disabled_tests=1",
6179 const char* argv2[] = {
"foo.exe",
nullptr};
6187 const char* argv[] = {
"foo.exe",
"--gtest_also_run_disabled_tests=0",
6190 const char* argv2[] = {
"foo.exe",
nullptr};
6198 const char* argv[] = {
"foo.exe",
"--gtest_shuffle",
nullptr};
6200 const char* argv2[] = {
"foo.exe",
nullptr};
6207 const char* argv[] = {
"foo.exe",
"--gtest_shuffle=0",
nullptr};
6209 const char* argv2[] = {
"foo.exe",
nullptr};
6216 const char* argv[] = {
"foo.exe",
"--gtest_shuffle=1",
nullptr};
6218 const char* argv2[] = {
"foo.exe",
nullptr};
6225 const char* argv[] = {
"foo.exe",
"--gtest_stack_trace_depth=5",
nullptr};
6227 const char* argv2[] = {
"foo.exe",
nullptr};
6233 const char* argv[] = {
"foo.exe",
"--gtest_stream_result_to=localhost:1234",
6236 const char* argv2[] = {
"foo.exe",
nullptr};
6244 const char* argv[] = {
"foo.exe",
"--gtest_throw_on_failure",
nullptr};
6246 const char* argv2[] = {
"foo.exe",
nullptr};
6253 const char* argv[] = {
"foo.exe",
"--gtest_throw_on_failure=0",
nullptr};
6255 const char* argv2[] = {
"foo.exe",
nullptr};
6263 const char* argv[] = {
"foo.exe",
"--gtest_throw_on_failure=1",
nullptr};
6265 const char* argv2[] = {
"foo.exe",
nullptr};
6270# if GTEST_OS_WINDOWS
6272TEST_F(ParseFlagsTest, WideStrings) {
6273 const wchar_t* argv[] = {
6275 L
"--gtest_filter=Foo*",
6276 L
"--gtest_list_tests=1",
6277 L
"--gtest_break_on_failure",
6278 L
"--non_gtest_flag",
6282 const wchar_t* argv2[] = {
6284 L
"--non_gtest_flag",
6288 Flags expected_flags;
6289 expected_flags.break_on_failure =
true;
6290 expected_flags.filter =
"Foo*";
6291 expected_flags.list_tests =
true;
6297#if GTEST_USE_OWN_FLAGFILE_FLAG_
6298class FlagfileTest :
public ParseFlagsTest {
6300 void SetUp()
override {
6310 void TearDown()
override {
6315 internal::FilePath CreateFlagfile(
const char* contents) {
6316 internal::FilePath file_path(internal::FilePath::GenerateUniqueFileName(
6319 fprintf(f,
"%s", contents);
6329TEST_F(FlagfileTest, Empty) {
6330 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};
6342TEST_F(FlagfileTest, FilterNonEmpty) {
6343 internal::FilePath flagfile_path(CreateFlagfile(
6345 std::string flagfile_flag =
6348 const char* argv[] = {
"foo.exe", flagfile_flag.c_str(),
nullptr};
6350 const char* argv2[] = {
"foo.exe",
nullptr};
6356TEST_F(FlagfileTest, SeveralFlags) {
6357 internal::FilePath flagfile_path(CreateFlagfile(
6361 std::string flagfile_flag =
6364 const char* argv[] = {
"foo.exe", flagfile_flag.c_str(),
nullptr};
6366 const char* argv2[] = {
"foo.exe",
nullptr};
6368 Flags expected_flags;
6369 expected_flags.break_on_failure =
true;
6370 expected_flags.filter =
"abc";
6371 expected_flags.list_tests =
true;
6387 <<
"There should be no tests running at this point.";
6396 <<
"There should be no tests running at this point.";
6406 <<
"There is a test running so we should have a valid TestInfo.";
6408 <<
"Expected the name of the currently running test suite.";
6410 <<
"Expected the name of the currently running test.";
6421 <<
"There is a test running so we should have a valid TestInfo.";
6423 <<
"Expected the name of the currently running test suite.";
6425 <<
"Expected the name of the currently running test.";
6450TEST(NestedTestingNamespaceTest, Success) {
6451 EXPECT_EQ(1, 1) <<
"This shouldn't fail.";
6455TEST(NestedTestingNamespaceTest, Failure) {
6457 "This failure is expected.");
6469 void SetUp()
override { Test::SetUp(); }
6475TEST(StreamingAssertionsTest, Unconditional) {
6476 SUCCEED() <<
"expected success";
6478 "expected failure");
6480 "expected failure");
6485# pragma option push -w-ccc -w-rch
6488TEST(StreamingAssertionsTest, Truth) {
6492 "expected failure");
6494 "expected failure");
6497TEST(StreamingAssertionsTest, Truth2) {
6501 "expected failure");
6503 "expected failure");
6511TEST(StreamingAssertionsTest, IntegerEquals) {
6512 EXPECT_EQ(1, 1) <<
"unexpected failure";
6513 ASSERT_EQ(1, 1) <<
"unexpected failure";
6515 "expected failure");
6517 "expected failure");
6520TEST(StreamingAssertionsTest, IntegerLessThan) {
6521 EXPECT_LT(1, 2) <<
"unexpected failure";
6522 ASSERT_LT(1, 2) <<
"unexpected failure";
6524 "expected failure");
6526 "expected failure");
6529TEST(StreamingAssertionsTest, StringsEqual) {
6533 "expected failure");
6535 "expected failure");
6538TEST(StreamingAssertionsTest, StringsNotEqual) {
6542 "expected failure");
6544 "expected failure");
6547TEST(StreamingAssertionsTest, StringsEqualIgnoringCase) {
6551 "expected failure");
6553 "expected failure");
6556TEST(StreamingAssertionsTest, StringNotEqualIgnoringCase) {
6560 "expected failure");
6562 "expected failure");
6565TEST(StreamingAssertionsTest, FloatingPointEquals) {
6569 "expected failure");
6571 "expected failure");
6574#if GTEST_HAS_EXCEPTIONS
6576TEST(StreamingAssertionsTest, Throw) {
6577 EXPECT_THROW(ThrowAnInteger(),
int) <<
"unexpected failure";
6578 ASSERT_THROW(ThrowAnInteger(),
int) <<
"unexpected failure";
6580 "expected failure",
"expected failure");
6582 "expected failure",
"expected failure");
6585TEST(StreamingAssertionsTest, NoThrow) {
6589 "expected failure",
"expected failure");
6591 "expected failure",
"expected failure");
6594TEST(StreamingAssertionsTest, AnyThrow) {
6598 "expected failure",
"expected failure");
6600 "expected failure",
"expected failure");
6607TEST(ColoredOutputTest, UsesColorsWhenGTestColorFlagIsYes) {
6610 SetEnv(
"TERM",
"xterm");
6614 SetEnv(
"TERM",
"dumb");
6619TEST(ColoredOutputTest, UsesColorsWhenGTestColorFlagIsAliasOfYes) {
6620 SetEnv(
"TERM",
"dumb");
6632TEST(ColoredOutputTest, UsesNoColorWhenGTestColorFlagIsNo) {
6635 SetEnv(
"TERM",
"xterm");
6639 SetEnv(
"TERM",
"dumb");
6644TEST(ColoredOutputTest, UsesNoColorWhenGTestColorFlagIsInvalid) {
6645 SetEnv(
"TERM",
"xterm");
6657TEST(ColoredOutputTest, UsesColorsWhenStdoutIsTty) {
6660 SetEnv(
"TERM",
"xterm");
6665TEST(ColoredOutputTest, UsesColorsWhenTermSupportsColors) {
6668#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW
6671 SetEnv(
"TERM",
"dumb");
6677 SetEnv(
"TERM",
"xterm");
6683 SetEnv(
"TERM",
"dumb");
6686 SetEnv(
"TERM",
"emacs");
6689 SetEnv(
"TERM",
"vt100");
6692 SetEnv(
"TERM",
"xterm-mono");
6695 SetEnv(
"TERM",
"xterm");
6698 SetEnv(
"TERM",
"xterm-color");
6701 SetEnv(
"TERM",
"xterm-256color");
6704 SetEnv(
"TERM",
"screen");
6707 SetEnv(
"TERM",
"screen-256color");
6710 SetEnv(
"TERM",
"tmux");
6713 SetEnv(
"TERM",
"tmux-256color");
6716 SetEnv(
"TERM",
"rxvt-unicode");
6719 SetEnv(
"TERM",
"rxvt-unicode-256color");
6722 SetEnv(
"TERM",
"linux");
6725 SetEnv(
"TERM",
"cygwin");
6734 StaticAssertTypeEq<const int, const int>();
6738template <
typename T>
6744TEST(StaticAssertTypeEqTest, WorksInClass) {
6752TEST(StaticAssertTypeEqTest, CompilesForEqualTypes) {
6753 StaticAssertTypeEq<int, IntAlias>();
6754 StaticAssertTypeEq<int*, IntAlias*>();
6757TEST(HasNonfatalFailureTest, ReturnsFalseWhenThereIsNoFailure) {
6761static void FailFatally() {
FAIL(); }
6763TEST(HasNonfatalFailureTest, ReturnsFalseWhenThereIsOnlyFatalFailure) {
6765 const bool has_nonfatal_failure = HasNonfatalFailure();
6766 ClearCurrentTestPartResults();
6770TEST(HasNonfatalFailureTest, ReturnsTrueWhenThereIsNonfatalFailure) {
6772 const bool has_nonfatal_failure = HasNonfatalFailure();
6773 ClearCurrentTestPartResults();
6777TEST(HasNonfatalFailureTest, ReturnsTrueWhenThereAreFatalAndNonfatalFailures) {
6780 const bool has_nonfatal_failure = HasNonfatalFailure();
6781 ClearCurrentTestPartResults();
6786static bool HasNonfatalFailureHelper() {
6790TEST(HasNonfatalFailureTest, WorksOutsideOfTestBody) {
6794TEST(HasNonfatalFailureTest, WorksOutsideOfTestBody2) {
6796 const bool has_nonfatal_failure = HasNonfatalFailureHelper();
6797 ClearCurrentTestPartResults();
6801TEST(HasFailureTest, ReturnsFalseWhenThereIsNoFailure) {
6805TEST(HasFailureTest, ReturnsTrueWhenThereIsFatalFailure) {
6807 const bool has_failure = HasFailure();
6808 ClearCurrentTestPartResults();
6812TEST(HasFailureTest, ReturnsTrueWhenThereIsNonfatalFailure) {
6814 const bool has_failure = HasFailure();
6815 ClearCurrentTestPartResults();
6819TEST(HasFailureTest, ReturnsTrueWhenThereAreFatalAndNonfatalFailures) {
6822 const bool has_failure = HasFailure();
6823 ClearCurrentTestPartResults();
6830TEST(HasFailureTest, WorksOutsideOfTestBody) {
6834TEST(HasFailureTest, WorksOutsideOfTestBody2) {
6836 const bool has_failure = HasFailureHelper();
6837 ClearCurrentTestPartResults();
6845 : on_start_counter_(on_start_counter),
6846 is_destroyed_(is_destroyed) {}
6850 *is_destroyed_ =
true;
6855 if (on_start_counter_ !=
nullptr) (*on_start_counter_)++;
6859 int* on_start_counter_;
6860 bool* is_destroyed_;
6864TEST(TestEventListenersTest, ConstructionWorks) {
6867 EXPECT_TRUE(TestEventListenersAccessor::GetRepeater(&listeners) !=
nullptr);
6874TEST(TestEventListenersTest, DestructionWorks) {
6875 bool default_result_printer_is_destroyed =
false;
6876 bool default_xml_printer_is_destroyed =
false;
6877 bool extra_listener_is_destroyed =
false;
6879 new TestListener(
nullptr, &default_result_printer_is_destroyed);
6881 new TestListener(
nullptr, &default_xml_printer_is_destroyed);
6883 new TestListener(
nullptr, &extra_listener_is_destroyed);
6887 TestEventListenersAccessor::SetDefaultResultPrinter(&listeners,
6888 default_result_printer);
6889 TestEventListenersAccessor::SetDefaultXmlGenerator(&listeners,
6890 default_xml_printer);
6891 listeners.
Append(extra_listener);
6900TEST(TestEventListenersTest, Append) {
6901 int on_start_counter = 0;
6902 bool is_destroyed =
false;
6906 listeners.
Append(listener);
6907 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
6908 *UnitTest::GetInstance());
6920 : vector_(vector), id_(id) {}
6924 vector_->push_back(GetEventDescription(
"OnTestProgramStart"));
6928 vector_->push_back(GetEventDescription(
"OnTestProgramEnd"));
6933 vector_->push_back(GetEventDescription(
"OnTestIterationStart"));
6938 vector_->push_back(GetEventDescription(
"OnTestIterationEnd"));
6942 std::string GetEventDescription(
const char* method) {
6944 message << id_ <<
"." << method;
6948 std::vector<std::string>* vector_;
6949 const char*
const id_;
6954TEST(EventListenerTest, AppendKeepsOrder) {
6955 std::vector<std::string> vec;
6961 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
6962 *UnitTest::GetInstance());
6964 EXPECT_STREQ(
"1st.OnTestProgramStart", vec[0].c_str());
6965 EXPECT_STREQ(
"2nd.OnTestProgramStart", vec[1].c_str());
6966 EXPECT_STREQ(
"3rd.OnTestProgramStart", vec[2].c_str());
6969 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramEnd(
6970 *UnitTest::GetInstance());
6977 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestIterationStart(
6978 *UnitTest::GetInstance(), 0);
6980 EXPECT_STREQ(
"1st.OnTestIterationStart", vec[0].c_str());
6981 EXPECT_STREQ(
"2nd.OnTestIterationStart", vec[1].c_str());
6982 EXPECT_STREQ(
"3rd.OnTestIterationStart", vec[2].c_str());
6985 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestIterationEnd(
6986 *UnitTest::GetInstance(), 0);
6988 EXPECT_STREQ(
"3rd.OnTestIterationEnd", vec[0].c_str());
6989 EXPECT_STREQ(
"2nd.OnTestIterationEnd", vec[1].c_str());
6990 EXPECT_STREQ(
"1st.OnTestIterationEnd", vec[2].c_str());
6995TEST(TestEventListenersTest, Release) {
6996 int on_start_counter = 0;
6997 bool is_destroyed =
false;
7004 listeners.
Append(listener);
7006 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
7007 *UnitTest::GetInstance());
7016TEST(EventListenerTest, SuppressEventForwarding) {
7017 int on_start_counter = 0;
7021 listeners.
Append(listener);
7022 ASSERT_TRUE(TestEventListenersAccessor::EventForwardingEnabled(listeners));
7023 TestEventListenersAccessor::SuppressEventForwarding(&listeners);
7024 ASSERT_FALSE(TestEventListenersAccessor::EventForwardingEnabled(listeners));
7025 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
7026 *UnitTest::GetInstance());
7032TEST(EventListenerDeathTest, EventsNotForwardedInDeathTestSubprecesses) {
7034 GTEST_CHECK_(TestEventListenersAccessor::EventForwardingEnabled(
7035 *GetUnitTestImpl()->listeners())) <<
"expected failure";},
7036 "expected failure");
7042TEST(EventListenerTest, default_result_printer) {
7043 int on_start_counter = 0;
7044 bool is_destroyed =
false;
7048 TestEventListenersAccessor::SetDefaultResultPrinter(&listeners, listener);
7052 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
7053 *UnitTest::GetInstance());
7059 TestEventListenersAccessor::SetDefaultResultPrinter(&listeners,
nullptr);
7066 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
7067 *UnitTest::GetInstance());
7073TEST(EventListenerTest, RemovingDefaultResultPrinterWorks) {
7074 int on_start_counter = 0;
7075 bool is_destroyed =
false;
7082 TestEventListenersAccessor::SetDefaultResultPrinter(&listeners, listener);
7089 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
7090 *UnitTest::GetInstance());
7101TEST(EventListenerTest, default_xml_generator) {
7102 int on_start_counter = 0;
7103 bool is_destroyed =
false;
7107 TestEventListenersAccessor::SetDefaultXmlGenerator(&listeners, listener);
7111 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
7112 *UnitTest::GetInstance());
7118 TestEventListenersAccessor::SetDefaultXmlGenerator(&listeners,
nullptr);
7125 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
7126 *UnitTest::GetInstance());
7132TEST(EventListenerTest, RemovingDefaultXmlGeneratorWorks) {
7133 int on_start_counter = 0;
7134 bool is_destroyed =
false;
7141 TestEventListenersAccessor::SetDefaultXmlGenerator(&listeners, listener);
7148 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
7149 *UnitTest::GetInstance());
7167 "An expected failure");
7173 "An expected failure");
7175 "An expected failure");
7180 "An expected failure");
7185 "An expected failure");
7189 "An expected failure");
7191 "An expected failure");
7196 "An expected failure");
7200 "An expected failure");
7202 "An expected failure");
7232struct IncompleteType;
7236TEST(HasDebugStringAndShortDebugStringTest, ValueIsCompileTimeConstant) {
7263TEST(HasDebugStringAndShortDebugStringTest,
7264 ValueIsTrueWhenTypeHasDebugStringAndShortDebugString) {
7271TEST(HasDebugStringAndShortDebugStringTest,
7272 ValueIsFalseWhenTypeIsNotAProtocolMessage) {
7280template <
typename T1,
typename T2>
7283 "GTEST_REMOVE_REFERENCE_AND_CONST_ failed.");
7286TEST(RemoveReferenceToConstTest, Works) {
7287 TestGTestRemoveReferenceAndConst<int, int>();
7288 TestGTestRemoveReferenceAndConst<double, double&>();
7289 TestGTestRemoveReferenceAndConst<char, const char>();
7290 TestGTestRemoveReferenceAndConst<char, const char&>();
7291 TestGTestRemoveReferenceAndConst<const char*, const char*>();
7296template <
typename T1,
typename T2>
7299 "GTEST_REFERENCE_TO_CONST_ failed.");
7302TEST(GTestReferenceToConstTest, Works) {
7303 TestGTestReferenceToConst<const char&, char>();
7304 TestGTestReferenceToConst<const int&, const int>();
7305 TestGTestReferenceToConst<const double&, double>();
7306 TestGTestReferenceToConst<const std::string&, const std::string&>();
7314TEST(IsContainerTestTest, WorksForNonContainer) {
7320TEST(IsContainerTestTest, WorksForContainer) {
7342TEST(IsContainerTestTest, ConstOnlyContainer) {
7344 sizeof(IsContainerTest<ConstOnlyContainerWithPointerIterator>(0)));
7346 sizeof(IsContainerTest<ConstOnlyContainerWithClassIterator>(0)));
7366TEST(ArrayEqTest, WorksForDegeneratedArrays) {
7371TEST(ArrayEqTest, WorksForOneDimensionalArrays) {
7373 const int a[] = { 0, 1 };
7374 long b[] = { 0, 1 };
7383TEST(ArrayEqTest, WorksForTwoDimensionalArrays) {
7384 const char a[][3] = {
"hi",
"lo" };
7385 const char b[][3] = {
"hi",
"lo" };
7386 const char c[][3] = {
"hi",
"li" };
7397TEST(ArrayAwareFindTest, WorksForOneDimensionalArray) {
7398 const char a[] =
"hello";
7403TEST(ArrayAwareFindTest, WorksForTwoDimensionalArray) {
7404 int a[][2] = { { 0, 1 }, { 2, 3 }, { 4, 5 } };
7405 const int b[2] = { 2, 3 };
7408 const int c[2] = { 6, 7 };
7414TEST(CopyArrayTest, WorksForDegeneratedArrays) {
7420TEST(CopyArrayTest, WorksForOneDimensionalArrays) {
7421 const char a[3] =
"hi";
7433TEST(CopyArrayTest, WorksForTwoDimensionalArrays) {
7434 const int a[2][3] = { { 0, 1, 2 }, { 3, 4, 5 } };
7448TEST(NativeArrayTest, ConstructorFromArrayWorks) {
7449 const int a[3] = { 0, 1, 2 };
7455TEST(NativeArrayTest, CreatesAndDeletesCopyOfArrayWhenAskedTo) {
7456 typedef int Array[2];
7457 Array* a =
new Array[1];
7470TEST(NativeArrayTest, TypeMembersAreCorrect) {
7471 StaticAssertTypeEq<char, NativeArray<char>::value_type>();
7472 StaticAssertTypeEq<int[2], NativeArray<int[2]>::value_type>();
7474 StaticAssertTypeEq<const char*, NativeArray<char>::const_iterator>();
7478TEST(NativeArrayTest, MethodsWork) {
7479 const int a[3] = { 0, 1, 2 };
7498 const int b1[3] = { 0, 1, 1 };
7499 const int b2[4] = { 0, 1, 2, 3 };
7504TEST(NativeArrayTest, WorksForTwoDimensionalArray) {
7505 const char a[2][3] = {
"hi",
"lo" };
7524 (std::is_base_of<IndexSequence<0, 1, 2>, MakeIndexSequence<3>>
::value));
7537 std::is_same<
char, ElemFromList<7,
int,
int,
int,
int,
int,
int,
int,
7545 FlatTuple<int, double, const char*> tuple = {};
7550 tuple = FlatTuple<int, double, const char*>(
7554 EXPECT_EQ(std::string(
"Foo"), tuple.Get<2>());
7556 tuple.Get<1>() = 5.1;
7561std::string AddIntToString(
int i,
const std::string& s) {
7562 return s + std::to_string(
i);
7573 EXPECT_TRUE(tuple.Apply([](
int i,
const std::string& s) ->
bool {
7574 return i == static_cast<int>(s.size());
7578 EXPECT_EQ(tuple.Apply(AddIntToString),
"Hello5");
7581 tuple.Apply([](
int&
i, std::string& s) {
7586 EXPECT_EQ(tuple.Get<1>(),
"HelloHello");
7632 { FlatTuple<ConstructionCounting> tuple; }
7644 FlatTuple<ConstructionCounting> tuple{
7657 FlatTuple<ConstructionCounting> tuple{
7672 FlatTuple<ConstructionCounting> tuple;
7674 tuple.Get<0>() = elem;
7688 FlatTuple<ConstructionCounting> tuple;
7707#define GTEST_FLAT_TUPLE_INT8 int, int, int, int, int, int, int, int,
7708#define GTEST_FLAT_TUPLE_INT16 GTEST_FLAT_TUPLE_INT8 GTEST_FLAT_TUPLE_INT8
7709#define GTEST_FLAT_TUPLE_INT32 GTEST_FLAT_TUPLE_INT16 GTEST_FLAT_TUPLE_INT16
7710#define GTEST_FLAT_TUPLE_INT64 GTEST_FLAT_TUPLE_INT32 GTEST_FLAT_TUPLE_INT32
7711#define GTEST_FLAT_TUPLE_INT128 GTEST_FLAT_TUPLE_INT64 GTEST_FLAT_TUPLE_INT64
7712#define GTEST_FLAT_TUPLE_INT256 GTEST_FLAT_TUPLE_INT128 GTEST_FLAT_TUPLE_INT128
7716 FlatTuple<GTEST_FLAT_TUPLE_INT256 int> tuple;
7719 tuple.Get<99>() = 17;
7720 tuple.Get<256>() = 1000;
7728TEST(SkipPrefixTest, SkipsWhenPrefixMatches) {
7729 const char*
const str =
"hello";
7731 const char*
p = str;
7740TEST(SkipPrefixTest, DoesNotSkipWhenPrefixDoesNotMatch) {
7741 const char*
const str =
"world";
7743 const char*
p = str;
7753TEST(AdHocTestResultTest, AdHocTestResultForUnitTestDoesNotShowFailure) {
7766 "DynamicUnitTestFixture",
"DynamicTest",
"TYPE",
"VALUE", __FILE__,
7771 for (
int i = 0;
i < unittest->total_test_suite_count(); ++
i) {
7772 auto* tests = unittest->GetTestSuite(
i);
7773 if (tests->name() != std::string(
"DynamicUnitTestFixture"))
continue;
7774 for (
int j = 0; j < tests->total_test_count(); ++j) {
7775 if (tests->GetTestInfo(j)->name() != std::string(
"DynamicTest"))
continue;
7777 EXPECT_STREQ(tests->GetTestInfo(j)->value_param(),
"VALUE");
7778 EXPECT_STREQ(tests->GetTestInfo(j)->type_param(),
"TYPE");
7783 FAIL() <<
"Didn't find the test!";
bool operator<(const UnicodeText::const_iterator &lhs, const UnicodeText::const_iterator &rhs)
bool operator!=(const UnicodeText &lhs, const UnicodeText &rhs)
#define EXPECT_NO_FATAL_FAILURE(statement)
#define EXPECT_STRCASENE(s1, s2)
#define GTEST_ASSERT_GT(val1, val2)
#define ASSERT_GT(val1, val2)
#define ASSERT_EQ(val1, val2)
#define EXPECT_NO_THROW(statement)
#define ASSERT_STRNE(s1, s2)
#define EXPECT_EQ(val1, val2)
#define ADD_FAILURE_AT(file, line)
#define ASSERT_FLOAT_EQ(val1, val2)
#define ASSERT_NO_FATAL_FAILURE(statement)
#define GTEST_ASSERT_GE(val1, val2)
#define ASSERT_STRCASEEQ(s1, s2)
#define GTEST_ASSERT_LT(val1, val2)
#define ASSERT_DOUBLE_EQ(val1, val2)
#define EXPECT_NE(val1, val2)
#define GTEST_ASSERT_NE(val1, val2)
#define ASSERT_NEAR(val1, val2, abs_error)
#define EXPECT_STRCASEEQ(s1, s2)
#define ASSERT_STREQ(s1, s2)
#define ASSERT_LE(val1, val2)
#define EXPECT_THROW(statement, expected_exception)
#define ASSERT_FALSE(condition)
#define EXPECT_NEAR(val1, val2, abs_error)
#define ASSERT_NO_THROW(statement)
#define GTEST_ASSERT_EQ(val1, val2)
#define EXPECT_FLOAT_EQ(val1, val2)
#define EXPECT_ANY_THROW(statement)
#define ASSERT_NE(val1, val2)
#define EXPECT_GT(val1, val2)
#define EXPECT_DOUBLE_EQ(val1, val2)
#define EXPECT_GE(val1, val2)
#define GTEST_ASSERT_LE(val1, val2)
#define EXPECT_TRUE(condition)
#define ASSERT_STRCASENE(s1, s2)
#define GTEST_FAIL_AT(file, line)
#define EXPECT_STREQ(s1, s2)
#define EXPECT_LE(val1, val2)
#define ASSERT_TRUE(condition)
#define EXPECT_FALSE(condition)
#define ASSERT_THROW(statement, expected_exception)
#define EXPECT_STRNE(s1, s2)
#define EXPECT_LT(val1, val2)
#define ASSERT_GE(val1, val2)
#define ASSERT_ANY_THROW(statement)
#define ASSERT_LT(val1, val2)
#define EXPECT_PRED_FORMAT1(pred_format, v1)
#define EXPECT_PRED3(pred, v1, v2, v3)
#define EXPECT_PRED2(pred, v1, v2)
#define ASSERT_PRED_FORMAT4(pred_format, v1, v2, v3, v4)
#define EXPECT_PRED_FORMAT4(pred_format, v1, v2, v3, v4)
#define ASSERT_PRED_FORMAT1(pred_format, v1)
#define ASSERT_PRED2(pred, v1, v2)
#define EXPECT_PRED1(pred, v1)
#define EXPECT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5)
#define ASSERT_PRED1(pred, v1)
#define ASSERT_PRED3(pred, v1, v2, v3)
#define ASSERT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5)
#define ASSERT_PRED_FORMAT2(pred_format, v1, v2)
#define EXPECT_PRED_FORMAT2(pred_format, v1, v2)
#define FRIEND_TEST(test_case_name, test_name)
#define EXPECT_FATAL_FAILURE(statement, substr)
#define EXPECT_NONFATAL_FAILURE(statement, substr)
#define EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(statement, substr)
#define EXPECT_FATAL_FAILURE_ON_ALL_THREADS(statement, substr)
#define GTEST_ATTRIBUTE_UNUSED_
#define GTEST_FLAG_PREFIX_
#define GTEST_FLAG_PREFIX_UPPER_
#define GTEST_DISABLE_MSC_DEPRECATED_PUSH_()
#define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
#define GTEST_REFERENCE_TO_CONST_(T)
#define GTEST_DISABLE_MSC_DEPRECATED_POP_()
#define GTEST_DISABLE_MSC_WARNINGS_POP_()
#define GTEST_CHECK_(condition)
#define GTEST_COMPILE_ASSERT_(expr, msg)
#define GTEST_REMOVE_REFERENCE_AND_CONST_(T)
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)
void TestGTestReferenceToConst()
#define GTEST_TEST_PARSING_FLAGS_(argv1, argv2, expected, should_print_help)
GTEST_TEST(AlternativeNameTest, Works)
#define VERIFY_CODE_LOCATION
TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded)
::std::ostream & operator<<(::std::ostream &os, const TestingVector &vector)
#define GTEST_USE_UNPROTECTED_COMMA_
void TestGTestRemoveReferenceAndConst()
Environment * AddGlobalTestEnvironment(Environment *env)
GTEST_API_ AssertionResult IsNotSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
GTEST_API_ AssertionResult FloatLE(const char *expr1, const char *expr2, float val1, float val2)
std::ostream & operator<<(std::ostream &os, const Message &sb)
GTEST_API_ AssertionResult IsSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
TYPED_TEST_P(CodeLocationForTYPEDTESTP, Verify)
TYPED_TEST(CodeLocationForTYPEDTEST, Verify)
TYPED_TEST_SUITE(CodeLocationForTYPEDTEST, int)
AssertionResult AssertionFailure()
constexpr bool StaticAssertTypeEq() noexcept
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)
INSTANTIATE_TEST_SUITE_P(, CodeLocationForTESTP, Values(0))
internal::TimeInMillis TimeInMillis
GTEST_API_ std::string TempDir()
TYPED_TEST_SUITE_P(CodeLocationForTYPEDTESTP)
INSTANTIATE_TYPED_TEST_SUITE_P(My, CodeLocationForTYPEDTESTP, int)
internal::ValueArray< T... > Values(T... v)
REGISTER_TYPED_TEST_SUITE_P(CodeLocationForTYPEDTESTP, Verify)
AssertionResult AssertionSuccess()
TEST_F(CurrentTestInfoTest, WorksForSecondTestInATestSuite)
TEST_F(TestInfoTest, Names)
GTEST_API_ AssertionResult DoubleLE(const char *expr1, const char *expr2, double val1, double val2)
TEST_P(CodeLocationForTESTP, Verify)
TEST(GTestEnvVarTest, Dummy)
std::string WideStringToUtf8(const wchar_t *str, int num_chars)
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)
GTEST_API_ bool SkipPrefix(const char *prefix, const char **pstr)
bool ShouldRunTestOnShard(int total_shards, int shard_index, int test_id)
void ParseGoogleTestFlagsOnly(int *argc, char **argv)
auto Apply(F &&f, Tuple &&args) -> decltype(ApplyImpl(std::forward< F >(f), std::forward< Tuple >(args), MakeIndexSequence< std::tuple_size< typename std::remove_reference< Tuple >::type >::value >()))
std::string CanonicalizeForStdLibVersioning(std::string s)
bool operator==(faketype, faketype)
std::string FormatEpochTimeInMillisAsIso8601(TimeInMillis ms)
int32_t Int32FromEnvOrDie(const char *var, int32_t default_val)
bool ParseInt32Flag(const char *str, const char *flag, int32_t *value)
constexpr BiggestInt kMaxBiggestInt
IsContainer IsContainerTest(int)
FilePath GetCurrentExecutableName()
TEST_F(ListenerTest, DoesFoo)
bool ShouldShard(const char *total_shards_env, const char *shard_index_env, bool in_subprocess_for_death_test)
std::string FormatTimeInMillisAsSeconds(TimeInMillis ms)
GTEST_API_ bool AlwaysTrue()
Iter ArrayAwareFind(Iter begin, Iter end, const Element &elem)
std::string StreamableToString(const T &streamable)
GTEST_API_ int32_t Int32FromGTestEnv(const char *flag, int32_t default_val)
bool ShouldUseColor(bool stdout_is_tty)
typename MakeIndexSequenceImpl< N >::type MakeIndexSequence
const TypeId kTestTypeIdInGoogleTest
GTEST_API_ void CaptureStdout()
GTEST_API_ TypeId GetTestTypeId()
std::string CodePointToUtf8(uint32_t code_point)
GTEST_API_ std::string AppendUserMessage(const std::string >est_msg, const Message &user_msg)
TimeInMillis GetTimeInMillis()
GTEST_API_ std::string GetCurrentOsStackTraceExceptTop(UnitTest *unit_test, int skip_count)
GTEST_API_ std::string GetCapturedStdout()
bool ArrayEq(const T *lhs, size_t size, const U *rhs)
void CopyArray(const T *from, size_t size, U *to)
GTEST_API_ std::vector< EditType > CalculateOptimalEdits(const std::vector< size_t > &left, const std::vector< size_t > &right)
GTEST_API_ std::string CreateUnifiedDiff(const std::vector< std::string > &left, const std::vector< std::string > &right, size_t context=2)
int RmDir(const char *dir)
FILE * FOpen(const char *path, const char *mode)
def AlsoRunDisabledTestsFlag()
Types< int, long > NumericTypes
std::ostream & operator<<(std::ostream &os, const MyTypeInNameSpace1 &val)
TEST(NestedTestingNamespaceTest, Success)
std::string GetString() const
static bool HasNonfatalFailure()
const char * value() const
int total_part_count() const
const TestProperty & GetTestProperty(int i) const
const TestPartResult & GetTestPartResult(int i) const
int test_property_count() const
const char * name() const
const TestResult * result() const
const char * test_suite_name() const
int total_test_count() const
const TestResult & ad_hoc_test_result() const
const TestInfo * GetTestInfo(int i) const
TestEventListener * Release(TestEventListener *listener)
void Append(TestEventListener *listener)
TestEventListener * default_result_printer() const
TestEventListener * default_xml_generator() const
const TestInfo * current_test_info() const GTEST_LOCK_EXCLUDED_(mutex_)
static UnitTest * GetInstance()
const TestResult & ad_hoc_test_result() const
const TestSuite * current_test_suite() const GTEST_LOCK_EXCLUDED_(mutex_)
const Bits & bits() const
static const uint32_t kMaxRange
const_iterator begin() const
const_iterator end() const
static bool EventForwardingEnabled(const TestEventListeners &listeners)
static TestEventListener * GetRepeater(TestEventListeners *listeners)
static void SetDefaultXmlGenerator(TestEventListeners *listeners, TestEventListener *listener)
static void SuppressEventForwarding(TestEventListeners *listeners)
static void SetDefaultResultPrinter(TestEventListeners *listeners, TestEventListener *listener)
void UnitTestRecordProperty(const char *key, const std::string &value)
UnitTestRecordPropertyTestHelper()
MyTypeInNameSpace1(int an_x)
MyTypeInNameSpace2(int an_x)
static const TestResult * GetTestResult(const TestInfo *test_info)
static const TestInfo * GetTestInfo(const char *test_name)
static void SetUpTestCase()
static const char * shared_resource_
static void TearDownTestCase()
static const char * shared_resource_
static void TearDownTestSuite()
static void SetUpTestSuite()
static Flags Shuffle(bool shuffle)
static Flags CatchExceptions(bool catch_exceptions)
static Flags RandomSeed(int32_t random_seed)
static Flags Brief(bool brief)
static Flags DeathTestUseFork(bool death_test_use_fork)
static Flags Output(const char *output)
static Flags Repeat(int32_t repeat)
static Flags BreakOnFailure(bool break_on_failure)
static Flags FailFast(bool fail_fast)
static Flags ListTests(bool list_tests)
static Flags AlsoRunDisabledTests(bool also_run_disabled_tests)
bool also_run_disabled_tests
static Flags StreamResultTo(const char *stream_result_to)
static Flags StackTraceDepth(int32_t stack_trace_depth)
const char * stream_result_to
static Flags ThrowOnFailure(bool throw_on_failure)
int32_t stack_trace_depth
static Flags PrintTime(bool print_time)
static Flags Filter(const char *filter)
static void CheckFlags(const Flags &expected)
static void AssertStringArrayEq(int size1, CharType **array1, int size2, CharType **array2)
static void TestParsingFlags(int argc1, const CharType **argv1, int argc2, const CharType **argv2, const Flags &expected, bool should_print_help)
static void TearDownTestSuite()
static void SetUpTestSuite()
StaticAssertTypeEqTestHelper()
void OnTestProgramStart(const UnitTest &) override
TestListener(int *on_start_counter, bool *is_destroyed)
void OnTestProgramStart(const UnitTest &) override
void OnTestIterationStart(const UnitTest &, int) override
void OnTestProgramEnd(const UnitTest &) override
SequenceTestingListener(std::vector< std::string > *vector, const char *id)
void OnTestIterationEnd(const UnitTest &, int) override
std::string ShortDebugString() const
std::string DebugString() const
int ShortDebugString() const
std::string DebugString() const
std::string DebugString()
std::string ShortDebugString() const
std::string DebugString()
const_iterator end() const
const_iterator begin() const
const_iterator begin() const
const_iterator end() const
const int & operator*() const
const_iterator & operator++()
ConstructionCounting & operator=(const ConstructionCounting &)
static int move_ctor_calls
ConstructionCounting(ConstructionCounting &&) noexcept
ConstructionCounting & operator=(ConstructionCounting &&) noexcept
static int copy_assignment_calls
ConstructionCounting(const ConstructionCounting &)
static int move_assignment_calls
static int copy_ctor_calls
static int default_ctor_calls