40 TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) {
75 #define GTEST_IMPLEMENTATION_ 1 77 #undef GTEST_IMPLEMENTATION_ 82 #if GTEST_CAN_STREAM_RESULTS_ 84 class StreamingListenerTest :
public Test {
86 class FakeSocketWriter :
public StreamingListener::AbstractSocketWriter {
89 virtual void Send(
const string& message) { output_ += message; }
94 StreamingListenerTest()
95 : fake_sock_writer_(
new FakeSocketWriter),
96 streamer_(fake_sock_writer_),
97 test_info_obj_(
"FooTest",
"Bar", NULL, NULL, 0, NULL) {}
100 string*
output() {
return &(fake_sock_writer_->output_); }
102 FakeSocketWriter*
const fake_sock_writer_;
103 StreamingListener streamer_;
108 TEST_F(StreamingListenerTest, OnTestProgramEnd) {
110 streamer_.OnTestProgramEnd(unit_test_);
114 TEST_F(StreamingListenerTest, OnTestIterationEnd) {
116 streamer_.OnTestIterationEnd(unit_test_, 42);
117 EXPECT_EQ(
"event=TestIterationEnd&passed=1&elapsed_time=0ms\n", *
output());
120 TEST_F(StreamingListenerTest, OnTestCaseStart) {
122 streamer_.OnTestCaseStart(
TestCase(
"FooTest",
"Bar", NULL, NULL));
126 TEST_F(StreamingListenerTest, OnTestCaseEnd) {
128 streamer_.OnTestCaseEnd(
TestCase(
"FooTest",
"Bar", NULL, NULL));
132 TEST_F(StreamingListenerTest, OnTestStart) {
134 streamer_.OnTestStart(test_info_obj_);
138 TEST_F(StreamingListenerTest, OnTestEnd) {
140 streamer_.OnTestEnd(test_info_obj_);
144 TEST_F(StreamingListenerTest, OnTestPartResult) {
151 "event=TestPartResult&file=foo.cc&line=42&message=failed%3D%0A%26%25\n",
155 #endif // GTEST_CAN_STREAM_RESULTS_ 189 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() {
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);
863 static bool RangeIsShuffled(
const TestingVector& vector,
int begin,
int end) {
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) {
1523 class GTestFlagSaverTest :
public Test {
1528 static void SetUpTestCase() {
1550 static void TearDownTestCase() {
1557 void VerifyAndModifyFlags() {
1587 GTEST_FLAG(stream_result_to) =
"localhost:1234";
1602 TEST_F(GTestFlagSaverTest, ModifyGTestFlags) {
1603 VerifyAndModifyFlags();
1608 TEST_F(GTestFlagSaverTest, VerifyGTestFlags) {
1609 VerifyAndModifyFlags();
1615 static void SetEnv(
const char*
name,
const char*
value) {
1616 #if GTEST_OS_WINDOWS_MOBILE 1619 #elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9) 1623 static std::map<std::string, std::string*> added_env;
1628 if (added_env.find(name) != added_env.end()) {
1629 prev_env = added_env[
name];
1632 (
Message() << name <<
"=" << value).GetString());
1637 putenv(const_cast<char*>(added_env[name]->c_str()));
1639 #elif GTEST_OS_WINDOWS // If we are on Windows proper. 1640 _putenv((
Message() << name <<
"=" << value).GetString().c_str());
1642 if (*value ==
'\0') {
1645 setenv(name, value, 1);
1647 #endif // GTEST_OS_WINDOWS_MOBILE 1650 #if !GTEST_OS_WINDOWS_MOBILE 1659 TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenVariableIsNotSet) {
1666 TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenValueOverflows) {
1667 printf(
"(expecting 2 warnings)\n");
1678 TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenValueIsInvalid) {
1679 printf(
"(expecting 2 warnings)\n");
1691 TEST(Int32FromGTestEnvTest, ParsesAndReturnsValidValue) {
1698 #endif // !GTEST_OS_WINDOWS_MOBILE 1704 TEST(ParseInt32FlagTest, ReturnsFalseForInvalidFlag) {
1715 TEST(ParseInt32FlagTest, ReturnsDefaultWhenValueOverflows) {
1716 printf(
"(expecting 2 warnings)\n");
1729 TEST(ParseInt32FlagTest, ReturnsDefaultWhenValueIsInvalid) {
1730 printf(
"(expecting 2 warnings)\n");
1743 TEST(ParseInt32FlagTest, ParsesAndReturnsValidValue) {
1756 #if !GTEST_OS_WINDOWS_MOBILE 1757 TEST(Int32FromEnvOrDieTest, ParsesAndReturnsValidValue) {
1764 #endif // !GTEST_OS_WINDOWS_MOBILE 1768 TEST(Int32FromEnvOrDieDeathTest, AbortsOnFailure) {
1777 TEST(Int32FromEnvOrDieDeathTest, AbortsOnInt32Overflow) {
1786 TEST(ShouldRunTestOnShardTest, IsPartitionWhenThereIsOneShard) {
1796 virtual void SetUp() {
1801 virtual void TearDown() {
1802 SetEnv(index_var_,
"");
1803 SetEnv(total_var_,
"");
1806 const char* index_var_;
1807 const char* total_var_;
1812 TEST_F(ShouldShardTest, ReturnsFalseWhenNeitherEnvVarIsSet) {
1813 SetEnv(index_var_,
"");
1814 SetEnv(total_var_,
"");
1821 TEST_F(ShouldShardTest, ReturnsFalseWhenTotalShardIsOne) {
1822 SetEnv(index_var_,
"0");
1823 SetEnv(total_var_,
"1");
1831 #if !GTEST_OS_WINDOWS_MOBILE 1832 TEST_F(ShouldShardTest, WorksWhenShardEnvVarsAreValid) {
1833 SetEnv(index_var_,
"4");
1834 SetEnv(total_var_,
"22");
1838 SetEnv(index_var_,
"8");
1839 SetEnv(total_var_,
"9");
1843 SetEnv(index_var_,
"0");
1844 SetEnv(total_var_,
"9");
1848 #endif // !GTEST_OS_WINDOWS_MOBILE 1852 typedef ShouldShardTest ShouldShardDeathTest;
1854 TEST_F(ShouldShardDeathTest, AbortsWhenShardingEnvVarsAreInvalid) {
1855 SetEnv(index_var_,
"4");
1856 SetEnv(total_var_,
"4");
1859 SetEnv(index_var_,
"4");
1860 SetEnv(total_var_,
"-2");
1863 SetEnv(index_var_,
"5");
1864 SetEnv(total_var_,
"");
1867 SetEnv(index_var_,
"");
1868 SetEnv(total_var_,
"5");
1874 TEST(ShouldRunTestOnShardTest, IsPartitionWhenThereAreFiveShards) {
1876 const int num_tests = 17;
1877 const int num_shards = 5;
1880 for (
int test_id = 0; test_id < num_tests; test_id++) {
1881 int prev_selected_shard_index = -1;
1882 for (
int shard_index = 0; shard_index < num_shards; shard_index++) {
1884 if (prev_selected_shard_index < 0) {
1885 prev_selected_shard_index = shard_index;
1887 ADD_FAILURE() <<
"Shard " << prev_selected_shard_index <<
" and " 1888 << shard_index <<
" are both selected to run test " << test_id;
1896 for (
int shard_index = 0; shard_index < num_shards; shard_index++) {
1897 int num_tests_on_shard = 0;
1898 for (
int test_id = 0; test_id < num_tests; test_id++) {
1899 num_tests_on_shard +=
1902 EXPECT_GE(num_tests_on_shard, num_tests / num_shards);
1916 TEST(UnitTestTest, CanGetOriginalWorkingDir) {
1921 TEST(UnitTestTest, ReturnsPlausibleTimestamp) {
1929 void ExpectNonFatalFailureRecordingPropertyWithReservedKey(
1933 <<
"' recorded unexpectedly.";
1936 void ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
1940 ExpectNonFatalFailureRecordingPropertyWithReservedKey(*test_info->
result(),
1944 void ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestCase(
1948 ExpectNonFatalFailureRecordingPropertyWithReservedKey(
1952 void ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestCase(
1954 ExpectNonFatalFailureRecordingPropertyWithReservedKey(
1961 class UnitTestRecordPropertyTest :
1964 static void SetUpTestCase() {
1965 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestCase(
1967 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestCase(
1969 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestCase(
1971 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestCase(
1973 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestCase(
1975 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestCase(
1991 TEST_F(UnitTestRecordPropertyTest, OnePropertyFoundWhenAdded) {
1992 UnitTestRecordProperty(
"key_1",
"1");
1994 ASSERT_EQ(1, unit_test_.ad_hoc_test_result().test_property_count());
1997 unit_test_.ad_hoc_test_result().GetTestProperty(0).key());
1999 unit_test_.ad_hoc_test_result().GetTestProperty(0).value());
2003 TEST_F(UnitTestRecordPropertyTest, MultiplePropertiesFoundWhenAdded) {
2004 UnitTestRecordProperty(
"key_1",
"1");
2005 UnitTestRecordProperty(
"key_2",
"2");
2007 ASSERT_EQ(2, unit_test_.ad_hoc_test_result().test_property_count());
2010 unit_test_.ad_hoc_test_result().GetTestProperty(0).key());
2011 EXPECT_STREQ(
"1", unit_test_.ad_hoc_test_result().GetTestProperty(0).value());
2014 unit_test_.ad_hoc_test_result().GetTestProperty(1).key());
2015 EXPECT_STREQ(
"2", unit_test_.ad_hoc_test_result().GetTestProperty(1).value());
2019 TEST_F(UnitTestRecordPropertyTest, OverridesValuesForDuplicateKeys) {
2020 UnitTestRecordProperty(
"key_1",
"1");
2021 UnitTestRecordProperty(
"key_2",
"2");
2022 UnitTestRecordProperty(
"key_1",
"12");
2023 UnitTestRecordProperty(
"key_2",
"22");
2025 ASSERT_EQ(2, unit_test_.ad_hoc_test_result().test_property_count());
2028 unit_test_.ad_hoc_test_result().GetTestProperty(0).key());
2030 unit_test_.ad_hoc_test_result().GetTestProperty(0).value());
2033 unit_test_.ad_hoc_test_result().GetTestProperty(1).key());
2035 unit_test_.ad_hoc_test_result().GetTestProperty(1).value());
2038 TEST_F(UnitTestRecordPropertyTest,
2039 AddFailureInsideTestsWhenUsingTestCaseReservedKeys) {
2040 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2042 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2044 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2046 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2048 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2050 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2054 TEST_F(UnitTestRecordPropertyTest,
2055 AddRecordWithReservedKeysGeneratesCorrectPropertyList) {
2058 "'classname', 'name', 'status', 'time', 'type_param', and 'value_param'" 2062 class UnitTestRecordPropertyTestEnvironment :
public Environment {
2064 virtual void TearDown() {
2065 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestCase(
2067 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestCase(
2069 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestCase(
2071 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestCase(
2073 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestCase(
2075 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestCase(
2077 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestCase(
2079 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestCase(
2097 bool IsEven(
int n) {
2098 return (n % 2) == 0;
2102 struct IsEvenFunctor {
2103 bool operator()(
int n) {
return IsEven(n); }
2114 msg << expr <<
" evaluates to " << n <<
", which is not even.";
2139 struct AssertIsEvenFunctor {
2141 return AssertIsEven(expr, n);
2146 bool SumIsEven2(
int n1,
int n2) {
2147 return IsEven(n1 + n2);
2152 struct SumIsEven3Functor {
2153 bool operator()(
int n1,
int n2,
int n3) {
2154 return IsEven(n1 + n2 + n3);
2161 const char* e1,
const char* e2,
const char* e3,
const char* e4,
2162 int n1,
int n2,
int n3,
int n4) {
2163 const int sum = n1 + n2 + n3 + n4;
2169 msg << e1 <<
" + " << e2 <<
" + " << e3 <<
" + " << e4
2170 <<
" (" << n1 <<
" + " << n2 <<
" + " << n3 <<
" + " << n4
2171 <<
") evaluates to " << sum <<
", which is not even.";
2177 struct AssertSumIsEven5Functor {
2179 const char* e1,
const char* e2,
const char* e3,
const char* e4,
2180 const char* e5,
int n1,
int n2,
int n3,
int n4,
int n5) {
2181 const int sum = n1 + n2 + n3 + n4 + n5;
2187 msg << e1 <<
" + " << e2 <<
" + " << e3 <<
" + " << e4 <<
" + " << e5
2189 << n1 <<
" + " << n2 <<
" + " << n3 <<
" + " << n4 <<
" + " << n5
2190 <<
") evaluates to " << sum <<
", which is not even.";
2199 TEST(Pred1Test, WithoutFormat) {
2201 EXPECT_PRED1(IsEvenFunctor(), 2) <<
"This failure is UNEXPECTED!";
2206 EXPECT_PRED1(IsEven, 5) <<
"This failure is expected.";
2207 },
"This failure is expected.");
2209 "evaluates to false");
2213 TEST(Pred1Test, WithFormat) {
2217 <<
"This failure is UNEXPECTED!";
2222 "n evaluates to 5, which is not even.");
2225 },
"This failure is expected.");
2230 TEST(Pred1Test, SingleEvaluationOnFailure) {
2234 EXPECT_EQ(1, n) <<
"The argument is not evaluated exactly once.";
2239 <<
"This failure is expected.";
2240 },
"This failure is expected.");
2241 EXPECT_EQ(2, n) <<
"The argument is not evaluated exactly once.";
2248 TEST(PredTest, WithoutFormat) {
2250 ASSERT_PRED2(SumIsEven2, 2, 4) <<
"This failure is UNEXPECTED!";
2257 EXPECT_PRED2(SumIsEven2, n1, n2) <<
"This failure is expected.";
2258 },
"This failure is expected.");
2261 },
"evaluates to false");
2265 TEST(PredTest, WithFormat) {
2268 "This failure is UNEXPECTED!";
2278 },
"evaluates to 13, which is not even.");
2281 <<
"This failure is expected.";
2282 },
"This failure is expected.");
2287 TEST(PredTest, SingleEvaluationOnFailure) {
2292 EXPECT_EQ(1, n1) <<
"Argument 1 is not evaluated exactly once.";
2293 EXPECT_EQ(1, n2) <<
"Argument 2 is not evaluated exactly once.";
2301 n1++, n2++, n3++, n4++, n5++)
2302 <<
"This failure is UNEXPECTED!";
2303 EXPECT_EQ(1, n1) <<
"Argument 1 is not evaluated exactly once.";
2304 EXPECT_EQ(1, n2) <<
"Argument 2 is not evaluated exactly once.";
2305 EXPECT_EQ(1, n3) <<
"Argument 3 is not evaluated exactly once.";
2306 EXPECT_EQ(1, n4) <<
"Argument 4 is not evaluated exactly once.";
2307 EXPECT_EQ(1, n5) <<
"Argument 5 is not evaluated exactly once.";
2313 <<
"This failure is expected.";
2314 },
"This failure is expected.");
2315 EXPECT_EQ(1, n1) <<
"Argument 1 is not evaluated exactly once.";
2316 EXPECT_EQ(1, n2) <<
"Argument 2 is not evaluated exactly once.";
2317 EXPECT_EQ(1, n3) <<
"Argument 3 is not evaluated exactly once.";
2320 n1 = n2 = n3 = n4 = 0;
2323 },
"evaluates to 1, which is not even.");
2324 EXPECT_EQ(1, n1) <<
"Argument 1 is not evaluated exactly once.";
2325 EXPECT_EQ(1, n2) <<
"Argument 2 is not evaluated exactly once.";
2326 EXPECT_EQ(1, n3) <<
"Argument 3 is not evaluated exactly once.";
2327 EXPECT_EQ(1, n4) <<
"Argument 4 is not evaluated exactly once.";
2334 bool IsPositive(
double x) {
2338 template <
typename T>
2339 bool IsNegative(T x) {
2343 template <
typename T1,
typename T2>
2344 bool GreaterThan(T1 x1, T2 x2) {
2350 TEST(PredicateAssertionTest, AcceptsOverloadedFunction) {
2358 TEST(PredicateAssertionTest, AcceptsTemplateFunction) {
2379 template <
typename T>
2385 template <
typename T1,
typename T2>
2387 const T1& x1,
const T2& x2) {
2394 TEST(PredicateFormatAssertionTest, AcceptsOverloadedFunction) {
2401 TEST(PredicateFormatAssertionTest, AcceptsTemplateFunction) {
2411 const char *
const p1 =
"good";
2415 const char p2[] =
"good";
2419 "Expected: \"bad\"");
2423 TEST(StringAssertionTest, ASSERT_STREQ_Null) {
2430 TEST(StringAssertionTest, ASSERT_STREQ_Null2) {
2445 "\"Hi\" vs \"Hi\"");
2472 TEST(StringAssertionTest, STREQ_Wide) {
2474 ASSERT_STREQ(static_cast<const wchar_t *>(NULL), NULL);
2496 EXPECT_STREQ(L
"abc\x8119", L
"abc\x8121") <<
"Expected failure";
2497 },
"Expected failure");
2501 TEST(StringAssertionTest, STRNE_Wide) {
2504 EXPECT_STRNE(static_cast<const wchar_t *>(NULL), NULL);
2526 ASSERT_STRNE(L
"abc\x8119", L
"abc\x8120") <<
"This shouldn't happen";
2533 TEST(IsSubstringTest, ReturnsCorrectResultForCString) {
2544 TEST(IsSubstringTest, ReturnsCorrectResultForWideCString) {
2555 TEST(IsSubstringTest, GeneratesCorrectMessageForCString) {
2557 " Actual: \"needle\"\n" 2558 "Expected: a substring of haystack_expr\n" 2559 "Which is: \"haystack\"",
2561 "needle",
"haystack").failure_message());
2566 TEST(IsSubstringTest, ReturnsCorrectResultsForStdString) {
2571 #if GTEST_HAS_STD_WSTRING 2574 TEST(IsSubstringTest, ReturnsCorrectResultForStdWstring) {
2581 TEST(IsSubstringTest, GeneratesCorrectMessageForWstring) {
2583 " Actual: L\"needle\"\n" 2584 "Expected: a substring of haystack_expr\n" 2585 "Which is: L\"haystack\"",
2587 "needle_expr",
"haystack_expr",
2588 ::
std::wstring(L
"needle"), L
"haystack").failure_message());
2591 #endif // GTEST_HAS_STD_WSTRING 2597 TEST(IsNotSubstringTest, ReturnsCorrectResultForCString) {
2604 TEST(IsNotSubstringTest, ReturnsCorrectResultForWideCString) {
2611 TEST(IsNotSubstringTest, GeneratesCorrectMessageForWideCString) {
2613 " Actual: L\"needle\"\n" 2614 "Expected: not a substring of haystack_expr\n" 2615 "Which is: L\"two needles\"",
2617 "needle_expr",
"haystack_expr",
2618 L
"needle", L
"two needles").failure_message());
2623 TEST(IsNotSubstringTest, ReturnsCorrectResultsForStdString) {
2630 TEST(IsNotSubstringTest, GeneratesCorrectMessageForStdString) {
2632 " Actual: \"needle\"\n" 2633 "Expected: not a substring of haystack_expr\n" 2634 "Which is: \"two needles\"",
2636 "needle_expr",
"haystack_expr",
2637 ::
std::string(
"needle"),
"two needles").failure_message());
2640 #if GTEST_HAS_STD_WSTRING 2644 TEST(IsNotSubstringTest, ReturnsCorrectResultForStdWstring) {
2650 #endif // GTEST_HAS_STD_WSTRING 2654 template <
typename RawType>
2655 class FloatingPointTest :
public Test {
2659 RawType close_to_positive_zero;
2660 RawType close_to_negative_zero;
2661 RawType further_from_negative_zero;
2663 RawType close_to_one;
2664 RawType further_from_one;
2667 RawType close_to_infinity;
2668 RawType further_from_infinity;
2675 typedef typename Floating::Bits Bits;
2677 virtual void SetUp() {
2678 const size_t max_ulps = Floating::kMaxUlps;
2681 const Bits zero_bits = Floating(0).
bits();
2684 values_.close_to_positive_zero = Floating::ReinterpretBits(
2685 zero_bits + max_ulps/2);
2686 values_.close_to_negative_zero = -Floating::ReinterpretBits(
2687 zero_bits + max_ulps - max_ulps/2);
2688 values_.further_from_negative_zero = -Floating::ReinterpretBits(
2689 zero_bits + max_ulps + 1 - max_ulps/2);
2692 const Bits one_bits = Floating(1).bits();
2695 values_.close_to_one = Floating::ReinterpretBits(one_bits + max_ulps);
2696 values_.further_from_one = Floating::ReinterpretBits(
2697 one_bits + max_ulps + 1);
2700 values_.infinity = Floating::Infinity();
2703 const Bits infinity_bits = Floating(values_.infinity).bits();
2706 values_.close_to_infinity = Floating::ReinterpretBits(
2707 infinity_bits - max_ulps);
2708 values_.further_from_infinity = Floating::ReinterpretBits(
2709 infinity_bits - max_ulps - 1);
2714 values_.nan1 = Floating::ReinterpretBits(Floating::kExponentBitMask
2715 | (static_cast<Bits>(1) << (Floating::kFractionBitCount - 1)) | 1);
2716 values_.nan2 = Floating::ReinterpretBits(Floating::kExponentBitMask
2717 | (static_cast<Bits>(1) << (Floating::kFractionBitCount - 1)) | 200);
2721 EXPECT_EQ(
sizeof(RawType),
sizeof(Bits));
2724 static TestValues values_;
2727 template <
typename RawType>
2728 typename FloatingPointTest<RawType>::TestValues
2729 FloatingPointTest<RawType>::values_;
2732 typedef FloatingPointTest<float> FloatTest;
2735 TEST_F(FloatTest, Size) {
2740 TEST_F(FloatTest, Zeros) {
2753 TEST_F(FloatTest, AlmostZeros) {
2760 static const FloatTest::TestValues& v = this->values_;
2768 v.further_from_negative_zero);
2769 },
"v.further_from_negative_zero");
2773 TEST_F(FloatTest, SmallDiff) {
2776 "values_.further_from_one");
2780 TEST_F(FloatTest, LargeDiff) {
2789 TEST_F(FloatTest, Infinity) {
2792 #if !GTEST_OS_SYMBIAN 2795 "-values_.infinity");
2801 #endif // !GTEST_OS_SYMBIAN 2806 #if !GTEST_OS_SYMBIAN 2815 static const FloatTest::TestValues& v = this->values_;
2826 #endif // !GTEST_OS_SYMBIAN 2830 TEST_F(FloatTest, Reflexive) {
2837 TEST_F(FloatTest, Commutative) {
2851 "The difference between 1.0f and 1.5f is 0.5, " 2852 "which exceeds 0.25f");
2862 "The difference between 1.0f and 1.5f is 0.5, " 2863 "which exceeds 0.25f");
2869 TEST_F(FloatTest, FloatLESucceeds) {
2878 TEST_F(FloatTest, FloatLEFails) {
2881 "(2.0f) <= (1.0f)");
2886 },
"(values_.further_from_one) <= (1.0f)");
2888 #if !GTEST_OS_SYMBIAN && !defined(__BORLANDC__) 2894 },
"(values_.nan1) <= (values_.infinity)");
2897 },
"(-values_.infinity) <= (values_.nan1)");
2900 },
"(values_.nan1) <= (values_.nan1)");
2901 #endif // !GTEST_OS_SYMBIAN && !defined(__BORLANDC__) 2905 typedef FloatingPointTest<double> DoubleTest;
2908 TEST_F(DoubleTest, Size) {
2913 TEST_F(DoubleTest, Zeros) {
2926 TEST_F(DoubleTest, AlmostZeros) {
2933 static const DoubleTest::TestValues& v = this->values_;
2941 v.further_from_negative_zero);
2942 },
"v.further_from_negative_zero");
2946 TEST_F(DoubleTest, SmallDiff) {
2949 "values_.further_from_one");
2953 TEST_F(DoubleTest, LargeDiff) {
2962 TEST_F(DoubleTest, Infinity) {
2965 #if !GTEST_OS_SYMBIAN 2968 "-values_.infinity");
2974 #endif // !GTEST_OS_SYMBIAN 2978 TEST_F(DoubleTest, NaN) {
2979 #if !GTEST_OS_SYMBIAN 2986 static const DoubleTest::TestValues& v = this->values_;
2995 #endif // !GTEST_OS_SYMBIAN 2999 TEST_F(DoubleTest, Reflexive) {
3002 #if !GTEST_OS_SYMBIAN 3005 #endif // !GTEST_OS_SYMBIAN 3009 TEST_F(DoubleTest, Commutative) {
3023 "The difference between 1.0 and 1.5 is 0.5, " 3024 "which exceeds 0.25");
3034 "The difference between 1.0 and 1.5 is 0.5, " 3035 "which exceeds 0.25");
3041 TEST_F(DoubleTest, DoubleLESucceeds) {
3050 TEST_F(DoubleTest, DoubleLEFails) {
3058 },
"(values_.further_from_one) <= (1.0)");
3060 #if !GTEST_OS_SYMBIAN && !defined(__BORLANDC__) 3066 },
"(values_.nan1) <= (values_.infinity)");
3069 },
" (-values_.infinity) <= (values_.nan1)");
3072 },
"(values_.nan1) <= (values_.nan1)");
3073 #endif // !GTEST_OS_SYMBIAN && !defined(__BORLANDC__) 3083 FAIL() <<
"Unexpected failure: Disabled test should not be run.";
3094 TEST(DISABLED_TestCase, TestShouldNotRun) {
3095 FAIL() <<
"Unexpected failure: Test in disabled test case should not be run.";
3100 TEST(DISABLED_TestCase, DISABLED_TestShouldNotRun) {
3101 FAIL() <<
"Unexpected failure: Test in disabled test case should not be run.";
3106 class DisabledTestsTest :
public Test {
3108 static void SetUpTestCase() {
3109 FAIL() <<
"Unexpected failure: All tests disabled in test case. " 3110 "SetupTestCase() should not be called.";
3113 static void TearDownTestCase() {
3114 FAIL() <<
"Unexpected failure: All tests disabled in test case. " 3115 "TearDownTestCase() should not be called.";
3119 TEST_F(DisabledTestsTest, DISABLED_TestShouldNotRun_1) {
3120 FAIL() <<
"Unexpected failure: Disabled test should not be run.";
3123 TEST_F(DisabledTestsTest, DISABLED_TestShouldNotRun_2) {
3124 FAIL() <<
"Unexpected failure: Disabled test should not be run.";
3129 #if GTEST_HAS_TYPED_TEST 3131 template <
typename T>
3135 typedef testing::Types<int, double> NumericTypes;
3139 FAIL() <<
"Unexpected failure: Disabled typed test should not run.";
3142 template <
typename T>
3143 class DISABLED_TypedTest :
public Test {
3148 TYPED_TEST(DISABLED_TypedTest, ShouldNotRun) {
3149 FAIL() <<
"Unexpected failure: Disabled typed test should not run.";
3152 #endif // GTEST_HAS_TYPED_TEST 3156 #if GTEST_HAS_TYPED_TEST_P 3158 template <
typename T>
3159 class TypedTestP :
public Test {
3165 FAIL() <<
"Unexpected failure: " 3166 <<
"Disabled type-parameterized test should not run.";
3173 template <
typename T>
3174 class DISABLED_TypedTestP :
public Test {
3180 FAIL() <<
"Unexpected failure: " 3181 <<
"Disabled type-parameterized test should not run.";
3188 #endif // GTEST_HAS_TYPED_TEST_P 3192 class SingleEvaluationTest :
public Test {
3197 static void CompareAndIncrementCharPtrs() {
3203 static void CompareAndIncrementInts() {
3208 SingleEvaluationTest() {
3215 static const char*
const s1_;
3216 static const char*
const s2_;
3217 static const char* p1_;
3218 static const char* p2_;
3224 const char*
const SingleEvaluationTest::s1_ =
"01234";
3225 const char*
const SingleEvaluationTest::s2_ =
"abcde";
3226 const char* SingleEvaluationTest::p1_;
3227 const char* SingleEvaluationTest::p2_;
3228 int SingleEvaluationTest::a_;
3229 int SingleEvaluationTest::b_;
3233 TEST_F(SingleEvaluationTest, FailedASSERT_STREQ) {
3241 TEST_F(SingleEvaluationTest, ASSERT_STR) {
3256 TEST_F(SingleEvaluationTest, FailedASSERT_NE) {
3258 "(a_++) != (b_++)");
3264 TEST_F(SingleEvaluationTest, OtherCases) {
3293 #if GTEST_HAS_EXCEPTIONS 3295 void ThrowAnInteger() {
3300 TEST_F(SingleEvaluationTest, ExceptionTests) {
3312 },
bool),
"throws a different type");
3342 #endif // GTEST_HAS_EXCEPTIONS 3345 class NoFatalFailureTest :
public Test {
3348 void FailsNonFatal() {
3352 FAIL() <<
"some fatal failure";
3355 void DoAssertNoFatalFailureOnFails() {
3360 void DoExpectNoFatalFailureOnFails() {
3366 TEST_F(NoFatalFailureTest, NoFailure) {
3371 TEST_F(NoFatalFailureTest, NonFatalIsNoFailure) {
3374 "some non-fatal failure");
3377 "some non-fatal failure");
3380 TEST_F(NoFatalFailureTest, AssertNoFatalFailureOnFatalFailure) {
3384 DoAssertNoFatalFailureOnFails();
3397 TEST_F(NoFatalFailureTest, ExpectNoFatalFailureOnFatalFailure) {
3401 DoExpectNoFatalFailureOnFails();
3418 TEST_F(NoFatalFailureTest, MessageIsStreamable) {
3437 std::string EditsToString(
const std::vector<EditType>& edits) {
3439 for (
size_t i = 0;
i < edits.size(); ++
i) {
3440 static const char kEdits[] =
" +-/";
3441 out.append(1, kEdits[edits[
i]]);
3447 std::vector<size_t> out;
3448 for (
size_t i = 0;
i < str.size(); ++
i) {
3449 out.push_back(str[
i]);
3454 std::vector<std::string> CharsToLines(
const std::string& str) {
3455 std::vector<std::string> out;
3456 for (
size_t i = 0;
i < str.size(); ++
i) {
3457 out.push_back(str.substr(
i, 1));
3462 TEST(EditDistance, TestCases) {
3467 const char* expected_edits;
3468 const char* expected_diff;
3470 static const Case kCases[] = {
3472 {__LINE__,
"A",
"A",
" ",
""},
3473 {__LINE__,
"ABCDE",
"ABCDE",
" ",
""},
3475 {__LINE__,
"X",
"XA",
" +",
"@@ +1,2 @@\n X\n+A\n"},
3476 {__LINE__,
"X",
"XABCD",
" ++++",
"@@ +1,5 @@\n X\n+A\n+B\n+C\n+D\n"},
3478 {__LINE__,
"XA",
"X",
" -",
"@@ -1,2 @@\n X\n-A\n"},
3479 {__LINE__,
"XABCD",
"X",
" ----",
"@@ -1,5 @@\n X\n-A\n-B\n-C\n-D\n"},
3481 {__LINE__,
"A",
"a",
"/",
"@@ -1,1 +1,1 @@\n-A\n+a\n"},
3482 {__LINE__,
"ABCD",
"abcd",
"////",
3483 "@@ -1,4 +1,4 @@\n-A\n-B\n-C\n-D\n+a\n+b\n+c\n+d\n"},
3485 {__LINE__,
"ABCDEFGH",
"ABXEGH1",
" -/ - +",
3486 "@@ -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"},
3487 {__LINE__,
"AAAABCCCC",
"ABABCDCDC",
"- / + / ",
3488 "@@ -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"},
3489 {__LINE__,
"ABCDE",
"BCDCD",
"- +/",
3490 "@@ -1,5 +1,5 @@\n-A\n B\n C\n D\n-E\n+C\n+D\n"},
3491 {__LINE__,
"ABCDEFGHIJKL",
"BCDCDEFGJKLJK",
"- ++ -- ++",
3492 "@@ -1,4 +1,5 @@\n-A\n B\n+C\n+D\n C\n D\n" 3493 "@@ -6,7 +7,7 @@\n F\n G\n-H\n-I\n J\n K\n L\n+J\n+K\n"},
3495 for (
const Case* c = kCases; c->left; ++c) {
3498 CharsToIndices(c->right))))
3499 <<
"Left <" << c->left <<
"> Right <" << c->right <<
"> Edits <" 3501 CharsToIndices(c->left), CharsToIndices(c->right))) <<
">";
3503 CharsToLines(c->right)))
3504 <<
"Left <" << c->left <<
"> Right <" << c->right <<
"> Diff <" 3514 EqFailure(
"foo",
"bar", foo_val, bar_val,
false)
3515 .failure_message());
3524 EqFailure(
"foo",
"6", foo_val, bar_val,
false)
3525 .failure_message());
3533 EqFailure(
"5",
"bar", foo_val, bar_val,
false)
3534 .failure_message());
3542 EqFailure(
"5",
"6", foo_val, bar_val,
false).failure_message());
3551 true).failure_message());
3555 "Expected: foo (ignoring case)\n" 3560 TEST(AssertionTest, EqFailureWithDiff) {
3562 "1\\n2XXX\\n3\\n5\\n6\\n7\\n8\\n9\\n10\\n11\\n12XXX\\n13\\n14\\n15");
3564 "1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n11\\n12\\n13\\n14");
3566 EqFailure(
"left",
"right", left, right,
false).failure_message());
3569 " Actual: 1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n11\\n12\\n13\\n14\n" 3572 "1\\n2XXX\\n3\\n5\\n6\\n7\\n8\\n9\\n10\\n11\\n12XXX\\n13\\n14\\n15\n" 3573 "With diff:\n@@ -1,5 +1,6 @@\n 1\n-2XXX\n+2\n 3\n+4\n 5\n 6\n" 3574 "@@ -7,8 +8,6 @@\n 8\n 9\n-10\n 11\n-12XXX\n+12\n 13\n 14\n-15\n",
3593 # pragma option push -w-ccc -w-rch 3604 TEST(AssertionTest, AssertTrueWithAssertionResult) {
3606 #ifndef __BORLANDC__ 3609 "Value of: ResultIsEven(3)\n" 3610 " Actual: false (3 is odd)\n" 3615 "Value of: ResultIsEvenNoExplanation(3)\n" 3616 " Actual: false (3 is odd)\n" 3630 TEST(AssertionTest, AssertFalseWithAssertionResult) {
3632 #ifndef __BORLANDC__ 3635 "Value of: ResultIsEven(2)\n" 3636 " Actual: true (2 is even)\n" 3641 "Value of: ResultIsEvenNoExplanation(2)\n" 3654 TEST(ExpectTest, ASSERT_EQ_Double) {
3673 #if GTEST_CAN_COMPARE_NULL 3674 TEST(AssertionTest, ASSERT_EQ_NULL) {
3676 const char*
p = NULL;
3688 #endif // GTEST_CAN_COMPARE_NULL 3694 TEST(ExpectTest, ASSERT_EQ_0) {
3709 "Expected: ('a') != ('a'), " 3710 "actual: 'a' (97, 0x61) vs 'a' (97, 0x61)");
3718 "Expected: (2) <= (0), actual: 2 vs 0");
3725 "Expected: (2) < (2), actual: 2 vs 2");
3733 "Expected: (2) >= (3), actual: 2 vs 3");
3740 "Expected: (2) > (2), actual: 2 vs 2");
3743 #if GTEST_HAS_EXCEPTIONS 3745 void ThrowNothing() {}
3751 # ifndef __BORLANDC__ 3756 "Expected: ThrowAnInteger() throws an exception of type bool.\n" 3757 " Actual: it throws a different type.");
3762 "Expected: ThrowNothing() throws an exception of type bool.\n" 3763 " Actual: it throws nothing.");
3770 "Expected: ThrowAnInteger() doesn't throw an exception." 3771 "\n Actual: it throws.");
3779 "Expected: ThrowNothing() throws an exception.\n" 3780 " Actual: it doesn't.");
3783 #endif // GTEST_HAS_EXCEPTIONS 3787 TEST(AssertionTest, AssertPrecedence) {
3789 bool false_value =
false;
3799 TEST(AssertionTest, NonFixtureSubroutine) {
3807 explicit Uncopyable(
int a_value) : value_(a_value) {}
3809 int value()
const {
return value_; }
3810 bool operator==(
const Uncopyable& rhs)
const {
3811 return value() == rhs.value();
3816 Uncopyable(
const Uncopyable&);
3821 ::std::ostream&
operator<<(::std::ostream& os,
const Uncopyable& value) {
3822 return os << value.value();
3826 bool IsPositiveUncopyable(
const Uncopyable& x) {
3827 return x.value() > 0;
3831 void TestAssertNonPositive() {
3836 void TestAssertEqualsUncopyable() {
3843 TEST(AssertionTest, AssertWorksWithUncopyableObject) {
3848 "IsPositiveUncopyable(y) evaluates to false, where\ny evaluates to -1");
3850 "Value of: y\n Actual: -1\nExpected: x\nWhich is: 5");
3854 TEST(AssertionTest, ExpectWorksWithUncopyableObject) {
3859 "IsPositiveUncopyable(y) evaluates to false, where\ny evaluates to -1");
3862 "Value of: y\n Actual: -1\nExpected: x\nWhich is: 5");
3881 #if !GTEST_OS_MAC && !defined(__SUNPRO_CC) && !defined(__HP_aCC) 3904 # endif // GTEST_OS_LINUX 3912 EXPECT_EQ(static_cast<int>(kCaseA), static_cast<int>(kCaseB));
3914 # endif // GTEST_OS_LINUX 3923 "(kCaseA) >= (kCaseB)");
3934 # ifndef __BORLANDC__ 3938 "Value of: kCaseB");
3947 #endif // !GTEST_OS_MAC && !defined(__SUNPRO_CC) 3949 #if GTEST_OS_WINDOWS 3951 static HRESULT UnexpectedHRESULTFailure() {
3952 return E_UNEXPECTED;
3955 static HRESULT OkHRESULTSuccess() {
3959 static HRESULT FalseHRESULTSuccess() {
3967 TEST(HRESULTAssertionTest, EXPECT_HRESULT_SUCCEEDED) {
3968 EXPECT_HRESULT_SUCCEEDED(S_OK);
3969 EXPECT_HRESULT_SUCCEEDED(S_FALSE);
3972 "Expected: (UnexpectedHRESULTFailure()) succeeds.\n" 3973 " Actual: 0x8000FFFF");
3976 TEST(HRESULTAssertionTest, ASSERT_HRESULT_SUCCEEDED) {
3977 ASSERT_HRESULT_SUCCEEDED(S_OK);
3978 ASSERT_HRESULT_SUCCEEDED(S_FALSE);
3981 "Expected: (UnexpectedHRESULTFailure()) succeeds.\n" 3982 " Actual: 0x8000FFFF");
3985 TEST(HRESULTAssertionTest, EXPECT_HRESULT_FAILED) {
3986 EXPECT_HRESULT_FAILED(E_UNEXPECTED);
3989 "Expected: (OkHRESULTSuccess()) fails.\n" 3992 "Expected: (FalseHRESULTSuccess()) fails.\n" 3996 TEST(HRESULTAssertionTest, ASSERT_HRESULT_FAILED) {
3997 ASSERT_HRESULT_FAILED(E_UNEXPECTED);
3999 # ifndef __BORLANDC__ 4003 "Expected: (OkHRESULTSuccess()) fails.\n" 4008 "Expected: (FalseHRESULTSuccess()) fails.\n" 4013 TEST(HRESULTAssertionTest, Streaming) {
4014 EXPECT_HRESULT_SUCCEEDED(S_OK) <<
"unexpected failure";
4015 ASSERT_HRESULT_SUCCEEDED(S_OK) <<
"unexpected failure";
4016 EXPECT_HRESULT_FAILED(E_UNEXPECTED) <<
"unexpected failure";
4017 ASSERT_HRESULT_FAILED(E_UNEXPECTED) <<
"unexpected failure";
4020 EXPECT_HRESULT_SUCCEEDED(E_UNEXPECTED) <<
"expected failure",
4021 "expected failure");
4023 # ifndef __BORLANDC__ 4027 ASSERT_HRESULT_SUCCEEDED(E_UNEXPECTED) <<
"expected failure",
4028 "expected failure");
4032 EXPECT_HRESULT_FAILED(S_OK) <<
"expected failure",
4033 "expected failure");
4036 ASSERT_HRESULT_FAILED(S_OK) <<
"expected failure",
4037 "expected failure");
4040 #endif // GTEST_OS_WINDOWS 4044 # pragma option push -w-ccc -w-rch 4048 TEST(AssertionSyntaxTest, BasicAssertionsBehavesLikeSingleStatement) {
4050 ASSERT_TRUE(
false) <<
"This should never be executed; " 4051 "It's a compilation test only.";
4067 #if GTEST_HAS_EXCEPTIONS 4070 TEST(ExpectThrowTest, DoesNotGenerateUnreachableCodeWarning) {
4082 TEST(AssertionSyntaxTest, ExceptionAssertionsBehavesLikeSingleStatement) {
4107 #endif // GTEST_HAS_EXCEPTIONS 4109 TEST(AssertionSyntaxTest, NoFatalFailureAssertionsBehavesLikeSingleStatement) {
4112 <<
"It's a compilation test only.";
4133 TEST(AssertionSyntaxTest, WorksWithSwitch) {
4143 EXPECT_FALSE(
false) <<
"EXPECT_FALSE failed in switch case";
4150 ASSERT_EQ(1, 1) <<
"ASSERT_EQ failed in default switch handler";
4158 #if GTEST_HAS_EXCEPTIONS 4160 void ThrowAString() {
4161 throw "std::string";
4166 TEST(AssertionSyntaxTest, WorksWithConst) {
4172 #endif // GTEST_HAS_EXCEPTIONS 4179 TEST(SuccessfulAssertionTest, SUCCEED) {
4186 TEST(SuccessfulAssertionTest, EXPECT) {
4192 TEST(SuccessfulAssertionTest, EXPECT_STR) {
4204 TEST(SuccessfulAssertionTest, ASSERT_STR) {
4215 TEST(AssertionWithMessageTest, EXPECT) {
4216 EXPECT_EQ(1, 1) <<
"This should succeed.";
4218 "Expected failure #1");
4219 EXPECT_LE(1, 2) <<
"This should succeed.";
4221 "Expected failure #2.");
4222 EXPECT_GE(1, 0) <<
"This should succeed.";
4224 "Expected failure #3.");
4228 "Expected failure #4.");
4231 "Expected failure #5.");
4235 "Expected failure #6.");
4236 EXPECT_NEAR(1, 1.1, 0.2) <<
"This should succeed.";
4240 ASSERT_EQ(1, 1) <<
"This should succeed.";
4241 ASSERT_NE(1, 2) <<
"This should succeed.";
4242 ASSERT_LE(1, 2) <<
"This should succeed.";
4243 ASSERT_LT(1, 2) <<
"This should succeed.";
4244 ASSERT_GE(1, 0) <<
"This should succeed.";
4246 "Expected failure.");
4249 TEST(AssertionWithMessageTest, ASSERT_STR) {
4254 "Expected failure.");
4257 TEST(AssertionWithMessageTest, ASSERT_FLOATING) {
4270 ASSERT_FALSE(
true) <<
"Expected failure: " << 2 <<
" > " << 1
4271 <<
" evaluates to " <<
true;
4272 },
"Expected failure");
4276 TEST(AssertionWithMessageTest,
FAIL) {
4283 SUCCEED() <<
"Success == " << 1;
4291 ASSERT_TRUE(
false) <<
static_cast<const char *
>(NULL)
4292 << static_cast<char *>(NULL);
4296 #if GTEST_OS_WINDOWS 4298 TEST(AssertionWithMessageTest, WideStringMessage) {
4300 EXPECT_TRUE(
false) << L
"This failure is expected.\x8119";
4301 },
"This failure is expected.");
4304 << L
"expected too.\x8120";
4305 },
"This failure is expected too.");
4307 #endif // GTEST_OS_WINDOWS 4313 "Intentional failure #1.");
4315 "Intentional failure #2.");
4326 TEST(ExpectTest, ExpectTrueWithAssertionResult) {
4329 "Value of: ResultIsEven(3)\n" 4330 " Actual: false (3 is odd)\n" 4334 "Value of: ResultIsEvenNoExplanation(3)\n" 4335 " Actual: false (3 is odd)\n" 4344 "Intentional failure #1.");
4346 "Intentional failure #2.");
4356 TEST(ExpectTest, ExpectFalseWithAssertionResult) {
4359 "Value of: ResultIsEven(2)\n" 4360 " Actual: true (2 is even)\n" 4364 "Value of: ResultIsEvenNoExplanation(2)\n" 4388 TEST(ExpectTest, EXPECT_EQ_Double) {
4397 #if GTEST_CAN_COMPARE_NULL 4399 TEST(ExpectTest, EXPECT_EQ_NULL) {
4401 const char*
p = NULL;
4413 #endif // GTEST_CAN_COMPARE_NULL 4419 TEST(ExpectTest, EXPECT_EQ_0) {
4435 "Expected: ('a') != ('a'), " 4436 "actual: 'a' (97, 0x61) vs 'a' (97, 0x61)");
4439 char*
const p0 = NULL;
4446 void* pv1 = (
void*)0x1234;
4447 char*
const p1 =
reinterpret_cast<char*
>(pv1);
4457 "Expected: (2) <= (0), actual: 2 vs 0");
4466 "Expected: (2) < (2), actual: 2 vs 2");
4476 "Expected: (2) >= (3), actual: 2 vs 3");
4485 "Expected: (2) > (2), actual: 2 vs 2");
4490 #if GTEST_HAS_EXCEPTIONS 4496 "Expected: ThrowAnInteger() throws an exception of " 4497 "type bool.\n Actual: it throws a different type.");
4500 "Expected: ThrowNothing() throws an exception of type bool.\n" 4501 " Actual: it throws nothing.");
4508 "Expected: ThrowAnInteger() doesn't throw an " 4509 "exception.\n Actual: it throws.");
4517 "Expected: ThrowNothing() throws an exception.\n" 4518 " Actual: it doesn't.");
4521 #endif // GTEST_HAS_EXCEPTIONS 4524 TEST(ExpectTest, ExpectPrecedence) {
4527 "Value of: true && false");
4534 TEST(StreamableToStringTest, Scalar) {
4539 TEST(StreamableToStringTest, Pointer) {
4546 TEST(StreamableToStringTest, NullPointer) {
4552 TEST(StreamableToStringTest, CString) {
4557 TEST(StreamableToStringTest, NullCString) {
4565 TEST(StreamableTest,
string) {
4567 "This failure message is a std::string, and is expected.");
4574 TEST(StreamableTest, stringWithEmbeddedNUL) {
4575 static const char char_array_with_nul[] =
4576 "Here's a NUL\0 and some more string";
4577 static const std::string string_with_nul(char_array_with_nul,
4578 sizeof(char_array_with_nul)
4581 "Here's a NUL\\0 and some more string");
4585 TEST(StreamableTest, NULChar) {
4587 FAIL() <<
"A NUL" <<
'\0' <<
" and some more string";
4588 },
"A NUL\\0 and some more string");
4592 TEST(StreamableTest,
int) {
4602 TEST(StreamableTest, NullCharPtr) {
4609 TEST(StreamableTest, BasicIoManip) {
4611 FAIL() <<
"Line 1." << std::endl
4612 <<
"A NUL char " << std::ends << std::flush <<
" in line 2.";
4613 },
"Line 1.\nA NUL char \\0 in line 2.");
4618 void AddFailureHelper(
bool* aborted) {
4626 bool aborted =
true;
4628 "Intentional failure.");
4652 "Intentional failure.");
4658 SUCCEED() <<
"Explicit success.";
4672 bool false_value =
false;
4674 },
"Value of: true");
4678 TEST(EqAssertionTest, Int) {
4685 TEST(EqAssertionTest, Time_T) {
4687 static_cast<time_t>(0));
4689 static_cast<time_t>(1234)),
4694 TEST(EqAssertionTest, Char) {
4696 const char ch =
'b';
4704 TEST(EqAssertionTest, WideChar) {
4709 " Actual: L'x' (120, 0x78)\n" 4711 "Which is: L'\0' (0, 0x0)");
4713 static wchar_t wchar;
4723 TEST(EqAssertionTest, StdString) {
4739 char*
const p1 =
const_cast<char*
>(
"foo");
4749 " Actual: \"A \\0 in the middle\"");
4752 #if GTEST_HAS_STD_WSTRING 4755 TEST(EqAssertionTest, StdWideString) {
4763 const wchar_t kTestX8119[] = {
'T',
'e',
's',
't', 0x8119,
'\0' };
4768 const wchar_t kTestX8120[] = {
'T',
'e',
's',
't', 0x8120,
'\0' };
4776 wstr3.at(2) = L
'\0';
4787 #endif // GTEST_HAS_STD_WSTRING 4789 #if GTEST_HAS_GLOBAL_STRING 4791 TEST(EqAssertionTest, GlobalString) {
4813 ASSERT_EQ(::
string(
"bar"), const_cast<char*>(
"foo"));
4817 #endif // GTEST_HAS_GLOBAL_STRING 4819 #if GTEST_HAS_GLOBAL_WSTRING 4822 TEST(EqAssertionTest, GlobalWideString) {
4829 const wchar_t kTestX8119[] = {
'T',
'e',
's',
't', 0x8119,
'\0' };
4834 const wchar_t kTestX8120[] = {
'T',
'e',
's',
't', 0x8120,
'\0' };
4840 wchar_t*
const p1 =
const_cast<wchar_t*
>(L
"foo");
4848 wstr3.at(2) = L
'\0';
4853 #endif // GTEST_HAS_GLOBAL_WSTRING 4856 TEST(EqAssertionTest, CharPointer) {
4857 char*
const p0 = NULL;
4862 void* pv1 = (
void*)0x1234;
4863 void* pv2 = (
void*)0xABC0;
4864 char*
const p1 =
reinterpret_cast<char*
>(pv1);
4865 char*
const p2 =
reinterpret_cast<char*
>(pv2);
4873 reinterpret_cast<char*>(0xABC0)),
4878 TEST(EqAssertionTest, WideCharPointer) {
4879 wchar_t*
const p0 = NULL;
4884 void* pv1 = (
void*)0x1234;
4885 void* pv2 = (
void*)0xABC0;
4886 wchar_t*
const p1 =
reinterpret_cast<wchar_t*
>(pv1);
4887 wchar_t*
const p2 =
reinterpret_cast<wchar_t*
>(pv2);
4894 void* pv3 = (
void*)0x1234;
4895 void* pv4 = (
void*)0xABC0;
4896 const wchar_t* p3 =
reinterpret_cast<const wchar_t*
>(pv3);
4897 const wchar_t* p4 =
reinterpret_cast<const wchar_t*
>(pv4);
4903 TEST(EqAssertionTest, OtherPointer) {
4904 ASSERT_EQ(static_cast<const int*>(NULL),
4905 static_cast<const int*>(NULL));
4907 reinterpret_cast<const int*>(0x1234)),
4912 class UnprintableChar {
4914 explicit UnprintableChar(
char ch) : char_(ch) {}
4916 bool operator==(
const UnprintableChar& rhs)
const {
4917 return char_ == rhs.char_;
4919 bool operator!=(
const UnprintableChar& rhs)
const {
4920 return char_ != rhs.char_;
4922 bool operator<(
const UnprintableChar& rhs)
const {
4923 return char_ < rhs.char_;
4925 bool operator<=(
const UnprintableChar& rhs)
const {
4926 return char_ <= rhs.char_;
4928 bool operator>(
const UnprintableChar& rhs)
const {
4929 return char_ > rhs.char_;
4931 bool operator>=(
const UnprintableChar& rhs)
const {
4932 return char_ >= rhs.char_;
4941 TEST(ComparisonAssertionTest, AcceptsUnprintableArgs) {
4942 const UnprintableChar
x(
'x'),
y(
'y');
4958 #ifndef __BORLANDC__ 4961 "1-byte object <78>");
4963 "1-byte object <78>");
4966 "1-byte object <79>");
4968 "1-byte object <78>");
4970 "1-byte object <79>");
4982 int Bar()
const {
return 1; }
4997 class FRIEND_TEST_Test2 :
public Test {
5014 class TestLifeCycleTest :
public Test {
5018 TestLifeCycleTest() { count_++; }
5022 ~TestLifeCycleTest() { count_--; }
5025 int count()
const {
return count_; }
5031 int TestLifeCycleTest::count_ = 0;
5034 TEST_F(TestLifeCycleTest, Test1) {
5041 TEST_F(TestLifeCycleTest, Test2) {
5052 TEST(AssertionResultTest, CopyConstructorWorksWhenNotOptimied) {
5062 EXPECT_EQ(static_cast<bool>(r3), static_cast<bool>(r1));
5068 TEST(AssertionResultTest, ConstructionWorks) {
5091 TEST(AssertionResultTest, NegationWorks) {
5101 TEST(AssertionResultTest, StreamingWorks) {
5103 r <<
"abc" <<
'd' << 0 <<
true;
5107 TEST(AssertionResultTest, CanStreamOstreamManipulators) {
5109 r <<
"Data" << std::endl << std::flush << std::ends <<
"Will be visible";
5114 #if GTEST_LANG_CXX11 5116 TEST(AssertionResultTest, ConstructibleFromContextuallyConvertibleToBool) {
5117 struct ExplicitlyConvertibleToBool {
5118 explicit operator bool()
const {
return value; }
5121 ExplicitlyConvertibleToBool v1 = {
false};
5122 ExplicitlyConvertibleToBool v2 = {
true};
5127 #endif // GTEST_LANG_CXX11 5133 TEST(AssertionResultTest, ConstructibleFromImplicitlyConvertible) {
5142 explicit Base(
int an_x) : x_(an_x) {}
5143 int x()
const {
return x_; }
5149 return os << val.
x();
5152 const Base* pointer) {
5153 return os <<
"(" << pointer->
x() <<
")";
5156 TEST(MessageTest, CanStreamUserTypeInGlobalNameSpace) {
5167 class MyTypeInUnnamedNameSpace :
public Base {
5169 explicit MyTypeInUnnamedNameSpace(
int an_x):
Base(an_x) {}
5172 const MyTypeInUnnamedNameSpace& val) {
5173 return os << val.x();
5176 const MyTypeInUnnamedNameSpace* pointer) {
5177 return os <<
"(" << pointer->x() <<
")";
5181 TEST(MessageTest, CanStreamUserTypeInUnnamedNameSpace) {
5183 MyTypeInUnnamedNameSpace
a(1);
5198 return os << val.
x();
5202 return os <<
"(" << pointer->
x() <<
")";
5206 TEST(MessageTest, CanStreamUserTypeInUserNameSpace) {
5224 return os << val.
x();
5228 return os <<
"(" << pointer->
x() <<
")";
5231 TEST(MessageTest, CanStreamUserTypeInUserNameSpaceWithStreamOperatorInGlobal) {
5242 char*
const p1 = NULL;
5243 unsigned char*
const p2 = NULL;
5249 msg << p1 << p2 << p3 << p4 << p5 << p6;
5257 const wchar_t* const_wstr = NULL;
5259 (
Message() << const_wstr).GetString().c_str());
5262 wchar_t* wstr = NULL;
5264 (
Message() << wstr).GetString().c_str());
5267 const_wstr = L
"abc\x8119";
5269 (
Message() << const_wstr).GetString().c_str());
5272 wstr =
const_cast<wchar_t*
>(const_wstr);
5274 (
Message() << wstr).GetString().c_str());
5287 GetTestCase(
"TestInfoTest",
"", NULL, NULL);
5291 if (strcmp(test_name, test_info->
name()) == 0)
5299 return test_info->
result();
5305 const TestInfo*
const test_info = GetTestInfo(
"Names");
5313 const TestInfo*
const test_info = GetTestInfo(
"result");
5316 ASSERT_EQ(0, GetTestResult(test_info)->total_part_count());
5319 ASSERT_EQ(0, GetTestResult(test_info)->total_part_count());
5329 printf(
"Setting up the test case . . .\n");
5334 shared_resource_ =
"123";
5346 printf(
"Tearing down the test case . . .\n");
5355 shared_resource_ = NULL;
5391 break_on_failure(
false),
5392 catch_exceptions(
false),
5393 death_test_use_fork(
false),
5402 stream_result_to(
""),
5403 throw_on_failure(
false) {}
5558 template <
typename CharType>
5560 size_t size2, CharType** array2) {
5561 ASSERT_EQ(size1, size2) <<
" Array sizes different.";
5563 for (
size_t i = 0;
i != size1;
i++) {
5591 template <
typename CharType>
5593 int argc2,
const CharType** argv2,
5594 const Flags& expected,
bool should_print_help) {
5598 #if GTEST_HAS_STREAM_REDIRECTION 5605 #if GTEST_HAS_STREAM_REDIRECTION 5610 CheckFlags(expected);
5614 AssertStringArrayEq(argc1 + 1, argv1, argc2 + 1, argv2);
5620 #if GTEST_HAS_STREAM_REDIRECTION 5621 const char*
const expected_help_fragment =
5622 "This program contains tests written using";
5623 if (should_print_help) {
5627 expected_help_fragment, captured_stdout);
5629 #endif // GTEST_HAS_STREAM_REDIRECTION 5637 #define GTEST_TEST_PARSING_FLAGS_(argv1, argv2, expected, should_print_help) \ 5638 TestParsingFlags(sizeof(argv1)/sizeof(*argv1) - 1, argv1, \ 5639 sizeof(argv2)/sizeof(*argv2) - 1, argv2, \ 5640 expected, should_print_help) 5645 const char* argv[] = {
5649 const char* argv2[] = {
5658 const char* argv[] = {
5663 const char* argv2[] = {
5673 const char* argv[] = {
5679 const char* argv2[] = {
5690 const char* argv[] = {
5696 const char* argv2[] = {
5706 const char* argv[] = {
5708 "--gtest_filter=abc",
5712 const char* argv2[] = {
5722 const char* argv[] = {
5724 "--gtest_break_on_failure",
5728 const char* argv2[] = {
5738 const char* argv[] = {
5740 "--gtest_break_on_failure=0",
5744 const char* argv2[] = {
5754 const char* argv[] = {
5756 "--gtest_break_on_failure=f",
5760 const char* argv2[] = {
5770 const char* argv[] = {
5772 "--gtest_break_on_failure=F",
5776 const char* argv2[] = {
5787 const char* argv[] = {
5789 "--gtest_break_on_failure=1",
5793 const char* argv2[] = {
5803 const char* argv[] = {
5805 "--gtest_catch_exceptions",
5809 const char* argv2[] = {
5819 const char* argv[] = {
5821 "--gtest_death_test_use_fork",
5825 const char* argv2[] = {
5836 const char* argv[] = {
5843 const char* argv2[] = {
5853 const char* argv[] = {
5855 "--gtest_break_on_failure",
5861 const char* argv2[] = {
5875 const char* argv[] = {
5877 "--gtest_list_tests",
5881 const char* argv2[] = {
5891 const char* argv[] = {
5893 "--gtest_list_tests=1",
5897 const char* argv2[] = {
5907 const char* argv[] = {
5909 "--gtest_list_tests=0",
5913 const char* argv2[] = {
5923 const char* argv[] = {
5925 "--gtest_list_tests=f",
5929 const char* argv2[] = {
5939 const char* argv[] = {
5941 "--gtest_list_tests=F",
5945 const char* argv2[] = {
5955 const char* argv[] = {
5961 const char* argv2[] = {
5972 const char* argv[] = {
5974 "--gtest_output=xml",
5978 const char* argv2[] = {
5988 const char* argv[] = {
5990 "--gtest_output=xml:file",
5994 const char* argv2[] = {
6004 const char* argv[] = {
6006 "--gtest_output=xml:directory/path/",
6010 const char* argv2[] = {
6021 const char* argv[] = {
6023 "--gtest_print_time",
6027 const char* argv2[] = {
6037 const char* argv[] = {
6039 "--gtest_print_time=1",
6043 const char* argv2[] = {
6053 const char* argv[] = {
6055 "--gtest_print_time=0",
6059 const char* argv2[] = {
6069 const char* argv[] = {
6071 "--gtest_print_time=f",
6075 const char* argv2[] = {
6085 const char* argv[] = {
6087 "--gtest_print_time=F",
6091 const char* argv2[] = {
6101 const char* argv[] = {
6103 "--gtest_random_seed=1000",
6107 const char* argv2[] = {
6117 const char* argv[] = {
6119 "--gtest_repeat=1000",
6123 const char* argv2[] = {
6133 const char* argv[] = {
6135 "--gtest_also_run_disabled_tests",
6139 const char* argv2[] = {
6150 const char* argv[] = {
6152 "--gtest_also_run_disabled_tests=1",
6156 const char* argv2[] = {
6167 const char* argv[] = {
6169 "--gtest_also_run_disabled_tests=0",
6173 const char* argv2[] = {
6184 const char* argv[] = {
6190 const char* argv2[] = {
6200 const char* argv[] = {
6202 "--gtest_shuffle=0",
6206 const char* argv2[] = {
6217 const char* argv[] = {
6219 "--gtest_shuffle=1",
6223 const char* argv2[] = {
6233 const char* argv[] = {
6235 "--gtest_stack_trace_depth=5",
6239 const char* argv2[] = {
6248 const char* argv[] = {
6250 "--gtest_stream_result_to=localhost:1234",
6254 const char* argv2[] = {
6265 const char* argv[] = {
6267 "--gtest_throw_on_failure",
6271 const char* argv2[] = {
6281 const char* argv[] = {
6283 "--gtest_throw_on_failure=0",
6287 const char* argv2[] = {
6298 const char* argv[] = {
6300 "--gtest_throw_on_failure=1",
6304 const char* argv2[] = {
6312 #if GTEST_OS_WINDOWS 6315 const wchar_t* argv[] = {
6317 L
"--gtest_filter=Foo*",
6318 L
"--gtest_list_tests=1",
6319 L
"--gtest_break_on_failure",
6320 L
"--non_gtest_flag",
6324 const wchar_t* argv2[] = {
6326 L
"--non_gtest_flag",
6330 Flags expected_flags;
6332 expected_flags.
filter =
"Foo*";
6337 #endif // GTEST_OS_WINDOWS 6349 <<
"There should be no tests running at this point.";
6358 <<
"There should be no tests running at this point.";
6368 <<
"There is a test running so we should have a valid TestInfo.";
6370 <<
"Expected the name of the currently running test case.";
6372 <<
"Expected the name of the currently running test.";
6383 <<
"There is a test running so we should have a valid TestInfo.";
6385 <<
"Expected the name of the currently running test case.";
6387 <<
"Expected the name of the currently running test.";
6411 TEST(NestedTestingNamespaceTest, Success) {
6412 EXPECT_EQ(1, 1) <<
"This shouldn't fail.";
6416 TEST(NestedTestingNamespaceTest, Failure) {
6418 "This failure is expected.");
6440 TEST(StreamingAssertionsTest, Unconditional) {
6441 SUCCEED() <<
"expected success";
6443 "expected failure");
6445 "expected failure");
6450 # pragma option push -w-ccc -w-rch 6453 TEST(StreamingAssertionsTest, Truth) {
6457 "expected failure");
6459 "expected failure");
6462 TEST(StreamingAssertionsTest, Truth2) {
6466 "expected failure");
6468 "expected failure");
6476 TEST(StreamingAssertionsTest, IntegerEquals) {
6477 EXPECT_EQ(1, 1) <<
"unexpected failure";
6478 ASSERT_EQ(1, 1) <<
"unexpected failure";
6480 "expected failure");
6482 "expected failure");
6485 TEST(StreamingAssertionsTest, IntegerLessThan) {
6486 EXPECT_LT(1, 2) <<
"unexpected failure";
6487 ASSERT_LT(1, 2) <<
"unexpected failure";
6489 "expected failure");
6491 "expected failure");
6494 TEST(StreamingAssertionsTest, StringsEqual) {
6498 "expected failure");
6500 "expected failure");
6503 TEST(StreamingAssertionsTest, StringsNotEqual) {
6507 "expected failure");
6509 "expected failure");
6512 TEST(StreamingAssertionsTest, StringsEqualIgnoringCase) {
6516 "expected failure");
6518 "expected failure");
6521 TEST(StreamingAssertionsTest, StringNotEqualIgnoringCase) {
6525 "expected failure");
6527 "expected failure");
6530 TEST(StreamingAssertionsTest, FloatingPointEquals) {
6534 "expected failure");
6536 "expected failure");
6539 #if GTEST_HAS_EXCEPTIONS 6541 TEST(StreamingAssertionsTest, Throw) {
6542 EXPECT_THROW(ThrowAnInteger(),
int) <<
"unexpected failure";
6543 ASSERT_THROW(ThrowAnInteger(),
int) <<
"unexpected failure";
6545 "expected failure",
"expected failure");
6547 "expected failure",
"expected failure");
6550 TEST(StreamingAssertionsTest, NoThrow) {
6554 "expected failure",
"expected failure");
6556 "expected failure",
"expected failure");
6559 TEST(StreamingAssertionsTest, AnyThrow) {
6563 "expected failure",
"expected failure");
6565 "expected failure",
"expected failure");
6568 #endif // GTEST_HAS_EXCEPTIONS 6572 TEST(ColoredOutputTest, UsesColorsWhenGTestColorFlagIsYes) {
6575 SetEnv(
"TERM",
"xterm");
6579 SetEnv(
"TERM",
"dumb");
6584 TEST(ColoredOutputTest, UsesColorsWhenGTestColorFlagIsAliasOfYes) {
6585 SetEnv(
"TERM",
"dumb");
6597 TEST(ColoredOutputTest, UsesNoColorWhenGTestColorFlagIsNo) {
6600 SetEnv(
"TERM",
"xterm");
6604 SetEnv(
"TERM",
"dumb");
6609 TEST(ColoredOutputTest, UsesNoColorWhenGTestColorFlagIsInvalid) {
6610 SetEnv(
"TERM",
"xterm");
6622 TEST(ColoredOutputTest, UsesColorsWhenStdoutIsTty) {
6625 SetEnv(
"TERM",
"xterm");
6630 TEST(ColoredOutputTest, UsesColorsWhenTermSupportsColors) {
6633 #if GTEST_OS_WINDOWS 6636 SetEnv(
"TERM",
"dumb");
6642 SetEnv(
"TERM",
"xterm");
6648 SetEnv(
"TERM",
"dumb");
6651 SetEnv(
"TERM",
"emacs");
6654 SetEnv(
"TERM",
"vt100");
6657 SetEnv(
"TERM",
"xterm-mono");
6660 SetEnv(
"TERM",
"xterm");
6663 SetEnv(
"TERM",
"xterm-color");
6666 SetEnv(
"TERM",
"xterm-256color");
6669 SetEnv(
"TERM",
"screen");
6672 SetEnv(
"TERM",
"screen-256color");
6675 SetEnv(
"TERM",
"linux");
6678 SetEnv(
"TERM",
"cygwin");
6680 #endif // GTEST_OS_WINDOWS 6687 StaticAssertTypeEq<const int, const int>();
6691 template <
typename T>
6697 TEST(StaticAssertTypeEqTest, WorksInClass) {
6705 TEST(StaticAssertTypeEqTest, CompilesForEqualTypes) {
6706 StaticAssertTypeEq<int, IntAlias>();
6707 StaticAssertTypeEq<int*, IntAlias*>();
6710 TEST(GetCurrentOsStackTraceExceptTopTest, ReturnsTheStackTrace) {
6718 TEST(HasNonfatalFailureTest, ReturnsFalseWhenThereIsNoFailure) {
6724 TEST(HasNonfatalFailureTest, ReturnsFalseWhenThereIsOnlyFatalFailure) {
6726 const bool has_nonfatal_failure = HasNonfatalFailure();
6727 ClearCurrentTestPartResults();
6731 TEST(HasNonfatalFailureTest, ReturnsTrueWhenThereIsNonfatalFailure) {
6733 const bool has_nonfatal_failure = HasNonfatalFailure();
6734 ClearCurrentTestPartResults();
6738 TEST(HasNonfatalFailureTest, ReturnsTrueWhenThereAreFatalAndNonfatalFailures) {
6741 const bool has_nonfatal_failure = HasNonfatalFailure();
6742 ClearCurrentTestPartResults();
6751 TEST(HasNonfatalFailureTest, WorksOutsideOfTestBody) {
6755 TEST(HasNonfatalFailureTest, WorksOutsideOfTestBody2) {
6758 ClearCurrentTestPartResults();
6762 TEST(HasFailureTest, ReturnsFalseWhenThereIsNoFailure) {
6766 TEST(HasFailureTest, ReturnsTrueWhenThereIsFatalFailure) {
6768 const bool has_failure = HasFailure();
6769 ClearCurrentTestPartResults();
6773 TEST(HasFailureTest, ReturnsTrueWhenThereIsNonfatalFailure) {
6775 const bool has_failure = HasFailure();
6776 ClearCurrentTestPartResults();
6780 TEST(HasFailureTest, ReturnsTrueWhenThereAreFatalAndNonfatalFailures) {
6783 const bool has_failure = HasFailure();
6784 ClearCurrentTestPartResults();
6791 TEST(HasFailureTest, WorksOutsideOfTestBody) {
6795 TEST(HasFailureTest, WorksOutsideOfTestBody2) {
6798 ClearCurrentTestPartResults();
6806 : on_start_counter_(on_start_counter),
6807 is_destroyed_(is_destroyed) {}
6811 *is_destroyed_ =
true;
6816 if (on_start_counter_ != NULL)
6817 (*on_start_counter_)++;
6826 TEST(TestEventListenersTest, ConstructionWorks) {
6836 TEST(TestEventListenersTest, DestructionWorks) {
6837 bool default_result_printer_is_destroyed =
false;
6838 bool default_xml_printer_is_destroyed =
false;
6839 bool extra_listener_is_destroyed =
false;
6841 NULL, &default_result_printer_is_destroyed);
6843 NULL, &default_xml_printer_is_destroyed);
6845 NULL, &extra_listener_is_destroyed);
6850 default_result_printer);
6852 default_xml_printer);
6853 listeners.
Append(extra_listener);
6862 TEST(TestEventListenersTest, Append) {
6863 int on_start_counter = 0;
6864 bool is_destroyed =
false;
6868 listeners.
Append(listener);
6882 : vector_(vector), id_(id) {}
6886 vector_->push_back(GetEventDescription(
"OnTestProgramStart"));
6890 vector_->push_back(GetEventDescription(
"OnTestProgramEnd"));
6895 vector_->push_back(GetEventDescription(
"OnTestIterationStart"));
6900 vector_->push_back(GetEventDescription(
"OnTestIterationEnd"));
6906 message << id_ <<
"." << method;
6916 TEST(EventListenerTest, AppendKeepsOrder) {
6917 std::vector<std::string>
vec;
6926 EXPECT_STREQ(
"1st.OnTestProgramStart", vec[0].c_str());
6927 EXPECT_STREQ(
"2nd.OnTestProgramStart", vec[1].c_str());
6928 EXPECT_STREQ(
"3rd.OnTestProgramStart", vec[2].c_str());
6942 EXPECT_STREQ(
"1st.OnTestIterationStart", vec[0].c_str());
6943 EXPECT_STREQ(
"2nd.OnTestIterationStart", vec[1].c_str());
6944 EXPECT_STREQ(
"3rd.OnTestIterationStart", vec[2].c_str());
6950 EXPECT_STREQ(
"3rd.OnTestIterationEnd", vec[0].c_str());
6951 EXPECT_STREQ(
"2nd.OnTestIterationEnd", vec[1].c_str());
6952 EXPECT_STREQ(
"1st.OnTestIterationEnd", vec[2].c_str());
6957 TEST(TestEventListenersTest, Release) {
6958 int on_start_counter = 0;
6959 bool is_destroyed =
false;
6966 listeners.
Append(listener);
6978 TEST(EventListenerTest, SuppressEventForwarding) {
6979 int on_start_counter = 0;
6983 listeners.
Append(listener);
6994 TEST(EventListenerDeathTest, EventsNotForwardedInDeathTestSubprecesses) {
6998 "expected failure");
7004 TEST(EventListenerTest, default_result_printer) {
7005 int on_start_counter = 0;
7006 bool is_destroyed =
false;
7035 TEST(EventListenerTest, RemovingDefaultResultPrinterWorks) {
7036 int on_start_counter = 0;
7037 bool is_destroyed =
false;
7063 TEST(EventListenerTest, default_xml_generator) {
7064 int on_start_counter = 0;
7065 bool is_destroyed =
false;
7094 TEST(EventListenerTest, RemovingDefaultXmlGeneratorWorks) {
7095 int on_start_counter = 0;
7096 bool is_destroyed =
false;
7129 "An expected failure");
7135 "An expected failure");
7137 "An expected failure");
7142 "An expected failure");
7147 "An expected failure");
7151 "An expected failure");
7153 "An expected failure");
7158 "An expected failure");
7162 "An expected failure");
7164 "An expected failure");
7175 TEST(IsAProtocolMessageTest, ValueIsCompileTimeConstant) {
7183 TEST(IsAProtocolMessageTest, ValueIsTrueWhenTypeIsAProtocolMessage) {
7190 TEST(IsAProtocolMessageTest, ValueIsFalseWhenTypeIsNotAProtocolMessage) {
7203 TEST(RemoveReferenceTest, DoesNotAffectNonReferenceType) {
7209 TEST(RemoveReferenceTest, RemovesReference) {
7216 template <
typename T1,
typename T2>
7221 TEST(RemoveReferenceTest, MacroVersion) {
7222 TestGTestRemoveReference<int, int>();
7223 TestGTestRemoveReference<const char, const char&>();
7228 TEST(RemoveConstTest, DoesNotAffectNonConstType) {
7234 TEST(RemoveConstTest, RemovesConst) {
7242 template <
typename T1,
typename T2>
7247 TEST(RemoveConstTest, MacroVersion) {
7248 TestGTestRemoveConst<int, int>();
7249 TestGTestRemoveConst<double&, double&>();
7250 TestGTestRemoveConst<char, const char>();
7255 template <
typename T1,
typename T2>
7260 TEST(RemoveReferenceToConstTest, Works) {
7261 TestGTestRemoveReferenceAndConst<int, int>();
7262 TestGTestRemoveReferenceAndConst<double, double&>();
7263 TestGTestRemoveReferenceAndConst<char, const char>();
7264 TestGTestRemoveReferenceAndConst<char, const char&>();
7265 TestGTestRemoveReferenceAndConst<const char*, const char*>();
7269 TEST(AddReferenceTest, DoesNotAffectReferenceType) {
7275 TEST(AddReferenceTest, AddsReference) {
7282 template <
typename T1,
typename T2>
7287 TEST(AddReferenceTest, MacroVersion) {
7288 TestGTestAddReference<int&, int>();
7289 TestGTestAddReference<const char&, const char&>();
7294 template <
typename T1,
typename T2>
7299 TEST(GTestReferenceToConstTest, Works) {
7300 TestGTestReferenceToConst<const char&, char>();
7301 TestGTestReferenceToConst<const int&, const int>();
7302 TestGTestReferenceToConst<const double&, double>();
7303 TestGTestReferenceToConst<const std::string&, const std::string&>();
7307 TEST(ImplicitlyConvertibleTest, ValueIsCompileTimeConstant) {
7315 TEST(ImplicitlyConvertibleTest, ValueIsTrueWhenConvertible) {
7328 TEST(ImplicitlyConvertibleTest, ValueIsFalseWhenNotConvertible) {
7340 TEST(IsContainerTestTest, WorksForNonContainer) {
7346 TEST(IsContainerTestTest, WorksForContainer) {
7355 TEST(ArrayEqTest, WorksForDegeneratedArrays) {
7360 TEST(ArrayEqTest, WorksForOneDimensionalArrays) {
7362 const int a[] = { 0, 1 };
7363 long b[] = { 0, 1 };
7372 TEST(ArrayEqTest, WorksForTwoDimensionalArrays) {
7373 const char a[][3] = {
"hi",
"lo" };
7374 const char b[][3] = {
"hi",
"lo" };
7375 const char c[][3] = {
"hi",
"li" };
7386 TEST(ArrayAwareFindTest, WorksForOneDimensionalArray) {
7387 const char a[] =
"hello";
7392 TEST(ArrayAwareFindTest, WorksForTwoDimensionalArray) {
7393 int a[][2] = { { 0, 1 }, { 2, 3 }, { 4, 5 } };
7394 const int b[2] = { 2, 3 };
7397 const int c[2] = { 6, 7 };
7403 TEST(CopyArrayTest, WorksForDegeneratedArrays) {
7409 TEST(CopyArrayTest, WorksForOneDimensionalArrays) {
7410 const char a[3] =
"hi";
7412 #ifndef __BORLANDC__ // C++Builder cannot compile some array size deductions. 7422 TEST(CopyArrayTest, WorksForTwoDimensionalArrays) {
7423 const int a[2][3] = { { 0, 1, 2 }, { 3, 4, 5 } };
7425 #ifndef __BORLANDC__ // C++Builder cannot compile some array size deductions. 7437 TEST(NativeArrayTest, ConstructorFromArrayWorks) {
7438 const int a[3] = { 0, 1, 2 };
7444 TEST(NativeArrayTest, CreatesAndDeletesCopyOfArrayWhenAskedTo) {
7445 typedef int Array[2];
7446 Array*
a =
new Array[1];
7459 TEST(NativeArrayTest, TypeMembersAreCorrect) {
7460 StaticAssertTypeEq<char, NativeArray<char>::value_type>();
7461 StaticAssertTypeEq<int[2], NativeArray<int[2]>::value_type>();
7463 StaticAssertTypeEq<const char*, NativeArray<char>::const_iterator>();
7464 StaticAssertTypeEq<const bool(*)[2], NativeArray<bool[2]>::const_iterator>();
7467 TEST(NativeArrayTest, MethodsWork) {
7468 const int a[3] = { 0, 1, 2 };
7487 const int b1[3] = { 0, 1, 1 };
7488 const int b2[4] = { 0, 1, 2, 3 };
7493 TEST(NativeArrayTest, WorksForTwoDimensionalArray) {
7494 const char a[2][3] = {
"hi",
"lo" };
7502 TEST(SkipPrefixTest, SkipsWhenPrefixMatches) {
7503 const char*
const str =
"hello";
7505 const char*
p =
str;
7514 TEST(SkipPrefixTest, DoesNotSkipWhenPrefixDoesNotMatch) {
7515 const char*
const str =
"world";
7517 const char*
p =
str;
GTEST_API_ bool g_help_flag
void SetDefaultResultPrinter(TestEventListener *listener)
UNITTEST_START const char * values[]
class UnitTestImpl * GetUnitTestImpl()
#define EXPECT_STRCASENE(s1, s2)
GTEST_API_ 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
#define EXPECT_PRED3(pred, v1, v2, v3)
int GetRandomSeedFromFlag(Int32 random_seed_flag)
static void SuppressEventForwarding(TestEventListeners *listeners)
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)
Environment * AddGlobalTestEnvironment(Environment *env)
GTEST_API_ std::string GetCapturedStdout()
#define EXPECT_STRNE(s1, s2)
#define EXPECT_PRED_FORMAT2(pred_format, v1, v2)
const char * summary() const
GTEST_API_ std::string GetCurrentOsStackTraceExceptTop(UnitTest *unit_test, int skip_count)
GTEST_API_ std::string FormatEpochTimeInMillisAsIso8601(TimeInMillis ms)
#define ASSERT_LE(val1, val2)
E GetElementOr(const std::vector< E > &v, int i, E default_value)
static Flags DeathTestUseFork(bool death_test_use_fork)
GTEST_API_ AssertionResult AssertionFailure()
#define EXPECT_THROW(statement, expected_exception)
#define EXPECT_NONFATAL_FAILURE(statement, substr)
const TestInfo * GetTestInfo(int i) const
static void SetUpTestCase()
bool operator>(const TransformStorage &lhs, const TransformStorage &rhs)
GTEST_API_ std::vector< EditType > CalculateOptimalEdits(const std::vector< size_t > &left, const std::vector< size_t > &right)
#define ASSERT_THROW(statement, expected_exception)
static Flags StackTraceDepth(Int32 stack_trace_depth)
#define ASSERT_PRED3(pred, v1, v2, v3)
#define EXPECT_LE(val1, val2)
#define GTEST_DISABLE_MSC_WARNINGS_POP_()
#define ASSERT_NE(val1, val2)
class GTEST_API_ testing::internal::ScopedTrace GTEST_ATTRIBUTE_UNUSED_
static Flags Output(const char *output)
#define EXPECT_FLOAT_EQ(expected, actual)
const char * message() const
int GetNextRandomSeed(int seed)
StaticAssertTypeEqTestHelper()
#define ASSERT_GE(val1, val2)
static const TestResult * GetTestResult(const TestInfo *test_info)
#define ASSERT_PRED1(pred, v1)
static bool EndsWithCaseInsensitive(const std::string &str, const std::string &suffix)
GTEST_API_ bool ShouldUseColor(bool stdout_is_tty)
TestEventListener * Release(TestEventListener *listener)
GTEST_API_ bool ShouldRunTestOnShard(int total_shards, int shard_index, int test_id)
virtual void OnTestProgramStart(const UnitTest &)
MyTypeInNameSpace2(int an_x)
TestEventListener * repeater()
void SuppressEventForwarding()
virtual void OnTestIterationStart(const UnitTest &unit_test, int iteration)=0
#define GTEST_TEST_PARSING_FLAGS_(argv1, argv2, expected, should_print_help)
#define EXPECT_GE(val1, val2)
bool operator==(T *ptr, const linked_ptr< T > &x)
static Flags BreakOnFailure(bool break_on_failure)
#define ADD_FAILURE_AT(file, line)
#define GTEST_IS_NULL_LITERAL_(x)
#define ASSERT_EQ(val1, val2)
static TestEventListener * GetRepeater(TestEventListeners *listeners)
const_iterator begin() const
TestEventListener * default_xml_generator() const
GTEST_TEST(AlternativeNameTest, Works)
GTEST_API_ bool SkipPrefix(const char *prefix, const char **pstr)
GTEST_API_ std::string FormatTimeInMillisAsSeconds(TimeInMillis ms)
static const TestInfo * GetTestInfo(const char *test_name)
const char * stream_result_to
static Flags AlsoRunDisabledTests(bool also_run_disabled_tests)
#define GTEST_USE_UNPROTECTED_COMMA_
const TestProperty & GetTestProperty(int i) const
static Flags StreamResultTo(const char *stream_result_to)
void Append(TestEventListener *listener)
static void ClearTestPartResults(TestResult *test_result)
GTEST_API_ bool ShouldShard(const char *total_shards_str, const char *shard_index_str, bool in_subprocess_for_death_test)
GTEST_API_ std::string CodePointToUtf8(UInt32 code_point)
static void FailFatally()
#define ASSERT_STRCASEEQ(expected, actual)
GTEST_API_ void CaptureStdout()
#define EXPECT_ANY_THROW(statement)
TypeWithSize< 8 >::Int TimeInMillis
TFSIMD_FORCE_INLINE const tfScalar & y() const
std::ostream & operator<<(std::ostream &os, const Message &sb)
#define EXPECT_LT(val1, val2)
#define EXPECT_DOUBLE_EQ(expected, actual)
int total_test_count() const
static void CheckFlags(const Flags &expected)
UNITTEST_START int result
#define EXPECT_FATAL_FAILURE_ON_ALL_THREADS(statement, substr)
#define EXPECT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5)
#define EXPECT_FATAL_FAILURE(statement, substr)
REGISTER_TYPED_TEST_CASE_P(TypeParamTest, TestA, TestB)
#define ASSERT_STREQ(expected, actual)
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)
#define EXPECT_NO_FATAL_FAILURE(statement)
static void SetDefaultXmlGenerator(TestEventListeners *listeners, TestEventListener *listener)
internal::TimeInMillis TimeInMillis
UnitTestRecordPropertyTestHelper()
static bool EventForwardingEnabled(const TestEventListeners &listeners)
void TestGTestReferenceToConst()
bool ArrayEq(const T *lhs, size_t size, const U *rhs)
TypeWithSize< 4 >::UInt UInt32
#define EXPECT_PRED1(pred, v1)
TYPED_TEST(TypedTest, TestA)
#define EXPECT_GT(val1, val2)
TEST_F(ListenerTest, DoesFoo)
TypeWithSize< 4 >::Int Int32
#define GTEST_ASSERT_EQ(expected, actual)
TYPED_TEST_CASE(TypedTest, MyTypes)
#define ASSERT_PRED_FORMAT1(pred_format, v1)
GTEST_API_ TypeId GetTestTypeId()
UNITTEST_START char * output
#define ASSERT_NO_THROW(statement)
const char * name() const
#define EXPECT_NEAR(val1, val2, abs_error)
#define GTEST_FLAG_PREFIX_UPPER_
virtual void OnTestIterationEnd(const UnitTest &unit_test, int iteration)=0
#define GTEST_COMPILE_ASSERT_(expr, msg)
virtual void OnTestProgramEnd(const UnitTest &unit_test)=0
bool GTEST_FLAG(internal_skip_environment_and_ad_hoc_tests)
#define ASSERT_TRUE(condition)
const char * message() const
GTEST_API_ AssertionResult AssertionSuccess()
TestListener(int *on_start_counter, bool *is_destroyed)
static void SetUpTestCase()
#define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
static bool CaseInsensitiveWideCStringEquals(const wchar_t *lhs, const wchar_t *rhs)
virtual void OnTestProgramStart(const UnitTest &)
#define GTEST_ASSERT_LT(val1, val2)
#define GTEST_CHECK_(condition)
#define EXPECT_NE(expected, actual)
void SetDefaultXmlGenerator(TestEventListener *listener)
const int kMaxStackTraceDepth
bool also_run_disabled_tests
UInt32 Generate(UInt32 range)
#define ASSERT_NO_FATAL_FAILURE(statement)
TYPED_TEST_CASE_P(TypeParamTest)
#define GTEST_ASSERT_GT(val1, val2)
GTEST_API_ const TypeId kTestTypeIdInGoogleTest
static void RecordProperty(TestResult *test_result, const std::string &xml_element, const TestProperty &property)
GTEST_API_ bool AlwaysTrue()
const char * file_name() const
void TestGTestRemoveConst()
#define ASSERT_DOUBLE_EQ(expected, actual)
static void TearDownTestCase()
std::vector< std::string > * vector_
#define EXPECT_STREQ(expected, actual)
void UnitTestRecordProperty(const char *key, const std::string &value)
#define GTEST_ASSERT_NE(val1, val2)
TFSIMD_FORCE_INLINE const tfScalar & x() const
static void SetDefaultResultPrinter(TestEventListeners *listeners, TestEventListener *listener)
static bool HasNonfatalFailureHelper()
#define EXPECT_STRCASEEQ(expected, actual)
std::string GetString() const
void TestGTestRemoveReference()
GTEST_API_ AssertionResult IsSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
GTEST_API_ TimeInMillis GetTimeInMillis()
MyTypeInNameSpace1(int an_x)
const char * test_case_name() const
const TestPartResult & GetTestPartResult(int index) const
const TestInfo * current_test_info() const GTEST_LOCK_EXCLUDED_(mutex_)
static void AssertStringArrayEq(size_t size1, CharType **array1, size_t size2, CharType **array2)
GTEST_API_ std::string WideStringToUtf8(const wchar_t *str, int num_chars)
bool EventForwardingEnabled() const
static Flags Shuffle(bool shuffle)
const TestResult & ad_hoc_test_result() const
#define EXPECT_EQ(expected, actual)
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)
virtual void OnTestIterationStart(const UnitTest &, int)
TYPED_TEST_P(TypeParamTest, TestA)
#define ASSERT_NEAR(val1, val2, abs_error)
#define EXPECT_PRED_FORMAT1(pred_format, v1)
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)
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)
const Bits & bits() const
#define ASSERT_FLOAT_EQ(expected, actual)
#define ASSERT_GT(val1, val2)
GTEST_API_ void ParseGoogleTestFlagsOnly(int *argc, char **argv)
INSTANTIATE_TYPED_TEST_CASE_P(My, TypeParamTest, MyTypes)
void Shuffle(internal::Random *random, std::vector< E > *v)
#define ASSERT_STRNE(s1, s2)
GTEST_API_ std::string CreateUnifiedDiff(const std::vector< std::string > &left, const std::vector< std::string > &right, size_t context=2)
virtual void OnTestIterationEnd(const UnitTest &, int)
#define ASSERT_PRED_FORMAT4(pred_format, v1, v2, v3, v4)
std::string GetEventDescription(const char *method)
const_iterator end() const
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
bool StaticAssertTypeEq()
void TestGTestAddReference()
virtual void OnTestProgramStart(const UnitTest &unit_test)=0
GTEST_API_ AssertionResult DoubleLE(const char *expr1, const char *expr2, double val1, double val2)
#define EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(statement, substr)
UNITTEST_START int * value
#define ASSERT_STRCASENE(s1, s2)
#define GTEST_ASSERT_GE(val1, val2)
#define FRIEND_TEST(test_case_name, test_name)
const TestResult * result() const
static bool HasFailureHelper()
#define EXPECT_TRUE(condition)
void CopyArray(const T *from, size_t size, U *to)
#define ASSERT_LT(val1, val2)
GTEST_API_ AssertionResult IsNotSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
static UnitTest * GetInstance()
TestEventListener * default_result_printer() const
static void TearDownTestCase()
TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded)
Iter ArrayAwareFind(Iter begin, Iter end, const Element &elem)
#define ASSERT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5)
static Flags CatchExceptions(bool catch_exceptions)
#define GTEST_ASSERT_LE(val1, val2)
bool operator!=(T *ptr, const linked_ptr< T > &x)
#define EXPECT_NO_THROW(statement)
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
#define EXPECT_FALSE(condition)
GTEST_API_ Int32 Int32FromEnvOrDie(const char *env_var, Int32 default_val)
const BiggestInt kMaxBiggestInt
SequenceTestingListener(std::vector< std::string > *vector, const char *id)
static Flags ListTests(bool list_tests)
#define ASSERT_PRED2(pred, v1, v2)
static std::string ShowWideCString(const wchar_t *wide_c_str)
IMETHOD void random(Vector &a)
#define ASSERT_FALSE(condition)
IsContainer IsContainerTest(int, typename C::iterator *=NULL, typename C::const_iterator *=NULL)
static Flags RandomSeed(Int32 random_seed)
#define EXPECT_PRED2(pred, v1, v2)
const TestCase * current_test_case() const GTEST_LOCK_EXCLUDED_(mutex_)
static const UInt32 kMaxRange
#define ASSERT_ANY_THROW(statement)
static bool HasNonfatalFailure()
#define GTEST_FLAG_PREFIX_
void TestGTestRemoveReferenceAndConst()
#define EXPECT_PRED_FORMAT4(pred_format, v1, v2, v3, v4)
GTEST_API_ bool ParseInt32Flag(const char *str, const char *flag, Int32 *value)
TEST(IsXDigitTest, WorksForNarrowAscii)
static Flags PrintTime(bool print_time)
GTEST_API_ AssertionResult FloatLE(const char *expr1, const char *expr2, float val1, float val2)
#define ASSERT_PRED_FORMAT2(pred_format, v1, v2)