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, 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);
290 #if GTEST_HAS_STREAM_REDIRECTION 295 #if GTEST_IS_THREADSAFE 296 using testing::internal::ThreadWithParam;
305 for (
size_t i = 0; i < vector.size(); i++) {
306 os << vector[i] <<
" ";
315 TEST(GetRandomSeedFromFlagTest, HandlesZero) {
321 TEST(GetRandomSeedFromFlagTest, PreservesValidSeed) {
329 TEST(GetRandomSeedFromFlagTest, NormalizesInvalidSeed) {
339 TEST(GetNextRandomSeedTest, WorksForValidInput) {
352 static void ClearCurrentTestPartResults() {
359 TEST(GetTypeIdTest, ReturnsSameValueForSameType) {
360 EXPECT_EQ(GetTypeId<int>(), GetTypeId<int>());
361 EXPECT_EQ(GetTypeId<Test>(), GetTypeId<Test>());
364 class SubClassOfTest :
public Test {};
365 class AnotherSubClassOfTest :
public Test {};
367 TEST(GetTypeIdTest, ReturnsDifferentValuesForDifferentTypes) {
368 EXPECT_NE(GetTypeId<int>(), GetTypeId<const int>());
369 EXPECT_NE(GetTypeId<int>(), GetTypeId<char>());
373 EXPECT_NE(GetTypeId<AnotherSubClassOfTest>(), GetTypeId<SubClassOfTest>());
378 TEST(GetTestTypeIdTest, ReturnsTheSameValueInsideOrOutsideOfGoogleTest) {
384 TEST(FormatTimeInMillisAsSecondsTest, FormatsZero) {
388 TEST(FormatTimeInMillisAsSecondsTest, FormatsPositiveNumber) {
396 TEST(FormatTimeInMillisAsSecondsTest, FormatsNegativeNumber) {
410 class FormatEpochTimeInMillisAsIso8601Test :
public Test {
418 virtual void SetUp() {
421 # pragma warning(push) // Saves the current warning state. 422 # pragma warning(disable:4996) // Temporarily disables warning 4996 427 saved_tz_ = strdup(getenv(
"TZ"));
428 # pragma warning(pop) // Restores the warning state again. 431 saved_tz_ = strdup(getenv(
"TZ"));
437 SetTimeZone(
"UTC+00");
440 virtual void TearDown() {
441 SetTimeZone(saved_tz_);
442 free(const_cast<char*>(saved_tz_));
446 static void SetTimeZone(
const char* time_zone) {
455 _putenv(env_var.c_str());
456 # pragma warning(push) // Saves the current warning state. 457 # pragma warning(disable:4996) // Temporarily disables warning 4996 460 # pragma warning(pop) // Restores the warning state again. 463 setenv((
"TZ"), time_zone, 1);
471 const char* saved_tz_;
474 const TimeInMillis FormatEpochTimeInMillisAsIso8601Test::kMillisPerSec;
476 TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsTwoDigitSegments) {
481 TEST_F(FormatEpochTimeInMillisAsIso8601Test, MillisecondsDoNotAffectResult) {
483 "2011-10-31T18:52:42",
487 TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsLeadingZeroes) {
492 TEST_F(FormatEpochTimeInMillisAsIso8601Test, Prints24HourTime) {
497 TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsEpochStart) {
501 #if GTEST_CAN_COMPARE_NULL 505 # pragma option push -w-ccc -w-rch 510 TEST(NullLiteralTest, IsTrueForNullLiterals) {
519 TEST(NullLiteralTest, IsFalseForNonNullLiterals) {
531 #endif // GTEST_CAN_COMPARE_NULL 536 TEST(CodePointToUtf8Test, CanEncodeNul) {
541 TEST(CodePointToUtf8Test, CanEncodeAscii) {
550 TEST(CodePointToUtf8Test, CanEncode8To11Bits) {
564 TEST(CodePointToUtf8Test, CanEncode12To16Bits) {
574 #if !GTEST_WIDE_STRING_USES_UTF16_ 581 TEST(CodePointToUtf8Test, CanEncode17To21Bits) {
593 TEST(CodePointToUtf8Test, CanEncodeInvalidCodePoint) {
597 #endif // !GTEST_WIDE_STRING_USES_UTF16_ 602 TEST(WideStringToUtf8Test, CanEncodeNul) {
608 TEST(WideStringToUtf8Test, CanEncodeAscii) {
617 TEST(WideStringToUtf8Test, CanEncode8To11Bits) {
623 const wchar_t s[] = { 0x576,
'\0' };
630 TEST(WideStringToUtf8Test, CanEncode12To16Bits) {
632 const wchar_t s1[] = { 0x8D3,
'\0' };
637 const wchar_t s2[] = { 0xC74D,
'\0' };
643 TEST(WideStringToUtf8Test, StopsOnNulCharacter) {
649 TEST(WideStringToUtf8Test, StopsWhenLengthLimitReached) {
653 #if !GTEST_WIDE_STRING_USES_UTF16_ 657 TEST(WideStringToUtf8Test, CanEncode17To21Bits) {
668 TEST(WideStringToUtf8Test, CanEncodeInvalidCodePoint) {
672 #else // !GTEST_WIDE_STRING_USES_UTF16_ 675 TEST(WideStringToUtf8Test, CanEncodeValidUtf16SUrrogatePairs) {
676 const wchar_t s[] = { 0xD801, 0xDC00,
'\0' };
682 TEST(WideStringToUtf8Test, CanEncodeInvalidUtf16SurrogatePair) {
684 const wchar_t s1[] = { 0xD800,
'\0' };
687 const wchar_t s2[] = { 0xD800,
'M',
'\0' };
690 const wchar_t s3[] = { 0xDC00,
'P',
'Q',
'R',
'\0' };
693 #endif // !GTEST_WIDE_STRING_USES_UTF16_ 696 #if !GTEST_WIDE_STRING_USES_UTF16_ 697 TEST(WideStringToUtf8Test, ConcatenatesCodepointsCorrectly) {
698 const wchar_t s[] = { 0x108634, 0xC74D,
'\n', 0x576, 0x8D3, 0x108634,
'\0'};
709 TEST(WideStringToUtf8Test, ConcatenatesCodepointsCorrectly) {
710 const wchar_t s[] = { 0xC74D,
'\n', 0x576, 0x8D3,
'\0'};
712 "\xEC\x9D\x8D" "\n" "\xD5\xB6" "\xE0\xA3\x93",
715 #endif // !GTEST_WIDE_STRING_USES_UTF16_ 719 TEST(RandomDeathTest, GeneratesCrashesOnInvalidRange) {
723 "Cannot generate a number in the range \\[0, 0\\)");
726 "Generation of a number in \\[0, 2147483649\\) was requested, " 727 "but this can only generate numbers in \\[0, 2147483648\\)");
730 TEST(RandomTest, GeneratesNumbersWithinRange) {
731 const UInt32 kRange = 10000;
733 for (
int i = 0; i < 10; i++) {
738 for (
int i = 0; i < 10; i++) {
739 EXPECT_LT(random2.Generate(kRange), kRange) <<
" for iteration " << i;
743 TEST(RandomTest, RepeatsWhenReseeded) {
744 const int kSeed = 123;
745 const int kArraySize = 10;
746 const UInt32 kRange = 10000;
747 UInt32 values[kArraySize];
750 for (
int i = 0; i < kArraySize; i++) {
751 values[i] = random.
Generate(kRange);
755 for (
int i = 0; i < kArraySize; i++) {
764 static bool IsPositive(
int n) {
return n > 0; }
782 static int g_sum = 0;
783 static void Accumulate(
int n) { g_sum += n; }
825 "Invalid shuffle range start -1: must be in range \\[0, 3\\]");
828 "Invalid shuffle range start 4: must be in range \\[0, 3\\]");
831 "Invalid shuffle range finish 2: must be in range \\[3, 3\\]");
834 "Invalid shuffle range finish 4: must be in range \\[3, 3\\]");
837 class VectorShuffleTest :
public Test {
839 static const int kVectorSize = 20;
841 VectorShuffleTest() : random_(1) {
842 for (
int i = 0; i < kVectorSize; i++) {
843 vector_.push_back(i);
848 if (kVectorSize != static_cast<int>(vector.size())) {
852 bool found_in_vector[kVectorSize] = {
false };
853 for (
size_t i = 0; i < vector.size(); i++) {
854 const int e = vector[i];
855 if (e < 0 || e >= kVectorSize || found_in_vector[e]) {
858 found_in_vector[e] =
true;
866 static bool VectorIsNotCorrupt(
const TestingVector& vector) {
867 return !VectorIsCorrupt(vector);
870 static bool RangeIsShuffled(
const TestingVector& vector,
int begin,
int end) {
871 for (
int i = begin; i <
end; i++) {
872 if (i != vector[i]) {
879 static bool RangeIsUnshuffled(
881 return !RangeIsShuffled(vector, begin, end);
885 return RangeIsShuffled(vector, 0, static_cast<int>(vector.size()));
888 static bool VectorIsUnshuffled(
const TestingVector& vector) {
889 return !VectorIsShuffled(vector);
896 const int VectorShuffleTest::kVectorSize;
898 TEST_F(VectorShuffleTest, HandlesEmptyRange) {
905 ShuffleRange(&random_, kVectorSize/2, kVectorSize/2, &vector_);
910 ShuffleRange(&random_, kVectorSize - 1, kVectorSize - 1, &vector_);
915 ShuffleRange(&random_, kVectorSize, kVectorSize, &vector_);
920 TEST_F(VectorShuffleTest, HandlesRangeOfSizeOne) {
927 ShuffleRange(&random_, kVectorSize/2, kVectorSize/2 + 1, &vector_);
932 ShuffleRange(&random_, kVectorSize - 1, kVectorSize, &vector_);
940 TEST_F(VectorShuffleTest, ShufflesEntireVector) {
948 EXPECT_NE(kVectorSize - 1, vector_[kVectorSize - 1]);
951 TEST_F(VectorShuffleTest, ShufflesStartOfVector) {
952 const int kRangeSize = kVectorSize/2;
958 EXPECT_PRED3(RangeIsUnshuffled, vector_, kRangeSize, kVectorSize);
961 TEST_F(VectorShuffleTest, ShufflesEndOfVector) {
962 const int kRangeSize = kVectorSize / 2;
963 ShuffleRange(&random_, kRangeSize, kVectorSize, &vector_);
966 EXPECT_PRED3(RangeIsUnshuffled, vector_, 0, kRangeSize);
967 EXPECT_PRED3(RangeIsShuffled, vector_, kRangeSize, kVectorSize);
970 TEST_F(VectorShuffleTest, ShufflesMiddleOfVector) {
971 int kRangeSize = kVectorSize/3;
972 ShuffleRange(&random_, kRangeSize, 2*kRangeSize, &vector_);
975 EXPECT_PRED3(RangeIsUnshuffled, vector_, 0, kRangeSize);
976 EXPECT_PRED3(RangeIsShuffled, vector_, kRangeSize, 2*kRangeSize);
977 EXPECT_PRED3(RangeIsUnshuffled, vector_, 2*kRangeSize, kVectorSize);
980 TEST_F(VectorShuffleTest, ShufflesRepeatably) {
982 for (
int i = 0; i < kVectorSize; i++) {
983 vector2.push_back(i);
986 random_.Reseed(1234);
988 random_.Reseed(1234);
994 for (
int i = 0; i < kVectorSize; i++) {
995 EXPECT_EQ(vector_[i], vector2[i]) <<
" where i is " << i;
1001 TEST(AssertHelperTest, AssertHelperIsSmall) {
1008 TEST(StringTest, EndsWithCaseInsensitive) {
1022 static const wchar_t*
const kNull = NULL;
1025 TEST(StringTest, CaseInsensitiveWideCStringEquals) {
1036 #if GTEST_OS_WINDOWS 1039 TEST(StringTest, ShowWideCString) {
1046 # if GTEST_OS_WINDOWS_MOBILE 1047 TEST(StringTest, AnsiAndUtf16Null) {
1048 EXPECT_EQ(NULL, String::AnsiToUtf16(NULL));
1049 EXPECT_EQ(NULL, String::Utf16ToAnsi(NULL));
1052 TEST(StringTest, AnsiAndUtf16ConvertBasic) {
1053 const char* ansi = String::Utf16ToAnsi(L
"str");
1056 const WCHAR* utf16 = String::AnsiToUtf16(
"str");
1057 EXPECT_EQ(0, wcsncmp(L
"str", utf16, 3));
1061 TEST(StringTest, AnsiAndUtf16ConvertPathChars) {
1062 const char* ansi = String::Utf16ToAnsi(L
".:\\ \"*?");
1065 const WCHAR* utf16 = String::AnsiToUtf16(
".:\\ \"*?");
1066 EXPECT_EQ(0, wcsncmp(L
".:\\ \"*?", utf16, 3));
1069 # endif // GTEST_OS_WINDOWS_MOBILE 1071 #endif // GTEST_OS_WINDOWS 1074 TEST(TestPropertyTest, StringValue) {
1081 TEST(TestPropertyTest, ReplaceStringValue) {
1084 property.SetValue(
"2");
1091 static void AddFatalFailure() {
1092 FAIL() <<
"Expected fatal failure.";
1095 static void AddNonfatalFailure() {
1099 class ScopedFakeTestPartResultReporterTest :
public Test {
1105 static void AddFailure(FailureMode failure) {
1106 if (failure == FATAL_FAILURE) {
1109 AddNonfatalFailure();
1116 TEST_F(ScopedFakeTestPartResultReporterTest, InterceptsTestFailures) {
1122 AddFailure(NONFATAL_FAILURE);
1123 AddFailure(FATAL_FAILURE);
1131 TEST_F(ScopedFakeTestPartResultReporterTest, DeprecatedConstructor) {
1136 AddFailure(NONFATAL_FAILURE);
1141 #if GTEST_IS_THREADSAFE 1143 class ScopedFakeTestPartResultReporterWithThreadsTest
1144 :
public ScopedFakeTestPartResultReporterTest {
1146 static void AddFailureInOtherThread(FailureMode failure) {
1147 ThreadWithParam<FailureMode> thread(&AddFailure, failure, NULL);
1152 TEST_F(ScopedFakeTestPartResultReporterWithThreadsTest,
1153 InterceptsTestFailuresInAllThreads) {
1158 AddFailure(NONFATAL_FAILURE);
1159 AddFailure(FATAL_FAILURE);
1160 AddFailureInOtherThread(NONFATAL_FAILURE);
1161 AddFailureInOtherThread(FATAL_FAILURE);
1171 #endif // GTEST_IS_THREADSAFE 1177 typedef ScopedFakeTestPartResultReporterTest ExpectFatalFailureTest;
1179 TEST_F(ExpectFatalFailureTest, CatchesFatalFaliure) {
1183 #if GTEST_HAS_GLOBAL_STRING 1184 TEST_F(ExpectFatalFailureTest, AcceptsStringObject) {
1189 TEST_F(ExpectFatalFailureTest, AcceptsStdStringObject) {
1194 TEST_F(ExpectFatalFailureTest, CatchesFatalFailureOnAllThreads) {
1198 "Expected fatal failure.");
1203 # pragma option push -w-ccc 1209 int NonVoidFunction() {
1215 TEST_F(ExpectFatalFailureTest, CanBeUsedInNonVoidFunction) {
1222 void DoesNotAbortHelper(
bool* aborted) {
1234 TEST_F(ExpectFatalFailureTest, DoesNotAbort) {
1235 bool aborted =
true;
1236 DoesNotAbortHelper(&aborted);
1244 static int global_var = 0;
1245 #define GTEST_USE_UNPROTECTED_COMMA_ global_var++, global_var++ 1247 TEST_F(ExpectFatalFailureTest, AcceptsMacroThatExpandsToUnprotectedComma) {
1248 #ifndef __BORLANDC__ 1264 typedef ScopedFakeTestPartResultReporterTest ExpectNonfatalFailureTest;
1266 TEST_F(ExpectNonfatalFailureTest, CatchesNonfatalFailure) {
1268 "Expected non-fatal failure.");
1271 #if GTEST_HAS_GLOBAL_STRING 1272 TEST_F(ExpectNonfatalFailureTest, AcceptsStringObject) {
1274 ::
string(
"Expected non-fatal failure."));
1278 TEST_F(ExpectNonfatalFailureTest, AcceptsStdStringObject) {
1283 TEST_F(ExpectNonfatalFailureTest, CatchesNonfatalFailureOnAllThreads) {
1287 "Expected non-fatal failure.");
1293 TEST_F(ExpectNonfatalFailureTest, AcceptsMacroThatExpandsToUnprotectedComma) {
1296 AddNonfatalFailure();
1301 AddNonfatalFailure();
1305 #if GTEST_IS_THREADSAFE 1307 typedef ScopedFakeTestPartResultReporterWithThreadsTest
1308 ExpectFailureWithThreadsTest;
1310 TEST_F(ExpectFailureWithThreadsTest, ExpectFatalFailureOnAllThreads) {
1312 "Expected fatal failure.");
1315 TEST_F(ExpectFailureWithThreadsTest, ExpectNonFatalFailureOnAllThreads) {
1317 AddFailureInOtherThread(NONFATAL_FAILURE),
"Expected non-fatal failure.");
1320 #endif // GTEST_IS_THREADSAFE 1324 TEST(TestPropertyTest, ConstructorWorks) {
1330 TEST(TestPropertyTest, SetValue) {
1333 property.SetValue(
"value_2");
1341 class TestResultTest :
public Test {
1343 typedef std::vector<TestPartResult> TPRVector;
1351 virtual void SetUp() {
1374 TPRVector* results1 =
const_cast<TPRVector*
>(
1376 TPRVector* results2 =
const_cast<TPRVector*
>(
1382 results1->push_back(*pr1);
1385 results2->push_back(*pr1);
1386 results2->push_back(*pr2);
1389 virtual void TearDown() {
1399 static void CompareTestPartResult(
const TestPartResult& expected,
1414 TEST_F(TestResultTest, total_part_count) {
1421 TEST_F(TestResultTest, Passed) {
1428 TEST_F(TestResultTest, Failed) {
1436 typedef TestResultTest TestResultDeathTest;
1438 TEST_F(TestResultDeathTest, GetTestPartResult) {
1439 CompareTestPartResult(*pr1, r2->GetTestPartResult(0));
1440 CompareTestPartResult(*pr2, r2->GetTestPartResult(1));
1446 TEST(TestResultPropertyTest, NoPropertiesFoundWhenNoneAreAdded) {
1452 TEST(TestResultPropertyTest, OnePropertyFoundWhenAdded) {
1463 TEST(TestResultPropertyTest, MultiplePropertiesFoundWhenAdded) {
1480 TEST(TestResultPropertyTest, OverridesValuesForDuplicateKeys) {
1502 TEST(TestResultPropertyTest, GetTestProperty) {
1530 class GTestFlagSaverTest :
public Test {
1535 static void SetUpTestCase() {
1557 static void TearDownTestCase() {
1564 void VerifyAndModifyFlags() {
1594 GTEST_FLAG(stream_result_to) =
"localhost:1234";
1609 TEST_F(GTestFlagSaverTest, ModifyGTestFlags) {
1610 VerifyAndModifyFlags();
1615 TEST_F(GTestFlagSaverTest, VerifyGTestFlags) {
1616 VerifyAndModifyFlags();
1622 static void SetEnv(
const char*
name,
const char* value) {
1623 #if GTEST_OS_WINDOWS_MOBILE 1626 #elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9) 1630 static std::map<std::string, std::string*> added_env;
1635 if (added_env.find(name) != added_env.end()) {
1636 prev_env = added_env[
name];
1639 (
Message() << name <<
"=" << value).GetString());
1644 putenv(const_cast<char*>(added_env[name]->c_str()));
1646 #elif GTEST_OS_WINDOWS // If we are on Windows proper. 1647 _putenv((
Message() << name <<
"=" << value).GetString().c_str());
1649 if (*value ==
'\0') {
1652 setenv(name, value, 1);
1654 #endif // GTEST_OS_WINDOWS_MOBILE 1657 #if !GTEST_OS_WINDOWS_MOBILE 1666 TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenVariableIsNotSet) {
1673 TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenValueOverflows) {
1674 printf(
"(expecting 2 warnings)\n");
1685 TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenValueIsInvalid) {
1686 printf(
"(expecting 2 warnings)\n");
1698 TEST(Int32FromGTestEnvTest, ParsesAndReturnsValidValue) {
1705 #endif // !GTEST_OS_WINDOWS_MOBILE 1711 TEST(ParseInt32FlagTest, ReturnsFalseForInvalidFlag) {
1722 TEST(ParseInt32FlagTest, ReturnsDefaultWhenValueOverflows) {
1723 printf(
"(expecting 2 warnings)\n");
1736 TEST(ParseInt32FlagTest, ReturnsDefaultWhenValueIsInvalid) {
1737 printf(
"(expecting 2 warnings)\n");
1750 TEST(ParseInt32FlagTest, ParsesAndReturnsValidValue) {
1763 #if !GTEST_OS_WINDOWS_MOBILE 1764 TEST(Int32FromEnvOrDieTest, ParsesAndReturnsValidValue) {
1771 #endif // !GTEST_OS_WINDOWS_MOBILE 1775 TEST(Int32FromEnvOrDieDeathTest, AbortsOnFailure) {
1784 TEST(Int32FromEnvOrDieDeathTest, AbortsOnInt32Overflow) {
1793 TEST(ShouldRunTestOnShardTest, IsPartitionWhenThereIsOneShard) {
1803 virtual void SetUp() {
1808 virtual void TearDown() {
1809 SetEnv(index_var_,
"");
1810 SetEnv(total_var_,
"");
1813 const char* index_var_;
1814 const char* total_var_;
1819 TEST_F(ShouldShardTest, ReturnsFalseWhenNeitherEnvVarIsSet) {
1820 SetEnv(index_var_,
"");
1821 SetEnv(total_var_,
"");
1828 TEST_F(ShouldShardTest, ReturnsFalseWhenTotalShardIsOne) {
1829 SetEnv(index_var_,
"0");
1830 SetEnv(total_var_,
"1");
1838 #if !GTEST_OS_WINDOWS_MOBILE 1839 TEST_F(ShouldShardTest, WorksWhenShardEnvVarsAreValid) {
1840 SetEnv(index_var_,
"4");
1841 SetEnv(total_var_,
"22");
1845 SetEnv(index_var_,
"8");
1846 SetEnv(total_var_,
"9");
1850 SetEnv(index_var_,
"0");
1851 SetEnv(total_var_,
"9");
1855 #endif // !GTEST_OS_WINDOWS_MOBILE 1859 typedef ShouldShardTest ShouldShardDeathTest;
1861 TEST_F(ShouldShardDeathTest, AbortsWhenShardingEnvVarsAreInvalid) {
1862 SetEnv(index_var_,
"4");
1863 SetEnv(total_var_,
"4");
1866 SetEnv(index_var_,
"4");
1867 SetEnv(total_var_,
"-2");
1870 SetEnv(index_var_,
"5");
1871 SetEnv(total_var_,
"");
1874 SetEnv(index_var_,
"");
1875 SetEnv(total_var_,
"5");
1881 TEST(ShouldRunTestOnShardTest, IsPartitionWhenThereAreFiveShards) {
1883 const int num_tests = 17;
1884 const int num_shards = 5;
1887 for (
int test_id = 0; test_id < num_tests; test_id++) {
1888 int prev_selected_shard_index = -1;
1889 for (
int shard_index = 0; shard_index < num_shards; shard_index++) {
1891 if (prev_selected_shard_index < 0) {
1892 prev_selected_shard_index = shard_index;
1894 ADD_FAILURE() <<
"Shard " << prev_selected_shard_index <<
" and " 1895 << shard_index <<
" are both selected to run test " << test_id;
1903 for (
int shard_index = 0; shard_index < num_shards; shard_index++) {
1904 int num_tests_on_shard = 0;
1905 for (
int test_id = 0; test_id < num_tests; test_id++) {
1906 num_tests_on_shard +=
1909 EXPECT_GE(num_tests_on_shard, num_tests / num_shards);
1923 TEST(UnitTestTest, CanGetOriginalWorkingDir) {
1928 TEST(UnitTestTest, ReturnsPlausibleTimestamp) {
1936 void ExpectNonFatalFailureRecordingPropertyWithReservedKey(
1937 const TestResult& test_result,
const char* key) {
1940 <<
"' recorded unexpectedly.";
1943 void ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
1947 ExpectNonFatalFailureRecordingPropertyWithReservedKey(*test_info->
result(),
1951 void ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestCase(
1955 ExpectNonFatalFailureRecordingPropertyWithReservedKey(
1959 void ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestCase(
1961 ExpectNonFatalFailureRecordingPropertyWithReservedKey(
1968 class UnitTestRecordPropertyTest :
1971 static void SetUpTestCase() {
1972 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestCase(
1974 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestCase(
1976 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestCase(
1978 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestCase(
1980 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestCase(
1982 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestCase(
1998 TEST_F(UnitTestRecordPropertyTest, OnePropertyFoundWhenAdded) {
1999 UnitTestRecordProperty(
"key_1",
"1");
2001 ASSERT_EQ(1, unit_test_.ad_hoc_test_result().test_property_count());
2004 unit_test_.ad_hoc_test_result().GetTestProperty(0).key());
2006 unit_test_.ad_hoc_test_result().GetTestProperty(0).value());
2010 TEST_F(UnitTestRecordPropertyTest, MultiplePropertiesFoundWhenAdded) {
2011 UnitTestRecordProperty(
"key_1",
"1");
2012 UnitTestRecordProperty(
"key_2",
"2");
2014 ASSERT_EQ(2, unit_test_.ad_hoc_test_result().test_property_count());
2017 unit_test_.ad_hoc_test_result().GetTestProperty(0).key());
2018 EXPECT_STREQ(
"1", unit_test_.ad_hoc_test_result().GetTestProperty(0).value());
2021 unit_test_.ad_hoc_test_result().GetTestProperty(1).key());
2022 EXPECT_STREQ(
"2", unit_test_.ad_hoc_test_result().GetTestProperty(1).value());
2026 TEST_F(UnitTestRecordPropertyTest, OverridesValuesForDuplicateKeys) {
2027 UnitTestRecordProperty(
"key_1",
"1");
2028 UnitTestRecordProperty(
"key_2",
"2");
2029 UnitTestRecordProperty(
"key_1",
"12");
2030 UnitTestRecordProperty(
"key_2",
"22");
2032 ASSERT_EQ(2, unit_test_.ad_hoc_test_result().test_property_count());
2035 unit_test_.ad_hoc_test_result().GetTestProperty(0).key());
2037 unit_test_.ad_hoc_test_result().GetTestProperty(0).value());
2040 unit_test_.ad_hoc_test_result().GetTestProperty(1).key());
2042 unit_test_.ad_hoc_test_result().GetTestProperty(1).value());
2045 TEST_F(UnitTestRecordPropertyTest,
2046 AddFailureInsideTestsWhenUsingTestCaseReservedKeys) {
2047 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2049 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2051 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2053 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2055 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2057 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2061 TEST_F(UnitTestRecordPropertyTest,
2062 AddRecordWithReservedKeysGeneratesCorrectPropertyList) {
2065 "'classname', 'name', 'status', 'time', 'type_param', and 'value_param'" 2069 class UnitTestRecordPropertyTestEnvironment :
public Environment {
2071 virtual void TearDown() {
2072 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestCase(
2074 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestCase(
2076 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestCase(
2078 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestCase(
2080 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestCase(
2082 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestCase(
2084 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestCase(
2086 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestCase(
2104 bool IsEven(
int n) {
2105 return (n % 2) == 0;
2109 struct IsEvenFunctor {
2110 bool operator()(
int n) {
return IsEven(n); }
2121 msg << expr <<
" evaluates to " << n <<
", which is not even.";
2146 struct AssertIsEvenFunctor {
2148 return AssertIsEven(expr, n);
2153 bool SumIsEven2(
int n1,
int n2) {
2154 return IsEven(n1 + n2);
2159 struct SumIsEven3Functor {
2160 bool operator()(
int n1,
int n2,
int n3) {
2161 return IsEven(n1 + n2 + n3);
2168 const char* e1,
const char* e2,
const char* e3,
const char* e4,
2169 int n1,
int n2,
int n3,
int n4) {
2170 const int sum = n1 + n2 + n3 + n4;
2176 msg << e1 <<
" + " << e2 <<
" + " << e3 <<
" + " << e4
2177 <<
" (" << n1 <<
" + " << n2 <<
" + " << n3 <<
" + " << n4
2178 <<
") evaluates to " << sum <<
", which is not even.";
2184 struct AssertSumIsEven5Functor {
2186 const char* e1,
const char* e2,
const char* e3,
const char* e4,
2187 const char* e5,
int n1,
int n2,
int n3,
int n4,
int n5) {
2188 const int sum = n1 + n2 + n3 + n4 + n5;
2194 msg << e1 <<
" + " << e2 <<
" + " << e3 <<
" + " << e4 <<
" + " << e5
2196 << n1 <<
" + " << n2 <<
" + " << n3 <<
" + " << n4 <<
" + " << n5
2197 <<
") evaluates to " << sum <<
", which is not even.";
2206 TEST(Pred1Test, WithoutFormat) {
2208 EXPECT_PRED1(IsEvenFunctor(), 2) <<
"This failure is UNEXPECTED!";
2213 EXPECT_PRED1(IsEven, 5) <<
"This failure is expected.";
2214 },
"This failure is expected.");
2216 "evaluates to false");
2220 TEST(Pred1Test, WithFormat) {
2224 <<
"This failure is UNEXPECTED!";
2229 "n evaluates to 5, which is not even.");
2232 },
"This failure is expected.");
2237 TEST(Pred1Test, SingleEvaluationOnFailure) {
2241 EXPECT_EQ(1, n) <<
"The argument is not evaluated exactly once.";
2246 <<
"This failure is expected.";
2247 },
"This failure is expected.");
2248 EXPECT_EQ(2, n) <<
"The argument is not evaluated exactly once.";
2255 TEST(PredTest, WithoutFormat) {
2257 ASSERT_PRED2(SumIsEven2, 2, 4) <<
"This failure is UNEXPECTED!";
2264 EXPECT_PRED2(SumIsEven2, n1, n2) <<
"This failure is expected.";
2265 },
"This failure is expected.");
2268 },
"evaluates to false");
2272 TEST(PredTest, WithFormat) {
2275 "This failure is UNEXPECTED!";
2285 },
"evaluates to 13, which is not even.");
2288 <<
"This failure is expected.";
2289 },
"This failure is expected.");
2294 TEST(PredTest, SingleEvaluationOnFailure) {
2299 EXPECT_EQ(1, n1) <<
"Argument 1 is not evaluated exactly once.";
2300 EXPECT_EQ(1, n2) <<
"Argument 2 is not evaluated exactly once.";
2308 n1++, n2++, n3++, n4++, n5++)
2309 <<
"This failure is UNEXPECTED!";
2310 EXPECT_EQ(1, n1) <<
"Argument 1 is not evaluated exactly once.";
2311 EXPECT_EQ(1, n2) <<
"Argument 2 is not evaluated exactly once.";
2312 EXPECT_EQ(1, n3) <<
"Argument 3 is not evaluated exactly once.";
2313 EXPECT_EQ(1, n4) <<
"Argument 4 is not evaluated exactly once.";
2314 EXPECT_EQ(1, n5) <<
"Argument 5 is not evaluated exactly once.";
2320 <<
"This failure is expected.";
2321 },
"This failure is expected.");
2322 EXPECT_EQ(1, n1) <<
"Argument 1 is not evaluated exactly once.";
2323 EXPECT_EQ(1, n2) <<
"Argument 2 is not evaluated exactly once.";
2324 EXPECT_EQ(1, n3) <<
"Argument 3 is not evaluated exactly once.";
2327 n1 = n2 = n3 = n4 = 0;
2330 },
"evaluates to 1, which is not even.");
2331 EXPECT_EQ(1, n1) <<
"Argument 1 is not evaluated exactly once.";
2332 EXPECT_EQ(1, n2) <<
"Argument 2 is not evaluated exactly once.";
2333 EXPECT_EQ(1, n3) <<
"Argument 3 is not evaluated exactly once.";
2334 EXPECT_EQ(1, n4) <<
"Argument 4 is not evaluated exactly once.";
2345 template <
typename T>
2346 bool IsNegative(T x) {
2350 template <
typename T1,
typename T2>
2351 bool GreaterThan(T1 x1, T2 x2) {
2357 TEST(PredicateAssertionTest, AcceptsOverloadedFunction) {
2365 TEST(PredicateAssertionTest, AcceptsTemplateFunction) {
2386 template <
typename T>
2392 template <
typename T1,
typename T2>
2394 const T1& x1,
const T2& x2) {
2401 TEST(PredicateFormatAssertionTest, AcceptsOverloadedFunction) {
2408 TEST(PredicateFormatAssertionTest, AcceptsTemplateFunction) {
2418 const char *
const p1 =
"good";
2422 const char p2[] =
"good";
2426 "Expected: \"bad\"");
2430 TEST(StringAssertionTest, ASSERT_STREQ_Null) {
2437 TEST(StringAssertionTest, ASSERT_STREQ_Null2) {
2452 "\"Hi\" vs \"Hi\"");
2479 TEST(StringAssertionTest, STREQ_Wide) {
2481 ASSERT_STREQ(static_cast<const wchar_t *>(NULL), NULL);
2503 EXPECT_STREQ(L
"abc\x8119", L
"abc\x8121") <<
"Expected failure";
2504 },
"Expected failure");
2508 TEST(StringAssertionTest, STRNE_Wide) {
2511 EXPECT_STRNE(static_cast<const wchar_t *>(NULL), NULL);
2533 ASSERT_STRNE(L
"abc\x8119", L
"abc\x8120") <<
"This shouldn't happen";
2540 TEST(IsSubstringTest, ReturnsCorrectResultForCString) {
2551 TEST(IsSubstringTest, ReturnsCorrectResultForWideCString) {
2562 TEST(IsSubstringTest, GeneratesCorrectMessageForCString) {
2564 " Actual: \"needle\"\n" 2565 "Expected: a substring of haystack_expr\n" 2566 "Which is: \"haystack\"",
2568 "needle",
"haystack").failure_message());
2573 TEST(IsSubstringTest, ReturnsCorrectResultsForStdString) {
2578 #if GTEST_HAS_STD_WSTRING 2581 TEST(IsSubstringTest, ReturnsCorrectResultForStdWstring) {
2588 TEST(IsSubstringTest, GeneratesCorrectMessageForWstring) {
2590 " Actual: L\"needle\"\n" 2591 "Expected: a substring of haystack_expr\n" 2592 "Which is: L\"haystack\"",
2594 "needle_expr",
"haystack_expr",
2595 ::
std::wstring(L
"needle"), L
"haystack").failure_message());
2598 #endif // GTEST_HAS_STD_WSTRING 2604 TEST(IsNotSubstringTest, ReturnsCorrectResultForCString) {
2611 TEST(IsNotSubstringTest, ReturnsCorrectResultForWideCString) {
2618 TEST(IsNotSubstringTest, GeneratesCorrectMessageForWideCString) {
2620 " Actual: L\"needle\"\n" 2621 "Expected: not a substring of haystack_expr\n" 2622 "Which is: L\"two needles\"",
2624 "needle_expr",
"haystack_expr",
2625 L
"needle", L
"two needles").failure_message());
2630 TEST(IsNotSubstringTest, ReturnsCorrectResultsForStdString) {
2637 TEST(IsNotSubstringTest, GeneratesCorrectMessageForStdString) {
2639 " Actual: \"needle\"\n" 2640 "Expected: not a substring of haystack_expr\n" 2641 "Which is: \"two needles\"",
2643 "needle_expr",
"haystack_expr",
2644 ::
std::string(
"needle"),
"two needles").failure_message());
2647 #if GTEST_HAS_STD_WSTRING 2651 TEST(IsNotSubstringTest, ReturnsCorrectResultForStdWstring) {
2657 #endif // GTEST_HAS_STD_WSTRING 2661 template <
typename RawType>
2662 class FloatingPointTest :
public Test {
2666 RawType close_to_positive_zero;
2667 RawType close_to_negative_zero;
2668 RawType further_from_negative_zero;
2670 RawType close_to_one;
2671 RawType further_from_one;
2674 RawType close_to_infinity;
2675 RawType further_from_infinity;
2682 typedef typename Floating::Bits Bits;
2684 virtual void SetUp() {
2685 const size_t max_ulps = Floating::kMaxUlps;
2688 const Bits zero_bits = Floating(0).
bits();
2691 values_.close_to_positive_zero = Floating::ReinterpretBits(
2692 zero_bits + max_ulps/2);
2693 values_.close_to_negative_zero = -Floating::ReinterpretBits(
2694 zero_bits + max_ulps - max_ulps/2);
2695 values_.further_from_negative_zero = -Floating::ReinterpretBits(
2696 zero_bits + max_ulps + 1 - max_ulps/2);
2699 const Bits one_bits = Floating(1).bits();
2702 values_.close_to_one = Floating::ReinterpretBits(one_bits + max_ulps);
2703 values_.further_from_one = Floating::ReinterpretBits(
2704 one_bits + max_ulps + 1);
2707 values_.infinity = Floating::Infinity();
2710 const Bits infinity_bits = Floating(values_.infinity).bits();
2713 values_.close_to_infinity = Floating::ReinterpretBits(
2714 infinity_bits - max_ulps);
2715 values_.further_from_infinity = Floating::ReinterpretBits(
2716 infinity_bits - max_ulps - 1);
2721 values_.nan1 = Floating::ReinterpretBits(Floating::kExponentBitMask
2722 | (static_cast<Bits>(1) << (Floating::kFractionBitCount - 1)) | 1);
2723 values_.nan2 = Floating::ReinterpretBits(Floating::kExponentBitMask
2724 | (static_cast<Bits>(1) << (Floating::kFractionBitCount - 1)) | 200);
2728 EXPECT_EQ(
sizeof(RawType),
sizeof(Bits));
2731 static TestValues values_;
2734 template <
typename RawType>
2735 typename FloatingPointTest<RawType>::TestValues
2736 FloatingPointTest<RawType>::values_;
2739 typedef FloatingPointTest<float>
FloatTest;
2742 TEST_F(FloatTest, Size) {
2747 TEST_F(FloatTest, Zeros) {
2760 TEST_F(FloatTest, AlmostZeros) {
2767 static const FloatTest::TestValues& v = this->values_;
2775 v.further_from_negative_zero);
2776 },
"v.further_from_negative_zero");
2780 TEST_F(FloatTest, SmallDiff) {
2783 "values_.further_from_one");
2787 TEST_F(FloatTest, LargeDiff) {
2796 TEST_F(FloatTest, Infinity) {
2799 #if !GTEST_OS_SYMBIAN 2802 "-values_.infinity");
2808 #endif // !GTEST_OS_SYMBIAN 2813 #if !GTEST_OS_SYMBIAN 2822 static const FloatTest::TestValues& v = this->values_;
2833 #endif // !GTEST_OS_SYMBIAN 2837 TEST_F(FloatTest, Reflexive) {
2844 TEST_F(FloatTest, Commutative) {
2858 "The difference between 1.0f and 1.5f is 0.5, " 2859 "which exceeds 0.25f");
2869 "The difference between 1.0f and 1.5f is 0.5, " 2870 "which exceeds 0.25f");
2876 TEST_F(FloatTest, FloatLESucceeds) {
2885 TEST_F(FloatTest, FloatLEFails) {
2888 "(2.0f) <= (1.0f)");
2893 },
"(values_.further_from_one) <= (1.0f)");
2895 #if !GTEST_OS_SYMBIAN && !defined(__BORLANDC__) 2901 },
"(values_.nan1) <= (values_.infinity)");
2904 },
"(-values_.infinity) <= (values_.nan1)");
2907 },
"(values_.nan1) <= (values_.nan1)");
2908 #endif // !GTEST_OS_SYMBIAN && !defined(__BORLANDC__) 2912 typedef FloatingPointTest<double>
DoubleTest;
2915 TEST_F(DoubleTest, Size) {
2920 TEST_F(DoubleTest, Zeros) {
2933 TEST_F(DoubleTest, AlmostZeros) {
2940 static const DoubleTest::TestValues& v = this->values_;
2948 v.further_from_negative_zero);
2949 },
"v.further_from_negative_zero");
2953 TEST_F(DoubleTest, SmallDiff) {
2956 "values_.further_from_one");
2960 TEST_F(DoubleTest, LargeDiff) {
2969 TEST_F(DoubleTest, Infinity) {
2972 #if !GTEST_OS_SYMBIAN 2975 "-values_.infinity");
2981 #endif // !GTEST_OS_SYMBIAN 2985 TEST_F(DoubleTest, NaN) {
2986 #if !GTEST_OS_SYMBIAN 2993 static const DoubleTest::TestValues& v = this->values_;
3002 #endif // !GTEST_OS_SYMBIAN 3006 TEST_F(DoubleTest, Reflexive) {
3009 #if !GTEST_OS_SYMBIAN 3012 #endif // !GTEST_OS_SYMBIAN 3016 TEST_F(DoubleTest, Commutative) {
3030 "The difference between 1.0 and 1.5 is 0.5, " 3031 "which exceeds 0.25");
3041 "The difference between 1.0 and 1.5 is 0.5, " 3042 "which exceeds 0.25");
3048 TEST_F(DoubleTest, DoubleLESucceeds) {
3057 TEST_F(DoubleTest, DoubleLEFails) {
3065 },
"(values_.further_from_one) <= (1.0)");
3067 #if !GTEST_OS_SYMBIAN && !defined(__BORLANDC__) 3073 },
"(values_.nan1) <= (values_.infinity)");
3076 },
" (-values_.infinity) <= (values_.nan1)");
3079 },
"(values_.nan1) <= (values_.nan1)");
3080 #endif // !GTEST_OS_SYMBIAN && !defined(__BORLANDC__) 3090 FAIL() <<
"Unexpected failure: Disabled test should not be run.";
3101 TEST(DISABLED_TestCase, TestShouldNotRun) {
3102 FAIL() <<
"Unexpected failure: Test in disabled test case should not be run.";
3107 TEST(DISABLED_TestCase, DISABLED_TestShouldNotRun) {
3108 FAIL() <<
"Unexpected failure: Test in disabled test case should not be run.";
3113 class DisabledTestsTest :
public Test {
3115 static void SetUpTestCase() {
3116 FAIL() <<
"Unexpected failure: All tests disabled in test case. " 3117 "SetupTestCase() should not be called.";
3120 static void TearDownTestCase() {
3121 FAIL() <<
"Unexpected failure: All tests disabled in test case. " 3122 "TearDownTestCase() should not be called.";
3126 TEST_F(DisabledTestsTest, DISABLED_TestShouldNotRun_1) {
3127 FAIL() <<
"Unexpected failure: Disabled test should not be run.";
3130 TEST_F(DisabledTestsTest, DISABLED_TestShouldNotRun_2) {
3131 FAIL() <<
"Unexpected failure: Disabled test should not be run.";
3136 #if GTEST_HAS_TYPED_TEST 3138 template <
typename T>
3142 typedef testing::Types<int, double> NumericTypes;
3146 FAIL() <<
"Unexpected failure: Disabled typed test should not run.";
3149 template <
typename T>
3150 class DISABLED_TypedTest :
public Test {
3155 TYPED_TEST(DISABLED_TypedTest, ShouldNotRun) {
3156 FAIL() <<
"Unexpected failure: Disabled typed test should not run.";
3159 #endif // GTEST_HAS_TYPED_TEST 3163 #if GTEST_HAS_TYPED_TEST_P 3165 template <
typename T>
3166 class TypedTestP :
public Test {
3172 FAIL() <<
"Unexpected failure: " 3173 <<
"Disabled type-parameterized test should not run.";
3180 template <
typename T>
3181 class DISABLED_TypedTestP :
public Test {
3187 FAIL() <<
"Unexpected failure: " 3188 <<
"Disabled type-parameterized test should not run.";
3195 #endif // GTEST_HAS_TYPED_TEST_P 3199 class SingleEvaluationTest :
public Test {
3204 static void CompareAndIncrementCharPtrs() {
3210 static void CompareAndIncrementInts() {
3215 SingleEvaluationTest() {
3222 static const char*
const s1_;
3223 static const char*
const s2_;
3224 static const char* p1_;
3225 static const char* p2_;
3231 const char*
const SingleEvaluationTest::s1_ =
"01234";
3232 const char*
const SingleEvaluationTest::s2_ =
"abcde";
3233 const char* SingleEvaluationTest::p1_;
3234 const char* SingleEvaluationTest::p2_;
3235 int SingleEvaluationTest::a_;
3236 int SingleEvaluationTest::b_;
3240 TEST_F(SingleEvaluationTest, FailedASSERT_STREQ) {
3248 TEST_F(SingleEvaluationTest, ASSERT_STR) {
3263 TEST_F(SingleEvaluationTest, FailedASSERT_NE) {
3265 "(a_++) != (b_++)");
3271 TEST_F(SingleEvaluationTest, OtherCases) {
3300 #if GTEST_HAS_EXCEPTIONS 3302 void ThrowAnInteger() {
3307 TEST_F(SingleEvaluationTest, ExceptionTests) {
3319 }, bool),
"throws a different type");
3349 #endif // GTEST_HAS_EXCEPTIONS 3352 class NoFatalFailureTest :
public Test {
3355 void FailsNonFatal() {
3359 FAIL() <<
"some fatal failure";
3362 void DoAssertNoFatalFailureOnFails() {
3367 void DoExpectNoFatalFailureOnFails() {
3373 TEST_F(NoFatalFailureTest, NoFailure) {
3378 TEST_F(NoFatalFailureTest, NonFatalIsNoFailure) {
3381 "some non-fatal failure");
3384 "some non-fatal failure");
3387 TEST_F(NoFatalFailureTest, AssertNoFatalFailureOnFatalFailure) {
3391 DoAssertNoFatalFailureOnFails();
3404 TEST_F(NoFatalFailureTest, ExpectNoFatalFailureOnFatalFailure) {
3408 DoExpectNoFatalFailureOnFails();
3425 TEST_F(NoFatalFailureTest, MessageIsStreamable) {
3448 EqFailure(
"foo",
"bar", foo_val, bar_val,
false)
3449 .failure_message());
3458 EqFailure(
"foo",
"6", foo_val, bar_val,
false)
3459 .failure_message());
3467 EqFailure(
"5",
"bar", foo_val, bar_val,
false)
3468 .failure_message());
3476 EqFailure(
"5",
"6", foo_val, bar_val,
false).failure_message());
3485 true).failure_message());
3489 "Expected: foo (ignoring case)\n" 3509 # pragma option push -w-ccc -w-rch 3520 TEST(AssertionTest, AssertTrueWithAssertionResult) {
3522 #ifndef __BORLANDC__ 3525 "Value of: ResultIsEven(3)\n" 3526 " Actual: false (3 is odd)\n" 3531 "Value of: ResultIsEvenNoExplanation(3)\n" 3532 " Actual: false (3 is odd)\n" 3546 TEST(AssertionTest, AssertFalseWithAssertionResult) {
3548 #ifndef __BORLANDC__ 3551 "Value of: ResultIsEven(2)\n" 3552 " Actual: true (2 is even)\n" 3557 "Value of: ResultIsEvenNoExplanation(2)\n" 3570 TEST(ExpectTest, ASSERT_EQ_Double) {
3589 #if GTEST_CAN_COMPARE_NULL 3590 TEST(AssertionTest, ASSERT_EQ_NULL) {
3592 const char* p = NULL;
3604 #endif // GTEST_CAN_COMPARE_NULL 3610 TEST(ExpectTest, ASSERT_EQ_0) {
3625 "Expected: ('a') != ('a'), " 3626 "actual: 'a' (97, 0x61) vs 'a' (97, 0x61)");
3634 "Expected: (2) <= (0), actual: 2 vs 0");
3641 "Expected: (2) < (2), actual: 2 vs 2");
3649 "Expected: (2) >= (3), actual: 2 vs 3");
3656 "Expected: (2) > (2), actual: 2 vs 2");
3659 #if GTEST_HAS_EXCEPTIONS 3661 void ThrowNothing() {}
3667 # ifndef __BORLANDC__ 3672 "Expected: ThrowAnInteger() throws an exception of type bool.\n" 3673 " Actual: it throws a different type.");
3678 "Expected: ThrowNothing() throws an exception of type bool.\n" 3679 " Actual: it throws nothing.");
3686 "Expected: ThrowAnInteger() doesn't throw an exception." 3687 "\n Actual: it throws.");
3695 "Expected: ThrowNothing() throws an exception.\n" 3696 " Actual: it doesn't.");
3699 #endif // GTEST_HAS_EXCEPTIONS 3703 TEST(AssertionTest, AssertPrecedence) {
3705 bool false_value =
false;
3715 TEST(AssertionTest, NonFixtureSubroutine) {
3723 explicit Uncopyable(
int a_value) : value_(a_value) {}
3725 int value()
const {
return value_; }
3726 bool operator==(
const Uncopyable& rhs)
const {
3727 return value() == rhs.value();
3732 Uncopyable(
const Uncopyable&);
3737 ::std::ostream&
operator<<(::std::ostream& os,
const Uncopyable& value) {
3738 return os << value.value();
3742 bool IsPositiveUncopyable(
const Uncopyable& x) {
3743 return x.value() > 0;
3747 void TestAssertNonPositive() {
3752 void TestAssertEqualsUncopyable() {
3759 TEST(AssertionTest, AssertWorksWithUncopyableObject) {
3764 "IsPositiveUncopyable(y) evaluates to false, where\ny evaluates to -1");
3766 "Value of: y\n Actual: -1\nExpected: x\nWhich is: 5");
3770 TEST(AssertionTest, ExpectWorksWithUncopyableObject) {
3775 "IsPositiveUncopyable(y) evaluates to false, where\ny evaluates to -1");
3778 "Value of: y\n Actual: -1\nExpected: x\nWhich is: 5");
3797 #if !GTEST_OS_MAC && !defined(__SUNPRO_CC) && !defined(__HP_aCC) 3820 # endif // GTEST_OS_LINUX 3828 EXPECT_EQ(static_cast<int>(kCaseA), static_cast<int>(kCaseB));
3830 # endif // GTEST_OS_LINUX 3839 "(kCaseA) >= (kCaseB)");
3850 # ifndef __BORLANDC__ 3854 "Value of: kCaseB");
3863 #endif // !GTEST_OS_MAC && !defined(__SUNPRO_CC) 3865 #if GTEST_OS_WINDOWS 3867 static HRESULT UnexpectedHRESULTFailure() {
3868 return E_UNEXPECTED;
3871 static HRESULT OkHRESULTSuccess() {
3875 static HRESULT FalseHRESULTSuccess() {
3883 TEST(HRESULTAssertionTest, EXPECT_HRESULT_SUCCEEDED) {
3884 EXPECT_HRESULT_SUCCEEDED(S_OK);
3885 EXPECT_HRESULT_SUCCEEDED(S_FALSE);
3888 "Expected: (UnexpectedHRESULTFailure()) succeeds.\n" 3889 " Actual: 0x8000FFFF");
3892 TEST(HRESULTAssertionTest, ASSERT_HRESULT_SUCCEEDED) {
3893 ASSERT_HRESULT_SUCCEEDED(S_OK);
3894 ASSERT_HRESULT_SUCCEEDED(S_FALSE);
3897 "Expected: (UnexpectedHRESULTFailure()) succeeds.\n" 3898 " Actual: 0x8000FFFF");
3901 TEST(HRESULTAssertionTest, EXPECT_HRESULT_FAILED) {
3902 EXPECT_HRESULT_FAILED(E_UNEXPECTED);
3905 "Expected: (OkHRESULTSuccess()) fails.\n" 3908 "Expected: (FalseHRESULTSuccess()) fails.\n" 3912 TEST(HRESULTAssertionTest, ASSERT_HRESULT_FAILED) {
3913 ASSERT_HRESULT_FAILED(E_UNEXPECTED);
3915 # ifndef __BORLANDC__ 3919 "Expected: (OkHRESULTSuccess()) fails.\n" 3924 "Expected: (FalseHRESULTSuccess()) fails.\n" 3929 TEST(HRESULTAssertionTest, Streaming) {
3930 EXPECT_HRESULT_SUCCEEDED(S_OK) <<
"unexpected failure";
3931 ASSERT_HRESULT_SUCCEEDED(S_OK) <<
"unexpected failure";
3932 EXPECT_HRESULT_FAILED(E_UNEXPECTED) <<
"unexpected failure";
3933 ASSERT_HRESULT_FAILED(E_UNEXPECTED) <<
"unexpected failure";
3936 EXPECT_HRESULT_SUCCEEDED(E_UNEXPECTED) <<
"expected failure",
3937 "expected failure");
3939 # ifndef __BORLANDC__ 3943 ASSERT_HRESULT_SUCCEEDED(E_UNEXPECTED) <<
"expected failure",
3944 "expected failure");
3948 EXPECT_HRESULT_FAILED(S_OK) <<
"expected failure",
3949 "expected failure");
3952 ASSERT_HRESULT_FAILED(S_OK) <<
"expected failure",
3953 "expected failure");
3956 #endif // GTEST_OS_WINDOWS 3960 # pragma option push -w-ccc -w-rch 3964 TEST(AssertionSyntaxTest, BasicAssertionsBehavesLikeSingleStatement) {
3966 ASSERT_TRUE(
false) <<
"This should never be executed; " 3967 "It's a compilation test only.";
3983 #if GTEST_HAS_EXCEPTIONS 3986 TEST(ExpectThrowTest, DoesNotGenerateUnreachableCodeWarning) {
3998 TEST(AssertionSyntaxTest, ExceptionAssertionsBehavesLikeSingleStatement) {
4023 #endif // GTEST_HAS_EXCEPTIONS 4025 TEST(AssertionSyntaxTest, NoFatalFailureAssertionsBehavesLikeSingleStatement) {
4028 <<
"It's a compilation test only.";
4049 TEST(AssertionSyntaxTest, WorksWithSwitch) {
4059 EXPECT_FALSE(
false) <<
"EXPECT_FALSE failed in switch case";
4066 ASSERT_EQ(1, 1) <<
"ASSERT_EQ failed in default switch handler";
4074 #if GTEST_HAS_EXCEPTIONS 4076 void ThrowAString() {
4077 throw "std::string";
4082 TEST(AssertionSyntaxTest, WorksWithConst) {
4088 #endif // GTEST_HAS_EXCEPTIONS 4102 TEST(SuccessfulAssertionTest, EXPECT) {
4108 TEST(SuccessfulAssertionTest, EXPECT_STR) {
4114 TEST(SuccessfulAssertionTest, ASSERT) {
4120 TEST(SuccessfulAssertionTest, ASSERT_STR) {
4131 TEST(AssertionWithMessageTest, EXPECT) {
4132 EXPECT_EQ(1, 1) <<
"This should succeed.";
4134 "Expected failure #1");
4135 EXPECT_LE(1, 2) <<
"This should succeed.";
4137 "Expected failure #2.");
4138 EXPECT_GE(1, 0) <<
"This should succeed.";
4140 "Expected failure #3.");
4144 "Expected failure #4.");
4147 "Expected failure #5.");
4151 "Expected failure #6.");
4152 EXPECT_NEAR(1, 1.1, 0.2) <<
"This should succeed.";
4155 TEST(AssertionWithMessageTest, ASSERT) {
4156 ASSERT_EQ(1, 1) <<
"This should succeed.";
4157 ASSERT_NE(1, 2) <<
"This should succeed.";
4158 ASSERT_LE(1, 2) <<
"This should succeed.";
4159 ASSERT_LT(1, 2) <<
"This should succeed.";
4160 ASSERT_GE(1, 0) <<
"This should succeed.";
4162 "Expected failure.");
4165 TEST(AssertionWithMessageTest, ASSERT_STR) {
4170 "Expected failure.");
4173 TEST(AssertionWithMessageTest, ASSERT_FLOATING) {
4186 ASSERT_FALSE(
true) <<
"Expected failure: " << 2 <<
" > " << 1
4187 <<
" evaluates to " <<
true;
4188 },
"Expected failure");
4192 TEST(AssertionWithMessageTest,
FAIL) {
4199 SUCCEED() <<
"Success == " << 1;
4207 ASSERT_TRUE(
false) <<
static_cast<const char *
>(NULL)
4208 << static_cast<char *>(NULL);
4212 #if GTEST_OS_WINDOWS 4214 TEST(AssertionWithMessageTest, WideStringMessage) {
4216 EXPECT_TRUE(
false) << L
"This failure is expected.\x8119";
4217 },
"This failure is expected.");
4220 << L
"expected too.\x8120";
4221 },
"This failure is expected too.");
4223 #endif // GTEST_OS_WINDOWS 4229 "Intentional failure #1.");
4231 "Intentional failure #2.");
4242 TEST(ExpectTest, ExpectTrueWithAssertionResult) {
4245 "Value of: ResultIsEven(3)\n" 4246 " Actual: false (3 is odd)\n" 4250 "Value of: ResultIsEvenNoExplanation(3)\n" 4251 " Actual: false (3 is odd)\n" 4260 "Intentional failure #1.");
4262 "Intentional failure #2.");
4272 TEST(ExpectTest, ExpectFalseWithAssertionResult) {
4275 "Value of: ResultIsEven(2)\n" 4276 " Actual: true (2 is even)\n" 4280 "Value of: ResultIsEvenNoExplanation(2)\n" 4304 TEST(ExpectTest, EXPECT_EQ_Double) {
4313 #if GTEST_CAN_COMPARE_NULL 4315 TEST(ExpectTest, EXPECT_EQ_NULL) {
4317 const char* p = NULL;
4329 #endif // GTEST_CAN_COMPARE_NULL 4335 TEST(ExpectTest, EXPECT_EQ_0) {
4351 "Expected: ('a') != ('a'), " 4352 "actual: 'a' (97, 0x61) vs 'a' (97, 0x61)");
4355 char*
const p0 = NULL;
4362 void* pv1 = (
void*)0x1234;
4363 char*
const p1 =
reinterpret_cast<char*
>(pv1);
4373 "Expected: (2) <= (0), actual: 2 vs 0");
4382 "Expected: (2) < (2), actual: 2 vs 2");
4392 "Expected: (2) >= (3), actual: 2 vs 3");
4401 "Expected: (2) > (2), actual: 2 vs 2");
4406 #if GTEST_HAS_EXCEPTIONS 4412 "Expected: ThrowAnInteger() throws an exception of " 4413 "type bool.\n Actual: it throws a different type.");
4416 "Expected: ThrowNothing() throws an exception of type bool.\n" 4417 " Actual: it throws nothing.");
4424 "Expected: ThrowAnInteger() doesn't throw an " 4425 "exception.\n Actual: it throws.");
4433 "Expected: ThrowNothing() throws an exception.\n" 4434 " Actual: it doesn't.");
4437 #endif // GTEST_HAS_EXCEPTIONS 4440 TEST(ExpectTest, ExpectPrecedence) {
4443 "Value of: true && false");
4450 TEST(StreamableToStringTest, Scalar) {
4455 TEST(StreamableToStringTest, Pointer) {
4462 TEST(StreamableToStringTest, NullPointer) {
4468 TEST(StreamableToStringTest, CString) {
4473 TEST(StreamableToStringTest, NullCString) {
4481 TEST(StreamableTest,
string) {
4483 "This failure message is a std::string, and is expected.");
4490 TEST(StreamableTest, stringWithEmbeddedNUL) {
4491 static const char char_array_with_nul[] =
4492 "Here's a NUL\0 and some more string";
4493 static const std::string string_with_nul(char_array_with_nul,
4494 sizeof(char_array_with_nul)
4497 "Here's a NUL\\0 and some more string");
4501 TEST(StreamableTest, NULChar) {
4503 FAIL() <<
"A NUL" <<
'\0' <<
" and some more string";
4504 },
"A NUL\\0 and some more string");
4508 TEST(StreamableTest,
int) {
4518 TEST(StreamableTest, NullCharPtr) {
4525 TEST(StreamableTest, BasicIoManip) {
4527 FAIL() <<
"Line 1." << std::endl
4528 <<
"A NUL char " << std::ends <<
std::flush <<
" in line 2.";
4529 },
"Line 1.\nA NUL char \\0 in line 2.");
4534 void AddFailureHelper(
bool* aborted) {
4542 bool aborted =
true;
4544 "Intentional failure.");
4568 "Intentional failure.");
4574 SUCCEED() <<
"Explicit success.";
4588 bool false_value =
false;
4590 },
"Value of: true");
4594 TEST(EqAssertionTest, Int) {
4601 TEST(EqAssertionTest, Time_T) {
4603 static_cast<time_t>(0));
4605 static_cast<time_t>(1234)),
4612 const char ch =
'b';
4620 TEST(EqAssertionTest, WideChar) {
4625 " Actual: L'x' (120, 0x78)\n" 4627 "Which is: L'\0' (0, 0x0)");
4629 static wchar_t wchar;
4639 TEST(EqAssertionTest, StdString) {
4655 char*
const p1 =
const_cast<char*
>(
"foo");
4665 " Actual: \"A \\0 in the middle\"");
4668 #if GTEST_HAS_STD_WSTRING 4671 TEST(EqAssertionTest, StdWideString) {
4679 const wchar_t kTestX8119[] = {
'T',
'e',
's',
't', 0x8119,
'\0' };
4684 const wchar_t kTestX8120[] = {
'T',
'e',
's',
't', 0x8120,
'\0' };
4692 wstr3.at(2) = L
'\0';
4703 #endif // GTEST_HAS_STD_WSTRING 4705 #if GTEST_HAS_GLOBAL_STRING 4707 TEST(EqAssertionTest, GlobalString) {
4729 ASSERT_EQ(::
string(
"bar"), const_cast<char*>(
"foo"));
4733 #endif // GTEST_HAS_GLOBAL_STRING 4735 #if GTEST_HAS_GLOBAL_WSTRING 4738 TEST(EqAssertionTest, GlobalWideString) {
4745 const wchar_t kTestX8119[] = {
'T',
'e',
's',
't', 0x8119,
'\0' };
4750 const wchar_t kTestX8120[] = {
'T',
'e',
's',
't', 0x8120,
'\0' };
4756 wchar_t*
const p1 =
const_cast<wchar_t*
>(L
"foo");
4764 wstr3.at(2) = L
'\0';
4769 #endif // GTEST_HAS_GLOBAL_WSTRING 4772 TEST(EqAssertionTest, CharPointer) {
4773 char*
const p0 = NULL;
4778 void* pv1 = (
void*)0x1234;
4779 void* pv2 = (
void*)0xABC0;
4780 char*
const p1 =
reinterpret_cast<char*
>(pv1);
4781 char*
const p2 =
reinterpret_cast<char*
>(pv2);
4789 reinterpret_cast<char*>(0xABC0)),
4794 TEST(EqAssertionTest, WideCharPointer) {
4795 wchar_t*
const p0 = NULL;
4800 void* pv1 = (
void*)0x1234;
4801 void* pv2 = (
void*)0xABC0;
4802 wchar_t*
const p1 =
reinterpret_cast<wchar_t*
>(pv1);
4803 wchar_t*
const p2 =
reinterpret_cast<wchar_t*
>(pv2);
4810 void* pv3 = (
void*)0x1234;
4811 void* pv4 = (
void*)0xABC0;
4812 const wchar_t* p3 =
reinterpret_cast<const wchar_t*
>(pv3);
4813 const wchar_t* p4 =
reinterpret_cast<const wchar_t*
>(pv4);
4819 TEST(EqAssertionTest, OtherPointer) {
4820 ASSERT_EQ(static_cast<const int*>(NULL),
4821 static_cast<const int*>(NULL));
4823 reinterpret_cast<const int*>(0x1234)),
4828 class UnprintableChar {
4830 explicit UnprintableChar(
char ch) : char_(ch) {}
4832 bool operator==(
const UnprintableChar& rhs)
const {
4833 return char_ == rhs.char_;
4835 bool operator!=(
const UnprintableChar& rhs)
const {
4836 return char_ != rhs.char_;
4838 bool operator<(
const UnprintableChar& rhs)
const {
4839 return char_ < rhs.char_;
4841 bool operator<=(
const UnprintableChar& rhs)
const {
4842 return char_ <= rhs.char_;
4844 bool operator>(
const UnprintableChar& rhs)
const {
4845 return char_ > rhs.char_;
4847 bool operator>=(
const UnprintableChar& rhs)
const {
4848 return char_ >= rhs.char_;
4857 TEST(ComparisonAssertionTest, AcceptsUnprintableArgs) {
4858 const UnprintableChar x(
'x'), y(
'y');
4874 #ifndef __BORLANDC__ 4877 "1-byte object <78>");
4879 "1-byte object <78>");
4882 "1-byte object <79>");
4884 "1-byte object <78>");
4886 "1-byte object <79>");
4898 int Bar()
const {
return 1; }
4913 class FRIEND_TEST_Test2 :
public Test {
4930 class TestLifeCycleTest :
public Test {
4934 TestLifeCycleTest() { count_++; }
4938 ~TestLifeCycleTest() { count_--; }
4941 int count()
const {
return count_; }
4947 int TestLifeCycleTest::count_ = 0;
4950 TEST_F(TestLifeCycleTest, Test1) {
4957 TEST_F(TestLifeCycleTest, Test2) {
4968 TEST(AssertionResultTest, CopyConstructorWorksWhenNotOptimied) {
4978 EXPECT_EQ(static_cast<bool>(r3), static_cast<bool>(r1));
4984 TEST(AssertionResultTest, ConstructionWorks) {
5007 TEST(AssertionResultTest, NegationWorks) {
5017 TEST(AssertionResultTest, StreamingWorks) {
5019 r <<
"abc" <<
'd' << 0 <<
true;
5023 TEST(AssertionResultTest, CanStreamOstreamManipulators) {
5025 r <<
"Data" << std::endl <<
std::flush << std::ends <<
"Will be visible";
5040 return os << val.
x();
5043 const Base* pointer) {
5044 return os <<
"(" << pointer->
x() <<
")";
5047 TEST(MessageTest, CanStreamUserTypeInGlobalNameSpace) {
5058 class MyTypeInUnnamedNameSpace :
public Base {
5060 explicit MyTypeInUnnamedNameSpace(
int an_x):
Base(an_x) {}
5063 const MyTypeInUnnamedNameSpace& val) {
5064 return os << val.x();
5067 const MyTypeInUnnamedNameSpace* pointer) {
5068 return os <<
"(" << pointer->x() <<
")";
5072 TEST(MessageTest, CanStreamUserTypeInUnnamedNameSpace) {
5074 MyTypeInUnnamedNameSpace a(1);
5083 class MyTypeInNameSpace1 :
public Base {
5089 return os << val.x();
5093 return os <<
"(" << pointer->x() <<
")";
5097 TEST(MessageTest, CanStreamUserTypeInUserNameSpace) {
5108 class MyTypeInNameSpace2 :
public ::Base {
5115 return os << val.
x();
5119 return os <<
"(" << pointer->
x() <<
")";
5122 TEST(MessageTest, CanStreamUserTypeInUserNameSpaceWithStreamOperatorInGlobal) {
5133 char*
const p1 = NULL;
5134 unsigned char*
const p2 = NULL;
5140 msg << p1 << p2 << p3 << p4 << p5 << p6;
5148 const wchar_t* const_wstr = NULL;
5150 (
Message() << const_wstr).GetString().c_str());
5153 wchar_t* wstr = NULL;
5155 (
Message() << wstr).GetString().c_str());
5158 const_wstr = L
"abc\x8119";
5160 (
Message() << const_wstr).GetString().c_str());
5163 wstr =
const_cast<wchar_t*
>(const_wstr);
5165 (
Message() << wstr).GetString().c_str());
5174 class TestInfoTest :
public Test {
5178 GetTestCase(
"TestInfoTest",
"", NULL, NULL);
5182 if (strcmp(test_name, test_info->
name()) == 0)
5190 return test_info->
result();
5196 const TestInfo*
const test_info = GetTestInfo(
"Names");
5204 const TestInfo*
const test_info = GetTestInfo(
"result");
5207 ASSERT_EQ(0, GetTestResult(test_info)->total_part_count());
5210 ASSERT_EQ(0, GetTestResult(test_info)->total_part_count());
5220 printf(
"Setting up the test case . . .\n");
5225 shared_resource_ =
"123";
5237 printf(
"Tearing down the test case . . .\n");
5246 shared_resource_ = NULL;
5257 static int counter_;
5260 static const char* shared_resource_;
5281 Flags() : also_run_disabled_tests(false),
5282 break_on_failure(false),
5283 catch_exceptions(false),
5284 death_test_use_fork(false),
5293 stream_result_to(
""),
5294 throw_on_failure(false) {}
5411 bool also_run_disabled_tests;
5412 bool break_on_failure;
5413 bool catch_exceptions;
5414 bool death_test_use_fork;
5422 Int32 stack_trace_depth;
5423 const char* stream_result_to;
5424 bool throw_on_failure;
5449 template <
typename CharType>
5451 size_t size2, CharType** array2) {
5452 ASSERT_EQ(size1, size2) <<
" Array sizes different.";
5454 for (
size_t i = 0; i != size1; i++) {
5455 ASSERT_STREQ(array1[i], array2[i]) <<
" where i == " << i;
5482 template <
typename CharType>
5484 int argc2,
const CharType** argv2,
5485 const Flags& expected,
bool should_print_help) {
5489 #if GTEST_HAS_STREAM_REDIRECTION 5496 #if GTEST_HAS_STREAM_REDIRECTION 5501 CheckFlags(expected);
5505 AssertStringArrayEq(argc1 + 1, argv1, argc2 + 1, argv2);
5511 #if GTEST_HAS_STREAM_REDIRECTION 5512 const char*
const expected_help_fragment =
5513 "This program contains tests written using";
5514 if (should_print_help) {
5518 expected_help_fragment, captured_stdout);
5520 #endif // GTEST_HAS_STREAM_REDIRECTION 5528 #define GTEST_TEST_PARSING_FLAGS_(argv1, argv2, expected, should_print_help) \ 5529 TestParsingFlags(sizeof(argv1)/sizeof(*argv1) - 1, argv1, \ 5530 sizeof(argv2)/sizeof(*argv2) - 1, argv2, \ 5531 expected, should_print_help) 5535 TEST_F(InitGoogleTestTest, Empty) {
5536 const char* argv[] = {
5540 const char* argv2[] = {
5548 TEST_F(InitGoogleTestTest, NoFlag) {
5549 const char* argv[] = {
5554 const char* argv2[] = {
5563 TEST_F(InitGoogleTestTest, FilterBad) {
5564 const char* argv[] = {
5570 const char* argv2[] = {
5580 TEST_F(InitGoogleTestTest, FilterEmpty) {
5581 const char* argv[] = {
5587 const char* argv2[] = {
5596 TEST_F(InitGoogleTestTest, FilterNonEmpty) {
5597 const char* argv[] = {
5599 "--gtest_filter=abc",
5603 const char* argv2[] = {
5612 TEST_F(InitGoogleTestTest, BreakOnFailureWithoutValue) {
5613 const char* argv[] = {
5615 "--gtest_break_on_failure",
5619 const char* argv2[] = {
5628 TEST_F(InitGoogleTestTest, BreakOnFailureFalse_0) {
5629 const char* argv[] = {
5631 "--gtest_break_on_failure=0",
5635 const char* argv2[] = {
5644 TEST_F(InitGoogleTestTest, BreakOnFailureFalse_f) {
5645 const char* argv[] = {
5647 "--gtest_break_on_failure=f",
5651 const char* argv2[] = {
5660 TEST_F(InitGoogleTestTest, BreakOnFailureFalse_F) {
5661 const char* argv[] = {
5663 "--gtest_break_on_failure=F",
5667 const char* argv2[] = {
5677 TEST_F(InitGoogleTestTest, BreakOnFailureTrue) {
5678 const char* argv[] = {
5680 "--gtest_break_on_failure=1",
5684 const char* argv2[] = {
5693 TEST_F(InitGoogleTestTest, CatchExceptions) {
5694 const char* argv[] = {
5696 "--gtest_catch_exceptions",
5700 const char* argv2[] = {
5709 TEST_F(InitGoogleTestTest, DeathTestUseFork) {
5710 const char* argv[] = {
5712 "--gtest_death_test_use_fork",
5716 const char* argv2[] = {
5726 TEST_F(InitGoogleTestTest, DuplicatedFlags) {
5727 const char* argv[] = {
5734 const char* argv2[] = {
5743 TEST_F(InitGoogleTestTest, UnrecognizedFlag) {
5744 const char* argv[] = {
5746 "--gtest_break_on_failure",
5752 const char* argv2[] = {
5759 flags.break_on_failure =
true;
5765 TEST_F(InitGoogleTestTest, ListTestsFlag) {
5766 const char* argv[] = {
5768 "--gtest_list_tests",
5772 const char* argv2[] = {
5781 TEST_F(InitGoogleTestTest, ListTestsTrue) {
5782 const char* argv[] = {
5784 "--gtest_list_tests=1",
5788 const char* argv2[] = {
5797 TEST_F(InitGoogleTestTest, ListTestsFalse) {
5798 const char* argv[] = {
5800 "--gtest_list_tests=0",
5804 const char* argv2[] = {
5813 TEST_F(InitGoogleTestTest, ListTestsFalse_f) {
5814 const char* argv[] = {
5816 "--gtest_list_tests=f",
5820 const char* argv2[] = {
5829 TEST_F(InitGoogleTestTest, ListTestsFalse_F) {
5830 const char* argv[] = {
5832 "--gtest_list_tests=F",
5836 const char* argv2[] = {
5845 TEST_F(InitGoogleTestTest, OutputEmpty) {
5846 const char* argv[] = {
5852 const char* argv2[] = {
5862 TEST_F(InitGoogleTestTest, OutputXml) {
5863 const char* argv[] = {
5865 "--gtest_output=xml",
5869 const char* argv2[] = {
5878 TEST_F(InitGoogleTestTest, OutputXmlFile) {
5879 const char* argv[] = {
5881 "--gtest_output=xml:file",
5885 const char* argv2[] = {
5894 TEST_F(InitGoogleTestTest, OutputXmlDirectory) {
5895 const char* argv[] = {
5897 "--gtest_output=xml:directory/path/",
5901 const char* argv2[] = {
5911 TEST_F(InitGoogleTestTest, PrintTimeFlag) {
5912 const char* argv[] = {
5914 "--gtest_print_time",
5918 const char* argv2[] = {
5927 TEST_F(InitGoogleTestTest, PrintTimeTrue) {
5928 const char* argv[] = {
5930 "--gtest_print_time=1",
5934 const char* argv2[] = {
5943 TEST_F(InitGoogleTestTest, PrintTimeFalse) {
5944 const char* argv[] = {
5946 "--gtest_print_time=0",
5950 const char* argv2[] = {
5959 TEST_F(InitGoogleTestTest, PrintTimeFalse_f) {
5960 const char* argv[] = {
5962 "--gtest_print_time=f",
5966 const char* argv2[] = {
5975 TEST_F(InitGoogleTestTest, PrintTimeFalse_F) {
5976 const char* argv[] = {
5978 "--gtest_print_time=F",
5982 const char* argv2[] = {
5991 TEST_F(InitGoogleTestTest, RandomSeed) {
5992 const char* argv[] = {
5994 "--gtest_random_seed=1000",
5998 const char* argv2[] = {
6007 TEST_F(InitGoogleTestTest, Repeat) {
6008 const char* argv[] = {
6010 "--gtest_repeat=1000",
6014 const char* argv2[] = {
6024 const char* argv[] = {
6026 "--gtest_also_run_disabled_tests",
6030 const char* argv2[] = {
6040 TEST_F(InitGoogleTestTest, AlsoRunDisabledTestsTrue) {
6041 const char* argv[] = {
6043 "--gtest_also_run_disabled_tests=1",
6047 const char* argv2[] = {
6057 TEST_F(InitGoogleTestTest, AlsoRunDisabledTestsFalse) {
6058 const char* argv[] = {
6060 "--gtest_also_run_disabled_tests=0",
6064 const char* argv2[] = {
6074 TEST_F(InitGoogleTestTest, ShuffleWithoutValue) {
6075 const char* argv[] = {
6081 const char* argv2[] = {
6090 TEST_F(InitGoogleTestTest, ShuffleFalse_0) {
6091 const char* argv[] = {
6093 "--gtest_shuffle=0",
6097 const char* argv2[] = {
6107 TEST_F(InitGoogleTestTest, ShuffleTrue) {
6108 const char* argv[] = {
6110 "--gtest_shuffle=1",
6114 const char* argv2[] = {
6123 TEST_F(InitGoogleTestTest, StackTraceDepth) {
6124 const char* argv[] = {
6126 "--gtest_stack_trace_depth=5",
6130 const char* argv2[] = {
6138 TEST_F(InitGoogleTestTest, StreamResultTo) {
6139 const char* argv[] = {
6141 "--gtest_stream_result_to=localhost:1234",
6145 const char* argv2[] = {
6155 TEST_F(InitGoogleTestTest, ThrowOnFailureWithoutValue) {
6156 const char* argv[] = {
6158 "--gtest_throw_on_failure",
6162 const char* argv2[] = {
6171 TEST_F(InitGoogleTestTest, ThrowOnFailureFalse_0) {
6172 const char* argv[] = {
6174 "--gtest_throw_on_failure=0",
6178 const char* argv2[] = {
6188 TEST_F(InitGoogleTestTest, ThrowOnFailureTrue) {
6189 const char* argv[] = {
6191 "--gtest_throw_on_failure=1",
6195 const char* argv2[] = {
6203 #if GTEST_OS_WINDOWS 6205 TEST_F(InitGoogleTestTest, WideStrings) {
6206 const wchar_t* argv[] = {
6208 L
"--gtest_filter=Foo*",
6209 L
"--gtest_list_tests=1",
6210 L
"--gtest_break_on_failure",
6211 L
"--non_gtest_flag",
6215 const wchar_t* argv2[] = {
6217 L
"--non_gtest_flag",
6221 Flags expected_flags;
6222 expected_flags.break_on_failure =
true;
6223 expected_flags.filter =
"Foo*";
6224 expected_flags.list_tests =
true;
6228 #endif // GTEST_OS_WINDOWS 6231 class CurrentTestInfoTest :
public Test {
6240 <<
"There should be no tests running at this point.";
6249 <<
"There should be no tests running at this point.";
6259 <<
"There is a test running so we should have a valid TestInfo.";
6261 <<
"Expected the name of the currently running test case.";
6263 <<
"Expected the name of the currently running test.";
6274 <<
"There is a test running so we should have a valid TestInfo.";
6276 <<
"Expected the name of the currently running test case.";
6278 <<
"Expected the name of the currently running test.";
6302 TEST(NestedTestingNamespaceTest, Success) {
6303 EXPECT_EQ(1, 1) <<
"This shouldn't fail.";
6307 TEST(NestedTestingNamespaceTest, Failure) {
6309 "This failure is expected.");
6331 TEST(StreamingAssertionsTest, Unconditional) {
6332 SUCCEED() <<
"expected success";
6334 "expected failure");
6336 "expected failure");
6341 # pragma option push -w-ccc -w-rch 6344 TEST(StreamingAssertionsTest, Truth) {
6348 "expected failure");
6350 "expected failure");
6353 TEST(StreamingAssertionsTest, Truth2) {
6357 "expected failure");
6359 "expected failure");
6367 TEST(StreamingAssertionsTest, IntegerEquals) {
6368 EXPECT_EQ(1, 1) <<
"unexpected failure";
6369 ASSERT_EQ(1, 1) <<
"unexpected failure";
6371 "expected failure");
6373 "expected failure");
6376 TEST(StreamingAssertionsTest, IntegerLessThan) {
6377 EXPECT_LT(1, 2) <<
"unexpected failure";
6378 ASSERT_LT(1, 2) <<
"unexpected failure";
6380 "expected failure");
6382 "expected failure");
6385 TEST(StreamingAssertionsTest, StringsEqual) {
6389 "expected failure");
6391 "expected failure");
6394 TEST(StreamingAssertionsTest, StringsNotEqual) {
6398 "expected failure");
6400 "expected failure");
6403 TEST(StreamingAssertionsTest, StringsEqualIgnoringCase) {
6407 "expected failure");
6409 "expected failure");
6412 TEST(StreamingAssertionsTest, StringNotEqualIgnoringCase) {
6416 "expected failure");
6418 "expected failure");
6421 TEST(StreamingAssertionsTest, FloatingPointEquals) {
6425 "expected failure");
6427 "expected failure");
6430 #if GTEST_HAS_EXCEPTIONS 6432 TEST(StreamingAssertionsTest, Throw) {
6433 EXPECT_THROW(ThrowAnInteger(),
int) <<
"unexpected failure";
6434 ASSERT_THROW(ThrowAnInteger(),
int) <<
"unexpected failure";
6436 "expected failure",
"expected failure");
6438 "expected failure",
"expected failure");
6441 TEST(StreamingAssertionsTest, NoThrow) {
6445 "expected failure",
"expected failure");
6447 "expected failure",
"expected failure");
6450 TEST(StreamingAssertionsTest, AnyThrow) {
6454 "expected failure",
"expected failure");
6456 "expected failure",
"expected failure");
6459 #endif // GTEST_HAS_EXCEPTIONS 6463 TEST(ColoredOutputTest, UsesColorsWhenGTestColorFlagIsYes) {
6466 SetEnv(
"TERM",
"xterm");
6470 SetEnv(
"TERM",
"dumb");
6475 TEST(ColoredOutputTest, UsesColorsWhenGTestColorFlagIsAliasOfYes) {
6476 SetEnv(
"TERM",
"dumb");
6488 TEST(ColoredOutputTest, UsesNoColorWhenGTestColorFlagIsNo) {
6491 SetEnv(
"TERM",
"xterm");
6495 SetEnv(
"TERM",
"dumb");
6500 TEST(ColoredOutputTest, UsesNoColorWhenGTestColorFlagIsInvalid) {
6501 SetEnv(
"TERM",
"xterm");
6513 TEST(ColoredOutputTest, UsesColorsWhenStdoutIsTty) {
6516 SetEnv(
"TERM",
"xterm");
6521 TEST(ColoredOutputTest, UsesColorsWhenTermSupportsColors) {
6524 #if GTEST_OS_WINDOWS 6527 SetEnv(
"TERM",
"dumb");
6533 SetEnv(
"TERM",
"xterm");
6539 SetEnv(
"TERM",
"dumb");
6542 SetEnv(
"TERM",
"emacs");
6545 SetEnv(
"TERM",
"vt100");
6548 SetEnv(
"TERM",
"xterm-mono");
6551 SetEnv(
"TERM",
"xterm");
6554 SetEnv(
"TERM",
"xterm-color");
6557 SetEnv(
"TERM",
"xterm-256color");
6560 SetEnv(
"TERM",
"screen");
6563 SetEnv(
"TERM",
"screen-256color");
6566 SetEnv(
"TERM",
"linux");
6569 SetEnv(
"TERM",
"cygwin");
6571 #endif // GTEST_OS_WINDOWS 6578 StaticAssertTypeEq<const int, const int>();
6582 template <
typename T>
6588 TEST(StaticAssertTypeEqTest, WorksInClass) {
6596 TEST(StaticAssertTypeEqTest, CompilesForEqualTypes) {
6597 StaticAssertTypeEq<int, IntAlias>();
6598 StaticAssertTypeEq<int*, IntAlias*>();
6601 TEST(GetCurrentOsStackTraceExceptTopTest, ReturnsTheStackTrace) {
6609 TEST(HasNonfatalFailureTest, ReturnsFalseWhenThereIsNoFailure) {
6615 TEST(HasNonfatalFailureTest, ReturnsFalseWhenThereIsOnlyFatalFailure) {
6617 const bool has_nonfatal_failure = HasNonfatalFailure();
6618 ClearCurrentTestPartResults();
6622 TEST(HasNonfatalFailureTest, ReturnsTrueWhenThereIsNonfatalFailure) {
6624 const bool has_nonfatal_failure = HasNonfatalFailure();
6625 ClearCurrentTestPartResults();
6629 TEST(HasNonfatalFailureTest, ReturnsTrueWhenThereAreFatalAndNonfatalFailures) {
6632 const bool has_nonfatal_failure = HasNonfatalFailure();
6633 ClearCurrentTestPartResults();
6642 TEST(HasNonfatalFailureTest, WorksOutsideOfTestBody) {
6646 TEST(HasNonfatalFailureTest, WorksOutsideOfTestBody2) {
6649 ClearCurrentTestPartResults();
6653 TEST(HasFailureTest, ReturnsFalseWhenThereIsNoFailure) {
6657 TEST(HasFailureTest, ReturnsTrueWhenThereIsFatalFailure) {
6659 const bool has_failure = HasFailure();
6660 ClearCurrentTestPartResults();
6664 TEST(HasFailureTest, ReturnsTrueWhenThereIsNonfatalFailure) {
6666 const bool has_failure = HasFailure();
6667 ClearCurrentTestPartResults();
6671 TEST(HasFailureTest, ReturnsTrueWhenThereAreFatalAndNonfatalFailures) {
6674 const bool has_failure = HasFailure();
6675 ClearCurrentTestPartResults();
6682 TEST(HasFailureTest, WorksOutsideOfTestBody) {
6686 TEST(HasFailureTest, WorksOutsideOfTestBody2) {
6689 ClearCurrentTestPartResults();
6697 : on_start_counter_(on_start_counter),
6698 is_destroyed_(is_destroyed) {}
6702 *is_destroyed_ =
true;
6707 if (on_start_counter_ != NULL)
6708 (*on_start_counter_)++;
6712 int* on_start_counter_;
6713 bool* is_destroyed_;
6717 TEST(TestEventListenersTest, ConstructionWorks) {
6727 TEST(TestEventListenersTest, DestructionWorks) {
6728 bool default_result_printer_is_destroyed =
false;
6729 bool default_xml_printer_is_destroyed =
false;
6730 bool extra_listener_is_destroyed =
false;
6732 NULL, &default_result_printer_is_destroyed);
6734 NULL, &default_xml_printer_is_destroyed);
6736 NULL, &extra_listener_is_destroyed);
6741 default_result_printer);
6743 default_xml_printer);
6744 listeners.
Append(extra_listener);
6753 TEST(TestEventListenersTest, Append) {
6754 int on_start_counter = 0;
6755 bool is_destroyed =
false;
6759 listeners.
Append(listener);
6773 : vector_(vector), id_(id) {}
6777 vector_->push_back(GetEventDescription(
"OnTestProgramStart"));
6781 vector_->push_back(GetEventDescription(
"OnTestProgramEnd"));
6786 vector_->push_back(GetEventDescription(
"OnTestIterationStart"));
6791 vector_->push_back(GetEventDescription(
"OnTestIterationEnd"));
6797 message << id_ <<
"." << method;
6801 std::vector<std::string>* vector_;
6802 const char*
const id_;
6807 TEST(EventListenerTest, AppendKeepsOrder) {
6808 std::vector<std::string> vec;
6817 EXPECT_STREQ(
"1st.OnTestProgramStart", vec[0].c_str());
6818 EXPECT_STREQ(
"2nd.OnTestProgramStart", vec[1].c_str());
6819 EXPECT_STREQ(
"3rd.OnTestProgramStart", vec[2].c_str());
6833 EXPECT_STREQ(
"1st.OnTestIterationStart", vec[0].c_str());
6834 EXPECT_STREQ(
"2nd.OnTestIterationStart", vec[1].c_str());
6835 EXPECT_STREQ(
"3rd.OnTestIterationStart", vec[2].c_str());
6841 EXPECT_STREQ(
"3rd.OnTestIterationEnd", vec[0].c_str());
6842 EXPECT_STREQ(
"2nd.OnTestIterationEnd", vec[1].c_str());
6843 EXPECT_STREQ(
"1st.OnTestIterationEnd", vec[2].c_str());
6848 TEST(TestEventListenersTest, Release) {
6849 int on_start_counter = 0;
6850 bool is_destroyed =
false;
6857 listeners.
Append(listener);
6869 TEST(EventListenerTest, SuppressEventForwarding) {
6870 int on_start_counter = 0;
6874 listeners.
Append(listener);
6885 TEST(EventListenerDeathTest, EventsNotForwardedInDeathTestSubprecesses) {
6889 "expected failure");
6895 TEST(EventListenerTest, default_result_printer) {
6896 int on_start_counter = 0;
6897 bool is_destroyed =
false;
6926 TEST(EventListenerTest, RemovingDefaultResultPrinterWorks) {
6927 int on_start_counter = 0;
6928 bool is_destroyed =
false;
6954 TEST(EventListenerTest, default_xml_generator) {
6955 int on_start_counter = 0;
6956 bool is_destroyed =
false;
6985 TEST(EventListenerTest, RemovingDefaultXmlGeneratorWorks) {
6986 int on_start_counter = 0;
6987 bool is_destroyed =
false;
7020 "An expected failure");
7026 "An expected failure");
7028 "An expected failure");
7033 "An expected failure");
7038 "An expected failure");
7042 "An expected failure");
7044 "An expected failure");
7049 "An expected failure");
7053 "An expected failure");
7055 "An expected failure");
7066 TEST(IsAProtocolMessageTest, ValueIsCompileTimeConstant) {
7074 TEST(IsAProtocolMessageTest, ValueIsTrueWhenTypeIsAProtocolMessage) {
7081 TEST(IsAProtocolMessageTest, ValueIsFalseWhenTypeIsNotAProtocolMessage) {
7094 TEST(RemoveReferenceTest, DoesNotAffectNonReferenceType) {
7100 TEST(RemoveReferenceTest, RemovesReference) {
7107 template <
typename T1,
typename T2>
7112 TEST(RemoveReferenceTest, MacroVersion) {
7113 TestGTestRemoveReference<int, int>();
7114 TestGTestRemoveReference<const char, const char&>();
7119 TEST(RemoveConstTest, DoesNotAffectNonConstType) {
7125 TEST(RemoveConstTest, RemovesConst) {
7133 template <
typename T1,
typename T2>
7138 TEST(RemoveConstTest, MacroVersion) {
7139 TestGTestRemoveConst<int, int>();
7140 TestGTestRemoveConst<double&, double&>();
7141 TestGTestRemoveConst<char, const char>();
7146 template <
typename T1,
typename T2>
7151 TEST(RemoveReferenceToConstTest, Works) {
7152 TestGTestRemoveReferenceAndConst<int, int>();
7153 TestGTestRemoveReferenceAndConst<double, double&>();
7154 TestGTestRemoveReferenceAndConst<char, const char>();
7155 TestGTestRemoveReferenceAndConst<char, const char&>();
7156 TestGTestRemoveReferenceAndConst<const char*, const char*>();
7160 TEST(AddReferenceTest, DoesNotAffectReferenceType) {
7166 TEST(AddReferenceTest, AddsReference) {
7173 template <
typename T1,
typename T2>
7178 TEST(AddReferenceTest, MacroVersion) {
7179 TestGTestAddReference<int&, int>();
7180 TestGTestAddReference<const char&, const char&>();
7185 template <
typename T1,
typename T2>
7190 TEST(GTestReferenceToConstTest, Works) {
7191 TestGTestReferenceToConst<const char&, char>();
7192 TestGTestReferenceToConst<const int&, const int>();
7193 TestGTestReferenceToConst<const double&, double>();
7194 TestGTestReferenceToConst<const std::string&, const std::string&>();
7198 TEST(ImplicitlyConvertibleTest, ValueIsCompileTimeConstant) {
7206 TEST(ImplicitlyConvertibleTest, ValueIsTrueWhenConvertible) {
7219 TEST(ImplicitlyConvertibleTest, ValueIsFalseWhenNotConvertible) {
7231 TEST(IsContainerTestTest, WorksForNonContainer) {
7237 TEST(IsContainerTestTest, WorksForContainer) {
7246 TEST(ArrayEqTest, WorksForDegeneratedArrays) {
7251 TEST(ArrayEqTest, WorksForOneDimensionalArrays) {
7253 const int a[] = { 0, 1 };
7254 long b[] = { 0, 1 };
7263 TEST(ArrayEqTest, WorksForTwoDimensionalArrays) {
7264 const char a[][3] = {
"hi",
"lo" };
7265 const char b[][3] = {
"hi",
"lo" };
7266 const char c[][3] = {
"hi",
"li" };
7277 TEST(ArrayAwareFindTest, WorksForOneDimensionalArray) {
7278 const char a[] =
"hello";
7283 TEST(ArrayAwareFindTest, WorksForTwoDimensionalArray) {
7284 int a[][2] = { { 0, 1 }, { 2, 3 }, { 4, 5 } };
7285 const int b[2] = { 2, 3 };
7288 const int c[2] = { 6, 7 };
7294 TEST(CopyArrayTest, WorksForDegeneratedArrays) {
7300 TEST(CopyArrayTest, WorksForOneDimensionalArrays) {
7301 const char a[3] =
"hi";
7303 #ifndef __BORLANDC__ // C++Builder cannot compile some array size deductions. 7313 TEST(CopyArrayTest, WorksForTwoDimensionalArrays) {
7314 const int a[2][3] = { { 0, 1, 2 }, { 3, 4, 5 } };
7316 #ifndef __BORLANDC__ // C++Builder cannot compile some array size deductions. 7328 TEST(NativeArrayTest, ConstructorFromArrayWorks) {
7329 const int a[3] = { 0, 1, 2 };
7335 TEST(NativeArrayTest, CreatesAndDeletesCopyOfArrayWhenAskedTo) {
7336 typedef int Array[2];
7337 Array* a =
new Array[1];
7350 TEST(NativeArrayTest, TypeMembersAreCorrect) {
7351 StaticAssertTypeEq<char, NativeArray<char>::value_type>();
7352 StaticAssertTypeEq<int[2], NativeArray<int[2]>::value_type>();
7354 StaticAssertTypeEq<const char*, NativeArray<char>::const_iterator>();
7355 StaticAssertTypeEq<const bool(*)[2], NativeArray<bool[2]>::const_iterator>();
7358 TEST(NativeArrayTest, MethodsWork) {
7359 const int a[3] = { 0, 1, 2 };
7378 const int b1[3] = { 0, 1, 1 };
7379 const int b2[4] = { 0, 1, 2, 3 };
7384 TEST(NativeArrayTest, WorksForTwoDimensionalArray) {
7385 const char a[2][3] = {
"hi",
"lo" };
7393 TEST(SkipPrefixTest, SkipsWhenPrefixMatches) {
7394 const char*
const str =
"hello";
7396 const char* p = str;
7405 TEST(SkipPrefixTest, DoesNotSkipWhenPrefixDoesNotMatch) {
7406 const char*
const str =
"world";
7408 const char* p = str;
#define ASSERT_ANY_THROW(statement)
GTEST_API_ bool g_help_flag
void SetDefaultResultPrinter(TestEventListener *listener)
UnitTestImpl * GetUnitTestImpl()
static void FailFatally()
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)
std::string GetCapturedStdout()
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
const char * summary() const
GTEST_TEST(AlternativeNameTest, Works)
#define EXPECT_FATAL_FAILURE(statement, substr)
GTEST_API_ std::string FormatEpochTimeInMillisAsIso8601(TimeInMillis ms)
TYPED_TEST_CASE_P(TypeParamTest)
E GetElementOr(const std::vector< E > &v, int i, E default_value)
static Flags DeathTestUseFork(bool death_test_use_fork)
AssertionResult AssertionFailure()
const TestInfo * GetTestInfo(int i) const
static void SetUpTestCase()
#define EXPECT_NONFATAL_FAILURE(statement, substr)
static Flags StackTraceDepth(Int32 stack_trace_depth)
Environment * AddGlobalTestEnvironment(Environment *env)
#define GTEST_USE_UNPROTECTED_COMMA_
#define ASSERT_PRED2(pred, v1, v2)
class testing::internal::GTestFlagSaver GTEST_ATTRIBUTE_UNUSED_
static Flags Output(const char *output)
TypeWithSize< 4 >::Int Int32
const char * message() const
int GetNextRandomSeed(int seed)
StaticAssertTypeEqTestHelper()
static const TestResult * GetTestResult(const TestInfo *test_info)
#define ASSERT_FLOAT_EQ(expected, actual)
TYPED_TEST_P(TypeParamTest, TestA)
#define ASSERT_NO_FATAL_FAILURE(statement)
static bool EndsWithCaseInsensitive(const std::string &str, const std::string &suffix)
GTEST_API_ bool ShouldUseColor(bool stdout_is_tty)
#define EXPECT_NO_FATAL_FAILURE(statement)
TypeWithSize< 4 >::UInt UInt32
TestEventListener * Release(TestEventListener *listener)
#define EXPECT_NO_THROW(statement)
GTEST_API_ bool ShouldRunTestOnShard(int total_shards, int shard_index, int test_id)
virtual void OnTestProgramStart(const UnitTest &)
MyTypeInNameSpace2(int an_x)
#define EXPECT_STRCASEEQ(expected, actual)
TestEventListener * repeater()
void SuppressEventForwarding()
virtual void OnTestIterationStart(const UnitTest &unit_test, int iteration)=0
FloatingPointTest< double > DoubleTest
bool operator==(T *ptr, const linked_ptr< T > &x)
static Flags BreakOnFailure(bool break_on_failure)
#define GTEST_TEST_PARSING_FLAGS_(argv1, argv2, expected, should_print_help)
#define EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(statement, substr)
static TestEventListener * GetRepeater(TestEventListeners *listeners)
#define EXPECT_LT(val1, val2)
const_iterator begin() const
TestEventListener * default_xml_generator() const
bool SkipPrefix(const char *prefix, const char **pstr)
GTEST_API_ std::string FormatTimeInMillisAsSeconds(TimeInMillis ms)
#define GTEST_ASSERT_LE(val1, val2)
static const TestInfo * GetTestInfo(const char *test_name)
static Flags AlsoRunDisabledTests(bool also_run_disabled_tests)
#define ASSERT_LE(val1, val2)
REGISTER_TYPED_TEST_CASE_P(TypeParamTest, TestA, TestB)
const TestProperty & GetTestProperty(int i) const
static Flags StreamResultTo(const char *stream_result_to)
const char * stream_result_to
void TestGTestRemoveReferenceAndConst()
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 EXPECT_NEAR(val1, val2, abs_error)
GTEST_API_ std::string CodePointToUtf8(UInt32 code_point)
#define GTEST_COMPILE_ASSERT_(expr, msg)
#define EXPECT_TRUE(condition)
#define EXPECT_GT(val1, val2)
#define ASSERT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5)
int total_test_count() const
std::ostream & operator<<(std::ostream &os, const TestPartResult &result)
static void CheckFlags(const Flags &expected)
TYPED_TEST_CASE(TypedTest, MyTypes)
OStream< ChannelType > & flush(OStream< ChannelType > &os)
#define EXPECT_STREQ(expected, actual)
#define EXPECT_STRCASENE(s1, s2)
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)
INSTANTIATE_TYPED_TEST_CASE_P(My, TypeParamTest, MyTypes)
static void SetDefaultXmlGenerator(TestEventListeners *listeners, TestEventListener *listener)
#define EXPECT_PRED1(pred, v1)
#define ASSERT_GT(val1, val2)
internal::TimeInMillis TimeInMillis
UnitTestRecordPropertyTestHelper()
static bool EventForwardingEnabled(const TestEventListeners &listeners)
#define ASSERT_DOUBLE_EQ(expected, actual)
bool ArrayEq(const T *lhs, size_t size, const U *rhs)
#define ASSERT_NE(val1, val2)
TEST_F(ListenerTest, DoesFoo)
static bool HasNonfatalFailureHelper()
#define ASSERT_PRED1(pred, v1)
#define GTEST_ASSERT_GE(val1, val2)
const char * name() const
#define ASSERT_THROW(statement, expected_exception)
virtual void OnTestIterationEnd(const UnitTest &unit_test, int iteration)=0
void TestGTestRemoveConst()
virtual void OnTestProgramEnd(const UnitTest &unit_test)=0
const char * message() const
AssertionResult AssertionSuccess()
TestListener(int *on_start_counter, bool *is_destroyed)
#define EXPECT_DOUBLE_EQ(expected, actual)
#define GTEST_ASSERT_LT(val1, val2)
static void SetUpTestCase()
static bool CaseInsensitiveWideCStringEquals(const wchar_t *lhs, const wchar_t *rhs)
virtual void OnTestProgramStart(const UnitTest &)
#define EXPECT_THROW(statement, expected_exception)
void SetDefaultXmlGenerator(TestEventListener *listener)
const int kMaxStackTraceDepth
FloatingPointTest< float > FloatTest
bool also_run_disabled_tests
void TestGTestRemoveReference()
#define ASSERT_LT(val1, val2)
UInt32 Generate(UInt32 range)
#define GTEST_ASSERT_GT(val1, val2)
#define EXPECT_FALSE(condition)
std::string GetCurrentOsStackTraceExceptTop(UnitTest *, int skip_count)
#define FRIEND_TEST(test_case_name, test_name)
GTEST_API_ const TypeId kTestTypeIdInGoogleTest
def AlsoRunDisabledTestsFlag()
static void RecordProperty(TestResult *test_result, const std::string &xml_element, const TestProperty &property)
const char * file_name() const
TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded)
#define ASSERT_PRED_FORMAT4(pred_format, v1, v2, v3, v4)
static void TearDownTestCase()
#define EXPECT_PRED3(pred, v1, v2, v3)
void TestGTestAddReference()
void UnitTestRecordProperty(const char *key, const std::string &value)
#define ASSERT_NO_THROW(statement)
static bool HasFailureHelper()
#define EXPECT_NE(expected, actual)
static void SetDefaultResultPrinter(TestEventListeners *listeners, TestEventListener *listener)
std::string GetString() const
void TestGTestReferenceToConst()
AssertionResult IsSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
#define EXPECT_GE(val1, val2)
GTEST_API_ TimeInMillis GetTimeInMillis()
MyTypeInNameSpace1(int an_x)
#define ASSERT_TRUE(condition)
#define EXPECT_FATAL_FAILURE_ON_ALL_THREADS(statement, substr)
const char * test_case_name() const
const TestPartResult & GetTestPartResult(int index) const
#define EXPECT_LE(val1, val2)
#define ASSERT_GE(val1, val2)
const TestInfo * current_test_info() const GTEST_LOCK_EXCLUDED_(mutex_)
static void AssertStringArrayEq(size_t size1, CharType **array1, size_t size2, CharType **array2)
#define EXPECT_ANY_THROW(statement)
GTEST_API_ std::string WideStringToUtf8(const wchar_t *str, int num_chars)
bool EventForwardingEnabled() const
static Flags Shuffle(bool shuffle)
#define GTEST_IS_NULL_LITERAL_(x)
const TestResult & ad_hoc_test_result() const
#define ASSERT_PRED3(pred, v1, v2, v3)
int test_property_count() const
void ShuffleRange(internal::Random *random, int begin, int end, std::vector< E > *v)
#define ASSERT_EQ(val1, val2)
std::string AppendUserMessage(const std::string >est_msg, const Message &user_msg)
#define EXPECT_PRED_FORMAT4(pred_format, v1, v2, v3, v4)
virtual void OnTestIterationStart(const UnitTest &, int)
int CountIf(const Container &c, Predicate predicate)
#define EXPECT_PRED2(pred, v1, v2)
#define EXPECT_STRNE(s1, s2)
static Flags ThrowOnFailure(bool throw_on_failure)
virtual void OnTestProgramEnd(const UnitTest &)
#define ASSERT_STRCASENE(s1, s2)
static Flags Filter(const char *filter)
AssertionResult EqFailure(const char *expected_expression, const char *actual_expression, const std::string &expected_value, const std::string &actual_value, bool ignoring_case)
#define ADD_FAILURE_AT(file, line)
const Bits & bits() const
#define ASSERT_NEAR(val1, val2, abs_error)
#define EXPECT_PRED_FORMAT2(pred_format, v1, v2)
TYPED_TEST(TypedTest, TestA)
#define GTEST_ASSERT_EQ(expected, actual)
GTEST_API_ void ParseGoogleTestFlagsOnly(int *argc, char **argv)
#define GTEST_ASSERT_NE(val1, val2)
void Shuffle(internal::Random *random, std::vector< E > *v)
virtual void OnTestIterationEnd(const UnitTest &, int)
std::string GetEventDescription(const char *method)
const_iterator end() const
#define GTEST_FLAG_PREFIX_
bool StaticAssertTypeEq()
#define ASSERT_PRED_FORMAT2(pred_format, v1, v2)
virtual void OnTestProgramStart(const UnitTest &unit_test)=0
#define ASSERT_STREQ(expected, actual)
AssertionResult DoubleLE(const char *expr1, const char *expr2, double val1, double val2)
Int32 Int32FromGTestEnv(const char *flag, Int32 default_value)
const TestResult * result() const
void CopyArray(const T *from, size_t size, U *to)
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()
#define EXPECT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5)
Iter ArrayAwareFind(Iter begin, Iter end, const Element &elem)
static Flags CatchExceptions(bool catch_exceptions)
#define ASSERT_STRCASEEQ(expected, actual)
TypeWithSize< 8 >::Int TimeInMillis
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)
#define GTEST_CHECK_(condition)
const char * value() const
#define ASSERT_PRED_FORMAT1(pred_format, v1)
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 GTEST_FLAG_PREFIX_UPPER_
#define EXPECT_PRED_FORMAT1(pred_format, v1)
static std::string ShowWideCString(const wchar_t *wide_c_str)
IsContainer IsContainerTest(int, typename C::iterator *=NULL, typename C::const_iterator *=NULL)
#define EXPECT_EQ(expected, actual)
#define ASSERT_STRNE(s1, s2)
static Flags RandomSeed(Int32 random_seed)
const TestCase * current_test_case() const GTEST_LOCK_EXCLUDED_(mutex_)
static bool HasNonfatalFailure()
#define EXPECT_FLOAT_EQ(expected, actual)
#define ASSERT_FALSE(condition)
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)
GTEST_API_ bool ParseInt32Flag(const char *str, const char *flag, Int32 *value)
static const UInt32 kMaxRange
TEST(IsXDigitTest, WorksForNarrowAscii)
static Flags PrintTime(bool print_time)
AssertionResult FloatLE(const char *expr1, const char *expr2, float val1, float val2)
void printf(BasicWriter< Char > &w, BasicCStringRef< Char > format, ArgList args)