40TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) {
41 bool dummy = testing::GTEST_FLAG(also_run_disabled_tests)
42 || testing::GTEST_FLAG(break_on_failure)
43 || testing::GTEST_FLAG(catch_exceptions)
44 || testing::GTEST_FLAG(color) !=
"unknown"
45 || testing::GTEST_FLAG(filter) !=
"unknown"
46 || testing::GTEST_FLAG(list_tests)
47 || testing::GTEST_FLAG(output) !=
"unknown"
48 || testing::GTEST_FLAG(print_time)
49 || testing::GTEST_FLAG(random_seed)
50 || testing::GTEST_FLAG(repeat) > 0
51 || testing::GTEST_FLAG(show_internal_stack_frames)
52 || testing::GTEST_FLAG(shuffle)
53 || testing::GTEST_FLAG(stack_trace_depth) > 0
54 || testing::GTEST_FLAG(stream_result_to) !=
"unknown"
55 || testing::GTEST_FLAG(throw_on_failure);
68#include <unordered_set>
77#if GTEST_CAN_STREAM_RESULTS_
79class StreamingListenerTest :
public Test {
81 class FakeSocketWriter :
public StreamingListener::AbstractSocketWriter {
84 virtual void Send(
const std::string& message) { output_ += message; }
89 StreamingListenerTest()
90 : fake_sock_writer_(new FakeSocketWriter),
91 streamer_(fake_sock_writer_),
92 test_info_obj_(
"FooTest",
"Bar", NULL, NULL,
93 CodeLocation(__FILE__, __LINE__), 0, NULL) {}
96 std::string* output() {
return &(fake_sock_writer_->output_); }
98 FakeSocketWriter*
const fake_sock_writer_;
99 StreamingListener streamer_;
104TEST_F(StreamingListenerTest, OnTestProgramEnd) {
106 streamer_.OnTestProgramEnd(unit_test_);
107 EXPECT_EQ(
"event=TestProgramEnd&passed=1\n", *output());
110TEST_F(StreamingListenerTest, OnTestIterationEnd) {
112 streamer_.OnTestIterationEnd(unit_test_, 42);
113 EXPECT_EQ(
"event=TestIterationEnd&passed=1&elapsed_time=0ms\n", *output());
116TEST_F(StreamingListenerTest, OnTestCaseStart) {
118 streamer_.OnTestCaseStart(
TestCase(
"FooTest",
"Bar", NULL, NULL));
119 EXPECT_EQ(
"event=TestCaseStart&name=FooTest\n", *output());
122TEST_F(StreamingListenerTest, OnTestCaseEnd) {
124 streamer_.OnTestCaseEnd(
TestCase(
"FooTest",
"Bar", NULL, NULL));
125 EXPECT_EQ(
"event=TestCaseEnd&passed=1&elapsed_time=0ms\n", *output());
128TEST_F(StreamingListenerTest, OnTestStart) {
130 streamer_.OnTestStart(test_info_obj_);
131 EXPECT_EQ(
"event=TestStart&name=Bar\n", *output());
134TEST_F(StreamingListenerTest, OnTestEnd) {
136 streamer_.OnTestEnd(test_info_obj_);
137 EXPECT_EQ(
"event=TestEnd&passed=1&elapsed_time=0ms\n", *output());
140TEST_F(StreamingListenerTest, OnTestPartResult) {
147 "event=TestPartResult&file=foo.cc&line=42&message=failed%3D%0A%26%25\n",
158 return listeners->repeater();
163 listeners->SetDefaultResultPrinter(listener);
167 listeners->SetDefaultXmlGenerator(listener);
171 return listeners.EventForwardingEnabled();
175 listeners->SuppressEventForwarding();
201using testing::GTEST_FLAG(also_run_disabled_tests);
202using testing::GTEST_FLAG(break_on_failure);
203using testing::GTEST_FLAG(catch_exceptions);
204using testing::GTEST_FLAG(color);
205using testing::GTEST_FLAG(death_test_use_fork);
206using testing::GTEST_FLAG(filter);
207using testing::GTEST_FLAG(list_tests);
208using testing::GTEST_FLAG(output);
209using testing::GTEST_FLAG(print_time);
210using testing::GTEST_FLAG(random_seed);
211using testing::GTEST_FLAG(repeat);
212using testing::GTEST_FLAG(show_internal_stack_frames);
213using testing::GTEST_FLAG(shuffle);
214using testing::GTEST_FLAG(stack_trace_depth);
215using testing::GTEST_FLAG(stream_result_to);
216using testing::GTEST_FLAG(throw_on_failure);
291#if GTEST_HAS_STREAM_REDIRECTION
296#if GTEST_IS_THREADSAFE
297using testing::internal::ThreadWithParam;
306 for (
size_t i = 0; i < vector.size(); i++) {
307 os << vector[i] <<
" ";
316TEST(GetRandomSeedFromFlagTest, HandlesZero) {
317 const int seed = GetRandomSeedFromFlag(0);
319 EXPECT_LE(seed,
static_cast<int>(kMaxRandomSeed));
322TEST(GetRandomSeedFromFlagTest, PreservesValidSeed) {
325 EXPECT_EQ(kMaxRandomSeed - 1, GetRandomSeedFromFlag(kMaxRandomSeed - 1));
326 EXPECT_EQ(
static_cast<int>(kMaxRandomSeed),
327 GetRandomSeedFromFlag(kMaxRandomSeed));
330TEST(GetRandomSeedFromFlagTest, NormalizesInvalidSeed) {
331 const int seed1 = GetRandomSeedFromFlag(-1);
333 EXPECT_LE(seed1,
static_cast<int>(kMaxRandomSeed));
335 const int seed2 = GetRandomSeedFromFlag(kMaxRandomSeed + 1);
337 EXPECT_LE(seed2,
static_cast<int>(kMaxRandomSeed));
340TEST(GetNextRandomSeedTest, WorksForValidInput) {
343 EXPECT_EQ(
static_cast<int>(kMaxRandomSeed),
344 GetNextRandomSeed(kMaxRandomSeed - 1));
345 EXPECT_EQ(1, GetNextRandomSeed(kMaxRandomSeed));
353static void ClearCurrentTestPartResults() {
355 GetUnitTestImpl()->current_test_result());
360TEST(GetTypeIdTest, ReturnsSameValueForSameType) {
361 EXPECT_EQ(GetTypeId<int>(), GetTypeId<int>());
362 EXPECT_EQ(GetTypeId<Test>(), GetTypeId<Test>());
365class SubClassOfTest :
public Test {};
366class AnotherSubClassOfTest :
public Test {};
368TEST(GetTypeIdTest, ReturnsDifferentValuesForDifferentTypes) {
369 EXPECT_NE(GetTypeId<int>(), GetTypeId<const int>());
370 EXPECT_NE(GetTypeId<int>(), GetTypeId<char>());
371 EXPECT_NE(GetTypeId<int>(), GetTestTypeId());
372 EXPECT_NE(GetTypeId<SubClassOfTest>(), GetTestTypeId());
373 EXPECT_NE(GetTypeId<AnotherSubClassOfTest>(), GetTestTypeId());
374 EXPECT_NE(GetTypeId<AnotherSubClassOfTest>(), GetTypeId<SubClassOfTest>());
379TEST(GetTestTypeIdTest, ReturnsTheSameValueInsideOrOutsideOfGoogleTest) {
380 EXPECT_EQ(kTestTypeIdInGoogleTest, GetTestTypeId());
385using ::testing::internal::CanonicalizeForStdLibVersioning;
387TEST(CanonicalizeForStdLibVersioning, LeavesUnversionedNamesUnchanged) {
396TEST(CanonicalizeForStdLibVersioning, ElidesDoubleUnderNames) {
410TEST(FormatTimeInMillisAsSecondsTest, FormatsZero) {
411 EXPECT_EQ(
"0", FormatTimeInMillisAsSeconds(0));
414TEST(FormatTimeInMillisAsSecondsTest, FormatsPositiveNumber) {
415 EXPECT_EQ(
"0.003", FormatTimeInMillisAsSeconds(3));
416 EXPECT_EQ(
"0.01", FormatTimeInMillisAsSeconds(10));
417 EXPECT_EQ(
"0.2", FormatTimeInMillisAsSeconds(200));
418 EXPECT_EQ(
"1.2", FormatTimeInMillisAsSeconds(1200));
419 EXPECT_EQ(
"3", FormatTimeInMillisAsSeconds(3000));
422TEST(FormatTimeInMillisAsSecondsTest, FormatsNegativeNumber) {
423 EXPECT_EQ(
"-0.003", FormatTimeInMillisAsSeconds(-3));
424 EXPECT_EQ(
"-0.01", FormatTimeInMillisAsSeconds(-10));
425 EXPECT_EQ(
"-0.2", FormatTimeInMillisAsSeconds(-200));
426 EXPECT_EQ(
"-1.2", FormatTimeInMillisAsSeconds(-1200));
427 EXPECT_EQ(
"-3", FormatTimeInMillisAsSeconds(-3000));
436class FormatEpochTimeInMillisAsIso8601Test :
public Test {
444 virtual void SetUp() {
449 saved_tz_ = strdup(getenv("TZ"));
455 SetTimeZone("UTC+00");
458 virtual
void TearDown() {
459 SetTimeZone(saved_tz_);
460 free(
const_cast<char*
>(saved_tz_));
464 static void SetTimeZone(
const char* time_zone) {
468#if _MSC_VER || GTEST_OS_WINDOWS_MINGW
471 const std::string env_var =
472 std::string(
"TZ=") + (time_zone ? time_zone :
"");
473 _putenv(env_var.c_str());
479 setenv((
"TZ"), time_zone, 1);
487 const char* saved_tz_;
490const TimeInMillis FormatEpochTimeInMillisAsIso8601Test::kMillisPerSec;
492TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsTwoDigitSegments) {
494 FormatEpochTimeInMillisAsIso8601(1320087162 * kMillisPerSec));
497TEST_F(FormatEpochTimeInMillisAsIso8601Test, MillisecondsDoNotAffectResult) {
499 "2011-10-31T18:52:42",
500 FormatEpochTimeInMillisAsIso8601(1320087162 * kMillisPerSec + 234));
503TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsLeadingZeroes) {
505 FormatEpochTimeInMillisAsIso8601(1315026422 * kMillisPerSec));
508TEST_F(FormatEpochTimeInMillisAsIso8601Test, Prints24HourTime) {
510 FormatEpochTimeInMillisAsIso8601(1317229702 * kMillisPerSec));
513TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsEpochStart) {
514 EXPECT_EQ(
"1970-01-01T00:00:00", FormatEpochTimeInMillisAsIso8601(0));
517#if GTEST_CAN_COMPARE_NULL
521# pragma option push -w-ccc -w-rch
526TEST(NullLiteralTest, IsTrueForNullLiterals) {
535TEST(NullLiteralTest, IsFalseForNonNullLiterals) {
552TEST(CodePointToUtf8Test, CanEncodeNul) {
557TEST(CodePointToUtf8Test, CanEncodeAscii) {
561 EXPECT_EQ(
"\x7F", CodePointToUtf8(L
'\x7F'));
566TEST(CodePointToUtf8Test, CanEncode8To11Bits) {
568 EXPECT_EQ(
"\xC3\x93", CodePointToUtf8(L
'\xD3'));
575 CodePointToUtf8(
static_cast<wchar_t>(0x576)));
580TEST(CodePointToUtf8Test, CanEncode12To16Bits) {
583 CodePointToUtf8(
static_cast<wchar_t>(0x8D3)));
587 CodePointToUtf8(
static_cast<wchar_t>(0xC74D)));
590#if !GTEST_WIDE_STRING_USES_UTF16_
597TEST(CodePointToUtf8Test, CanEncode17To21Bits) {
599 EXPECT_EQ(
"\xF0\x90\xA3\x93", CodePointToUtf8(L
'\x108D3'));
602 EXPECT_EQ(
"\xF0\x90\x90\x80", CodePointToUtf8(L
'\x10400'));
605 EXPECT_EQ(
"\xF4\x88\x98\xB4", CodePointToUtf8(L
'\x108634'));
609TEST(CodePointToUtf8Test, CanEncodeInvalidCodePoint) {
610 EXPECT_EQ(
"(Invalid Unicode 0x1234ABCD)", CodePointToUtf8(L
'\x1234ABCD'));
618TEST(WideStringToUtf8Test, CanEncodeNul) {
624TEST(WideStringToUtf8Test, CanEncodeAscii) {
628 EXPECT_STREQ(
"ab", WideStringToUtf8(L
"ab", -1).c_str());
633TEST(WideStringToUtf8Test, CanEncode8To11Bits) {
635 EXPECT_STREQ(
"\xC3\x93", WideStringToUtf8(L
"\xD3", 1).c_str());
636 EXPECT_STREQ(
"\xC3\x93", WideStringToUtf8(L
"\xD3", -1).c_str());
639 const wchar_t s[] = { 0x576,
'\0' };
646TEST(WideStringToUtf8Test, CanEncode12To16Bits) {
648 const wchar_t s1[] = { 0x8D3,
'\0' };
649 EXPECT_STREQ(
"\xE0\xA3\x93", WideStringToUtf8(s1, 1).c_str());
650 EXPECT_STREQ(
"\xE0\xA3\x93", WideStringToUtf8(s1, -1).c_str());
653 const wchar_t s2[] = { 0xC74D,
'\0' };
654 EXPECT_STREQ(
"\xEC\x9D\x8D", WideStringToUtf8(s2, 1).c_str());
655 EXPECT_STREQ(
"\xEC\x9D\x8D", WideStringToUtf8(s2, -1).c_str());
659TEST(WideStringToUtf8Test, StopsOnNulCharacter) {
660 EXPECT_STREQ(
"ABC", WideStringToUtf8(L
"ABC\0XYZ", 100).c_str());
665TEST(WideStringToUtf8Test, StopsWhenLengthLimitReached) {
666 EXPECT_STREQ(
"ABC", WideStringToUtf8(L
"ABCDEF", 3).c_str());
669#if !GTEST_WIDE_STRING_USES_UTF16_
673TEST(WideStringToUtf8Test, CanEncode17To21Bits) {
675 EXPECT_STREQ(
"\xF0\x90\xA3\x93", WideStringToUtf8(L
"\x108D3", 1).c_str());
676 EXPECT_STREQ(
"\xF0\x90\xA3\x93", WideStringToUtf8(L
"\x108D3", -1).c_str());
679 EXPECT_STREQ(
"\xF4\x88\x98\xB4", WideStringToUtf8(L
"\x108634", 1).c_str());
680 EXPECT_STREQ(
"\xF4\x88\x98\xB4", WideStringToUtf8(L
"\x108634", -1).c_str());
684TEST(WideStringToUtf8Test, CanEncodeInvalidCodePoint) {
686 WideStringToUtf8(L
"\xABCDFF", -1).c_str());
691TEST(WideStringToUtf8Test, CanEncodeValidUtf16SUrrogatePairs) {
692 const wchar_t s[] = { 0xD801, 0xDC00,
'\0' };
693 EXPECT_STREQ(
"\xF0\x90\x90\x80", WideStringToUtf8(
s, -1).c_str());
698TEST(WideStringToUtf8Test, CanEncodeInvalidUtf16SurrogatePair) {
700 const wchar_t s1[] = { 0xD800,
'\0' };
701 EXPECT_STREQ(
"\xED\xA0\x80", WideStringToUtf8(s1, -1).c_str());
703 const wchar_t s2[] = { 0xD800,
'M',
'\0' };
704 EXPECT_STREQ(
"\xED\xA0\x80M", WideStringToUtf8(s2, -1).c_str());
706 const wchar_t s3[] = { 0xDC00,
'P',
'Q',
'R',
'\0' };
707 EXPECT_STREQ(
"\xED\xB0\x80PQR", WideStringToUtf8(s3, -1).c_str());
712#if !GTEST_WIDE_STRING_USES_UTF16_
713TEST(WideStringToUtf8Test, ConcatenatesCodepointsCorrectly) {
714 const wchar_t s[] = { 0x108634, 0xC74D,
'\n', 0x576, 0x8D3, 0x108634,
'\0'};
722 WideStringToUtf8(
s, -1).c_str());
725TEST(WideStringToUtf8Test, ConcatenatesCodepointsCorrectly) {
726 const wchar_t s[] = { 0xC74D,
'\n', 0x576, 0x8D3,
'\0'};
728 "\xEC\x9D\x8D" "\n" "\xD5\xB6" "\xE0\xA3\x93",
729 WideStringToUtf8(
s, -1).c_str());
735TEST(RandomDeathTest, GeneratesCrashesOnInvalidRange) {
739 "Cannot generate a number in the range \\[0, 0\\)");
742 "Generation of a number in \\[0, 2147483649\\) was requested, "
743 "but this can only generate numbers in \\[0, 2147483648\\)");
746TEST(RandomTest, GeneratesNumbersWithinRange) {
747 const UInt32 kRange = 10000;
749 for (
int i = 0; i < 10; i++) {
754 for (
int i = 0; i < 10; i++) {
755 EXPECT_LT(random2.Generate(kRange), kRange) <<
" for iteration " << i;
759TEST(RandomTest, RepeatsWhenReseeded) {
760 const int kSeed = 123;
761 const int kArraySize = 10;
762 const UInt32 kRange = 10000;
766 for (
int i = 0; i < kArraySize; i++) {
771 for (
int i = 0; i < kArraySize; i++) {
772 EXPECT_EQ(values[i],
random.Generate(kRange)) <<
" for iteration " << i;
780static bool IsPositive(
int n) {
return n > 0; }
782TEST(ContainerUtilityTest, CountIf) {
799static void Accumulate(
int n) { g_sum += n; }
801TEST(ContainerUtilityTest, ForEach) {
804 ForEach(v, Accumulate);
809 ForEach(v, Accumulate);
815 ForEach(v, Accumulate);
820TEST(ContainerUtilityTest, GetElementOr) {
832TEST(ContainerUtilityDeathTest, ShuffleRange) {
840 ShuffleRange(&
random, -1, 1, &
a),
841 "Invalid shuffle range start -1: must be in range \\[0, 3\\]");
843 ShuffleRange(&
random, 4, 4, &
a),
844 "Invalid shuffle range start 4: must be in range \\[0, 3\\]");
846 ShuffleRange(&
random, 3, 2, &
a),
847 "Invalid shuffle range finish 2: must be in range \\[3, 3\\]");
849 ShuffleRange(&
random, 3, 4, &
a),
850 "Invalid shuffle range finish 4: must be in range \\[3, 3\\]");
853class VectorShuffleTest :
public Test {
855 static const int kVectorSize = 20;
857 VectorShuffleTest() : random_(1) {
858 for (
int i = 0; i < kVectorSize; i++) {
859 vector_.push_back(i);
864 if (kVectorSize !=
static_cast<int>(vector.size())) {
868 bool found_in_vector[kVectorSize] = {
false };
869 for (
size_t i = 0; i < vector.size(); i++) {
870 const int e = vector[i];
871 if (e < 0 || e >= kVectorSize || found_in_vector[e]) {
874 found_in_vector[e] =
true;
882 static bool VectorIsNotCorrupt(
const TestingVector& vector) {
883 return !VectorIsCorrupt(vector);
886 static bool RangeIsShuffled(
const TestingVector& vector,
int begin,
int end) {
887 for (
int i = begin; i < end; i++) {
888 if (i != vector[i]) {
895 static bool RangeIsUnshuffled(
897 return !RangeIsShuffled(vector, begin, end);
901 return RangeIsShuffled(vector, 0,
static_cast<int>(vector.size()));
904 static bool VectorIsUnshuffled(
const TestingVector& vector) {
905 return !VectorIsShuffled(vector);
912const int VectorShuffleTest::kVectorSize;
914TEST_F(VectorShuffleTest, HandlesEmptyRange) {
916 ShuffleRange(&random_, 0, 0, &vector_);
921 ShuffleRange(&random_, kVectorSize/2, kVectorSize/2, &vector_);
926 ShuffleRange(&random_, kVectorSize - 1, kVectorSize - 1, &vector_);
931 ShuffleRange(&random_, kVectorSize, kVectorSize, &vector_);
936TEST_F(VectorShuffleTest, HandlesRangeOfSizeOne) {
938 ShuffleRange(&random_, 0, 1, &vector_);
943 ShuffleRange(&random_, kVectorSize/2, kVectorSize/2 + 1, &vector_);
948 ShuffleRange(&random_, kVectorSize - 1, kVectorSize, &vector_);
956TEST_F(VectorShuffleTest, ShufflesEntireVector) {
957 Shuffle(&random_, &vector_);
964 EXPECT_NE(kVectorSize - 1, vector_[kVectorSize - 1]);
967TEST_F(VectorShuffleTest, ShufflesStartOfVector) {
968 const int kRangeSize = kVectorSize/2;
970 ShuffleRange(&random_, 0, kRangeSize, &vector_);
974 EXPECT_PRED3(RangeIsUnshuffled, vector_, kRangeSize, kVectorSize);
977TEST_F(VectorShuffleTest, ShufflesEndOfVector) {
978 const int kRangeSize = kVectorSize / 2;
979 ShuffleRange(&random_, kRangeSize, kVectorSize, &vector_);
982 EXPECT_PRED3(RangeIsUnshuffled, vector_, 0, kRangeSize);
983 EXPECT_PRED3(RangeIsShuffled, vector_, kRangeSize, kVectorSize);
986TEST_F(VectorShuffleTest, ShufflesMiddleOfVector) {
987 int kRangeSize = kVectorSize/3;
988 ShuffleRange(&random_, kRangeSize, 2*kRangeSize, &vector_);
991 EXPECT_PRED3(RangeIsUnshuffled, vector_, 0, kRangeSize);
992 EXPECT_PRED3(RangeIsShuffled, vector_, kRangeSize, 2*kRangeSize);
993 EXPECT_PRED3(RangeIsUnshuffled, vector_, 2*kRangeSize, kVectorSize);
996TEST_F(VectorShuffleTest, ShufflesRepeatably) {
998 for (
int i = 0; i < kVectorSize; i++) {
999 vector2.push_back(i);
1002 random_.Reseed(1234);
1003 Shuffle(&random_, &vector_);
1004 random_.Reseed(1234);
1005 Shuffle(&random_, &vector2);
1010 for (
int i = 0; i < kVectorSize; i++) {
1011 EXPECT_EQ(vector_[i], vector2[i]) <<
" where i is " << i;
1017TEST(AssertHelperTest, AssertHelperIsSmall) {
1024TEST(StringTest, EndsWithCaseInsensitive) {
1025 EXPECT_TRUE(String::EndsWithCaseInsensitive(
"foobar",
"BAR"));
1026 EXPECT_TRUE(String::EndsWithCaseInsensitive(
"foobaR",
"bar"));
1027 EXPECT_TRUE(String::EndsWithCaseInsensitive(
"foobar",
""));
1028 EXPECT_TRUE(String::EndsWithCaseInsensitive(
"",
""));
1030 EXPECT_FALSE(String::EndsWithCaseInsensitive(
"Foobar",
"foo"));
1031 EXPECT_FALSE(String::EndsWithCaseInsensitive(
"foobar",
"Foo"));
1032 EXPECT_FALSE(String::EndsWithCaseInsensitive(
"",
"foo"));
1038static const wchar_t*
const kNull = NULL;
1041TEST(StringTest, CaseInsensitiveWideCStringEquals) {
1042 EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(NULL, NULL));
1043 EXPECT_FALSE(String::CaseInsensitiveWideCStringEquals(kNull, L
""));
1044 EXPECT_FALSE(String::CaseInsensitiveWideCStringEquals(L
"", kNull));
1045 EXPECT_FALSE(String::CaseInsensitiveWideCStringEquals(kNull, L
"foobar"));
1046 EXPECT_FALSE(String::CaseInsensitiveWideCStringEquals(L
"foobar", kNull));
1047 EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(L
"foobar", L
"foobar"));
1048 EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(L
"foobar", L
"FOOBAR"));
1049 EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(L
"FOOBAR", L
"foobar"));
1055TEST(StringTest, ShowWideCString) {
1057 String::ShowWideCString(NULL).c_str());
1058 EXPECT_STREQ(
"", String::ShowWideCString(L
"").c_str());
1059 EXPECT_STREQ(
"foo", String::ShowWideCString(L
"foo").c_str());
1062# if GTEST_OS_WINDOWS_MOBILE
1063TEST(StringTest, AnsiAndUtf16Null) {
1064 EXPECT_EQ(NULL, String::AnsiToUtf16(NULL));
1065 EXPECT_EQ(NULL, String::Utf16ToAnsi(NULL));
1068TEST(StringTest, AnsiAndUtf16ConvertBasic) {
1069 const char* ansi = String::Utf16ToAnsi(L
"str");
1072 const WCHAR* utf16 = String::AnsiToUtf16(
"str");
1073 EXPECT_EQ(0, wcsncmp(L
"str", utf16, 3));
1077TEST(StringTest, AnsiAndUtf16ConvertPathChars) {
1078 const char* ansi = String::Utf16ToAnsi(L
".:\\ \"*?");
1081 const WCHAR* utf16 = String::AnsiToUtf16(
".:\\ \"*?");
1082 EXPECT_EQ(0, wcsncmp(L
".:\\ \"*?", utf16, 3));
1090TEST(TestPropertyTest, StringValue) {
1097TEST(TestPropertyTest, ReplaceStringValue) {
1100 property.SetValue(
"2");
1107static void AddFatalFailure() {
1108 FAIL() <<
"Expected fatal failure.";
1111static void AddNonfatalFailure() {
1115class ScopedFakeTestPartResultReporterTest :
public Test {
1121 static void AddFailure(FailureMode failure) {
1122 if (failure == FATAL_FAILURE) {
1125 AddNonfatalFailure();
1132TEST_F(ScopedFakeTestPartResultReporterTest, InterceptsTestFailures) {
1136 ScopedFakeTestPartResultReporter::INTERCEPT_ONLY_CURRENT_THREAD,
1138 AddFailure(NONFATAL_FAILURE);
1139 AddFailure(FATAL_FAILURE);
1147TEST_F(ScopedFakeTestPartResultReporterTest, DeprecatedConstructor) {
1152 AddFailure(NONFATAL_FAILURE);
1157#if GTEST_IS_THREADSAFE
1159class ScopedFakeTestPartResultReporterWithThreadsTest
1160 :
public ScopedFakeTestPartResultReporterTest {
1162 static void AddFailureInOtherThread(FailureMode failure) {
1163 ThreadWithParam<FailureMode> thread(&AddFailure, failure, NULL);
1168TEST_F(ScopedFakeTestPartResultReporterWithThreadsTest,
1169 InterceptsTestFailuresInAllThreads) {
1173 ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS, &
results);
1174 AddFailure(NONFATAL_FAILURE);
1175 AddFailure(FATAL_FAILURE);
1176 AddFailureInOtherThread(NONFATAL_FAILURE);
1177 AddFailureInOtherThread(FATAL_FAILURE);
1193typedef ScopedFakeTestPartResultReporterTest ExpectFatalFailureTest;
1195TEST_F(ExpectFatalFailureTest, CatchesFatalFaliure) {
1199#if GTEST_HAS_GLOBAL_STRING
1200TEST_F(ExpectFatalFailureTest, AcceptsStringObject) {
1205TEST_F(ExpectFatalFailureTest, AcceptsStdStringObject) {
1207 ::std::string(
"Expected fatal failure."));
1210TEST_F(ExpectFatalFailureTest, CatchesFatalFailureOnAllThreads) {
1214 "Expected fatal failure.");
1219# pragma option push -w-ccc
1225int NonVoidFunction() {
1231TEST_F(ExpectFatalFailureTest, CanBeUsedInNonVoidFunction) {
1238void DoesNotAbortHelper(
bool* aborted) {
1250TEST_F(ExpectFatalFailureTest, DoesNotAbort) {
1252 DoesNotAbortHelper(&aborted);
1260static int global_var = 0;
1261#define GTEST_USE_UNPROTECTED_COMMA_ global_var++, global_var++
1263TEST_F(ExpectFatalFailureTest, AcceptsMacroThatExpandsToUnprotectedComma) {
1280typedef ScopedFakeTestPartResultReporterTest ExpectNonfatalFailureTest;
1282TEST_F(ExpectNonfatalFailureTest, CatchesNonfatalFailure) {
1284 "Expected non-fatal failure.");
1287#if GTEST_HAS_GLOBAL_STRING
1288TEST_F(ExpectNonfatalFailureTest, AcceptsStringObject) {
1290 ::string(
"Expected non-fatal failure."));
1294TEST_F(ExpectNonfatalFailureTest, AcceptsStdStringObject) {
1296 ::std::string(
"Expected non-fatal failure."));
1299TEST_F(ExpectNonfatalFailureTest, CatchesNonfatalFailureOnAllThreads) {
1303 "Expected non-fatal failure.");
1309TEST_F(ExpectNonfatalFailureTest, AcceptsMacroThatExpandsToUnprotectedComma) {
1312 AddNonfatalFailure();
1317 AddNonfatalFailure();
1321#if GTEST_IS_THREADSAFE
1323typedef ScopedFakeTestPartResultReporterWithThreadsTest
1324 ExpectFailureWithThreadsTest;
1326TEST_F(ExpectFailureWithThreadsTest, ExpectFatalFailureOnAllThreads) {
1328 "Expected fatal failure.");
1331TEST_F(ExpectFailureWithThreadsTest, ExpectNonFatalFailureOnAllThreads) {
1333 AddFailureInOtherThread(NONFATAL_FAILURE),
"Expected non-fatal failure.");
1340TEST(TestPropertyTest, ConstructorWorks) {
1346TEST(TestPropertyTest, SetValue) {
1349 property.SetValue(
"value_2");
1357class TestResultTest :
public Test {
1359 typedef std::vector<TestPartResult> TPRVector;
1367 virtual void SetUp() {
1390 TPRVector* results1 =
const_cast<TPRVector*
>(
1391 &TestResultAccessor::test_part_results(*r1));
1392 TPRVector* results2 =
const_cast<TPRVector*
>(
1393 &TestResultAccessor::test_part_results(*r2));
1398 results1->push_back(*pr1);
1401 results2->push_back(*pr1);
1402 results2->push_back(*pr2);
1405 virtual void TearDown() {
1415 static void CompareTestPartResult(
const TestPartResult& expected,
1430TEST_F(TestResultTest, total_part_count) {
1437TEST_F(TestResultTest, Passed) {
1444TEST_F(TestResultTest, Failed) {
1452typedef TestResultTest TestResultDeathTest;
1454TEST_F(TestResultDeathTest, GetTestPartResult) {
1462TEST(TestResultPropertyTest, NoPropertiesFoundWhenNoneAreAdded) {
1468TEST(TestResultPropertyTest, OnePropertyFoundWhenAdded) {
1471 TestResultAccessor::RecordProperty(&test_result,
"testcase", property);
1479TEST(TestResultPropertyTest, MultiplePropertiesFoundWhenAdded) {
1483 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_1);
1484 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_2);
1496TEST(TestResultPropertyTest, OverridesValuesForDuplicateKeys) {
1502 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_1_1);
1503 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_2_1);
1504 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_1_2);
1505 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_2_2);
1518TEST(TestResultPropertyTest, GetTestProperty) {
1523 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_1);
1524 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_2);
1525 TestResultAccessor::RecordProperty(&test_result,
"testcase", property_3);
1556class GTestFlagSaverTest :
public Test {
1561 static void SetUpTestCase() {
1576 GTEST_FLAG(stack_trace_depth) = kMaxStackTraceDepth;
1583 static void TearDownTestCase() {
1590 void VerifyAndModifyFlags() {
1620 GTEST_FLAG(stream_result_to) =
"localhost:1234";
1635TEST_F(GTestFlagSaverTest, ModifyGTestFlags) {
1636 VerifyAndModifyFlags();
1641TEST_F(GTestFlagSaverTest, VerifyGTestFlags) {
1642 VerifyAndModifyFlags();
1648static void SetEnv(
const char*
name,
const char*
value) {
1649#if GTEST_OS_WINDOWS_MOBILE
1652#elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9)
1656 static std::map<std::string, std::string*> added_env;
1660 std::string *prev_env = NULL;
1661 if (added_env.find(
name) != added_env.end()) {
1662 prev_env = added_env[
name];
1664 added_env[
name] =
new std::string(
1670 putenv(
const_cast<char*
>(added_env[
name]->c_str()));
1672#elif GTEST_OS_WINDOWS
1675 if (*
value ==
'\0') {
1683#if !GTEST_OS_WINDOWS_MOBILE
1692TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenVariableIsNotSet) {
1694 EXPECT_EQ(10, Int32FromGTestEnv(
"temp", 10));
1697# if !defined(GTEST_GET_INT32_FROM_ENV_)
1701TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenValueOverflows) {
1702 printf(
"(expecting 2 warnings)\n");
1705 EXPECT_EQ(20, Int32FromGTestEnv(
"temp", 20));
1708 EXPECT_EQ(30, Int32FromGTestEnv(
"temp", 30));
1713TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenValueIsInvalid) {
1714 printf(
"(expecting 2 warnings)\n");
1717 EXPECT_EQ(40, Int32FromGTestEnv(
"temp", 40));
1720 EXPECT_EQ(50, Int32FromGTestEnv(
"temp", 50));
1728TEST(Int32FromGTestEnvTest, ParsesAndReturnsValidValue) {
1730 EXPECT_EQ(123, Int32FromGTestEnv(
"temp", 0));
1733 EXPECT_EQ(-321, Int32FromGTestEnv(
"temp", 0));
1741TEST(ParseInt32FlagTest, ReturnsFalseForInvalidFlag) {
1752TEST(ParseInt32FlagTest, ReturnsDefaultWhenValueOverflows) {
1753 printf(
"(expecting 2 warnings)\n");
1766TEST(ParseInt32FlagTest, ReturnsDefaultWhenValueIsInvalid) {
1767 printf(
"(expecting 2 warnings)\n");
1780TEST(ParseInt32FlagTest, ParsesAndReturnsValidValue) {
1793#if !GTEST_OS_WINDOWS_MOBILE
1794TEST(Int32FromEnvOrDieTest, ParsesAndReturnsValidValue) {
1805TEST(Int32FromEnvOrDieDeathTest, AbortsOnFailure) {
1814TEST(Int32FromEnvOrDieDeathTest, AbortsOnInt32Overflow) {
1823TEST(ShouldRunTestOnShardTest, IsPartitionWhenThereIsOneShard) {
1833 virtual void SetUp() {
1838 virtual void TearDown() {
1839 SetEnv(index_var_,
"");
1840 SetEnv(total_var_,
"");
1843 const char* index_var_;
1844 const char* total_var_;
1849TEST_F(ShouldShardTest, ReturnsFalseWhenNeitherEnvVarIsSet) {
1850 SetEnv(index_var_,
"");
1851 SetEnv(total_var_,
"");
1853 EXPECT_FALSE(ShouldShard(total_var_, index_var_,
false));
1854 EXPECT_FALSE(ShouldShard(total_var_, index_var_,
true));
1858TEST_F(ShouldShardTest, ReturnsFalseWhenTotalShardIsOne) {
1859 SetEnv(index_var_,
"0");
1860 SetEnv(total_var_,
"1");
1861 EXPECT_FALSE(ShouldShard(total_var_, index_var_,
false));
1862 EXPECT_FALSE(ShouldShard(total_var_, index_var_,
true));
1868#if !GTEST_OS_WINDOWS_MOBILE
1869TEST_F(ShouldShardTest, WorksWhenShardEnvVarsAreValid) {
1870 SetEnv(index_var_,
"4");
1871 SetEnv(total_var_,
"22");
1872 EXPECT_TRUE(ShouldShard(total_var_, index_var_,
false));
1873 EXPECT_FALSE(ShouldShard(total_var_, index_var_,
true));
1875 SetEnv(index_var_,
"8");
1876 SetEnv(total_var_,
"9");
1877 EXPECT_TRUE(ShouldShard(total_var_, index_var_,
false));
1878 EXPECT_FALSE(ShouldShard(total_var_, index_var_,
true));
1880 SetEnv(index_var_,
"0");
1881 SetEnv(total_var_,
"9");
1882 EXPECT_TRUE(ShouldShard(total_var_, index_var_,
false));
1883 EXPECT_FALSE(ShouldShard(total_var_, index_var_,
true));
1889typedef ShouldShardTest ShouldShardDeathTest;
1891TEST_F(ShouldShardDeathTest, AbortsWhenShardingEnvVarsAreInvalid) {
1892 SetEnv(index_var_,
"4");
1893 SetEnv(total_var_,
"4");
1896 SetEnv(index_var_,
"4");
1897 SetEnv(total_var_,
"-2");
1900 SetEnv(index_var_,
"5");
1901 SetEnv(total_var_,
"");
1904 SetEnv(index_var_,
"");
1905 SetEnv(total_var_,
"5");
1911TEST(ShouldRunTestOnShardTest, IsPartitionWhenThereAreFiveShards) {
1913 const int num_tests = 17;
1914 const int num_shards = 5;
1917 for (
int test_id = 0; test_id < num_tests; test_id++) {
1918 int prev_selected_shard_index = -1;
1919 for (
int shard_index = 0; shard_index < num_shards; shard_index++) {
1920 if (ShouldRunTestOnShard(num_shards, shard_index, test_id)) {
1921 if (prev_selected_shard_index < 0) {
1922 prev_selected_shard_index = shard_index;
1924 ADD_FAILURE() <<
"Shard " << prev_selected_shard_index <<
" and "
1925 << shard_index <<
" are both selected to run test " << test_id;
1933 for (
int shard_index = 0; shard_index < num_shards; shard_index++) {
1934 int num_tests_on_shard = 0;
1935 for (
int test_id = 0; test_id < num_tests; test_id++) {
1936 num_tests_on_shard +=
1937 ShouldRunTestOnShard(num_shards, shard_index, test_id);
1939 EXPECT_GE(num_tests_on_shard, num_tests / num_shards);
1953TEST(UnitTestTest, CanGetOriginalWorkingDir) {
1954 ASSERT_TRUE(UnitTest::GetInstance()->original_working_dir() != NULL);
1955 EXPECT_STRNE(UnitTest::GetInstance()->original_working_dir(),
"");
1958TEST(UnitTestTest, ReturnsPlausibleTimestamp) {
1959 EXPECT_LT(0, UnitTest::GetInstance()->start_timestamp());
1960 EXPECT_LE(UnitTest::GetInstance()->start_timestamp(), GetTimeInMillis());
1966void ExpectNonFatalFailureRecordingPropertyWithReservedKey(
1967 const TestResult& test_result,
const char* key) {
1970 <<
"' recorded unexpectedly.";
1973void ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
1975 const TestInfo* test_info = UnitTest::GetInstance()->current_test_info();
1977 ExpectNonFatalFailureRecordingPropertyWithReservedKey(*test_info->
result(),
1981void ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestCase(
1983 const TestCase* test_case = UnitTest::GetInstance()->current_test_case();
1985 ExpectNonFatalFailureRecordingPropertyWithReservedKey(
1989void ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestCase(
1991 ExpectNonFatalFailureRecordingPropertyWithReservedKey(
1992 UnitTest::GetInstance()->ad_hoc_test_result(), key);
1998class UnitTestRecordPropertyTest :
2001 static void SetUpTestCase() {
2002 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestCase(
2004 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestCase(
2006 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestCase(
2008 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestCase(
2010 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestCase(
2012 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestCase(
2015 Test::RecordProperty(
"test_case_key_1",
"1");
2016 const TestCase* test_case = UnitTest::GetInstance()->current_test_case();
2028TEST_F(UnitTestRecordPropertyTest, OnePropertyFoundWhenAdded) {
2029 UnitTestRecordProperty(
"key_1",
"1");
2031 ASSERT_EQ(1, unit_test_.ad_hoc_test_result().test_property_count());
2034 unit_test_.ad_hoc_test_result().GetTestProperty(0).key());
2036 unit_test_.ad_hoc_test_result().GetTestProperty(0).value());
2040TEST_F(UnitTestRecordPropertyTest, MultiplePropertiesFoundWhenAdded) {
2041 UnitTestRecordProperty(
"key_1",
"1");
2042 UnitTestRecordProperty(
"key_2",
"2");
2044 ASSERT_EQ(2, unit_test_.ad_hoc_test_result().test_property_count());
2047 unit_test_.ad_hoc_test_result().GetTestProperty(0).key());
2048 EXPECT_STREQ(
"1", unit_test_.ad_hoc_test_result().GetTestProperty(0).value());
2051 unit_test_.ad_hoc_test_result().GetTestProperty(1).key());
2052 EXPECT_STREQ(
"2", unit_test_.ad_hoc_test_result().GetTestProperty(1).value());
2056TEST_F(UnitTestRecordPropertyTest, OverridesValuesForDuplicateKeys) {
2057 UnitTestRecordProperty(
"key_1",
"1");
2058 UnitTestRecordProperty(
"key_2",
"2");
2059 UnitTestRecordProperty(
"key_1",
"12");
2060 UnitTestRecordProperty(
"key_2",
"22");
2062 ASSERT_EQ(2, unit_test_.ad_hoc_test_result().test_property_count());
2065 unit_test_.ad_hoc_test_result().GetTestProperty(0).key());
2067 unit_test_.ad_hoc_test_result().GetTestProperty(0).value());
2070 unit_test_.ad_hoc_test_result().GetTestProperty(1).key());
2072 unit_test_.ad_hoc_test_result().GetTestProperty(1).value());
2075TEST_F(UnitTestRecordPropertyTest,
2076 AddFailureInsideTestsWhenUsingTestCaseReservedKeys) {
2077 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2079 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2081 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2083 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2085 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2087 ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2091TEST_F(UnitTestRecordPropertyTest,
2092 AddRecordWithReservedKeysGeneratesCorrectPropertyList) {
2094 Test::RecordProperty(
"name",
"1"),
2095 "'classname', 'name', 'status', 'time', 'type_param', and 'value_param'"
2099class UnitTestRecordPropertyTestEnvironment :
public Environment {
2101 virtual void TearDown() {
2102 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestCase(
2104 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestCase(
2106 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestCase(
2108 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestCase(
2110 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestCase(
2112 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestCase(
2114 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestCase(
2116 ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestCase(
2135 return (n % 2) == 0;
2139struct IsEvenFunctor {
2140 bool operator()(
int n) {
return IsEven(n); }
2147 return AssertionSuccess();
2151 msg << expr <<
" evaluates to " << n <<
", which is not even.";
2152 return AssertionFailure(msg);
2159 return AssertionSuccess() << n <<
" is even";
2161 return AssertionFailure() << n <<
" is odd";
2169 return AssertionSuccess();
2171 return AssertionFailure() << n <<
" is odd";
2176struct AssertIsEvenFunctor {
2178 return AssertIsEven(expr, n);
2183bool SumIsEven2(
int n1,
int n2) {
2184 return IsEven(n1 + n2);
2189struct SumIsEven3Functor {
2190 bool operator()(
int n1,
int n2,
int n3) {
2191 return IsEven(n1 + n2 + n3);
2198 const char* e1,
const char* e2,
const char* e3,
const char* e4,
2199 int n1,
int n2,
int n3,
int n4) {
2200 const int sum = n1 + n2 + n3 + n4;
2202 return AssertionSuccess();
2206 msg << e1 <<
" + " << e2 <<
" + " << e3 <<
" + " << e4
2207 <<
" (" << n1 <<
" + " << n2 <<
" + " << n3 <<
" + " << n4
2208 <<
") evaluates to " << sum <<
", which is not even.";
2209 return AssertionFailure(msg);
2214struct AssertSumIsEven5Functor {
2216 const char* e1,
const char* e2,
const char* e3,
const char* e4,
2217 const char* e5,
int n1,
int n2,
int n3,
int n4,
int n5) {
2218 const int sum = n1 + n2 + n3 + n4 + n5;
2220 return AssertionSuccess();
2224 msg << e1 <<
" + " << e2 <<
" + " << e3 <<
" + " << e4 <<
" + " << e5
2226 << n1 <<
" + " << n2 <<
" + " << n3 <<
" + " << n4 <<
" + " << n5
2227 <<
") evaluates to " << sum <<
", which is not even.";
2228 return AssertionFailure(msg);
2236TEST(Pred1Test, WithoutFormat) {
2238 EXPECT_PRED1(IsEvenFunctor(), 2) <<
"This failure is UNEXPECTED!";
2243 EXPECT_PRED1(IsEven, 5) <<
"This failure is expected.";
2244 },
"This failure is expected.");
2246 "evaluates to false");
2250TEST(Pred1Test, WithFormat) {
2254 <<
"This failure is UNEXPECTED!";
2259 "n evaluates to 5, which is not even.");
2262 },
"This failure is expected.");
2267TEST(Pred1Test, SingleEvaluationOnFailure) {
2271 EXPECT_EQ(1, n) <<
"The argument is not evaluated exactly once.";
2276 <<
"This failure is expected.";
2277 },
"This failure is expected.");
2278 EXPECT_EQ(2, n) <<
"The argument is not evaluated exactly once.";
2285TEST(PredTest, WithoutFormat) {
2287 ASSERT_PRED2(SumIsEven2, 2, 4) <<
"This failure is UNEXPECTED!";
2294 EXPECT_PRED2(SumIsEven2, n1, n2) <<
"This failure is expected.";
2295 },
"This failure is expected.");
2298 },
"evaluates to false");
2302TEST(PredTest, WithFormat) {
2305 "This failure is UNEXPECTED!";
2315 },
"evaluates to 13, which is not even.");
2318 <<
"This failure is expected.";
2319 },
"This failure is expected.");
2324TEST(PredTest, SingleEvaluationOnFailure) {
2329 EXPECT_EQ(1, n1) <<
"Argument 1 is not evaluated exactly once.";
2330 EXPECT_EQ(1, n2) <<
"Argument 2 is not evaluated exactly once.";
2338 n1++, n2++, n3++, n4++, n5++)
2339 <<
"This failure is UNEXPECTED!";
2340 EXPECT_EQ(1, n1) <<
"Argument 1 is not evaluated exactly once.";
2341 EXPECT_EQ(1, n2) <<
"Argument 2 is not evaluated exactly once.";
2342 EXPECT_EQ(1, n3) <<
"Argument 3 is not evaluated exactly once.";
2343 EXPECT_EQ(1, n4) <<
"Argument 4 is not evaluated exactly once.";
2344 EXPECT_EQ(1, n5) <<
"Argument 5 is not evaluated exactly once.";
2350 <<
"This failure is expected.";
2351 },
"This failure is expected.");
2352 EXPECT_EQ(1, n1) <<
"Argument 1 is not evaluated exactly once.";
2353 EXPECT_EQ(1, n2) <<
"Argument 2 is not evaluated exactly once.";
2354 EXPECT_EQ(1, n3) <<
"Argument 3 is not evaluated exactly once.";
2357 n1 = n2 = n3 = n4 = 0;
2360 },
"evaluates to 1, which is not even.");
2361 EXPECT_EQ(1, n1) <<
"Argument 1 is not evaluated exactly once.";
2362 EXPECT_EQ(1, n2) <<
"Argument 2 is not evaluated exactly once.";
2363 EXPECT_EQ(1, n3) <<
"Argument 3 is not evaluated exactly once.";
2364 EXPECT_EQ(1, n4) <<
"Argument 4 is not evaluated exactly once.";
2375template <
typename T>
2376bool IsNegative(
T x) {
2380template <
typename T1,
typename T2>
2387TEST(PredicateAssertionTest, AcceptsOverloadedFunction) {
2395TEST(PredicateAssertionTest, AcceptsTemplateFunction) {
2407 return n > 0 ? AssertionSuccess() :
2408 AssertionFailure(
Message() <<
"Failure");
2412 return x > 0 ? AssertionSuccess() :
2413 AssertionFailure(
Message() <<
"Failure");
2416template <
typename T>
2418 return x < 0 ? AssertionSuccess() :
2419 AssertionFailure(
Message() <<
"Failure");
2422template <
typename T1,
typename T2>
2424 const T1& x1,
const T2& x2) {
2425 return x1 == x2 ? AssertionSuccess() :
2426 AssertionFailure(
Message() <<
"Failure");
2431TEST(PredicateFormatAssertionTest, AcceptsOverloadedFunction) {
2438TEST(PredicateFormatAssertionTest, AcceptsTemplateFunction) {
2448 const char *
const p1 =
"good";
2452 const char p2[] =
"good";
2456 " \"bad\"\n \"good\"");
2460TEST(StringAssertionTest, ASSERT_STREQ_Null) {
2467TEST(StringAssertionTest, ASSERT_STREQ_Null2) {
2482 "\"Hi\" vs \"Hi\"");
2509TEST(StringAssertionTest, STREQ_Wide) {
2511 ASSERT_STREQ(
static_cast<const wchar_t *
>(NULL), NULL);
2533 EXPECT_STREQ(L
"abc\x8119", L
"abc\x8121") <<
"Expected failure";
2534 },
"Expected failure");
2538TEST(StringAssertionTest, STRNE_Wide) {
2541 EXPECT_STRNE(
static_cast<const wchar_t *
>(NULL), NULL);
2563 ASSERT_STRNE(L
"abc\x8119", L
"abc\x8120") <<
"This shouldn't happen";
2570TEST(IsSubstringTest, ReturnsCorrectResultForCString) {
2573 EXPECT_FALSE(IsSubstring(
"",
"",
"needle",
"haystack"));
2575 EXPECT_TRUE(IsSubstring(
"",
"",
static_cast<const char*
>(NULL), NULL));
2576 EXPECT_TRUE(IsSubstring(
"",
"",
"needle",
"two needles"));
2581TEST(IsSubstringTest, ReturnsCorrectResultForWideCString) {
2584 EXPECT_FALSE(IsSubstring(
"",
"", L
"needle", L
"haystack"));
2586 EXPECT_TRUE(IsSubstring(
"",
"",
static_cast<const wchar_t*
>(NULL), NULL));
2587 EXPECT_TRUE(IsSubstring(
"",
"", L
"needle", L
"two needles"));
2592TEST(IsSubstringTest, GeneratesCorrectMessageForCString) {
2594 " Actual: \"needle\"\n"
2595 "Expected: a substring of haystack_expr\n"
2596 "Which is: \"haystack\"",
2597 IsSubstring(
"needle_expr",
"haystack_expr",
2598 "needle",
"haystack").failure_message());
2603TEST(IsSubstringTest, ReturnsCorrectResultsForStdString) {
2604 EXPECT_TRUE(IsSubstring(
"",
"", std::string(
"hello"),
"ahellob"));
2605 EXPECT_FALSE(IsSubstring(
"",
"",
"hello", std::string(
"world")));
2608#if GTEST_HAS_STD_WSTRING
2611TEST(IsSubstringTest, ReturnsCorrectResultForStdWstring) {
2612 EXPECT_TRUE(IsSubstring(
"",
"", ::std::wstring(L
"needle"), L
"two needles"));
2613 EXPECT_FALSE(IsSubstring(
"",
"", L
"needle", ::std::wstring(L
"haystack")));
2618TEST(IsSubstringTest, GeneratesCorrectMessageForWstring) {
2620 " Actual: L\"needle\"\n"
2621 "Expected: a substring of haystack_expr\n"
2622 "Which is: L\"haystack\"",
2624 "needle_expr",
"haystack_expr",
2625 ::std::wstring(L
"needle"), L
"haystack").failure_message());
2634TEST(IsNotSubstringTest, ReturnsCorrectResultForCString) {
2635 EXPECT_TRUE(IsNotSubstring(
"",
"",
"needle",
"haystack"));
2636 EXPECT_FALSE(IsNotSubstring(
"",
"",
"needle",
"two needles"));
2641TEST(IsNotSubstringTest, ReturnsCorrectResultForWideCString) {
2642 EXPECT_TRUE(IsNotSubstring(
"",
"", L
"needle", L
"haystack"));
2643 EXPECT_FALSE(IsNotSubstring(
"",
"", L
"needle", L
"two needles"));
2648TEST(IsNotSubstringTest, GeneratesCorrectMessageForWideCString) {
2650 " Actual: L\"needle\"\n"
2651 "Expected: not a substring of haystack_expr\n"
2652 "Which is: L\"two needles\"",
2654 "needle_expr",
"haystack_expr",
2655 L
"needle", L
"two needles").failure_message());
2660TEST(IsNotSubstringTest, ReturnsCorrectResultsForStdString) {
2661 EXPECT_FALSE(IsNotSubstring(
"",
"", std::string(
"hello"),
"ahellob"));
2662 EXPECT_TRUE(IsNotSubstring(
"",
"",
"hello", std::string(
"world")));
2667TEST(IsNotSubstringTest, GeneratesCorrectMessageForStdString) {
2669 " Actual: \"needle\"\n"
2670 "Expected: not a substring of haystack_expr\n"
2671 "Which is: \"two needles\"",
2673 "needle_expr",
"haystack_expr",
2674 ::std::string(
"needle"),
"two needles").failure_message());
2677#if GTEST_HAS_STD_WSTRING
2681TEST(IsNotSubstringTest, ReturnsCorrectResultForStdWstring) {
2683 IsNotSubstring(
"",
"", ::std::wstring(L
"needle"), L
"two needles"));
2684 EXPECT_TRUE(IsNotSubstring(
"",
"", L
"needle", ::std::wstring(L
"haystack")));
2691template <
typename RawType>
2692class FloatingPointTest :
public Test {
2696 RawType close_to_positive_zero;
2697 RawType close_to_negative_zero;
2698 RawType further_from_negative_zero;
2700 RawType close_to_one;
2701 RawType further_from_one;
2704 RawType close_to_infinity;
2705 RawType further_from_infinity;
2712 typedef typename Floating::Bits
Bits;
2714 virtual void SetUp() {
2715 const size_t max_ulps = Floating::kMaxUlps;
2718 const Bits zero_bits = Floating(0).bits();
2721 values_.close_to_positive_zero = Floating::ReinterpretBits(
2722 zero_bits + max_ulps/2);
2723 values_.close_to_negative_zero = -Floating::ReinterpretBits(
2724 zero_bits + max_ulps - max_ulps/2);
2725 values_.further_from_negative_zero = -Floating::ReinterpretBits(
2726 zero_bits + max_ulps + 1 - max_ulps/2);
2729 const Bits one_bits = Floating(1).bits();
2732 values_.close_to_one = Floating::ReinterpretBits(one_bits + max_ulps);
2733 values_.further_from_one = Floating::ReinterpretBits(
2734 one_bits + max_ulps + 1);
2737 values_.infinity = Floating::Infinity();
2740 const Bits infinity_bits = Floating(values_.infinity).bits();
2743 values_.close_to_infinity = Floating::ReinterpretBits(
2744 infinity_bits - max_ulps);
2745 values_.further_from_infinity = Floating::ReinterpretBits(
2746 infinity_bits - max_ulps - 1);
2751 values_.nan1 = Floating::ReinterpretBits(Floating::kExponentBitMask
2752 | (
static_cast<Bits>(1) << (Floating::kFractionBitCount - 1)) | 1);
2753 values_.nan2 = Floating::ReinterpretBits(Floating::kExponentBitMask
2754 | (
static_cast<Bits>(1) << (Floating::kFractionBitCount - 1)) | 200);
2758 EXPECT_EQ(
sizeof(RawType),
sizeof(Bits));
2761 static TestValues values_;
2764template <
typename RawType>
2765typename FloatingPointTest<RawType>::TestValues
2766 FloatingPointTest<RawType>::values_;
2769typedef FloatingPointTest<float>
FloatTest;
2777TEST_F(FloatTest, Zeros) {
2790TEST_F(FloatTest, AlmostZeros) {
2797 static const FloatTest::TestValues& v = this->values_;
2805 v.further_from_negative_zero);
2806 },
"v.further_from_negative_zero");
2810TEST_F(FloatTest, SmallDiff) {
2813 "values_.further_from_one");
2817TEST_F(FloatTest, LargeDiff) {
2826TEST_F(FloatTest, Infinity) {
2829#if !GTEST_OS_SYMBIAN
2832 "-values_.infinity");
2843#if !GTEST_OS_SYMBIAN
2852 static const FloatTest::TestValues& v = this->values_;
2867TEST_F(FloatTest, Reflexive) {
2874TEST_F(FloatTest, Commutative) {
2888 "The difference between 1.0f and 1.5f is 0.5, "
2889 "which exceeds 0.25f");
2899 "The difference between 1.0f and 1.5f is 0.5, "
2900 "which exceeds 0.25f");
2906TEST_F(FloatTest, FloatLESucceeds) {
2915TEST_F(FloatTest, FloatLEFails) {
2918 "(2.0f) <= (1.0f)");
2923 },
"(values_.further_from_one) <= (1.0f)");
2925#if !GTEST_OS_SYMBIAN && !defined(__BORLANDC__)
2931 },
"(values_.nan1) <= (values_.infinity)");
2934 },
"(-values_.infinity) <= (values_.nan1)");
2937 },
"(values_.nan1) <= (values_.nan1)");
2945TEST_F(DoubleTest, Size) {
2950TEST_F(DoubleTest, Zeros) {
2963TEST_F(DoubleTest, AlmostZeros) {
2970 static const DoubleTest::TestValues& v = this->values_;
2978 v.further_from_negative_zero);
2979 },
"v.further_from_negative_zero");
2983TEST_F(DoubleTest, SmallDiff) {
2986 "values_.further_from_one");
2990TEST_F(DoubleTest, LargeDiff) {
2999TEST_F(DoubleTest, Infinity) {
3002#if !GTEST_OS_SYMBIAN
3005 "-values_.infinity");
3016#if !GTEST_OS_SYMBIAN
3023 static const DoubleTest::TestValues& v = this->values_;
3036TEST_F(DoubleTest, Reflexive) {
3039#if !GTEST_OS_SYMBIAN
3046TEST_F(DoubleTest, Commutative) {
3060 "The difference between 1.0 and 1.5 is 0.5, "
3061 "which exceeds 0.25");
3071 "The difference between 1.0 and 1.5 is 0.5, "
3072 "which exceeds 0.25");
3078TEST_F(DoubleTest, DoubleLESucceeds) {
3087TEST_F(DoubleTest, DoubleLEFails) {
3095 },
"(values_.further_from_one) <= (1.0)");
3097#if !GTEST_OS_SYMBIAN && !defined(__BORLANDC__)
3103 },
"(values_.nan1) <= (values_.infinity)");
3106 },
" (-values_.infinity) <= (values_.nan1)");
3109 },
"(values_.nan1) <= (values_.nan1)");
3120 FAIL() <<
"Unexpected failure: Disabled test should not be run.";
3131TEST(DISABLED_TestCase, TestShouldNotRun) {
3132 FAIL() <<
"Unexpected failure: Test in disabled test case should not be run.";
3137TEST(DISABLED_TestCase, DISABLED_TestShouldNotRun) {
3138 FAIL() <<
"Unexpected failure: Test in disabled test case should not be run.";
3143class DisabledTestsTest :
public Test {
3145 static void SetUpTestCase() {
3146 FAIL() <<
"Unexpected failure: All tests disabled in test case. "
3147 "SetUpTestCase() should not be called.";
3150 static void TearDownTestCase() {
3151 FAIL() <<
"Unexpected failure: All tests disabled in test case. "
3152 "TearDownTestCase() should not be called.";
3156TEST_F(DisabledTestsTest, DISABLED_TestShouldNotRun_1) {
3157 FAIL() <<
"Unexpected failure: Disabled test should not be run.";
3160TEST_F(DisabledTestsTest, DISABLED_TestShouldNotRun_2) {
3161 FAIL() <<
"Unexpected failure: Disabled test should not be run.";
3166#if GTEST_HAS_TYPED_TEST
3168template <
typename T>
3172typedef testing::Types<int, double> NumericTypes;
3176 FAIL() <<
"Unexpected failure: Disabled typed test should not run.";
3179template <
typename T>
3180class DISABLED_TypedTest :
public Test {
3185TYPED_TEST(DISABLED_TypedTest, ShouldNotRun) {
3186 FAIL() <<
"Unexpected failure: Disabled typed test should not run.";
3193#if GTEST_HAS_TYPED_TEST_P
3195template <
typename T>
3196class TypedTestP :
public Test {
3202 FAIL() <<
"Unexpected failure: "
3203 <<
"Disabled type-parameterized test should not run.";
3210template <
typename T>
3211class DISABLED_TypedTestP :
public Test {
3217 FAIL() <<
"Unexpected failure: "
3218 <<
"Disabled type-parameterized test should not run.";
3229class SingleEvaluationTest :
public Test {
3234 static void CompareAndIncrementCharPtrs() {
3240 static void CompareAndIncrementInts() {
3245 SingleEvaluationTest() {
3252 static const char*
const s1_;
3253 static const char*
const s2_;
3254 static const char* p1_;
3255 static const char* p2_;
3261const char*
const SingleEvaluationTest::s1_ =
"01234";
3262const char*
const SingleEvaluationTest::s2_ =
"abcde";
3263const char* SingleEvaluationTest::p1_;
3264const char* SingleEvaluationTest::p2_;
3265int SingleEvaluationTest::a_;
3266int SingleEvaluationTest::b_;
3270TEST_F(SingleEvaluationTest, FailedASSERT_STREQ) {
3278TEST_F(SingleEvaluationTest, ASSERT_STR) {
3293TEST_F(SingleEvaluationTest, FailedASSERT_NE) {
3295 "(a_++) != (b_++)");
3301TEST_F(SingleEvaluationTest, OtherCases) {
3330#if GTEST_HAS_EXCEPTIONS
3332void ThrowAnInteger() {
3349 }, bool),
"throws a different type");
3382class NoFatalFailureTest :
public Test {
3385 void FailsNonFatal() {
3389 FAIL() <<
"some fatal failure";
3392 void DoAssertNoFatalFailureOnFails() {
3397 void DoExpectNoFatalFailureOnFails() {
3403TEST_F(NoFatalFailureTest, NoFailure) {
3408TEST_F(NoFatalFailureTest, NonFatalIsNoFailure) {
3411 "some non-fatal failure");
3414 "some non-fatal failure");
3417TEST_F(NoFatalFailureTest, AssertNoFatalFailureOnFatalFailure) {
3421 DoAssertNoFatalFailureOnFails();
3424 EXPECT_EQ(TestPartResult::kFatalFailure,
3426 EXPECT_EQ(TestPartResult::kFatalFailure,
3434TEST_F(NoFatalFailureTest, ExpectNoFatalFailureOnFatalFailure) {
3438 DoExpectNoFatalFailureOnFails();
3441 EXPECT_EQ(TestPartResult::kFatalFailure,
3443 EXPECT_EQ(TestPartResult::kNonFatalFailure,
3445 EXPECT_EQ(TestPartResult::kNonFatalFailure,
3455TEST_F(NoFatalFailureTest, MessageIsStreamable) {
3462 EXPECT_EQ(TestPartResult::kNonFatalFailure,
3464 EXPECT_EQ(TestPartResult::kNonFatalFailure,
3474std::string EditsToString(
const std::vector<EditType>& edits) {
3476 for (
size_t i = 0; i < edits.size(); ++i) {
3477 static const char kEdits[] =
" +-/";
3478 out.append(1, kEdits[edits[i]]);
3483std::vector<size_t> CharsToIndices(
const std::string& str) {
3484 std::vector<size_t> out;
3485 for (
size_t i = 0; i <
str.size(); ++i) {
3486 out.push_back(str[i]);
3491std::vector<std::string> CharsToLines(
const std::string& str) {
3492 std::vector<std::string> out;
3493 for (
size_t i = 0; i <
str.size(); ++i) {
3494 out.push_back(
str.substr(i, 1));
3499TEST(EditDistance, TestCases) {
3504 const char* expected_edits;
3505 const char* expected_diff;
3507 static const Case kCases[] = {
3509 {__LINE__,
"A",
"A",
" ",
""},
3510 {__LINE__,
"ABCDE",
"ABCDE",
" ",
""},
3512 {__LINE__,
"X",
"XA",
" +",
"@@ +1,2 @@\n X\n+A\n"},
3513 {__LINE__,
"X",
"XABCD",
" ++++",
"@@ +1,5 @@\n X\n+A\n+B\n+C\n+D\n"},
3515 {__LINE__,
"XA",
"X",
" -",
"@@ -1,2 @@\n X\n-A\n"},
3516 {__LINE__,
"XABCD",
"X",
" ----",
"@@ -1,5 @@\n X\n-A\n-B\n-C\n-D\n"},
3518 {__LINE__,
"A",
"a",
"/",
"@@ -1,1 +1,1 @@\n-A\n+a\n"},
3519 {__LINE__,
"ABCD",
"abcd",
"////",
3520 "@@ -1,4 +1,4 @@\n-A\n-B\n-C\n-D\n+a\n+b\n+c\n+d\n"},
3522 {__LINE__,
"ABCDEFGH",
"ABXEGH1",
" -/ - +",
3523 "@@ -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"},
3524 {__LINE__,
"AAAABCCCC",
"ABABCDCDC",
"- / + / ",
3525 "@@ -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"},
3526 {__LINE__,
"ABCDE",
"BCDCD",
"- +/",
3527 "@@ -1,5 +1,5 @@\n-A\n B\n C\n D\n-E\n+C\n+D\n"},
3528 {__LINE__,
"ABCDEFGHIJKL",
"BCDCDEFGJKLJK",
"- ++ -- ++",
3529 "@@ -1,4 +1,5 @@\n-A\n B\n+C\n+D\n C\n D\n"
3530 "@@ -6,7 +7,7 @@\n F\n G\n-H\n-I\n J\n K\n L\n+J\n+K\n"},
3532 for (
const Case* c = kCases; c->left; ++c) {
3534 EditsToString(CalculateOptimalEdits(CharsToIndices(c->left),
3535 CharsToIndices(c->right))))
3536 <<
"Left <" << c->left <<
"> Right <" << c->right <<
"> Edits <"
3537 << EditsToString(CalculateOptimalEdits(
3538 CharsToIndices(c->left), CharsToIndices(c->right))) <<
">";
3539 EXPECT_TRUE(c->expected_diff == CreateUnifiedDiff(CharsToLines(c->left),
3540 CharsToLines(c->right)))
3541 <<
"Left <" << c->left <<
"> Right <" << c->right <<
"> Diff <"
3542 << CreateUnifiedDiff(CharsToLines(c->left), CharsToLines(c->right))
3548TEST(AssertionTest, EqFailure) {
3549 const std::string foo_val(
"5"), bar_val(
"6");
3550 const std::string msg1(
3551 EqFailure(
"foo",
"bar", foo_val, bar_val,
false)
3552 .failure_message());
3554 "Expected equality of these values:\n"
3561 const std::string msg2(
3562 EqFailure(
"foo",
"6", foo_val, bar_val,
false)
3563 .failure_message());
3565 "Expected equality of these values:\n"
3571 const std::string msg3(
3572 EqFailure(
"5",
"bar", foo_val, bar_val,
false)
3573 .failure_message());
3575 "Expected equality of these values:\n"
3581 const std::string msg4(
3582 EqFailure(
"5",
"6", foo_val, bar_val,
false).failure_message());
3584 "Expected equality of these values:\n"
3589 const std::string msg5(
3590 EqFailure(
"foo",
"bar",
3591 std::string(
"\"x\""), std::string(
"\"y\""),
3592 true).failure_message());
3594 "Expected equality of these values:\n"
3596 " Which is: \"x\"\n"
3598 " Which is: \"y\"\n"
3603TEST(AssertionTest, EqFailureWithDiff) {
3604 const std::string left(
3605 "1\\n2XXX\\n3\\n5\\n6\\n7\\n8\\n9\\n10\\n11\\n12XXX\\n13\\n14\\n15");
3606 const std::string right(
3607 "1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n11\\n12\\n13\\n14");
3608 const std::string msg1(
3609 EqFailure(
"left",
"right", left, right,
false).failure_message());
3611 "Expected equality of these values:\n"
3614 "1\\n2XXX\\n3\\n5\\n6\\n7\\n8\\n9\\n10\\n11\\n12XXX\\n13\\n14\\n15\n"
3616 " Which is: 1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n11\\n12\\n13\\n14\n"
3617 "With diff:\n@@ -1,5 +1,6 @@\n 1\n-2XXX\n+2\n 3\n+4\n 5\n 6\n"
3618 "@@ -7,8 +8,6 @@\n 8\n 9\n-10\n 11\n-12XXX\n+12\n 13\n 14\n-15\n",
3623TEST(AssertionTest, AppendUserMessage) {
3624 const std::string
foo(
"foo");
3628 AppendUserMessage(
foo, msg).c_str());
3632 AppendUserMessage(
foo, msg).c_str());
3637# pragma option push -w-ccc -w-rch
3648TEST(AssertionTest, AssertTrueWithAssertionResult) {
3653 "Value of: ResultIsEven(3)\n"
3654 " Actual: false (3 is odd)\n"
3659 "Value of: ResultIsEvenNoExplanation(3)\n"
3660 " Actual: false (3 is odd)\n"
3674TEST(AssertionTest, AssertFalseWithAssertionResult) {
3679 "Value of: ResultIsEven(2)\n"
3680 " Actual: true (2 is even)\n"
3685 "Value of: ResultIsEvenNoExplanation(2)\n"
3698TEST(ExpectTest, ASSERT_EQ_Double) {
3711 "Expected equality of these values:\n"
3718#if GTEST_CAN_COMPARE_NULL
3719TEST(AssertionTest, ASSERT_EQ_NULL) {
3721 const char*
p = NULL;
3739TEST(ExpectTest, ASSERT_EQ_0) {
3754 "Expected: ('a') != ('a'), "
3755 "actual: 'a' (97, 0x61) vs 'a' (97, 0x61)");
3763 "Expected: (2) <= (0), actual: 2 vs 0");
3770 "Expected: (2) < (2), actual: 2 vs 2");
3778 "Expected: (2) >= (3), actual: 2 vs 3");
3785 "Expected: (2) > (2), actual: 2 vs 2");
3788#if GTEST_HAS_EXCEPTIONS
3790void ThrowNothing() {}
3796# ifndef __BORLANDC__
3801 "Expected: ThrowAnInteger() throws an exception of type bool.\n"
3802 " Actual: it throws a different type.");
3807 "Expected: ThrowNothing() throws an exception of type bool.\n"
3808 " Actual: it throws nothing.");
3815 "Expected: ThrowAnInteger() doesn't throw an exception."
3816 "\n Actual: it throws.");
3824 "Expected: ThrowNothing() throws an exception.\n"
3825 " Actual: it doesn't.");
3832TEST(AssertionTest, AssertPrecedence) {
3834 bool false_value =
false;
3844TEST(AssertionTest, NonFixtureSubroutine) {
3846 " x\n Which is: 2");
3852 explicit Uncopyable(
int a_value) : value_(a_value) {}
3854 int value()
const {
return value_; }
3855 bool operator==(
const Uncopyable& rhs)
const {
3856 return value() == rhs.value();
3861 Uncopyable(
const Uncopyable&);
3871bool IsPositiveUncopyable(
const Uncopyable& x) {
3872 return x.value() > 0;
3876void TestAssertNonPositive() {
3881void TestAssertEqualsUncopyable() {
3888TEST(AssertionTest, AssertWorksWithUncopyableObject) {
3893 "IsPositiveUncopyable(y) evaluates to false, where\ny evaluates to -1");
3895 "Expected equality of these values:\n"
3896 " x\n Which is: 5\n y\n Which is: -1");
3900TEST(AssertionTest, ExpectWorksWithUncopyableObject) {
3905 "IsPositiveUncopyable(y) evaluates to false, where\ny evaluates to -1");
3908 "Expected equality of these values:\n"
3909 " x\n Which is: 5\n y\n Which is: -1");
3917TEST(AssertionTest, NamedEnum) {
3928#if !GTEST_OS_MAC && !defined(__SUNPRO_CC) && !defined(__HP_aCC)
3959 EXPECT_EQ(
static_cast<int>(kCaseA),
static_cast<int>(kCaseB));
3970 "(kCaseA) >= (kCaseB)");
3981# ifndef __BORLANDC__
3985 " kCaseB\n Which is: ");
3998static HRESULT UnexpectedHRESULTFailure() {
3999 return E_UNEXPECTED;
4002static HRESULT OkHRESULTSuccess() {
4006static HRESULT FalseHRESULTSuccess() {
4014TEST(HRESULTAssertionTest, EXPECT_HRESULT_SUCCEEDED) {
4015 EXPECT_HRESULT_SUCCEEDED(S_OK);
4016 EXPECT_HRESULT_SUCCEEDED(S_FALSE);
4019 "Expected: (UnexpectedHRESULTFailure()) succeeds.\n"
4020 " Actual: 0x8000FFFF");
4023TEST(HRESULTAssertionTest, ASSERT_HRESULT_SUCCEEDED) {
4024 ASSERT_HRESULT_SUCCEEDED(S_OK);
4025 ASSERT_HRESULT_SUCCEEDED(S_FALSE);
4028 "Expected: (UnexpectedHRESULTFailure()) succeeds.\n"
4029 " Actual: 0x8000FFFF");
4032TEST(HRESULTAssertionTest, EXPECT_HRESULT_FAILED) {
4033 EXPECT_HRESULT_FAILED(E_UNEXPECTED);
4036 "Expected: (OkHRESULTSuccess()) fails.\n"
4039 "Expected: (FalseHRESULTSuccess()) fails.\n"
4043TEST(HRESULTAssertionTest, ASSERT_HRESULT_FAILED) {
4044 ASSERT_HRESULT_FAILED(E_UNEXPECTED);
4046# ifndef __BORLANDC__
4050 "Expected: (OkHRESULTSuccess()) fails.\n"
4055 "Expected: (FalseHRESULTSuccess()) fails.\n"
4060TEST(HRESULTAssertionTest, Streaming) {
4061 EXPECT_HRESULT_SUCCEEDED(S_OK) <<
"unexpected failure";
4062 ASSERT_HRESULT_SUCCEEDED(S_OK) <<
"unexpected failure";
4063 EXPECT_HRESULT_FAILED(E_UNEXPECTED) <<
"unexpected failure";
4064 ASSERT_HRESULT_FAILED(E_UNEXPECTED) <<
"unexpected failure";
4067 EXPECT_HRESULT_SUCCEEDED(E_UNEXPECTED) <<
"expected failure",
4068 "expected failure");
4070# ifndef __BORLANDC__
4074 ASSERT_HRESULT_SUCCEEDED(E_UNEXPECTED) <<
"expected failure",
4075 "expected failure");
4079 EXPECT_HRESULT_FAILED(S_OK) <<
"expected failure",
4080 "expected failure");
4083 ASSERT_HRESULT_FAILED(S_OK) <<
"expected failure",
4084 "expected failure");
4091# pragma option push -w-ccc -w-rch
4095TEST(AssertionSyntaxTest, BasicAssertionsBehavesLikeSingleStatement) {
4097 ASSERT_TRUE(
false) <<
"This should never be executed; "
4098 "It's a compilation test only.";
4114#if GTEST_HAS_EXCEPTIONS
4117TEST(ExpectThrowTest, DoesNotGenerateUnreachableCodeWarning) {
4129TEST(AssertionSyntaxTest, ExceptionAssertionsBehavesLikeSingleStatement) {
4156TEST(AssertionSyntaxTest, NoFatalFailureAssertionsBehavesLikeSingleStatement) {
4159 <<
"It's a compilation test only.";
4180TEST(AssertionSyntaxTest, WorksWithSwitch) {
4190 EXPECT_FALSE(
false) <<
"EXPECT_FALSE failed in switch case";
4197 ASSERT_EQ(1, 1) <<
"ASSERT_EQ failed in default switch handler";
4205#if GTEST_HAS_EXCEPTIONS
4207void ThrowAString() {
4208 throw "std::string";
4213TEST(AssertionSyntaxTest, WorksWithConst) {
4229 EXPECT_EQ(2, GetUnitTestImpl()->current_test_result()->total_part_count());
4235 EXPECT_EQ(0, GetUnitTestImpl()->current_test_result()->total_part_count());
4239TEST(SuccessfulAssertionTest, EXPECT_STR) {
4241 EXPECT_EQ(0, GetUnitTestImpl()->current_test_result()->total_part_count());
4245TEST(SuccessfulAssertionTest, ASSERT) {
4247 EXPECT_EQ(0, GetUnitTestImpl()->current_test_result()->total_part_count());
4251TEST(SuccessfulAssertionTest, ASSERT_STR) {
4253 EXPECT_EQ(0, GetUnitTestImpl()->current_test_result()->total_part_count());
4263 EXPECT_EQ(1, 1) <<
"This should succeed.";
4265 "Expected failure #1");
4266 EXPECT_LE(1, 2) <<
"This should succeed.";
4268 "Expected failure #2.");
4269 EXPECT_GE(1, 0) <<
"This should succeed.";
4271 "Expected failure #3.");
4275 "Expected failure #4.");
4278 "Expected failure #5.");
4282 "Expected failure #6.");
4283 EXPECT_NEAR(1, 1.1, 0.2) <<
"This should succeed.";
4286TEST(AssertionWithMessageTest, ASSERT) {
4287 ASSERT_EQ(1, 1) <<
"This should succeed.";
4288 ASSERT_NE(1, 2) <<
"This should succeed.";
4289 ASSERT_LE(1, 2) <<
"This should succeed.";
4290 ASSERT_LT(1, 2) <<
"This should succeed.";
4291 ASSERT_GE(1, 0) <<
"This should succeed.";
4293 "Expected failure.");
4296TEST(AssertionWithMessageTest, ASSERT_STR) {
4301 "Expected failure.");
4304TEST(AssertionWithMessageTest, ASSERT_FLOATING) {
4317 ASSERT_FALSE(
true) <<
"Expected failure: " << 2 <<
" > " << 1
4318 <<
" evaluates to " <<
true;
4319 },
"Expected failure");
4323TEST(AssertionWithMessageTest,
FAIL) {
4330 SUCCEED() <<
"Success == " << 1;
4338 ASSERT_TRUE(
false) <<
static_cast<const char *
>(NULL)
4339 <<
static_cast<char *
>(NULL);
4345TEST(AssertionWithMessageTest, WideStringMessage) {
4347 EXPECT_TRUE(
false) << L
"This failure is expected.\x8119";
4348 },
"This failure is expected.");
4351 << L
"expected too.\x8120";
4352 },
"This failure is expected too.");
4360 "Intentional failure #1.");
4362 "Intentional failure #2.");
4373TEST(ExpectTest, ExpectTrueWithAssertionResult) {
4376 "Value of: ResultIsEven(3)\n"
4377 " Actual: false (3 is odd)\n"
4381 "Value of: ResultIsEvenNoExplanation(3)\n"
4382 " Actual: false (3 is odd)\n"
4391 "Intentional failure #1.");
4393 "Intentional failure #2.");
4403TEST(ExpectTest, ExpectFalseWithAssertionResult) {
4406 "Value of: ResultIsEven(2)\n"
4407 " Actual: true (2 is even)\n"
4411 "Value of: ResultIsEvenNoExplanation(2)\n"
4425 "Expected equality of these values:\n"
4436TEST(ExpectTest, EXPECT_EQ_Double) {
4445#if GTEST_CAN_COMPARE_NULL
4447TEST(ExpectTest, EXPECT_EQ_NULL) {
4449 const char*
p = NULL;
4467TEST(ExpectTest, EXPECT_EQ_0) {
4483 "Expected: ('a') != ('a'), "
4484 "actual: 'a' (97, 0x61) vs 'a' (97, 0x61)");
4487 char*
const p0 = NULL;
4494 void* pv1 = (
void*)0x1234;
4495 char*
const p1 =
reinterpret_cast<char*
>(pv1);
4505 "Expected: (2) <= (0), actual: 2 vs 0");
4514 "Expected: (2) < (2), actual: 2 vs 2");
4524 "Expected: (2) >= (3), actual: 2 vs 3");
4533 "Expected: (2) > (2), actual: 2 vs 2");
4538#if GTEST_HAS_EXCEPTIONS
4544 "Expected: ThrowAnInteger() throws an exception of "
4545 "type bool.\n Actual: it throws a different type.");
4548 "Expected: ThrowNothing() throws an exception of type bool.\n"
4549 " Actual: it throws nothing.");
4556 "Expected: ThrowAnInteger() doesn't throw an "
4557 "exception.\n Actual: it throws.");
4565 "Expected: ThrowNothing() throws an exception.\n"
4566 " Actual: it doesn't.");
4572TEST(ExpectTest, ExpectPrecedence) {
4575 " true && false\n Which is: false");
4582TEST(StreamableToStringTest, Scalar) {
4594TEST(StreamableToStringTest, NullPointer) {
4600TEST(StreamableToStringTest, CString) {
4601 EXPECT_STREQ(
"Foo", StreamableToString(
"Foo").c_str());
4605TEST(StreamableToStringTest, NullCString) {
4613TEST(StreamableTest,
string) {
4614 static const std::string
str(
4615 "This failure message is a std::string, and is expected.");
4622TEST(StreamableTest, stringWithEmbeddedNUL) {
4623 static const char char_array_with_nul[] =
4624 "Here's a NUL\0 and some more string";
4625 static const std::string string_with_nul(char_array_with_nul,
4626 sizeof(char_array_with_nul)
4629 "Here's a NUL\\0 and some more string");
4633TEST(StreamableTest, NULChar) {
4635 FAIL() <<
"A NUL" <<
'\0' <<
" and some more string";
4636 },
"A NUL\\0 and some more string");
4640TEST(StreamableTest,
int) {
4650TEST(StreamableTest, NullCharPtr) {
4657TEST(StreamableTest, BasicIoManip) {
4659 FAIL() <<
"Line 1." << std::endl
4660 <<
"A NUL char " << std::ends << std::flush <<
" in line 2.";
4661 },
"Line 1.\nA NUL char \\0 in line 2.");
4666void AddFailureHelper(
bool* aborted) {
4676 "Intentional failure.");
4700 "Intentional failure.");
4706 SUCCEED() <<
"Explicit success.";
4720 bool false_value =
false;
4722 },
" false_value\n Which is: false\n true");
4726TEST(EqAssertionTest, Int) {
4733TEST(EqAssertionTest, Time_T) {
4735 static_cast<time_t
>(0));
4737 static_cast<time_t
>(1234)),
4742TEST(EqAssertionTest, Char) {
4744 const char ch =
'b';
4746 " ch\n Which is: 'b'");
4748 " ch\n Which is: 'b'");
4752TEST(EqAssertionTest, WideChar) {
4756 "Expected equality of these values:\n"
4758 " Which is: L'\0' (0, 0x0)\n"
4760 " Which is: L'x' (120, 0x78)");
4762 static wchar_t wchar;
4768 " wchar\n Which is: L'");
4772TEST(EqAssertionTest, StdString) {
4775 ASSERT_EQ(
"Test", ::std::string(
"Test"));
4778 static const ::std::string str1(
"A * in the middle");
4779 static const ::std::string str2(str1);
4788 char*
const p1 =
const_cast<char*
>(
"foo");
4794 static ::std::string str3(str1);
4797 " str3\n Which is: \"A \\0 in the middle\"");
4800#if GTEST_HAS_STD_WSTRING
4803TEST(EqAssertionTest, StdWideString) {
4805 const ::std::wstring wstr1(L
"A * in the middle");
4806 const ::std::wstring wstr2(wstr1);
4811 const wchar_t kTestX8119[] = {
'T',
'e',
's',
't', 0x8119,
'\0' };
4812 EXPECT_EQ(::std::wstring(kTestX8119), kTestX8119);
4816 const wchar_t kTestX8120[] = {
'T',
'e',
's',
't', 0x8120,
'\0' };
4818 EXPECT_EQ(::std::wstring(kTestX8119), kTestX8120);
4823 ::std::wstring wstr3(wstr1);
4824 wstr3.at(2) = L
'\0';
4831 ASSERT_EQ(
const_cast<wchar_t*
>(L
"foo"), ::std::wstring(L
"bar"));
4837#if GTEST_HAS_GLOBAL_STRING
4839TEST(EqAssertionTest, GlobalString) {
4844 const ::string str1(
"A * in the middle");
4845 const ::string str2(str1);
4854 ::string str3(str1);
4861 ASSERT_EQ(::string(
"bar"),
const_cast<char*
>(
"foo"));
4867#if GTEST_HAS_GLOBAL_WSTRING
4870TEST(EqAssertionTest, GlobalWideString) {
4872 static const ::wstring wstr1(L
"A * in the middle");
4873 static const ::wstring wstr2(wstr1);
4877 const wchar_t kTestX8119[] = {
'T',
'e',
's',
't', 0x8119,
'\0' };
4878 ASSERT_EQ(kTestX8119, ::wstring(kTestX8119));
4882 const wchar_t kTestX8120[] = {
'T',
'e',
's',
't', 0x8120,
'\0' };
4884 EXPECT_EQ(kTestX8120, ::wstring(kTestX8119));
4888 wchar_t*
const p1 =
const_cast<wchar_t*
>(L
"foo");
4894 static ::wstring wstr3;
4896 wstr3.at(2) = L
'\0';
4904TEST(EqAssertionTest, CharPointer) {
4905 char*
const p0 = NULL;
4910 void* pv1 = (
void*)0x1234;
4911 void* pv2 = (
void*)0xABC0;
4912 char*
const p1 =
reinterpret_cast<char*
>(pv1);
4913 char*
const p2 =
reinterpret_cast<char*
>(pv2);
4921 reinterpret_cast<char*
>(0xABC0)),
4926TEST(EqAssertionTest, WideCharPointer) {
4927 wchar_t*
const p0 = NULL;
4932 void* pv1 = (
void*)0x1234;
4933 void* pv2 = (
void*)0xABC0;
4934 wchar_t*
const p1 =
reinterpret_cast<wchar_t*
>(pv1);
4935 wchar_t*
const p2 =
reinterpret_cast<wchar_t*
>(pv2);
4942 void* pv3 = (
void*)0x1234;
4943 void* pv4 = (
void*)0xABC0;
4944 const wchar_t* p3 =
reinterpret_cast<const wchar_t*
>(pv3);
4945 const wchar_t* p4 =
reinterpret_cast<const wchar_t*
>(pv4);
4951TEST(EqAssertionTest, OtherPointer) {
4952 ASSERT_EQ(
static_cast<const int*
>(NULL),
4953 static_cast<const int*
>(NULL));
4955 reinterpret_cast<const int*
>(0x1234)),
4960class UnprintableChar {
4962 explicit UnprintableChar(
char ch) : char_(
ch) {}
4964 bool operator==(
const UnprintableChar& rhs)
const {
4965 return char_ == rhs.char_;
4967 bool operator!=(
const UnprintableChar& rhs)
const {
4968 return char_ != rhs.char_;
4970 bool operator<(
const UnprintableChar& rhs)
const {
4971 return char_ < rhs.char_;
4973 bool operator<=(
const UnprintableChar& rhs)
const {
4974 return char_ <= rhs.char_;
4976 bool operator>(
const UnprintableChar& rhs)
const {
4977 return char_ > rhs.char_;
4979 bool operator>=(
const UnprintableChar& rhs)
const {
4980 return char_ >= rhs.char_;
4989TEST(ComparisonAssertionTest, AcceptsUnprintableArgs) {
4990 const UnprintableChar x(
'x'),
y(
'y');
5009 "1-byte object <78>");
5011 "1-byte object <78>");
5014 "1-byte object <79>");
5016 "1-byte object <78>");
5018 "1-byte object <79>");
5030 int Bar()
const {
return 1; }
5045class FRIEND_TEST_Test2 :
public Test {
5062class TestLifeCycleTest :
public Test {
5066 TestLifeCycleTest() { count_++; }
5070 ~TestLifeCycleTest() { count_--; }
5073 int count()
const {
return count_; }
5079int TestLifeCycleTest::count_ = 0;
5082TEST_F(TestLifeCycleTest, Test1) {
5089TEST_F(TestLifeCycleTest, Test2) {
5100TEST(AssertionResultTest, CopyConstructorWorksWhenNotOptimied) {
5110 EXPECT_EQ(
static_cast<bool>(r3),
static_cast<bool>(r1));
5116TEST(AssertionResultTest, ConstructionWorks) {
5139TEST(AssertionResultTest, NegationWorks) {
5149TEST(AssertionResultTest, StreamingWorks) {
5151 r <<
"abc" <<
'd' << 0 <<
true;
5155TEST(AssertionResultTest, CanStreamOstreamManipulators) {
5157 r <<
"Data" << std::endl << std::flush << std::ends <<
"Will be visible";
5164TEST(AssertionResultTest, ConstructibleFromContextuallyConvertibleToBool) {
5165 struct ExplicitlyConvertibleToBool {
5166 explicit operator bool()
const {
return value; }
5169 ExplicitlyConvertibleToBool v1 = {
false};
5170 ExplicitlyConvertibleToBool v2 = {
true};
5181TEST(AssertionResultTest, ConstructibleFromImplicitlyConvertible) {
5190 explicit Base(
int an_x) : x_(an_x) {}
5191 int x()
const {
return x_; }
5197 return os << val.x();
5201 return os <<
"(" <<
pointer->x() <<
")";
5204TEST(MessageTest, CanStreamUserTypeInGlobalNameSpace) {
5215class MyTypeInUnnamedNameSpace :
public Base {
5217 explicit MyTypeInUnnamedNameSpace(
int an_x): Base(an_x) {}
5220 const MyTypeInUnnamedNameSpace& val) {
5221 return os << val.x();
5224 const MyTypeInUnnamedNameSpace*
pointer) {
5225 return os <<
"(" <<
pointer->x() <<
")";
5229TEST(MessageTest, CanStreamUserTypeInUnnamedNameSpace) {
5231 MyTypeInUnnamedNameSpace
a(1);
5246 return os << val.x();
5250 return os <<
"(" <<
pointer->x() <<
")";
5254TEST(MessageTest, CanStreamUserTypeInUserNameSpace) {
5272 return os << val.x();
5276 return os <<
"(" <<
pointer->x() <<
")";
5279TEST(MessageTest, CanStreamUserTypeInUserNameSpaceWithStreamOperatorInGlobal) {
5290 char*
const p1 = NULL;
5291 unsigned char*
const p2 = NULL;
5297 msg << p1 << p2 << p3 << p4 << p5 << p6;
5305 const wchar_t* const_wstr = NULL;
5307 (
Message() << const_wstr).GetString().c_str());
5310 wchar_t* wstr = NULL;
5312 (
Message() << wstr).GetString().c_str());
5315 const_wstr = L
"abc\x8119";
5317 (
Message() << const_wstr).GetString().c_str());
5320 wstr =
const_cast<wchar_t*
>(const_wstr);
5322 (
Message() << wstr).GetString().c_str());
5334 const TestCase*
const test_case = GetUnitTestImpl()->
5335 GetTestCase(
"TestInfoTest",
"", NULL, NULL);
5339 if (strcmp(test_name, test_info->
name()) == 0)
5347 return test_info->
result();
5353 const TestInfo*
const test_info = GetTestInfo(
"Names");
5361 const TestInfo*
const test_info = GetTestInfo(
"result");
5364 ASSERT_EQ(0, GetTestResult(test_info)->total_part_count());
5367 ASSERT_EQ(0, GetTestResult(test_info)->total_part_count());
5370#define VERIFY_CODE_LOCATION \
5371 const int expected_line = __LINE__ - 1; \
5372 const TestInfo* const test_info = GetUnitTestImpl()->current_test_info(); \
5373 ASSERT_TRUE(test_info); \
5374 EXPECT_STREQ(__FILE__, test_info->file()); \
5375 EXPECT_EQ(expected_line, test_info->line())
5397template <
typename T>
5407template <
typename T>
5421#undef VERIFY_CODE_LOCATION
5430 printf(
"Setting up the test case . . .\n");
5447 printf(
"Tearing down the test case . . .\n");
5492 Flags() : also_run_disabled_tests(false),
5493 break_on_failure(false),
5494 catch_exceptions(false),
5495 death_test_use_fork(false),
5503 stack_trace_depth(kMaxStackTraceDepth),
5504 stream_result_to(
""),
5505 throw_on_failure(false) {}
5660 template <
typename CharType>
5662 size_t size2, CharType** array2) {
5663 ASSERT_EQ(size1, size2) <<
" Array sizes different.";
5665 for (
size_t i = 0; i != size1; i++) {
5666 ASSERT_STREQ(array1[i], array2[i]) <<
" where i == " << i;
5673 GTEST_FLAG(also_run_disabled_tests));
5686 GTEST_FLAG(stream_result_to).c_str());
5693 template <
typename CharType>
5695 int argc2,
const CharType** argv2,
5696 const Flags& expected,
bool should_print_help) {
5700# if GTEST_HAS_STREAM_REDIRECTION
5707# if GTEST_HAS_STREAM_REDIRECTION
5708 const std::string captured_stdout = GetCapturedStdout();
5722# if GTEST_HAS_STREAM_REDIRECTION
5723 const char*
const expected_help_fragment =
5724 "This program contains tests written using";
5725 if (should_print_help) {
5729 expected_help_fragment, captured_stdout);
5739# define GTEST_TEST_PARSING_FLAGS_(argv1, argv2, expected, should_print_help) \
5740 TestParsingFlags(sizeof(argv1)/sizeof(*argv1) - 1, argv1, \
5741 sizeof(argv2)/sizeof(*argv2) - 1, argv2, \
5742 expected, should_print_help)
5747 const char*
argv[] = {
5751 const char* argv2[] = {
5760 const char*
argv[] = {
5765 const char* argv2[] = {
5775 const char*
argv[] = {
5781 const char* argv2[] = {
5792 const char*
argv[] = {
5798 const char* argv2[] = {
5808 const char*
argv[] = {
5810 "--gtest_filter=abc",
5814 const char* argv2[] = {
5824 const char*
argv[] = {
5826 "--gtest_break_on_failure",
5830 const char* argv2[] = {
5840 const char*
argv[] = {
5842 "--gtest_break_on_failure=0",
5846 const char* argv2[] = {
5856 const char*
argv[] = {
5858 "--gtest_break_on_failure=f",
5862 const char* argv2[] = {
5872 const char*
argv[] = {
5874 "--gtest_break_on_failure=F",
5878 const char* argv2[] = {
5889 const char*
argv[] = {
5891 "--gtest_break_on_failure=1",
5895 const char* argv2[] = {
5905 const char*
argv[] = {
5907 "--gtest_catch_exceptions",
5911 const char* argv2[] = {
5921 const char*
argv[] = {
5923 "--gtest_death_test_use_fork",
5927 const char* argv2[] = {
5938 const char*
argv[] = {
5945 const char* argv2[] = {
5955 const char*
argv[] = {
5957 "--gtest_break_on_failure",
5963 const char* argv2[] = {
5977 const char*
argv[] = {
5979 "--gtest_list_tests",
5983 const char* argv2[] = {
5993 const char*
argv[] = {
5995 "--gtest_list_tests=1",
5999 const char* argv2[] = {
6009 const char*
argv[] = {
6011 "--gtest_list_tests=0",
6015 const char* argv2[] = {
6025 const char*
argv[] = {
6027 "--gtest_list_tests=f",
6031 const char* argv2[] = {
6041 const char*
argv[] = {
6043 "--gtest_list_tests=F",
6047 const char* argv2[] = {
6057 const char*
argv[] = {
6063 const char* argv2[] = {
6074 const char*
argv[] = {
6076 "--gtest_output=xml",
6080 const char* argv2[] = {
6090 const char*
argv[] = {
6092 "--gtest_output=xml:file",
6096 const char* argv2[] = {
6106 const char*
argv[] = {
6108 "--gtest_output=xml:directory/path/",
6112 const char* argv2[] = {
6123 const char*
argv[] = {
6125 "--gtest_print_time",
6129 const char* argv2[] = {
6139 const char*
argv[] = {
6141 "--gtest_print_time=1",
6145 const char* argv2[] = {
6155 const char*
argv[] = {
6157 "--gtest_print_time=0",
6161 const char* argv2[] = {
6171 const char*
argv[] = {
6173 "--gtest_print_time=f",
6177 const char* argv2[] = {
6187 const char*
argv[] = {
6189 "--gtest_print_time=F",
6193 const char* argv2[] = {
6203 const char*
argv[] = {
6205 "--gtest_random_seed=1000",
6209 const char* argv2[] = {
6219 const char*
argv[] = {
6221 "--gtest_repeat=1000",
6225 const char* argv2[] = {
6235 const char*
argv[] = {
6237 "--gtest_also_run_disabled_tests",
6241 const char* argv2[] = {
6252 const char*
argv[] = {
6254 "--gtest_also_run_disabled_tests=1",
6258 const char* argv2[] = {
6269 const char*
argv[] = {
6271 "--gtest_also_run_disabled_tests=0",
6275 const char* argv2[] = {
6286 const char*
argv[] = {
6292 const char* argv2[] = {
6302 const char*
argv[] = {
6304 "--gtest_shuffle=0",
6308 const char* argv2[] = {
6318 const char*
argv[] = {
6320 "--gtest_shuffle=1",
6324 const char* argv2[] = {
6334 const char*
argv[] = {
6336 "--gtest_stack_trace_depth=5",
6340 const char* argv2[] = {
6349 const char*
argv[] = {
6351 "--gtest_stream_result_to=localhost:1234",
6355 const char* argv2[] = {
6366 const char*
argv[] = {
6368 "--gtest_throw_on_failure",
6372 const char* argv2[] = {
6382 const char*
argv[] = {
6384 "--gtest_throw_on_failure=0",
6388 const char* argv2[] = {
6399 const char*
argv[] = {
6401 "--gtest_throw_on_failure=1",
6405 const char* argv2[] = {
6413# if GTEST_OS_WINDOWS
6415TEST_F(ParseFlagsTest, WideStrings) {
6416 const wchar_t*
argv[] = {
6418 L
"--gtest_filter=Foo*",
6419 L
"--gtest_list_tests=1",
6420 L
"--gtest_break_on_failure",
6421 L
"--non_gtest_flag",
6425 const wchar_t* argv2[] = {
6427 L
"--non_gtest_flag",
6431 Flags expected_flags;
6432 expected_flags.break_on_failure =
true;
6433 expected_flags.filter =
"Foo*";
6434 expected_flags.list_tests =
true;
6440#if GTEST_USE_OWN_FLAGFILE_FLAG_
6441class FlagfileTest :
public ParseFlagsTest {
6443 virtual void SetUp() {
6444 ParseFlagsTest::SetUp();
6453 virtual void TearDown() {
6455 ParseFlagsTest::TearDown();
6458 internal::FilePath CreateFlagfile(
const char* contents) {
6459 internal::FilePath file_path(internal::FilePath::GenerateUniqueFileName(
6462 fprintf(
f,
"%s", contents);
6472TEST_F(FlagfileTest, Empty) {
6473 internal::FilePath flagfile_path(CreateFlagfile(
""));
6474 std::string flagfile_flag =
6477 const char*
argv[] = {
6479 flagfile_flag.c_str(),
6483 const char* argv2[] = {
6492TEST_F(FlagfileTest, FilterNonEmpty) {
6493 internal::FilePath flagfile_path(CreateFlagfile(
6495 std::string flagfile_flag =
6498 const char*
argv[] = {
6500 flagfile_flag.c_str(),
6504 const char* argv2[] = {
6513TEST_F(FlagfileTest, SeveralFlags) {
6514 internal::FilePath flagfile_path(CreateFlagfile(
6518 std::string flagfile_flag =
6521 const char*
argv[] = {
6523 flagfile_flag.c_str(),
6527 const char* argv2[] = {
6532 Flags expected_flags;
6533 expected_flags.break_on_failure =
true;
6534 expected_flags.filter =
"abc";
6535 expected_flags.list_tests =
true;
6551 <<
"There should be no tests running at this point.";
6560 <<
"There should be no tests running at this point.";
6570 <<
"There is a test running so we should have a valid TestInfo.";
6572 <<
"Expected the name of the currently running test case.";
6574 <<
"Expected the name of the currently running test.";
6585 <<
"There is a test running so we should have a valid TestInfo.";
6587 <<
"Expected the name of the currently running test case.";
6589 <<
"Expected the name of the currently running test.";
6614TEST(NestedTestingNamespaceTest, Success) {
6615 EXPECT_EQ(1, 1) <<
"This shouldn't fail.";
6619TEST(NestedTestingNamespaceTest, Failure) {
6621 "This failure is expected.");
6643TEST(StreamingAssertionsTest, Unconditional) {
6644 SUCCEED() <<
"expected success";
6646 "expected failure");
6648 "expected failure");
6653# pragma option push -w-ccc -w-rch
6656TEST(StreamingAssertionsTest, Truth) {
6660 "expected failure");
6662 "expected failure");
6665TEST(StreamingAssertionsTest, Truth2) {
6669 "expected failure");
6671 "expected failure");
6679TEST(StreamingAssertionsTest, IntegerEquals) {
6680 EXPECT_EQ(1, 1) <<
"unexpected failure";
6681 ASSERT_EQ(1, 1) <<
"unexpected failure";
6683 "expected failure");
6685 "expected failure");
6688TEST(StreamingAssertionsTest, IntegerLessThan) {
6689 EXPECT_LT(1, 2) <<
"unexpected failure";
6690 ASSERT_LT(1, 2) <<
"unexpected failure";
6692 "expected failure");
6694 "expected failure");
6697TEST(StreamingAssertionsTest, StringsEqual) {
6701 "expected failure");
6703 "expected failure");
6706TEST(StreamingAssertionsTest, StringsNotEqual) {
6710 "expected failure");
6712 "expected failure");
6715TEST(StreamingAssertionsTest, StringsEqualIgnoringCase) {
6719 "expected failure");
6721 "expected failure");
6724TEST(StreamingAssertionsTest, StringNotEqualIgnoringCase) {
6728 "expected failure");
6730 "expected failure");
6733TEST(StreamingAssertionsTest, FloatingPointEquals) {
6737 "expected failure");
6739 "expected failure");
6742#if GTEST_HAS_EXCEPTIONS
6744TEST(StreamingAssertionsTest, Throw) {
6745 EXPECT_THROW(ThrowAnInteger(),
int) <<
"unexpected failure";
6746 ASSERT_THROW(ThrowAnInteger(),
int) <<
"unexpected failure";
6748 "expected failure",
"expected failure");
6750 "expected failure",
"expected failure");
6753TEST(StreamingAssertionsTest, NoThrow) {
6757 "expected failure",
"expected failure");
6759 "expected failure",
"expected failure");
6762TEST(StreamingAssertionsTest, AnyThrow) {
6766 "expected failure",
"expected failure");
6768 "expected failure",
"expected failure");
6775TEST(ColoredOutputTest, UsesColorsWhenGTestColorFlagIsYes) {
6778 SetEnv(
"TERM",
"xterm");
6782 SetEnv(
"TERM",
"dumb");
6787TEST(ColoredOutputTest, UsesColorsWhenGTestColorFlagIsAliasOfYes) {
6788 SetEnv(
"TERM",
"dumb");
6800TEST(ColoredOutputTest, UsesNoColorWhenGTestColorFlagIsNo) {
6803 SetEnv(
"TERM",
"xterm");
6807 SetEnv(
"TERM",
"dumb");
6812TEST(ColoredOutputTest, UsesNoColorWhenGTestColorFlagIsInvalid) {
6813 SetEnv(
"TERM",
"xterm");
6825TEST(ColoredOutputTest, UsesColorsWhenStdoutIsTty) {
6828 SetEnv(
"TERM",
"xterm");
6833TEST(ColoredOutputTest, UsesColorsWhenTermSupportsColors) {
6839 SetEnv(
"TERM",
"dumb");
6845 SetEnv(
"TERM",
"xterm");
6851 SetEnv(
"TERM",
"dumb");
6854 SetEnv(
"TERM",
"emacs");
6857 SetEnv(
"TERM",
"vt100");
6860 SetEnv(
"TERM",
"xterm-mono");
6863 SetEnv(
"TERM",
"xterm");
6866 SetEnv(
"TERM",
"xterm-color");
6869 SetEnv(
"TERM",
"xterm-256color");
6872 SetEnv(
"TERM",
"screen");
6875 SetEnv(
"TERM",
"screen-256color");
6878 SetEnv(
"TERM",
"tmux");
6881 SetEnv(
"TERM",
"tmux-256color");
6884 SetEnv(
"TERM",
"rxvt-unicode");
6887 SetEnv(
"TERM",
"rxvt-unicode-256color");
6890 SetEnv(
"TERM",
"linux");
6893 SetEnv(
"TERM",
"cygwin");
6902 StaticAssertTypeEq<const int, const int>();
6906template <
typename T>
6912TEST(StaticAssertTypeEqTest, WorksInClass) {
6920TEST(StaticAssertTypeEqTest, CompilesForEqualTypes) {
6921 StaticAssertTypeEq<int, IntAlias>();
6922 StaticAssertTypeEq<int*, IntAlias*>();
6925TEST(HasNonfatalFailureTest, ReturnsFalseWhenThereIsNoFailure) {
6929static void FailFatally() {
FAIL(); }
6931TEST(HasNonfatalFailureTest, ReturnsFalseWhenThereIsOnlyFatalFailure) {
6933 const bool has_nonfatal_failure = HasNonfatalFailure();
6934 ClearCurrentTestPartResults();
6938TEST(HasNonfatalFailureTest, ReturnsTrueWhenThereIsNonfatalFailure) {
6940 const bool has_nonfatal_failure = HasNonfatalFailure();
6941 ClearCurrentTestPartResults();
6945TEST(HasNonfatalFailureTest, ReturnsTrueWhenThereAreFatalAndNonfatalFailures) {
6948 const bool has_nonfatal_failure = HasNonfatalFailure();
6949 ClearCurrentTestPartResults();
6954static bool HasNonfatalFailureHelper() {
6958TEST(HasNonfatalFailureTest, WorksOutsideOfTestBody) {
6962TEST(HasNonfatalFailureTest, WorksOutsideOfTestBody2) {
6964 const bool has_nonfatal_failure = HasNonfatalFailureHelper();
6965 ClearCurrentTestPartResults();
6969TEST(HasFailureTest, ReturnsFalseWhenThereIsNoFailure) {
6973TEST(HasFailureTest, ReturnsTrueWhenThereIsFatalFailure) {
6975 const bool has_failure = HasFailure();
6976 ClearCurrentTestPartResults();
6980TEST(HasFailureTest, ReturnsTrueWhenThereIsNonfatalFailure) {
6982 const bool has_failure = HasFailure();
6983 ClearCurrentTestPartResults();
6987TEST(HasFailureTest, ReturnsTrueWhenThereAreFatalAndNonfatalFailures) {
6990 const bool has_failure = HasFailure();
6991 ClearCurrentTestPartResults();
6998TEST(HasFailureTest, WorksOutsideOfTestBody) {
7002TEST(HasFailureTest, WorksOutsideOfTestBody2) {
7004 const bool has_failure = HasFailureHelper();
7005 ClearCurrentTestPartResults();
7013 : on_start_counter_(on_start_counter),
7014 is_destroyed_(is_destroyed) {}
7018 *is_destroyed_ =
true;
7023 if (on_start_counter_ != NULL)
7024 (*on_start_counter_)++;
7028 int* on_start_counter_;
7029 bool* is_destroyed_;
7033TEST(TestEventListenersTest, ConstructionWorks) {
7043TEST(TestEventListenersTest, DestructionWorks) {
7044 bool default_result_printer_is_destroyed =
false;
7045 bool default_xml_printer_is_destroyed =
false;
7046 bool extra_listener_is_destroyed =
false;
7048 NULL, &default_result_printer_is_destroyed);
7050 NULL, &default_xml_printer_is_destroyed);
7052 NULL, &extra_listener_is_destroyed);
7057 default_result_printer);
7059 default_xml_printer);
7060 listeners.
Append(extra_listener);
7069TEST(TestEventListenersTest, Append) {
7070 int on_start_counter = 0;
7071 bool is_destroyed =
false;
7075 listeners.
Append(listener);
7089 : vector_(vector), id_(
id) {}
7093 vector_->push_back(GetEventDescription(
"OnTestProgramStart"));
7097 vector_->push_back(GetEventDescription(
"OnTestProgramEnd"));
7102 vector_->push_back(GetEventDescription(
"OnTestIterationStart"));
7107 vector_->push_back(GetEventDescription(
"OnTestIterationEnd"));
7111 std::string GetEventDescription(
const char* method) {
7113 message << id_ <<
"." << method;
7114 return message.GetString();
7117 std::vector<std::string>* vector_;
7118 const char*
const id_;
7123TEST(EventListenerTest, AppendKeepsOrder) {
7124 std::vector<std::string> vec;
7133 EXPECT_STREQ(
"1st.OnTestProgramStart", vec[0].c_str());
7134 EXPECT_STREQ(
"2nd.OnTestProgramStart", vec[1].c_str());
7135 EXPECT_STREQ(
"3rd.OnTestProgramStart", vec[2].c_str());
7149 EXPECT_STREQ(
"1st.OnTestIterationStart", vec[0].c_str());
7150 EXPECT_STREQ(
"2nd.OnTestIterationStart", vec[1].c_str());
7151 EXPECT_STREQ(
"3rd.OnTestIterationStart", vec[2].c_str());
7157 EXPECT_STREQ(
"3rd.OnTestIterationEnd", vec[0].c_str());
7158 EXPECT_STREQ(
"2nd.OnTestIterationEnd", vec[1].c_str());
7159 EXPECT_STREQ(
"1st.OnTestIterationEnd", vec[2].c_str());
7164TEST(TestEventListenersTest, Release) {
7165 int on_start_counter = 0;
7166 bool is_destroyed =
false;
7173 listeners.
Append(listener);
7185TEST(EventListenerTest, SuppressEventForwarding) {
7186 int on_start_counter = 0;
7190 listeners.
Append(listener);
7201TEST(EventListenerDeathTest, EventsNotForwardedInDeathTestSubprecesses) {
7204 *GetUnitTestImpl()->listeners())) <<
"expected failure";},
7205 "expected failure");
7211TEST(EventListenerTest, default_result_printer) {
7212 int on_start_counter = 0;
7213 bool is_destroyed =
false;
7242TEST(EventListenerTest, RemovingDefaultResultPrinterWorks) {
7243 int on_start_counter = 0;
7244 bool is_destroyed =
false;
7270TEST(EventListenerTest, default_xml_generator) {
7271 int on_start_counter = 0;
7272 bool is_destroyed =
false;
7301TEST(EventListenerTest, RemovingDefaultXmlGeneratorWorks) {
7302 int on_start_counter = 0;
7303 bool is_destroyed =
false;
7336 "An expected failure");
7342 "An expected failure");
7344 "An expected failure");
7349 "An expected failure");
7354 "An expected failure");
7358 "An expected failure");
7360 "An expected failure");
7365 "An expected failure");
7369 "An expected failure");
7371 "An expected failure");
7382TEST(IsAProtocolMessageTest, ValueIsCompileTimeConstant) {
7390TEST(IsAProtocolMessageTest, ValueIsTrueWhenTypeIsAProtocolMessage) {
7397TEST(IsAProtocolMessageTest, ValueIsFalseWhenTypeIsNotAProtocolMessage) {
7410TEST(RemoveReferenceTest, DoesNotAffectNonReferenceType) {
7416TEST(RemoveReferenceTest, RemovesReference) {
7423template <
typename T1,
typename T2>
7428TEST(RemoveReferenceTest, MacroVersion) {
7435TEST(RemoveConstTest, DoesNotAffectNonConstType) {
7441TEST(RemoveConstTest, RemovesConst) {
7449template <
typename T1,
typename T2>
7454TEST(RemoveConstTest, MacroVersion) {
7462template <
typename T1,
typename T2>
7467TEST(RemoveReferenceToConstTest, Works) {
7476TEST(AddReferenceTest, DoesNotAffectReferenceType) {
7482TEST(AddReferenceTest, AddsReference) {
7489template <
typename T1,
typename T2>
7494TEST(AddReferenceTest, MacroVersion) {
7501template <
typename T1,
typename T2>
7506TEST(GTestReferenceToConstTest, Works) {
7514TEST(ImplicitlyConvertibleTest, ValueIsCompileTimeConstant) {
7522TEST(ImplicitlyConvertibleTest, ValueIsTrueWhenConvertible) {
7535TEST(ImplicitlyConvertibleTest, ValueIsFalseWhenNotConvertible) {
7547TEST(IsContainerTestTest, WorksForNonContainer) {
7553TEST(IsContainerTestTest, WorksForContainer) {
7555 sizeof(IsContainerTest<std::vector<bool> >(0)));
7557 sizeof(IsContainerTest<std::map<int, double> >(0)));
7561struct ConstOnlyContainerWithPointerIterator {
7562 using const_iterator =
int*;
7563 const_iterator begin()
const;
7564 const_iterator end()
const;
7567struct ConstOnlyContainerWithClassIterator {
7568 struct const_iterator {
7570 const_iterator& operator++();
7572 const_iterator begin()
const;
7573 const_iterator end()
const;
7576TEST(IsContainerTestTest, ConstOnlyContainer) {
7578 sizeof(IsContainerTest<ConstOnlyContainerWithPointerIterator>(0)));
7580 sizeof(IsContainerTest<ConstOnlyContainerWithClassIterator>(0)));
7599#if GTEST_HAS_HASH_SET_
7606TEST(ArrayEqTest, WorksForDegeneratedArrays) {
7611TEST(ArrayEqTest, WorksForOneDimensionalArrays) {
7613 const int a[] = { 0, 1 };
7614 long b[] = { 0, 1 };
7623TEST(ArrayEqTest, WorksForTwoDimensionalArrays) {
7624 const char a[][3] = {
"hi",
"lo" };
7625 const char b[][3] = {
"hi",
"lo" };
7626 const char c[][3] = {
"hi",
"li" };
7637TEST(ArrayAwareFindTest, WorksForOneDimensionalArray) {
7638 const char a[] =
"hello";
7643TEST(ArrayAwareFindTest, WorksForTwoDimensionalArray) {
7644 int a[][2] = { { 0, 1 }, { 2, 3 }, { 4, 5 } };
7645 const int b[2] = { 2, 3 };
7648 const int c[2] = { 6, 7 };
7654TEST(CopyArrayTest, WorksForDegeneratedArrays) {
7660TEST(CopyArrayTest, WorksForOneDimensionalArrays) {
7661 const char a[3] =
"hi";
7673TEST(CopyArrayTest, WorksForTwoDimensionalArrays) {
7674 const int a[2][3] = { { 0, 1, 2 }, { 3, 4, 5 } };
7688TEST(NativeArrayTest, ConstructorFromArrayWorks) {
7689 const int a[3] = { 0, 1, 2 };
7695TEST(NativeArrayTest, CreatesAndDeletesCopyOfArrayWhenAskedTo) {
7696 typedef int Array[2];
7697 Array*
a =
new Array[1];
7710TEST(NativeArrayTest, TypeMembersAreCorrect) {
7711 StaticAssertTypeEq<char, NativeArray<char>::value_type>();
7712 StaticAssertTypeEq<int[2], NativeArray<int[2]>::value_type>();
7714 StaticAssertTypeEq<const char*, NativeArray<char>::const_iterator>();
7718TEST(NativeArrayTest, MethodsWork) {
7719 const int a[3] = { 0, 1, 2 };
7738 const int b1[3] = { 0, 1, 1 };
7739 const int b2[4] = { 0, 1, 2, 3 };
7744TEST(NativeArrayTest, WorksForTwoDimensionalArray) {
7745 const char a[2][3] = {
"hi",
"lo" };
7753TEST(SkipPrefixTest, SkipsWhenPrefixMatches) {
7754 const char*
const str =
"hello";
7756 const char*
p = str;
7765TEST(SkipPrefixTest, DoesNotSkipWhenPrefixDoesNotMatch) {
7766 const char*
const str =
"world";
7768 const char*
p = str;
7782 FAIL() <<
"A failure happened inside SetUpTestCase().";
const CBigNum operator*(const CBigNum &a, const CBigNum &b)
bool operator<(const CBigNum &a, const CBigNum &b)
bool operator<=(const CBigNum &a, const CBigNum &b)
bool operator>=(const CBigNum &a, const CBigNum &b)
bool operator>(const CBigNum &a, const CBigNum &b)
static void SetUpTestCase()
Represents a JSON Pointer. Use Pointer for UTF8 encoding and default allocator.
virtual void OnTestProgramStart(const UnitTest &)
virtual void OnTestIterationStart(const UnitTest &, int)
virtual void OnTestIterationEnd(const UnitTest &, int)
virtual void OnTestProgramEnd(const UnitTest &)
SequenceTestingListener(std::vector< std::string > *vector, const char *id)
StaticAssertTypeEqTestHelper()
virtual void OnTestProgramStart(const UnitTest &)
TestListener(int *on_start_counter, bool *is_destroyed)
MyTypeInNameSpace1(int an_x)
MyTypeInNameSpace2(int an_x)
const char * message() const
static void SetUpTestCase()
static void TearDownTestCase()
std::string GetString() const
static void CheckFlags(const Flags &expected)
static void AssertStringArrayEq(size_t size1, CharType **array1, size_t size2, CharType **array2)
static void TestParsingFlags(int argc1, const CharType **argv1, int argc2, const CharType **argv2, const Flags &expected, bool should_print_help)
static void SetUpTestCase()
static const char * shared_resource_
static void TearDownTestCase()
const TestInfo * GetTestInfo(int i) const
const TestResult & ad_hoc_test_result() const
int total_test_count() const
virtual void OnTestIterationEnd(const UnitTest &unit_test, int iteration)=0
virtual void OnTestProgramStart(const UnitTest &unit_test)=0
virtual void OnTestIterationStart(const UnitTest &unit_test, int iteration)=0
virtual void OnTestProgramEnd(const UnitTest &unit_test)=0
TestEventListener * Release(TestEventListener *listener)
void Append(TestEventListener *listener)
TestEventListener * default_result_printer() const
TestEventListener * default_xml_generator() const
static bool HasNonfatalFailure()
const char * name() const
const TestResult * result() const
const char * test_case_name() const
static const TestResult * GetTestResult(const TestInfo *test_info)
static const TestInfo * GetTestInfo(const char *test_name)
const TestPartResult & GetTestPartResult(int index) const
const char * message() const
const char * summary() const
const char * file_name() const
bool nonfatally_failed() const
bool fatally_failed() const
const char * value() const
int total_part_count() const
const TestProperty & GetTestProperty(int i) const
const TestPartResult & GetTestPartResult(int i) const
int test_property_count() const
const TestInfo * current_test_info() const GTEST_LOCK_EXCLUDED_(mutex_)
static UnitTest * GetInstance()
const TestCase * current_test_case() const GTEST_LOCK_EXCLUDED_(mutex_)
const TestResult & ad_hoc_test_result() const
const_iterator begin() const
const_iterator end() const
static const UInt32 kMaxRange
static bool EventForwardingEnabled(const TestEventListeners &listeners)
static TestEventListener * GetRepeater(TestEventListeners *listeners)
static void SetDefaultXmlGenerator(TestEventListeners *listeners, TestEventListener *listener)
static void SuppressEventForwarding(TestEventListeners *listeners)
static void SetDefaultResultPrinter(TestEventListeners *listeners, TestEventListener *listener)
static void ClearTestPartResults(TestResult *test_result)
void UnitTestRecordProperty(const char *key, const std::string &value)
UnitTestRecordPropertyTestHelper()
bool operator!=(const environment &other)
bool operator==(const environment &other)
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)
#define GTEST_IS_NULL_LITERAL_(x)
#define INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator,...)
#define TEST_P(test_case_name, test_name)
#define GTEST_ATTRIBUTE_UNUSED_
#define GTEST_FLAG_PREFIX_
#define GTEST_FLAG_PREFIX_UPPER_
#define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
#define GTEST_DISABLE_MSC_WARNINGS_POP_()
#define GTEST_CHECK_(condition)
#define GTEST_COMPILE_ASSERT_(expr, msg)
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
#define EXPECT_FATAL_FAILURE(statement, substr)
#define EXPECT_NONFATAL_FAILURE(statement, substr)
#define EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(statement, substr)
#define EXPECT_FATAL_FAILURE_ON_ALL_THREADS(statement, substr)
#define EXPECT_NO_FATAL_FAILURE(statement)
#define EXPECT_STRCASENE(s1, s2)
#define GTEST_ASSERT_GT(val1, val2)
#define TEST_F(test_fixture, test_name)
#define ASSERT_GT(val1, val2)
#define ASSERT_EQ(val1, val2)
#define EXPECT_NO_THROW(statement)
#define ASSERT_STRNE(s1, s2)
#define EXPECT_EQ(val1, val2)
#define ADD_FAILURE_AT(file, line)
#define ASSERT_FLOAT_EQ(val1, val2)
#define ASSERT_NO_FATAL_FAILURE(statement)
#define GTEST_ASSERT_GE(val1, val2)
#define ASSERT_STRCASEEQ(s1, s2)
#define GTEST_ASSERT_LT(val1, val2)
#define ASSERT_DOUBLE_EQ(val1, val2)
#define EXPECT_NE(val1, val2)
#define GTEST_ASSERT_NE(val1, val2)
#define GTEST_TEST(test_case_name, test_name)
#define ASSERT_NEAR(val1, val2, abs_error)
#define EXPECT_STRCASEEQ(s1, s2)
#define ASSERT_STREQ(s1, s2)
#define ASSERT_LE(val1, val2)
#define EXPECT_THROW(statement, expected_exception)
#define ASSERT_FALSE(condition)
#define EXPECT_NEAR(val1, val2, abs_error)
#define ASSERT_NO_THROW(statement)
#define GTEST_ASSERT_EQ(val1, val2)
#define EXPECT_FLOAT_EQ(val1, val2)
#define EXPECT_ANY_THROW(statement)
#define ASSERT_NE(val1, val2)
#define EXPECT_GT(val1, val2)
#define EXPECT_DOUBLE_EQ(val1, val2)
#define EXPECT_GE(val1, val2)
#define GTEST_ASSERT_LE(val1, val2)
#define EXPECT_TRUE(condition)
#define ASSERT_STRCASENE(s1, s2)
#define EXPECT_STREQ(s1, s2)
#define TEST(test_case_name, test_name)
#define EXPECT_LE(val1, val2)
#define ASSERT_TRUE(condition)
#define EXPECT_FALSE(condition)
#define ASSERT_THROW(statement, expected_exception)
#define EXPECT_STRNE(s1, s2)
#define EXPECT_LT(val1, val2)
#define ASSERT_GE(val1, val2)
#define ASSERT_ANY_THROW(statement)
#define ASSERT_LT(val1, val2)
REGISTER_TYPED_TEST_CASE_P(TypeParamTest, TestA, TestB)
TYPED_TEST(TypedTest, TestA)
TYPED_TEST_CASE(TypedTest, MyTypes)
TYPED_TEST_CASE_P(TypeParamTest)
TYPED_TEST_P(TypeParamTest, TestA)
INSTANTIATE_TYPED_TEST_CASE_P(My, TypeParamTest, MyTypes)
#define EXPECT_PRED_FORMAT1(pred_format, v1)
#define EXPECT_PRED3(pred, v1, v2, v3)
#define EXPECT_PRED2(pred, v1, v2)
#define ASSERT_PRED_FORMAT4(pred_format, v1, v2, v3, v4)
#define EXPECT_PRED_FORMAT4(pred_format, v1, v2, v3, v4)
#define ASSERT_PRED_FORMAT1(pred_format, v1)
#define ASSERT_PRED2(pred, v1, v2)
#define EXPECT_PRED1(pred, v1)
#define EXPECT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5)
#define ASSERT_PRED1(pred, v1)
#define ASSERT_PRED3(pred, v1, v2, v3)
#define ASSERT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5)
#define ASSERT_PRED_FORMAT2(pred_format, v1, v2)
#define EXPECT_PRED_FORMAT2(pred_format, v1, v2)
#define FRIEND_TEST(test_case_name, test_name)
void TestGTestReferenceToConst()
#define GTEST_TEST_PARSING_FLAGS_(argv1, argv2, expected, should_print_help)
#define VERIFY_CODE_LOCATION
void TestGTestRemoveConst()
void TestGTestAddReference()
::std::ostream & operator<<(::std::ostream &os, const TestingVector &vector)
#define GTEST_USE_UNPROTECTED_COMMA_
void TestGTestRemoveReference()
void TestGTestRemoveReferenceAndConst()
GeneratorWrapper< T > values(std::initializer_list< T > values)
LOGGING_API void printf(Category category, const char *format,...)
static const Reg8 ch(Operand::CH)
std::ostream & operator<<(std::ostream &os, const MyTypeInNameSpace1 &val)
FloatingPointTest< float > FloatTest
Matcher< int > GreaterThan(int n)
FloatingPointTest< double > DoubleTest
GTEST_API_ std::vector< EditType > CalculateOptimalEdits(const std::vector< size_t > &left, const std::vector< size_t > &right)
GTEST_API_ std::string CreateUnifiedDiff(const std::vector< std::string > &left, const std::vector< std::string > &right, size_t context=2)
int RmDir(const char *dir)
FILE * FOpen(const char *path, const char *mode)
GTEST_API_ std::string WideStringToUtf8(const wchar_t *str, int num_chars)
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)
GTEST_API_ std::string CodePointToUtf8(UInt32 code_point)
void ShuffleRange(internal::Random *random, int begin, int end, std::vector< E > *v)
GTEST_API_ Int32 Int32FromGTestEnv(const char *flag, Int32 default_val)
GTEST_API_ bool ShouldShard(const char *total_shards_str, const char *shard_index_str, bool in_subprocess_for_death_test)
int CountIf(const Container &c, Predicate predicate)
GTEST_API_ bool SkipPrefix(const char *prefix, const char **pstr)
TypeWithSize< 4 >::UInt UInt32
GTEST_API_ bool ShouldRunTestOnShard(int total_shards, int shard_index, int test_id)
GTEST_API_ void ParseGoogleTestFlagsOnly(int *argc, char **argv)
void ForEach(const Container &c, Functor functor)
std::string CanonicalizeForStdLibVersioning(std::string s)
GTEST_API_ std::string FormatEpochTimeInMillisAsIso8601(TimeInMillis ms)
int GetNextRandomSeed(int seed)
E GetElementOr(const std::vector< E > &v, int i, E default_value)
TypeWithSize< 4 >::Int Int32
GTEST_API_ std::string FormatTimeInMillisAsSeconds(TimeInMillis ms)
void Shuffle(internal::Random *random, std::vector< E > *v)
GTEST_API_ bool AlwaysTrue()
GTEST_API_ bool g_help_flag
Iter ArrayAwareFind(Iter begin, Iter end, const Element &elem)
class UnitTestImpl * GetUnitTestImpl()
GTEST_API_ Int32 Int32FromEnvOrDie(const char *env_var, Int32 default_val)
std::string StreamableToString(const T &streamable)
GTEST_API_ bool ShouldUseColor(bool stdout_is_tty)
GTEST_API_ const TypeId kTestTypeIdInGoogleTest
IsContainer IsContainerTest(int, typename C::iterator *=NULL, typename C::const_iterator *=NULL)
GTEST_API_ void CaptureStdout()
GTEST_API_ TypeId GetTestTypeId()
const BiggestInt kMaxBiggestInt
GTEST_API_ bool ParseInt32Flag(const char *str, const char *flag, Int32 *value)
GTEST_API_ std::string AppendUserMessage(const std::string >est_msg, const Message &user_msg)
GTEST_API_ TimeInMillis GetTimeInMillis()
int GetRandomSeedFromFlag(Int32 random_seed_flag)
GTEST_API_ std::string GetCurrentOsStackTraceExceptTop(UnitTest *unit_test, int skip_count)
GTEST_API_ std::string GetCapturedStdout()
bool ArrayEq(const T *lhs, size_t size, const U *rhs)
void CopyArray(const T *from, size_t size, U *to)
internal::ValueArray1< T1 > Values(T1 v1)
INSTANTIATE_TYPED_TEST_CASE_P(My, CodeLocationForTYPEDTESTP, int)
Environment * AddGlobalTestEnvironment(Environment *env)
GTEST_API_ AssertionResult IsNotSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
GTEST_API_ AssertionResult FloatLE(const char *expr1, const char *expr2, float val1, float val2)
GTEST_API_ AssertionResult IsSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
TYPED_TEST_P(CodeLocationForTYPEDTESTP, Verify)
TYPED_TEST(CodeLocationForTYPEDTEST, Verify)
TYPED_TEST_CASE_P(CodeLocationForTYPEDTESTP)
bool StaticAssertTypeEq()
GTEST_API_ AssertionResult AssertionFailure()
internal::TimeInMillis TimeInMillis
REGISTER_TYPED_TEST_CASE_P(CodeLocationForTYPEDTESTP, Verify)
GTEST_API_ std::string TempDir()
GTEST_API_ AssertionResult AssertionSuccess()
GTEST_API_ AssertionResult DoubleLE(const char *expr1, const char *expr2, double val1, double val2)
const int kMaxStackTraceDepth
TYPED_TEST_CASE(CodeLocationForTYPEDTEST, int)
const GenericPointer< typename T::ValueType > & pointer
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
#define T(meth, val, expected)
static Flags StackTraceDepth(Int32 stack_trace_depth)
static Flags Repeat(Int32 repeat)
static Flags Shuffle(bool shuffle)
static Flags CatchExceptions(bool catch_exceptions)
static Flags DeathTestUseFork(bool death_test_use_fork)
static Flags Output(const char *output)
static Flags BreakOnFailure(bool break_on_failure)
static Flags RandomSeed(Int32 random_seed)
static Flags ListTests(bool list_tests)
static Flags AlsoRunDisabledTests(bool also_run_disabled_tests)
bool also_run_disabled_tests
static Flags StreamResultTo(const char *stream_result_to)
const char * stream_result_to
static Flags ThrowOnFailure(bool throw_on_failure)
static Flags PrintTime(bool print_time)
static Flags Filter(const char *filter)
account_query_db::get_accounts_by_authorizers_result results