39TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) {
69#include <unordered_set>
83 false, std::enable_if_t<std::is_constructible<T>::value,
int>> = 0>
87static_assert(
sizeof(
decltype(std::declval<ConvertibleGlobalType&>()
89 "error in operator<< overload resolution");
94#if GTEST_CAN_STREAM_RESULTS_
96class StreamingListenerTest :
public Test {
98 class FakeSocketWriter :
public StreamingListener::AbstractSocketWriter {
101 void Send(
const std::string& message)
override { output_ += message; }
106 StreamingListenerTest()
107 : fake_sock_writer_(new FakeSocketWriter),
108 streamer_(fake_sock_writer_),
109 test_info_obj_(
"FooTest",
"Bar", nullptr, nullptr,
110 CodeLocation(__FILE__, __LINE__), nullptr, nullptr) {}
113 std::string*
output() {
return &(fake_sock_writer_->output_); }
115 FakeSocketWriter*
const fake_sock_writer_;
116 StreamingListener streamer_;
121TEST_F(StreamingListenerTest, OnTestProgramEnd) {
123 streamer_.OnTestProgramEnd(unit_test_);
127TEST_F(StreamingListenerTest, OnTestIterationEnd) {
129 streamer_.OnTestIterationEnd(unit_test_, 42);
130 EXPECT_EQ(
"event=TestIterationEnd&passed=1&elapsed_time=0ms\n", *
output());
133TEST_F(StreamingListenerTest, OnTestSuiteStart) {
135 streamer_.OnTestSuiteStart(TestSuite(
"FooTest",
"Bar",
nullptr,
nullptr));
139TEST_F(StreamingListenerTest, OnTestSuiteEnd) {
141 streamer_.OnTestSuiteEnd(TestSuite(
"FooTest",
"Bar",
nullptr,
nullptr));
145TEST_F(StreamingListenerTest, OnTestStart) {
147 streamer_.OnTestStart(test_info_obj_);
151TEST_F(StreamingListenerTest, OnTestEnd) {
153 streamer_.OnTestEnd(test_info_obj_);
157TEST_F(StreamingListenerTest, OnTestPartResult) {
159 streamer_.OnTestPartResult(TestPartResult(TestPartResult::kFatalFailure,
160 "foo.cc", 42,
"failed=\n&%"));
164 "event=TestPartResult&file=foo.cc&line=42&message=failed%3D%0A%26%25\n",
175 return listeners->repeater();
180 listeners->SetDefaultResultPrinter(listener);
184 listeners->SetDefaultXmlGenerator(listener);
188 return listeners.EventForwardingEnabled();
212using testing::AssertionResult;
222using testing::ScopedFakeTestPartResultReporter;
227using testing::TestPartResult;
228using testing::TestPartResultArray;
280#if GTEST_HAS_STREAM_REDIRECTION
285#ifdef GTEST_IS_THREADSAFE
286using testing::internal::ThreadWithParam;
293 for (
size_t i = 0;
i < vector.size();
i++) {
294 os << vector[
i] <<
" ";
303TEST(GetRandomSeedFromFlagTest, HandlesZero) {
304 const int seed = GetRandomSeedFromFlag(0);
306 EXPECT_LE(seed,
static_cast<int>(kMaxRandomSeed));
309TEST(GetRandomSeedFromFlagTest, PreservesValidSeed) {
312 EXPECT_EQ(kMaxRandomSeed - 1, GetRandomSeedFromFlag(kMaxRandomSeed - 1));
313 EXPECT_EQ(
static_cast<int>(kMaxRandomSeed),
314 GetRandomSeedFromFlag(kMaxRandomSeed));
317TEST(GetRandomSeedFromFlagTest, NormalizesInvalidSeed) {
318 const int seed1 = GetRandomSeedFromFlag(-1);
320 EXPECT_LE(seed1,
static_cast<int>(kMaxRandomSeed));
322 const int seed2 = GetRandomSeedFromFlag(kMaxRandomSeed + 1);
324 EXPECT_LE(seed2,
static_cast<int>(kMaxRandomSeed));
327TEST(GetNextRandomSeedTest, WorksForValidInput) {
330 EXPECT_EQ(
static_cast<int>(kMaxRandomSeed),
331 GetNextRandomSeed(kMaxRandomSeed - 1));
332 EXPECT_EQ(1, GetNextRandomSeed(kMaxRandomSeed));
340static void ClearCurrentTestPartResults() {
342 GetUnitTestImpl()->current_test_result());
347TEST(GetTypeIdTest, ReturnsSameValueForSameType) {
348 EXPECT_EQ(GetTypeId<int>(), GetTypeId<int>());
349 EXPECT_EQ(GetTypeId<Test>(), GetTypeId<Test>());
352class SubClassOfTest :
public Test {};
353class AnotherSubClassOfTest :
public Test {};
355TEST(GetTypeIdTest, ReturnsDifferentValuesForDifferentTypes) {
356 EXPECT_NE(GetTypeId<int>(), GetTypeId<const int>());
357 EXPECT_NE(GetTypeId<int>(), GetTypeId<char>());
358 EXPECT_NE(GetTypeId<int>(), GetTestTypeId());
359 EXPECT_NE(GetTypeId<SubClassOfTest>(), GetTestTypeId());
360 EXPECT_NE(GetTypeId<AnotherSubClassOfTest>(), GetTestTypeId());
361 EXPECT_NE(GetTypeId<AnotherSubClassOfTest>(), GetTypeId<SubClassOfTest>());
366TEST(GetTestTypeIdTest, ReturnsTheSameValueInsideOrOutsideOfGoogleTest) {
367 EXPECT_EQ(kTestTypeIdInGoogleTest, GetTestTypeId());
372using ::testing::internal::CanonicalizeForStdLibVersioning;
374TEST(CanonicalizeForStdLibVersioning, LeavesUnversionedNamesUnchanged) {
383TEST(CanonicalizeForStdLibVersioning, ElidesDoubleUnderNames) {
397TEST(FormatTimeInMillisAsSecondsTest, FormatsZero) {
398 EXPECT_EQ(
"0.", FormatTimeInMillisAsSeconds(0));
401TEST(FormatTimeInMillisAsSecondsTest, FormatsPositiveNumber) {
402 EXPECT_EQ(
"0.003", FormatTimeInMillisAsSeconds(3));
403 EXPECT_EQ(
"0.01", FormatTimeInMillisAsSeconds(10));
404 EXPECT_EQ(
"0.2", FormatTimeInMillisAsSeconds(200));
405 EXPECT_EQ(
"1.2", FormatTimeInMillisAsSeconds(1200));
406 EXPECT_EQ(
"3.", FormatTimeInMillisAsSeconds(3000));
407 EXPECT_EQ(
"10.", FormatTimeInMillisAsSeconds(10000));
408 EXPECT_EQ(
"100.", FormatTimeInMillisAsSeconds(100000));
409 EXPECT_EQ(
"123.456", FormatTimeInMillisAsSeconds(123456));
410 EXPECT_EQ(
"1234567.89", FormatTimeInMillisAsSeconds(1234567890));
413TEST(FormatTimeInMillisAsSecondsTest, FormatsNegativeNumber) {
414 EXPECT_EQ(
"-0.003", FormatTimeInMillisAsSeconds(-3));
415 EXPECT_EQ(
"-0.01", FormatTimeInMillisAsSeconds(-10));
416 EXPECT_EQ(
"-0.2", FormatTimeInMillisAsSeconds(-200));
417 EXPECT_EQ(
"-1.2", FormatTimeInMillisAsSeconds(-1200));
418 EXPECT_EQ(
"-3.", FormatTimeInMillisAsSeconds(-3000));
419 EXPECT_EQ(
"-10.", FormatTimeInMillisAsSeconds(-10000));
420 EXPECT_EQ(
"-100.", FormatTimeInMillisAsSeconds(-100000));
421 EXPECT_EQ(
"-123.456", FormatTimeInMillisAsSeconds(-123456));
422 EXPECT_EQ(
"-1234567.89", FormatTimeInMillisAsSeconds(-1234567890));
431class FormatEpochTimeInMillisAsIso8601Test :
public Test {
436 static const TimeInMillis kMillisPerSec = 1000;
439 void SetUp()
override {
443 if (const
char* tz = getenv("TZ")) {
444 saved_tz_ = std::make_unique<std::string>(tz);
451 SetTimeZone("UTC+00");
454 void TearDown()
override {
455 SetTimeZone(saved_tz_ !=
nullptr ? saved_tz_->c_str() : nullptr);
459 static void SetTimeZone(
const char* time_zone) {
463#if defined(_MSC_VER) || defined(GTEST_OS_WINDOWS_MINGW)
466 const std::string env_var =
467 std::string(
"TZ=") + (time_zone ? time_zone :
"");
468 _putenv(env_var.c_str());
473#if defined(GTEST_OS_LINUX_ANDROID) && __ANDROID_API__ < 21
476 setenv(
"TZ",
"UTC", 1);
480 setenv((
"TZ"), time_zone, 1);
488 std::unique_ptr<std::string> saved_tz_;
491const TimeInMillis FormatEpochTimeInMillisAsIso8601Test::kMillisPerSec;
493TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsTwoDigitSegments) {
495 FormatEpochTimeInMillisAsIso8601(1320087162 * kMillisPerSec));
498TEST_F(FormatEpochTimeInMillisAsIso8601Test, IncludesMillisecondsAfterDot) {
500 FormatEpochTimeInMillisAsIso8601(1320087162 * kMillisPerSec + 234));
503TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsLeadingZeroes) {
505 FormatEpochTimeInMillisAsIso8601(1315026422 * kMillisPerSec));
508TEST_F(FormatEpochTimeInMillisAsIso8601Test, Prints24HourTime) {
510 FormatEpochTimeInMillisAsIso8601(1317229702 * kMillisPerSec));
513TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsEpochStart) {
514 EXPECT_EQ(
"1970-01-01T00:00:00.000", FormatEpochTimeInMillisAsIso8601(0));
519#pragma option push -w-ccc -w-rch
524TEST(NullLiteralTest, LHSAllowsNullLiterals) {
525 EXPECT_EQ(0,
static_cast<void*
>(
nullptr));
526 ASSERT_EQ(0,
static_cast<void*
>(
nullptr));
527 EXPECT_EQ(NULL,
static_cast<void*
>(
nullptr));
528 ASSERT_EQ(NULL,
static_cast<void*
>(
nullptr));
529 EXPECT_EQ(
nullptr,
static_cast<void*
>(
nullptr));
530 ASSERT_EQ(
nullptr,
static_cast<void*
>(
nullptr));
532 const int*
const p =
nullptr;
542 template <
typename T>
548struct ConvertToPointer {
550 operator T*()
const {
555struct ConvertToAllButNoPointers {
556 template <
typename T,
557 typename std::enable_if<!std::is_pointer<T>::value,
int>::type = 0>
566TEST(NullLiteralTest, ImplicitConversion) {
567 EXPECT_EQ(ConvertToPointer{},
static_cast<void*
>(
nullptr));
568#if !defined(__GNUC__) || defined(__clang__)
570 EXPECT_EQ(ConvertToAll{},
static_cast<void*
>(
nullptr));
577#pragma clang diagnostic push
578#if __has_warning("-Wzero-as-null-pointer-constant")
579#pragma clang diagnostic error "-Wzero-as-null-pointer-constant"
583TEST(NullLiteralTest, NoConversionNoWarning) {
591#pragma clang diagnostic pop
603TEST(CodePointToUtf8Test, CanEncodeNul) {
608TEST(CodePointToUtf8Test, CanEncodeAscii) {
612 EXPECT_EQ(
"\x7F", CodePointToUtf8(L
'\x7F'));
617TEST(CodePointToUtf8Test, CanEncode8To11Bits) {
619 EXPECT_EQ(
"\xC3\x93", CodePointToUtf8(L
'\xD3'));
625 EXPECT_EQ(
"\xD5\xB6", CodePointToUtf8(
static_cast<wchar_t>(0x576)));
630TEST(CodePointToUtf8Test, CanEncode12To16Bits) {
632 EXPECT_EQ(
"\xE0\xA3\x93", CodePointToUtf8(
static_cast<wchar_t>(0x8D3)));
635 EXPECT_EQ(
"\xEC\x9D\x8D", CodePointToUtf8(
static_cast<wchar_t>(0xC74D)));
638#if !GTEST_WIDE_STRING_USES_UTF16_
645TEST(CodePointToUtf8Test, CanEncode17To21Bits) {
647 EXPECT_EQ(
"\xF0\x90\xA3\x93", CodePointToUtf8(L
'\x108D3'));
650 EXPECT_EQ(
"\xF0\x90\x90\x80", CodePointToUtf8(L
'\x10400'));
653 EXPECT_EQ(
"\xF4\x88\x98\xB4", CodePointToUtf8(L
'\x108634'));
657TEST(CodePointToUtf8Test, CanEncodeInvalidCodePoint) {
658 EXPECT_EQ(
"(Invalid Unicode 0x1234ABCD)", CodePointToUtf8(L
'\x1234ABCD'));
666TEST(WideStringToUtf8Test, CanEncodeNul) {
672TEST(WideStringToUtf8Test, CanEncodeAscii) {
676 EXPECT_STREQ(
"ab", WideStringToUtf8(L
"ab", -1).c_str());
681TEST(WideStringToUtf8Test, CanEncode8To11Bits) {
683 EXPECT_STREQ(
"\xC3\x93", WideStringToUtf8(L
"\xD3", 1).c_str());
684 EXPECT_STREQ(
"\xC3\x93", WideStringToUtf8(L
"\xD3", -1).c_str());
687 const wchar_t s[] = {0x576,
'\0'};
688 EXPECT_STREQ(
"\xD5\xB6", WideStringToUtf8(s, 1).c_str());
689 EXPECT_STREQ(
"\xD5\xB6", WideStringToUtf8(s, -1).c_str());
694TEST(WideStringToUtf8Test, CanEncode12To16Bits) {
696 const wchar_t s1[] = {0x8D3,
'\0'};
697 EXPECT_STREQ(
"\xE0\xA3\x93", WideStringToUtf8(s1, 1).c_str());
698 EXPECT_STREQ(
"\xE0\xA3\x93", WideStringToUtf8(s1, -1).c_str());
701 const wchar_t s2[] = {0xC74D,
'\0'};
702 EXPECT_STREQ(
"\xEC\x9D\x8D", WideStringToUtf8(s2, 1).c_str());
703 EXPECT_STREQ(
"\xEC\x9D\x8D", WideStringToUtf8(s2, -1).c_str());
707TEST(WideStringToUtf8Test, StopsOnNulCharacter) {
708 EXPECT_STREQ(
"ABC", WideStringToUtf8(L
"ABC\0XYZ", 100).c_str());
713TEST(WideStringToUtf8Test, StopsWhenLengthLimitReached) {
714 EXPECT_STREQ(
"ABC", WideStringToUtf8(L
"ABCDEF", 3).c_str());
717#if !GTEST_WIDE_STRING_USES_UTF16_
721TEST(WideStringToUtf8Test, CanEncode17To21Bits) {
723 EXPECT_STREQ(
"\xF0\x90\xA3\x93", WideStringToUtf8(L
"\x108D3", 1).c_str());
724 EXPECT_STREQ(
"\xF0\x90\xA3\x93", WideStringToUtf8(L
"\x108D3", -1).c_str());
727 EXPECT_STREQ(
"\xF4\x88\x98\xB4", WideStringToUtf8(L
"\x108634", 1).c_str());
728 EXPECT_STREQ(
"\xF4\x88\x98\xB4", WideStringToUtf8(L
"\x108634", -1).c_str());
732TEST(WideStringToUtf8Test, CanEncodeInvalidCodePoint) {
734 WideStringToUtf8(L
"\xABCDFF", -1).c_str());
739TEST(WideStringToUtf8Test, CanEncodeValidUtf16SUrrogatePairs) {
740 const wchar_t s[] = {0xD801, 0xDC00,
'\0'};
741 EXPECT_STREQ(
"\xF0\x90\x90\x80", WideStringToUtf8(s, -1).c_str());
746TEST(WideStringToUtf8Test, CanEncodeInvalidUtf16SurrogatePair) {
748 const wchar_t s1[] = {0xD800,
'\0'};
749 EXPECT_STREQ(
"\xED\xA0\x80", WideStringToUtf8(s1, -1).c_str());
751 const wchar_t s2[] = {0xD800,
'M',
'\0'};
752 EXPECT_STREQ(
"\xED\xA0\x80M", WideStringToUtf8(s2, -1).c_str());
754 const wchar_t s3[] = {0xDC00,
'P',
'Q',
'R',
'\0'};
755 EXPECT_STREQ(
"\xED\xB0\x80PQR", WideStringToUtf8(s3, -1).c_str());
760#if !GTEST_WIDE_STRING_USES_UTF16_
761TEST(WideStringToUtf8Test, ConcatenatesCodepointsCorrectly) {
762 const wchar_t s[] = {0x108634, 0xC74D,
'\n', 0x576, 0x8D3, 0x108634,
'\0'};
770 WideStringToUtf8(s, -1).c_str());
773TEST(WideStringToUtf8Test, ConcatenatesCodepointsCorrectly) {
774 const wchar_t s[] = {0xC74D,
'\n', 0x576, 0x8D3,
'\0'};
780 WideStringToUtf8(s, -1).c_str());
786TEST(RandomDeathTest, GeneratesCrashesOnInvalidRange) {
789 "Cannot generate a number in the range \\[0, 0\\)");
792 "Generation of a number in \\[0, 2147483649\\) was requested, "
793 "but this can only generate numbers in \\[0, 2147483648\\)");
796TEST(RandomTest, GeneratesNumbersWithinRange) {
797 constexpr uint32_t kRange = 10000;
799 for (
int i = 0;
i < 10;
i++) {
800 EXPECT_LT(random.Generate(kRange), kRange) <<
" for iteration " <<
i;
804 for (
int i = 0;
i < 10;
i++) {
805 EXPECT_LT(random2.Generate(kRange), kRange) <<
" for iteration " <<
i;
809TEST(RandomTest, RepeatsWhenReseeded) {
810 constexpr int kSeed = 123;
811 constexpr int kArraySize = 10;
812 constexpr uint32_t kRange = 10000;
813 uint32_t values[kArraySize];
816 for (
int i = 0;
i < kArraySize;
i++) {
817 values[
i] = random.Generate(kRange);
820 random.Reseed(kSeed);
821 for (
int i = 0;
i < kArraySize;
i++) {
822 EXPECT_EQ(values[
i], random.Generate(kRange)) <<
" for iteration " <<
i;
830static bool IsPositive(
int n) {
return n > 0; }
832TEST(ContainerUtilityTest, CountIf) {
849static void Accumulate(
int n) { g_sum += n; }
851TEST(ContainerUtilityTest, ForEach) {
854 ForEach(v, Accumulate);
859 ForEach(v, Accumulate);
865 ForEach(v, Accumulate);
870TEST(ContainerUtilityTest, GetElementOr) {
878 EXPECT_EQ(
'x', GetElementOr(a, -2,
'x'));
882TEST(ContainerUtilityDeathTest, ShuffleRange) {
890 ShuffleRange(&random, -1, 1, &a),
891 "Invalid shuffle range start -1: must be in range \\[0, 3\\]");
893 ShuffleRange(&random, 4, 4, &a),
894 "Invalid shuffle range start 4: must be in range \\[0, 3\\]");
896 ShuffleRange(&random, 3, 2, &a),
897 "Invalid shuffle range finish 2: must be in range \\[3, 3\\]");
899 ShuffleRange(&random, 3, 4, &a),
900 "Invalid shuffle range finish 4: must be in range \\[3, 3\\]");
903class VectorShuffleTest :
public Test {
905 static const size_t kVectorSize = 20;
907 VectorShuffleTest() : random_(1) {
909 vector_.push_back(
i);
914 if (kVectorSize != vector.size()) {
918 bool found_in_vector[kVectorSize] = {
false};
919 for (
size_t i = 0;
i < vector.size();
i++) {
920 const int e = vector[
i];
921 if (e < 0 || e >=
static_cast<int>(kVectorSize) || found_in_vector[e]) {
924 found_in_vector[e] =
true;
932 static bool VectorIsNotCorrupt(
const TestingVector& vector) {
933 return !VectorIsCorrupt(vector);
936 static bool RangeIsShuffled(
const TestingVector& vector,
int begin,
int end) {
937 for (
int i = begin;
i < end;
i++) {
938 if (
i != vector[
static_cast<size_t>(
i)]) {
945 static bool RangeIsUnshuffled(
const TestingVector& vector,
int begin,
947 return !RangeIsShuffled(vector, begin, end);
951 return RangeIsShuffled(vector, 0,
static_cast<int>(vector.size()));
954 static bool VectorIsUnshuffled(
const TestingVector& vector) {
955 return !VectorIsShuffled(vector);
962const size_t VectorShuffleTest::kVectorSize;
964TEST_F(VectorShuffleTest, HandlesEmptyRange) {
966 ShuffleRange(&random_, 0, 0, &vector_);
971 ShuffleRange(&random_, kVectorSize / 2, kVectorSize / 2, &vector_);
976 ShuffleRange(&random_, kVectorSize - 1, kVectorSize - 1, &vector_);
981 ShuffleRange(&random_, kVectorSize, kVectorSize, &vector_);
986TEST_F(VectorShuffleTest, HandlesRangeOfSizeOne) {
988 ShuffleRange(&random_, 0, 1, &vector_);
993 ShuffleRange(&random_, kVectorSize / 2, kVectorSize / 2 + 1, &vector_);
998 ShuffleRange(&random_, kVectorSize - 1, kVectorSize, &vector_);
1006TEST_F(VectorShuffleTest, ShufflesEntireVector) {
1007 Shuffle(&random_, &vector_);
1014 EXPECT_NE(
static_cast<int>(kVectorSize - 1), vector_[kVectorSize - 1]);
1017TEST_F(VectorShuffleTest, ShufflesStartOfVector) {
1018 const int kRangeSize = kVectorSize / 2;
1020 ShuffleRange(&random_, 0, kRangeSize, &vector_);
1025 static_cast<int>(kVectorSize));
1028TEST_F(VectorShuffleTest, ShufflesEndOfVector) {
1029 const int kRangeSize = kVectorSize / 2;
1030 ShuffleRange(&random_, kRangeSize, kVectorSize, &vector_);
1033 EXPECT_PRED3(RangeIsUnshuffled, vector_, 0, kRangeSize);
1035 static_cast<int>(kVectorSize));
1038TEST_F(VectorShuffleTest, ShufflesMiddleOfVector) {
1039 const int kRangeSize =
static_cast<int>(kVectorSize) / 3;
1040 ShuffleRange(&random_, kRangeSize, 2 * kRangeSize, &vector_);
1043 EXPECT_PRED3(RangeIsUnshuffled, vector_, 0, kRangeSize);
1044 EXPECT_PRED3(RangeIsShuffled, vector_, kRangeSize, 2 * kRangeSize);
1045 EXPECT_PRED3(RangeIsUnshuffled, vector_, 2 * kRangeSize,
1046 static_cast<int>(kVectorSize));
1049TEST_F(VectorShuffleTest, ShufflesRepeatably) {
1051 for (
size_t i = 0;
i < kVectorSize;
i++) {
1052 vector2.push_back(
static_cast<int>(
i));
1055 random_.Reseed(1234);
1056 Shuffle(&random_, &vector_);
1057 random_.Reseed(1234);
1058 Shuffle(&random_, &vector2);
1063 for (
size_t i = 0;
i < kVectorSize;
i++) {
1064 EXPECT_EQ(vector_[
i], vector2[
i]) <<
" where i is " <<
i;
1070TEST(AssertHelperTest, AssertHelperIsSmall) {
1077TEST(StringTest, EndsWithCaseInsensitive) {
1078 EXPECT_TRUE(String::EndsWithCaseInsensitive(
"foobar",
"BAR"));
1079 EXPECT_TRUE(String::EndsWithCaseInsensitive(
"foobaR",
"bar"));
1080 EXPECT_TRUE(String::EndsWithCaseInsensitive(
"foobar",
""));
1081 EXPECT_TRUE(String::EndsWithCaseInsensitive(
"",
""));
1083 EXPECT_FALSE(String::EndsWithCaseInsensitive(
"Foobar",
"foo"));
1084 EXPECT_FALSE(String::EndsWithCaseInsensitive(
"foobar",
"Foo"));
1085 EXPECT_FALSE(String::EndsWithCaseInsensitive(
"",
"foo"));
1091static const wchar_t*
const kNull =
nullptr;
1094TEST(StringTest, CaseInsensitiveWideCStringEquals) {
1095 EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(
nullptr,
nullptr));
1096 EXPECT_FALSE(String::CaseInsensitiveWideCStringEquals(kNull, L
""));
1097 EXPECT_FALSE(String::CaseInsensitiveWideCStringEquals(L
"", kNull));
1098 EXPECT_FALSE(String::CaseInsensitiveWideCStringEquals(kNull, L
"foobar"));
1099 EXPECT_FALSE(String::CaseInsensitiveWideCStringEquals(L
"foobar", kNull));
1100 EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(L
"foobar", L
"foobar"));
1101 EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(L
"foobar", L
"FOOBAR"));
1102 EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(L
"FOOBAR", L
"foobar"));
1105#ifdef GTEST_OS_WINDOWS
1108TEST(StringTest, ShowWideCString) {
1109 EXPECT_STREQ(
"(null)", String::ShowWideCString(NULL).c_str());
1110 EXPECT_STREQ(
"", String::ShowWideCString(L
"").c_str());
1111 EXPECT_STREQ(
"foo", String::ShowWideCString(L
"foo").c_str());
1114#ifdef GTEST_OS_WINDOWS_MOBILE
1115TEST(StringTest, AnsiAndUtf16Null) {
1116 EXPECT_EQ(NULL, String::AnsiToUtf16(NULL));
1117 EXPECT_EQ(NULL, String::Utf16ToAnsi(NULL));
1120TEST(StringTest, AnsiAndUtf16ConvertBasic) {
1121 const char* ansi = String::Utf16ToAnsi(L
"str");
1124 const WCHAR* utf16 = String::AnsiToUtf16(
"str");
1125 EXPECT_EQ(0, wcsncmp(L
"str", utf16, 3));
1129TEST(StringTest, AnsiAndUtf16ConvertPathChars) {
1130 const char* ansi = String::Utf16ToAnsi(L
".:\\ \"*?");
1133 const WCHAR* utf16 = String::AnsiToUtf16(
".:\\ \"*?");
1134 EXPECT_EQ(0, wcsncmp(L
".:\\ \"*?", utf16, 3));
1142TEST(TestPropertyTest, StringValue) {
1149TEST(TestPropertyTest, ReplaceStringValue) {
1152 property.SetValue(
"2");
1159static void AddFatalFailure() {
FAIL() <<
"Expected fatal failure."; }
1161static void AddNonfatalFailure() {
1165class ScopedFakeTestPartResultReporterTest :
public Test {
1167 enum FailureMode { FATAL_FAILURE, NONFATAL_FAILURE };
1168 static void AddFailure(FailureMode failure) {
1169 if (failure == FATAL_FAILURE) {
1172 AddNonfatalFailure();
1179TEST_F(ScopedFakeTestPartResultReporterTest, InterceptsTestFailures) {
1180 TestPartResultArray results;
1182 ScopedFakeTestPartResultReporter reporter(
1183 ScopedFakeTestPartResultReporter::INTERCEPT_ONLY_CURRENT_THREAD,
1185 AddFailure(NONFATAL_FAILURE);
1186 AddFailure(FATAL_FAILURE);
1190 EXPECT_TRUE(results.GetTestPartResult(0).nonfatally_failed());
1191 EXPECT_TRUE(results.GetTestPartResult(1).fatally_failed());
1194TEST_F(ScopedFakeTestPartResultReporterTest, DeprecatedConstructor) {
1195 TestPartResultArray results;
1198 ScopedFakeTestPartResultReporter reporter(&results);
1199 AddFailure(NONFATAL_FAILURE);
1204#ifdef GTEST_IS_THREADSAFE
1206class ScopedFakeTestPartResultReporterWithThreadsTest
1207 :
public ScopedFakeTestPartResultReporterTest {
1209 static void AddFailureInOtherThread(FailureMode failure) {
1210 ThreadWithParam<FailureMode> thread(&AddFailure, failure,
nullptr);
1215TEST_F(ScopedFakeTestPartResultReporterWithThreadsTest,
1216 InterceptsTestFailuresInAllThreads) {
1217 TestPartResultArray results;
1219 ScopedFakeTestPartResultReporter reporter(
1220 ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS, &results);
1221 AddFailure(NONFATAL_FAILURE);
1222 AddFailure(FATAL_FAILURE);
1223 AddFailureInOtherThread(NONFATAL_FAILURE);
1224 AddFailureInOtherThread(FATAL_FAILURE);
1228 EXPECT_TRUE(results.GetTestPartResult(0).nonfatally_failed());
1229 EXPECT_TRUE(results.GetTestPartResult(1).fatally_failed());
1230 EXPECT_TRUE(results.GetTestPartResult(2).nonfatally_failed());
1231 EXPECT_TRUE(results.GetTestPartResult(3).fatally_failed());
1240typedef ScopedFakeTestPartResultReporterTest ExpectFatalFailureTest;
1242TEST_F(ExpectFatalFailureTest, CatchesFatalFaliure) {
1246TEST_F(ExpectFatalFailureTest, AcceptsStdStringObject) {
1248 ::std::string(
"Expected fatal failure."));
1251TEST_F(ExpectFatalFailureTest, CatchesFatalFailureOnAllThreads) {
1255 "Expected fatal failure.");
1260#pragma option push -w-ccc
1266int NonVoidFunction() {
1272TEST_F(ExpectFatalFailureTest, CanBeUsedInNonVoidFunction) {
1279void DoesNotAbortHelper(
bool* aborted) {
1291TEST_F(ExpectFatalFailureTest, DoesNotAbort) {
1292 bool aborted =
true;
1293 DoesNotAbortHelper(&aborted);
1301static int global_var = 0;
1302#define GTEST_USE_UNPROTECTED_COMMA_ global_var++, global_var++
1304TEST_F(ExpectFatalFailureTest, AcceptsMacroThatExpandsToUnprotectedComma) {
1325typedef ScopedFakeTestPartResultReporterTest ExpectNonfatalFailureTest;
1327TEST_F(ExpectNonfatalFailureTest, CatchesNonfatalFailure) {
1331TEST_F(ExpectNonfatalFailureTest, AcceptsStdStringObject) {
1333 ::std::string(
"Expected non-fatal failure."));
1336TEST_F(ExpectNonfatalFailureTest, CatchesNonfatalFailureOnAllThreads) {
1340 "Expected non-fatal failure.");
1346TEST_F(ExpectNonfatalFailureTest, AcceptsMacroThatExpandsToUnprotectedComma) {
1350 AddNonfatalFailure();
1357 AddNonfatalFailure();
1362#ifdef GTEST_IS_THREADSAFE
1364typedef ScopedFakeTestPartResultReporterWithThreadsTest
1365 ExpectFailureWithThreadsTest;
1367TEST_F(ExpectFailureWithThreadsTest, ExpectFatalFailureOnAllThreads) {
1369 "Expected fatal failure.");
1372TEST_F(ExpectFailureWithThreadsTest, ExpectNonFatalFailureOnAllThreads) {
1374 AddFailureInOtherThread(NONFATAL_FAILURE),
"Expected non-fatal failure.");
1381TEST(TestPropertyTest, ConstructorWorks) {
1387TEST(TestPropertyTest, SetValue) {
1390 property.SetValue(
"value_2");
1398class TestResultTest :
public Test {
1400 typedef std::vector<TestPartResult> TPRVector;
1403 TestPartResult *pr1, *pr2;
1408 void SetUp()
override {
1410 pr1 =
new TestPartResult(TestPartResult::kSuccess,
"foo/bar.cc", 10,
1414 pr2 =
new TestPartResult(TestPartResult::kFatalFailure,
"foo/bar.cc",
1427 TPRVector* results1 =
1428 const_cast<TPRVector*
>(&TestResultAccessor::test_part_results(*r1));
1429 TPRVector* results2 =
1430 const_cast<TPRVector*
>(&TestResultAccessor::test_part_results(*r2));
1435 results1->push_back(*pr1);
1438 results2->push_back(*pr1);
1439 results2->push_back(*pr2);
1442 void TearDown()
override {
1452 static void CompareTestPartResult(
const TestPartResult& expected,
1453 const TestPartResult& actual) {
1454 EXPECT_EQ(expected.type(), actual.type());
1455 EXPECT_STREQ(expected.file_name(), actual.file_name());
1456 EXPECT_EQ(expected.line_number(), actual.line_number());
1459 EXPECT_EQ(expected.passed(), actual.passed());
1460 EXPECT_EQ(expected.failed(), actual.failed());
1461 EXPECT_EQ(expected.nonfatally_failed(), actual.nonfatally_failed());
1462 EXPECT_EQ(expected.fatally_failed(), actual.fatally_failed());
1467TEST_F(TestResultTest, total_part_count) {
1474TEST_F(TestResultTest, Passed) {
1481TEST_F(TestResultTest, Failed) {
1489typedef TestResultTest TestResultDeathTest;
1491TEST_F(TestResultDeathTest, GetTestPartResult) {
1499TEST(TestResultPropertyTest, NoPropertiesFoundWhenNoneAreAdded) {
1505TEST(TestResultPropertyTest, OnePropertyFoundWhenAdded) {
1508 TestResultAccessor::RecordProperty(&test_result,
"testcase", property);
1516TEST(TestResultPropertyTest, MultiplePropertiesFoundWhenAdded) {
1520 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_1);
1521 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_2);
1533TEST(TestResultPropertyTest, OverridesValuesForDuplicateKeys) {
1539 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_1_1);
1540 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_2_1);
1541 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_1_2);
1542 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_2_2);
1555TEST(TestResultPropertyTest, GetTestProperty) {
1560 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_1);
1561 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_2);
1562 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_3);
1593class GTestFlagSaverTest :
public Test {
1598 static void SetUpTestSuite() {
1623 static void TearDownTestSuite() {
1630 void VerifyAndModifyFlags() {
1681TEST_F(GTestFlagSaverTest, ModifyGTestFlags) { VerifyAndModifyFlags(); }
1685TEST_F(GTestFlagSaverTest, VerifyGTestFlags) { VerifyAndModifyFlags(); }
1690static void SetEnv(
const char* name,
const char*
value) {
1691#ifdef 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];
1707 new std::string((
Message() << name <<
"=" <<
value).GetString());
1712 putenv(
const_cast<char*
>(added_env[name]->c_str()));
1714#elif defined(GTEST_OS_WINDOWS)
1715 _putenv((
Message() << name <<
"=" <<
value).GetString().c_str());
1717 if (*
value ==
'\0') {
1720 setenv(name,
value, 1);
1725#ifndef GTEST_OS_WINDOWS_MOBILE
1734TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenVariableIsNotSet) {
1736 EXPECT_EQ(10, Int32FromGTestEnv(
"temp", 10));
1739#if !defined(GTEST_GET_INT32_FROM_ENV_)
1743TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenValueOverflows) {
1744 printf(
"(expecting 2 warnings)\n");
1747 EXPECT_EQ(20, Int32FromGTestEnv(
"temp", 20));
1750 EXPECT_EQ(30, Int32FromGTestEnv(
"temp", 30));
1755TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenValueIsInvalid) {
1756 printf(
"(expecting 2 warnings)\n");
1759 EXPECT_EQ(40, Int32FromGTestEnv(
"temp", 40));
1762 EXPECT_EQ(50, Int32FromGTestEnv(
"temp", 50));
1770TEST(Int32FromGTestEnvTest, ParsesAndReturnsValidValue) {
1772 EXPECT_EQ(123, Int32FromGTestEnv(
"temp", 0));
1775 EXPECT_EQ(-321, Int32FromGTestEnv(
"temp", 0));
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;
1834#ifndef GTEST_OS_WINDOWS_MOBILE
1835TEST(Int32FromEnvOrDieTest, ParsesAndReturnsValidValue) {
1846TEST(Int32FromEnvOrDieDeathTest, AbortsOnFailure) {
1854TEST(Int32FromEnvOrDieDeathTest, AbortsOnInt32Overflow) {
1862TEST(ShouldRunTestOnShardTest, IsPartitionWhenThereIsOneShard) {
1872 void SetUp()
override {
1877 void TearDown()
override {
1878 SetEnv(index_var_,
"");
1879 SetEnv(total_var_,
"");
1882 const char* index_var_;
1883 const char* total_var_;
1888TEST_F(ShouldShardTest, ReturnsFalseWhenNeitherEnvVarIsSet) {
1889 SetEnv(index_var_,
"");
1890 SetEnv(total_var_,
"");
1892 EXPECT_FALSE(ShouldShard(total_var_, index_var_,
false));
1893 EXPECT_FALSE(ShouldShard(total_var_, index_var_,
true));
1897TEST_F(ShouldShardTest, ReturnsFalseWhenTotalShardIsOne) {
1898 SetEnv(index_var_,
"0");
1899 SetEnv(total_var_,
"1");
1900 EXPECT_FALSE(ShouldShard(total_var_, index_var_,
false));
1901 EXPECT_FALSE(ShouldShard(total_var_, index_var_,
true));
1907#ifndef GTEST_OS_WINDOWS_MOBILE
1908TEST_F(ShouldShardTest, WorksWhenShardEnvVarsAreValid) {
1909 SetEnv(index_var_,
"4");
1910 SetEnv(total_var_,
"22");
1911 EXPECT_TRUE(ShouldShard(total_var_, index_var_,
false));
1912 EXPECT_FALSE(ShouldShard(total_var_, index_var_,
true));
1914 SetEnv(index_var_,
"8");
1915 SetEnv(total_var_,
"9");
1916 EXPECT_TRUE(ShouldShard(total_var_, index_var_,
false));
1917 EXPECT_FALSE(ShouldShard(total_var_, index_var_,
true));
1919 SetEnv(index_var_,
"0");
1920 SetEnv(total_var_,
"9");
1921 EXPECT_TRUE(ShouldShard(total_var_, index_var_,
false));
1922 EXPECT_FALSE(ShouldShard(total_var_, index_var_,
true));
1928typedef ShouldShardTest ShouldShardDeathTest;
1930TEST_F(ShouldShardDeathTest, AbortsWhenShardingEnvVarsAreInvalid) {
1931 SetEnv(index_var_,
"4");
1932 SetEnv(total_var_,
"4");
1935 SetEnv(index_var_,
"4");
1936 SetEnv(total_var_,
"-2");
1939 SetEnv(index_var_,
"5");
1940 SetEnv(total_var_,
"");
1943 SetEnv(index_var_,
"");
1944 SetEnv(total_var_,
"5");
1950TEST(ShouldRunTestOnShardTest, IsPartitionWhenThereAreFiveShards) {
1952 const int num_tests = 17;
1953 const int num_shards = 5;
1956 for (
int test_id = 0; test_id < num_tests; test_id++) {
1957 int prev_selected_shard_index = -1;
1958 for (
int shard_index = 0; shard_index < num_shards; shard_index++) {
1959 if (ShouldRunTestOnShard(num_shards, shard_index, test_id)) {
1960 if (prev_selected_shard_index < 0) {
1961 prev_selected_shard_index = shard_index;
1963 ADD_FAILURE() <<
"Shard " << prev_selected_shard_index <<
" and "
1964 << shard_index <<
" are both selected to run test "
1973 for (
int shard_index = 0; shard_index < num_shards; shard_index++) {
1974 int num_tests_on_shard = 0;
1975 for (
int test_id = 0; test_id < num_tests; test_id++) {
1976 num_tests_on_shard +=
1977 ShouldRunTestOnShard(num_shards, shard_index, test_id);
1979 EXPECT_GE(num_tests_on_shard, num_tests / num_shards);
1993TEST(UnitTestTest, CanGetOriginalWorkingDir) {
1994 ASSERT_TRUE(UnitTest::GetInstance()->original_working_dir() !=
nullptr);
1995 EXPECT_STRNE(UnitTest::GetInstance()->original_working_dir(),
"");
1998TEST(UnitTestTest, ReturnsPlausibleTimestamp) {
1999 EXPECT_LT(0, UnitTest::GetInstance()->start_timestamp());
2000 EXPECT_LE(UnitTest::GetInstance()->start_timestamp(), GetTimeInMillis());
2006void ExpectNonFatalFailureRecordingPropertyWithReservedKey(
2007 const TestResult& test_result,
const char* key) {
2010 <<
"Property for key '" << key <<
"' recorded unexpectedly.";
2013void ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2015 const TestInfo* test_info = UnitTest::GetInstance()->current_test_info();
2017 ExpectNonFatalFailureRecordingPropertyWithReservedKey(*test_info->
result(),
2021void ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2024 UnitTest::GetInstance()->current_test_suite();
2026 ExpectNonFatalFailureRecordingPropertyWithReservedKey(
2030void ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2032 ExpectNonFatalFailureRecordingPropertyWithReservedKey(
2033 UnitTest::GetInstance()->ad_hoc_test_result(), key);
2039class UnitTestRecordPropertyTest
2042 static void SetUpTestSuite() {
2043 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2045 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2047 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2049 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2051 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2053 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2056 Test::RecordProperty(
"test_case_key_1",
"1");
2059 UnitTest::GetInstance()->current_test_suite();
2072TEST_F(UnitTestRecordPropertyTest, OnePropertyFoundWhenAdded) {
2073 UnitTestRecordProperty(
"key_1",
"1");
2075 ASSERT_EQ(1, unit_test_.ad_hoc_test_result().test_property_count());
2078 unit_test_.ad_hoc_test_result().GetTestProperty(0).key());
2079 EXPECT_STREQ(
"1", unit_test_.ad_hoc_test_result().GetTestProperty(0).value());
2083TEST_F(UnitTestRecordPropertyTest, MultiplePropertiesFoundWhenAdded) {
2084 UnitTestRecordProperty(
"key_1",
"1");
2085 UnitTestRecordProperty(
"key_2",
"2");
2087 ASSERT_EQ(2, unit_test_.ad_hoc_test_result().test_property_count());
2090 unit_test_.ad_hoc_test_result().GetTestProperty(0).key());
2091 EXPECT_STREQ(
"1", unit_test_.ad_hoc_test_result().GetTestProperty(0).value());
2094 unit_test_.ad_hoc_test_result().GetTestProperty(1).key());
2095 EXPECT_STREQ(
"2", unit_test_.ad_hoc_test_result().GetTestProperty(1).value());
2099TEST_F(UnitTestRecordPropertyTest, OverridesValuesForDuplicateKeys) {
2100 UnitTestRecordProperty(
"key_1",
"1");
2101 UnitTestRecordProperty(
"key_2",
"2");
2102 UnitTestRecordProperty(
"key_1",
"12");
2103 UnitTestRecordProperty(
"key_2",
"22");
2105 ASSERT_EQ(2, unit_test_.ad_hoc_test_result().test_property_count());
2108 unit_test_.ad_hoc_test_result().GetTestProperty(0).key());
2110 unit_test_.ad_hoc_test_result().GetTestProperty(0).value());
2113 unit_test_.ad_hoc_test_result().GetTestProperty(1).key());
2115 unit_test_.ad_hoc_test_result().GetTestProperty(1).value());
2118TEST_F(UnitTestRecordPropertyTest,
2119 AddFailureInsideTestsWhenUsingTestSuiteReservedKeys) {
2120 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
"name");
2121 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2123 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2125 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
"status");
2126 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
"time");
2127 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2131TEST_F(UnitTestRecordPropertyTest,
2132 AddRecordWithReservedKeysGeneratesCorrectPropertyList) {
2134 Test::RecordProperty(
"name",
"1"),
2135 "'classname', 'name', 'status', 'time', 'type_param', 'value_param',"
2136 " 'file', and 'line' are reserved");
2139class UnitTestRecordPropertyTestEnvironment :
public Environment {
2141 void TearDown()
override {
2142 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2144 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2146 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2148 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2150 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2152 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2154 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2156 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2174bool IsEven(
int n) {
return (n % 2) == 0; }
2177struct IsEvenFunctor {
2178 bool operator()(
int n) {
return IsEven(n); }
2183AssertionResult AssertIsEven(
const char* expr,
int n) {
2185 return AssertionSuccess();
2189 msg << expr <<
" evaluates to " << n <<
", which is not even.";
2190 return AssertionFailure(msg);
2195AssertionResult ResultIsEven(
int n) {
2197 return AssertionSuccess() << n <<
" is even";
2199 return AssertionFailure() << n <<
" is odd";
2205AssertionResult ResultIsEvenNoExplanation(
int n) {
2207 return AssertionSuccess();
2209 return AssertionFailure() << n <<
" is odd";
2214struct AssertIsEvenFunctor {
2215 AssertionResult operator()(
const char* expr,
int n) {
2216 return AssertIsEven(expr, n);
2221bool SumIsEven2(
int n1,
int n2) {
return IsEven(n1 + n2); }
2225struct SumIsEven3Functor {
2226 bool operator()(
int n1,
int n2,
int n3) {
return IsEven(n1 + n2 + n3); }
2231AssertionResult AssertSumIsEven4(
const char* e1,
const char* e2,
const char* e3,
2232 const char* e4,
int n1,
int n2,
int n3,
2234 const int sum = n1 + n2 + n3 + n4;
2236 return AssertionSuccess();
2240 msg << e1 <<
" + " << e2 <<
" + " << e3 <<
" + " << e4 <<
" (" << n1 <<
" + "
2241 << n2 <<
" + " << n3 <<
" + " << n4 <<
") evaluates to " << sum
2242 <<
", which is not even.";
2243 return AssertionFailure(msg);
2248struct AssertSumIsEven5Functor {
2249 AssertionResult operator()(
const char* e1,
const char* e2,
const char* e3,
2250 const char* e4,
const char* e5,
int n1,
int n2,
2251 int n3,
int n4,
int n5) {
2252 const int sum = n1 + n2 + n3 + n4 + n5;
2254 return AssertionSuccess();
2258 msg << e1 <<
" + " << e2 <<
" + " << e3 <<
" + " << e4 <<
" + " << e5
2259 <<
" (" << n1 <<
" + " << n2 <<
" + " << n3 <<
" + " << n4 <<
" + "
2260 << n5 <<
") evaluates to " << sum <<
", which is not even.";
2261 return AssertionFailure(msg);
2268TEST(Pred1Test, WithoutFormat) {
2270 EXPECT_PRED1(IsEvenFunctor(), 2) <<
"This failure is UNEXPECTED!";
2276 EXPECT_PRED1(IsEven, 5) <<
"This failure is expected.";
2278 "This failure is expected.");
2283TEST(Pred1Test, WithFormat) {
2287 <<
"This failure is UNEXPECTED!";
2292 "n evaluates to 5, which is not even.");
2297 "This failure is expected.");
2302TEST(Pred1Test, SingleEvaluationOnFailure) {
2306 EXPECT_EQ(1, n) <<
"The argument is not evaluated exactly once.";
2312 <<
"This failure is expected.";
2314 "This failure is expected.");
2315 EXPECT_EQ(2, n) <<
"The argument is not evaluated exactly once.";
2321TEST(PredTest, WithoutFormat) {
2323 ASSERT_PRED2(SumIsEven2, 2, 4) <<
"This failure is UNEXPECTED!";
2331 EXPECT_PRED2(SumIsEven2, n1, n2) <<
"This failure is expected.";
2333 "This failure is expected.");
2338 "evaluates to false");
2342TEST(PredTest, WithFormat) {
2345 <<
"This failure is UNEXPECTED!";
2357 "evaluates to 13, which is not even.");
2361 <<
"This failure is expected.";
2363 "This failure is expected.");
2368TEST(PredTest, SingleEvaluationOnFailure) {
2373 EXPECT_EQ(1, n1) <<
"Argument 1 is not evaluated exactly once.";
2374 EXPECT_EQ(1, n2) <<
"Argument 2 is not evaluated exactly once.";
2382 <<
"This failure is UNEXPECTED!";
2383 EXPECT_EQ(1, n1) <<
"Argument 1 is not evaluated exactly once.";
2384 EXPECT_EQ(1, n2) <<
"Argument 2 is not evaluated exactly once.";
2385 EXPECT_EQ(1, n3) <<
"Argument 3 is not evaluated exactly once.";
2386 EXPECT_EQ(1, n4) <<
"Argument 4 is not evaluated exactly once.";
2387 EXPECT_EQ(1, n5) <<
"Argument 5 is not evaluated exactly once.";
2394 <<
"This failure is expected.";
2396 "This failure is expected.");
2397 EXPECT_EQ(1, n1) <<
"Argument 1 is not evaluated exactly once.";
2398 EXPECT_EQ(1, n2) <<
"Argument 2 is not evaluated exactly once.";
2399 EXPECT_EQ(1, n3) <<
"Argument 3 is not evaluated exactly once.";
2402 n1 = n2 = n3 = n4 = 0;
2407 "evaluates to 1, which is not even.");
2408 EXPECT_EQ(1, n1) <<
"Argument 1 is not evaluated exactly once.";
2409 EXPECT_EQ(1, n2) <<
"Argument 2 is not evaluated exactly once.";
2410 EXPECT_EQ(1, n3) <<
"Argument 3 is not evaluated exactly once.";
2411 EXPECT_EQ(1, n4) <<
"Argument 4 is not evaluated exactly once.";
2415TEST(PredTest, ExpectPredEvalFailure) {
2416 std::set<int> set_a = {2, 1, 3, 4, 5};
2417 std::set<int> set_b = {0, 4, 8};
2418 const auto compare_sets = [](std::set<int>, std::set<int>) {
return false; };
2421 "compare_sets(set_a, set_b) evaluates to false, where\nset_a evaluates "
2422 "to { 1, 2, 3, 4, 5 }\nset_b evaluates to { 0, 4, 8 }");
2428bool IsPositive(
double x) {
return x > 0; }
2430template <
typename T>
2431bool IsNegative(
T x) {
2435template <
typename T1,
typename T2>
2436bool GreaterThan(T1 x1, T2 x2) {
2442TEST(PredicateAssertionTest, AcceptsOverloadedFunction) {
2450TEST(PredicateAssertionTest, AcceptsTemplateFunction) {
2460AssertionResult IsPositiveFormat(
const char* ,
int n) {
2461 return n > 0 ? AssertionSuccess() : AssertionFailure(
Message() <<
"Failure");
2464AssertionResult IsPositiveFormat(
const char* ,
double x) {
2465 return x > 0 ? AssertionSuccess() : AssertionFailure(
Message() <<
"Failure");
2468template <
typename T>
2469AssertionResult IsNegativeFormat(
const char* ,
T x) {
2470 return x < 0 ? AssertionSuccess() : AssertionFailure(
Message() <<
"Failure");
2473template <
typename T1,
typename T2>
2474AssertionResult EqualsFormat(
const char* ,
const char* ,
2475 const T1& x1,
const T2& x2) {
2476 return x1 == x2 ? AssertionSuccess()
2477 : AssertionFailure(
Message() <<
"Failure");
2482TEST(PredicateFormatAssertionTest, AcceptsOverloadedFunction) {
2489TEST(PredicateFormatAssertionTest, AcceptsTemplateFunction) {
2498 const char*
const p1 =
"good";
2502 const char p2[] =
"good";
2509TEST(StringAssertionTest, ASSERT_STREQ_Null) {
2510 ASSERT_STREQ(
static_cast<const char*
>(
nullptr),
nullptr);
2515TEST(StringAssertionTest, ASSERT_STREQ_Null2) {
2553TEST(StringAssertionTest, STREQ_Wide) {
2555 ASSERT_STREQ(
static_cast<const wchar_t*
>(
nullptr),
nullptr);
2575 EXPECT_STREQ(L
"abc\x8119", L
"abc\x8121") <<
"Expected failure";
2577 "Expected failure");
2581TEST(StringAssertionTest, STRNE_Wide) {
2585 EXPECT_STRNE(
static_cast<const wchar_t*
>(
nullptr),
nullptr);
2605 ASSERT_STRNE(L
"abc\x8119", L
"abc\x8120") <<
"This shouldn't happen";
2612TEST(IsSubstringTest, ReturnsCorrectResultForCString) {
2615 EXPECT_FALSE(IsSubstring(
"",
"",
"needle",
"haystack"));
2617 EXPECT_TRUE(IsSubstring(
"",
"",
static_cast<const char*
>(
nullptr),
nullptr));
2618 EXPECT_TRUE(IsSubstring(
"",
"",
"needle",
"two needles"));
2623TEST(IsSubstringTest, ReturnsCorrectResultForWideCString) {
2626 EXPECT_FALSE(IsSubstring(
"",
"", L
"needle", L
"haystack"));
2629 IsSubstring(
"",
"",
static_cast<const wchar_t*
>(
nullptr),
nullptr));
2630 EXPECT_TRUE(IsSubstring(
"",
"", L
"needle", L
"two needles"));
2635TEST(IsSubstringTest, GeneratesCorrectMessageForCString) {
2637 "Value of: needle_expr\n"
2638 " Actual: \"needle\"\n"
2639 "Expected: a substring of haystack_expr\n"
2640 "Which is: \"haystack\"",
2641 IsSubstring(
"needle_expr",
"haystack_expr",
"needle",
"haystack")
2642 .failure_message());
2647TEST(IsSubstringTest, ReturnsCorrectResultsForStdString) {
2648 EXPECT_TRUE(IsSubstring(
"",
"", std::string(
"hello"),
"ahellob"));
2649 EXPECT_FALSE(IsSubstring(
"",
"",
"hello", std::string(
"world")));
2652#if GTEST_HAS_STD_WSTRING
2655TEST(IsSubstringTest, ReturnsCorrectResultForStdWstring) {
2656 EXPECT_TRUE(IsSubstring(
"",
"", ::std::wstring(L
"needle"), L
"two needles"));
2657 EXPECT_FALSE(IsSubstring(
"",
"", L
"needle", ::std::wstring(L
"haystack")));
2662TEST(IsSubstringTest, GeneratesCorrectMessageForWstring) {
2664 "Value of: needle_expr\n"
2665 " Actual: L\"needle\"\n"
2666 "Expected: a substring of haystack_expr\n"
2667 "Which is: L\"haystack\"",
2668 IsSubstring(
"needle_expr",
"haystack_expr", ::std::wstring(L
"needle"),
2670 .failure_message());
2679TEST(IsNotSubstringTest, ReturnsCorrectResultForCString) {
2680 EXPECT_TRUE(IsNotSubstring(
"",
"",
"needle",
"haystack"));
2681 EXPECT_FALSE(IsNotSubstring(
"",
"",
"needle",
"two needles"));
2686TEST(IsNotSubstringTest, ReturnsCorrectResultForWideCString) {
2687 EXPECT_TRUE(IsNotSubstring(
"",
"", L
"needle", L
"haystack"));
2688 EXPECT_FALSE(IsNotSubstring(
"",
"", L
"needle", L
"two needles"));
2693TEST(IsNotSubstringTest, GeneratesCorrectMessageForWideCString) {
2695 "Value of: needle_expr\n"
2696 " Actual: L\"needle\"\n"
2697 "Expected: not a substring of haystack_expr\n"
2698 "Which is: L\"two needles\"",
2699 IsNotSubstring(
"needle_expr",
"haystack_expr", L
"needle", L
"two needles")
2700 .failure_message());
2705TEST(IsNotSubstringTest, ReturnsCorrectResultsForStdString) {
2706 EXPECT_FALSE(IsNotSubstring(
"",
"", std::string(
"hello"),
"ahellob"));
2707 EXPECT_TRUE(IsNotSubstring(
"",
"",
"hello", std::string(
"world")));
2712TEST(IsNotSubstringTest, GeneratesCorrectMessageForStdString) {
2714 "Value of: needle_expr\n"
2715 " Actual: \"needle\"\n"
2716 "Expected: not a substring of haystack_expr\n"
2717 "Which is: \"two needles\"",
2718 IsNotSubstring(
"needle_expr",
"haystack_expr", ::std::string(
"needle"),
2720 .failure_message());
2723#if GTEST_HAS_STD_WSTRING
2727TEST(IsNotSubstringTest, ReturnsCorrectResultForStdWstring) {
2729 IsNotSubstring(
"",
"", ::std::wstring(L
"needle"), L
"two needles"));
2730 EXPECT_TRUE(IsNotSubstring(
"",
"", L
"needle", ::std::wstring(L
"haystack")));
2737template <
typename RawType>
2738class FloatingPointTest :
public Test {
2742 RawType close_to_positive_zero;
2743 RawType close_to_negative_zero;
2744 RawType further_from_negative_zero;
2746 RawType close_to_one;
2747 RawType further_from_one;
2750 RawType close_to_infinity;
2751 RawType further_from_infinity;
2758 typedef typename Floating::Bits Bits;
2760 void SetUp()
override {
2761 const uint32_t max_ulps = Floating::kMaxUlps;
2764 const Bits zero_bits = Floating(0).
bits();
2767 values_.close_to_positive_zero =
2768 Floating::ReinterpretBits(zero_bits + max_ulps / 2);
2769 values_.close_to_negative_zero =
2770 -Floating::ReinterpretBits(zero_bits + max_ulps - max_ulps / 2);
2771 values_.further_from_negative_zero =
2772 -Floating::ReinterpretBits(zero_bits + max_ulps + 1 - max_ulps / 2);
2775 const Bits one_bits = Floating(1).bits();
2778 values_.close_to_one = Floating::ReinterpretBits(one_bits + max_ulps);
2779 values_.further_from_one =
2780 Floating::ReinterpretBits(one_bits + max_ulps + 1);
2783 values_.infinity = Floating::Infinity();
2786 const Bits infinity_bits = Floating(values_.infinity).bits();
2789 values_.close_to_infinity =
2790 Floating::ReinterpretBits(infinity_bits - max_ulps);
2791 values_.further_from_infinity =
2792 Floating::ReinterpretBits(infinity_bits - max_ulps - 1);
2797 values_.nan1 = Floating::ReinterpretBits(
2798 Floating::kExponentBitMask |
2799 (
static_cast<Bits
>(1) << (Floating::kFractionBitCount - 1)) | 1);
2800 values_.nan2 = Floating::ReinterpretBits(
2801 Floating::kExponentBitMask |
2802 (
static_cast<Bits
>(1) << (Floating::kFractionBitCount - 1)) | 200);
2805 void TestSize() {
EXPECT_EQ(
sizeof(RawType),
sizeof(Bits)); }
2807 static TestValues values_;
2810template <
typename RawType>
2811typename FloatingPointTest<RawType>::TestValues
2812 FloatingPointTest<RawType>::values_;
2815typedef FloatingPointTest<float> FloatTest;
2818TEST_F(FloatTest, Size) { TestSize(); }
2821TEST_F(FloatTest, Zeros) {
2832TEST_F(FloatTest, AlmostZeros) {
2839 static const FloatTest::TestValues& v = this->values_;
2847 ASSERT_FLOAT_EQ(v.close_to_positive_zero, v.further_from_negative_zero);
2849 "v.further_from_negative_zero");
2853TEST_F(FloatTest, SmallDiff) {
2856 "values_.further_from_one");
2860TEST_F(FloatTest, LargeDiff) {
2868TEST_F(FloatTest, Infinity) {
2872 "-values_.infinity");
2888 static const FloatTest::TestValues& v = this->values_;
2898TEST_F(FloatTest, Reflexive) {
2905TEST_F(FloatTest, Commutative) {
2919 "The difference between 1.0f and 1.5f is 0.5, "
2920 "which exceeds 0.25f");
2928 "The difference between 1.0f and 1.5f is 0.5, "
2929 "which exceeds 0.25f");
2933TEST_F(FloatTest, FloatLESucceeds) {
2942TEST_F(FloatTest, FloatLEFails) {
2945 "(2.0f) <= (1.0f)");
2952 "(values_.further_from_one) <= (1.0f)");
2958 "(values_.nan1) <= (values_.infinity)");
2963 "(-values_.infinity) <= (values_.nan1)");
2968 "(values_.nan1) <= (values_.nan1)");
2972typedef FloatingPointTest<double> DoubleTest;
2975TEST_F(DoubleTest, Size) { TestSize(); }
2978TEST_F(DoubleTest, Zeros) {
2989TEST_F(DoubleTest, AlmostZeros) {
2996 static const DoubleTest::TestValues& v = this->values_;
3005 v.further_from_negative_zero);
3007 "v.further_from_negative_zero");
3011TEST_F(DoubleTest, SmallDiff) {
3014 "values_.further_from_one");
3018TEST_F(DoubleTest, LargeDiff) {
3026TEST_F(DoubleTest, Infinity) {
3030 "-values_.infinity");
3040 static const DoubleTest::TestValues& v = this->values_;
3050TEST_F(DoubleTest, Reflexive) {
3057TEST_F(DoubleTest, Commutative) {
3071 "The difference between 1.0 and 1.5 is 0.5, "
3072 "which exceeds 0.25");
3076 EXPECT_NEAR(4.2934311416234112e+18, 4.2934311416234107e+18, 1.0),
3077 "The abs_error parameter 1.0 evaluates to 1 which is smaller than the "
3078 "minimum distance between doubles for numbers of this magnitude which is "
3087 "The difference between 1.0 and 1.5 is 0.5, "
3088 "which exceeds 0.25");
3092TEST_F(DoubleTest, DoubleLESucceeds) {
3101TEST_F(DoubleTest, DoubleLEFails) {
3111 "(values_.further_from_one) <= (1.0)");
3117 "(values_.nan1) <= (values_.infinity)");
3122 " (-values_.infinity) <= (values_.nan1)");
3127 "(values_.nan1) <= (values_.nan1)");
3136 FAIL() <<
"Unexpected failure: Disabled test should not be run.";
3145TEST(DISABLED_TestSuite, TestShouldNotRun) {
3146 FAIL() <<
"Unexpected failure: Test in disabled test case should not be run.";
3151TEST(DISABLED_TestSuite, DISABLED_TestShouldNotRun) {
3152 FAIL() <<
"Unexpected failure: Test in disabled test case should not be run.";
3157class DisabledTestsTest :
public Test {
3159 static void SetUpTestSuite() {
3160 FAIL() <<
"Unexpected failure: All tests disabled in test case. "
3161 "SetUpTestSuite() should not be called.";
3164 static void TearDownTestSuite() {
3165 FAIL() <<
"Unexpected failure: All tests disabled in test case. "
3166 "TearDownTestSuite() should not be called.";
3170TEST_F(DisabledTestsTest, DISABLED_TestShouldNotRun_1) {
3171 FAIL() <<
"Unexpected failure: Disabled test should not be run.";
3174TEST_F(DisabledTestsTest, DISABLED_TestShouldNotRun_2) {
3175 FAIL() <<
"Unexpected failure: Disabled test should not be run.";
3180template <
typename T>
3187 FAIL() <<
"Unexpected failure: Disabled typed test should not run.";
3190template <
typename T>
3191class DISABLED_TypedTest :
public Test {};
3195TYPED_TEST(DISABLED_TypedTest, ShouldNotRun) {
3196 FAIL() <<
"Unexpected failure: Disabled typed test should not run.";
3201template <
typename T>
3207 FAIL() <<
"Unexpected failure: "
3208 <<
"Disabled type-parameterized test should not run.";
3215template <
typename T>
3216class DISABLED_TypedTestP :
public Test {};
3221 FAIL() <<
"Unexpected failure: "
3222 <<
"Disabled type-parameterized test should not run.";
3231class SingleEvaluationTest :
public Test {
3236 static void CompareAndIncrementCharPtrs() {
ASSERT_STREQ(p1_++, p2_++); }
3240 static void CompareAndIncrementInts() {
ASSERT_NE(
a_++,
b_++); }
3243 SingleEvaluationTest() {
3250 static const char*
const s1_;
3251 static const char*
const s2_;
3252 static const char* p1_;
3253 static const char* p2_;
3259const char*
const SingleEvaluationTest::s1_ =
"01234";
3260const char*
const SingleEvaluationTest::s2_ =
"abcde";
3261const char* SingleEvaluationTest::p1_;
3262const char* SingleEvaluationTest::p2_;
3263int SingleEvaluationTest::a_;
3264int SingleEvaluationTest::b_;
3268TEST_F(SingleEvaluationTest, FailedASSERT_STREQ) {
3276TEST_F(SingleEvaluationTest, ASSERT_STR) {
3290TEST_F(SingleEvaluationTest, FailedASSERT_NE) {
3292 "(a_++) != (b_++)");
3298TEST_F(SingleEvaluationTest, OtherCases) {
3327#if GTEST_HAS_EXCEPTIONS
3331#define ERROR_DESC "std::runtime_error"
3335#define ERROR_DESC "an std::exception-derived error"
3339void ThrowAnInteger() {
throw 1; }
3340void ThrowRuntimeError(
const char* what) {
throw std::runtime_error(what); }
3343TEST_F(SingleEvaluationTest, ExceptionTests) {
3360 "throws a different type");
3367 ThrowRuntimeError(
"A description");
3370 "throws " ERROR_DESC
3371 " with description \"A description\"");
3405class NoFatalFailureTest :
public Test {
3408 void FailsNonFatal() {
ADD_FAILURE() <<
"some non-fatal failure"; }
3409 void Fails() {
FAIL() <<
"some fatal failure"; }
3411 void DoAssertNoFatalFailureOnFails() {
3416 void DoExpectNoFatalFailureOnFails() {
3422TEST_F(NoFatalFailureTest, NoFailure) {
3427TEST_F(NoFatalFailureTest, NonFatalIsNoFailure) {
3429 "some non-fatal failure");
3431 "some non-fatal failure");
3434TEST_F(NoFatalFailureTest, AssertNoFatalFailureOnFatalFailure) {
3435 TestPartResultArray gtest_failures;
3437 ScopedFakeTestPartResultReporter gtest_reporter(>est_failures);
3438 DoAssertNoFatalFailureOnFails();
3441 EXPECT_EQ(TestPartResult::kFatalFailure,
3442 gtest_failures.GetTestPartResult(0).type());
3443 EXPECT_EQ(TestPartResult::kFatalFailure,
3444 gtest_failures.GetTestPartResult(1).type());
3446 gtest_failures.GetTestPartResult(0).message());
3448 gtest_failures.GetTestPartResult(1).message());
3451TEST_F(NoFatalFailureTest, ExpectNoFatalFailureOnFatalFailure) {
3452 TestPartResultArray gtest_failures;
3454 ScopedFakeTestPartResultReporter gtest_reporter(>est_failures);
3455 DoExpectNoFatalFailureOnFails();
3458 EXPECT_EQ(TestPartResult::kFatalFailure,
3459 gtest_failures.GetTestPartResult(0).type());
3460 EXPECT_EQ(TestPartResult::kNonFatalFailure,
3461 gtest_failures.GetTestPartResult(1).type());
3462 EXPECT_EQ(TestPartResult::kNonFatalFailure,
3463 gtest_failures.GetTestPartResult(2).type());
3465 gtest_failures.GetTestPartResult(0).message());
3467 gtest_failures.GetTestPartResult(1).message());
3469 gtest_failures.GetTestPartResult(2).message());
3472TEST_F(NoFatalFailureTest, MessageIsStreamable) {
3473 TestPartResultArray gtest_failures;
3475 ScopedFakeTestPartResultReporter gtest_reporter(>est_failures);
3479 EXPECT_EQ(TestPartResult::kFatalFailure,
3480 gtest_failures.GetTestPartResult(0).type());
3481 EXPECT_EQ(TestPartResult::kNonFatalFailure,
3482 gtest_failures.GetTestPartResult(1).type());
3484 gtest_failures.GetTestPartResult(0).message());
3486 gtest_failures.GetTestPartResult(1).message());
3491std::string EditsToString(
const std::vector<EditType>& edits) {
3493 for (
size_t i = 0;
i < edits.size(); ++
i) {
3494 static const char kEdits[] =
" +-/";
3495 out.append(1, kEdits[edits[
i]]);
3500std::vector<size_t> CharsToIndices(
const std::string& str) {
3501 std::vector<size_t> out;
3502 for (
size_t i = 0;
i < str.size(); ++
i) {
3503 out.push_back(
static_cast<size_t>(str[
i]));
3508std::vector<std::string> CharsToLines(
const std::string& str) {
3509 std::vector<std::string> out;
3510 for (
size_t i = 0;
i < str.size(); ++
i) {
3511 out.push_back(str.substr(
i, 1));
3516TEST(EditDistance, TestSuites) {
3521 const char* expected_edits;
3522 const char* expected_diff;
3524 static const Case kCases[] = {
3526 {__LINE__,
"A",
"A",
" ",
""},
3527 {__LINE__,
"ABCDE",
"ABCDE",
" ",
""},
3529 {__LINE__,
"X",
"XA",
" +",
"@@ +1,2 @@\n X\n+A\n"},
3530 {__LINE__,
"X",
"XABCD",
" ++++",
"@@ +1,5 @@\n X\n+A\n+B\n+C\n+D\n"},
3532 {__LINE__,
"XA",
"X",
" -",
"@@ -1,2 @@\n X\n-A\n"},
3533 {__LINE__,
"XABCD",
"X",
" ----",
"@@ -1,5 @@\n X\n-A\n-B\n-C\n-D\n"},
3535 {__LINE__,
"A",
"a",
"/",
"@@ -1,1 +1,1 @@\n-A\n+a\n"},
3536 {__LINE__,
"ABCD",
"abcd",
"////",
3537 "@@ -1,4 +1,4 @@\n-A\n-B\n-C\n-D\n+a\n+b\n+c\n+d\n"},
3539 {__LINE__,
"ABCDEFGH",
"ABXEGH1",
" -/ - +",
3540 "@@ -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"},
3541 {__LINE__,
"AAAABCCCC",
"ABABCDCDC",
"- / + / ",
3542 "@@ -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"},
3543 {__LINE__,
"ABCDE",
"BCDCD",
"- +/",
3544 "@@ -1,5 +1,5 @@\n-A\n B\n C\n D\n-E\n+C\n+D\n"},
3545 {__LINE__,
"ABCDEFGHIJKL",
"BCDCDEFGJKLJK",
"- ++ -- ++",
3546 "@@ -1,4 +1,5 @@\n-A\n B\n+C\n+D\n C\n D\n"
3547 "@@ -6,7 +7,7 @@\n F\n G\n-H\n-I\n J\n K\n L\n+J\n+K\n"},
3549 for (
const Case* c = kCases; c->left; ++c) {
3551 EditsToString(CalculateOptimalEdits(CharsToIndices(c->left),
3552 CharsToIndices(c->right))))
3553 <<
"Left <" << c->left <<
"> Right <" << c->right <<
"> Edits <"
3554 << EditsToString(CalculateOptimalEdits(CharsToIndices(c->left),
3555 CharsToIndices(c->right)))
3557 EXPECT_TRUE(c->expected_diff == CreateUnifiedDiff(CharsToLines(c->left),
3558 CharsToLines(c->right)))
3559 <<
"Left <" << c->left <<
"> Right <" << c->right <<
"> Diff <"
3560 << CreateUnifiedDiff(CharsToLines(c->left), CharsToLines(c->right))
3566TEST(AssertionTest, EqFailure) {
3567 const std::string foo_val(
"5"), bar_val(
"6");
3568 const std::string msg1(
3569 EqFailure(
"foo",
"bar", foo_val, bar_val,
false).failure_message());
3571 "Expected equality of these values:\n"
3578 const std::string msg2(
3579 EqFailure(
"foo",
"6", foo_val, bar_val,
false).failure_message());
3581 "Expected equality of these values:\n"
3587 const std::string msg3(
3588 EqFailure(
"5",
"bar", foo_val, bar_val,
false).failure_message());
3590 "Expected equality of these values:\n"
3596 const std::string msg4(
3597 EqFailure(
"5",
"6", foo_val, bar_val,
false).failure_message());
3599 "Expected equality of these values:\n"
3604 const std::string msg5(
3605 EqFailure(
"foo",
"bar", std::string(
"\"x\""), std::string(
"\"y\""),
true)
3606 .failure_message());
3608 "Expected equality of these values:\n"
3610 " Which is: \"x\"\n"
3612 " Which is: \"y\"\n"
3617TEST(AssertionTest, EqFailureWithDiff) {
3618 const std::string left(
3619 "1\\n2XXX\\n3\\n5\\n6\\n7\\n8\\n9\\n10\\n11\\n12XXX\\n13\\n14\\n15");
3620 const std::string right(
3621 "1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n11\\n12\\n13\\n14");
3622 const std::string msg1(
3623 EqFailure(
"left",
"right", left, right,
false).failure_message());
3625 "Expected equality of these values:\n"
3628 "1\\n2XXX\\n3\\n5\\n6\\n7\\n8\\n9\\n10\\n11\\n12XXX\\n13\\n14\\n15\n"
3630 " Which is: 1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n11\\n12\\n13\\n14\n"
3631 "With diff:\n@@ -1,5 +1,6 @@\n 1\n-2XXX\n+2\n 3\n+4\n 5\n 6\n"
3632 "@@ -7,8 +8,6 @@\n 8\n 9\n-10\n 11\n-12XXX\n+12\n 13\n 14\n-15\n",
3637TEST(AssertionTest, AppendUserMessage) {
3638 const std::string
foo(
"foo");
3649#pragma option push -w-ccc -w-rch
3659TEST(AssertionTest, AssertTrueWithAssertionResult) {
3664 "Value of: ResultIsEven(3)\n"
3665 " Actual: false (3 is odd)\n"
3670 "Value of: ResultIsEvenNoExplanation(3)\n"
3671 " Actual: false (3 is odd)\n"
3685TEST(AssertionTest, AssertFalseWithAssertionResult) {
3690 "Value of: ResultIsEven(2)\n"
3691 " Actual: true (2 is even)\n"
3696 "Value of: ResultIsEvenNoExplanation(2)\n"
3709TEST(ExpectTest, ASSERT_EQ_Double) {
3722 "Expected equality of these values:\n"
3730TEST(AssertionTest, ASSERT_EQ_NULL) {
3732 const char*
p =
nullptr;
3744TEST(ExpectTest, ASSERT_EQ_0) {
3758 "Expected: ('a') != ('a'), "
3759 "actual: 'a' (97, 0x61) vs 'a' (97, 0x61)");
3788#if GTEST_HAS_EXCEPTIONS
3790void ThrowNothing() {}
3801 "Expected: ThrowAnInteger() throws an exception of type bool.\n"
3802 " Actual: it throws a different type.");
3804 ASSERT_THROW(ThrowRuntimeError(
"A description"), std::logic_error),
3805 "Expected: ThrowRuntimeError(\"A description\") "
3806 "throws an exception of type std::logic_error.\n "
3807 "Actual: it throws " ERROR_DESC
3809 "with description \"A description\".");
3814 "Expected: ThrowNothing() throws an exception of type bool.\n"
3815 " Actual: it throws nothing.");
3822 "Expected: ThrowAnInteger() doesn't throw an exception."
3823 "\n Actual: it throws.");
3825 "Expected: ThrowRuntimeError(\"A description\") "
3826 "doesn't throw an exception.\n "
3827 "Actual: it throws " ERROR_DESC
3829 "with description \"A description\".");
3836 "Expected: ThrowNothing() throws an exception.\n"
3837 " Actual: it doesn't.");
3844TEST(AssertionTest, AssertPrecedence) {
3846 bool false_value =
false;
3854TEST(AssertionTest, NonFixtureSubroutine) {
3861 explicit Uncopyable(
int a_value) : value_(a_value) {}
3863 int value()
const {
return value_; }
3864 bool operator==(
const Uncopyable& rhs)
const {
3865 return value() == rhs.value();
3871 Uncopyable(
const Uncopyable&);
3876::std::ostream&
operator<<(::std::ostream& os,
const Uncopyable&
value) {
3877 return os <<
value.value();
3880bool IsPositiveUncopyable(
const Uncopyable&
x) {
return x.value() > 0; }
3883void TestAssertNonPositive() {
3888void TestAssertEqualsUncopyable() {
3895TEST(AssertionTest, AssertWorksWithUncopyableObject) {
3900 TestAssertNonPositive(),
3901 "IsPositiveUncopyable(y) evaluates to false, where\ny evaluates to -1");
3903 "Expected equality of these values:\n"
3904 " x\n Which is: 5\n y\n Which is: -1");
3908TEST(AssertionTest, ExpectWorksWithUncopyableObject) {
3914 "IsPositiveUncopyable(y) evaluates to false, where\ny evaluates to -1");
3917 "Expected equality of these values:\n"
3918 " x\n Which is: 5\n y\n Which is: -1");
3921enum NamedEnum { kE1 = 0, kE2 = 1 };
3923TEST(AssertionTest, NamedEnum) {
3931#if !defined(__SUNPRO_CC) && !defined(__HP_aCC)
3937#ifdef GTEST_OS_LINUX
3960#ifdef GTEST_OS_LINUX
3962 EXPECT_EQ(
static_cast<int>(kCaseA),
static_cast<int>(kCaseB));
3994#ifdef GTEST_OS_WINDOWS
3996static HRESULT UnexpectedHRESULTFailure() {
return E_UNEXPECTED; }
3998static HRESULT OkHRESULTSuccess() {
return S_OK; }
4000static HRESULT FalseHRESULTSuccess() {
return S_FALSE; }
4006TEST(HRESULTAssertionTest, EXPECT_HRESULT_SUCCEEDED) {
4007 EXPECT_HRESULT_SUCCEEDED(S_OK);
4008 EXPECT_HRESULT_SUCCEEDED(S_FALSE);
4011 "Expected: (UnexpectedHRESULTFailure()) succeeds.\n"
4012 " Actual: 0x8000FFFF");
4015TEST(HRESULTAssertionTest, ASSERT_HRESULT_SUCCEEDED) {
4016 ASSERT_HRESULT_SUCCEEDED(S_OK);
4017 ASSERT_HRESULT_SUCCEEDED(S_FALSE);
4020 "Expected: (UnexpectedHRESULTFailure()) succeeds.\n"
4021 " Actual: 0x8000FFFF");
4024TEST(HRESULTAssertionTest, EXPECT_HRESULT_FAILED) {
4025 EXPECT_HRESULT_FAILED(E_UNEXPECTED);
4028 "Expected: (OkHRESULTSuccess()) fails.\n"
4031 "Expected: (FalseHRESULTSuccess()) fails.\n"
4035TEST(HRESULTAssertionTest, ASSERT_HRESULT_FAILED) {
4036 ASSERT_HRESULT_FAILED(E_UNEXPECTED);
4042 "Expected: (OkHRESULTSuccess()) fails.\n"
4047 "Expected: (FalseHRESULTSuccess()) fails.\n"
4052TEST(HRESULTAssertionTest, Streaming) {
4053 EXPECT_HRESULT_SUCCEEDED(S_OK) <<
"unexpected failure";
4054 ASSERT_HRESULT_SUCCEEDED(S_OK) <<
"unexpected failure";
4055 EXPECT_HRESULT_FAILED(E_UNEXPECTED) <<
"unexpected failure";
4056 ASSERT_HRESULT_FAILED(E_UNEXPECTED) <<
"unexpected failure";
4059 <<
"expected failure",
4060 "expected failure");
4066 <<
"expected failure",
4067 "expected failure");
4071 "expected failure");
4074 "expected failure");
4081#pragma GCC diagnostic push
4082#pragma GCC diagnostic ignored "-Wdangling-else"
4083#pragma GCC diagnostic ignored "-Wempty-body"
4084#pragma GCC diagnostic ignored "-Wpragmas"
4087TEST(AssertionSyntaxTest, BasicAssertionsBehavesLikeSingleStatement) {
4089 ASSERT_TRUE(
false) <<
"This should never be executed; "
4090 "It's a compilation test only.";
4105#pragma GCC diagnostic pop
4108#if GTEST_HAS_EXCEPTIONS
4111TEST(ExpectThrowTest, DoesNotGenerateUnreachableCodeWarning) {
4123TEST(ExpectThrowTest, DoesNotGenerateDuplicateCatchClauseWarning) {
4129#pragma GCC diagnostic push
4130#pragma GCC diagnostic ignored "-Wdangling-else"
4131#pragma GCC diagnostic ignored "-Wempty-body"
4132#pragma GCC diagnostic ignored "-Wpragmas"
4134TEST(AssertionSyntaxTest, ExceptionAssertionsBehavesLikeSingleStatement) {
4157#pragma GCC diagnostic pop
4164#pragma GCC diagnostic push
4165#pragma GCC diagnostic ignored "-Wdangling-else"
4166#pragma GCC diagnostic ignored "-Wempty-body"
4167#pragma GCC diagnostic ignored "-Wpragmas"
4169TEST(AssertionSyntaxTest, NoFatalFailureAssertionsBehavesLikeSingleStatement) {
4172 <<
"It's a compilation test only.";
4192#pragma GCC diagnostic pop
4196TEST(AssertionSyntaxTest, WorksWithSwitch) {
4206 EXPECT_FALSE(
false) <<
"EXPECT_FALSE failed in switch case";
4213 ASSERT_EQ(1, 1) <<
"ASSERT_EQ failed in default switch handler";
4221#if GTEST_HAS_EXCEPTIONS
4223void ThrowAString() {
throw "std::string"; }
4227TEST(AssertionSyntaxTest, WorksWithConst) {
4243 EXPECT_EQ(2, GetUnitTestImpl()->current_test_result()->total_part_count());
4247TEST(SuccessfulAssertionTest, EXPECT) {
4249 EXPECT_EQ(0, GetUnitTestImpl()->current_test_result()->total_part_count());
4253TEST(SuccessfulAssertionTest, EXPECT_STR) {
4255 EXPECT_EQ(0, GetUnitTestImpl()->current_test_result()->total_part_count());
4259TEST(SuccessfulAssertionTest, ASSERT) {
4261 EXPECT_EQ(0, GetUnitTestImpl()->current_test_result()->total_part_count());
4265TEST(SuccessfulAssertionTest, ASSERT_STR) {
4267 EXPECT_EQ(0, GetUnitTestImpl()->current_test_result()->total_part_count());
4276TEST(AssertionWithMessageTest, EXPECT) {
4277 EXPECT_EQ(1, 1) <<
"This should succeed.";
4279 "Expected failure #1");
4280 EXPECT_LE(1, 2) <<
"This should succeed.";
4282 "Expected failure #2.");
4283 EXPECT_GE(1, 0) <<
"This should succeed.";
4285 "Expected failure #3.");
4289 "Expected failure #4.");
4292 "Expected failure #5.");
4296 "Expected failure #6.");
4297 EXPECT_NEAR(1, 1.1, 0.2) <<
"This should succeed.";
4300TEST(AssertionWithMessageTest, ASSERT) {
4301 ASSERT_EQ(1, 1) <<
"This should succeed.";
4302 ASSERT_NE(1, 2) <<
"This should succeed.";
4303 ASSERT_LE(1, 2) <<
"This should succeed.";
4304 ASSERT_LT(1, 2) <<
"This should succeed.";
4305 ASSERT_GE(1, 0) <<
"This should succeed.";
4307 "Expected failure.");
4310TEST(AssertionWithMessageTest, ASSERT_STR) {
4315 "Expected failure.");
4318TEST(AssertionWithMessageTest, ASSERT_FLOATING) {
4330 ASSERT_FALSE(
true) <<
"Expected failure: " << 2 <<
" > " << 1
4331 <<
" evaluates to " <<
true;
4333 "Expected failure");
4348 ASSERT_TRUE(
false) <<
static_cast<const char*
>(
nullptr)
4349 <<
static_cast<char*
>(
nullptr);
4354#ifdef GTEST_OS_WINDOWS
4356TEST(AssertionWithMessageTest, WideStringMessage) {
4359 EXPECT_TRUE(
false) << L
"This failure is expected.\x8119";
4361 "This failure is expected.");
4364 ASSERT_EQ(1, 2) <<
"This failure is " << L
"expected too.\x8120";
4366 "This failure is expected too.");
4374 "Intentional failure #1.");
4376 "Intentional failure #2.");
4386TEST(ExpectTest, ExpectTrueWithAssertionResult) {
4389 "Value of: ResultIsEven(3)\n"
4390 " Actual: false (3 is odd)\n"
4394 "Value of: ResultIsEvenNoExplanation(3)\n"
4395 " Actual: false (3 is odd)\n"
4404 "Intentional failure #1.");
4406 "Intentional failure #2.");
4415TEST(ExpectTest, ExpectFalseWithAssertionResult) {
4418 "Value of: ResultIsEven(2)\n"
4419 " Actual: true (2 is even)\n"
4423 "Value of: ResultIsEvenNoExplanation(2)\n"
4438 "Expected equality of these values:\n"
4449TEST(ExpectTest, EXPECT_EQ_Double) {
4458TEST(ExpectTest, EXPECT_EQ_NULL) {
4460 const char*
p =
nullptr;
4472TEST(ExpectTest, EXPECT_EQ_0) {
4487 "Expected: ('a') != ('a'), "
4488 "actual: 'a' (97, 0x61) vs 'a' (97, 0x61)");
4490 char*
const p0 =
nullptr;
4496 void* pv1 = (
void*)0x1234;
4497 char*
const p1 =
reinterpret_cast<char*
>(pv1);
4506 "Expected: (2) <= (0), actual: 2 vs 0");
4514 "Expected: (2) < (2), actual: 2 vs 2");
4523 "Expected: (2) >= (3), actual: 2 vs 3");
4531 "Expected: (2) > (2), actual: 2 vs 2");
4535#if GTEST_HAS_EXCEPTIONS
4541 "Expected: ThrowAnInteger() throws an exception of "
4542 "type bool.\n Actual: it throws a different type.");
4544 EXPECT_THROW(ThrowRuntimeError(
"A description"), std::logic_error),
4545 "Expected: ThrowRuntimeError(\"A description\") "
4546 "throws an exception of type std::logic_error.\n "
4547 "Actual: it throws " ERROR_DESC
4549 "with description \"A description\".");
4552 "Expected: ThrowNothing() throws an exception of type bool.\n"
4553 " Actual: it throws nothing.");
4560 "Expected: ThrowAnInteger() doesn't throw an "
4561 "exception.\n Actual: it throws.");
4563 "Expected: ThrowRuntimeError(\"A description\") "
4564 "doesn't throw an exception.\n "
4565 "Actual: it throws " ERROR_DESC
4567 "with description \"A description\".");
4574 "Expected: ThrowNothing() throws an exception.\n"
4575 " Actual: it doesn't.");
4581TEST(ExpectTest, ExpectPrecedence) {
4584 " true && false\n Which is: false");
4590TEST(StreamableToStringTest, Scalar) {
4595TEST(StreamableToStringTest, Pointer) {
4602TEST(StreamableToStringTest, NullPointer) {
4608TEST(StreamableToStringTest, CString) {
4609 EXPECT_STREQ(
"Foo", StreamableToString(
"Foo").c_str());
4613TEST(StreamableToStringTest, NullCString) {
4621TEST(StreamableTest,
string) {
4622 static const std::string str(
4623 "This failure message is a std::string, and is expected.");
4629TEST(StreamableTest, stringWithEmbeddedNUL) {
4630 static const char char_array_with_nul[] =
4631 "Here's a NUL\0 and some more string";
4632 static const std::string string_with_nul(
4633 char_array_with_nul,
4634 sizeof(char_array_with_nul) - 1);
4636 "Here's a NUL\\0 and some more string");
4640TEST(StreamableTest, NULChar) {
4643 FAIL() <<
"A NUL" <<
'\0' <<
" and some more string";
4645 "A NUL\\0 and some more string");
4656TEST(StreamableTest, NullCharPtr) {
4662TEST(StreamableTest, BasicIoManip) {
4665 FAIL() <<
"Line 1." << std::endl
4666 <<
"A NUL char " << std::ends << std::flush <<
" in line 2.";
4668 "Line 1.\nA NUL char \\0 in line 2.");
4673void AddFailureHelper(
bool* aborted) {
4681 bool aborted =
true;
4705 "Intentional failure.");
4724 SUCCEED() <<
"Explicit success.";
4739 bool false_value =
false;
4742 " false_value\n Which is: false\n true");
4746TEST(EqAssertionTest, Int) {
4752TEST(EqAssertionTest, Time_T) {
4753 EXPECT_EQ(
static_cast<time_t
>(0),
static_cast<time_t
>(0));
4755 ASSERT_EQ(
static_cast<time_t
>(0),
static_cast<time_t
>(1234)),
"1234");
4759TEST(EqAssertionTest, Char) {
4761 const char ch =
'b';
4767TEST(EqAssertionTest, WideChar) {
4771 "Expected equality of these values:\n"
4773 " Which is: L'\0' (0, 0x0)\n"
4775 " Which is: L'x' (120, 0x78)");
4777 static wchar_t wchar;
4782 " wchar\n Which is: L'");
4786TEST(EqAssertionTest, StdString) {
4789 ASSERT_EQ(
"Test", ::std::string(
"Test"));
4792 static const ::std::string str1(
"A * in the middle");
4793 static const ::std::string str2(str1);
4801 char*
const p1 =
const_cast<char*
>(
"foo");
4806 static ::std::string str3(str1);
4809 " str3\n Which is: \"A \\0 in the middle\"");
4812#if GTEST_HAS_STD_WSTRING
4815TEST(EqAssertionTest, StdWideString) {
4817 const ::std::wstring wstr1(L
"A * in the middle");
4818 const ::std::wstring wstr2(wstr1);
4823 const wchar_t kTestX8119[] = {
'T',
'e',
's',
't', 0x8119,
'\0'};
4824 EXPECT_EQ(::std::wstring(kTestX8119), kTestX8119);
4828 const wchar_t kTestX8120[] = {
'T',
'e',
's',
't', 0x8120,
'\0'};
4831 EXPECT_EQ(::std::wstring(kTestX8119), kTestX8120);
4837 ::std::wstring wstr3(wstr1);
4838 wstr3.at(2) = L
'\0';
4845 ASSERT_EQ(
const_cast<wchar_t*
>(L
"foo"), ::std::wstring(L
"bar"));
4853TEST(EqAssertionTest, CharPointer) {
4854 char*
const p0 =
nullptr;
4859 void* pv1 = (
void*)0x1234;
4860 void* pv2 = (
void*)0xABC0;
4861 char*
const p1 =
reinterpret_cast<char*
>(pv1);
4862 char*
const p2 =
reinterpret_cast<char*
>(pv2);
4868 reinterpret_cast<char*
>(0xABC0)),
4873TEST(EqAssertionTest, WideCharPointer) {
4874 wchar_t*
const p0 =
nullptr;
4879 void* pv1 = (
void*)0x1234;
4880 void* pv2 = (
void*)0xABC0;
4881 wchar_t*
const p1 =
reinterpret_cast<wchar_t*
>(pv1);
4882 wchar_t*
const p2 =
reinterpret_cast<wchar_t*
>(pv2);
4887 void* pv3 = (
void*)0x1234;
4888 void* pv4 = (
void*)0xABC0;
4889 const wchar_t* p3 =
reinterpret_cast<const wchar_t*
>(pv3);
4890 const wchar_t* p4 =
reinterpret_cast<const wchar_t*
>(pv4);
4895TEST(EqAssertionTest, OtherPointer) {
4896 ASSERT_EQ(
static_cast<const int*
>(
nullptr),
static_cast<const int*
>(
nullptr));
4898 reinterpret_cast<const int*
>(0x1234)),
4903class UnprintableChar {
4905 explicit UnprintableChar(
char ch) : char_(
ch) {}
4907 bool operator==(
const UnprintableChar& rhs)
const {
4908 return char_ == rhs.char_;
4910 bool operator!=(
const UnprintableChar& rhs)
const {
4911 return char_ != rhs.char_;
4913 bool operator<(
const UnprintableChar& rhs)
const {
return char_ < rhs.char_; }
4914 bool operator<=(
const UnprintableChar& rhs)
const {
4915 return char_ <= rhs.char_;
4917 bool operator>(
const UnprintableChar& rhs)
const {
return char_ > rhs.char_; }
4918 bool operator>=(
const UnprintableChar& rhs)
const {
4919 return char_ >= rhs.char_;
4928TEST(ComparisonAssertionTest, AcceptsUnprintableArgs) {
4929 const UnprintableChar
x(
'x'),
y(
'y');
4948 "1-byte object <78>");
4950 "1-byte object <78>");
4953 "1-byte object <79>");
4955 "1-byte object <78>");
4957 "1-byte object <79>");
4969 int Bar()
const {
return 1; }
4982class FRIEND_TEST_Test2 :
public Test {
4997class TestLifeCycleTest :
public Test {
5001 TestLifeCycleTest() { count_++; }
5005 ~TestLifeCycleTest()
override { count_--; }
5008 int count()
const {
return count_; }
5014int TestLifeCycleTest::count_ = 0;
5017TEST_F(TestLifeCycleTest, Test1) {
5024TEST_F(TestLifeCycleTest, Test2) {
5035TEST(AssertionResultTest, CopyConstructorWorksWhenNotOptimied) {
5038 AssertionResult r1 = AssertionSuccess();
5039 AssertionResult r2 = r1;
5044 AssertionResult r3 = r1;
5045 EXPECT_EQ(
static_cast<bool>(r3),
static_cast<bool>(r1));
5051TEST(AssertionResultTest, ConstructionWorks) {
5052 AssertionResult r1 = AssertionSuccess();
5056 AssertionResult r2 = AssertionSuccess() <<
"abc";
5060 AssertionResult r3 = AssertionFailure();
5064 AssertionResult r4 = AssertionFailure() <<
"def";
5068 AssertionResult r5 = AssertionFailure(
Message() <<
"ghi");
5074TEST(AssertionResultTest, NegationWorks) {
5075 AssertionResult r1 = AssertionSuccess() <<
"abc";
5079 AssertionResult r2 = AssertionFailure() <<
"def";
5084TEST(AssertionResultTest, StreamingWorks) {
5085 AssertionResult r = AssertionSuccess();
5086 r <<
"abc" <<
'd' << 0 <<
true;
5090TEST(AssertionResultTest, CanStreamOstreamManipulators) {
5091 AssertionResult r = AssertionSuccess();
5092 r <<
"Data" << std::endl << std::flush << std::ends <<
"Will be visible";
5098TEST(AssertionResultTest, ConstructibleFromContextuallyConvertibleToBool) {
5099 struct ExplicitlyConvertibleToBool {
5100 explicit operator bool()
const {
return value; }
5103 ExplicitlyConvertibleToBool v1 = {
false};
5104 ExplicitlyConvertibleToBool v2 = {
true};
5110 operator AssertionResult()
const {
return AssertionResult(
true); }
5113TEST(AssertionResultTest, ConstructibleFromImplicitlyConvertible) {
5122 explicit Base(
int an_x) : x_(an_x) {}
5123 int x()
const {
return x_; }
5129 return os << val.
x();
5132 return os <<
"(" << pointer->
x() <<
")";
5135TEST(MessageTest, CanStreamUserTypeInGlobalNameSpace) {
5146class MyTypeInUnnamedNameSpace :
public Base {
5148 explicit MyTypeInUnnamedNameSpace(
int an_x) :
Base(an_x) {}
5151 const MyTypeInUnnamedNameSpace& val) {
5152 return os << val.x();
5155 const MyTypeInUnnamedNameSpace* pointer) {
5156 return os <<
"(" << pointer->x() <<
")";
5160TEST(MessageTest, CanStreamUserTypeInUnnamedNameSpace) {
5162 MyTypeInUnnamedNameSpace a(1);
5176 return os << val.
x();
5179 return os <<
"(" << pointer->
x() <<
")";
5183TEST(MessageTest, CanStreamUserTypeInUserNameSpace) {
5201 return os << val.
x();
5205 return os <<
"(" << pointer->
x() <<
")";
5208TEST(MessageTest, CanStreamUserTypeInUserNameSpaceWithStreamOperatorInGlobal) {
5219 char*
const p1 =
nullptr;
5220 unsigned char*
const p2 =
nullptr;
5222 double* p4 =
nullptr;
5226 msg << p1 << p2 << p3 << p4 << p5 << p6;
5233 const wchar_t* const_wstr =
nullptr;
5237 wchar_t* wstr =
nullptr;
5241 const_wstr = L
"abc\x8119";
5243 (
Message() << const_wstr).GetString().c_str());
5246 wstr =
const_cast<wchar_t*
>(const_wstr);
5259 GetUnitTestImpl()->GetTestSuite(
"TestInfoTest",
"",
nullptr,
nullptr);
5263 if (strcmp(test_name, test_info->
name()) == 0)
return test_info;
5269 return test_info->
result();
5275 const TestInfo*
const test_info = GetTestInfo(
"Names");
5283 const TestInfo*
const test_info = GetTestInfo(
"result");
5286 ASSERT_EQ(0, GetTestResult(test_info)->total_part_count());
5289 ASSERT_EQ(0, GetTestResult(test_info)->total_part_count());
5292#define VERIFY_CODE_LOCATION \
5293 const int expected_line = __LINE__ - 1; \
5294 const TestInfo* const test_info = GetUnitTestImpl()->current_test_info(); \
5295 ASSERT_TRUE(test_info); \
5296 EXPECT_STREQ(__FILE__, test_info->file()); \
5297 EXPECT_EQ(expected_line, test_info->line())
5318template <
typename T>
5327template <
typename T>
5340#undef VERIFY_CODE_LOCATION
5345#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
5351 printf(
"Setting up the test case . . .\n");
5368 printf(
"Tearing down the test case . . .\n");
5410 printf(
"Setting up the test suite . . .\n");
5427 printf(
"Tearing down the test suite . . .\n");
5675 template <
typename CharType>
5677 CharType** array2) {
5678 ASSERT_EQ(size1, size2) <<
" Array sizes different.";
5680 for (
int i = 0;
i != size1;
i++) {
5713 template <
typename CharType>
5715 const CharType** argv2,
const Flags& expected,
5716 bool should_print_help) {
5720#if GTEST_HAS_STREAM_REDIRECTION
5727#if GTEST_HAS_STREAM_REDIRECTION
5728 const std::string captured_stdout = GetCapturedStdout();
5742#if GTEST_HAS_STREAM_REDIRECTION
5743 const char*
const expected_help_fragment =
5744 "This program contains tests written using";
5745 if (should_print_help) {
5759#define GTEST_TEST_PARSING_FLAGS_(argv1, argv2, expected, should_print_help) \
5760 TestParsingFlags(sizeof(argv1) / sizeof(*argv1) - 1, argv1, \
5761 sizeof(argv2) / sizeof(*argv2) - 1, argv2, expected, \
5767 const char* argv[] = {
nullptr};
5769 const char* argv2[] = {
nullptr};
5776 const char* argv[] = {
"foo.exe",
nullptr};
5778 const char* argv2[] = {
"foo.exe",
nullptr};
5785 const char* argv[] = {
"foo.exe",
"--gtest_fail_fast",
nullptr};
5787 const char* argv2[] = {
"foo.exe",
nullptr};
5794 const char* argv[] = {
"foo.exe",
"--gtest_filter=",
nullptr};
5796 const char* argv2[] = {
"foo.exe",
nullptr};
5803 const char* argv[] = {
"foo.exe",
"--gtest_filter=abc",
nullptr};
5805 const char* argv2[] = {
"foo.exe",
nullptr};
5812 const char* argv[] = {
"foo.exe",
"--gtest_break_on_failure",
nullptr};
5814 const char* argv2[] = {
"foo.exe",
nullptr};
5821 const char* argv[] = {
"foo.exe",
"--gtest_break_on_failure=0",
nullptr};
5823 const char* argv2[] = {
"foo.exe",
nullptr};
5830 const char* argv[] = {
"foo.exe",
"--gtest_break_on_failure=f",
nullptr};
5832 const char* argv2[] = {
"foo.exe",
nullptr};
5839 const char* argv[] = {
"foo.exe",
"--gtest_break_on_failure=F",
nullptr};
5841 const char* argv2[] = {
"foo.exe",
nullptr};
5849 const char* argv[] = {
"foo.exe",
"--gtest_break_on_failure=1",
nullptr};
5851 const char* argv2[] = {
"foo.exe",
nullptr};
5858 const char* argv[] = {
"foo.exe",
"--gtest_catch_exceptions",
nullptr};
5860 const char* argv2[] = {
"foo.exe",
nullptr};
5867 const char* argv[] = {
"foo.exe",
"--gtest_death_test_use_fork",
nullptr};
5869 const char* argv2[] = {
"foo.exe",
nullptr};
5877 const char* argv[] = {
"foo.exe",
"--gtest_filter=a",
"--gtest_filter=b",
5880 const char* argv2[] = {
"foo.exe",
nullptr};
5887 const char* argv[] = {
"foo.exe",
"--gtest_break_on_failure",
5889 "--gtest_filter=b",
nullptr};
5891 const char* argv2[] = {
"foo.exe",
"bar",
nullptr};
5901 const char* argv[] = {
"foo.exe",
"--gtest_list_tests",
nullptr};
5903 const char* argv2[] = {
"foo.exe",
nullptr};
5910 const char* argv[] = {
"foo.exe",
"--gtest_list_tests=1",
nullptr};
5912 const char* argv2[] = {
"foo.exe",
nullptr};
5919 const char* argv[] = {
"foo.exe",
"--gtest_list_tests=0",
nullptr};
5921 const char* argv2[] = {
"foo.exe",
nullptr};
5928 const char* argv[] = {
"foo.exe",
"--gtest_list_tests=f",
nullptr};
5930 const char* argv2[] = {
"foo.exe",
nullptr};
5937 const char* argv[] = {
"foo.exe",
"--gtest_list_tests=F",
nullptr};
5939 const char* argv2[] = {
"foo.exe",
nullptr};
5946 const char* argv[] = {
"foo.exe",
"--gtest_output=xml",
nullptr};
5948 const char* argv2[] = {
"foo.exe",
nullptr};
5955 const char* argv[] = {
"foo.exe",
"--gtest_output=xml:file",
nullptr};
5957 const char* argv2[] = {
"foo.exe",
nullptr};
5964 const char* argv[] = {
"foo.exe",
"--gtest_output=xml:directory/path/",
5967 const char* argv2[] = {
"foo.exe",
nullptr};
5975 const char* argv[] = {
"foo.exe",
"--gtest_brief",
nullptr};
5977 const char* argv2[] = {
"foo.exe",
nullptr};
5984 const char* argv[] = {
"foo.exe",
"--gtest_brief=1",
nullptr};
5986 const char* argv2[] = {
"foo.exe",
nullptr};
5993 const char* argv[] = {
"foo.exe",
"--gtest_brief=0",
nullptr};
5995 const char* argv2[] = {
"foo.exe",
nullptr};
6002 const char* argv[] = {
"foo.exe",
"--gtest_print_time",
nullptr};
6004 const char* argv2[] = {
"foo.exe",
nullptr};
6011 const char* argv[] = {
"foo.exe",
"--gtest_print_time=1",
nullptr};
6013 const char* argv2[] = {
"foo.exe",
nullptr};
6020 const char* argv[] = {
"foo.exe",
"--gtest_print_time=0",
nullptr};
6022 const char* argv2[] = {
"foo.exe",
nullptr};
6029 const char* argv[] = {
"foo.exe",
"--gtest_print_time=f",
nullptr};
6031 const char* argv2[] = {
"foo.exe",
nullptr};
6038 const char* argv[] = {
"foo.exe",
"--gtest_print_time=F",
nullptr};
6040 const char* argv2[] = {
"foo.exe",
nullptr};
6047 const char* argv[] = {
"foo.exe",
"--gtest_random_seed=1000",
nullptr};
6049 const char* argv2[] = {
"foo.exe",
nullptr};
6056 const char* argv[] = {
"foo.exe",
"--gtest_repeat=1000",
nullptr};
6058 const char* argv2[] = {
"foo.exe",
nullptr};
6065 const char* argv[] = {
6067 "--gtest_recreate_environments_when_repeating=0",
6071 const char* argv2[] = {
"foo.exe",
nullptr};
6079 const char* argv[] = {
"foo.exe",
"--gtest_also_run_disabled_tests",
nullptr};
6081 const char* argv2[] = {
"foo.exe",
nullptr};
6089 const char* argv[] = {
"foo.exe",
"--gtest_also_run_disabled_tests=1",
6092 const char* argv2[] = {
"foo.exe",
nullptr};
6100 const char* argv[] = {
"foo.exe",
"--gtest_also_run_disabled_tests=0",
6103 const char* argv2[] = {
"foo.exe",
nullptr};
6111 const char* argv[] = {
"foo.exe",
"--gtest_shuffle",
nullptr};
6113 const char* argv2[] = {
"foo.exe",
nullptr};
6120 const char* argv[] = {
"foo.exe",
"--gtest_shuffle=0",
nullptr};
6122 const char* argv2[] = {
"foo.exe",
nullptr};
6129 const char* argv[] = {
"foo.exe",
"--gtest_shuffle=1",
nullptr};
6131 const char* argv2[] = {
"foo.exe",
nullptr};
6138 const char* argv[] = {
"foo.exe",
"--gtest_stack_trace_depth=5",
nullptr};
6140 const char* argv2[] = {
"foo.exe",
nullptr};
6146 const char* argv[] = {
"foo.exe",
"--gtest_stream_result_to=localhost:1234",
6149 const char* argv2[] = {
"foo.exe",
nullptr};
6157 const char* argv[] = {
"foo.exe",
"--gtest_throw_on_failure",
nullptr};
6159 const char* argv2[] = {
"foo.exe",
nullptr};
6166 const char* argv[] = {
"foo.exe",
"--gtest_throw_on_failure=0",
nullptr};
6168 const char* argv2[] = {
"foo.exe",
nullptr};
6176 const char* argv[] = {
"foo.exe",
"--gtest_throw_on_failure=1",
nullptr};
6178 const char* argv2[] = {
"foo.exe",
nullptr};
6185 const char* argv[] = {
"foo.exe",
"--gtest_filter",
nullptr};
6187 const char* argv2[] = {
"foo.exe",
"--gtest_filter",
nullptr};
6189#if defined(GTEST_HAS_ABSL) && defined(GTEST_HAS_DEATH_TEST)
6192 testing::ExitedWithCode(1),
6193 "ERROR: Missing the value for the flag 'gtest_filter'");
6194#elif !defined(GTEST_HAS_ABSL)
6197 static_cast<void>(argv);
6198 static_cast<void>(argv2);
6204 const char* argv[] = {
"foo.exe",
"--gtest_output",
nullptr};
6206 const char* argv2[] = {
"foo.exe",
"--gtest_output",
nullptr};
6208#if defined(GTEST_HAS_ABSL) && defined(GTEST_HAS_DEATH_TEST)
6211 testing::ExitedWithCode(1),
6212 "ERROR: Missing the value for the flag 'gtest_output'");
6213#elif !defined(GTEST_HAS_ABSL)
6216 static_cast<void>(argv);
6217 static_cast<void>(argv2);
6221#ifdef GTEST_HAS_ABSL
6222TEST_F(ParseFlagsTest, AbseilPositionalFlags) {
6223 const char* argv[] = {
"foo.exe",
"--gtest_throw_on_failure=1",
"--",
6224 "--other_flag",
nullptr};
6229 const char* argv2[] = {
"foo.exe",
"--other_flag",
nullptr};
6236 const char* argv[] = {
"foo.exe",
"--gtest_filter=abcd",
"--other_flag",
6239 const char* argv2[] = {
"foo.exe",
"--other_flag",
nullptr};
6244#ifdef GTEST_OS_WINDOWS
6246TEST_F(ParseFlagsTest, WideStrings) {
6247 const wchar_t* argv[] = {L
"foo.exe",
6248 L
"--gtest_filter=Foo*",
6249 L
"--gtest_list_tests=1",
6250 L
"--gtest_break_on_failure",
6251 L
"--non_gtest_flag",
6254 const wchar_t* argv2[] = {L
"foo.exe", L
"--non_gtest_flag", NULL};
6256 Flags expected_flags;
6257 expected_flags.break_on_failure =
true;
6258 expected_flags.filter =
"Foo*";
6259 expected_flags.list_tests =
true;
6265#if GTEST_USE_OWN_FLAGFILE_FLAG_
6266class FlagfileTest :
public ParseFlagsTest {
6268 void SetUp()
override {
6269 ParseFlagsTest::SetUp();
6278 void TearDown()
override {
6280 ParseFlagsTest::TearDown();
6283 internal::FilePath CreateFlagfile(
const char* contents) {
6284 internal::FilePath file_path(internal::FilePath::GenerateUniqueFileName(
6287 fprintf(f,
"%s", contents);
6297TEST_F(FlagfileTest, Empty) {
6298 internal::FilePath flagfile_path(CreateFlagfile(
""));
6299 std::string flagfile_flag =
6302 const char* argv[] = {
"foo.exe", flagfile_flag.c_str(),
nullptr};
6304 const char* argv2[] = {
"foo.exe",
nullptr};
6310TEST_F(FlagfileTest, FilterNonEmpty) {
6311 internal::FilePath flagfile_path(
6313 std::string flagfile_flag =
6316 const char* argv[] = {
"foo.exe", flagfile_flag.c_str(),
nullptr};
6318 const char* argv2[] = {
"foo.exe",
nullptr};
6324TEST_F(FlagfileTest, SeveralFlags) {
6325 internal::FilePath flagfile_path(
6329 std::string flagfile_flag =
6332 const char* argv[] = {
"foo.exe", flagfile_flag.c_str(),
nullptr};
6334 const char* argv2[] = {
"foo.exe",
nullptr};
6336 Flags expected_flags;
6337 expected_flags.break_on_failure =
true;
6338 expected_flags.filter =
"abc";
6339 expected_flags.list_tests =
true;
6354 <<
"There should be no tests running at this point.";
6362 <<
"There should be no tests running at this point.";
6371 <<
"There is a test running so we should have a valid TestInfo.";
6373 <<
"Expected the name of the currently running test suite.";
6375 <<
"Expected the name of the currently running test.";
6385 <<
"There is a test running so we should have a valid TestInfo.";
6387 <<
"Expected the name of the currently running test suite.";
6389 <<
"Expected the name of the currently running test.";
6413TEST(NestedTestingNamespaceTest, Success) {
6414 EXPECT_EQ(1, 1) <<
"This shouldn't fail.";
6418TEST(NestedTestingNamespaceTest, Failure) {
6420 "This failure is expected.");
6432 void SetUp()
override { Test::SetUp(); }
6438TEST(StreamingAssertionsTest, Unconditional) {
6439 SUCCEED() <<
"expected success";
6441 "expected failure");
6447#pragma option push -w-ccc -w-rch
6450TEST(StreamingAssertionsTest, Truth) {
6454 "expected failure");
6456 "expected failure");
6459TEST(StreamingAssertionsTest, Truth2) {
6463 "expected failure");
6465 "expected failure");
6473TEST(StreamingAssertionsTest, IntegerEquals) {
6474 EXPECT_EQ(1, 1) <<
"unexpected failure";
6475 ASSERT_EQ(1, 1) <<
"unexpected failure";
6477 "expected failure");
6479 "expected failure");
6482TEST(StreamingAssertionsTest, IntegerLessThan) {
6483 EXPECT_LT(1, 2) <<
"unexpected failure";
6484 ASSERT_LT(1, 2) <<
"unexpected failure";
6486 "expected failure");
6488 "expected failure");
6491TEST(StreamingAssertionsTest, StringsEqual) {
6495 "expected failure");
6497 "expected failure");
6500TEST(StreamingAssertionsTest, StringsNotEqual) {
6504 "expected failure");
6506 "expected failure");
6509TEST(StreamingAssertionsTest, StringsEqualIgnoringCase) {
6513 "expected failure");
6515 "expected failure");
6518TEST(StreamingAssertionsTest, StringNotEqualIgnoringCase) {
6522 "expected failure");
6524 "expected failure");
6527TEST(StreamingAssertionsTest, FloatingPointEquals) {
6531 "expected failure");
6533 "expected failure");
6536#if GTEST_HAS_EXCEPTIONS
6538TEST(StreamingAssertionsTest, Throw) {
6539 EXPECT_THROW(ThrowAnInteger(),
int) <<
"unexpected failure";
6540 ASSERT_THROW(ThrowAnInteger(),
int) <<
"unexpected failure";
6542 <<
"expected failure",
6543 "expected failure");
6545 <<
"expected failure",
6546 "expected failure");
6549TEST(StreamingAssertionsTest, NoThrow) {
6553 <<
"expected failure",
6554 "expected failure");
6556 "expected failure");
6559TEST(StreamingAssertionsTest, AnyThrow) {
6563 <<
"expected failure",
6564 "expected failure");
6566 "expected failure");
6573TEST(ColoredOutputTest, UsesColorsWhenGTestColorFlagIsYes) {
6576 SetEnv(
"TERM",
"xterm");
6580 SetEnv(
"TERM",
"dumb");
6585TEST(ColoredOutputTest, UsesColorsWhenGTestColorFlagIsAliasOfYes) {
6586 SetEnv(
"TERM",
"dumb");
6598TEST(ColoredOutputTest, UsesNoColorWhenGTestColorFlagIsNo) {
6601 SetEnv(
"TERM",
"xterm");
6605 SetEnv(
"TERM",
"dumb");
6610TEST(ColoredOutputTest, UsesNoColorWhenGTestColorFlagIsInvalid) {
6611 SetEnv(
"TERM",
"xterm");
6623TEST(ColoredOutputTest, UsesColorsWhenStdoutIsTty) {
6626 SetEnv(
"TERM",
"xterm");
6631TEST(ColoredOutputTest, UsesColorsWhenTermSupportsColors) {
6634#if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_MINGW)
6637 SetEnv(
"TERM",
"dumb");
6643 SetEnv(
"TERM",
"xterm");
6649 SetEnv(
"TERM",
"dumb");
6652 SetEnv(
"TERM",
"emacs");
6655 SetEnv(
"TERM",
"vt100");
6658 SetEnv(
"TERM",
"xterm-mono");
6661 SetEnv(
"TERM",
"xterm");
6664 SetEnv(
"TERM",
"xterm-color");
6667 SetEnv(
"TERM",
"xterm-kitty");
6670 SetEnv(
"TERM",
"xterm-256color");
6673 SetEnv(
"TERM",
"screen");
6676 SetEnv(
"TERM",
"screen-256color");
6679 SetEnv(
"TERM",
"tmux");
6682 SetEnv(
"TERM",
"tmux-256color");
6685 SetEnv(
"TERM",
"rxvt-unicode");
6688 SetEnv(
"TERM",
"rxvt-unicode-256color");
6691 SetEnv(
"TERM",
"linux");
6694 SetEnv(
"TERM",
"cygwin");
6703 StaticAssertTypeEq<const int, const int>();
6707template <
typename T>
6713TEST(StaticAssertTypeEqTest, WorksInClass) {
6721TEST(StaticAssertTypeEqTest, CompilesForEqualTypes) {
6722 StaticAssertTypeEq<int, IntAlias>();
6723 StaticAssertTypeEq<int*, IntAlias*>();
6726TEST(HasNonfatalFailureTest, ReturnsFalseWhenThereIsNoFailure) {
6732TEST(HasNonfatalFailureTest, ReturnsFalseWhenThereIsOnlyFatalFailure) {
6734 const bool has_nonfatal_failure = HasNonfatalFailure();
6735 ClearCurrentTestPartResults();
6739TEST(HasNonfatalFailureTest, ReturnsTrueWhenThereIsNonfatalFailure) {
6741 const bool has_nonfatal_failure = HasNonfatalFailure();
6742 ClearCurrentTestPartResults();
6746TEST(HasNonfatalFailureTest, ReturnsTrueWhenThereAreFatalAndNonfatalFailures) {
6749 const bool has_nonfatal_failure = HasNonfatalFailure();
6750 ClearCurrentTestPartResults();
6759TEST(HasNonfatalFailureTest, WorksOutsideOfTestBody) {
6763TEST(HasNonfatalFailureTest, WorksOutsideOfTestBody2) {
6766 ClearCurrentTestPartResults();
6770TEST(HasFailureTest, ReturnsFalseWhenThereIsNoFailure) {
6774TEST(HasFailureTest, ReturnsTrueWhenThereIsFatalFailure) {
6776 const bool has_failure = HasFailure();
6777 ClearCurrentTestPartResults();
6781TEST(HasFailureTest, ReturnsTrueWhenThereIsNonfatalFailure) {
6783 const bool has_failure = HasFailure();
6784 ClearCurrentTestPartResults();
6788TEST(HasFailureTest, ReturnsTrueWhenThereAreFatalAndNonfatalFailures) {
6791 const bool has_failure = HasFailure();
6792 ClearCurrentTestPartResults();
6799TEST(HasFailureTest, WorksOutsideOfTestBody) {
6803TEST(HasFailureTest, WorksOutsideOfTestBody2) {
6806 ClearCurrentTestPartResults();
6814 : on_start_counter_(on_start_counter), is_destroyed_(is_destroyed) {}
6817 if (is_destroyed_) *is_destroyed_ =
true;
6822 if (on_start_counter_ !=
nullptr) (*on_start_counter_)++;
6826 int* on_start_counter_;
6827 bool* is_destroyed_;
6831TEST(TestEventListenersTest, ConstructionWorks) {
6841TEST(TestEventListenersTest, DestructionWorks) {
6842 bool default_result_printer_is_destroyed =
false;
6843 bool default_xml_printer_is_destroyed =
false;
6844 bool extra_listener_is_destroyed =
false;
6846 new TestListener(
nullptr, &default_result_printer_is_destroyed);
6848 new TestListener(
nullptr, &default_xml_printer_is_destroyed);
6850 new TestListener(
nullptr, &extra_listener_is_destroyed);
6855 default_result_printer);
6857 default_xml_printer);
6858 listeners.
Append(extra_listener);
6867TEST(TestEventListenersTest, Append) {
6868 int on_start_counter = 0;
6869 bool is_destroyed =
false;
6873 listeners.
Append(listener);
6887 : vector_(vector), id_(id) {}
6891 vector_->push_back(GetEventDescription(
"OnTestProgramStart"));
6895 vector_->push_back(GetEventDescription(
"OnTestProgramEnd"));
6900 vector_->push_back(GetEventDescription(
"OnTestIterationStart"));
6905 vector_->push_back(GetEventDescription(
"OnTestIterationEnd"));
6909 std::string GetEventDescription(
const char* method) {
6911 message << id_ <<
"." << method;
6912 return message.GetString();
6915 std::vector<std::string>* vector_;
6916 const char*
const id_;
6922TEST(EventListenerTest, AppendKeepsOrder) {
6923 std::vector<std::string> vec;
6932 EXPECT_STREQ(
"1st.OnTestProgramStart", vec[0].c_str());
6933 EXPECT_STREQ(
"2nd.OnTestProgramStart", vec[1].c_str());
6934 EXPECT_STREQ(
"3rd.OnTestProgramStart", vec[2].c_str());
6948 EXPECT_STREQ(
"1st.OnTestIterationStart", vec[0].c_str());
6949 EXPECT_STREQ(
"2nd.OnTestIterationStart", vec[1].c_str());
6950 EXPECT_STREQ(
"3rd.OnTestIterationStart", vec[2].c_str());
6956 EXPECT_STREQ(
"3rd.OnTestIterationEnd", vec[0].c_str());
6957 EXPECT_STREQ(
"2nd.OnTestIterationEnd", vec[1].c_str());
6958 EXPECT_STREQ(
"1st.OnTestIterationEnd", vec[2].c_str());
6963TEST(TestEventListenersTest, Release) {
6964 int on_start_counter = 0;
6965 bool is_destroyed =
false;
6972 listeners.
Append(listener);
6984TEST(EventListenerTest, SuppressEventForwarding) {
6985 int on_start_counter = 0;
6989 listeners.
Append(listener);
7000TEST(EventListenerDeathTest, EventsNotForwardedInDeathTestSubprocesses) {
7004 *GetUnitTestImpl()->listeners()))
7005 <<
"expected failure";
7007 "expected failure");
7013TEST(EventListenerTest, default_result_printer) {
7014 int on_start_counter = 0;
7015 bool is_destroyed =
false;
7044TEST(EventListenerTest, RemovingDefaultResultPrinterWorks) {
7045 int on_start_counter = 0;
7046 bool is_destroyed =
false;
7072TEST(EventListenerTest, default_xml_generator) {
7073 int on_start_counter = 0;
7074 bool is_destroyed =
false;
7103TEST(EventListenerTest, RemovingDefaultXmlGeneratorWorks) {
7104 int on_start_counter = 0;
7105 bool is_destroyed =
false;
7138 "An expected failure");
7144 "An expected failure");
7146 "An expected failure");
7151 "An expected failure");
7156 "An expected failure");
7160 "An expected failure");
7162 "An expected failure");
7167 "An expected failure");
7171 "An expected failure");
7173 "An expected failure");
7203struct IncompleteType;
7207TEST(HasDebugStringAndShortDebugStringTest, ValueIsCompileTimeConstant) {
7232TEST(HasDebugStringAndShortDebugStringTest,
7233 ValueIsTrueWhenTypeHasDebugStringAndShortDebugString) {
7240TEST(HasDebugStringAndShortDebugStringTest,
7241 ValueIsFalseWhenTypeIsNotAProtocolMessage) {
7249template <
typename T1,
typename T2>
7252 "GTEST_REMOVE_REFERENCE_AND_CONST_ failed.");
7255TEST(RemoveReferenceToConstTest, Works) {
7265template <
typename T1,
typename T2>
7268 "GTEST_REFERENCE_TO_CONST_ failed.");
7271TEST(GTestReferenceToConstTest, Works) {
7282TEST(IsContainerTestTest, WorksForNonContainer) {
7283 EXPECT_EQ(
sizeof(IsNotContainer),
sizeof(IsContainerTest<int>(0)));
7284 EXPECT_EQ(
sizeof(IsNotContainer),
sizeof(IsContainerTest<
char[5]>(0)));
7285 EXPECT_EQ(
sizeof(IsNotContainer),
sizeof(IsContainerTest<NonContainer>(0)));
7288TEST(IsContainerTestTest, WorksForContainer) {
7289 EXPECT_EQ(
sizeof(IsContainer),
sizeof(IsContainerTest<std::vector<bool>>(0)));
7291 sizeof(IsContainerTest<std::map<int, double>>(0)));
7309TEST(IsContainerTestTest, ConstOnlyContainer) {
7311 sizeof(IsContainerTest<ConstOnlyContainerWithPointerIterator>(0)));
7313 sizeof(IsContainerTest<ConstOnlyContainerWithClassIterator>(0)));
7333TEST(ArrayEqTest, WorksForDegeneratedArrays) {
7338TEST(ArrayEqTest, WorksForOneDimensionalArrays) {
7340 const int a[] = {0, 1};
7350TEST(ArrayEqTest, WorksForTwoDimensionalArrays) {
7351 const char a[][3] = {
"hi",
"lo"};
7352 const char b[][3] = {
"hi",
"lo"};
7353 const char c[][3] = {
"hi",
"li"};
7364TEST(ArrayAwareFindTest, WorksForOneDimensionalArray) {
7365 const char a[] =
"hello";
7366 EXPECT_EQ(a + 4, ArrayAwareFind(a, a + 5,
'o'));
7367 EXPECT_EQ(a + 5, ArrayAwareFind(a, a + 5,
'x'));
7370TEST(ArrayAwareFindTest, WorksForTwoDimensionalArray) {
7371 int a[][2] = {{0, 1}, {2, 3}, {4, 5}};
7372 const int b[2] = {2, 3};
7373 EXPECT_EQ(a + 1, ArrayAwareFind(a, a + 3, b));
7375 const int c[2] = {6, 7};
7376 EXPECT_EQ(a + 3, ArrayAwareFind(a, a + 3, c));
7381TEST(CopyArrayTest, WorksForDegeneratedArrays) {
7387TEST(CopyArrayTest, WorksForOneDimensionalArrays) {
7388 const char a[3] =
"hi";
7400TEST(CopyArrayTest, WorksForTwoDimensionalArrays) {
7401 const int a[2][3] = {{0, 1, 2}, {3, 4, 5}};
7415TEST(NativeArrayTest, ConstructorFromArrayWorks) {
7416 const int a[3] = {0, 1, 2};
7422TEST(NativeArrayTest, CreatesAndDeletesCopyOfArrayWhenAskedTo) {
7423 typedef int Array[2];
7424 Array* a =
new Array[1];
7437TEST(NativeArrayTest, TypeMembersAreCorrect) {
7438 StaticAssertTypeEq<char, NativeArray<char>::value_type>();
7439 StaticAssertTypeEq<int[2], NativeArray<int[2]>::value_type>();
7441 StaticAssertTypeEq<const char*, NativeArray<char>::const_iterator>();
7445TEST(NativeArrayTest, MethodsWork) {
7446 const int a[3] = {0, 1, 2};
7465 const int b1[3] = {0, 1, 1};
7466 const int b2[4] = {0, 1, 2, 3};
7471TEST(NativeArrayTest, WorksForTwoDimensionalArray) {
7472 const char a[2][3] = {
"hi",
"lo"};
7479TEST(IndexSequence, MakeIndexSequence) {
7483 (std::is_same<IndexSequence<>, MakeIndexSequence<0>::type>
::value));
7485 (std::is_same<IndexSequence<0>, MakeIndexSequence<1>::type>
::value));
7487 (std::is_same<IndexSequence<0, 1>, MakeIndexSequence<2>::type>
::value));
7489 std::is_same<IndexSequence<0, 1, 2>, MakeIndexSequence<3>::type>
::value));
7491 (std::is_base_of<IndexSequence<0, 1, 2>, MakeIndexSequence<3>>
::value));
7498 (std::is_same<
int, ElemFromList<0, int, double, char>::type>
::value));
7500 (std::is_same<
double, ElemFromList<1, int, double, char>::type>
::value));
7502 (std::is_same<
char, ElemFromList<2, int, double, char>::type>
::value));
7504 std::is_same<
char, ElemFromList<7,
int,
int,
int,
int,
int,
int,
int,
7505 char,
int,
int,
int,
int>::type>
::value));
7512 FlatTuple<int, double, const char*> tuple = {};
7517 tuple = FlatTuple<int, double, const char*>(
7521 EXPECT_EQ(std::string(
"Foo"), tuple.Get<2>());
7523 tuple.Get<1>() = 5.1;
7528std::string AddIntToString(
int i,
const std::string& s) {
7529 return s + std::to_string(
i);
7540 EXPECT_TRUE(tuple.Apply([](
int i,
const std::string& s) ->
bool {
7541 return i == static_cast<int>(s.size());
7545 EXPECT_EQ(tuple.Apply(AddIntToString),
"Hello5");
7548 tuple.Apply([](
int&
i, std::string& s) {
7553 EXPECT_EQ(tuple.Get<1>(),
"HelloHello");
7599 { FlatTuple<ConstructionCounting> tuple; }
7611 FlatTuple<ConstructionCounting> tuple{
7624 FlatTuple<ConstructionCounting> tuple{
7639 FlatTuple<ConstructionCounting> tuple;
7641 tuple.Get<0>() = elem;
7655 FlatTuple<ConstructionCounting> tuple;
7674#define GTEST_FLAT_TUPLE_INT8 int, int, int, int, int, int, int, int,
7675#define GTEST_FLAT_TUPLE_INT16 GTEST_FLAT_TUPLE_INT8 GTEST_FLAT_TUPLE_INT8
7676#define GTEST_FLAT_TUPLE_INT32 GTEST_FLAT_TUPLE_INT16 GTEST_FLAT_TUPLE_INT16
7677#define GTEST_FLAT_TUPLE_INT64 GTEST_FLAT_TUPLE_INT32 GTEST_FLAT_TUPLE_INT32
7678#define GTEST_FLAT_TUPLE_INT128 GTEST_FLAT_TUPLE_INT64 GTEST_FLAT_TUPLE_INT64
7679#define GTEST_FLAT_TUPLE_INT256 GTEST_FLAT_TUPLE_INT128 GTEST_FLAT_TUPLE_INT128
7683 FlatTuple<GTEST_FLAT_TUPLE_INT256 int> tuple;
7686 tuple.Get<99>() = 17;
7687 tuple.Get<256>() = 1000;
7695TEST(SkipPrefixTest, SkipsWhenPrefixMatches) {
7696 const char*
const str =
"hello";
7698 const char*
p = str;
7707TEST(SkipPrefixTest, DoesNotSkipWhenPrefixDoesNotMatch) {
7708 const char*
const str =
"world";
7710 const char*
p = str;
7720TEST(AdHocTestResultTest, AdHocTestResultForUnitTestDoesNotShowFailure) {
7733 "DynamicUnitTestFixture",
"DynamicTest",
"TYPE",
"VALUE", __FILE__,
7738 for (
int i = 0;
i < unittest->total_test_suite_count(); ++
i) {
7739 auto* tests = unittest->GetTestSuite(
i);
7740 if (tests->name() != std::string(
"DynamicUnitTestFixture"))
continue;
7741 for (
int j = 0; j < tests->total_test_count(); ++j) {
7742 if (tests->GetTestInfo(j)->name() != std::string(
"DynamicTest"))
continue;
7744 EXPECT_STREQ(tests->GetTestInfo(j)->value_param(),
"VALUE");
7745 EXPECT_STREQ(tests->GetTestInfo(j)->type_param(),
"TYPE");
7750 FAIL() <<
"Didn't find the test!";
7755TEST(PatternGlobbingTest, MatchesFilterLinearRuntime) {
7756 std::string name(100,
'a');
7757 name.push_back(
'b');
7759 std::string pattern;
7760 for (
int i = 0;
i < 100; ++
i) {
7761 pattern.append(
"a*");
7763 pattern.push_back(
'b');
7769TEST(PatternGlobbingTest, MatchesFilterWithMultiplePatterns) {
7770 const std::string name =
"aaaa";
7778TEST(PatternGlobbingTest, MatchesFilterEdgeCases) {
Definition gtest_unittest.cc:5120
Base(int an_x)
Definition gtest_unittest.cc:5122
int x() const
Definition gtest_unittest.cc:5123
Definition gtest_unittest.cc:7179
Definition gtest_unittest.cc:7180
Definition gtest_xml_output_unittest_.cc:65
Definition googletest-output-test_.cc:945
void TestBody() override
Definition googletest-output-test_.cc:947
Definition gtest_unittest.cc:7726
Definition googletest-list-tests-unittest_.cc:69
Definition gtest_unittest.cc:7280
Definition gtest_unittest.cc:6430
void TearDown() override
Definition gtest_unittest.cc:6433
void SetUp() override
Definition gtest_unittest.cc:6432
Definition gtest_unittest.cc:6884
void OnTestProgramStart(const UnitTest &) override
Definition gtest_unittest.cc:6890
void OnTestIterationStart(const UnitTest &, int) override
Definition gtest_unittest.cc:6898
void OnTestProgramEnd(const UnitTest &) override
Definition gtest_unittest.cc:6894
SequenceTestingListener(std::vector< std::string > *vector, const char *id)
Definition gtest_unittest.cc:6886
void OnTestIterationEnd(const UnitTest &, int) override
Definition gtest_unittest.cc:6903
Definition gtest_unittest.cc:6708
StaticAssertTypeEqTestHelper()
Definition gtest_unittest.cc:6710
Definition gtest_unittest.cc:6810
~TestListener() override
Definition gtest_unittest.cc:6816
void OnTestProgramStart(const UnitTest &) override
Definition gtest_unittest.cc:6821
TestListener(int *on_start_counter, bool *is_destroyed)
Definition gtest_unittest.cc:6813
TestListener()
Definition gtest_unittest.cc:6812
Definition gtest_unittest.cc:289
Definition googletest-output-test_.cc:733
Definition googletest-list-tests-unittest_.cc:108
Definition gtest_unittest.cc:6410
Definition gtest_unittest.cc:6405
Definition gtest_unittest.cc:6401
Definition gtest_unittest.cc:5171
MyTypeInNameSpace1(int an_x)
Definition gtest_unittest.cc:5173
Definition gtest_unittest.cc:5194
MyTypeInNameSpace2(int an_x)
Definition gtest_unittest.cc:5196
Definition gtest_unittest.cc:5304
Definition gtest_unittest.cc:5310
Definition gtest_unittest.cc:5328
Definition gtest_unittest.cc:5319
Definition gtest_unittest.cc:6346
static void TearDownTestSuite()
Definition gtest_unittest.cc:6359
static void SetUpTestSuite()
Definition gtest_unittest.cc:6350
Definition gtest-message.h:101
std::string GetString() const
Definition gtest.cc:1301
Definition gtest_unittest.cc:5651
static void CheckFlags(const Flags &expected)
Definition gtest_unittest.cc:5686
void SetUp() override
Definition gtest_unittest.cc:5654
static void AssertStringArrayEq(int size1, CharType **array1, int size2, CharType **array2)
Definition gtest_unittest.cc:5676
static void TestParsingFlags(int argc1, const CharType **argv1, int argc2, const CharType **argv2, const Flags &expected, bool should_print_help)
Definition gtest_unittest.cc:5714
Definition gtest_unittest.cc:5346
static void SetUpTestCase()
Definition gtest_unittest.cc:5350
static int counter_
Definition gtest_unittest.cc:5388
void SetUp() override
Definition gtest_unittest.cc:5381
static const char * shared_resource_
Definition gtest_unittest.cc:5391
static void TearDownTestCase()
Definition gtest_unittest.cc:5367
Definition gtest_unittest.cc:5405
static int counter_
Definition gtest_unittest.cc:5447
static const char * shared_resource_
Definition gtest_unittest.cc:5450
static void TearDownTestSuite()
Definition gtest_unittest.cc:5426
void SetUp() override
Definition gtest_unittest.cc:5440
static void SetUpTestSuite()
Definition gtest_unittest.cc:5409
virtual void OnTestIterationEnd(const UnitTest &unit_test, int iteration)=0
virtual void OnTestProgramStart(const UnitTest &unit_test)=0
virtual void OnTestIterationStart(const UnitTest &unit_test, int iteration)=0
virtual void OnTestProgramEnd(const UnitTest &unit_test)=0
TestEventListener * Release(TestEventListener *listener)
Definition gtest.cc:5095
void Append(TestEventListener *listener)
Definition gtest.cc:5088
void SuppressEventForwarding(bool)
Definition gtest.cc:5143
TestEventListener * default_result_printer() const
Definition gtest.h:1043
TestEventListener * default_xml_generator() const
Definition gtest.h:1054
Definition gtest_unittest.cc:5255
static const TestResult * GetTestResult(const TestInfo *test_info)
Definition gtest_unittest.cc:5268
static const TestInfo * GetTestInfo(const char *test_name)
Definition gtest_unittest.cc:5257
const char * name() const
Definition gtest.h:549
const TestResult * result() const
Definition gtest.h:600
const char * test_suite_name() const
Definition gtest.h:541
const char * value() const
Definition gtest.h:382
const char * key() const
Definition gtest.h:379
int total_part_count() const
Definition gtest.cc:2447
const TestProperty & GetTestProperty(int i) const
Definition gtest.cc:2270
const TestPartResult & GetTestPartResult(int i) const
Definition gtest.cc:2262
bool Passed() const
Definition gtest.h:416
bool Failed() const
Definition gtest.cc:2418
int test_property_count() const
Definition gtest.cc:2452
int total_test_count() const
Definition gtest.cc:2916
const TestResult & ad_hoc_test_result() const
Definition gtest.h:752
const TestInfo * GetTestInfo(int i) const
Definition gtest.cc:2948
static bool HasFailure()
Definition gtest.h:284
static bool HasNonfatalFailure()
Definition gtest.cc:2705
const TestInfo * current_test_info() const GTEST_LOCK_EXCLUDED_(mutex_)
Definition gtest.cc:5518
static UnitTest * GetInstance()
Definition gtest.cc:5156
const TestResult & ad_hoc_test_result() const
Definition gtest.cc:5275
Definition gtest-internal.h:1268
Definition gtest-internal.h:246
const Bits & bits() const
Definition gtest-internal.h:313
Definition gtest-internal-inl.h:140
Definition gtest-internal.h:881
Definition gtest-internal.h:1086
const_iterator begin() const
Definition gtest-internal.h:1114
const_iterator end() const
Definition gtest-internal.h:1115
size_t size() const
Definition gtest-internal.h:1113
Definition gtest-internal.h:855
static const uint32_t kMaxRange
Definition gtest-internal.h:857
Definition gtest-string.h:63
Definition gtest_unittest.cc:172
static bool EventForwardingEnabled(const TestEventListeners &listeners)
Definition gtest_unittest.cc:187
static TestEventListener * GetRepeater(TestEventListeners *listeners)
Definition gtest_unittest.cc:174
static void SetDefaultXmlGenerator(TestEventListeners *listeners, TestEventListener *listener)
Definition gtest_unittest.cc:182
static void SuppressEventForwarding(TestEventListeners *listeners)
Definition gtest_unittest.cc:191
static void SetDefaultResultPrinter(TestEventListeners *listeners, TestEventListener *listener)
Definition gtest_unittest.cc:178
Definition gtest-internal-inl.h:1041
static void ClearTestPartResults(TestResult *test_result)
Definition gtest-internal-inl.h:1049
static bool MatchesFilter(const std::string &name, const char *filter)
Definition gtest.cc:850
Definition gtest_unittest.cc:196
UnitTest unit_test_
Definition gtest_unittest.cc:205
void UnitTestRecordProperty(const char *key, const std::string &value)
Definition gtest_unittest.cc:201
UnitTestRecordPropertyTestHelper()
Definition gtest_unittest.cc:198
pRC::Float<> T
Definition externs_nonTT.hpp:1
int value
Definition gmock-actions_test.cc:1714
int i
Definition gmock-matchers-comparisons_test.cc:603
const double y
Definition gmock-matchers-containers_test.cc:377
int x
Definition gmock-matchers-containers_test.cc:376
const char * p
Definition gmock-matchers-containers_test.cc:379
char ch
Definition gmock-matchers-containers_test.cc:384
MockB b_
Definition gmock-spec-builders_test.cc:1330
MockA a_
Definition gmock-spec-builders_test.cc:1329
int * count
Definition gmock_stress_test.cc:90
FilePath testdata_path_
Definition googletest-filepath-test.cc:520
void TestEq1(int x)
Definition googletest-output-test_.cc:60
AnonymousEnum
Definition googletest-printers-test.cc:65
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)
Definition gtest-death-test.h:337
#define GTEST_REMOVE_REFERENCE_AND_CONST_(T)
Definition gtest-internal.h:874
#define TEST_P(test_suite_name, test_name)
Definition gtest-param-test.h:450
#define INSTANTIATE_TEST_SUITE_P(prefix, test_suite_name,...)
Definition gtest-param-test.h:496
#define GTEST_FLAG_PREFIX_
Definition gtest-port.h:331
#define GTEST_FLAG_PREFIX_UPPER_
Definition gtest-port.h:333
#define GTEST_DISABLE_MSC_DEPRECATED_PUSH_()
Definition gtest-port.h:373
#define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
Definition gtest-port.h:360
#define GTEST_REFERENCE_TO_CONST_(T)
Definition gtest-port.h:1116
#define GTEST_DISABLE_MSC_DEPRECATED_POP_()
Definition gtest-port.h:375
#define GTEST_FLAG_SET(name, value)
Definition gtest-port.h:2294
#define GTEST_DISABLE_MSC_WARNINGS_POP_()
Definition gtest-port.h:361
#define GTEST_CHECK_(condition)
Definition gtest-port.h:1078
#define GTEST_FLAG_GET(name)
Definition gtest-port.h:2293
#define EXPECT_FATAL_FAILURE(statement, substr)
Definition gtest-spi.h:149
#define EXPECT_NONFATAL_FAILURE(statement, substr)
Definition gtest-spi.h:217
#define EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(statement, substr)
Definition gtest-spi.h:234
#define EXPECT_FATAL_FAILURE_ON_ALL_THREADS(statement, substr)
Definition gtest-spi.h:167
#define REGISTER_TYPED_TEST_SUITE_P(SuiteName,...)
Definition gtest-typed-test.h:289
#define TYPED_TEST_SUITE_P(SuiteName)
Definition gtest-typed-test.h:259
#define TYPED_TEST_P(SuiteName, TestName)
Definition gtest-typed-test.h:270
#define INSTANTIATE_TYPED_TEST_SUITE_P(Prefix, SuiteName, Types,...)
Definition gtest-typed-test.h:306
#define TYPED_TEST(CaseName, TestName)
Definition gtest-typed-test.h:197
#define TYPED_TEST_SUITE(CaseName, Types,...)
Definition gtest-typed-test.h:191
#define EXPECT_NO_FATAL_FAILURE(statement)
Definition gtest.h:2042
#define EXPECT_STRCASENE(s1, s2)
Definition gtest.h:1943
#define GTEST_ASSERT_GT(val1, val2)
Definition gtest.h:1891
#define TEST_F(test_fixture, test_name)
Definition gtest.h:2208
#define ASSERT_GT(val1, val2)
Definition gtest.h:1918
#define ASSERT_EQ(val1, val2)
Definition gtest.h:1898
#define GTEST_TEST(test_suite_name, test_name)
Definition gtest.h:2169
#define GTEST_SUCCEED()
Definition gtest.h:1758
#define EXPECT_NO_THROW(statement)
Definition gtest.h:1777
#define ASSERT_STRNE(s1, s2)
Definition gtest.h:1948
#define FAIL()
Definition gtest.h:1754
#define EXPECT_EQ(val1, val2)
Definition gtest.h:1868
#define ADD_FAILURE_AT(file, line)
Definition gtest.h:1739
#define ASSERT_FLOAT_EQ(val1, val2)
Definition gtest.h:1977
#define ASSERT_NO_FATAL_FAILURE(statement)
Definition gtest.h:2040
#define GTEST_ASSERT_GE(val1, val2)
Definition gtest.h:1889
#define ASSERT_STRCASEEQ(s1, s2)
Definition gtest.h:1950
#define GTEST_ASSERT_LT(val1, val2)
Definition gtest.h:1887
#define GTEST_FAIL()
Definition gtest.h:1744
#define ASSERT_DOUBLE_EQ(val1, val2)
Definition gtest.h:1981
#define EXPECT_NE(val1, val2)
Definition gtest.h:1870
#define GTEST_ASSERT_NE(val1, val2)
Definition gtest.h:1883
#define ASSERT_NEAR(val1, val2, abs_error)
Definition gtest.h:1989
#define EXPECT_STRCASEEQ(s1, s2)
Definition gtest.h:1941
#define ASSERT_STREQ(s1, s2)
Definition gtest.h:1946
#define SUCCEED()
Definition gtest.h:1763
#define ASSERT_LE(val1, val2)
Definition gtest.h:1906
#define EXPECT_THROW(statement, expected_exception)
Definition gtest.h:1775
#define ASSERT_FALSE(condition)
Definition gtest.h:1819
#define EXPECT_NEAR(val1, val2, abs_error)
Definition gtest.h:1985
#define ASSERT_NO_THROW(statement)
Definition gtest.h:1783
#define GTEST_ASSERT_EQ(val1, val2)
Definition gtest.h:1881
#define EXPECT_FLOAT_EQ(val1, val2)
Definition gtest.h:1969
#define EXPECT_ANY_THROW(statement)
Definition gtest.h:1779
#define ASSERT_NE(val1, val2)
Definition gtest.h:1902
#define EXPECT_GT(val1, val2)
Definition gtest.h:1878
#define EXPECT_DOUBLE_EQ(val1, val2)
Definition gtest.h:1973
#define TEST(test_suite_name, test_name)
Definition gtest.h:2176
#define EXPECT_GE(val1, val2)
Definition gtest.h:1876
#define GTEST_ASSERT_LE(val1, val2)
Definition gtest.h:1885
#define EXPECT_TRUE(condition)
Definition gtest.h:1807
#define ASSERT_STRCASENE(s1, s2)
Definition gtest.h:1952
#define GTEST_FAIL_AT(file, line)
Definition gtest.h:1747
#define EXPECT_STREQ(s1, s2)
Definition gtest.h:1937
#define ADD_FAILURE()
Definition gtest.h:1735
#define EXPECT_LE(val1, val2)
Definition gtest.h:1872
#define ASSERT_TRUE(condition)
Definition gtest.h:1815
#define EXPECT_FALSE(condition)
Definition gtest.h:1811
#define ASSERT_THROW(statement, expected_exception)
Definition gtest.h:1781
#define EXPECT_STRNE(s1, s2)
Definition gtest.h:1939
#define EXPECT_LT(val1, val2)
Definition gtest.h:1874
#define ASSERT_GE(val1, val2)
Definition gtest.h:1914
#define ASSERT_ANY_THROW(statement)
Definition gtest.h:1785
#define ASSERT_LT(val1, val2)
Definition gtest.h:1910
#define EXPECT_PRED_FORMAT1(pred_format, v1)
Definition gtest_pred_impl.h:108
#define EXPECT_PRED3(pred, v1, v2, v3)
Definition gtest_pred_impl.h:184
#define EXPECT_PRED2(pred, v1, v2)
Definition gtest_pred_impl.h:145
#define ASSERT_PRED_FORMAT4(pred_format, v1, v2, v3, v4)
Definition gtest_pred_impl.h:227
#define EXPECT_PRED_FORMAT4(pred_format, v1, v2, v3, v4)
Definition gtest_pred_impl.h:223
#define ASSERT_PRED_FORMAT1(pred_format, v1)
Definition gtest_pred_impl.h:111
#define ASSERT_PRED2(pred, v1, v2)
Definition gtest_pred_impl.h:149
#define EXPECT_PRED1(pred, v1)
Definition gtest_pred_impl.h:110
#define EXPECT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5)
Definition gtest_pred_impl.h:268
#define ASSERT_PRED1(pred, v1)
Definition gtest_pred_impl.h:113
#define ASSERT_PRED3(pred, v1, v2, v3)
Definition gtest_pred_impl.h:188
#define ASSERT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5)
Definition gtest_pred_impl.h:272
#define ASSERT_PRED_FORMAT2(pred_format, v1, v2)
Definition gtest_pred_impl.h:147
#define EXPECT_PRED_FORMAT2(pred_format, v1, v2)
Definition gtest_pred_impl.h:143
#define FRIEND_TEST(test_case_name, test_name)
Definition gtest_prod.h:57
void TestGTestReferenceToConst()
Definition gtest_unittest.cc:7266
#define GTEST_TEST_PARSING_FLAGS_(argv1, argv2, expected, should_print_help)
Definition gtest_unittest.cc:5759
auto * dynamic_test
Definition gtest_unittest.cc:7732
static void FailFatally()
Definition gtest_unittest.cc:6730
void operator<<(ConvertibleGlobalType &, int)
#define VERIFY_CODE_LOCATION
Definition gtest_unittest.cc:5292
int IntAlias
Definition gtest_unittest.cc:6719
static bool HasNonfatalFailureHelper()
Definition gtest_unittest.cc:6755
#define GTEST_USE_UNPROTECTED_COMMA_
Definition gtest_unittest.cc:1302
static bool HasFailureHelper()
Definition gtest_unittest.cc:6797
static bool dummy1 GTEST_ATTRIBUTE_UNUSED_
Definition gtest_unittest.cc:6701
void TestGTestRemoveReferenceAndConst()
Definition gtest_unittest.cc:7250
Definition googletest-output-test_.cc:471
output
Definition gmock_output_test.py:182
Types< int, long > NumericTypes
Definition gtest-typed-test_test.cc:154
Definition gtest_unittest.cc:6396
Definition gtest_unittest.cc:5170
std::ostream & operator<<(std::ostream &os, const MyTypeInNameSpace1 &val)
Definition gtest_unittest.cc:5175
Definition gtest_unittest.cc:5193
constexpr auto operator!=(GaussianDistribution< T > const &lhs, GaussianDistribution< T > const &rhs)
Definition gaussian.hpp:114
constexpr auto operator==(GaussianDistribution< T > const &lhs, GaussianDistribution< T > const &rhs)
Definition gaussian.hpp:96
GTEST_API_ std::vector< EditType > CalculateOptimalEdits(const std::vector< size_t > &left, const std::vector< size_t > &right)
Definition gtest.cc:1308
GTEST_API_ std::string CreateUnifiedDiff(const std::vector< std::string > &left, const std::vector< std::string > &right, size_t context=2)
Definition gtest.cc:1483
EditType
Definition gtest-internal.h:174
int RmDir(const char *dir)
Definition gtest-port.h:2027
FILE * FOpen(const char *path, const char *mode)
Definition gtest-port.h:2089
GTEST_API_ std::string WideStringToUtf8(const wchar_t *str, int num_chars)
Definition gtest.cc:2056
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)
Definition gtest.cc:1593
void ShuffleRange(internal::Random *random, int begin, int end, std::vector< E > *v)
Definition gtest-internal-inl.h:304
GTEST_API_ bool ShouldShard(const char *total_shards_str, const char *shard_index_str, bool in_subprocess_for_death_test)
Definition gtest.cc:6017
int GetRandomSeedFromFlag(int32_t random_seed_flag)
Definition gtest-internal-inl.h:113
int CountIf(const Container &c, Predicate predicate)
Definition gtest-internal-inl.h:275
GTEST_API_ bool SkipPrefix(const char *prefix, const char **pstr)
Definition gtest.cc:6324
typename MakeIndexSequenceImpl< N >::type MakeIndexSequence
Definition gtest-internal.h:1175
const int kMaxRandomSeed
Definition gtest-internal-inl.h:83
GTEST_API_ bool ShouldRunTestOnShard(int total_shards, int shard_index, int test_id)
Definition gtest.cc:6079
GTEST_API_ void ParseGoogleTestFlagsOnly(int *argc, char **argv)
Definition gtest.cc:6685
bool AlwaysFalse()
Definition gtest-internal.h:829
void ForEach(const Container &c, Functor functor)
Definition gtest-internal-inl.h:287
std::string CanonicalizeForStdLibVersioning(std::string s)
Definition gtest-type-util.h:61
TypeId GetTypeId()
Definition gtest-internal.h:419
int GetNextRandomSeed(int seed)
Definition gtest-internal-inl.h:130
E GetElementOr(const std::vector< E > &v, int i, E default_value)
Definition gtest-internal-inl.h:294
constexpr BiggestInt kMaxBiggestInt
Definition gtest-port.h:2174
IsContainer IsContainerTest(int)
Definition gtest-internal.h:939
GTEST_API_ bool ParseFlag(const char *str, const char *flag, int32_t *value)
Definition gtest.cc:6392
void Shuffle(internal::Random *random, std::vector< E > *v)
Definition gtest-internal-inl.h:328
GTEST_API_ bool AlwaysTrue()
Definition gtest.cc:6312
GTEST_API_ bool g_help_flag
Definition gtest.cc:205
Iter ArrayAwareFind(Iter begin, Iter end, const Element &elem)
Definition gtest-internal.h:1034
class UnitTestImpl * GetUnitTestImpl()
Definition gtest-internal-inl.h:966
GTEST_API_ int32_t Int32FromEnvOrDie(const char *env_var, int32_t default_val)
Definition gtest.cc:6061
GTEST_API_ std::string FormatTimeInMillisAsSeconds(TimeInMillis ms)
std::string StreamableToString(const T &streamable)
Definition gtest-message.h:243
GTEST_API_ int32_t Int32FromGTestEnv(const char *flag, int32_t default_val)
Definition gtest-port.cc:1338
char IsNotContainer
Definition gtest-internal.h:943
GTEST_API_ std::string FormatEpochTimeInMillisAsIso8601(TimeInMillis ms)
GTEST_API_ bool ShouldUseColor(bool stdout_is_tty)
Definition gtest.cc:3238
GTEST_API_ const TypeId kTestTypeIdInGoogleTest
Definition gtest.cc:966
GTEST_API_ void CaptureStdout()
GTEST_API_ TypeId GetTestTypeId()
Definition gtest.cc:962
GTEST_API_ std::string CodePointToUtf8(uint32_t code_point)
Definition gtest.cc:1989
int IsContainer
Definition gtest-internal.h:932
GTEST_API_ std::string AppendUserMessage(const std::string >est_msg, const Message &user_msg)
Definition gtest.cc:2235
GTEST_API_ TimeInMillis GetTimeInMillis()
Definition gtest.cc:1174
GTEST_API_ std::string GetCapturedStdout()
bool ArrayEq(const T *lhs, size_t size, const U *rhs)
Definition gtest-internal.h:1024
void CopyArray(const T *from, size_t size, U *to)
Definition gtest-internal.h:1064
Definition gmock-actions.h:151
Environment * AddGlobalTestEnvironment(Environment *env)
Definition gtest.h:1330
GTEST_API_ AssertionResult IsNotSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
Definition gtest.cc:1845
GTEST_API_ AssertionResult FloatLE(const char *expr1, const char *expr2, float val1, float val2)
Definition gtest.cc:1714
GTEST_API_ AssertionResult IsSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
Definition gtest.cc:1835
AssertionResult AssertionFailure()
Definition gtest-assertion-result.cc:69
constexpr bool StaticAssertTypeEq() noexcept
Definition gtest.h:2139
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)
Definition gtest.h:2283
internal::TimeInMillis TimeInMillis
Definition gtest.h:364
GTEST_API_ std::string TempDir()
Definition gtest.cc:6850
internal::ValueArray< T... > Values(T... v)
Definition gtest-param-test.h:335
AssertionResult AssertionSuccess()
Definition gtest-assertion-result.cc:66
GTEST_API_ AssertionResult DoubleLE(const char *expr1, const char *expr2, double val1, double val2)
Definition gtest.cc:1721
const int kMaxStackTraceDepth
Definition gtest.h:172
Definition gtest_unittest.cc:7317
void hasher
Definition gtest_unittest.cc:7318
Definition gtest_pred_impl_unittest.cc:54
Definition gtest_unittest.cc:7301
const int & operator*() const
const_iterator & operator++()
Definition gtest_unittest.cc:7300
const_iterator begin() const
const_iterator end() const
Definition gtest_unittest.cc:7294
const_iterator end() const
const_iterator begin() const
int * const_iterator
Definition gtest_unittest.cc:7295
Definition gtest_unittest.cc:7556
ConstructionCounting & operator=(const ConstructionCounting &)
Definition gtest_unittest.cc:7561
ConstructionCounting()
Definition gtest_unittest.cc:7557
static void Reset()
Definition gtest_unittest.cc:7570
static int dtor_calls
Definition gtest_unittest.cc:7580
static int move_ctor_calls
Definition gtest_unittest.cc:7582
~ConstructionCounting()
Definition gtest_unittest.cc:7558
ConstructionCounting(ConstructionCounting &&) noexcept
Definition gtest_unittest.cc:7560
ConstructionCounting & operator=(ConstructionCounting &&) noexcept
Definition gtest_unittest.cc:7565
static int copy_assignment_calls
Definition gtest_unittest.cc:7583
ConstructionCounting(const ConstructionCounting &)
Definition gtest_unittest.cc:7559
static int move_assignment_calls
Definition gtest_unittest.cc:7584
static int copy_ctor_calls
Definition gtest_unittest.cc:7581
static int default_ctor_calls
Definition gtest_unittest.cc:7579
Definition gtest_unittest.cc:76
Definition gtest_unittest.cc:5109
Definition gtest_unittest.cc:7182
std::string ShortDebugString() const
Definition gtest_unittest.cc:7184
std::string DebugString() const
Definition gtest_unittest.cc:7183
Definition gtest_unittest.cc:7187
Definition gtest_unittest.cc:7199
std::string DebugString()
Definition gtest_unittest.cc:7200
Definition gtest_unittest.cc:7194
std::string DebugString()
Definition gtest_unittest.cc:7195
std::string ShortDebugString() const
Definition gtest_unittest.cc:7196
Definition gtest_unittest.cc:7320
void hasher
Definition gtest_unittest.cc:7321
void reverse_iterator
Definition gtest_unittest.cc:7322
Definition gtest_unittest.cc:7189
int ShortDebugString() const
Definition gtest_unittest.cc:7191
std::string DebugString() const
Definition gtest_unittest.cc:7190
Definition gtest_unittest.cc:5469
bool catch_exceptions
Definition gtest_unittest.cc:5633
bool recreate_environments_when_repeating
Definition gtest_unittest.cc:5643
static Flags Shuffle(bool shuffle)
Definition gtest_unittest.cc:5600
static Flags CatchExceptions(bool catch_exceptions)
Definition gtest_unittest.cc:5510
static Flags RandomSeed(int32_t random_seed)
Definition gtest_unittest.cc:5574
static Flags Brief(bool brief)
Definition gtest_unittest.cc:5558
int32_t repeat
Definition gtest_unittest.cc:5642
bool list_tests
Definition gtest_unittest.cc:5637
Flags()
Definition gtest_unittest.cc:5471
static Flags DeathTestUseFork(bool death_test_use_fork)
Definition gtest_unittest.cc:5518
static Flags Output(const char *output)
Definition gtest_unittest.cc:5550
bool shuffle
Definition gtest_unittest.cc:5644
static Flags Repeat(int32_t repeat)
Definition gtest_unittest.cc:5582
static Flags BreakOnFailure(bool break_on_failure)
Definition gtest_unittest.cc:5502
static Flags RecreateEnvironmentsWhenRepeating(bool recreate_environments_when_repeating)
Definition gtest_unittest.cc:5590
static Flags FailFast(bool fail_fast)
Definition gtest_unittest.cc:5526
bool death_test_use_fork
Definition gtest_unittest.cc:5634
static Flags ListTests(bool list_tests)
Definition gtest_unittest.cc:5542
bool print_time
Definition gtest_unittest.cc:5640
int32_t random_seed
Definition gtest_unittest.cc:5641
static Flags AlsoRunDisabledTests(bool also_run_disabled_tests)
Definition gtest_unittest.cc:5494
const char * output
Definition gtest_unittest.cc:5638
bool also_run_disabled_tests
Definition gtest_unittest.cc:5631
static Flags StreamResultTo(const char *stream_result_to)
Definition gtest_unittest.cc:5616
bool fail_fast
Definition gtest_unittest.cc:5635
const char * filter
Definition gtest_unittest.cc:5636
static Flags StackTraceDepth(int32_t stack_trace_depth)
Definition gtest_unittest.cc:5608
const char * stream_result_to
Definition gtest_unittest.cc:5646
bool throw_on_failure
Definition gtest_unittest.cc:5647
bool break_on_failure
Definition gtest_unittest.cc:5632
bool brief
Definition gtest_unittest.cc:5639
static Flags ThrowOnFailure(bool throw_on_failure)
Definition gtest_unittest.cc:5624
int32_t stack_trace_depth
Definition gtest_unittest.cc:5645
static Flags PrintTime(bool print_time)
Definition gtest_unittest.cc:5566
static Flags Filter(const char *filter)
Definition gtest_unittest.cc:5534
Definition gtest-internal.h:1198
Definition gtest-internal.h:1204
Definition gtest-internal.h:1148
Definition gtest-internal.h:954
Definition gtest-type-util.h:190
Definition gtest-internal.h:1075
Definition gtest-internal.h:1074