35 #include "gtest/gtest.h" 40 TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) {
68 #include "gtest/gtest-spi.h" 75 #define GTEST_IMPLEMENTATION_ 1 76 #include "src/gtest-internal-inl.h" 77 #undef GTEST_IMPLEMENTATION_ 82 #if GTEST_CAN_STREAM_RESULTS_ 84 class StreamingListenerTest :
public Test {
86 class FakeSocketWriter :
public StreamingListener::AbstractSocketWriter {
94 StreamingListenerTest()
95 : fake_sock_writer_(
new FakeSocketWriter),
96 streamer_(fake_sock_writer_),
97 test_info_obj_(
"FooTest",
"Bar", NULL, NULL,
98 CodeLocation(__FILE__, __LINE__), 0, NULL) {}
101 string*
output() {
return &(fake_sock_writer_->output_); }
103 FakeSocketWriter*
const fake_sock_writer_;
104 StreamingListener streamer_;
109 TEST_F(StreamingListenerTest, OnTestProgramEnd) {
111 streamer_.OnTestProgramEnd(unit_test_);
115 TEST_F(StreamingListenerTest, OnTestIterationEnd) {
117 streamer_.OnTestIterationEnd(unit_test_, 42);
118 EXPECT_EQ(
"event=TestIterationEnd&passed=1&elapsed_time=0ms\n", *
output());
121 TEST_F(StreamingListenerTest, OnTestCaseStart) {
123 streamer_.OnTestCaseStart(
TestCase(
"FooTest",
"Bar", NULL, NULL));
127 TEST_F(StreamingListenerTest, OnTestCaseEnd) {
129 streamer_.OnTestCaseEnd(
TestCase(
"FooTest",
"Bar", NULL, NULL));
133 TEST_F(StreamingListenerTest, OnTestStart) {
135 streamer_.OnTestStart(test_info_obj_);
139 TEST_F(StreamingListenerTest, OnTestEnd) {
141 streamer_.OnTestEnd(test_info_obj_);
145 TEST_F(StreamingListenerTest, OnTestPartResult) {
152 "event=TestPartResult&file=foo.cc&line=42&message=failed%3D%0A%26%25\n",
156 #endif // GTEST_CAN_STREAM_RESULTS_ 190 unit_test_.RecordProperty(key, value);
293 #if GTEST_HAS_STREAM_REDIRECTION 298 #if GTEST_IS_THREADSAFE 299 using testing::internal::ThreadWithParam;
308 for (
size_t i = 0;
i < vector.size();
i++) {
309 os << vector[
i] <<
" ";
318 TEST(GetRandomSeedFromFlagTest, HandlesZero) {
324 TEST(GetRandomSeedFromFlagTest, PreservesValidSeed) {
332 TEST(GetRandomSeedFromFlagTest, NormalizesInvalidSeed) {
342 TEST(GetNextRandomSeedTest, WorksForValidInput) {
355 static void ClearCurrentTestPartResults() {
362 TEST(GetTypeIdTest, ReturnsSameValueForSameType) {
363 EXPECT_EQ(GetTypeId<int>(), GetTypeId<int>());
364 EXPECT_EQ(GetTypeId<Test>(), GetTypeId<Test>());
367 class SubClassOfTest :
public Test {};
368 class AnotherSubClassOfTest :
public Test {};
370 TEST(GetTypeIdTest, ReturnsDifferentValuesForDifferentTypes) {
371 EXPECT_NE(GetTypeId<int>(), GetTypeId<const int>());
372 EXPECT_NE(GetTypeId<int>(), GetTypeId<char>());
376 EXPECT_NE(GetTypeId<AnotherSubClassOfTest>(), GetTypeId<SubClassOfTest>());
381 TEST(GetTestTypeIdTest, ReturnsTheSameValueInsideOrOutsideOfGoogleTest) {
387 TEST(FormatTimeInMillisAsSecondsTest, FormatsZero) {
391 TEST(FormatTimeInMillisAsSecondsTest, FormatsPositiveNumber) {
399 TEST(FormatTimeInMillisAsSecondsTest, FormatsNegativeNumber) {
413 class FormatEpochTimeInMillisAsIso8601Test :
public Test {
421 virtual void SetUp() {
426 saved_tz_ = strdup(getenv(
"TZ"));
432 SetTimeZone(
"UTC+00");
435 virtual void TearDown() {
436 SetTimeZone(saved_tz_);
437 free(const_cast<char*>(saved_tz_));
441 static void SetTimeZone(
const char* time_zone) {
450 _putenv(env_var.c_str());
456 setenv((
"TZ"), time_zone, 1);
464 const char* saved_tz_;
467 const TimeInMillis FormatEpochTimeInMillisAsIso8601Test::kMillisPerSec;
469 TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsTwoDigitSegments) {
474 TEST_F(FormatEpochTimeInMillisAsIso8601Test, MillisecondsDoNotAffectResult) {
476 "2011-10-31T18:52:42",
480 TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsLeadingZeroes) {
485 TEST_F(FormatEpochTimeInMillisAsIso8601Test, Prints24HourTime) {
490 TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsEpochStart) {
494 #if GTEST_CAN_COMPARE_NULL 498 # pragma option push -w-ccc -w-rch 503 TEST(NullLiteralTest, IsTrueForNullLiterals) {
512 TEST(NullLiteralTest, IsFalseForNonNullLiterals) {
524 #endif // GTEST_CAN_COMPARE_NULL 529 TEST(CodePointToUtf8Test, CanEncodeNul) {
534 TEST(CodePointToUtf8Test, CanEncodeAscii) {
543 TEST(CodePointToUtf8Test, CanEncode8To11Bits) {
557 TEST(CodePointToUtf8Test, CanEncode12To16Bits) {
567 #if !GTEST_WIDE_STRING_USES_UTF16_ 574 TEST(CodePointToUtf8Test, CanEncode17To21Bits) {
586 TEST(CodePointToUtf8Test, CanEncodeInvalidCodePoint) {
590 #endif // !GTEST_WIDE_STRING_USES_UTF16_ 595 TEST(WideStringToUtf8Test, CanEncodeNul) {
601 TEST(WideStringToUtf8Test, CanEncodeAscii) {
610 TEST(WideStringToUtf8Test, CanEncode8To11Bits) {
616 const wchar_t s[] = { 0x576,
'\0' };
623 TEST(WideStringToUtf8Test, CanEncode12To16Bits) {
625 const wchar_t s1[] = { 0x8D3,
'\0' };
630 const wchar_t s2[] = { 0xC74D,
'\0' };
636 TEST(WideStringToUtf8Test, StopsOnNulCharacter) {
642 TEST(WideStringToUtf8Test, StopsWhenLengthLimitReached) {
646 #if !GTEST_WIDE_STRING_USES_UTF16_ 650 TEST(WideStringToUtf8Test, CanEncode17To21Bits) {
661 TEST(WideStringToUtf8Test, CanEncodeInvalidCodePoint) {
665 #else // !GTEST_WIDE_STRING_USES_UTF16_ 668 TEST(WideStringToUtf8Test, CanEncodeValidUtf16SUrrogatePairs) {
669 const wchar_t s[] = { 0xD801, 0xDC00,
'\0' };
675 TEST(WideStringToUtf8Test, CanEncodeInvalidUtf16SurrogatePair) {
677 const wchar_t s1[] = { 0xD800,
'\0' };
680 const wchar_t s2[] = { 0xD800,
'M',
'\0' };
683 const wchar_t s3[] = { 0xDC00,
'P',
'Q',
'R',
'\0' };
686 #endif // !GTEST_WIDE_STRING_USES_UTF16_ 689 #if !GTEST_WIDE_STRING_USES_UTF16_ 690 TEST(WideStringToUtf8Test, ConcatenatesCodepointsCorrectly) {
691 const wchar_t s[] = { 0x108634, 0xC74D,
'\n', 0x576, 0x8D3, 0x108634,
'\0'};
702 TEST(WideStringToUtf8Test, ConcatenatesCodepointsCorrectly) {
703 const wchar_t s[] = { 0xC74D,
'\n', 0x576, 0x8D3,
'\0'};
705 "\xEC\x9D\x8D" "\n" "\xD5\xB6" "\xE0\xA3\x93",
708 #endif // !GTEST_WIDE_STRING_USES_UTF16_ 712 TEST(RandomDeathTest, GeneratesCrashesOnInvalidRange) {
716 "Cannot generate a number in the range \\[0, 0\\)");
719 "Generation of a number in \\[0, 2147483649\\) was requested, " 720 "but this can only generate numbers in \\[0, 2147483648\\)");
723 TEST(RandomTest, GeneratesNumbersWithinRange) {
724 const UInt32 kRange = 10000;
726 for (
int i = 0;
i < 10;
i++) {
731 for (
int i = 0;
i < 10;
i++) {
732 EXPECT_LT(random2.Generate(kRange), kRange) <<
" for iteration " <<
i;
736 TEST(RandomTest, RepeatsWhenReseeded) {
737 const int kSeed = 123;
738 const int kArraySize = 10;
739 const UInt32 kRange = 10000;
743 for (
int i = 0;
i < kArraySize;
i++) {
748 for (
int i = 0;
i < kArraySize;
i++) {
757 static bool IsPositive(
int n) {
return n > 0; }
775 static int g_sum = 0;
776 static void Accumulate(
int n) { g_sum += n; }
818 "Invalid shuffle range start -1: must be in range \\[0, 3\\]");
821 "Invalid shuffle range start 4: must be in range \\[0, 3\\]");
824 "Invalid shuffle range finish 2: must be in range \\[3, 3\\]");
827 "Invalid shuffle range finish 4: must be in range \\[3, 3\\]");
830 class VectorShuffleTest :
public Test {
832 static const int kVectorSize = 20;
834 VectorShuffleTest() : random_(1) {
835 for (
int i = 0;
i < kVectorSize;
i++) {
836 vector_.push_back(
i);
841 if (kVectorSize != static_cast<int>(vector.size())) {
845 bool found_in_vector[kVectorSize] = {
false };
846 for (
size_t i = 0;
i < vector.size();
i++) {
847 const int e = vector[
i];
848 if (e < 0 || e >= kVectorSize || found_in_vector[e]) {
851 found_in_vector[e] =
true;
859 static bool VectorIsNotCorrupt(
const TestingVector& vector) {
860 return !VectorIsCorrupt(vector);
864 for (
int i = begin;
i <
end;
i++) {
865 if (
i != vector[
i]) {
872 static bool RangeIsUnshuffled(
874 return !RangeIsShuffled(vector, begin, end);
878 return RangeIsShuffled(vector, 0, static_cast<int>(vector.size()));
881 static bool VectorIsUnshuffled(
const TestingVector& vector) {
882 return !VectorIsShuffled(vector);
889 const int VectorShuffleTest::kVectorSize;
891 TEST_F(VectorShuffleTest, HandlesEmptyRange) {
898 ShuffleRange(&random_, kVectorSize/2, kVectorSize/2, &vector_);
903 ShuffleRange(&random_, kVectorSize - 1, kVectorSize - 1, &vector_);
908 ShuffleRange(&random_, kVectorSize, kVectorSize, &vector_);
913 TEST_F(VectorShuffleTest, HandlesRangeOfSizeOne) {
920 ShuffleRange(&random_, kVectorSize/2, kVectorSize/2 + 1, &vector_);
925 ShuffleRange(&random_, kVectorSize - 1, kVectorSize, &vector_);
933 TEST_F(VectorShuffleTest, ShufflesEntireVector) {
941 EXPECT_NE(kVectorSize - 1, vector_[kVectorSize - 1]);
944 TEST_F(VectorShuffleTest, ShufflesStartOfVector) {
945 const int kRangeSize = kVectorSize/2;
951 EXPECT_PRED3(RangeIsUnshuffled, vector_, kRangeSize, kVectorSize);
954 TEST_F(VectorShuffleTest, ShufflesEndOfVector) {
955 const int kRangeSize = kVectorSize / 2;
956 ShuffleRange(&random_, kRangeSize, kVectorSize, &vector_);
959 EXPECT_PRED3(RangeIsUnshuffled, vector_, 0, kRangeSize);
960 EXPECT_PRED3(RangeIsShuffled, vector_, kRangeSize, kVectorSize);
963 TEST_F(VectorShuffleTest, ShufflesMiddleOfVector) {
964 int kRangeSize = kVectorSize/3;
965 ShuffleRange(&random_, kRangeSize, 2*kRangeSize, &vector_);
968 EXPECT_PRED3(RangeIsUnshuffled, vector_, 0, kRangeSize);
969 EXPECT_PRED3(RangeIsShuffled, vector_, kRangeSize, 2*kRangeSize);
970 EXPECT_PRED3(RangeIsUnshuffled, vector_, 2*kRangeSize, kVectorSize);
973 TEST_F(VectorShuffleTest, ShufflesRepeatably) {
975 for (
int i = 0;
i < kVectorSize;
i++) {
976 vector2.push_back(
i);
979 random_.Reseed(1234);
981 random_.Reseed(1234);
987 for (
int i = 0;
i < kVectorSize;
i++) {
988 EXPECT_EQ(vector_[
i], vector2[i]) <<
" where i is " <<
i;
994 TEST(AssertHelperTest, AssertHelperIsSmall) {
1001 TEST(StringTest, EndsWithCaseInsensitive) {
1015 static const wchar_t*
const kNull = NULL;
1018 TEST(StringTest, CaseInsensitiveWideCStringEquals) {
1029 #if GTEST_OS_WINDOWS 1032 TEST(StringTest, ShowWideCString) {
1039 # if GTEST_OS_WINDOWS_MOBILE 1040 TEST(StringTest, AnsiAndUtf16Null) {
1041 EXPECT_EQ(NULL, String::AnsiToUtf16(NULL));
1042 EXPECT_EQ(NULL, String::Utf16ToAnsi(NULL));
1045 TEST(StringTest, AnsiAndUtf16ConvertBasic) {
1046 const char* ansi = String::Utf16ToAnsi(L
"str");
1049 const WCHAR* utf16 = String::AnsiToUtf16(
"str");
1050 EXPECT_EQ(0, wcsncmp(L
"str", utf16, 3));
1054 TEST(StringTest, AnsiAndUtf16ConvertPathChars) {
1055 const char* ansi = String::Utf16ToAnsi(L
".:\\ \"*?");
1058 const WCHAR* utf16 = String::AnsiToUtf16(
".:\\ \"*?");
1059 EXPECT_EQ(0, wcsncmp(L
".:\\ \"*?", utf16, 3));
1062 # endif // GTEST_OS_WINDOWS_MOBILE 1064 #endif // GTEST_OS_WINDOWS 1067 TEST(TestPropertyTest, StringValue) {
1074 TEST(TestPropertyTest, ReplaceStringValue) {
1077 property.SetValue(
"2");
1084 static void AddFatalFailure() {
1085 FAIL() <<
"Expected fatal failure.";
1088 static void AddNonfatalFailure() {
1092 class ScopedFakeTestPartResultReporterTest :
public Test {
1098 static void AddFailure(FailureMode failure) {
1099 if (failure == FATAL_FAILURE) {
1102 AddNonfatalFailure();
1109 TEST_F(ScopedFakeTestPartResultReporterTest, InterceptsTestFailures) {
1115 AddFailure(NONFATAL_FAILURE);
1116 AddFailure(FATAL_FAILURE);
1124 TEST_F(ScopedFakeTestPartResultReporterTest, DeprecatedConstructor) {
1129 AddFailure(NONFATAL_FAILURE);
1134 #if GTEST_IS_THREADSAFE 1136 class ScopedFakeTestPartResultReporterWithThreadsTest
1137 :
public ScopedFakeTestPartResultReporterTest {
1139 static void AddFailureInOtherThread(FailureMode failure) {
1140 ThreadWithParam<FailureMode> thread(&AddFailure, failure, NULL);
1145 TEST_F(ScopedFakeTestPartResultReporterWithThreadsTest,
1146 InterceptsTestFailuresInAllThreads) {
1151 AddFailure(NONFATAL_FAILURE);
1152 AddFailure(FATAL_FAILURE);
1153 AddFailureInOtherThread(NONFATAL_FAILURE);
1154 AddFailureInOtherThread(FATAL_FAILURE);
1164 #endif // GTEST_IS_THREADSAFE 1170 typedef ScopedFakeTestPartResultReporterTest ExpectFatalFailureTest;
1172 TEST_F(ExpectFatalFailureTest, CatchesFatalFaliure) {
1176 #if GTEST_HAS_GLOBAL_STRING 1177 TEST_F(ExpectFatalFailureTest, AcceptsStringObject) {
1182 TEST_F(ExpectFatalFailureTest, AcceptsStdStringObject) {
1187 TEST_F(ExpectFatalFailureTest, CatchesFatalFailureOnAllThreads) {
1191 "Expected fatal failure.");
1196 # pragma option push -w-ccc 1202 int NonVoidFunction() {
1208 TEST_F(ExpectFatalFailureTest, CanBeUsedInNonVoidFunction) {
1215 void DoesNotAbortHelper(
bool* aborted) {
1227 TEST_F(ExpectFatalFailureTest, DoesNotAbort) {
1228 bool aborted =
true;
1229 DoesNotAbortHelper(&aborted);
1237 static int global_var = 0;
1238 #define GTEST_USE_UNPROTECTED_COMMA_ global_var++, global_var++ 1240 TEST_F(ExpectFatalFailureTest, AcceptsMacroThatExpandsToUnprotectedComma) {
1241 #ifndef __BORLANDC__ 1257 typedef ScopedFakeTestPartResultReporterTest ExpectNonfatalFailureTest;
1259 TEST_F(ExpectNonfatalFailureTest, CatchesNonfatalFailure) {
1261 "Expected non-fatal failure.");
1264 #if GTEST_HAS_GLOBAL_STRING 1265 TEST_F(ExpectNonfatalFailureTest, AcceptsStringObject) {
1267 ::
string(
"Expected non-fatal failure."));
1271 TEST_F(ExpectNonfatalFailureTest, AcceptsStdStringObject) {
1276 TEST_F(ExpectNonfatalFailureTest, CatchesNonfatalFailureOnAllThreads) {
1280 "Expected non-fatal failure.");
1286 TEST_F(ExpectNonfatalFailureTest, AcceptsMacroThatExpandsToUnprotectedComma) {
1289 AddNonfatalFailure();
1294 AddNonfatalFailure();
1298 #if GTEST_IS_THREADSAFE 1300 typedef ScopedFakeTestPartResultReporterWithThreadsTest
1301 ExpectFailureWithThreadsTest;
1303 TEST_F(ExpectFailureWithThreadsTest, ExpectFatalFailureOnAllThreads) {
1305 "Expected fatal failure.");
1308 TEST_F(ExpectFailureWithThreadsTest, ExpectNonFatalFailureOnAllThreads) {
1310 AddFailureInOtherThread(NONFATAL_FAILURE),
"Expected non-fatal failure.");
1313 #endif // GTEST_IS_THREADSAFE 1317 TEST(TestPropertyTest, ConstructorWorks) {
1323 TEST(TestPropertyTest, SetValue) {
1326 property.SetValue(
"value_2");
1334 class TestResultTest :
public Test {
1336 typedef std::vector<TestPartResult> TPRVector;
1344 virtual void SetUp() {
1367 TPRVector* results1 =
const_cast<TPRVector*
>(
1369 TPRVector* results2 =
const_cast<TPRVector*
>(
1375 results1->push_back(*pr1);
1378 results2->push_back(*pr1);
1379 results2->push_back(*pr2);
1382 virtual void TearDown() {
1392 static void CompareTestPartResult(
const TestPartResult& expected,
1407 TEST_F(TestResultTest, total_part_count) {
1414 TEST_F(TestResultTest, Passed) {
1421 TEST_F(TestResultTest, Failed) {
1429 typedef TestResultTest TestResultDeathTest;
1431 TEST_F(TestResultDeathTest, GetTestPartResult) {
1432 CompareTestPartResult(*pr1, r2->GetTestPartResult(0));
1433 CompareTestPartResult(*pr2, r2->GetTestPartResult(1));
1439 TEST(TestResultPropertyTest, NoPropertiesFoundWhenNoneAreAdded) {
1445 TEST(TestResultPropertyTest, OnePropertyFoundWhenAdded) {
1456 TEST(TestResultPropertyTest, MultiplePropertiesFoundWhenAdded) {
1473 TEST(TestResultPropertyTest, OverridesValuesForDuplicateKeys) {
1495 TEST(TestResultPropertyTest, GetTestProperty) {
1533 class GTestFlagSaverTest :
public Test {
1538 static void SetUpTestCase() {
1560 static void TearDownTestCase() {
1567 void VerifyAndModifyFlags() {
1597 GTEST_FLAG(stream_result_to) =
"localhost:1234";
1612 TEST_F(GTestFlagSaverTest, ModifyGTestFlags) {
1613 VerifyAndModifyFlags();
1618 TEST_F(GTestFlagSaverTest, VerifyGTestFlags) {
1619 VerifyAndModifyFlags();
1625 static void SetEnv(
const char*
name,
const char*
value) {
1626 #if GTEST_OS_WINDOWS_MOBILE 1629 #elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9) 1633 static std::map<std::string, std::string*> added_env;
1638 if (added_env.find(name) != added_env.end()) {
1639 prev_env = added_env[
name];
1642 (
Message() << name <<
"=" << value).GetString());
1647 putenv(const_cast<char*>(added_env[name]->c_str()));
1649 #elif GTEST_OS_WINDOWS // If we are on Windows proper. 1650 _putenv((
Message() << name <<
"=" << value).GetString().c_str());
1652 if (*value ==
'\0') {
1655 setenv(name, value, 1);
1657 #endif // GTEST_OS_WINDOWS_MOBILE 1660 #if !GTEST_OS_WINDOWS_MOBILE 1669 TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenVariableIsNotSet) {
1674 # if !defined(GTEST_GET_INT32_FROM_ENV_) 1678 TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenValueOverflows) {
1679 printf(
"(expecting 2 warnings)\n");
1690 TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenValueIsInvalid) {
1691 printf(
"(expecting 2 warnings)\n");
1700 # endif // !defined(GTEST_GET_INT32_FROM_ENV_) 1705 TEST(Int32FromGTestEnvTest, ParsesAndReturnsValidValue) {
1712 #endif // !GTEST_OS_WINDOWS_MOBILE 1718 TEST(ParseInt32FlagTest, ReturnsFalseForInvalidFlag) {
1729 TEST(ParseInt32FlagTest, ReturnsDefaultWhenValueOverflows) {
1730 printf(
"(expecting 2 warnings)\n");
1743 TEST(ParseInt32FlagTest, ReturnsDefaultWhenValueIsInvalid) {
1744 printf(
"(expecting 2 warnings)\n");
1757 TEST(ParseInt32FlagTest, ParsesAndReturnsValidValue) {
1770 #if !GTEST_OS_WINDOWS_MOBILE 1771 TEST(Int32FromEnvOrDieTest, ParsesAndReturnsValidValue) {
1778 #endif // !GTEST_OS_WINDOWS_MOBILE 1782 TEST(Int32FromEnvOrDieDeathTest, AbortsOnFailure) {
1791 TEST(Int32FromEnvOrDieDeathTest, AbortsOnInt32Overflow) {
1800 TEST(ShouldRunTestOnShardTest, IsPartitionWhenThereIsOneShard) {
1810 virtual void SetUp() {
1815 virtual void TearDown() {
1816 SetEnv(index_var_,
"");
1817 SetEnv(total_var_,
"");
1820 const char* index_var_;
1821 const char* total_var_;
1826 TEST_F(ShouldShardTest, ReturnsFalseWhenNeitherEnvVarIsSet) {
1827 SetEnv(index_var_,
"");
1828 SetEnv(total_var_,
"");
1835 TEST_F(ShouldShardTest, ReturnsFalseWhenTotalShardIsOne) {
1836 SetEnv(index_var_,
"0");
1837 SetEnv(total_var_,
"1");
1845 #if !GTEST_OS_WINDOWS_MOBILE 1846 TEST_F(ShouldShardTest, WorksWhenShardEnvVarsAreValid) {
1847 SetEnv(index_var_,
"4");
1848 SetEnv(total_var_,
"22");
1852 SetEnv(index_var_,
"8");
1853 SetEnv(total_var_,
"9");
1857 SetEnv(index_var_,
"0");
1858 SetEnv(total_var_,
"9");
1862 #endif // !GTEST_OS_WINDOWS_MOBILE 1866 typedef ShouldShardTest ShouldShardDeathTest;
1868 TEST_F(ShouldShardDeathTest, AbortsWhenShardingEnvVarsAreInvalid) {
1869 SetEnv(index_var_,
"4");
1870 SetEnv(total_var_,
"4");
1873 SetEnv(index_var_,
"4");
1874 SetEnv(total_var_,
"-2");
1877 SetEnv(index_var_,
"5");
1878 SetEnv(total_var_,
"");
1881 SetEnv(index_var_,
"");
1882 SetEnv(total_var_,
"5");
1888 TEST(ShouldRunTestOnShardTest, IsPartitionWhenThereAreFiveShards) {
1890 const int num_tests = 17;
1891 const int num_shards = 5;
1894 for (
int test_id = 0; test_id < num_tests; test_id++) {
1895 int prev_selected_shard_index = -1;
1896 for (
int shard_index = 0; shard_index < num_shards; shard_index++) {
1898 if (prev_selected_shard_index < 0) {
1899 prev_selected_shard_index = shard_index;
1901 ADD_FAILURE() <<
"Shard " << prev_selected_shard_index <<
" and " 1902 << shard_index <<
" are both selected to run test " << test_id;
1910 for (
int shard_index = 0; shard_index < num_shards; shard_index++) {
1911 int num_tests_on_shard = 0;
1912 for (
int test_id = 0; test_id < num_tests; test_id++) {
1913 num_tests_on_shard +=
1916 EXPECT_GE(num_tests_on_shard, num_tests / num_shards);
1930 TEST(UnitTestTest, CanGetOriginalWorkingDir) {
1935 TEST(UnitTestTest, ReturnsPlausibleTimestamp) {
1943 void ExpectNonFatalFailureRecordingPropertyWithReservedKey(
1944 const TestResult& test_result,
const char* key) {
1947 <<
"' recorded unexpectedly.";
1950 void ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
1954 ExpectNonFatalFailureRecordingPropertyWithReservedKey(*test_info->
result(),
1958 void ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestCase(
1962 ExpectNonFatalFailureRecordingPropertyWithReservedKey(
1966 void ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestCase(
1968 ExpectNonFatalFailureRecordingPropertyWithReservedKey(
1975 class UnitTestRecordPropertyTest :
1978 static void SetUpTestCase() {
1979 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestCase(
1981 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestCase(
1983 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestCase(
1985 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestCase(
1987 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestCase(
1989 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestCase(
2005 TEST_F(UnitTestRecordPropertyTest, OnePropertyFoundWhenAdded) {
2006 UnitTestRecordProperty(
"key_1",
"1");
2008 ASSERT_EQ(1, unit_test_.ad_hoc_test_result().test_property_count());
2011 unit_test_.ad_hoc_test_result().GetTestProperty(0).key());
2013 unit_test_.ad_hoc_test_result().GetTestProperty(0).value());
2017 TEST_F(UnitTestRecordPropertyTest, MultiplePropertiesFoundWhenAdded) {
2018 UnitTestRecordProperty(
"key_1",
"1");
2019 UnitTestRecordProperty(
"key_2",
"2");
2021 ASSERT_EQ(2, unit_test_.ad_hoc_test_result().test_property_count());
2024 unit_test_.ad_hoc_test_result().GetTestProperty(0).key());
2025 EXPECT_STREQ(
"1", unit_test_.ad_hoc_test_result().GetTestProperty(0).value());
2028 unit_test_.ad_hoc_test_result().GetTestProperty(1).key());
2029 EXPECT_STREQ(
"2", unit_test_.ad_hoc_test_result().GetTestProperty(1).value());
2033 TEST_F(UnitTestRecordPropertyTest, OverridesValuesForDuplicateKeys) {
2034 UnitTestRecordProperty(
"key_1",
"1");
2035 UnitTestRecordProperty(
"key_2",
"2");
2036 UnitTestRecordProperty(
"key_1",
"12");
2037 UnitTestRecordProperty(
"key_2",
"22");
2039 ASSERT_EQ(2, unit_test_.ad_hoc_test_result().test_property_count());
2042 unit_test_.ad_hoc_test_result().GetTestProperty(0).key());
2044 unit_test_.ad_hoc_test_result().GetTestProperty(0).value());
2047 unit_test_.ad_hoc_test_result().GetTestProperty(1).key());
2049 unit_test_.ad_hoc_test_result().GetTestProperty(1).value());
2052 TEST_F(UnitTestRecordPropertyTest,
2053 AddFailureInsideTestsWhenUsingTestCaseReservedKeys) {
2054 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2056 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2058 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2060 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2062 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2064 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2068 TEST_F(UnitTestRecordPropertyTest,
2069 AddRecordWithReservedKeysGeneratesCorrectPropertyList) {
2072 "'classname', 'name', 'status', 'time', 'type_param', and 'value_param'" 2076 class UnitTestRecordPropertyTestEnvironment :
public Environment {
2078 virtual void TearDown() {
2079 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestCase(
2081 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestCase(
2083 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestCase(
2085 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestCase(
2087 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestCase(
2089 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestCase(
2091 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestCase(
2093 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestCase(
2111 bool IsEven(
int n) {
2112 return (n % 2) == 0;
2116 struct IsEvenFunctor {
2117 bool operator()(
int n) {
return IsEven(n); }
2128 msg << expr <<
" evaluates to " << n <<
", which is not even.";
2153 struct AssertIsEvenFunctor {
2155 return AssertIsEven(expr, n);
2160 bool SumIsEven2(
int n1,
int n2) {
2161 return IsEven(n1 + n2);
2166 struct SumIsEven3Functor {
2167 bool operator()(
int n1,
int n2,
int n3) {
2168 return IsEven(n1 + n2 + n3);
2175 const char* e1,
const char* e2,
const char* e3,
const char* e4,
2176 int n1,
int n2,
int n3,
int n4) {
2177 const int sum = n1 + n2 + n3 + n4;
2183 msg << e1 <<
" + " << e2 <<
" + " << e3 <<
" + " << e4
2184 <<
" (" << n1 <<
" + " << n2 <<
" + " << n3 <<
" + " << n4
2185 <<
") evaluates to " << sum <<
", which is not even.";
2191 struct AssertSumIsEven5Functor {
2193 const char* e1,
const char* e2,
const char* e3,
const char* e4,
2194 const char* e5,
int n1,
int n2,
int n3,
int n4,
int n5) {
2195 const int sum = n1 + n2 + n3 + n4 + n5;
2201 msg << e1 <<
" + " << e2 <<
" + " << e3 <<
" + " << e4 <<
" + " << e5
2203 << n1 <<
" + " << n2 <<
" + " << n3 <<
" + " << n4 <<
" + " << n5
2204 <<
") evaluates to " << sum <<
", which is not even.";
2213 TEST(Pred1Test, WithoutFormat) {
2215 EXPECT_PRED1(IsEvenFunctor(), 2) <<
"This failure is UNEXPECTED!";
2220 EXPECT_PRED1(IsEven, 5) <<
"This failure is expected.";
2221 },
"This failure is expected.");
2223 "evaluates to false");
2227 TEST(Pred1Test, WithFormat) {
2231 <<
"This failure is UNEXPECTED!";
2236 "n evaluates to 5, which is not even.");
2239 },
"This failure is expected.");
2244 TEST(Pred1Test, SingleEvaluationOnFailure) {
2248 EXPECT_EQ(1, n) <<
"The argument is not evaluated exactly once.";
2253 <<
"This failure is expected.";
2254 },
"This failure is expected.");
2255 EXPECT_EQ(2, n) <<
"The argument is not evaluated exactly once.";
2262 TEST(PredTest, WithoutFormat) {
2264 ASSERT_PRED2(SumIsEven2, 2, 4) <<
"This failure is UNEXPECTED!";
2271 EXPECT_PRED2(SumIsEven2, n1, n2) <<
"This failure is expected.";
2272 },
"This failure is expected.");
2275 },
"evaluates to false");
2279 TEST(PredTest, WithFormat) {
2282 "This failure is UNEXPECTED!";
2292 },
"evaluates to 13, which is not even.");
2295 <<
"This failure is expected.";
2296 },
"This failure is expected.");
2301 TEST(PredTest, SingleEvaluationOnFailure) {
2306 EXPECT_EQ(1, n1) <<
"Argument 1 is not evaluated exactly once.";
2307 EXPECT_EQ(1, n2) <<
"Argument 2 is not evaluated exactly once.";
2315 n1++, n2++, n3++, n4++, n5++)
2316 <<
"This failure is UNEXPECTED!";
2317 EXPECT_EQ(1, n1) <<
"Argument 1 is not evaluated exactly once.";
2318 EXPECT_EQ(1, n2) <<
"Argument 2 is not evaluated exactly once.";
2319 EXPECT_EQ(1, n3) <<
"Argument 3 is not evaluated exactly once.";
2320 EXPECT_EQ(1, n4) <<
"Argument 4 is not evaluated exactly once.";
2321 EXPECT_EQ(1, n5) <<
"Argument 5 is not evaluated exactly once.";
2327 <<
"This failure is expected.";
2328 },
"This failure is expected.");
2329 EXPECT_EQ(1, n1) <<
"Argument 1 is not evaluated exactly once.";
2330 EXPECT_EQ(1, n2) <<
"Argument 2 is not evaluated exactly once.";
2331 EXPECT_EQ(1, n3) <<
"Argument 3 is not evaluated exactly once.";
2334 n1 = n2 = n3 = n4 = 0;
2337 },
"evaluates to 1, which is not even.");
2338 EXPECT_EQ(1, n1) <<
"Argument 1 is not evaluated exactly once.";
2339 EXPECT_EQ(1, n2) <<
"Argument 2 is not evaluated exactly once.";
2340 EXPECT_EQ(1, n3) <<
"Argument 3 is not evaluated exactly once.";
2341 EXPECT_EQ(1, n4) <<
"Argument 4 is not evaluated exactly once.";
2352 template <
typename T>
2353 bool IsNegative(
T x) {
2357 template <
typename T1,
typename T2>
2364 TEST(PredicateAssertionTest, AcceptsOverloadedFunction) {
2372 TEST(PredicateAssertionTest, AcceptsTemplateFunction) {
2393 template <
typename T>
2399 template <
typename T1,
typename T2>
2401 const T1& x1,
const T2& x2) {
2408 TEST(PredicateFormatAssertionTest, AcceptsOverloadedFunction) {
2415 TEST(PredicateFormatAssertionTest, AcceptsTemplateFunction) {
2425 const char *
const p1 =
"good";
2429 const char p2[] =
"good";
2433 "Expected: \"bad\"");
2437 TEST(StringAssertionTest, ASSERT_STREQ_Null) {
2444 TEST(StringAssertionTest, ASSERT_STREQ_Null2) {
2459 "\"Hi\" vs \"Hi\"");
2486 TEST(StringAssertionTest, STREQ_Wide) {
2488 ASSERT_STREQ(static_cast<const wchar_t *>(NULL), NULL);
2510 EXPECT_STREQ(L
"abc\x8119", L
"abc\x8121") <<
"Expected failure";
2511 },
"Expected failure");
2515 TEST(StringAssertionTest, STRNE_Wide) {
2518 EXPECT_STRNE(static_cast<const wchar_t *>(NULL), NULL);
2540 ASSERT_STRNE(L
"abc\x8119", L
"abc\x8120") <<
"This shouldn't happen";
2547 TEST(IsSubstringTest, ReturnsCorrectResultForCString) {
2558 TEST(IsSubstringTest, ReturnsCorrectResultForWideCString) {
2569 TEST(IsSubstringTest, GeneratesCorrectMessageForCString) {
2571 " Actual: \"needle\"\n" 2572 "Expected: a substring of haystack_expr\n" 2573 "Which is: \"haystack\"",
2575 "needle",
"haystack").failure_message());
2580 TEST(IsSubstringTest, ReturnsCorrectResultsForStdString) {
2585 #if GTEST_HAS_STD_WSTRING 2588 TEST(IsSubstringTest, ReturnsCorrectResultForStdWstring) {
2595 TEST(IsSubstringTest, GeneratesCorrectMessageForWstring) {
2597 " Actual: L\"needle\"\n" 2598 "Expected: a substring of haystack_expr\n" 2599 "Which is: L\"haystack\"",
2601 "needle_expr",
"haystack_expr",
2602 ::
std::wstring(L
"needle"), L
"haystack").failure_message());
2605 #endif // GTEST_HAS_STD_WSTRING 2611 TEST(IsNotSubstringTest, ReturnsCorrectResultForCString) {
2618 TEST(IsNotSubstringTest, ReturnsCorrectResultForWideCString) {
2625 TEST(IsNotSubstringTest, GeneratesCorrectMessageForWideCString) {
2627 " Actual: L\"needle\"\n" 2628 "Expected: not a substring of haystack_expr\n" 2629 "Which is: L\"two needles\"",
2631 "needle_expr",
"haystack_expr",
2632 L
"needle", L
"two needles").failure_message());
2637 TEST(IsNotSubstringTest, ReturnsCorrectResultsForStdString) {
2644 TEST(IsNotSubstringTest, GeneratesCorrectMessageForStdString) {
2646 " Actual: \"needle\"\n" 2647 "Expected: not a substring of haystack_expr\n" 2648 "Which is: \"two needles\"",
2650 "needle_expr",
"haystack_expr",
2651 ::
std::string(
"needle"),
"two needles").failure_message());
2654 #if GTEST_HAS_STD_WSTRING 2658 TEST(IsNotSubstringTest, ReturnsCorrectResultForStdWstring) {
2664 #endif // GTEST_HAS_STD_WSTRING 2668 template <
typename RawType>
2669 class FloatingPointTest :
public Test {
2673 RawType close_to_positive_zero;
2674 RawType close_to_negative_zero;
2675 RawType further_from_negative_zero;
2677 RawType close_to_one;
2678 RawType further_from_one;
2681 RawType close_to_infinity;
2682 RawType further_from_infinity;
2689 typedef typename Floating::Bits Bits;
2691 virtual void SetUp() {
2692 const size_t max_ulps = Floating::kMaxUlps;
2695 const Bits zero_bits = Floating(0).
bits();
2698 values_.close_to_positive_zero = Floating::ReinterpretBits(
2699 zero_bits + max_ulps/2);
2700 values_.close_to_negative_zero = -Floating::ReinterpretBits(
2701 zero_bits + max_ulps - max_ulps/2);
2702 values_.further_from_negative_zero = -Floating::ReinterpretBits(
2703 zero_bits + max_ulps + 1 - max_ulps/2);
2706 const Bits one_bits = Floating(1).bits();
2709 values_.close_to_one = Floating::ReinterpretBits(one_bits + max_ulps);
2710 values_.further_from_one = Floating::ReinterpretBits(
2711 one_bits + max_ulps + 1);
2714 values_.infinity = Floating::Infinity();
2717 const Bits infinity_bits = Floating(values_.infinity).bits();
2720 values_.close_to_infinity = Floating::ReinterpretBits(
2721 infinity_bits - max_ulps);
2722 values_.further_from_infinity = Floating::ReinterpretBits(
2723 infinity_bits - max_ulps - 1);
2728 values_.nan1 = Floating::ReinterpretBits(Floating::kExponentBitMask
2729 | (static_cast<Bits>(1) << (Floating::kFractionBitCount - 1)) | 1);
2730 values_.nan2 = Floating::ReinterpretBits(Floating::kExponentBitMask
2731 | (static_cast<Bits>(1) << (Floating::kFractionBitCount - 1)) | 200);
2735 EXPECT_EQ(
sizeof(RawType),
sizeof(Bits));
2738 static TestValues values_;
2741 template <
typename RawType>
2742 typename FloatingPointTest<RawType>::TestValues
2743 FloatingPointTest<RawType>::values_;
2746 typedef FloatingPointTest<float>
FloatTest;
2749 TEST_F(FloatTest, Size) {
2754 TEST_F(FloatTest, Zeros) {
2767 TEST_F(FloatTest, AlmostZeros) {
2774 static const FloatTest::TestValues&
v = this->values_;
2782 v.further_from_negative_zero);
2783 },
"v.further_from_negative_zero");
2787 TEST_F(FloatTest, SmallDiff) {
2790 "values_.further_from_one");
2794 TEST_F(FloatTest, LargeDiff) {
2803 TEST_F(FloatTest, Infinity) {
2806 #if !GTEST_OS_SYMBIAN 2809 "-values_.infinity");
2815 #endif // !GTEST_OS_SYMBIAN 2820 #if !GTEST_OS_SYMBIAN 2829 static const FloatTest::TestValues&
v = this->values_;
2840 #endif // !GTEST_OS_SYMBIAN 2844 TEST_F(FloatTest, Reflexive) {
2851 TEST_F(FloatTest, Commutative) {
2865 "The difference between 1.0f and 1.5f is 0.5, " 2866 "which exceeds 0.25f");
2876 "The difference between 1.0f and 1.5f is 0.5, " 2877 "which exceeds 0.25f");
2883 TEST_F(FloatTest, FloatLESucceeds) {
2892 TEST_F(FloatTest, FloatLEFails) {
2895 "(2.0f) <= (1.0f)");
2900 },
"(values_.further_from_one) <= (1.0f)");
2902 #if !GTEST_OS_SYMBIAN && !defined(__BORLANDC__) 2908 },
"(values_.nan1) <= (values_.infinity)");
2911 },
"(-values_.infinity) <= (values_.nan1)");
2914 },
"(values_.nan1) <= (values_.nan1)");
2915 #endif // !GTEST_OS_SYMBIAN && !defined(__BORLANDC__) 2919 typedef FloatingPointTest<double>
DoubleTest;
2922 TEST_F(DoubleTest, Size) {
2927 TEST_F(DoubleTest, Zeros) {
2940 TEST_F(DoubleTest, AlmostZeros) {
2947 static const DoubleTest::TestValues&
v = this->values_;
2955 v.further_from_negative_zero);
2956 },
"v.further_from_negative_zero");
2960 TEST_F(DoubleTest, SmallDiff) {
2963 "values_.further_from_one");
2967 TEST_F(DoubleTest, LargeDiff) {
2976 TEST_F(DoubleTest, Infinity) {
2979 #if !GTEST_OS_SYMBIAN 2982 "-values_.infinity");
2988 #endif // !GTEST_OS_SYMBIAN 2992 TEST_F(DoubleTest, NaN) {
2993 #if !GTEST_OS_SYMBIAN 3000 static const DoubleTest::TestValues&
v = this->values_;
3009 #endif // !GTEST_OS_SYMBIAN 3013 TEST_F(DoubleTest, Reflexive) {
3016 #if !GTEST_OS_SYMBIAN 3019 #endif // !GTEST_OS_SYMBIAN 3023 TEST_F(DoubleTest, Commutative) {
3037 "The difference between 1.0 and 1.5 is 0.5, " 3038 "which exceeds 0.25");
3048 "The difference between 1.0 and 1.5 is 0.5, " 3049 "which exceeds 0.25");
3055 TEST_F(DoubleTest, DoubleLESucceeds) {
3064 TEST_F(DoubleTest, DoubleLEFails) {
3072 },
"(values_.further_from_one) <= (1.0)");
3074 #if !GTEST_OS_SYMBIAN && !defined(__BORLANDC__) 3080 },
"(values_.nan1) <= (values_.infinity)");
3083 },
" (-values_.infinity) <= (values_.nan1)");
3086 },
"(values_.nan1) <= (values_.nan1)");
3087 #endif // !GTEST_OS_SYMBIAN && !defined(__BORLANDC__) 3097 FAIL() <<
"Unexpected failure: Disabled test should not be run.";
3108 TEST(DISABLED_TestCase, TestShouldNotRun) {
3109 FAIL() <<
"Unexpected failure: Test in disabled test case should not be run.";
3114 TEST(DISABLED_TestCase, DISABLED_TestShouldNotRun) {
3115 FAIL() <<
"Unexpected failure: Test in disabled test case should not be run.";
3120 class DisabledTestsTest :
public Test {
3122 static void SetUpTestCase() {
3123 FAIL() <<
"Unexpected failure: All tests disabled in test case. " 3124 "SetupTestCase() should not be called.";
3127 static void TearDownTestCase() {
3128 FAIL() <<
"Unexpected failure: All tests disabled in test case. " 3129 "TearDownTestCase() should not be called.";
3133 TEST_F(DisabledTestsTest, DISABLED_TestShouldNotRun_1) {
3134 FAIL() <<
"Unexpected failure: Disabled test should not be run.";
3137 TEST_F(DisabledTestsTest, DISABLED_TestShouldNotRun_2) {
3138 FAIL() <<
"Unexpected failure: Disabled test should not be run.";
3143 #if GTEST_HAS_TYPED_TEST 3145 template <
typename T>
3149 typedef testing::Types<int, double> NumericTypes;
3153 FAIL() <<
"Unexpected failure: Disabled typed test should not run.";
3156 template <
typename T>
3157 class DISABLED_TypedTest :
public Test {
3162 TYPED_TEST(DISABLED_TypedTest, ShouldNotRun) {
3163 FAIL() <<
"Unexpected failure: Disabled typed test should not run.";
3166 #endif // GTEST_HAS_TYPED_TEST 3170 #if GTEST_HAS_TYPED_TEST_P 3172 template <
typename T>
3173 class TypedTestP :
public Test {
3179 FAIL() <<
"Unexpected failure: " 3180 <<
"Disabled type-parameterized test should not run.";
3187 template <
typename T>
3188 class DISABLED_TypedTestP :
public Test {
3194 FAIL() <<
"Unexpected failure: " 3195 <<
"Disabled type-parameterized test should not run.";
3202 #endif // GTEST_HAS_TYPED_TEST_P 3206 class SingleEvaluationTest :
public Test {
3211 static void CompareAndIncrementCharPtrs() {
3217 static void CompareAndIncrementInts() {
3222 SingleEvaluationTest() {
3229 static const char*
const s1_;
3230 static const char*
const s2_;
3231 static const char* p1_;
3232 static const char* p2_;
3238 const char*
const SingleEvaluationTest::s1_ =
"01234";
3239 const char*
const SingleEvaluationTest::s2_ =
"abcde";
3240 const char* SingleEvaluationTest::p1_;
3241 const char* SingleEvaluationTest::p2_;
3242 int SingleEvaluationTest::a_;
3243 int SingleEvaluationTest::b_;
3247 TEST_F(SingleEvaluationTest, FailedASSERT_STREQ) {
3255 TEST_F(SingleEvaluationTest, ASSERT_STR) {
3270 TEST_F(SingleEvaluationTest, FailedASSERT_NE) {
3272 "(a_++) != (b_++)");
3278 TEST_F(SingleEvaluationTest, OtherCases) {
3307 #if GTEST_HAS_EXCEPTIONS 3309 void ThrowAnInteger() {
3314 TEST_F(SingleEvaluationTest, ExceptionTests) {
3326 }, bool),
"throws a different type");
3356 #endif // GTEST_HAS_EXCEPTIONS 3359 class NoFatalFailureTest :
public Test {
3362 void FailsNonFatal() {
3366 FAIL() <<
"some fatal failure";
3369 void DoAssertNoFatalFailureOnFails() {
3374 void DoExpectNoFatalFailureOnFails() {
3380 TEST_F(NoFatalFailureTest, NoFailure) {
3385 TEST_F(NoFatalFailureTest, NonFatalIsNoFailure) {
3388 "some non-fatal failure");
3391 "some non-fatal failure");
3394 TEST_F(NoFatalFailureTest, AssertNoFatalFailureOnFatalFailure) {
3398 DoAssertNoFatalFailureOnFails();
3411 TEST_F(NoFatalFailureTest, ExpectNoFatalFailureOnFatalFailure) {
3415 DoExpectNoFatalFailureOnFails();
3432 TEST_F(NoFatalFailureTest, MessageIsStreamable) {
3451 std::string EditsToString(
const std::vector<EditType>& edits) {
3453 for (
size_t i = 0;
i < edits.size(); ++
i) {
3454 static const char kEdits[] =
" +-/";
3455 out.append(1, kEdits[edits[
i]]);
3460 std::vector<size_t> CharsToIndices(
const std::string& str) {
3461 std::vector<size_t> out;
3462 for (
size_t i = 0;
i < str.size(); ++
i) {
3463 out.push_back(str[
i]);
3468 std::vector<std::string> CharsToLines(
const std::string& str) {
3469 std::vector<std::string> out;
3470 for (
size_t i = 0;
i < str.size(); ++
i) {
3471 out.push_back(str.substr(
i, 1));
3476 TEST(EditDistance, TestCases) {
3481 const char* expected_edits;
3482 const char* expected_diff;
3484 static const Case kCases[] = {
3486 {__LINE__,
"A",
"A",
" ",
""},
3487 {__LINE__,
"ABCDE",
"ABCDE",
" ",
""},
3489 {__LINE__,
"X",
"XA",
" +",
"@@ +1,2 @@\n X\n+A\n"},
3490 {__LINE__,
"X",
"XABCD",
" ++++",
"@@ +1,5 @@\n X\n+A\n+B\n+C\n+D\n"},
3492 {__LINE__,
"XA",
"X",
" -",
"@@ -1,2 @@\n X\n-A\n"},
3493 {__LINE__,
"XABCD",
"X",
" ----",
"@@ -1,5 @@\n X\n-A\n-B\n-C\n-D\n"},
3495 {__LINE__,
"A",
"a",
"/",
"@@ -1,1 +1,1 @@\n-A\n+a\n"},
3496 {__LINE__,
"ABCD",
"abcd",
"////",
3497 "@@ -1,4 +1,4 @@\n-A\n-B\n-C\n-D\n+a\n+b\n+c\n+d\n"},
3499 {__LINE__,
"ABCDEFGH",
"ABXEGH1",
" -/ - +",
3500 "@@ -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"},
3501 {__LINE__,
"AAAABCCCC",
"ABABCDCDC",
"- / + / ",
3502 "@@ -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"},
3503 {__LINE__,
"ABCDE",
"BCDCD",
"- +/",
3504 "@@ -1,5 +1,5 @@\n-A\n B\n C\n D\n-E\n+C\n+D\n"},
3505 {__LINE__,
"ABCDEFGHIJKL",
"BCDCDEFGJKLJK",
"- ++ -- ++",
3506 "@@ -1,4 +1,5 @@\n-A\n B\n+C\n+D\n C\n D\n" 3507 "@@ -6,7 +7,7 @@\n F\n G\n-H\n-I\n J\n K\n L\n+J\n+K\n"},
3509 for (
const Case*
c = kCases;
c->left; ++
c) {
3512 CharsToIndices(
c->right))))
3513 <<
"Left <" <<
c->left <<
"> Right <" <<
c->right <<
"> Edits <" 3515 CharsToIndices(
c->left), CharsToIndices(
c->right))) <<
">";
3517 CharsToLines(
c->right)))
3518 <<
"Left <" <<
c->left <<
"> Right <" <<
c->right <<
"> Diff <" 3528 EqFailure(
"foo",
"bar", foo_val, bar_val,
false)
3529 .failure_message());
3533 "To be equal to: bar\n" 3538 EqFailure(
"foo",
"6", foo_val, bar_val,
false)
3539 .failure_message());
3543 "To be equal to: 6",
3547 EqFailure(
"5",
"bar", foo_val, bar_val,
false)
3548 .failure_message());
3551 "To be equal to: bar\n" 3556 EqFailure(
"5",
"6", foo_val, bar_val,
false).failure_message());
3559 "To be equal to: 6",
3565 true).failure_message());
3568 " Which is: \"x\"\n" 3569 "To be equal to: bar\n" 3570 " Which is: \"y\"\n" 3575 TEST(AssertionTest, EqFailureWithDiff) {
3577 "1\\n2XXX\\n3\\n5\\n6\\n7\\n8\\n9\\n10\\n11\\n12XXX\\n13\\n14\\n15");
3579 "1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n11\\n12\\n13\\n14");
3581 EqFailure(
"left",
"right", left, right,
false).failure_message());
3585 "1\\n2XXX\\n3\\n5\\n6\\n7\\n8\\n9\\n10\\n11\\n12XXX\\n13\\n14\\n15\n" 3586 "To be equal to: right\n" 3587 " Which is: 1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n11\\n12\\n13\\n14\n" 3588 "With diff:\n@@ -1,5 +1,6 @@\n 1\n-2XXX\n+2\n 3\n+4\n 5\n 6\n" 3589 "@@ -7,8 +8,6 @@\n 8\n 9\n-10\n 11\n-12XXX\n+12\n 13\n 14\n-15\n",
3608 # pragma option push -w-ccc -w-rch 3619 TEST(AssertionTest, AssertTrueWithAssertionResult) {
3621 #ifndef __BORLANDC__ 3624 "Value of: ResultIsEven(3)\n" 3625 " Actual: false (3 is odd)\n" 3630 "Value of: ResultIsEvenNoExplanation(3)\n" 3631 " Actual: false (3 is odd)\n" 3645 TEST(AssertionTest, AssertFalseWithAssertionResult) {
3647 #ifndef __BORLANDC__ 3650 "Value of: ResultIsEven(2)\n" 3651 " Actual: true (2 is even)\n" 3656 "Value of: ResultIsEvenNoExplanation(2)\n" 3669 TEST(ExpectTest, ASSERT_EQ_Double) {
3683 "To be equal to: 2*3\n" 3688 #if GTEST_CAN_COMPARE_NULL 3689 TEST(AssertionTest, ASSERT_EQ_NULL) {
3691 const char* p = NULL;
3701 "To be equal to: &n\n");
3703 #endif // GTEST_CAN_COMPARE_NULL 3709 TEST(ExpectTest, ASSERT_EQ_0) {
3724 "Expected: ('a') != ('a'), " 3725 "actual: 'a' (97, 0x61) vs 'a' (97, 0x61)");
3733 "Expected: (2) <= (0), actual: 2 vs 0");
3740 "Expected: (2) < (2), actual: 2 vs 2");
3748 "Expected: (2) >= (3), actual: 2 vs 3");
3755 "Expected: (2) > (2), actual: 2 vs 2");
3758 #if GTEST_HAS_EXCEPTIONS 3760 void ThrowNothing() {}
3766 # ifndef __BORLANDC__ 3771 "Expected: ThrowAnInteger() throws an exception of type bool.\n" 3772 " Actual: it throws a different type.");
3777 "Expected: ThrowNothing() throws an exception of type bool.\n" 3778 " Actual: it throws nothing.");
3785 "Expected: ThrowAnInteger() doesn't throw an exception." 3786 "\n Actual: it throws.");
3794 "Expected: ThrowNothing() throws an exception.\n" 3795 " Actual: it doesn't.");
3798 #endif // GTEST_HAS_EXCEPTIONS 3802 TEST(AssertionTest, AssertPrecedence) {
3804 bool false_value =
false;
3814 TEST(AssertionTest, NonFixtureSubroutine) {
3816 "To be equal to: x");
3822 explicit Uncopyable(
int a_value) : value_(a_value) {}
3824 int value()
const {
return value_; }
3826 return value() == rhs.value();
3831 Uncopyable(
const Uncopyable&);
3836 ::std::ostream&
operator<<(::std::ostream& os,
const Uncopyable& value) {
3837 return os << value.value();
3841 bool IsPositiveUncopyable(
const Uncopyable& x) {
3842 return x.value() > 0;
3846 void TestAssertNonPositive() {
3851 void TestAssertEqualsUncopyable() {
3858 TEST(AssertionTest, AssertWorksWithUncopyableObject) {
3863 "IsPositiveUncopyable(y) evaluates to false, where\ny evaluates to -1");
3865 "Expected: x\n Which is: 5\nTo be equal to: y\n Which is: -1");
3869 TEST(AssertionTest, ExpectWorksWithUncopyableObject) {
3874 "IsPositiveUncopyable(y) evaluates to false, where\ny evaluates to -1");
3877 "Expected: x\n Which is: 5\nTo be equal to: y\n Which is: -1");
3896 #if !GTEST_OS_MAC && !defined(__SUNPRO_CC) && !defined(__HP_aCC) 3919 # endif // GTEST_OS_LINUX 3927 EXPECT_EQ(static_cast<int>(kCaseA), static_cast<int>(kCaseB));
3929 # endif // GTEST_OS_LINUX 3938 "(kCaseA) >= (kCaseB)");
3949 # ifndef __BORLANDC__ 3953 "To be equal to: kCaseB");
3962 #endif // !GTEST_OS_MAC && !defined(__SUNPRO_CC) 3964 #if GTEST_OS_WINDOWS 3966 static HRESULT UnexpectedHRESULTFailure() {
3967 return E_UNEXPECTED;
3970 static HRESULT OkHRESULTSuccess() {
3974 static HRESULT FalseHRESULTSuccess() {
3982 TEST(HRESULTAssertionTest, EXPECT_HRESULT_SUCCEEDED) {
3983 EXPECT_HRESULT_SUCCEEDED(S_OK);
3984 EXPECT_HRESULT_SUCCEEDED(S_FALSE);
3987 "Expected: (UnexpectedHRESULTFailure()) succeeds.\n" 3988 " Actual: 0x8000FFFF");
3991 TEST(HRESULTAssertionTest, ASSERT_HRESULT_SUCCEEDED) {
3992 ASSERT_HRESULT_SUCCEEDED(S_OK);
3993 ASSERT_HRESULT_SUCCEEDED(S_FALSE);
3996 "Expected: (UnexpectedHRESULTFailure()) succeeds.\n" 3997 " Actual: 0x8000FFFF");
4000 TEST(HRESULTAssertionTest, EXPECT_HRESULT_FAILED) {
4001 EXPECT_HRESULT_FAILED(E_UNEXPECTED);
4004 "Expected: (OkHRESULTSuccess()) fails.\n" 4007 "Expected: (FalseHRESULTSuccess()) fails.\n" 4011 TEST(HRESULTAssertionTest, ASSERT_HRESULT_FAILED) {
4012 ASSERT_HRESULT_FAILED(E_UNEXPECTED);
4014 # ifndef __BORLANDC__ 4018 "Expected: (OkHRESULTSuccess()) fails.\n" 4023 "Expected: (FalseHRESULTSuccess()) fails.\n" 4028 TEST(HRESULTAssertionTest, Streaming) {
4029 EXPECT_HRESULT_SUCCEEDED(S_OK) <<
"unexpected failure";
4030 ASSERT_HRESULT_SUCCEEDED(S_OK) <<
"unexpected failure";
4031 EXPECT_HRESULT_FAILED(E_UNEXPECTED) <<
"unexpected failure";
4032 ASSERT_HRESULT_FAILED(E_UNEXPECTED) <<
"unexpected failure";
4035 EXPECT_HRESULT_SUCCEEDED(E_UNEXPECTED) <<
"expected failure",
4036 "expected failure");
4038 # ifndef __BORLANDC__ 4042 ASSERT_HRESULT_SUCCEEDED(E_UNEXPECTED) <<
"expected failure",
4043 "expected failure");
4047 EXPECT_HRESULT_FAILED(S_OK) <<
"expected failure",
4048 "expected failure");
4051 ASSERT_HRESULT_FAILED(S_OK) <<
"expected failure",
4052 "expected failure");
4055 #endif // GTEST_OS_WINDOWS 4059 # pragma option push -w-ccc -w-rch 4063 TEST(AssertionSyntaxTest, BasicAssertionsBehavesLikeSingleStatement) {
4065 ASSERT_TRUE(
false) <<
"This should never be executed; " 4066 "It's a compilation test only.";
4082 #if GTEST_HAS_EXCEPTIONS 4085 TEST(ExpectThrowTest, DoesNotGenerateUnreachableCodeWarning) {
4097 TEST(AssertionSyntaxTest, ExceptionAssertionsBehavesLikeSingleStatement) {
4122 #endif // GTEST_HAS_EXCEPTIONS 4124 TEST(AssertionSyntaxTest, NoFatalFailureAssertionsBehavesLikeSingleStatement) {
4127 <<
"It's a compilation test only.";
4148 TEST(AssertionSyntaxTest, WorksWithSwitch) {
4158 EXPECT_FALSE(
false) <<
"EXPECT_FALSE failed in switch case";
4165 ASSERT_EQ(1, 1) <<
"ASSERT_EQ failed in default switch handler";
4173 #if GTEST_HAS_EXCEPTIONS 4175 void ThrowAString() {
4176 throw "std::string";
4181 TEST(AssertionSyntaxTest, WorksWithConst) {
4187 #endif // GTEST_HAS_EXCEPTIONS 4201 TEST(SuccessfulAssertionTest, EXPECT) {
4207 TEST(SuccessfulAssertionTest, EXPECT_STR) {
4213 TEST(SuccessfulAssertionTest, ASSERT) {
4219 TEST(SuccessfulAssertionTest, ASSERT_STR) {
4230 TEST(AssertionWithMessageTest, EXPECT) {
4231 EXPECT_EQ(1, 1) <<
"This should succeed.";
4233 "Expected failure #1");
4234 EXPECT_LE(1, 2) <<
"This should succeed.";
4236 "Expected failure #2.");
4237 EXPECT_GE(1, 0) <<
"This should succeed.";
4239 "Expected failure #3.");
4243 "Expected failure #4.");
4246 "Expected failure #5.");
4250 "Expected failure #6.");
4251 EXPECT_NEAR(1, 1.1, 0.2) <<
"This should succeed.";
4254 TEST(AssertionWithMessageTest, ASSERT) {
4255 ASSERT_EQ(1, 1) <<
"This should succeed.";
4256 ASSERT_NE(1, 2) <<
"This should succeed.";
4257 ASSERT_LE(1, 2) <<
"This should succeed.";
4258 ASSERT_LT(1, 2) <<
"This should succeed.";
4259 ASSERT_GE(1, 0) <<
"This should succeed.";
4261 "Expected failure.");
4264 TEST(AssertionWithMessageTest, ASSERT_STR) {
4269 "Expected failure.");
4272 TEST(AssertionWithMessageTest, ASSERT_FLOATING) {
4285 ASSERT_FALSE(
true) <<
"Expected failure: " << 2 <<
" > " << 1
4286 <<
" evaluates to " <<
true;
4287 },
"Expected failure");
4291 TEST(AssertionWithMessageTest,
FAIL) {
4298 SUCCEED() <<
"Success == " << 1;
4306 ASSERT_TRUE(
false) <<
static_cast<const char *
>(NULL)
4307 << static_cast<char *>(NULL);
4311 #if GTEST_OS_WINDOWS 4313 TEST(AssertionWithMessageTest, WideStringMessage) {
4315 EXPECT_TRUE(
false) << L
"This failure is expected.\x8119";
4316 },
"This failure is expected.");
4319 << L
"expected too.\x8120";
4320 },
"This failure is expected too.");
4322 #endif // GTEST_OS_WINDOWS 4328 "Intentional failure #1.");
4330 "Intentional failure #2.");
4341 TEST(ExpectTest, ExpectTrueWithAssertionResult) {
4344 "Value of: ResultIsEven(3)\n" 4345 " Actual: false (3 is odd)\n" 4349 "Value of: ResultIsEvenNoExplanation(3)\n" 4350 " Actual: false (3 is odd)\n" 4359 "Intentional failure #1.");
4361 "Intentional failure #2.");
4371 TEST(ExpectTest, ExpectFalseWithAssertionResult) {
4374 "Value of: ResultIsEven(2)\n" 4375 " Actual: true (2 is even)\n" 4379 "Value of: ResultIsEvenNoExplanation(2)\n" 4394 "To be equal to: 2*3\n" 4403 TEST(ExpectTest, EXPECT_EQ_Double) {
4412 #if GTEST_CAN_COMPARE_NULL 4414 TEST(ExpectTest, EXPECT_EQ_NULL) {
4416 const char* p = NULL;
4426 "To be equal to: &n\n");
4428 #endif // GTEST_CAN_COMPARE_NULL 4434 TEST(ExpectTest, EXPECT_EQ_0) {
4450 "Expected: ('a') != ('a'), " 4451 "actual: 'a' (97, 0x61) vs 'a' (97, 0x61)");
4454 char*
const p0 = NULL;
4461 void* pv1 = (
void*)0x1234;
4462 char*
const p1 =
reinterpret_cast<char*
>(pv1);
4472 "Expected: (2) <= (0), actual: 2 vs 0");
4481 "Expected: (2) < (2), actual: 2 vs 2");
4491 "Expected: (2) >= (3), actual: 2 vs 3");
4500 "Expected: (2) > (2), actual: 2 vs 2");
4505 #if GTEST_HAS_EXCEPTIONS 4511 "Expected: ThrowAnInteger() throws an exception of " 4512 "type bool.\n Actual: it throws a different type.");
4515 "Expected: ThrowNothing() throws an exception of type bool.\n" 4516 " Actual: it throws nothing.");
4523 "Expected: ThrowAnInteger() doesn't throw an " 4524 "exception.\n Actual: it throws.");
4532 "Expected: ThrowNothing() throws an exception.\n" 4533 " Actual: it doesn't.");
4536 #endif // GTEST_HAS_EXCEPTIONS 4539 TEST(ExpectTest, ExpectPrecedence) {
4542 "To be equal to: true && false");
4549 TEST(StreamableToStringTest, Scalar) {
4554 TEST(StreamableToStringTest, Pointer) {
4561 TEST(StreamableToStringTest, NullPointer) {
4567 TEST(StreamableToStringTest, CString) {
4572 TEST(StreamableToStringTest, NullCString) {
4580 TEST(StreamableTest,
string) {
4582 "This failure message is a std::string, and is expected.");
4589 TEST(StreamableTest, stringWithEmbeddedNUL) {
4590 static const char char_array_with_nul[] =
4591 "Here's a NUL\0 and some more string";
4592 static const std::string string_with_nul(char_array_with_nul,
4593 sizeof(char_array_with_nul)
4596 "Here's a NUL\\0 and some more string");
4600 TEST(StreamableTest, NULChar) {
4602 FAIL() <<
"A NUL" <<
'\0' <<
" and some more string";
4603 },
"A NUL\\0 and some more string");
4607 TEST(StreamableTest,
int) {
4617 TEST(StreamableTest, NullCharPtr) {
4624 TEST(StreamableTest, BasicIoManip) {
4626 FAIL() <<
"Line 1." << std::endl
4627 <<
"A NUL char " << std::ends << std::flush <<
" in line 2.";
4628 },
"Line 1.\nA NUL char \\0 in line 2.");
4633 void AddFailureHelper(
bool* aborted) {
4641 bool aborted =
true;
4643 "Intentional failure.");
4667 "Intentional failure.");
4673 SUCCEED() <<
"Explicit success.";
4687 bool false_value =
false;
4689 },
"To be equal to: true");
4693 TEST(EqAssertionTest, Int) {
4700 TEST(EqAssertionTest, Time_T) {
4702 static_cast<time_t>(0));
4704 static_cast<time_t>(1234)),
4711 const char ch =
'b';
4719 TEST(EqAssertionTest, WideChar) {
4723 " Expected: L'\0'\n" 4724 " Which is: L'\0' (0, 0x0)\n" 4725 "To be equal to: L'x'\n" 4726 " Which is: L'x' (120, 0x78)");
4728 static wchar_t wchar;
4734 "To be equal to: wchar");
4738 TEST(EqAssertionTest, StdString) {
4754 char*
const p1 =
const_cast<char*
>(
"foo");
4763 "To be equal to: str3\n" 4764 " Which is: \"A \\0 in the middle\"");
4767 #if GTEST_HAS_STD_WSTRING 4770 TEST(EqAssertionTest, StdWideString) {
4778 const wchar_t kTestX8119[] = {
'T',
'e',
's',
't', 0x8119,
'\0' };
4783 const wchar_t kTestX8120[] = {
'T',
'e',
's',
't', 0x8120,
'\0' };
4791 wstr3.at(2) = L
'\0';
4802 #endif // GTEST_HAS_STD_WSTRING 4804 #if GTEST_HAS_GLOBAL_STRING 4806 TEST(EqAssertionTest, GlobalString) {
4828 ASSERT_EQ(::
string(
"bar"), const_cast<char*>(
"foo"));
4832 #endif // GTEST_HAS_GLOBAL_STRING 4834 #if GTEST_HAS_GLOBAL_WSTRING 4837 TEST(EqAssertionTest, GlobalWideString) {
4844 const wchar_t kTestX8119[] = {
'T',
'e',
's',
't', 0x8119,
'\0' };
4849 const wchar_t kTestX8120[] = {
'T',
'e',
's',
't', 0x8120,
'\0' };
4855 wchar_t*
const p1 =
const_cast<wchar_t*
>(L
"foo");
4863 wstr3.at(2) = L
'\0';
4868 #endif // GTEST_HAS_GLOBAL_WSTRING 4871 TEST(EqAssertionTest, CharPointer) {
4872 char*
const p0 = NULL;
4877 void* pv1 = (
void*)0x1234;
4878 void* pv2 = (
void*)0xABC0;
4879 char*
const p1 =
reinterpret_cast<char*
>(pv1);
4880 char*
const p2 =
reinterpret_cast<char*
>(pv2);
4884 "To be equal to: p2");
4888 reinterpret_cast<char*>(0xABC0)),
4893 TEST(EqAssertionTest, WideCharPointer) {
4894 wchar_t*
const p0 = NULL;
4899 void* pv1 = (
void*)0x1234;
4900 void* pv2 = (
void*)0xABC0;
4901 wchar_t*
const p1 =
reinterpret_cast<wchar_t*
>(pv1);
4902 wchar_t*
const p2 =
reinterpret_cast<wchar_t*
>(pv2);
4906 "To be equal to: p2");
4909 void* pv3 = (
void*)0x1234;
4910 void* pv4 = (
void*)0xABC0;
4911 const wchar_t* p3 =
reinterpret_cast<const wchar_t*
>(pv3);
4912 const wchar_t* p4 =
reinterpret_cast<const wchar_t*
>(pv4);
4918 TEST(EqAssertionTest, OtherPointer) {
4919 ASSERT_EQ(static_cast<const int*>(NULL),
4920 static_cast<const int*>(NULL));
4922 reinterpret_cast<const int*>(0x1234)),
4927 class UnprintableChar {
4929 explicit UnprintableChar(
char ch) : char_(ch) {}
4932 return char_ == rhs.char_;
4934 bool operator!=(
const UnprintableChar& rhs)
const {
4935 return char_ != rhs.char_;
4937 bool operator<(
const UnprintableChar& rhs)
const {
4938 return char_ < rhs.char_;
4940 bool operator<=(
const UnprintableChar& rhs)
const {
4941 return char_ <= rhs.char_;
4943 bool operator>(
const UnprintableChar& rhs)
const {
4944 return char_ > rhs.char_;
4946 bool operator>=(
const UnprintableChar& rhs)
const {
4947 return char_ >= rhs.char_;
4956 TEST(ComparisonAssertionTest, AcceptsUnprintableArgs) {
4957 const UnprintableChar
x(
'x'),
y(
'y');
4973 #ifndef __BORLANDC__ 4976 "1-byte object <78>");
4978 "1-byte object <78>");
4981 "1-byte object <79>");
4983 "1-byte object <78>");
4985 "1-byte object <79>");
4997 int Bar()
const {
return 1; }
5012 class FRIEND_TEST_Test2 :
public Test {
5029 class TestLifeCycleTest :
public Test {
5033 TestLifeCycleTest() { count_++; }
5037 ~TestLifeCycleTest() { count_--; }
5040 int count()
const {
return count_; }
5046 int TestLifeCycleTest::count_ = 0;
5049 TEST_F(TestLifeCycleTest, Test1) {
5056 TEST_F(TestLifeCycleTest, Test2) {
5067 TEST(AssertionResultTest, CopyConstructorWorksWhenNotOptimied) {
5077 EXPECT_EQ(static_cast<bool>(r3), static_cast<bool>(r1));
5083 TEST(AssertionResultTest, ConstructionWorks) {
5106 TEST(AssertionResultTest, NegationWorks) {
5116 TEST(AssertionResultTest, StreamingWorks) {
5118 r <<
"abc" <<
'd' << 0 <<
true;
5122 TEST(AssertionResultTest, CanStreamOstreamManipulators) {
5124 r <<
"Data" << std::endl << std::flush << std::ends <<
"Will be visible";
5129 #if GTEST_LANG_CXX11 5131 TEST(AssertionResultTest, ConstructibleFromContextuallyConvertibleToBool) {
5132 struct ExplicitlyConvertibleToBool {
5133 explicit operator bool()
const {
return value; }
5136 ExplicitlyConvertibleToBool v1 = {
false};
5137 ExplicitlyConvertibleToBool v2 = {
true};
5142 #endif // GTEST_LANG_CXX11 5148 TEST(AssertionResultTest, ConstructibleFromImplicitlyConvertible) {
5164 return os << val.x();
5167 const Base* pointer) {
5168 return os <<
"(" << pointer->x() <<
")";
5171 TEST(MessageTest, CanStreamUserTypeInGlobalNameSpace) {
5182 class MyTypeInUnnamedNameSpace :
public Base {
5184 explicit MyTypeInUnnamedNameSpace(
int an_x):
Base(an_x) {}
5187 const MyTypeInUnnamedNameSpace&
val) {
5188 return os << val.x();
5191 const MyTypeInUnnamedNameSpace* pointer) {
5192 return os <<
"(" << pointer->x() <<
")";
5196 TEST(MessageTest, CanStreamUserTypeInUnnamedNameSpace) {
5198 MyTypeInUnnamedNameSpace
a(1);
5213 return os << val.x();
5217 return os <<
"(" << pointer->x() <<
")";
5221 TEST(MessageTest, CanStreamUserTypeInUserNameSpace) {
5239 return os << val.x();
5243 return os <<
"(" << pointer->x() <<
")";
5246 TEST(MessageTest, CanStreamUserTypeInUserNameSpaceWithStreamOperatorInGlobal) {
5257 char*
const p1 = NULL;
5258 unsigned char*
const p2 = NULL;
5264 msg << p1 << p2 << p3 << p4 << p5 << p6;
5272 const wchar_t* const_wstr = NULL;
5274 (
Message() << const_wstr).GetString().c_str());
5277 wchar_t* wstr = NULL;
5279 (
Message() << wstr).GetString().c_str());
5282 const_wstr = L
"abc\x8119";
5284 (
Message() << const_wstr).GetString().c_str());
5287 wstr =
const_cast<wchar_t*
>(const_wstr);
5289 (
Message() << wstr).GetString().c_str());
5302 GetTestCase(
"TestInfoTest",
"", NULL, NULL);
5306 if (strcmp(test_name, test_info->
name()) == 0)
5314 return test_info->
result();
5320 const TestInfo*
const test_info = GetTestInfo(
"Names");
5328 const TestInfo*
const test_info = GetTestInfo(
"result");
5331 ASSERT_EQ(0, GetTestResult(test_info)->total_part_count());
5334 ASSERT_EQ(0, GetTestResult(test_info)->total_part_count());
5337 #define VERIFY_CODE_LOCATION \ 5338 const int expected_line = __LINE__ - 1; \ 5339 const TestInfo* const test_info = GetUnitTestImpl()->current_test_info(); \ 5340 ASSERT_TRUE(test_info); \ 5341 EXPECT_STREQ(__FILE__, test_info->file()); \ 5342 EXPECT_EQ(expected_line, test_info->line()) 5344 TEST(CodeLocationForTEST, Verify) {
5364 template <
typename T>
5374 template <
typename T>
5388 #undef VERIFY_CODE_LOCATION 5397 printf(
"Setting up the test case . . .\n");
5402 shared_resource_ =
"123";
5414 printf(
"Tearing down the test case . . .\n");
5423 shared_resource_ = NULL;
5458 Flags() : also_run_disabled_tests(false),
5459 break_on_failure(false),
5460 catch_exceptions(false),
5461 death_test_use_fork(false),
5470 stream_result_to(
""),
5471 throw_on_failure(false) {}
5626 template <
typename CharType>
5628 size_t size2, CharType** array2) {
5629 ASSERT_EQ(size1, size2) <<
" Array sizes different.";
5631 for (
size_t i = 0;
i != size1;
i++) {
5659 template <
typename CharType>
5661 int argc2,
const CharType** argv2,
5662 const Flags& expected,
bool should_print_help) {
5666 #if GTEST_HAS_STREAM_REDIRECTION 5673 #if GTEST_HAS_STREAM_REDIRECTION 5678 CheckFlags(expected);
5682 AssertStringArrayEq(argc1 + 1, argv1, argc2 + 1, argv2);
5688 #if GTEST_HAS_STREAM_REDIRECTION 5689 const char*
const expected_help_fragment =
5690 "This program contains tests written using";
5691 if (should_print_help) {
5695 expected_help_fragment, captured_stdout);
5697 #endif // GTEST_HAS_STREAM_REDIRECTION 5705 #define GTEST_TEST_PARSING_FLAGS_(argv1, argv2, expected, should_print_help) \ 5706 TestParsingFlags(sizeof(argv1)/sizeof(*argv1) - 1, argv1, \ 5707 sizeof(argv2)/sizeof(*argv2) - 1, argv2, \ 5708 expected, should_print_help) 5713 const char*
argv[] = {
5717 const char* argv2[] = {
5726 const char*
argv[] = {
5731 const char* argv2[] = {
5741 const char*
argv[] = {
5747 const char* argv2[] = {
5758 const char*
argv[] = {
5764 const char* argv2[] = {
5774 const char*
argv[] = {
5776 "--gtest_filter=abc",
5780 const char* argv2[] = {
5790 const char*
argv[] = {
5792 "--gtest_break_on_failure",
5796 const char* argv2[] = {
5806 const char*
argv[] = {
5808 "--gtest_break_on_failure=0",
5812 const char* argv2[] = {
5822 const char*
argv[] = {
5824 "--gtest_break_on_failure=f",
5828 const char* argv2[] = {
5838 const char*
argv[] = {
5840 "--gtest_break_on_failure=F",
5844 const char* argv2[] = {
5855 const char*
argv[] = {
5857 "--gtest_break_on_failure=1",
5861 const char* argv2[] = {
5871 const char*
argv[] = {
5873 "--gtest_catch_exceptions",
5877 const char* argv2[] = {
5887 const char*
argv[] = {
5889 "--gtest_death_test_use_fork",
5893 const char* argv2[] = {
5904 const char*
argv[] = {
5911 const char* argv2[] = {
5921 const char*
argv[] = {
5923 "--gtest_break_on_failure",
5929 const char* argv2[] = {
5943 const char*
argv[] = {
5945 "--gtest_list_tests",
5949 const char* argv2[] = {
5959 const char*
argv[] = {
5961 "--gtest_list_tests=1",
5965 const char* argv2[] = {
5975 const char*
argv[] = {
5977 "--gtest_list_tests=0",
5981 const char* argv2[] = {
5991 const char*
argv[] = {
5993 "--gtest_list_tests=f",
5997 const char* argv2[] = {
6007 const char*
argv[] = {
6009 "--gtest_list_tests=F",
6013 const char* argv2[] = {
6023 const char*
argv[] = {
6029 const char* argv2[] = {
6040 const char*
argv[] = {
6042 "--gtest_output=xml",
6046 const char* argv2[] = {
6056 const char*
argv[] = {
6058 "--gtest_output=xml:file",
6062 const char* argv2[] = {
6072 const char*
argv[] = {
6074 "--gtest_output=xml:directory/path/",
6078 const char* argv2[] = {
6089 const char*
argv[] = {
6091 "--gtest_print_time",
6095 const char* argv2[] = {
6105 const char*
argv[] = {
6107 "--gtest_print_time=1",
6111 const char* argv2[] = {
6121 const char*
argv[] = {
6123 "--gtest_print_time=0",
6127 const char* argv2[] = {
6137 const char*
argv[] = {
6139 "--gtest_print_time=f",
6143 const char* argv2[] = {
6153 const char*
argv[] = {
6155 "--gtest_print_time=F",
6159 const char* argv2[] = {
6169 const char*
argv[] = {
6171 "--gtest_random_seed=1000",
6175 const char* argv2[] = {
6185 const char*
argv[] = {
6187 "--gtest_repeat=1000",
6191 const char* argv2[] = {
6201 const char*
argv[] = {
6203 "--gtest_also_run_disabled_tests",
6207 const char* argv2[] = {
6218 const char*
argv[] = {
6220 "--gtest_also_run_disabled_tests=1",
6224 const char* argv2[] = {
6235 const char*
argv[] = {
6237 "--gtest_also_run_disabled_tests=0",
6241 const char* argv2[] = {
6252 const char*
argv[] = {
6258 const char* argv2[] = {
6268 const char*
argv[] = {
6270 "--gtest_shuffle=0",
6274 const char* argv2[] = {
6285 const char*
argv[] = {
6287 "--gtest_shuffle=1",
6291 const char* argv2[] = {
6301 const char*
argv[] = {
6303 "--gtest_stack_trace_depth=5",
6307 const char* argv2[] = {
6316 const char*
argv[] = {
6318 "--gtest_stream_result_to=localhost:1234",
6322 const char* argv2[] = {
6333 const char*
argv[] = {
6335 "--gtest_throw_on_failure",
6339 const char* argv2[] = {
6349 const char*
argv[] = {
6351 "--gtest_throw_on_failure=0",
6355 const char* argv2[] = {
6366 const char*
argv[] = {
6368 "--gtest_throw_on_failure=1",
6372 const char* argv2[] = {
6380 #if GTEST_OS_WINDOWS 6383 const wchar_t*
argv[] = {
6385 L
"--gtest_filter=Foo*",
6386 L
"--gtest_list_tests=1",
6387 L
"--gtest_break_on_failure",
6388 L
"--non_gtest_flag",
6392 const wchar_t* argv2[] = {
6394 L
"--non_gtest_flag",
6398 Flags expected_flags;
6400 expected_flags.
filter =
"Foo*";
6405 # endif // GTEST_OS_WINDOWS 6407 #if GTEST_USE_OWN_FLAGFILE_FLAG_ 6410 virtual void SetUp() {
6420 virtual void TearDown() {
6429 fprintf(f,
"%s", contents);
6439 TEST_F(FlagfileTest, Empty) {
6444 const char*
argv[] = {
6446 flagfile_flag.c_str(),
6450 const char* argv2[] = {
6459 TEST_F(FlagfileTest, FilterNonEmpty) {
6465 const char*
argv[] = {
6467 flagfile_flag.c_str(),
6471 const char* argv2[] = {
6480 TEST_F(FlagfileTest, SeveralFlags) {
6488 const char*
argv[] = {
6490 flagfile_flag.c_str(),
6494 const char* argv2[] = {
6499 Flags expected_flags;
6501 expected_flags.
filter =
"abc";
6506 #endif // GTEST_USE_OWN_FLAGFILE_FLAG_ 6518 <<
"There should be no tests running at this point.";
6527 <<
"There should be no tests running at this point.";
6537 <<
"There is a test running so we should have a valid TestInfo.";
6539 <<
"Expected the name of the currently running test case.";
6541 <<
"Expected the name of the currently running test.";
6552 <<
"There is a test running so we should have a valid TestInfo.";
6554 <<
"Expected the name of the currently running test case.";
6556 <<
"Expected the name of the currently running test.";
6580 TEST(NestedTestingNamespaceTest, Success) {
6581 EXPECT_EQ(1, 1) <<
"This shouldn't fail.";
6585 TEST(NestedTestingNamespaceTest, Failure) {
6587 "This failure is expected.");
6609 TEST(StreamingAssertionsTest, Unconditional) {
6610 SUCCEED() <<
"expected success";
6612 "expected failure");
6614 "expected failure");
6619 # pragma option push -w-ccc -w-rch 6622 TEST(StreamingAssertionsTest, Truth) {
6626 "expected failure");
6628 "expected failure");
6631 TEST(StreamingAssertionsTest, Truth2) {
6635 "expected failure");
6637 "expected failure");
6645 TEST(StreamingAssertionsTest, IntegerEquals) {
6646 EXPECT_EQ(1, 1) <<
"unexpected failure";
6647 ASSERT_EQ(1, 1) <<
"unexpected failure";
6649 "expected failure");
6651 "expected failure");
6654 TEST(StreamingAssertionsTest, IntegerLessThan) {
6655 EXPECT_LT(1, 2) <<
"unexpected failure";
6656 ASSERT_LT(1, 2) <<
"unexpected failure";
6658 "expected failure");
6660 "expected failure");
6663 TEST(StreamingAssertionsTest, StringsEqual) {
6667 "expected failure");
6669 "expected failure");
6672 TEST(StreamingAssertionsTest, StringsNotEqual) {
6676 "expected failure");
6678 "expected failure");
6681 TEST(StreamingAssertionsTest, StringsEqualIgnoringCase) {
6685 "expected failure");
6687 "expected failure");
6690 TEST(StreamingAssertionsTest, StringNotEqualIgnoringCase) {
6694 "expected failure");
6696 "expected failure");
6699 TEST(StreamingAssertionsTest, FloatingPointEquals) {
6703 "expected failure");
6705 "expected failure");
6708 #if GTEST_HAS_EXCEPTIONS 6710 TEST(StreamingAssertionsTest, Throw) {
6711 EXPECT_THROW(ThrowAnInteger(),
int) <<
"unexpected failure";
6712 ASSERT_THROW(ThrowAnInteger(),
int) <<
"unexpected failure";
6714 "expected failure",
"expected failure");
6716 "expected failure",
"expected failure");
6719 TEST(StreamingAssertionsTest, NoThrow) {
6723 "expected failure",
"expected failure");
6725 "expected failure",
"expected failure");
6728 TEST(StreamingAssertionsTest, AnyThrow) {
6732 "expected failure",
"expected failure");
6734 "expected failure",
"expected failure");
6737 #endif // GTEST_HAS_EXCEPTIONS 6741 TEST(ColoredOutputTest, UsesColorsWhenGTestColorFlagIsYes) {
6744 SetEnv(
"TERM",
"xterm");
6748 SetEnv(
"TERM",
"dumb");
6753 TEST(ColoredOutputTest, UsesColorsWhenGTestColorFlagIsAliasOfYes) {
6754 SetEnv(
"TERM",
"dumb");
6766 TEST(ColoredOutputTest, UsesNoColorWhenGTestColorFlagIsNo) {
6769 SetEnv(
"TERM",
"xterm");
6773 SetEnv(
"TERM",
"dumb");
6778 TEST(ColoredOutputTest, UsesNoColorWhenGTestColorFlagIsInvalid) {
6779 SetEnv(
"TERM",
"xterm");
6791 TEST(ColoredOutputTest, UsesColorsWhenStdoutIsTty) {
6794 SetEnv(
"TERM",
"xterm");
6799 TEST(ColoredOutputTest, UsesColorsWhenTermSupportsColors) {
6802 #if GTEST_OS_WINDOWS 6805 SetEnv(
"TERM",
"dumb");
6811 SetEnv(
"TERM",
"xterm");
6817 SetEnv(
"TERM",
"dumb");
6820 SetEnv(
"TERM",
"emacs");
6823 SetEnv(
"TERM",
"vt100");
6826 SetEnv(
"TERM",
"xterm-mono");
6829 SetEnv(
"TERM",
"xterm");
6832 SetEnv(
"TERM",
"xterm-color");
6835 SetEnv(
"TERM",
"xterm-256color");
6838 SetEnv(
"TERM",
"screen");
6841 SetEnv(
"TERM",
"screen-256color");
6844 SetEnv(
"TERM",
"tmux");
6847 SetEnv(
"TERM",
"tmux-256color");
6850 SetEnv(
"TERM",
"rxvt-unicode");
6853 SetEnv(
"TERM",
"rxvt-unicode-256color");
6856 SetEnv(
"TERM",
"linux");
6859 SetEnv(
"TERM",
"cygwin");
6861 #endif // GTEST_OS_WINDOWS 6868 StaticAssertTypeEq<const int, const int>();
6872 template <
typename T>
6878 TEST(StaticAssertTypeEqTest, WorksInClass) {
6886 TEST(StaticAssertTypeEqTest, CompilesForEqualTypes) {
6887 StaticAssertTypeEq<int, IntAlias>();
6888 StaticAssertTypeEq<int*, IntAlias*>();
6891 TEST(GetCurrentOsStackTraceExceptTopTest, ReturnsTheStackTrace) {
6899 TEST(HasNonfatalFailureTest, ReturnsFalseWhenThereIsNoFailure) {
6905 TEST(HasNonfatalFailureTest, ReturnsFalseWhenThereIsOnlyFatalFailure) {
6907 const bool has_nonfatal_failure = HasNonfatalFailure();
6908 ClearCurrentTestPartResults();
6912 TEST(HasNonfatalFailureTest, ReturnsTrueWhenThereIsNonfatalFailure) {
6914 const bool has_nonfatal_failure = HasNonfatalFailure();
6915 ClearCurrentTestPartResults();
6919 TEST(HasNonfatalFailureTest, ReturnsTrueWhenThereAreFatalAndNonfatalFailures) {
6922 const bool has_nonfatal_failure = HasNonfatalFailure();
6923 ClearCurrentTestPartResults();
6932 TEST(HasNonfatalFailureTest, WorksOutsideOfTestBody) {
6936 TEST(HasNonfatalFailureTest, WorksOutsideOfTestBody2) {
6939 ClearCurrentTestPartResults();
6943 TEST(HasFailureTest, ReturnsFalseWhenThereIsNoFailure) {
6947 TEST(HasFailureTest, ReturnsTrueWhenThereIsFatalFailure) {
6949 const bool has_failure = HasFailure();
6950 ClearCurrentTestPartResults();
6954 TEST(HasFailureTest, ReturnsTrueWhenThereIsNonfatalFailure) {
6956 const bool has_failure = HasFailure();
6957 ClearCurrentTestPartResults();
6961 TEST(HasFailureTest, ReturnsTrueWhenThereAreFatalAndNonfatalFailures) {
6964 const bool has_failure = HasFailure();
6965 ClearCurrentTestPartResults();
6972 TEST(HasFailureTest, WorksOutsideOfTestBody) {
6976 TEST(HasFailureTest, WorksOutsideOfTestBody2) {
6979 ClearCurrentTestPartResults();
6987 : on_start_counter_(on_start_counter),
6988 is_destroyed_(is_destroyed) {}
6992 *is_destroyed_ =
true;
6997 if (on_start_counter_ != NULL)
6998 (*on_start_counter_)++;
7007 TEST(TestEventListenersTest, ConstructionWorks) {
7017 TEST(TestEventListenersTest, DestructionWorks) {
7018 bool default_result_printer_is_destroyed =
false;
7019 bool default_xml_printer_is_destroyed =
false;
7020 bool extra_listener_is_destroyed =
false;
7022 NULL, &default_result_printer_is_destroyed);
7024 NULL, &default_xml_printer_is_destroyed);
7026 NULL, &extra_listener_is_destroyed);
7031 default_result_printer);
7033 default_xml_printer);
7034 listeners.
Append(extra_listener);
7043 TEST(TestEventListenersTest, Append) {
7044 int on_start_counter = 0;
7045 bool is_destroyed =
false;
7049 listeners.
Append(listener);
7063 : vector_(vector), id_(id) {}
7067 vector_->push_back(GetEventDescription(
"OnTestProgramStart"));
7071 vector_->push_back(GetEventDescription(
"OnTestProgramEnd"));
7076 vector_->push_back(GetEventDescription(
"OnTestIterationStart"));
7081 vector_->push_back(GetEventDescription(
"OnTestIterationEnd"));
7087 message << id_ <<
"." << method;
7097 TEST(EventListenerTest, AppendKeepsOrder) {
7098 std::vector<std::string>
vec;
7107 EXPECT_STREQ(
"1st.OnTestProgramStart", vec[0].c_str());
7108 EXPECT_STREQ(
"2nd.OnTestProgramStart", vec[1].c_str());
7109 EXPECT_STREQ(
"3rd.OnTestProgramStart", vec[2].c_str());
7123 EXPECT_STREQ(
"1st.OnTestIterationStart", vec[0].c_str());
7124 EXPECT_STREQ(
"2nd.OnTestIterationStart", vec[1].c_str());
7125 EXPECT_STREQ(
"3rd.OnTestIterationStart", vec[2].c_str());
7131 EXPECT_STREQ(
"3rd.OnTestIterationEnd", vec[0].c_str());
7132 EXPECT_STREQ(
"2nd.OnTestIterationEnd", vec[1].c_str());
7133 EXPECT_STREQ(
"1st.OnTestIterationEnd", vec[2].c_str());
7138 TEST(TestEventListenersTest, Release) {
7139 int on_start_counter = 0;
7140 bool is_destroyed =
false;
7147 listeners.
Append(listener);
7159 TEST(EventListenerTest, SuppressEventForwarding) {
7160 int on_start_counter = 0;
7164 listeners.
Append(listener);
7175 TEST(EventListenerDeathTest, EventsNotForwardedInDeathTestSubprecesses) {
7179 "expected failure");
7185 TEST(EventListenerTest, default_result_printer) {
7186 int on_start_counter = 0;
7187 bool is_destroyed =
false;
7216 TEST(EventListenerTest, RemovingDefaultResultPrinterWorks) {
7217 int on_start_counter = 0;
7218 bool is_destroyed =
false;
7244 TEST(EventListenerTest, default_xml_generator) {
7245 int on_start_counter = 0;
7246 bool is_destroyed =
false;
7275 TEST(EventListenerTest, RemovingDefaultXmlGeneratorWorks) {
7276 int on_start_counter = 0;
7277 bool is_destroyed =
false;
7310 "An expected failure");
7316 "An expected failure");
7318 "An expected failure");
7323 "An expected failure");
7328 "An expected failure");
7332 "An expected failure");
7334 "An expected failure");
7339 "An expected failure");
7343 "An expected failure");
7345 "An expected failure");
7356 TEST(IsAProtocolMessageTest, ValueIsCompileTimeConstant) {
7364 TEST(IsAProtocolMessageTest, ValueIsTrueWhenTypeIsAProtocolMessage) {
7371 TEST(IsAProtocolMessageTest, ValueIsFalseWhenTypeIsNotAProtocolMessage) {
7384 TEST(RemoveReferenceTest, DoesNotAffectNonReferenceType) {
7390 TEST(RemoveReferenceTest, RemovesReference) {
7397 template <
typename T1,
typename T2>
7402 TEST(RemoveReferenceTest, MacroVersion) {
7403 TestGTestRemoveReference<int, int>();
7404 TestGTestRemoveReference<const char, const char&>();
7409 TEST(RemoveConstTest, DoesNotAffectNonConstType) {
7415 TEST(RemoveConstTest, RemovesConst) {
7423 template <
typename T1,
typename T2>
7428 TEST(RemoveConstTest, MacroVersion) {
7429 TestGTestRemoveConst<int, int>();
7430 TestGTestRemoveConst<double&, double&>();
7431 TestGTestRemoveConst<char, const char>();
7436 template <
typename T1,
typename T2>
7441 TEST(RemoveReferenceToConstTest, Works) {
7442 TestGTestRemoveReferenceAndConst<int, int>();
7443 TestGTestRemoveReferenceAndConst<double, double&>();
7444 TestGTestRemoveReferenceAndConst<char, const char>();
7445 TestGTestRemoveReferenceAndConst<char, const char&>();
7446 TestGTestRemoveReferenceAndConst<const char*, const char*>();
7450 TEST(AddReferenceTest, DoesNotAffectReferenceType) {
7456 TEST(AddReferenceTest, AddsReference) {
7463 template <
typename T1,
typename T2>
7468 TEST(AddReferenceTest, MacroVersion) {
7469 TestGTestAddReference<int&, int>();
7470 TestGTestAddReference<const char&, const char&>();
7475 template <
typename T1,
typename T2>
7480 TEST(GTestReferenceToConstTest, Works) {
7481 TestGTestReferenceToConst<const char&, char>();
7482 TestGTestReferenceToConst<const int&, const int>();
7483 TestGTestReferenceToConst<const double&, double>();
7484 TestGTestReferenceToConst<const std::string&, const std::string&>();
7488 TEST(ImplicitlyConvertibleTest, ValueIsCompileTimeConstant) {
7496 TEST(ImplicitlyConvertibleTest, ValueIsTrueWhenConvertible) {
7509 TEST(ImplicitlyConvertibleTest, ValueIsFalseWhenNotConvertible) {
7521 TEST(IsContainerTestTest, WorksForNonContainer) {
7527 TEST(IsContainerTestTest, WorksForContainer) {
7536 TEST(ArrayEqTest, WorksForDegeneratedArrays) {
7541 TEST(ArrayEqTest, WorksForOneDimensionalArrays) {
7543 const int a[] = { 0, 1 };
7544 long b[] = { 0, 1 };
7553 TEST(ArrayEqTest, WorksForTwoDimensionalArrays) {
7554 const char a[][3] = {
"hi",
"lo" };
7555 const char b[][3] = {
"hi",
"lo" };
7556 const char c[][3] = {
"hi",
"li" };
7567 TEST(ArrayAwareFindTest, WorksForOneDimensionalArray) {
7568 const char a[] =
"hello";
7573 TEST(ArrayAwareFindTest, WorksForTwoDimensionalArray) {
7574 int a[][2] = { { 0, 1 }, { 2, 3 }, { 4, 5 } };
7575 const int b[2] = { 2, 3 };
7578 const int c[2] = { 6, 7 };
7584 TEST(CopyArrayTest, WorksForDegeneratedArrays) {
7590 TEST(CopyArrayTest, WorksForOneDimensionalArrays) {
7591 const char a[3] =
"hi";
7593 #ifndef __BORLANDC__ // C++Builder cannot compile some array size deductions. 7603 TEST(CopyArrayTest, WorksForTwoDimensionalArrays) {
7604 const int a[2][3] = { { 0, 1, 2 }, { 3, 4, 5 } };
7606 #ifndef __BORLANDC__ // C++Builder cannot compile some array size deductions. 7618 TEST(NativeArrayTest, ConstructorFromArrayWorks) {
7619 const int a[3] = { 0, 1, 2 };
7625 TEST(NativeArrayTest, CreatesAndDeletesCopyOfArrayWhenAskedTo) {
7626 typedef int Array[2];
7627 Array*
a =
new Array[1];
7640 TEST(NativeArrayTest, TypeMembersAreCorrect) {
7641 StaticAssertTypeEq<char, NativeArray<char>::value_type>();
7642 StaticAssertTypeEq<int[2], NativeArray<int[2]>::value_type>();
7644 StaticAssertTypeEq<const char*, NativeArray<char>::const_iterator>();
7645 StaticAssertTypeEq<const bool(*)[2], NativeArray<bool[2]>::const_iterator>();
7648 TEST(NativeArrayTest, MethodsWork) {
7649 const int a[3] = { 0, 1, 2 };
7668 const int b1[3] = { 0, 1, 1 };
7669 const int b2[4] = { 0, 1, 2, 3 };
7674 TEST(NativeArrayTest, WorksForTwoDimensionalArray) {
7675 const char a[2][3] = {
"hi",
"lo" };
7683 TEST(SkipPrefixTest, SkipsWhenPrefixMatches) {
7684 const char*
const str =
"hello";
7686 const char* p = str;
7695 TEST(SkipPrefixTest, DoesNotSkipWhenPrefixDoesNotMatch) {
7696 const char*
const str =
"world";
7698 const char* p = str;
#define EXPECT_PRED3(pred, v1, v2, v3)
static bool HasNonfatalFailureHelper()
GTEST_API_ bool g_help_flag
#define EXPECT_LE(val1, val2)
void SetDefaultResultPrinter(TestEventListener *listener)
INSTANTIATE_TEST_CASE_P(, CodeLocationForTESTP, Values(0))
#define GTEST_FLAG_PREFIX_
#define ASSERT_GE(val1, val2)
#define EXPECT_ANY_THROW(statement)
class UnitTestImpl * GetUnitTestImpl()
Matcher< int > GreaterThan(int n)
#define ASSERT_GT(val1, val2)
bool operator>(const Expected< Value, Error > &lhs, const Expected< Value, Error > &rhs)
Int32 Int32FromGTestEnv(const char *flag, Int32 default_val)
static const char * shared_resource_
static const std::vector< testing::TestPartResult > & test_part_results(const TestResult &test_result)
bool fatally_failed() const
int GetRandomSeedFromFlag(Int32 random_seed_flag)
static void SuppressEventForwarding(TestEventListeners *listeners)
TYPED_TEST(CodeLocationForTYPEDTEST, Verify)
#define EXPECT_PRED_FORMAT2(pred_format, v1, v2)
Integral2 random(Integral1 low, Integral2 up)
#define ASSERT_NEAR(val1, val2, abs_error)
#define ASSERT_STREQ(s1, s2)
const char * summary() const
std::atomic< int64_t > sum(0)
GTEST_API_ std::string GetCurrentOsStackTraceExceptTop(UnitTest *unit_test, int skip_count)
GTEST_API_ std::string FormatEpochTimeInMillisAsIso8601(TimeInMillis ms)
E GetElementOr(const std::vector< E > &v, int i, E default_value)
TYPED_TEST_CASE(CodeLocationForTYPEDTEST, int)
TYPED_TEST_CASE_P(CodeLocationForTYPEDTESTP)
static Flags DeathTestUseFork(bool death_test_use_fork)
GTEST_API_ AssertionResult AssertionFailure()
#define EXPECT_NO_THROW(statement)
PUSHMI_INLINE_VAR constexpr detail::filter_fn filter
#define EXPECT_THROW(statement, expected_exception)
const TestInfo * GetTestInfo(int i) const
static void SetUpTestCase()
#define EXPECT_STRCASENE(s1, s2)
#define ASSERT_EQ(val1, val2)
static bool HasFailureHelper()
GTEST_API_ std::vector< EditType > CalculateOptimalEdits(const std::vector< size_t > &left, const std::vector< size_t > &right)
#define ASSERT_PRED_FORMAT1(pred_format, v1)
TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded)
static Flags StackTraceDepth(Int32 stack_trace_depth)
Environment * AddGlobalTestEnvironment(Environment *env)
#define GTEST_USE_UNPROTECTED_COMMA_
#define ASSERT_LT(val1, val2)
class GTEST_API_ testing::internal::ScopedTrace GTEST_ATTRIBUTE_UNUSED_
static Flags Output(const char *output)
TypeWithSize< 4 >::Int Int32
FILE * FOpen(const char *path, const char *mode)
const char * message() const
int GetNextRandomSeed(int seed)
StaticAssertTypeEqTestHelper()
static const TestResult * GetTestResult(const TestInfo *test_info)
static bool EndsWithCaseInsensitive(const std::string &str, const std::string &suffix)
static void FailFatally()
GTEST_API_ bool ShouldUseColor(bool stdout_is_tty)
static const UInt32 kMaxRange
TypeWithSize< 4 >::UInt UInt32
#define EXPECT_EQ(val1, val2)
TestEventListener * Release(TestEventListener *listener)
GTEST_API_ bool ShouldRunTestOnShard(int total_shards, int shard_index, int test_id)
REGISTER_TYPED_TEST_CASE_P(CodeLocationForTYPEDTESTP, Verify)
virtual void OnTestProgramStart(const UnitTest &)
MyTypeInNameSpace2(int an_x)
TestEventListener * repeater()
#define ASSERT_STRCASEEQ(s1, s2)
void SuppressEventForwarding()
virtual void OnTestIterationStart(const UnitTest &unit_test, int iteration)=0
bool operator==(T *ptr, const linked_ptr< T > &x)
static Flags BreakOnFailure(bool break_on_failure)
#define EXPECT_FATAL_FAILURE_ON_ALL_THREADS(statement, substr)
#define EXPECT_PRED1(pred, v1)
#define ASSERT_LE(val1, val2)
auto begin(TestAdlIterable &instance)
static TestEventListener * GetRepeater(TestEventListeners *listeners)
const_iterator begin() const
TestEventListener * default_xml_generator() const
std::ostream & operator<<(std::ostream &os, const Message &sb)
#define EXPECT_STRCASEEQ(s1, s2)
GTEST_API_ bool SkipPrefix(const char *prefix, const char **pstr)
GTEST_API_ std::string FormatTimeInMillisAsSeconds(TimeInMillis ms)
static const TestInfo * GetTestInfo(const char *test_name)
static Flags AlsoRunDisabledTests(bool also_run_disabled_tests)
#define ASSERT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5)
const TestProperty & GetTestProperty(int i) const
static Flags StreamResultTo(const char *stream_result_to)
const char * stream_result_to
#define GTEST_TEST_PARSING_FLAGS_(argv1, argv2, expected, should_print_help)
void Append(TestEventListener *listener)
static void ClearTestPartResults(TestResult *test_result)
GTEST_API_ bool ShouldShard(const char *total_shards_str, const char *shard_index_str, bool in_subprocess_for_death_test)
#define ASSERT_PRED3(pred, v1, v2, v3)
#define EXPECT_STRNE(s1, s2)
GTEST_API_ std::string CodePointToUtf8(UInt32 code_point)
#define GTEST_COMPILE_ASSERT_(expr, msg)
#define GTEST_ASSERT_EQ(val1, val2)
#define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
#define EXPECT_GE(val1, val2)
int total_test_count() const
static void CheckFlags(const Flags &expected)
TEST_P(CodeLocationForTESTP, Verify)
std::string StreamableToString(const T &streamable)
static void TestParsingFlags(int argc1, const CharType **argv1, int argc2, const CharType **argv2, const Flags &expected, bool should_print_help)
static void SetDefaultXmlGenerator(TestEventListeners *listeners, TestEventListener *listener)
internal::TimeInMillis TimeInMillis
UnitTestRecordPropertyTestHelper()
FOLLY_PUSH_WARNING RHS rhs
static bool EventForwardingEnabled(const TestEventListeners &listeners)
#define EXPECT_FLOAT_EQ(val1, val2)
bool ArrayEq(const T *lhs, size_t size, const U *rhs)
#define EXPECT_PRED_FORMAT1(pred_format, v1)
TEST_F(ListenerTest, DoesFoo)
#define ASSERT_DOUBLE_EQ(val1, val2)
#define EXPECT_STREQ(s1, s2)
GTEST_API_ TypeId GetTestTypeId()
#define ASSERT_FLOAT_EQ(val1, val2)
const char * name() const
virtual void OnTestIterationEnd(const UnitTest &unit_test, int iteration)=0
virtual void OnTestProgramEnd(const UnitTest &unit_test)=0
#define GTEST_ASSERT_LT(val1, val2)
const char * message() const
GTEST_API_ AssertionResult AssertionSuccess()
int RmDir(const char *dir)
TestListener(int *on_start_counter, bool *is_destroyed)
static void SetUpTestCase()
static bool CaseInsensitiveWideCStringEquals(const wchar_t *lhs, const wchar_t *rhs)
virtual void OnTestProgramStart(const UnitTest &)
void SetDefaultXmlGenerator(TestEventListener *listener)
const int kMaxStackTraceDepth
bool also_run_disabled_tests
#define GTEST_ASSERT_GE(val1, val2)
std::vector< std::string > * vector_
#define ADD_FAILURE_AT(file, line)
#define GTEST_CHECK_(condition)
GTEST_API_ const TypeId kTestTypeIdInGoogleTest
auto end(TestAdlIterable &instance)
def AlsoRunDisabledTestsFlag()
static void RecordProperty(TestResult *test_result, const std::string &xml_element, const TestProperty &property)
GTEST_API_ bool AlwaysTrue()
const char * file_name() const
void repeat(F const &func)
static void TearDownTestCase()
void UnitTestRecordProperty(const char *key, const std::string &value)
AtomicCounter< T, DeterministicAtomic > Base
#define ASSERT_STRCASENE(s1, s2)
static void SetDefaultResultPrinter(TestEventListeners *listeners, TestEventListener *listener)
void TestGTestRemoveReferenceAndConst()
#define GTEST_FLAG_PREFIX_UPPER_
std::string GetString() const
void TestGTestAddReference()
GTEST_API_ AssertionResult IsSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
GTEST_API_ FilePath GetCurrentExecutableName()
const char * c_str() const
GTEST_API_ TimeInMillis GetTimeInMillis()
#define EXPECT_FATAL_FAILURE(statement, substr)
MyTypeInNameSpace1(int an_x)
TYPED_TEST_P(CodeLocationForTYPEDTESTP, Verify)
static const char *const value
const char * test_case_name() const
#define ASSERT_ANY_THROW(statement)
#define VERIFY_CODE_LOCATION
const TestPartResult & GetTestPartResult(int index) const
#define ASSERT_THROW(statement, expected_exception)
const TestInfo * current_test_info() const GTEST_LOCK_EXCLUDED_(mutex_)
static void AssertStringArrayEq(size_t size1, CharType **array1, size_t size2, CharType **array2)
static FilePath GenerateUniqueFileName(const FilePath &directory, const FilePath &base_name, const char *extension)
#define ASSERT_PRED2(pred, v1, v2)
GTEST_API_ std::string WideStringToUtf8(const wchar_t *str, int num_chars)
bool EventForwardingEnabled() const
static Flags Shuffle(bool shuffle)
#define EXPECT_PRED2(pred, v1, v2)
const TestResult & ad_hoc_test_result() const
#define GTEST_ASSERT_GT(val1, val2)
int test_property_count() const
void ShuffleRange(internal::Random *random, int begin, int end, std::vector< E > *v)
GTEST_API_ std::string AppendUserMessage(const std::string >est_msg, const Message &user_msg)
bool operator>=(const Expected< Value, Error > &lhs, const Expected< Value, Error > &rhs)
virtual void OnTestIterationStart(const UnitTest &, int)
#define EXPECT_NEAR(val1, val2, abs_error)
#define EXPECT_TRUE(condition)
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)
#define GTEST_ASSERT_LE(val1, val2)
void TestGTestRemoveConst()
int CountIf(const Container &c, Predicate predicate)
static Flags ThrowOnFailure(bool throw_on_failure)
virtual void OnTestProgramEnd(const UnitTest &)
static Flags Filter(const char *filter)
#define EXPECT_DOUBLE_EQ(val1, val2)
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)
FloatingPointTest< double > DoubleTest
const Bits & bits() const
INSTANTIATE_TYPED_TEST_CASE_P(My, CodeLocationForTYPEDTESTP, int)
GTEST_API_ void ParseGoogleTestFlagsOnly(int *argc, char **argv)
void Shuffle(internal::Random *random, std::vector< E > *v)
bool operator<=(const Expected< Value, Error > &lhs, const Expected< Value, Error > &rhs)
GTEST_API_ std::string CreateUnifiedDiff(const std::vector< std::string > &left, const std::vector< std::string > &right, size_t context=2)
virtual void OnTestIterationEnd(const UnitTest &, int)
#define GTEST_DISABLE_MSC_WARNINGS_POP_()
#define ASSERT_PRED_FORMAT4(pred_format, v1, v2, v3, v4)
#define EXPECT_NE(val1, val2)
GTEST_TEST(AlternativeNameTest, Works)
std::string GetEventDescription(const char *method)
const_iterator end() const
#define EXPECT_NONFATAL_FAILURE(statement, substr)
#define ASSERT_PRED_FORMAT2(pred_format, v1, v2)
#define EXPECT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5)
#define ASSERT_STRNE(s1, s2)
bool StaticAssertTypeEq()
FloatingPointTest< float > FloatTest
#define EXPECT_PRED_FORMAT4(pred_format, v1, v2, v3, v4)
virtual void OnTestProgramStart(const UnitTest &unit_test)=0
GTEST_API_ AssertionResult DoubleLE(const char *expr1, const char *expr2, double val1, double val2)
std::string GetCapturedStdout()
#define ASSERT_PRED1(pred, v1)
#define EXPECT_NO_FATAL_FAILURE(statement)
#define ASSERT_NO_FATAL_FAILURE(statement)
const TestResult * result() const
void CopyArray(const T *from, size_t size, U *to)
GTEST_API_ AssertionResult IsNotSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
#define ASSERT_NE(val1, val2)
static UnitTest * GetInstance()
#define ASSERT_FALSE(condition)
folly::detail::CompressionCounter * counter_
TestEventListener * default_result_printer() const
#define EXPECT_FALSE(condition)
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
static void TearDownTestCase()
Iter ArrayAwareFind(Iter begin, Iter end, const Element &elem)
static Flags CatchExceptions(bool catch_exceptions)
TypeWithSize< 8 >::Int TimeInMillis
#define EXPECT_LT(val1, val2)
UInt32 Generate(UInt32 range)
bool operator!=(T *ptr, const linked_ptr< T > &x)
void ForEach(const Container &c, Functor functor)
bool nonfatally_failed() const
static void RecordProperty(const std::string &key, const std::string &value)
static Flags Repeat(Int32 repeat)
const char * value() const
GTEST_API_ Int32 Int32FromEnvOrDie(const char *env_var, Int32 default_val)
const BiggestInt kMaxBiggestInt
#define FRIEND_TEST(test_case_name, test_name)
SequenceTestingListener(std::vector< std::string > *vector, const char *id)
#define ASSERT_NO_THROW(statement)
static Flags ListTests(bool list_tests)
#define ASSERT_TRUE(condition)
static std::string ShowWideCString(const wchar_t *wide_c_str)
IsContainer IsContainerTest(int, typename C::iterator *=NULL, typename C::const_iterator *=NULL)
static Flags RandomSeed(Int32 random_seed)
const TestCase * current_test_case() const GTEST_LOCK_EXCLUDED_(mutex_)
void TestGTestRemoveReference()
GMockOutputTest ExpectedCall FILE
static bool HasNonfatalFailure()
std::enable_if< IsLessThanComparable< Value >::value, bool >::type operator<(const Expected< Value, Error > &lhs, const Expected< Value, Error > &rhs)
#define GTEST_IS_NULL_LITERAL_(x)
#define GTEST_ASSERT_NE(val1, val2)
GTEST_API_ bool ParseInt32Flag(const char *str, const char *flag, Int32 *value)
std::vector< int > values(1'000)
void TestGTestReferenceToConst()
#define EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(statement, substr)
TEST(IsXDigitTest, WorksForNarrowAscii)
static Flags PrintTime(bool print_time)
GTEST_API_ AssertionResult FloatLE(const char *expr1, const char *expr2, float val1, float val2)
#define EXPECT_GT(val1, val2)