34 #include "gtest/gtest.h"
39 TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) {
66 #include <unordered_set>
68 #include "gtest/gtest-spi.h"
69 #include "src/gtest-internal-inl.h"
74 #if GTEST_CAN_STREAM_RESULTS_
76 class StreamingListenerTest :
public Test {
78 class FakeSocketWriter :
public StreamingListener::AbstractSocketWriter {
86 StreamingListenerTest()
87 : fake_sock_writer_(
new FakeSocketWriter),
88 streamer_(fake_sock_writer_),
89 test_info_obj_(
"FooTest",
"Bar", nullptr, nullptr,
90 CodeLocation(__FILE__, __LINE__), nullptr, nullptr) {}
95 FakeSocketWriter*
const fake_sock_writer_;
96 StreamingListener streamer_;
101 TEST_F(StreamingListenerTest, OnTestProgramEnd) {
103 streamer_.OnTestProgramEnd(unit_test_);
107 TEST_F(StreamingListenerTest, OnTestIterationEnd) {
109 streamer_.OnTestIterationEnd(unit_test_, 42);
110 EXPECT_EQ(
"event=TestIterationEnd&passed=1&elapsed_time=0ms\n", *
output());
113 TEST_F(StreamingListenerTest, OnTestCaseStart) {
115 streamer_.OnTestCaseStart(
TestCase(
"FooTest",
"Bar",
nullptr,
nullptr));
119 TEST_F(StreamingListenerTest, OnTestCaseEnd) {
121 streamer_.OnTestCaseEnd(
TestCase(
"FooTest",
"Bar",
nullptr,
nullptr));
125 TEST_F(StreamingListenerTest, OnTestStart) {
127 streamer_.OnTestStart(test_info_obj_);
131 TEST_F(StreamingListenerTest, OnTestEnd) {
133 streamer_.OnTestEnd(test_info_obj_);
137 TEST_F(StreamingListenerTest, OnTestPartResult) {
144 "event=TestPartResult&file=foo.cc&line=42&message=failed%3D%0A%26%25\n",
148 #endif // GTEST_CAN_STREAM_RESULTS_
176 class UnitTestRecordPropertyTestHelper :
public Test {
287 #if GTEST_HAS_STREAM_REDIRECTION
292 #if GTEST_IS_THREADSAFE
293 using testing::internal::ThreadWithParam;
302 for (
size_t i = 0;
i < vector.size();
i++) {
303 os << vector[
i] <<
" ";
312 TEST(GetRandomSeedFromFlagTest, HandlesZero) {
318 TEST(GetRandomSeedFromFlagTest, PreservesValidSeed) {
326 TEST(GetRandomSeedFromFlagTest, NormalizesInvalidSeed) {
336 TEST(GetNextRandomSeedTest, WorksForValidInput) {
349 static void ClearCurrentTestPartResults() {
350 TestResultAccessor::ClearTestPartResults(
356 TEST(GetTypeIdTest, ReturnsSameValueForSameType) {
357 EXPECT_EQ(GetTypeId<int>(), GetTypeId<int>());
358 EXPECT_EQ(GetTypeId<Test>(), GetTypeId<Test>());
361 class SubClassOfTest :
public Test {};
362 class AnotherSubClassOfTest :
public Test {};
364 TEST(GetTypeIdTest, ReturnsDifferentValuesForDifferentTypes) {
365 EXPECT_NE(GetTypeId<int>(), GetTypeId<const int>());
366 EXPECT_NE(GetTypeId<int>(), GetTypeId<char>());
370 EXPECT_NE(GetTypeId<AnotherSubClassOfTest>(), GetTypeId<SubClassOfTest>());
375 TEST(GetTestTypeIdTest, ReturnsTheSameValueInsideOrOutsideOfGoogleTest) {
406 TEST(FormatTimeInMillisAsSecondsTest, FormatsZero) {
410 TEST(FormatTimeInMillisAsSecondsTest, FormatsPositiveNumber) {
418 TEST(FormatTimeInMillisAsSecondsTest, FormatsNegativeNumber) {
432 class FormatEpochTimeInMillisAsIso8601Test :
public Test {
440 void SetUp()
override {
451 SetTimeZone("UTC+00");
454 void TearDown()
override {
455 SetTimeZone(saved_tz_);
456 free(
const_cast<char*
>(saved_tz_));
460 static void SetTimeZone(
const char* time_zone) {
464 #if _MSC_VER || GTEST_OS_WINDOWS_MINGW
475 setenv((
"TZ"), time_zone, 1);
483 const char* saved_tz_;
486 const TimeInMillis FormatEpochTimeInMillisAsIso8601Test::kMillisPerSec;
488 TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsTwoDigitSegments) {
493 TEST_F(FormatEpochTimeInMillisAsIso8601Test, MillisecondsDoNotAffectResult) {
495 "2011-10-31T18:52:42",
499 TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsLeadingZeroes) {
504 TEST_F(FormatEpochTimeInMillisAsIso8601Test, Prints24HourTime) {
509 TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsEpochStart) {
515 # pragma option push -w-ccc -w-rch
520 TEST(NullLiteralTest, IsTrueForNullLiterals) {
529 TEST(NullLiteralTest, IsFalseForNonNullLiterals) {
536 struct ConvertToAll {
537 template <
typename T>
543 struct ConvertToAllButNoPointers {
544 template <
typename T,
551 TEST(NullLiteralTest, ImplicitConversion) {
565 TEST(CodePointToUtf8Test, CanEncodeNul) {
570 TEST(CodePointToUtf8Test, CanEncodeAscii) {
579 TEST(CodePointToUtf8Test, CanEncode8To11Bits) {
593 TEST(CodePointToUtf8Test, CanEncode12To16Bits) {
603 #if !GTEST_WIDE_STRING_USES_UTF16_
610 TEST(CodePointToUtf8Test, CanEncode17To21Bits) {
622 TEST(CodePointToUtf8Test, CanEncodeInvalidCodePoint) {
626 #endif // !GTEST_WIDE_STRING_USES_UTF16_
631 TEST(WideStringToUtf8Test, CanEncodeNul) {
637 TEST(WideStringToUtf8Test, CanEncodeAscii) {
646 TEST(WideStringToUtf8Test, CanEncode8To11Bits) {
652 const wchar_t s[] = { 0x576,
'\0' };
659 TEST(WideStringToUtf8Test, CanEncode12To16Bits) {
661 const wchar_t s1[] = { 0x8D3,
'\0' };
666 const wchar_t s2[] = { 0xC74D,
'\0' };
672 TEST(WideStringToUtf8Test, StopsOnNulCharacter) {
678 TEST(WideStringToUtf8Test, StopsWhenLengthLimitReached) {
682 #if !GTEST_WIDE_STRING_USES_UTF16_
686 TEST(WideStringToUtf8Test, CanEncode17To21Bits) {
697 TEST(WideStringToUtf8Test, CanEncodeInvalidCodePoint) {
701 #else // !GTEST_WIDE_STRING_USES_UTF16_
704 TEST(WideStringToUtf8Test, CanEncodeValidUtf16SUrrogatePairs) {
705 const wchar_t s[] = { 0xD801, 0xDC00,
'\0' };
711 TEST(WideStringToUtf8Test, CanEncodeInvalidUtf16SurrogatePair) {
713 const wchar_t s1[] = { 0xD800,
'\0' };
716 const wchar_t s2[] = { 0xD800,
'M',
'\0' };
719 const wchar_t s3[] = { 0xDC00,
'P',
'Q',
'R',
'\0' };
722 #endif // !GTEST_WIDE_STRING_USES_UTF16_
725 #if !GTEST_WIDE_STRING_USES_UTF16_
726 TEST(WideStringToUtf8Test, ConcatenatesCodepointsCorrectly) {
727 const wchar_t s[] = { 0x108634, 0xC74D,
'\n', 0x576, 0x8D3, 0x108634,
'\0'};
738 TEST(WideStringToUtf8Test, ConcatenatesCodepointsCorrectly) {
739 const wchar_t s[] = { 0xC74D,
'\n', 0x576, 0x8D3,
'\0'};
741 "\xEC\x9D\x8D" "\n" "\xD5\xB6" "\xE0\xA3\x93",
744 #endif // !GTEST_WIDE_STRING_USES_UTF16_
748 TEST(RandomDeathTest, GeneratesCrashesOnInvalidRange) {
752 "Cannot generate a number in the range \\[0, 0\\)");
755 "Generation of a number in \\[0, 2147483649\\) was requested, "
756 "but this can only generate numbers in \\[0, 2147483648\\)");
760 const UInt32 kRange = 10000;
762 for (
int i = 0;
i < 10;
i++) {
763 EXPECT_LT(random.Generate(kRange), kRange) <<
" for iteration " <<
i;
767 for (
int i = 0;
i < 10;
i++) {
768 EXPECT_LT(random2.Generate(kRange), kRange) <<
" for iteration " <<
i;
773 const int kSeed = 123;
774 const int kArraySize = 10;
775 const UInt32 kRange = 10000;
779 for (
int i = 0;
i < kArraySize;
i++) {
780 values[
i] = random.Generate(kRange);
783 random.Reseed(kSeed);
784 for (
int i = 0;
i < kArraySize;
i++) {
793 static bool IsPositive(
int n) {
return n > 0; }
811 static int g_sum = 0;
812 static void Accumulate(
int n) { g_sum +=
n; }
854 "Invalid shuffle range start -1: must be in range \\[0, 3\\]");
857 "Invalid shuffle range start 4: must be in range \\[0, 3\\]");
860 "Invalid shuffle range finish 2: must be in range \\[3, 3\\]");
863 "Invalid shuffle range finish 4: must be in range \\[3, 3\\]");
866 class VectorShuffleTest :
public Test {
868 static const int kVectorSize = 20;
870 VectorShuffleTest() : random_(1) {
871 for (
int i = 0;
i < kVectorSize;
i++) {
872 vector_.push_back(
i);
877 if (kVectorSize !=
static_cast<int>(vector.size())) {
881 bool found_in_vector[kVectorSize] = {
false };
882 for (
size_t i = 0;
i < vector.size();
i++) {
883 const int e = vector[
i];
884 if (e < 0 || e >= kVectorSize || found_in_vector[e]) {
887 found_in_vector[
e] =
true;
895 static bool VectorIsNotCorrupt(
const TestingVector& vector) {
896 return !VectorIsCorrupt(vector);
901 if (
i != vector[
i]) {
908 static bool RangeIsUnshuffled(
910 return !RangeIsShuffled(vector,
begin,
end);
914 return RangeIsShuffled(vector, 0,
static_cast<int>(vector.size()));
917 static bool VectorIsUnshuffled(
const TestingVector& vector) {
918 return !VectorIsShuffled(vector);
925 const int VectorShuffleTest::kVectorSize;
927 TEST_F(VectorShuffleTest, HandlesEmptyRange) {
934 ShuffleRange(&random_, kVectorSize/2, kVectorSize/2, &vector_);
939 ShuffleRange(&random_, kVectorSize - 1, kVectorSize - 1, &vector_);
944 ShuffleRange(&random_, kVectorSize, kVectorSize, &vector_);
949 TEST_F(VectorShuffleTest, HandlesRangeOfSizeOne) {
956 ShuffleRange(&random_, kVectorSize/2, kVectorSize/2 + 1, &vector_);
961 ShuffleRange(&random_, kVectorSize - 1, kVectorSize, &vector_);
969 TEST_F(VectorShuffleTest, ShufflesEntireVector) {
977 EXPECT_NE(kVectorSize - 1, vector_[kVectorSize - 1]);
980 TEST_F(VectorShuffleTest, ShufflesStartOfVector) {
981 const int kRangeSize = kVectorSize/2;
987 EXPECT_PRED3(RangeIsUnshuffled, vector_, kRangeSize, kVectorSize);
990 TEST_F(VectorShuffleTest, ShufflesEndOfVector) {
991 const int kRangeSize = kVectorSize / 2;
992 ShuffleRange(&random_, kRangeSize, kVectorSize, &vector_);
995 EXPECT_PRED3(RangeIsUnshuffled, vector_, 0, kRangeSize);
996 EXPECT_PRED3(RangeIsShuffled, vector_, kRangeSize, kVectorSize);
999 TEST_F(VectorShuffleTest, ShufflesMiddleOfVector) {
1000 int kRangeSize = kVectorSize/3;
1001 ShuffleRange(&random_, kRangeSize, 2*kRangeSize, &vector_);
1004 EXPECT_PRED3(RangeIsUnshuffled, vector_, 0, kRangeSize);
1005 EXPECT_PRED3(RangeIsShuffled, vector_, kRangeSize, 2*kRangeSize);
1006 EXPECT_PRED3(RangeIsUnshuffled, vector_, 2*kRangeSize, kVectorSize);
1009 TEST_F(VectorShuffleTest, ShufflesRepeatably) {
1011 for (
int i = 0;
i < kVectorSize;
i++) {
1012 vector2.push_back(
i);
1015 random_.Reseed(1234);
1017 random_.Reseed(1234);
1023 for (
int i = 0;
i < kVectorSize;
i++) {
1024 EXPECT_EQ(vector_[
i], vector2[
i]) <<
" where i is " <<
i;
1030 TEST(AssertHelperTest, AssertHelperIsSmall) {
1037 TEST(StringTest, EndsWithCaseInsensitive) {
1038 EXPECT_TRUE(String::EndsWithCaseInsensitive(
"foobar",
"BAR"));
1039 EXPECT_TRUE(String::EndsWithCaseInsensitive(
"foobaR",
"bar"));
1040 EXPECT_TRUE(String::EndsWithCaseInsensitive(
"foobar",
""));
1041 EXPECT_TRUE(String::EndsWithCaseInsensitive(
"",
""));
1043 EXPECT_FALSE(String::EndsWithCaseInsensitive(
"Foobar",
"foo"));
1044 EXPECT_FALSE(String::EndsWithCaseInsensitive(
"foobar",
"Foo"));
1045 EXPECT_FALSE(String::EndsWithCaseInsensitive(
"",
"foo"));
1051 static const wchar_t*
const kNull =
nullptr;
1054 TEST(StringTest, CaseInsensitiveWideCStringEquals) {
1055 EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(
nullptr,
nullptr));
1060 EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(
L"foobar",
L"foobar"));
1061 EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(
L"foobar",
L"FOOBAR"));
1062 EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(
L"FOOBAR",
L"foobar"));
1065 #if GTEST_OS_WINDOWS
1068 TEST(StringTest, ShowWideCString) {
1070 String::ShowWideCString(NULL).
c_str());
1075 # if GTEST_OS_WINDOWS_MOBILE
1076 TEST(StringTest, AnsiAndUtf16Null) {
1077 EXPECT_EQ(NULL, String::AnsiToUtf16(NULL));
1078 EXPECT_EQ(NULL, String::Utf16ToAnsi(NULL));
1081 TEST(StringTest, AnsiAndUtf16ConvertBasic) {
1082 const char* ansi = String::Utf16ToAnsi(
L"str");
1085 const WCHAR* utf16 = String::AnsiToUtf16(
"str");
1090 TEST(StringTest, AnsiAndUtf16ConvertPathChars) {
1091 const char* ansi = String::Utf16ToAnsi(
L".:\\ \"*?");
1094 const WCHAR* utf16 = String::AnsiToUtf16(
".:\\ \"*?");
1095 EXPECT_EQ(0, wcsncmp(
L".:\\ \"*?", utf16, 3));
1098 # endif // GTEST_OS_WINDOWS_MOBILE
1100 #endif // GTEST_OS_WINDOWS
1110 TEST(TestPropertyTest, ReplaceStringValue) {
1113 property.SetValue(
"2");
1120 static void AddFatalFailure() {
1121 FAIL() <<
"Expected fatal failure.";
1124 static void AddNonfatalFailure() {
1128 class ScopedFakeTestPartResultReporterTest :
public Test {
1134 static void AddFailure(FailureMode failure) {
1138 AddNonfatalFailure();
1145 TEST_F(ScopedFakeTestPartResultReporterTest, InterceptsTestFailures) {
1149 ScopedFakeTestPartResultReporter::INTERCEPT_ONLY_CURRENT_THREAD,
1151 AddFailure(NONFATAL_FAILURE);
1160 TEST_F(ScopedFakeTestPartResultReporterTest, DeprecatedConstructor) {
1165 AddFailure(NONFATAL_FAILURE);
1170 #if GTEST_IS_THREADSAFE
1172 class ScopedFakeTestPartResultReporterWithThreadsTest
1173 :
public ScopedFakeTestPartResultReporterTest {
1175 static void AddFailureInOtherThread(FailureMode failure) {
1176 ThreadWithParam<FailureMode>
thread(&AddFailure, failure,
nullptr);
1181 TEST_F(ScopedFakeTestPartResultReporterWithThreadsTest,
1182 InterceptsTestFailuresInAllThreads) {
1186 ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS, &
results);
1187 AddFailure(NONFATAL_FAILURE);
1189 AddFailureInOtherThread(NONFATAL_FAILURE);
1200 #endif // GTEST_IS_THREADSAFE
1206 typedef ScopedFakeTestPartResultReporterTest ExpectFatalFailureTest;
1208 TEST_F(ExpectFatalFailureTest, CatchesFatalFaliure) {
1212 #if GTEST_HAS_GLOBAL_STRING
1213 TEST_F(ExpectFatalFailureTest, AcceptsStringObject) {
1218 TEST_F(ExpectFatalFailureTest, AcceptsStdStringObject) {
1223 TEST_F(ExpectFatalFailureTest, CatchesFatalFailureOnAllThreads) {
1227 "Expected fatal failure.");
1232 # pragma option push -w-ccc
1238 int NonVoidFunction() {
1244 TEST_F(ExpectFatalFailureTest, CanBeUsedInNonVoidFunction) {
1251 void DoesNotAbortHelper(
bool* aborted) {
1263 TEST_F(ExpectFatalFailureTest, DoesNotAbort) {
1264 bool aborted =
true;
1265 DoesNotAbortHelper(&aborted);
1273 static int global_var = 0;
1274 #define GTEST_USE_UNPROTECTED_COMMA_ global_var++, global_var++
1276 TEST_F(ExpectFatalFailureTest, AcceptsMacroThatExpandsToUnprotectedComma) {
1277 #ifndef __BORLANDC__
1293 typedef ScopedFakeTestPartResultReporterTest ExpectNonfatalFailureTest;
1295 TEST_F(ExpectNonfatalFailureTest, CatchesNonfatalFailure) {
1297 "Expected non-fatal failure.");
1300 #if GTEST_HAS_GLOBAL_STRING
1301 TEST_F(ExpectNonfatalFailureTest, AcceptsStringObject) {
1303 ::
string(
"Expected non-fatal failure."));
1307 TEST_F(ExpectNonfatalFailureTest, AcceptsStdStringObject) {
1312 TEST_F(ExpectNonfatalFailureTest, CatchesNonfatalFailureOnAllThreads) {
1316 "Expected non-fatal failure.");
1322 TEST_F(ExpectNonfatalFailureTest, AcceptsMacroThatExpandsToUnprotectedComma) {
1325 AddNonfatalFailure();
1330 AddNonfatalFailure();
1334 #if GTEST_IS_THREADSAFE
1336 typedef ScopedFakeTestPartResultReporterWithThreadsTest
1337 ExpectFailureWithThreadsTest;
1339 TEST_F(ExpectFailureWithThreadsTest, ExpectFatalFailureOnAllThreads) {
1341 "Expected fatal failure.");
1344 TEST_F(ExpectFailureWithThreadsTest, ExpectNonFatalFailureOnAllThreads) {
1346 AddFailureInOtherThread(NONFATAL_FAILURE),
"Expected non-fatal failure.");
1349 #endif // GTEST_IS_THREADSAFE
1353 TEST(TestPropertyTest, ConstructorWorks) {
1359 TEST(TestPropertyTest, SetValue) {
1362 property.SetValue(
"value_2");
1370 class TestResultTest :
public Test {
1372 typedef std::vector<TestPartResult> TPRVector;
1380 void SetUp()
override {
1402 TPRVector* results1 =
const_cast<TPRVector*
>(
1403 &TestResultAccessor::test_part_results(*r1));
1404 TPRVector* results2 =
const_cast<TPRVector*
>(
1405 &TestResultAccessor::test_part_results(*r2));
1410 results1->push_back(*pr1);
1413 results2->push_back(*pr1);
1414 results2->push_back(*pr2);
1417 void TearDown()
override {
1427 static void CompareTestPartResult(
const TestPartResult& expected,
1442 TEST_F(TestResultTest, total_part_count) {
1449 TEST_F(TestResultTest, Passed) {
1456 TEST_F(TestResultTest, Failed) {
1464 typedef TestResultTest TestResultDeathTest;
1466 TEST_F(TestResultDeathTest, GetTestPartResult) {
1474 TEST(TestResultPropertyTest, NoPropertiesFoundWhenNoneAreAdded) {
1480 TEST(TestResultPropertyTest, OnePropertyFoundWhenAdded) {
1483 TestResultAccessor::RecordProperty(&
test_result,
"testcase", property);
1491 TEST(TestResultPropertyTest, MultiplePropertiesFoundWhenAdded) {
1495 TestResultAccessor::RecordProperty(&
test_result,
"testcase", property_1);
1496 TestResultAccessor::RecordProperty(&
test_result,
"testcase", property_2);
1508 TEST(TestResultPropertyTest, OverridesValuesForDuplicateKeys) {
1514 TestResultAccessor::RecordProperty(&
test_result,
"testcase", property_1_1);
1515 TestResultAccessor::RecordProperty(&
test_result,
"testcase", property_2_1);
1516 TestResultAccessor::RecordProperty(&
test_result,
"testcase", property_1_2);
1517 TestResultAccessor::RecordProperty(&
test_result,
"testcase", property_2_2);
1530 TEST(TestResultPropertyTest, GetTestProperty) {
1535 TestResultAccessor::RecordProperty(&
test_result,
"testcase", property_1);
1536 TestResultAccessor::RecordProperty(&
test_result,
"testcase", property_2);
1537 TestResultAccessor::RecordProperty(&
test_result,
"testcase", property_3);
1568 class GTestFlagSaverTest :
public Test {
1573 static void SetUpTestSuite() {
1595 static void TearDownTestSuite() {
1602 void VerifyAndModifyFlags() {
1632 GTEST_FLAG(stream_result_to) =
"localhost:1234";
1647 TEST_F(GTestFlagSaverTest, ModifyGTestFlags) {
1648 VerifyAndModifyFlags();
1653 TEST_F(GTestFlagSaverTest, VerifyGTestFlags) {
1654 VerifyAndModifyFlags();
1660 static void SetEnv(
const char*
name,
const char*
value) {
1661 #if GTEST_OS_WINDOWS_MOBILE
1664 #elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9)
1668 static std::map<std::string, std::string*> added_env;
1673 if (added_env.find(
name) != added_env.end()) {
1674 prev_env = added_env[
name];
1682 putenv(
const_cast<char*
>(added_env[
name]->
c_str()));
1684 #elif GTEST_OS_WINDOWS // If we are on Windows proper.
1687 if (*
value ==
'\0') {
1692 #endif // GTEST_OS_WINDOWS_MOBILE
1695 #if !GTEST_OS_WINDOWS_MOBILE
1704 TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenVariableIsNotSet) {
1709 # if !defined(GTEST_GET_INT32_FROM_ENV_)
1713 TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenValueOverflows) {
1714 printf(
"(expecting 2 warnings)\n");
1725 TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenValueIsInvalid) {
1726 printf(
"(expecting 2 warnings)\n");
1735 # endif // !defined(GTEST_GET_INT32_FROM_ENV_)
1740 TEST(Int32FromGTestEnvTest, ParsesAndReturnsValidValue) {
1747 #endif // !GTEST_OS_WINDOWS_MOBILE
1753 TEST(ParseInt32FlagTest, ReturnsFalseForInvalidFlag) {
1764 TEST(ParseInt32FlagTest, ReturnsDefaultWhenValueOverflows) {
1765 printf(
"(expecting 2 warnings)\n");
1778 TEST(ParseInt32FlagTest, ReturnsDefaultWhenValueIsInvalid) {
1779 printf(
"(expecting 2 warnings)\n");
1792 TEST(ParseInt32FlagTest, ParsesAndReturnsValidValue) {
1805 #if !GTEST_OS_WINDOWS_MOBILE
1806 TEST(Int32FromEnvOrDieTest, ParsesAndReturnsValidValue) {
1813 #endif // !GTEST_OS_WINDOWS_MOBILE
1817 TEST(Int32FromEnvOrDieDeathTest, AbortsOnFailure) {
1826 TEST(Int32FromEnvOrDieDeathTest, AbortsOnInt32Overflow) {
1835 TEST(ShouldRunTestOnShardTest, IsPartitionWhenThereIsOneShard) {
1845 void SetUp()
override {
1850 void TearDown()
override {
1851 SetEnv(index_var_,
"");
1852 SetEnv(total_var_,
"");
1855 const char* index_var_;
1856 const char* total_var_;
1861 TEST_F(ShouldShardTest, ReturnsFalseWhenNeitherEnvVarIsSet) {
1862 SetEnv(index_var_,
"");
1863 SetEnv(total_var_,
"");
1870 TEST_F(ShouldShardTest, ReturnsFalseWhenTotalShardIsOne) {
1871 SetEnv(index_var_,
"0");
1872 SetEnv(total_var_,
"1");
1880 #if !GTEST_OS_WINDOWS_MOBILE
1881 TEST_F(ShouldShardTest, WorksWhenShardEnvVarsAreValid) {
1882 SetEnv(index_var_,
"4");
1883 SetEnv(total_var_,
"22");
1887 SetEnv(index_var_,
"8");
1888 SetEnv(total_var_,
"9");
1892 SetEnv(index_var_,
"0");
1893 SetEnv(total_var_,
"9");
1897 #endif // !GTEST_OS_WINDOWS_MOBILE
1901 typedef ShouldShardTest ShouldShardDeathTest;
1903 TEST_F(ShouldShardDeathTest, AbortsWhenShardingEnvVarsAreInvalid) {
1904 SetEnv(index_var_,
"4");
1905 SetEnv(total_var_,
"4");
1908 SetEnv(index_var_,
"4");
1909 SetEnv(total_var_,
"-2");
1912 SetEnv(index_var_,
"5");
1913 SetEnv(total_var_,
"");
1916 SetEnv(index_var_,
"");
1917 SetEnv(total_var_,
"5");
1923 TEST(ShouldRunTestOnShardTest, IsPartitionWhenThereAreFiveShards) {
1925 const int num_tests = 17;
1926 const int num_shards = 5;
1929 for (
int test_id = 0; test_id < num_tests; test_id++) {
1930 int prev_selected_shard_index = -1;
1931 for (
int shard_index = 0; shard_index < num_shards; shard_index++) {
1933 if (prev_selected_shard_index < 0) {
1934 prev_selected_shard_index = shard_index;
1936 ADD_FAILURE() <<
"Shard " << prev_selected_shard_index <<
" and "
1937 << shard_index <<
" are both selected to run test " << test_id;
1945 for (
int shard_index = 0; shard_index < num_shards; shard_index++) {
1946 int num_tests_on_shard = 0;
1947 for (
int test_id = 0; test_id < num_tests; test_id++) {
1948 num_tests_on_shard +=
1951 EXPECT_GE(num_tests_on_shard, num_tests / num_shards);
1965 TEST(UnitTestTest, CanGetOriginalWorkingDir) {
1966 ASSERT_TRUE(UnitTest::GetInstance()->original_working_dir() !=
nullptr);
1967 EXPECT_STRNE(UnitTest::GetInstance()->original_working_dir(),
"");
1970 TEST(UnitTestTest, ReturnsPlausibleTimestamp) {
1971 EXPECT_LT(0, UnitTest::GetInstance()->start_timestamp());
1978 void ExpectNonFatalFailureRecordingPropertyWithReservedKey(
1982 <<
"' recorded unexpectedly.";
1985 void ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
1987 const TestInfo* test_info = UnitTest::GetInstance()->current_test_info();
1989 ExpectNonFatalFailureRecordingPropertyWithReservedKey(*test_info->
result(),
1993 void ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
1995 const TestCase* test_case = UnitTest::GetInstance()->current_test_case();
1997 ExpectNonFatalFailureRecordingPropertyWithReservedKey(
1998 test_case->ad_hoc_test_result(),
key);
2001 void ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2003 ExpectNonFatalFailureRecordingPropertyWithReservedKey(
2004 UnitTest::GetInstance()->ad_hoc_test_result(),
key);
2010 class UnitTestRecordPropertyTest :
2013 static void SetUpTestSuite() {
2014 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2016 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2018 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2020 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2022 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2024 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2027 Test::RecordProperty(
"test_case_key_1",
"1");
2029 UnitTest::GetInstance()->current_test_case();
2034 test_suite->ad_hoc_test_result().GetTestProperty(0).key());
2036 test_suite->ad_hoc_test_result().GetTestProperty(0).value());
2041 TEST_F(UnitTestRecordPropertyTest, OnePropertyFoundWhenAdded) {
2042 UnitTestRecordProperty(
"key_1",
"1");
2044 ASSERT_EQ(1, unit_test_.ad_hoc_test_result().test_property_count());
2047 unit_test_.ad_hoc_test_result().GetTestProperty(0).key());
2049 unit_test_.ad_hoc_test_result().GetTestProperty(0).value());
2053 TEST_F(UnitTestRecordPropertyTest, MultiplePropertiesFoundWhenAdded) {
2054 UnitTestRecordProperty(
"key_1",
"1");
2055 UnitTestRecordProperty(
"key_2",
"2");
2057 ASSERT_EQ(2, unit_test_.ad_hoc_test_result().test_property_count());
2060 unit_test_.ad_hoc_test_result().GetTestProperty(0).key());
2061 EXPECT_STREQ(
"1", unit_test_.ad_hoc_test_result().GetTestProperty(0).value());
2064 unit_test_.ad_hoc_test_result().GetTestProperty(1).key());
2065 EXPECT_STREQ(
"2", unit_test_.ad_hoc_test_result().GetTestProperty(1).value());
2069 TEST_F(UnitTestRecordPropertyTest, OverridesValuesForDuplicateKeys) {
2070 UnitTestRecordProperty(
"key_1",
"1");
2071 UnitTestRecordProperty(
"key_2",
"2");
2072 UnitTestRecordProperty(
"key_1",
"12");
2073 UnitTestRecordProperty(
"key_2",
"22");
2075 ASSERT_EQ(2, unit_test_.ad_hoc_test_result().test_property_count());
2078 unit_test_.ad_hoc_test_result().GetTestProperty(0).key());
2080 unit_test_.ad_hoc_test_result().GetTestProperty(0).value());
2083 unit_test_.ad_hoc_test_result().GetTestProperty(1).key());
2085 unit_test_.ad_hoc_test_result().GetTestProperty(1).value());
2088 TEST_F(UnitTestRecordPropertyTest,
2089 AddFailureInsideTestsWhenUsingTestSuiteReservedKeys) {
2090 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2092 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2094 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2096 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2098 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2100 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2104 TEST_F(UnitTestRecordPropertyTest,
2105 AddRecordWithReservedKeysGeneratesCorrectPropertyList) {
2107 Test::RecordProperty(
"name",
"1"),
2108 "'classname', 'name', 'status', 'time', 'type_param', 'value_param',"
2109 " 'file', and 'line' are reserved");
2112 class UnitTestRecordPropertyTestEnvironment :
public Environment {
2114 void TearDown()
override {
2115 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2117 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2119 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2121 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2123 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2125 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2127 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2129 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2147 bool IsEven(
int n) {
2148 return (
n % 2) == 0;
2152 struct IsEvenFunctor {
2153 bool operator()(
int n) {
return IsEven(
n); }
2164 msg << expr <<
" evaluates to " <<
n <<
", which is not even.";
2189 struct AssertIsEvenFunctor {
2191 return AssertIsEven(expr,
n);
2196 bool SumIsEven2(
int n1,
int n2) {
2197 return IsEven(n1 + n2);
2202 struct SumIsEven3Functor {
2203 bool operator()(
int n1,
int n2,
int n3) {
2204 return IsEven(n1 + n2 + n3);
2211 const char* e1,
const char* e2,
const char* e3,
const char* e4,
2212 int n1,
int n2,
int n3,
int n4) {
2213 const int sum = n1 + n2 + n3 + n4;
2219 msg << e1 <<
" + " << e2 <<
" + " << e3 <<
" + " << e4
2220 <<
" (" << n1 <<
" + " << n2 <<
" + " << n3 <<
" + " << n4
2221 <<
") evaluates to " <<
sum <<
", which is not even.";
2227 struct AssertSumIsEven5Functor {
2229 const char* e1,
const char* e2,
const char* e3,
const char* e4,
2230 const char* e5,
int n1,
int n2,
int n3,
int n4,
int n5) {
2231 const int sum = n1 + n2 + n3 + n4 + n5;
2237 msg << e1 <<
" + " << e2 <<
" + " << e3 <<
" + " << e4 <<
" + " << e5
2239 << n1 <<
" + " << n2 <<
" + " << n3 <<
" + " << n4 <<
" + " << n5
2240 <<
") evaluates to " <<
sum <<
", which is not even.";
2249 TEST(Pred1Test, WithoutFormat) {
2251 EXPECT_PRED1(IsEvenFunctor(), 2) <<
"This failure is UNEXPECTED!";
2256 EXPECT_PRED1(IsEven, 5) <<
"This failure is expected.";
2257 },
"This failure is expected.");
2259 "evaluates to false");
2263 TEST(Pred1Test, WithFormat) {
2267 <<
"This failure is UNEXPECTED!";
2272 "n evaluates to 5, which is not even.");
2275 },
"This failure is expected.");
2280 TEST(Pred1Test, SingleEvaluationOnFailure) {
2284 EXPECT_EQ(1,
n) <<
"The argument is not evaluated exactly once.";
2289 <<
"This failure is expected.";
2290 },
"This failure is expected.");
2291 EXPECT_EQ(2,
n) <<
"The argument is not evaluated exactly once.";
2298 TEST(PredTest, WithoutFormat) {
2300 ASSERT_PRED2(SumIsEven2, 2, 4) <<
"This failure is UNEXPECTED!";
2307 EXPECT_PRED2(SumIsEven2, n1, n2) <<
"This failure is expected.";
2308 },
"This failure is expected.");
2311 },
"evaluates to false");
2315 TEST(PredTest, WithFormat) {
2318 "This failure is UNEXPECTED!";
2328 },
"evaluates to 13, which is not even.");
2331 <<
"This failure is expected.";
2332 },
"This failure is expected.");
2337 TEST(PredTest, SingleEvaluationOnFailure) {
2342 EXPECT_EQ(1, n1) <<
"Argument 1 is not evaluated exactly once.";
2343 EXPECT_EQ(1, n2) <<
"Argument 2 is not evaluated exactly once.";
2351 n1++, n2++, n3++, n4++, n5++)
2352 <<
"This failure is UNEXPECTED!";
2353 EXPECT_EQ(1, n1) <<
"Argument 1 is not evaluated exactly once.";
2354 EXPECT_EQ(1, n2) <<
"Argument 2 is not evaluated exactly once.";
2355 EXPECT_EQ(1, n3) <<
"Argument 3 is not evaluated exactly once.";
2356 EXPECT_EQ(1, n4) <<
"Argument 4 is not evaluated exactly once.";
2357 EXPECT_EQ(1, n5) <<
"Argument 5 is not evaluated exactly once.";
2363 <<
"This failure is expected.";
2364 },
"This failure is expected.");
2365 EXPECT_EQ(1, n1) <<
"Argument 1 is not evaluated exactly once.";
2366 EXPECT_EQ(1, n2) <<
"Argument 2 is not evaluated exactly once.";
2367 EXPECT_EQ(1, n3) <<
"Argument 3 is not evaluated exactly once.";
2370 n1 = n2 = n3 = n4 = 0;
2373 },
"evaluates to 1, which is not even.");
2374 EXPECT_EQ(1, n1) <<
"Argument 1 is not evaluated exactly once.";
2375 EXPECT_EQ(1, n2) <<
"Argument 2 is not evaluated exactly once.";
2376 EXPECT_EQ(1, n3) <<
"Argument 3 is not evaluated exactly once.";
2377 EXPECT_EQ(1, n4) <<
"Argument 4 is not evaluated exactly once.";
2381 TEST(PredTest, ExpectPredEvalFailure) {
2382 std::set<int> set_a = {2, 1, 3, 4, 5};
2383 std::set<int> set_b = {0, 4, 8};
2384 const auto compare_sets = [] (std::set<int>, std::set<int>) {
return false; };
2387 "compare_sets(set_a, set_b) evaluates to false, where\nset_a evaluates "
2388 "to { 1, 2, 3, 4, 5 }\nset_b evaluates to { 0, 4, 8 }");
2394 bool IsPositive(
double x) {
2398 template <
typename T>
2399 bool IsNegative(
T x) {
2403 template <
typename T1,
typename T2>
2404 bool GreaterThan(
T1 x1,
T2 x2) {
2410 TEST(PredicateAssertionTest, AcceptsOverloadedFunction) {
2418 TEST(PredicateAssertionTest, AcceptsTemplateFunction) {
2439 template <
typename T>
2445 template <
typename T1,
typename T2>
2447 const T1& x1,
const T2& x2) {
2454 TEST(PredicateFormatAssertionTest, AcceptsOverloadedFunction) {
2461 TEST(PredicateFormatAssertionTest, AcceptsTemplateFunction) {
2471 const char *
const p1 =
"good";
2475 const char p2[] =
"good";
2479 " \"bad\"\n \"good\"");
2483 TEST(StringAssertionTest, ASSERT_STREQ_Null) {
2484 ASSERT_STREQ(
static_cast<const char*
>(
nullptr),
nullptr);
2489 TEST(StringAssertionTest, ASSERT_STREQ_Null2) {
2503 "\"Hi\" vs \"Hi\"");
2530 TEST(StringAssertionTest, STREQ_Wide) {
2532 ASSERT_STREQ(
static_cast<const wchar_t*
>(
nullptr),
nullptr);
2554 },
"Expected failure");
2558 TEST(StringAssertionTest, STRNE_Wide) {
2562 EXPECT_STRNE(
static_cast<const wchar_t*
>(
nullptr),
nullptr);
2585 ASSERT_STRNE(
L"abc\x8119",
L"abc\x8120") <<
"This shouldn't happen";
2592 TEST(IsSubstringTest, ReturnsCorrectResultForCString) {
2603 TEST(IsSubstringTest, ReturnsCorrectResultForWideCString) {
2609 IsSubstring(
"",
"",
static_cast<const wchar_t*
>(
nullptr),
nullptr));
2615 TEST(IsSubstringTest, GeneratesCorrectMessageForCString) {
2617 " Actual: \"needle\"\n"
2618 "Expected: a substring of haystack_expr\n"
2619 "Which is: \"haystack\"",
2621 "needle",
"haystack").failure_message());
2626 TEST(IsSubstringTest, ReturnsCorrectResultsForStdString) {
2631 #if GTEST_HAS_STD_WSTRING
2634 TEST(IsSubstringTest, ReturnsCorrectResultForStdWstring) {
2641 TEST(IsSubstringTest, GeneratesCorrectMessageForWstring) {
2643 " Actual: L\"needle\"\n"
2644 "Expected: a substring of haystack_expr\n"
2645 "Which is: L\"haystack\"",
2647 "needle_expr",
"haystack_expr",
2651 #endif // GTEST_HAS_STD_WSTRING
2657 TEST(IsNotSubstringTest, ReturnsCorrectResultForCString) {
2664 TEST(IsNotSubstringTest, ReturnsCorrectResultForWideCString) {
2671 TEST(IsNotSubstringTest, GeneratesCorrectMessageForWideCString) {
2673 " Actual: L\"needle\"\n"
2674 "Expected: not a substring of haystack_expr\n"
2675 "Which is: L\"two needles\"",
2677 "needle_expr",
"haystack_expr",
2678 L"needle",
L"two needles").failure_message());
2683 TEST(IsNotSubstringTest, ReturnsCorrectResultsForStdString) {
2690 TEST(IsNotSubstringTest, GeneratesCorrectMessageForStdString) {
2692 " Actual: \"needle\"\n"
2693 "Expected: not a substring of haystack_expr\n"
2694 "Which is: \"two needles\"",
2696 "needle_expr",
"haystack_expr",
2697 ::
std::string(
"needle"),
"two needles").failure_message());
2700 #if GTEST_HAS_STD_WSTRING
2704 TEST(IsNotSubstringTest, ReturnsCorrectResultForStdWstring) {
2710 #endif // GTEST_HAS_STD_WSTRING
2714 template <
typename RawType>
2715 class FloatingPointTest :
public Test {
2719 RawType close_to_positive_zero;
2720 RawType close_to_negative_zero;
2721 RawType further_from_negative_zero;
2723 RawType close_to_one;
2724 RawType further_from_one;
2727 RawType close_to_infinity;
2728 RawType further_from_infinity;
2735 typedef typename Floating::Bits Bits;
2737 void SetUp()
override {
2738 const size_t max_ulps = Floating::kMaxUlps;
2741 const Bits zero_bits = Floating(0).
bits();
2744 values_.close_to_positive_zero = Floating::ReinterpretBits(
2745 zero_bits + max_ulps/2);
2746 values_.close_to_negative_zero = -Floating::ReinterpretBits(
2747 zero_bits + max_ulps - max_ulps/2);
2748 values_.further_from_negative_zero = -Floating::ReinterpretBits(
2749 zero_bits + max_ulps + 1 - max_ulps/2);
2752 const Bits one_bits = Floating(1).bits();
2755 values_.close_to_one = Floating::ReinterpretBits(one_bits + max_ulps);
2756 values_.further_from_one = Floating::ReinterpretBits(
2757 one_bits + max_ulps + 1);
2760 values_.infinity = Floating::Infinity();
2763 const Bits infinity_bits = Floating(values_.infinity).bits();
2766 values_.close_to_infinity = Floating::ReinterpretBits(
2767 infinity_bits - max_ulps);
2768 values_.further_from_infinity = Floating::ReinterpretBits(
2769 infinity_bits - max_ulps - 1);
2774 values_.nan1 = Floating::ReinterpretBits(Floating::kExponentBitMask
2775 | (
static_cast<Bits
>(1) << (Floating::kFractionBitCount - 1)) | 1);
2776 values_.nan2 = Floating::ReinterpretBits(Floating::kExponentBitMask
2777 | (
static_cast<Bits
>(1) << (Floating::kFractionBitCount - 1)) | 200);
2781 EXPECT_EQ(
sizeof(RawType),
sizeof(Bits));
2784 static TestValues values_;
2787 template <
typename RawType>
2788 typename FloatingPointTest<RawType>::TestValues
2789 FloatingPointTest<RawType>::values_;
2792 typedef FloatingPointTest<float> FloatTest;
2795 TEST_F(FloatTest, Size) {
2800 TEST_F(FloatTest, Zeros) {
2813 TEST_F(FloatTest, AlmostZeros) {
2820 static const FloatTest::TestValues&
v = this->values_;
2828 v.further_from_negative_zero);
2829 },
"v.further_from_negative_zero");
2833 TEST_F(FloatTest, SmallDiff) {
2836 "values_.further_from_one");
2840 TEST_F(FloatTest, LargeDiff) {
2849 TEST_F(FloatTest, Infinity) {
2853 "-values_.infinity");
2869 static const FloatTest::TestValues&
v = this->values_;
2883 TEST_F(FloatTest, Reflexive) {
2890 TEST_F(FloatTest, Commutative) {
2904 "The difference between 1.0f and 1.5f is 0.5, "
2905 "which exceeds 0.25f");
2915 "The difference between 1.0f and 1.5f is 0.5, "
2916 "which exceeds 0.25f");
2922 TEST_F(FloatTest, FloatLESucceeds) {
2931 TEST_F(FloatTest, FloatLEFails) {
2934 "(2.0f) <= (1.0f)");
2939 },
"(values_.further_from_one) <= (1.0f)");
2943 },
"(values_.nan1) <= (values_.infinity)");
2946 },
"(-values_.infinity) <= (values_.nan1)");
2949 },
"(values_.nan1) <= (values_.nan1)");
2953 typedef FloatingPointTest<double> DoubleTest;
2956 TEST_F(DoubleTest, Size) {
2961 TEST_F(DoubleTest, Zeros) {
2974 TEST_F(DoubleTest, AlmostZeros) {
2981 static const DoubleTest::TestValues&
v = this->values_;
2989 v.further_from_negative_zero);
2990 },
"v.further_from_negative_zero");
2994 TEST_F(DoubleTest, SmallDiff) {
2997 "values_.further_from_one");
3001 TEST_F(DoubleTest, LargeDiff) {
3010 TEST_F(DoubleTest, Infinity) {
3014 "-values_.infinity");
3023 TEST_F(DoubleTest, NaN) {
3024 static const DoubleTest::TestValues&
v = this->values_;
3036 TEST_F(DoubleTest, Reflexive) {
3043 TEST_F(DoubleTest, Commutative) {
3057 "The difference between 1.0 and 1.5 is 0.5, "
3058 "which exceeds 0.25");
3068 "The difference between 1.0 and 1.5 is 0.5, "
3069 "which exceeds 0.25");
3075 TEST_F(DoubleTest, DoubleLESucceeds) {
3084 TEST_F(DoubleTest, DoubleLEFails) {
3092 },
"(values_.further_from_one) <= (1.0)");
3096 },
"(values_.nan1) <= (values_.infinity)");
3099 },
" (-values_.infinity) <= (values_.nan1)");
3102 },
"(values_.nan1) <= (values_.nan1)");
3112 FAIL() <<
"Unexpected failure: Disabled test should not be run.";
3123 TEST(DISABLED_TestSuite, TestShouldNotRun) {
3124 FAIL() <<
"Unexpected failure: Test in disabled test case should not be run.";
3129 TEST(DISABLED_TestSuite, DISABLED_TestShouldNotRun) {
3130 FAIL() <<
"Unexpected failure: Test in disabled test case should not be run.";
3135 class DisabledTestsTest :
public Test {
3137 static void SetUpTestSuite() {
3138 FAIL() <<
"Unexpected failure: All tests disabled in test case. "
3139 "SetUpTestSuite() should not be called.";
3142 static void TearDownTestSuite() {
3143 FAIL() <<
"Unexpected failure: All tests disabled in test case. "
3144 "TearDownTestSuite() should not be called.";
3148 TEST_F(DisabledTestsTest, DISABLED_TestShouldNotRun_1) {
3149 FAIL() <<
"Unexpected failure: Disabled test should not be run.";
3152 TEST_F(DisabledTestsTest, DISABLED_TestShouldNotRun_2) {
3153 FAIL() <<
"Unexpected failure: Disabled test should not be run.";
3158 #if GTEST_HAS_TYPED_TEST
3160 template <
typename T>
3168 FAIL() <<
"Unexpected failure: Disabled typed test should not run.";
3171 template <
typename T>
3172 class DISABLED_TypedTest :
public Test {
3177 TYPED_TEST(DISABLED_TypedTest, ShouldNotRun) {
3178 FAIL() <<
"Unexpected failure: Disabled typed test should not run.";
3181 #endif // GTEST_HAS_TYPED_TEST
3185 #if GTEST_HAS_TYPED_TEST_P
3187 template <
typename T>
3194 FAIL() <<
"Unexpected failure: "
3195 <<
"Disabled type-parameterized test should not run.";
3202 template <
typename T>
3203 class DISABLED_TypedTestP :
public Test {
3209 FAIL() <<
"Unexpected failure: "
3210 <<
"Disabled type-parameterized test should not run.";
3217 #endif // GTEST_HAS_TYPED_TEST_P
3221 class SingleEvaluationTest :
public Test {
3226 static void CompareAndIncrementCharPtrs() {
3232 static void CompareAndIncrementInts() {
3237 SingleEvaluationTest() {
3244 static const char*
const s1_;
3245 static const char*
const s2_;
3246 static const char* p1_;
3247 static const char* p2_;
3253 const char*
const SingleEvaluationTest::s1_ =
"01234";
3254 const char*
const SingleEvaluationTest::s2_ =
"abcde";
3255 const char* SingleEvaluationTest::p1_;
3256 const char* SingleEvaluationTest::p2_;
3262 TEST_F(SingleEvaluationTest, FailedASSERT_STREQ) {
3270 TEST_F(SingleEvaluationTest, ASSERT_STR) {
3285 TEST_F(SingleEvaluationTest, FailedASSERT_NE) {
3287 "(a_++) != (b_++)");
3293 TEST_F(SingleEvaluationTest, OtherCases) {
3322 #if GTEST_HAS_EXCEPTIONS
3324 void ThrowAnInteger() {
3329 TEST_F(SingleEvaluationTest, ExceptionTests) {
3341 },
bool),
"throws a different type");
3371 #endif // GTEST_HAS_EXCEPTIONS
3374 class NoFatalFailureTest :
public Test {
3377 void FailsNonFatal() {
3381 FAIL() <<
"some fatal failure";
3384 void DoAssertNoFatalFailureOnFails() {
3389 void DoExpectNoFatalFailureOnFails() {
3395 TEST_F(NoFatalFailureTest, NoFailure) {
3400 TEST_F(NoFatalFailureTest, NonFatalIsNoFailure) {
3403 "some non-fatal failure");
3406 "some non-fatal failure");
3409 TEST_F(NoFatalFailureTest, AssertNoFatalFailureOnFatalFailure) {
3413 DoAssertNoFatalFailureOnFails();
3416 EXPECT_EQ(TestPartResult::kFatalFailure,
3418 EXPECT_EQ(TestPartResult::kFatalFailure,
3426 TEST_F(NoFatalFailureTest, ExpectNoFatalFailureOnFatalFailure) {
3430 DoExpectNoFatalFailureOnFails();
3433 EXPECT_EQ(TestPartResult::kFatalFailure,
3435 EXPECT_EQ(TestPartResult::kNonFatalFailure,
3437 EXPECT_EQ(TestPartResult::kNonFatalFailure,
3447 TEST_F(NoFatalFailureTest, MessageIsStreamable) {
3454 EXPECT_EQ(TestPartResult::kNonFatalFailure,
3456 EXPECT_EQ(TestPartResult::kNonFatalFailure,
3466 std::string EditsToString(
const std::vector<EditType>& edits) {
3468 for (
size_t i = 0;
i < edits.size(); ++
i) {
3469 static const char kEdits[] =
" +-/";
3470 out.append(1, kEdits[edits[
i]]);
3476 std::vector<size_t>
out;
3477 for (
size_t i = 0;
i <
str.size(); ++
i) {
3484 std::vector<std::string>
out;
3485 for (
size_t i = 0;
i <
str.size(); ++
i) {
3486 out.push_back(
str.substr(
i, 1));
3491 TEST(EditDistance, TestSuites) {
3496 const char* expected_edits;
3497 const char* expected_diff;
3499 static const Case kCases[] = {
3501 {__LINE__,
"A",
"A",
" ",
""},
3502 {__LINE__,
"ABCDE",
"ABCDE",
" ",
""},
3504 {__LINE__,
"X",
"XA",
" +",
"@@ +1,2 @@\n X\n+A\n"},
3505 {__LINE__,
"X",
"XABCD",
" ++++",
"@@ +1,5 @@\n X\n+A\n+B\n+C\n+D\n"},
3507 {__LINE__,
"XA",
"X",
" -",
"@@ -1,2 @@\n X\n-A\n"},
3508 {__LINE__,
"XABCD",
"X",
" ----",
"@@ -1,5 @@\n X\n-A\n-B\n-C\n-D\n"},
3510 {__LINE__,
"A",
"a",
"/",
"@@ -1,1 +1,1 @@\n-A\n+a\n"},
3511 {__LINE__,
"ABCD",
"abcd",
"////",
3512 "@@ -1,4 +1,4 @@\n-A\n-B\n-C\n-D\n+a\n+b\n+c\n+d\n"},
3514 {__LINE__,
"ABCDEFGH",
"ABXEGH1",
" -/ - +",
3515 "@@ -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"},
3516 {__LINE__,
"AAAABCCCC",
"ABABCDCDC",
"- / + / ",
3517 "@@ -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"},
3518 {__LINE__,
"ABCDE",
"BCDCD",
"- +/",
3519 "@@ -1,5 +1,5 @@\n-A\n B\n C\n D\n-E\n+C\n+D\n"},
3520 {__LINE__,
"ABCDEFGHIJKL",
"BCDCDEFGJKLJK",
"- ++ -- ++",
3521 "@@ -1,4 +1,5 @@\n-A\n B\n+C\n+D\n C\n D\n"
3522 "@@ -6,7 +7,7 @@\n F\n G\n-H\n-I\n J\n K\n L\n+J\n+K\n"},
3524 for (
const Case*
c = kCases;
c->left; ++
c) {
3527 CharsToIndices(
c->right))))
3528 <<
"Left <" <<
c->left <<
"> Right <" <<
c->right <<
"> Edits <"
3530 CharsToIndices(
c->left), CharsToIndices(
c->right))) <<
">";
3532 CharsToLines(
c->right)))
3533 <<
"Left <" <<
c->left <<
"> Right <" <<
c->right <<
"> Diff <"
3543 EqFailure(
"foo",
"bar", foo_val, bar_val,
false)
3544 .failure_message());
3546 "Expected equality of these values:\n"
3554 EqFailure(
"foo",
"6", foo_val, bar_val,
false)
3555 .failure_message());
3557 "Expected equality of these values:\n"
3564 EqFailure(
"5",
"bar", foo_val, bar_val,
false)
3565 .failure_message());
3567 "Expected equality of these values:\n"
3574 EqFailure(
"5",
"6", foo_val, bar_val,
false).failure_message());
3576 "Expected equality of these values:\n"
3584 true).failure_message());
3586 "Expected equality of these values:\n"
3588 " Which is: \"x\"\n"
3590 " Which is: \"y\"\n"
3595 TEST(AssertionTest, EqFailureWithDiff) {
3597 "1\\n2XXX\\n3\\n5\\n6\\n7\\n8\\n9\\n10\\n11\\n12XXX\\n13\\n14\\n15");
3599 "1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n11\\n12\\n13\\n14");
3601 EqFailure(
"left",
"right", left, right,
false).failure_message());
3603 "Expected equality of these values:\n"
3606 "1\\n2XXX\\n3\\n5\\n6\\n7\\n8\\n9\\n10\\n11\\n12XXX\\n13\\n14\\n15\n"
3608 " Which is: 1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n11\\n12\\n13\\n14\n"
3609 "With diff:\n@@ -1,5 +1,6 @@\n 1\n-2XXX\n+2\n 3\n+4\n 5\n 6\n"
3610 "@@ -7,8 +8,6 @@\n 8\n 9\n-10\n 11\n-12XXX\n+12\n 13\n 14\n-15\n",
3629 # pragma option push -w-ccc -w-rch
3640 TEST(AssertionTest, AssertTrueWithAssertionResult) {
3642 #ifndef __BORLANDC__
3645 "Value of: ResultIsEven(3)\n"
3646 " Actual: false (3 is odd)\n"
3651 "Value of: ResultIsEvenNoExplanation(3)\n"
3652 " Actual: false (3 is odd)\n"
3666 TEST(AssertionTest, AssertFalseWithAssertionResult) {
3668 #ifndef __BORLANDC__
3671 "Value of: ResultIsEven(2)\n"
3672 " Actual: true (2 is even)\n"
3677 "Value of: ResultIsEvenNoExplanation(2)\n"
3690 TEST(ExpectTest, ASSERT_EQ_Double) {
3703 "Expected equality of these values:\n"
3710 TEST(AssertionTest, ASSERT_EQ_NULL) {
3712 const char*
p =
nullptr;
3728 TEST(ExpectTest, ASSERT_EQ_0) {
3743 "Expected: ('a') != ('a'), "
3744 "actual: 'a' (97, 0x61) vs 'a' (97, 0x61)");
3752 "Expected: (2) <= (0), actual: 2 vs 0");
3759 "Expected: (2) < (2), actual: 2 vs 2");
3767 "Expected: (2) >= (3), actual: 2 vs 3");
3774 "Expected: (2) > (2), actual: 2 vs 2");
3777 #if GTEST_HAS_EXCEPTIONS
3779 void ThrowNothing() {}
3785 # ifndef __BORLANDC__
3790 "Expected: ThrowAnInteger() throws an exception of type bool.\n"
3791 " Actual: it throws a different type.");
3796 "Expected: ThrowNothing() throws an exception of type bool.\n"
3797 " Actual: it throws nothing.");
3804 "Expected: ThrowAnInteger() doesn't throw an exception."
3805 "\n Actual: it throws.");
3813 "Expected: ThrowNothing() throws an exception.\n"
3814 " Actual: it doesn't.");
3817 #endif // GTEST_HAS_EXCEPTIONS
3821 TEST(AssertionTest, AssertPrecedence) {
3823 bool false_value =
false;
3833 TEST(AssertionTest, NonFixtureSubroutine) {
3835 " x\n Which is: 2");
3841 explicit Uncopyable(
int a_value) :
value_(a_value) {}
3844 bool operator==(
const Uncopyable& rhs)
const {
3845 return value() == rhs.value();
3850 Uncopyable(
const Uncopyable&);
3855 ::std::ostream&
operator<<(::std::ostream& os,
const Uncopyable&
value) {
3856 return os <<
value.value();
3860 bool IsPositiveUncopyable(
const Uncopyable&
x) {
3861 return x.value() > 0;
3865 void TestAssertNonPositive() {
3870 void TestAssertEqualsUncopyable() {
3877 TEST(AssertionTest, AssertWorksWithUncopyableObject) {
3882 "IsPositiveUncopyable(y) evaluates to false, where\ny evaluates to -1");
3884 "Expected equality of these values:\n"
3885 " x\n Which is: 5\n y\n Which is: -1");
3889 TEST(AssertionTest, ExpectWorksWithUncopyableObject) {
3894 "IsPositiveUncopyable(y) evaluates to false, where\ny evaluates to -1");
3897 "Expected equality of these values:\n"
3898 " x\n Which is: 5\n y\n Which is: -1");
3906 TEST(AssertionTest, NamedEnum) {
3914 #if !defined(__SUNPRO_CC) && !defined(__HP_aCC)
3937 # endif // GTEST_OS_LINUX
3945 EXPECT_EQ(
static_cast<int>(kCaseA),
static_cast<int>(kCaseB));
3947 # endif // GTEST_OS_LINUX
3956 "(kCaseA) >= (kCaseB)");
3967 # ifndef __BORLANDC__
3971 " kCaseB\n Which is: ");
3980 #endif // !GTEST_OS_MAC && !defined(__SUNPRO_CC)
3982 #if GTEST_OS_WINDOWS
3984 static HRESULT UnexpectedHRESULTFailure() {
3985 return E_UNEXPECTED;
3988 static HRESULT OkHRESULTSuccess() {
3992 static HRESULT FalseHRESULTSuccess() {
4000 TEST(HRESULTAssertionTest, EXPECT_HRESULT_SUCCEEDED) {
4001 EXPECT_HRESULT_SUCCEEDED(S_OK);
4002 EXPECT_HRESULT_SUCCEEDED(S_FALSE);
4005 "Expected: (UnexpectedHRESULTFailure()) succeeds.\n"
4006 " Actual: 0x8000FFFF");
4009 TEST(HRESULTAssertionTest, ASSERT_HRESULT_SUCCEEDED) {
4010 ASSERT_HRESULT_SUCCEEDED(S_OK);
4011 ASSERT_HRESULT_SUCCEEDED(S_FALSE);
4014 "Expected: (UnexpectedHRESULTFailure()) succeeds.\n"
4015 " Actual: 0x8000FFFF");
4018 TEST(HRESULTAssertionTest, EXPECT_HRESULT_FAILED) {
4019 EXPECT_HRESULT_FAILED(E_UNEXPECTED);
4022 "Expected: (OkHRESULTSuccess()) fails.\n"
4025 "Expected: (FalseHRESULTSuccess()) fails.\n"
4029 TEST(HRESULTAssertionTest, ASSERT_HRESULT_FAILED) {
4030 ASSERT_HRESULT_FAILED(E_UNEXPECTED);
4032 # ifndef __BORLANDC__
4036 "Expected: (OkHRESULTSuccess()) fails.\n"
4041 "Expected: (FalseHRESULTSuccess()) fails.\n"
4046 TEST(HRESULTAssertionTest, Streaming) {
4047 EXPECT_HRESULT_SUCCEEDED(S_OK) <<
"unexpected failure";
4048 ASSERT_HRESULT_SUCCEEDED(S_OK) <<
"unexpected failure";
4049 EXPECT_HRESULT_FAILED(E_UNEXPECTED) <<
"unexpected failure";
4050 ASSERT_HRESULT_FAILED(E_UNEXPECTED) <<
"unexpected failure";
4053 EXPECT_HRESULT_SUCCEEDED(E_UNEXPECTED) <<
"expected failure",
4054 "expected failure");
4056 # ifndef __BORLANDC__
4060 ASSERT_HRESULT_SUCCEEDED(E_UNEXPECTED) <<
"expected failure",
4061 "expected failure");
4065 EXPECT_HRESULT_FAILED(S_OK) <<
"expected failure",
4066 "expected failure");
4069 ASSERT_HRESULT_FAILED(S_OK) <<
"expected failure",
4070 "expected failure");
4073 #endif // GTEST_OS_WINDOWS
4077 # pragma option push -w-ccc -w-rch
4081 TEST(AssertionSyntaxTest, BasicAssertionsBehavesLikeSingleStatement) {
4083 ASSERT_TRUE(
false) <<
"This should never be executed; "
4084 "It's a compilation test only.";
4100 #if GTEST_HAS_EXCEPTIONS
4103 TEST(ExpectThrowTest, DoesNotGenerateUnreachableCodeWarning) {
4115 TEST(AssertionSyntaxTest, ExceptionAssertionsBehavesLikeSingleStatement) {
4140 #endif // GTEST_HAS_EXCEPTIONS
4142 TEST(AssertionSyntaxTest, NoFatalFailureAssertionsBehavesLikeSingleStatement) {
4145 <<
"It's a compilation test only.";
4166 TEST(AssertionSyntaxTest, WorksWithSwitch) {
4176 EXPECT_FALSE(
false) <<
"EXPECT_FALSE failed in switch case";
4183 ASSERT_EQ(1, 1) <<
"ASSERT_EQ failed in default switch handler";
4191 #if GTEST_HAS_EXCEPTIONS
4193 void ThrowAString() {
4194 throw "std::string";
4199 TEST(AssertionSyntaxTest, WorksWithConst) {
4205 #endif // GTEST_HAS_EXCEPTIONS
4219 TEST(SuccessfulAssertionTest, EXPECT) {
4225 TEST(SuccessfulAssertionTest, EXPECT_STR) {
4237 TEST(SuccessfulAssertionTest, ASSERT_STR) {
4248 TEST(AssertionWithMessageTest, EXPECT) {
4249 EXPECT_EQ(1, 1) <<
"This should succeed.";
4251 "Expected failure #1");
4252 EXPECT_LE(1, 2) <<
"This should succeed.";
4254 "Expected failure #2.");
4255 EXPECT_GE(1, 0) <<
"This should succeed.";
4257 "Expected failure #3.");
4261 "Expected failure #4.");
4264 "Expected failure #5.");
4268 "Expected failure #6.");
4269 EXPECT_NEAR(1, 1.1, 0.2) <<
"This should succeed.";
4273 ASSERT_EQ(1, 1) <<
"This should succeed.";
4274 ASSERT_NE(1, 2) <<
"This should succeed.";
4275 ASSERT_LE(1, 2) <<
"This should succeed.";
4276 ASSERT_LT(1, 2) <<
"This should succeed.";
4277 ASSERT_GE(1, 0) <<
"This should succeed.";
4279 "Expected failure.");
4282 TEST(AssertionWithMessageTest, ASSERT_STR) {
4287 "Expected failure.");
4290 TEST(AssertionWithMessageTest, ASSERT_FLOATING) {
4303 ASSERT_FALSE(
true) <<
"Expected failure: " << 2 <<
" > " << 1
4304 <<
" evaluates to " <<
true;
4305 },
"Expected failure");
4309 TEST(AssertionWithMessageTest,
FAIL) {
4316 SUCCEED() <<
"Success == " << 1;
4325 ASSERT_TRUE(
false) <<
static_cast<const char*
>(
nullptr)
4326 <<
static_cast<char*
>(
nullptr);
4331 #if GTEST_OS_WINDOWS
4333 TEST(AssertionWithMessageTest, WideStringMessage) {
4335 EXPECT_TRUE(
false) <<
L"This failure is expected.\x8119";
4336 },
"This failure is expected.");
4339 <<
L"expected too.\x8120";
4340 },
"This failure is expected too.");
4342 #endif // GTEST_OS_WINDOWS
4348 "Intentional failure #1.");
4350 "Intentional failure #2.");
4361 TEST(ExpectTest, ExpectTrueWithAssertionResult) {
4364 "Value of: ResultIsEven(3)\n"
4365 " Actual: false (3 is odd)\n"
4369 "Value of: ResultIsEvenNoExplanation(3)\n"
4370 " Actual: false (3 is odd)\n"
4379 "Intentional failure #1.");
4381 "Intentional failure #2.");
4391 TEST(ExpectTest, ExpectFalseWithAssertionResult) {
4394 "Value of: ResultIsEven(2)\n"
4395 " Actual: true (2 is even)\n"
4399 "Value of: ResultIsEvenNoExplanation(2)\n"
4413 "Expected equality of these values:\n"
4424 TEST(ExpectTest, EXPECT_EQ_Double) {
4434 TEST(ExpectTest, EXPECT_EQ_NULL) {
4436 const char*
p =
nullptr;
4452 TEST(ExpectTest, EXPECT_EQ_0) {
4468 "Expected: ('a') != ('a'), "
4469 "actual: 'a' (97, 0x61) vs 'a' (97, 0x61)");
4472 char*
const p0 =
nullptr;
4479 void* pv1 = (
void*)0x1234;
4480 char*
const p1 =
reinterpret_cast<char*
>(pv1);
4490 "Expected: (2) <= (0), actual: 2 vs 0");
4499 "Expected: (2) < (2), actual: 2 vs 2");
4509 "Expected: (2) >= (3), actual: 2 vs 3");
4518 "Expected: (2) > (2), actual: 2 vs 2");
4523 #if GTEST_HAS_EXCEPTIONS
4529 "Expected: ThrowAnInteger() throws an exception of "
4530 "type bool.\n Actual: it throws a different type.");
4533 "Expected: ThrowNothing() throws an exception of type bool.\n"
4534 " Actual: it throws nothing.");
4541 "Expected: ThrowAnInteger() doesn't throw an "
4542 "exception.\n Actual: it throws.");
4550 "Expected: ThrowNothing() throws an exception.\n"
4551 " Actual: it doesn't.");
4554 #endif // GTEST_HAS_EXCEPTIONS
4557 TEST(ExpectTest, ExpectPrecedence) {
4560 " true && false\n Which is: false");
4567 TEST(StreamableToStringTest, Scalar) {
4579 TEST(StreamableToStringTest, NullPointer) {
4585 TEST(StreamableToStringTest, CString) {
4590 TEST(StreamableToStringTest, NullCString) {
4598 TEST(StreamableTest,
string) {
4600 "This failure message is a std::string, and is expected.");
4607 TEST(StreamableTest, stringWithEmbeddedNUL) {
4608 static const char char_array_with_nul[] =
4609 "Here's a NUL\0 and some more string";
4610 static const std::string string_with_nul(char_array_with_nul,
4611 sizeof(char_array_with_nul)
4614 "Here's a NUL\\0 and some more string");
4618 TEST(StreamableTest, NULChar) {
4620 FAIL() <<
"A NUL" <<
'\0' <<
" and some more string";
4621 },
"A NUL\\0 and some more string");
4625 TEST(StreamableTest,
int) {
4635 TEST(StreamableTest, NullCharPtr) {
4641 TEST(StreamableTest, BasicIoManip) {
4643 FAIL() <<
"Line 1." << std::endl
4644 <<
"A NUL char " << std::ends << std::flush <<
" in line 2.";
4645 },
"Line 1.\nA NUL char \\0 in line 2.");
4650 void AddFailureHelper(
bool* aborted) {
4658 bool aborted =
true;
4660 "Intentional failure.");
4684 "Intentional failure.");
4690 SUCCEED() <<
"Explicit success.";
4704 bool false_value =
false;
4706 },
" false_value\n Which is: false\n true");
4717 TEST(EqAssertionTest, Time_T) {
4719 static_cast<time_t
>(0));
4721 static_cast<time_t
>(1234)),
4728 const char ch =
'b';
4730 " ch\n Which is: 'b'");
4732 " ch\n Which is: 'b'");
4736 TEST(EqAssertionTest, WideChar) {
4740 "Expected equality of these values:\n"
4742 " Which is: L'\0' (0, 0x0)\n"
4744 " Which is: L'x' (120, 0x78)");
4746 static wchar_t wchar;
4752 " wchar\n Which is: L'");
4756 TEST(EqAssertionTest, StdString) {
4772 char*
const p1 =
const_cast<char*
>(
"foo");
4781 " str3\n Which is: \"A \\0 in the middle\"");
4784 #if GTEST_HAS_STD_WSTRING
4787 TEST(EqAssertionTest, StdWideString) {
4795 const wchar_t kTestX8119[] = {
'T',
'e',
's',
't', 0x8119,
'\0' };
4800 const wchar_t kTestX8120[] = {
'T',
'e',
's',
't', 0x8120,
'\0' };
4808 wstr3.at(2) =
L'\0';
4819 #endif // GTEST_HAS_STD_WSTRING
4821 #if GTEST_HAS_GLOBAL_STRING
4823 TEST(EqAssertionTest, GlobalString) {
4845 ASSERT_EQ(::
string(
"bar"),
const_cast<char*
>(
"foo"));
4849 #endif // GTEST_HAS_GLOBAL_STRING
4851 #if GTEST_HAS_GLOBAL_WSTRING
4854 TEST(EqAssertionTest, GlobalWideString) {
4861 const wchar_t kTestX8119[] = {
'T',
'e',
's',
't', 0x8119,
'\0' };
4866 const wchar_t kTestX8120[] = {
'T',
'e',
's',
't', 0x8120,
'\0' };
4872 wchar_t*
const p1 =
const_cast<wchar_t*
>(
L"foo");
4880 wstr3.at(2) =
L'\0';
4885 #endif // GTEST_HAS_GLOBAL_WSTRING
4888 TEST(EqAssertionTest, CharPointer) {
4889 char*
const p0 =
nullptr;
4894 void* pv1 = (
void*)0x1234;
4895 void* pv2 = (
void*)0xABC0;
4896 char*
const p1 =
reinterpret_cast<char*
>(pv1);
4897 char*
const p2 =
reinterpret_cast<char*
>(pv2);
4905 reinterpret_cast<char*
>(0xABC0)),
4910 TEST(EqAssertionTest, WideCharPointer) {
4911 wchar_t*
const p0 =
nullptr;
4916 void* pv1 = (
void*)0x1234;
4917 void* pv2 = (
void*)0xABC0;
4918 wchar_t*
const p1 =
reinterpret_cast<wchar_t*
>(pv1);
4919 wchar_t*
const p2 =
reinterpret_cast<wchar_t*
>(pv2);
4926 void* pv3 = (
void*)0x1234;
4927 void* pv4 = (
void*)0xABC0;
4928 const wchar_t* p3 =
reinterpret_cast<const wchar_t*
>(pv3);
4929 const wchar_t* p4 =
reinterpret_cast<const wchar_t*
>(pv4);
4935 TEST(EqAssertionTest, OtherPointer) {
4936 ASSERT_EQ(
static_cast<const int*
>(
nullptr),
static_cast<const int*
>(
nullptr));
4938 reinterpret_cast<const int*
>(0x1234)),
4943 class UnprintableChar {
4945 explicit UnprintableChar(
char ch) : char_(
ch) {}
4947 bool operator==(
const UnprintableChar& rhs)
const {
4948 return char_ == rhs.char_;
4950 bool operator!=(
const UnprintableChar& rhs)
const {
4951 return char_ != rhs.char_;
4953 bool operator<(
const UnprintableChar& rhs)
const {
4954 return char_ < rhs.char_;
4956 bool operator<=(
const UnprintableChar& rhs)
const {
4957 return char_ <= rhs.char_;
4959 bool operator>(
const UnprintableChar& rhs)
const {
4960 return char_ > rhs.char_;
4962 bool operator>=(
const UnprintableChar& rhs)
const {
4963 return char_ >= rhs.char_;
4972 TEST(ComparisonAssertionTest, AcceptsUnprintableArgs) {
4973 const UnprintableChar
x(
'x'),
y(
'y');
4989 #ifndef __BORLANDC__
4992 "1-byte object <78>");
4994 "1-byte object <78>");
4997 "1-byte object <79>");
4999 "1-byte object <78>");
5001 "1-byte object <79>");
5013 int Bar()
const {
return 1; }
5028 class FRIEND_TEST_Test2 :
public Test {
5045 class TestLifeCycleTest :
public Test {
5049 TestLifeCycleTest() {
count_++; }
5053 ~TestLifeCycleTest()
override {
count_--; }
5065 TEST_F(TestLifeCycleTest, Test1) {
5072 TEST_F(TestLifeCycleTest, Test2) {
5083 TEST(AssertionResultTest, CopyConstructorWorksWhenNotOptimied) {
5093 EXPECT_EQ(
static_cast<bool>(r3),
static_cast<bool>(r1));
5099 TEST(AssertionResultTest, ConstructionWorks) {
5122 TEST(AssertionResultTest, NegationWorks) {
5132 TEST(AssertionResultTest, StreamingWorks) {
5134 r <<
"abc" <<
'd' << 0 <<
true;
5138 TEST(AssertionResultTest, CanStreamOstreamManipulators) {
5140 r <<
"Data" << std::endl << std::flush << std::ends <<
"Will be visible";
5146 TEST(AssertionResultTest, ConstructibleFromContextuallyConvertibleToBool) {
5147 struct ExplicitlyConvertibleToBool {
5148 explicit operator bool()
const {
return value; }
5151 ExplicitlyConvertibleToBool v1 = {
false};
5152 ExplicitlyConvertibleToBool v2 = {
true};
5161 TEST(AssertionResultTest, ConstructibleFromImplicitlyConvertible) {
5177 return os << val.x();
5180 const Base* pointer) {
5181 return os <<
"(" << pointer->x() <<
")";
5184 TEST(MessageTest, CanStreamUserTypeInGlobalNameSpace) {
5195 class MyTypeInUnnamedNameSpace :
public Base {
5197 explicit MyTypeInUnnamedNameSpace(
int an_x): Base(an_x) {}
5200 const MyTypeInUnnamedNameSpace& val) {
5201 return os << val.x();
5204 const MyTypeInUnnamedNameSpace* pointer) {
5205 return os <<
"(" << pointer->x() <<
")";
5209 TEST(MessageTest, CanStreamUserTypeInUnnamedNameSpace) {
5211 MyTypeInUnnamedNameSpace
a(1);
5220 class MyTypeInNameSpace1 :
public Base {
5225 const MyTypeInNameSpace1& val) {
5226 return os << val.x();
5229 const MyTypeInNameSpace1* pointer) {
5230 return os <<
"(" << pointer->x() <<
")";
5234 TEST(MessageTest, CanStreamUserTypeInUserNameSpace) {
5245 class MyTypeInNameSpace2 :
public ::Base {
5252 return os << val.x();
5256 return os <<
"(" << pointer->x() <<
")";
5259 TEST(MessageTest, CanStreamUserTypeInUserNameSpaceWithStreamOperatorInGlobal) {
5270 char*
const p1 =
nullptr;
5271 unsigned char*
const p2 =
nullptr;
5273 double* p4 =
nullptr;
5277 msg << p1 << p2 << p3 << p4 << p5 << p6;
5279 msg.GetString().c_str());
5285 const wchar_t* const_wstr =
nullptr;
5290 wchar_t* wstr =
nullptr;
5295 const_wstr =
L"abc\x8119";
5300 wstr =
const_cast<wchar_t*
>(const_wstr);
5311 class TestInfoTest :
public Test {
5319 if (strcmp(test_name, test_info->
name()) == 0)
5327 return test_info->
result();
5332 TEST_F(TestInfoTest, Names) {
5333 const TestInfo*
const test_info = GetTestInfo(
"Names");
5341 const TestInfo*
const test_info = GetTestInfo(
"result");
5344 ASSERT_EQ(0, GetTestResult(test_info)->total_part_count());
5347 ASSERT_EQ(0, GetTestResult(test_info)->total_part_count());
5350 #define VERIFY_CODE_LOCATION \
5351 const int expected_line = __LINE__ - 1; \
5352 const TestInfo* const test_info = GetUnitTestImpl()->current_test_info(); \
5353 ASSERT_TRUE(test_info); \
5354 EXPECT_STREQ(__FILE__, test_info->file()); \
5355 EXPECT_EQ(expected_line, test_info->line())
5361 class CodeLocationForTESTF :
public Test {
5368 class CodeLocationForTESTP :
public TestWithParam<int> {
5377 template <
typename T>
5378 class CodeLocationForTYPEDTEST :
public Test {
5387 template <
typename T>
5388 class CodeLocationForTYPEDTESTP :
public Test {
5401 #undef VERIFY_CODE_LOCATION
5405 #ifndef REMOVE_LEGACY_TEST_CASEAPI
5406 class SetUpTestCaseTest :
public Test {
5411 printf(
"Setting up the test case . . .\n");
5428 printf(
"Tearing down the test case . . .\n");
5461 TEST_F(SetUpTestCaseTest, Test2) {
5464 #endif // REMOVE_LEGACY_TEST_CASEAPI
5467 class SetUpTestSuiteTest :
public Test {
5472 printf(
"Setting up the test suite . . .\n");
5489 printf(
"Tearing down the test suite . . .\n");
5519 TEST_F(SetUpTestSuiteTest, TestSetupTestSuite1) {
5524 TEST_F(SetUpTestSuiteTest, TestSetupTestSuite2) {
5680 class ParseFlagsTest :
public Test {
5701 template <
typename CharType>
5703 size_t size2, CharType** array2) {
5704 ASSERT_EQ(size1, size2) <<
" Array sizes different.";
5706 for (
size_t i = 0;
i != size1;
i++) {
5713 EXPECT_EQ(expected.also_run_disabled_tests,
5734 template <
typename CharType>
5736 int argc2,
const CharType** argv2,
5737 const Flags& expected,
bool should_print_help) {
5741 # if GTEST_HAS_STREAM_REDIRECTION
5748 # if GTEST_HAS_STREAM_REDIRECTION
5763 # if GTEST_HAS_STREAM_REDIRECTION
5764 const char*
const expected_help_fragment =
5765 "This program contains tests written using";
5766 if (should_print_help) {
5770 expected_help_fragment, captured_stdout);
5772 # endif // GTEST_HAS_STREAM_REDIRECTION
5780 # define GTEST_TEST_PARSING_FLAGS_(argv1, argv2, expected, should_print_help) \
5781 TestParsingFlags(sizeof(argv1)/sizeof(*argv1) - 1, argv1, \
5782 sizeof(argv2)/sizeof(*argv2) - 1, argv2, \
5783 expected, should_print_help)
5788 const char* argv[] = {
nullptr};
5790 const char* argv2[] = {
nullptr};
5796 TEST_F(ParseFlagsTest, NoFlag) {
5797 const char* argv[] = {
"foo.exe",
nullptr};
5799 const char* argv2[] = {
"foo.exe",
nullptr};
5805 TEST_F(ParseFlagsTest, FilterBad) {
5806 const char* argv[] = {
"foo.exe",
"--gtest_filter",
nullptr};
5808 const char* argv2[] = {
"foo.exe",
"--gtest_filter",
nullptr};
5814 TEST_F(ParseFlagsTest, FilterEmpty) {
5815 const char* argv[] = {
"foo.exe",
"--gtest_filter=",
nullptr};
5817 const char* argv2[] = {
"foo.exe",
nullptr};
5823 TEST_F(ParseFlagsTest, FilterNonEmpty) {
5824 const char* argv[] = {
"foo.exe",
"--gtest_filter=abc",
nullptr};
5826 const char* argv2[] = {
"foo.exe",
nullptr};
5832 TEST_F(ParseFlagsTest, BreakOnFailureWithoutValue) {
5833 const char* argv[] = {
"foo.exe",
"--gtest_break_on_failure",
nullptr};
5835 const char* argv2[] = {
"foo.exe",
nullptr};
5841 TEST_F(ParseFlagsTest, BreakOnFailureFalse_0) {
5842 const char* argv[] = {
"foo.exe",
"--gtest_break_on_failure=0",
nullptr};
5844 const char* argv2[] = {
"foo.exe",
nullptr};
5850 TEST_F(ParseFlagsTest, BreakOnFailureFalse_f) {
5851 const char* argv[] = {
"foo.exe",
"--gtest_break_on_failure=f",
nullptr};
5853 const char* argv2[] = {
"foo.exe",
nullptr};
5859 TEST_F(ParseFlagsTest, BreakOnFailureFalse_F) {
5860 const char* argv[] = {
"foo.exe",
"--gtest_break_on_failure=F",
nullptr};
5862 const char* argv2[] = {
"foo.exe",
nullptr};
5869 TEST_F(ParseFlagsTest, BreakOnFailureTrue) {
5870 const char* argv[] = {
"foo.exe",
"--gtest_break_on_failure=1",
nullptr};
5872 const char* argv2[] = {
"foo.exe",
nullptr};
5878 TEST_F(ParseFlagsTest, CatchExceptions) {
5879 const char* argv[] = {
"foo.exe",
"--gtest_catch_exceptions",
nullptr};
5881 const char* argv2[] = {
"foo.exe",
nullptr};
5887 TEST_F(ParseFlagsTest, DeathTestUseFork) {
5888 const char* argv[] = {
"foo.exe",
"--gtest_death_test_use_fork",
nullptr};
5890 const char* argv2[] = {
"foo.exe",
nullptr};
5897 TEST_F(ParseFlagsTest, DuplicatedFlags) {
5898 const char* argv[] = {
"foo.exe",
"--gtest_filter=a",
"--gtest_filter=b",
5901 const char* argv2[] = {
"foo.exe",
nullptr};
5907 TEST_F(ParseFlagsTest, UnrecognizedFlag) {
5908 const char* argv[] = {
"foo.exe",
"--gtest_break_on_failure",
5910 "--gtest_filter=b",
nullptr};
5912 const char* argv2[] = {
"foo.exe",
"bar",
nullptr};
5915 flags.break_on_failure =
true;
5921 TEST_F(ParseFlagsTest, ListTestsFlag) {
5922 const char* argv[] = {
"foo.exe",
"--gtest_list_tests",
nullptr};
5924 const char* argv2[] = {
"foo.exe",
nullptr};
5930 TEST_F(ParseFlagsTest, ListTestsTrue) {
5931 const char* argv[] = {
"foo.exe",
"--gtest_list_tests=1",
nullptr};
5933 const char* argv2[] = {
"foo.exe",
nullptr};
5939 TEST_F(ParseFlagsTest, ListTestsFalse) {
5940 const char* argv[] = {
"foo.exe",
"--gtest_list_tests=0",
nullptr};
5942 const char* argv2[] = {
"foo.exe",
nullptr};
5948 TEST_F(ParseFlagsTest, ListTestsFalse_f) {
5949 const char* argv[] = {
"foo.exe",
"--gtest_list_tests=f",
nullptr};
5951 const char* argv2[] = {
"foo.exe",
nullptr};
5957 TEST_F(ParseFlagsTest, ListTestsFalse_F) {
5958 const char* argv[] = {
"foo.exe",
"--gtest_list_tests=F",
nullptr};
5960 const char* argv2[] = {
"foo.exe",
nullptr};
5966 TEST_F(ParseFlagsTest, OutputEmpty) {
5967 const char* argv[] = {
"foo.exe",
"--gtest_output",
nullptr};
5969 const char* argv2[] = {
"foo.exe",
"--gtest_output",
nullptr};
5975 TEST_F(ParseFlagsTest, OutputXml) {
5976 const char* argv[] = {
"foo.exe",
"--gtest_output=xml",
nullptr};
5978 const char* argv2[] = {
"foo.exe",
nullptr};
5984 TEST_F(ParseFlagsTest, OutputXmlFile) {
5985 const char* argv[] = {
"foo.exe",
"--gtest_output=xml:file",
nullptr};
5987 const char* argv2[] = {
"foo.exe",
nullptr};
5993 TEST_F(ParseFlagsTest, OutputXmlDirectory) {
5994 const char* argv[] = {
"foo.exe",
"--gtest_output=xml:directory/path/",
5997 const char* argv2[] = {
"foo.exe",
nullptr};
6004 TEST_F(ParseFlagsTest, PrintTimeFlag) {
6005 const char* argv[] = {
"foo.exe",
"--gtest_print_time",
nullptr};
6007 const char* argv2[] = {
"foo.exe",
nullptr};
6013 TEST_F(ParseFlagsTest, PrintTimeTrue) {
6014 const char* argv[] = {
"foo.exe",
"--gtest_print_time=1",
nullptr};
6016 const char* argv2[] = {
"foo.exe",
nullptr};
6022 TEST_F(ParseFlagsTest, PrintTimeFalse) {
6023 const char* argv[] = {
"foo.exe",
"--gtest_print_time=0",
nullptr};
6025 const char* argv2[] = {
"foo.exe",
nullptr};
6031 TEST_F(ParseFlagsTest, PrintTimeFalse_f) {
6032 const char* argv[] = {
"foo.exe",
"--gtest_print_time=f",
nullptr};
6034 const char* argv2[] = {
"foo.exe",
nullptr};
6040 TEST_F(ParseFlagsTest, PrintTimeFalse_F) {
6041 const char* argv[] = {
"foo.exe",
"--gtest_print_time=F",
nullptr};
6043 const char* argv2[] = {
"foo.exe",
nullptr};
6050 const char* argv[] = {
"foo.exe",
"--gtest_random_seed=1000",
nullptr};
6052 const char* argv2[] = {
"foo.exe",
nullptr};
6058 TEST_F(ParseFlagsTest, Repeat) {
6059 const char* argv[] = {
"foo.exe",
"--gtest_repeat=1000",
nullptr};
6061 const char* argv2[] = {
"foo.exe",
nullptr};
6068 const char* argv[] = {
"foo.exe",
"--gtest_also_run_disabled_tests",
nullptr};
6070 const char* argv2[] = {
"foo.exe",
nullptr};
6077 TEST_F(ParseFlagsTest, AlsoRunDisabledTestsTrue) {
6078 const char* argv[] = {
"foo.exe",
"--gtest_also_run_disabled_tests=1",
6081 const char* argv2[] = {
"foo.exe",
nullptr};
6088 TEST_F(ParseFlagsTest, AlsoRunDisabledTestsFalse) {
6089 const char* argv[] = {
"foo.exe",
"--gtest_also_run_disabled_tests=0",
6092 const char* argv2[] = {
"foo.exe",
nullptr};
6099 TEST_F(ParseFlagsTest, ShuffleWithoutValue) {
6100 const char* argv[] = {
"foo.exe",
"--gtest_shuffle",
nullptr};
6102 const char* argv2[] = {
"foo.exe",
nullptr};
6108 TEST_F(ParseFlagsTest, ShuffleFalse_0) {
6109 const char* argv[] = {
"foo.exe",
"--gtest_shuffle=0",
nullptr};
6111 const char* argv2[] = {
"foo.exe",
nullptr};
6117 TEST_F(ParseFlagsTest, ShuffleTrue) {
6118 const char* argv[] = {
"foo.exe",
"--gtest_shuffle=1",
nullptr};
6120 const char* argv2[] = {
"foo.exe",
nullptr};
6126 TEST_F(ParseFlagsTest, StackTraceDepth) {
6127 const char* argv[] = {
"foo.exe",
"--gtest_stack_trace_depth=5",
nullptr};
6129 const char* argv2[] = {
"foo.exe",
nullptr};
6134 TEST_F(ParseFlagsTest, StreamResultTo) {
6135 const char* argv[] = {
"foo.exe",
"--gtest_stream_result_to=localhost:1234",
6138 const char* argv2[] = {
"foo.exe",
nullptr};
6145 TEST_F(ParseFlagsTest, ThrowOnFailureWithoutValue) {
6146 const char* argv[] = {
"foo.exe",
"--gtest_throw_on_failure",
nullptr};
6148 const char* argv2[] = {
"foo.exe",
nullptr};
6154 TEST_F(ParseFlagsTest, ThrowOnFailureFalse_0) {
6155 const char* argv[] = {
"foo.exe",
"--gtest_throw_on_failure=0",
nullptr};
6157 const char* argv2[] = {
"foo.exe",
nullptr};
6164 TEST_F(ParseFlagsTest, ThrowOnFailureTrue) {
6165 const char* argv[] = {
"foo.exe",
"--gtest_throw_on_failure=1",
nullptr};
6167 const char* argv2[] = {
"foo.exe",
nullptr};
6172 # if GTEST_OS_WINDOWS
6174 TEST_F(ParseFlagsTest, WideStrings) {
6175 const wchar_t* argv[] = {
6177 L"--gtest_filter=Foo*",
6178 L"--gtest_list_tests=1",
6179 L"--gtest_break_on_failure",
6180 L"--non_gtest_flag",
6184 const wchar_t* argv2[] = {
6186 L"--non_gtest_flag",
6190 Flags expected_flags;
6191 expected_flags.break_on_failure =
true;
6192 expected_flags.filter =
"Foo*";
6193 expected_flags.list_tests =
true;
6197 # endif // GTEST_OS_WINDOWS
6199 #if GTEST_USE_OWN_FLAGFILE_FLAG_
6200 class FlagfileTest :
public ParseFlagsTest {
6202 virtual void SetUp() {
6212 virtual void TearDown() {
6236 const char* argv[] = {
"foo.exe", flagfile_flag.c_str(),
nullptr};
6238 const char* argv2[] = {
"foo.exe",
nullptr};
6244 TEST_F(FlagfileTest, FilterNonEmpty) {
6250 const char* argv[] = {
"foo.exe", flagfile_flag.c_str(),
nullptr};
6252 const char* argv2[] = {
"foo.exe",
nullptr};
6258 TEST_F(FlagfileTest, SeveralFlags) {
6266 const char* argv[] = {
"foo.exe", flagfile_flag.c_str(),
nullptr};
6268 const char* argv2[] = {
"foo.exe",
nullptr};
6270 Flags expected_flags;
6271 expected_flags.break_on_failure =
true;
6272 expected_flags.filter =
"abc";
6273 expected_flags.list_tests =
true;
6277 #endif // GTEST_USE_OWN_FLAGFILE_FLAG_
6280 class CurrentTestInfoTest :
public Test {
6289 <<
"There should be no tests running at this point.";
6298 <<
"There should be no tests running at this point.";
6304 TEST_F(CurrentTestInfoTest, WorksForFirstTestInATestSuite) {
6308 <<
"There is a test running so we should have a valid TestInfo.";
6310 <<
"Expected the name of the currently running test case.";
6312 <<
"Expected the name of the currently running test.";
6319 TEST_F(CurrentTestInfoTest, WorksForSecondTestInATestSuite) {
6323 <<
"There is a test running so we should have a valid TestInfo.";
6325 <<
"Expected the name of the currently running test case.";
6327 <<
"Expected the name of the currently running test.";
6352 TEST(NestedTestingNamespaceTest, Success) {
6353 EXPECT_EQ(1, 1) <<
"This shouldn't fail.";
6357 TEST(NestedTestingNamespaceTest, Failure) {
6359 "This failure is expected.");
6371 void SetUp()
override { Test::SetUp(); }
6377 TEST(StreamingAssertionsTest, Unconditional) {
6378 SUCCEED() <<
"expected success";
6380 "expected failure");
6382 "expected failure");
6387 # pragma option push -w-ccc -w-rch
6390 TEST(StreamingAssertionsTest, Truth) {
6394 "expected failure");
6396 "expected failure");
6399 TEST(StreamingAssertionsTest, Truth2) {
6403 "expected failure");
6405 "expected failure");
6413 TEST(StreamingAssertionsTest, IntegerEquals) {
6414 EXPECT_EQ(1, 1) <<
"unexpected failure";
6415 ASSERT_EQ(1, 1) <<
"unexpected failure";
6417 "expected failure");
6419 "expected failure");
6422 TEST(StreamingAssertionsTest, IntegerLessThan) {
6423 EXPECT_LT(1, 2) <<
"unexpected failure";
6424 ASSERT_LT(1, 2) <<
"unexpected failure";
6426 "expected failure");
6428 "expected failure");
6431 TEST(StreamingAssertionsTest, StringsEqual) {
6435 "expected failure");
6437 "expected failure");
6440 TEST(StreamingAssertionsTest, StringsNotEqual) {
6444 "expected failure");
6446 "expected failure");
6449 TEST(StreamingAssertionsTest, StringsEqualIgnoringCase) {
6453 "expected failure");
6455 "expected failure");
6458 TEST(StreamingAssertionsTest, StringNotEqualIgnoringCase) {
6462 "expected failure");
6464 "expected failure");
6467 TEST(StreamingAssertionsTest, FloatingPointEquals) {
6471 "expected failure");
6473 "expected failure");
6476 #if GTEST_HAS_EXCEPTIONS
6479 EXPECT_THROW(ThrowAnInteger(),
int) <<
"unexpected failure";
6480 ASSERT_THROW(ThrowAnInteger(),
int) <<
"unexpected failure";
6482 "expected failure",
"expected failure");
6484 "expected failure",
"expected failure");
6487 TEST(StreamingAssertionsTest, NoThrow) {
6491 "expected failure",
"expected failure");
6493 "expected failure",
"expected failure");
6496 TEST(StreamingAssertionsTest, AnyThrow) {
6500 "expected failure",
"expected failure");
6502 "expected failure",
"expected failure");
6505 #endif // GTEST_HAS_EXCEPTIONS
6509 TEST(ColoredOutputTest, UsesColorsWhenGTestColorFlagIsYes) {
6512 SetEnv(
"TERM",
"xterm");
6516 SetEnv(
"TERM",
"dumb");
6521 TEST(ColoredOutputTest, UsesColorsWhenGTestColorFlagIsAliasOfYes) {
6522 SetEnv(
"TERM",
"dumb");
6534 TEST(ColoredOutputTest, UsesNoColorWhenGTestColorFlagIsNo) {
6537 SetEnv(
"TERM",
"xterm");
6541 SetEnv(
"TERM",
"dumb");
6546 TEST(ColoredOutputTest, UsesNoColorWhenGTestColorFlagIsInvalid) {
6547 SetEnv(
"TERM",
"xterm");
6559 TEST(ColoredOutputTest, UsesColorsWhenStdoutIsTty) {
6562 SetEnv(
"TERM",
"xterm");
6567 TEST(ColoredOutputTest, UsesColorsWhenTermSupportsColors) {
6570 #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW
6573 SetEnv(
"TERM",
"dumb");
6579 SetEnv(
"TERM",
"xterm");
6585 SetEnv(
"TERM",
"dumb");
6588 SetEnv(
"TERM",
"emacs");
6591 SetEnv(
"TERM",
"vt100");
6594 SetEnv(
"TERM",
"xterm-mono");
6597 SetEnv(
"TERM",
"xterm");
6600 SetEnv(
"TERM",
"xterm-color");
6603 SetEnv(
"TERM",
"xterm-256color");
6606 SetEnv(
"TERM",
"screen");
6609 SetEnv(
"TERM",
"screen-256color");
6612 SetEnv(
"TERM",
"tmux");
6615 SetEnv(
"TERM",
"tmux-256color");
6618 SetEnv(
"TERM",
"rxvt-unicode");
6621 SetEnv(
"TERM",
"rxvt-unicode-256color");
6624 SetEnv(
"TERM",
"linux");
6627 SetEnv(
"TERM",
"cygwin");
6629 #endif // GTEST_OS_WINDOWS
6636 StaticAssertTypeEq<const int, const int>();
6640 template <
typename T>
6646 TEST(StaticAssertTypeEqTest, WorksInClass) {
6654 TEST(StaticAssertTypeEqTest, CompilesForEqualTypes) {
6655 StaticAssertTypeEq<int, IntAlias>();
6656 StaticAssertTypeEq<int*, IntAlias*>();
6659 TEST(HasNonfatalFailureTest, ReturnsFalseWhenThereIsNoFailure) {
6665 TEST(HasNonfatalFailureTest, ReturnsFalseWhenThereIsOnlyFatalFailure) {
6667 const bool has_nonfatal_failure = HasNonfatalFailure();
6668 ClearCurrentTestPartResults();
6672 TEST(HasNonfatalFailureTest, ReturnsTrueWhenThereIsNonfatalFailure) {
6674 const bool has_nonfatal_failure = HasNonfatalFailure();
6675 ClearCurrentTestPartResults();
6679 TEST(HasNonfatalFailureTest, ReturnsTrueWhenThereAreFatalAndNonfatalFailures) {
6682 const bool has_nonfatal_failure = HasNonfatalFailure();
6683 ClearCurrentTestPartResults();
6692 TEST(HasNonfatalFailureTest, WorksOutsideOfTestBody) {
6696 TEST(HasNonfatalFailureTest, WorksOutsideOfTestBody2) {
6699 ClearCurrentTestPartResults();
6703 TEST(HasFailureTest, ReturnsFalseWhenThereIsNoFailure) {
6707 TEST(HasFailureTest, ReturnsTrueWhenThereIsFatalFailure) {
6709 const bool has_failure = HasFailure();
6710 ClearCurrentTestPartResults();
6714 TEST(HasFailureTest, ReturnsTrueWhenThereIsNonfatalFailure) {
6716 const bool has_failure = HasFailure();
6717 ClearCurrentTestPartResults();
6721 TEST(HasFailureTest, ReturnsTrueWhenThereAreFatalAndNonfatalFailures) {
6724 const bool has_failure = HasFailure();
6725 ClearCurrentTestPartResults();
6732 TEST(HasFailureTest, WorksOutsideOfTestBody) {
6736 TEST(HasFailureTest, WorksOutsideOfTestBody2) {
6739 ClearCurrentTestPartResults();
6766 TEST(TestEventListenersTest, ConstructionWorks) {
6769 EXPECT_TRUE(TestEventListenersAccessor::GetRepeater(&listeners) !=
nullptr);
6776 TEST(TestEventListenersTest, DestructionWorks) {
6777 bool default_result_printer_is_destroyed =
false;
6778 bool default_xml_printer_is_destroyed =
false;
6779 bool extra_listener_is_destroyed =
false;
6781 new TestListener(
nullptr, &default_result_printer_is_destroyed);
6783 new TestListener(
nullptr, &default_xml_printer_is_destroyed);
6785 new TestListener(
nullptr, &extra_listener_is_destroyed);
6789 TestEventListenersAccessor::SetDefaultResultPrinter(&listeners,
6790 default_result_printer);
6791 TestEventListenersAccessor::SetDefaultXmlGenerator(&listeners,
6792 default_xml_printer);
6793 listeners.
Append(extra_listener);
6803 int on_start_counter = 0;
6804 bool is_destroyed =
false;
6808 listeners.
Append(listener);
6809 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
6810 *UnitTest::GetInstance());
6850 std::vector<std::string>*
vector_;
6851 const char*
const id_;
6856 TEST(EventListenerTest, AppendKeepsOrder) {
6857 std::vector<std::string> vec;
6863 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
6864 *UnitTest::GetInstance());
6871 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramEnd(
6872 *UnitTest::GetInstance());
6879 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestIterationStart(
6880 *UnitTest::GetInstance(), 0);
6887 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestIterationEnd(
6888 *UnitTest::GetInstance(), 0);
6897 TEST(TestEventListenersTest, Release) {
6898 int on_start_counter = 0;
6899 bool is_destroyed =
false;
6906 listeners.
Append(listener);
6908 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
6909 *UnitTest::GetInstance());
6918 TEST(EventListenerTest, SuppressEventForwarding) {
6919 int on_start_counter = 0;
6923 listeners.
Append(listener);
6924 ASSERT_TRUE(TestEventListenersAccessor::EventForwardingEnabled(listeners));
6925 TestEventListenersAccessor::SuppressEventForwarding(&listeners);
6926 ASSERT_FALSE(TestEventListenersAccessor::EventForwardingEnabled(listeners));
6927 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
6928 *UnitTest::GetInstance());
6934 TEST(EventListenerDeathTest, EventsNotForwardedInDeathTestSubprecesses) {
6936 GTEST_CHECK_(TestEventListenersAccessor::EventForwardingEnabled(
6938 "expected failure");
6944 TEST(EventListenerTest, default_result_printer) {
6945 int on_start_counter = 0;
6946 bool is_destroyed =
false;
6950 TestEventListenersAccessor::SetDefaultResultPrinter(&listeners, listener);
6954 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
6955 *UnitTest::GetInstance());
6961 TestEventListenersAccessor::SetDefaultResultPrinter(&listeners,
nullptr);
6968 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
6969 *UnitTest::GetInstance());
6975 TEST(EventListenerTest, RemovingDefaultResultPrinterWorks) {
6976 int on_start_counter = 0;
6977 bool is_destroyed =
false;
6984 TestEventListenersAccessor::SetDefaultResultPrinter(&listeners, listener);
6991 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
6992 *UnitTest::GetInstance());
7003 TEST(EventListenerTest, default_xml_generator) {
7004 int on_start_counter = 0;
7005 bool is_destroyed =
false;
7009 TestEventListenersAccessor::SetDefaultXmlGenerator(&listeners, listener);
7013 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
7014 *UnitTest::GetInstance());
7020 TestEventListenersAccessor::SetDefaultXmlGenerator(&listeners,
nullptr);
7027 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
7028 *UnitTest::GetInstance());
7034 TEST(EventListenerTest, RemovingDefaultXmlGeneratorWorks) {
7035 int on_start_counter = 0;
7036 bool is_destroyed =
false;
7043 TestEventListenersAccessor::SetDefaultXmlGenerator(&listeners, listener);
7050 TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
7051 *UnitTest::GetInstance());
7069 "An expected failure");
7075 "An expected failure");
7077 "An expected failure");
7082 "An expected failure");
7087 "An expected failure");
7091 "An expected failure");
7093 "An expected failure");
7098 "An expected failure");
7102 "An expected failure");
7104 "An expected failure");
7114 TEST(IsAProtocolMessageTest, ValueIsCompileTimeConstant) {
7122 TEST(IsAProtocolMessageTest, ValueIsTrueWhenTypeIsAProtocolMessage) {
7129 TEST(IsAProtocolMessageTest, ValueIsFalseWhenTypeIsNotAProtocolMessage) {
7142 TEST(RemoveReferenceTest, DoesNotAffectNonReferenceType) {
7148 TEST(RemoveReferenceTest, RemovesReference) {
7155 template <
typename T1,
typename T2>
7160 TEST(RemoveReferenceTest, MacroVersion) {
7161 TestGTestRemoveReference<int, int>();
7162 TestGTestRemoveReference<const char, const char&>();
7167 TEST(RemoveConstTest, DoesNotAffectNonConstType) {
7173 TEST(RemoveConstTest, RemovesConst) {
7181 template <
typename T1,
typename T2>
7186 TEST(RemoveConstTest, MacroVersion) {
7187 TestGTestRemoveConst<int, int>();
7188 TestGTestRemoveConst<double&, double&>();
7189 TestGTestRemoveConst<char, const char>();
7194 template <
typename T1,
typename T2>
7199 TEST(RemoveReferenceToConstTest, Works) {
7200 TestGTestRemoveReferenceAndConst<int, int>();
7201 TestGTestRemoveReferenceAndConst<double, double&>();
7202 TestGTestRemoveReferenceAndConst<char, const char>();
7203 TestGTestRemoveReferenceAndConst<char, const char&>();
7204 TestGTestRemoveReferenceAndConst<const char*, const char*>();
7208 TEST(AddReferenceTest, DoesNotAffectReferenceType) {
7214 TEST(AddReferenceTest, AddsReference) {
7221 template <
typename T1,
typename T2>
7226 TEST(AddReferenceTest, MacroVersion) {
7227 TestGTestAddReference<int&, int>();
7228 TestGTestAddReference<const char&, const char&>();
7233 template <
typename T1,
typename T2>
7238 TEST(GTestReferenceToConstTest, Works) {
7239 TestGTestReferenceToConst<const char&, char>();
7240 TestGTestReferenceToConst<const int&, const int>();
7241 TestGTestReferenceToConst<const double&, double>();
7242 TestGTestReferenceToConst<const std::string&, const std::string&>();
7250 TEST(IsContainerTestTest, WorksForNonContainer) {
7256 TEST(IsContainerTestTest, WorksForContainer) {
7270 struct const_iterator {
7274 const_iterator
begin()
const;
7275 const_iterator
end()
const;
7278 TEST(IsContainerTestTest, ConstOnlyContainer) {
7280 sizeof(IsContainerTest<ConstOnlyContainerWithPointerIterator>(0)));
7282 sizeof(IsContainerTest<ConstOnlyContainerWithClassIterator>(0)));
7302 TEST(ArrayEqTest, WorksForDegeneratedArrays) {
7307 TEST(ArrayEqTest, WorksForOneDimensionalArrays) {
7309 const int a[] = { 0, 1 };
7310 long b[] = { 0, 1 };
7319 TEST(ArrayEqTest, WorksForTwoDimensionalArrays) {
7320 const char a[][3] = {
"hi",
"lo" };
7321 const char b[][3] = {
"hi",
"lo" };
7322 const char c[][3] = {
"hi",
"li" };
7333 TEST(ArrayAwareFindTest, WorksForOneDimensionalArray) {
7334 const char a[] =
"hello";
7339 TEST(ArrayAwareFindTest, WorksForTwoDimensionalArray) {
7340 int a[][2] = { { 0, 1 }, { 2, 3 }, { 4, 5 } };
7341 const int b[2] = { 2, 3 };
7344 const int c[2] = { 6, 7 };
7350 TEST(CopyArrayTest, WorksForDegeneratedArrays) {
7356 TEST(CopyArrayTest, WorksForOneDimensionalArrays) {
7357 const char a[3] =
"hi";
7359 #ifndef __BORLANDC__ // C++Builder cannot compile some array size deductions.
7369 TEST(CopyArrayTest, WorksForTwoDimensionalArrays) {
7370 const int a[2][3] = { { 0, 1, 2 }, { 3, 4, 5 } };
7372 #ifndef __BORLANDC__ // C++Builder cannot compile some array size deductions.
7384 TEST(NativeArrayTest, ConstructorFromArrayWorks) {
7385 const int a[3] = { 0, 1, 2 };
7391 TEST(NativeArrayTest, CreatesAndDeletesCopyOfArrayWhenAskedTo) {
7392 typedef int Array[2];
7406 TEST(NativeArrayTest, TypeMembersAreCorrect) {
7410 StaticAssertTypeEq<const char*, NativeArray<char>::const_iterator>();
7414 TEST(NativeArrayTest, MethodsWork) {
7415 const int a[3] = { 0, 1, 2 };
7434 const int b1[3] = { 0, 1, 1 };
7435 const int b2[4] = { 0, 1, 2, 3 };
7440 TEST(NativeArrayTest, WorksForTwoDimensionalArray) {
7441 const char a[2][3] = {
"hi",
"lo" };
7460 (std::is_base_of<IndexSequence<0, 1, 2>, MakeIndexSequence<3>>::
value));
7470 (std::is_same<
double,
7478 int,
int,
int,
int,
int,
int,
int,
char,
int,
int,
7486 FlatTuple<int, double, const char*> tuple = {};
7491 tuple = FlatTuple<int, double, const char*>(7, 3.2,
"Foo");
7496 tuple.Get<1>() = 5.1;
7506 #define GTEST_FLAT_TUPLE_INT8 int, int, int, int, int, int, int, int,
7507 #define GTEST_FLAT_TUPLE_INT16 GTEST_FLAT_TUPLE_INT8 GTEST_FLAT_TUPLE_INT8
7508 #define GTEST_FLAT_TUPLE_INT32 GTEST_FLAT_TUPLE_INT16 GTEST_FLAT_TUPLE_INT16
7509 #define GTEST_FLAT_TUPLE_INT64 GTEST_FLAT_TUPLE_INT32 GTEST_FLAT_TUPLE_INT32
7510 #define GTEST_FLAT_TUPLE_INT128 GTEST_FLAT_TUPLE_INT64 GTEST_FLAT_TUPLE_INT64
7511 #define GTEST_FLAT_TUPLE_INT256 GTEST_FLAT_TUPLE_INT128 GTEST_FLAT_TUPLE_INT128
7515 FlatTuple<GTEST_FLAT_TUPLE_INT256 int> tuple;
7518 tuple.Get<99>() = 17;
7519 tuple.Get<256>() = 1000;
7527 TEST(SkipPrefixTest, SkipsWhenPrefixMatches) {
7528 const char*
const str =
"hello";
7530 const char*
p =
str;
7539 TEST(SkipPrefixTest, DoesNotSkipWhenPrefixDoesNotMatch) {
7540 const char*
const str =
"world";
7542 const char*
p =
str;
7556 FAIL() <<
"A failure happened inside SetUpTestSuite().";
7580 "DynamicUnitTestFixture",
"DynamicTest",
"TYPE",
"VALUE", __FILE__,
7585 for (
int i = 0;
i <
unittest->total_test_suite_count(); ++
i) {
7588 for (
int j = 0; j <
tests->total_test_count(); ++j) {
7597 FAIL() <<
"Didn't find the test!";