bloaty/third_party/googletest/googletest/test/gtest_unittest.cc
Go to the documentation of this file.
1 // Copyright 2005, Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 // * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 
30 //
31 // Tests for Google Test itself. This verifies that the basic constructs of
32 // Google Test work.
33 
34 #include "gtest/gtest.h"
35 
36 // Verifies that the command line flag variables can be accessed in
37 // code once "gtest.h" has been #included.
38 // Do not move it after other gtest #includes.
39 TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) {
40  bool dummy = testing::GTEST_FLAG(also_run_disabled_tests)
41  || testing::GTEST_FLAG(break_on_failure)
42  || testing::GTEST_FLAG(catch_exceptions)
43  || testing::GTEST_FLAG(color) != "unknown"
44  || testing::GTEST_FLAG(filter) != "unknown"
45  || testing::GTEST_FLAG(list_tests)
46  || testing::GTEST_FLAG(output) != "unknown"
47  || testing::GTEST_FLAG(print_time)
48  || testing::GTEST_FLAG(random_seed)
49  || testing::GTEST_FLAG(repeat) > 0
50  || testing::GTEST_FLAG(show_internal_stack_frames)
51  || testing::GTEST_FLAG(shuffle)
52  || testing::GTEST_FLAG(stack_trace_depth) > 0
53  || testing::GTEST_FLAG(stream_result_to) != "unknown"
54  || testing::GTEST_FLAG(throw_on_failure);
55  EXPECT_TRUE(dummy || !dummy); // Suppresses warning that dummy is unused.
56 }
57 
58 #include <limits.h> // For INT_MAX.
59 #include <stdlib.h>
60 #include <string.h>
61 #include <time.h>
62 
63 #include <map>
64 #include <ostream>
65 #include <type_traits>
66 #include <unordered_set>
67 #include <vector>
68 
69 #include "gtest/gtest-spi.h"
70 #include "src/gtest-internal-inl.h"
71 
72 namespace testing {
73 namespace internal {
74 
75 #if GTEST_CAN_STREAM_RESULTS_
76 
77 class StreamingListenerTest : public Test {
78  public:
79  class FakeSocketWriter : public StreamingListener::AbstractSocketWriter {
80  public:
81  // Sends a string to the socket.
82  void Send(const std::string& message) override { output_ += message; }
83 
85  };
86 
87  StreamingListenerTest()
88  : fake_sock_writer_(new FakeSocketWriter),
89  streamer_(fake_sock_writer_),
90  test_info_obj_("FooTest", "Bar", nullptr, nullptr,
91  CodeLocation(__FILE__, __LINE__), nullptr, nullptr) {}
92 
93  protected:
94  std::string* output() { return &(fake_sock_writer_->output_); }
95 
96  FakeSocketWriter* const fake_sock_writer_;
97  StreamingListener streamer_;
98  UnitTest unit_test_;
99  TestInfo test_info_obj_; // The name test_info_ was taken by testing::Test.
100 };
101 
102 TEST_F(StreamingListenerTest, OnTestProgramEnd) {
103  *output() = "";
104  streamer_.OnTestProgramEnd(unit_test_);
105  EXPECT_EQ("event=TestProgramEnd&passed=1\n", *output());
106 }
107 
108 TEST_F(StreamingListenerTest, OnTestIterationEnd) {
109  *output() = "";
110  streamer_.OnTestIterationEnd(unit_test_, 42);
111  EXPECT_EQ("event=TestIterationEnd&passed=1&elapsed_time=0ms\n", *output());
112 }
113 
114 TEST_F(StreamingListenerTest, OnTestCaseStart) {
115  *output() = "";
116  streamer_.OnTestCaseStart(TestCase("FooTest", "Bar", nullptr, nullptr));
117  EXPECT_EQ("event=TestCaseStart&name=FooTest\n", *output());
118 }
119 
120 TEST_F(StreamingListenerTest, OnTestCaseEnd) {
121  *output() = "";
122  streamer_.OnTestCaseEnd(TestCase("FooTest", "Bar", nullptr, nullptr));
123  EXPECT_EQ("event=TestCaseEnd&passed=1&elapsed_time=0ms\n", *output());
124 }
125 
126 TEST_F(StreamingListenerTest, OnTestStart) {
127  *output() = "";
128  streamer_.OnTestStart(test_info_obj_);
129  EXPECT_EQ("event=TestStart&name=Bar\n", *output());
130 }
131 
132 TEST_F(StreamingListenerTest, OnTestEnd) {
133  *output() = "";
134  streamer_.OnTestEnd(test_info_obj_);
135  EXPECT_EQ("event=TestEnd&passed=1&elapsed_time=0ms\n", *output());
136 }
137 
138 TEST_F(StreamingListenerTest, OnTestPartResult) {
139  *output() = "";
140  streamer_.OnTestPartResult(TestPartResult(
141  TestPartResult::kFatalFailure, "foo.cc", 42, "failed=\n&%"));
142 
143  // Meta characters in the failure message should be properly escaped.
144  EXPECT_EQ(
145  "event=TestPartResult&file=foo.cc&line=42&message=failed%3D%0A%26%25\n",
146  *output());
147 }
148 
149 #endif // GTEST_CAN_STREAM_RESULTS_
150 
151 // Provides access to otherwise private parts of the TestEventListeners class
152 // that are needed to test it.
154  public:
156  return listeners->repeater();
157  }
158 
160  TestEventListener* listener) {
161  listeners->SetDefaultResultPrinter(listener);
162  }
164  TestEventListener* listener) {
165  listeners->SetDefaultXmlGenerator(listener);
166  }
167 
168  static bool EventForwardingEnabled(const TestEventListeners& listeners) {
169  return listeners.EventForwardingEnabled();
170  }
171 
172  static void SuppressEventForwarding(TestEventListeners* listeners) {
173  listeners->SuppressEventForwarding();
174  }
175 };
176 
178  protected:
180 
181  // Forwards to UnitTest::RecordProperty() to bypass access controls.
182  void UnitTestRecordProperty(const char* key, const std::string& value) {
184  }
185 
187 };
188 
189 } // namespace internal
190 } // namespace testing
191 
195 using testing::DoubleLE;
198 using testing::FloatLE;
199 using testing::GTEST_FLAG(also_run_disabled_tests);
200 using testing::GTEST_FLAG(break_on_failure);
201 using testing::GTEST_FLAG(catch_exceptions);
202 using testing::GTEST_FLAG(color);
203 using testing::GTEST_FLAG(death_test_use_fork);
204 using testing::GTEST_FLAG(filter);
205 using testing::GTEST_FLAG(list_tests);
207 using testing::GTEST_FLAG(print_time);
208 using testing::GTEST_FLAG(random_seed);
209 using testing::GTEST_FLAG(repeat);
210 using testing::GTEST_FLAG(show_internal_stack_frames);
211 using testing::GTEST_FLAG(shuffle);
212 using testing::GTEST_FLAG(stack_trace_depth);
213 using testing::GTEST_FLAG(stream_result_to);
214 using testing::GTEST_FLAG(throw_on_failure);
217 using testing::Message;
220 using testing::Test;
221 using testing::TestCase;
223 using testing::TestInfo;
227 using testing::TestResult;
229 using testing::UnitTest;
285 
286 #if GTEST_HAS_STREAM_REDIRECTION
289 #endif
290 
291 #if GTEST_IS_THREADSAFE
292 using testing::internal::ThreadWithParam;
293 #endif
294 
295 class TestingVector : public std::vector<int> {
296 };
297 
298 ::std::ostream& operator<<(::std::ostream& os,
299  const TestingVector& vector) {
300  os << "{ ";
301  for (size_t i = 0; i < vector.size(); i++) {
302  os << vector[i] << " ";
303  }
304  os << "}";
305  return os;
306 }
307 
308 // This line tests that we can define tests in an unnamed namespace.
309 namespace {
310 
311 TEST(GetRandomSeedFromFlagTest, HandlesZero) {
312  const int seed = GetRandomSeedFromFlag(0);
313  EXPECT_LE(1, seed);
314  EXPECT_LE(seed, static_cast<int>(kMaxRandomSeed));
315 }
316 
317 TEST(GetRandomSeedFromFlagTest, PreservesValidSeed) {
321  EXPECT_EQ(static_cast<int>(kMaxRandomSeed),
323 }
324 
325 TEST(GetRandomSeedFromFlagTest, NormalizesInvalidSeed) {
326  const int seed1 = GetRandomSeedFromFlag(-1);
327  EXPECT_LE(1, seed1);
328  EXPECT_LE(seed1, static_cast<int>(kMaxRandomSeed));
329 
330  const int seed2 = GetRandomSeedFromFlag(kMaxRandomSeed + 1);
331  EXPECT_LE(1, seed2);
332  EXPECT_LE(seed2, static_cast<int>(kMaxRandomSeed));
333 }
334 
335 TEST(GetNextRandomSeedTest, WorksForValidInput) {
338  EXPECT_EQ(static_cast<int>(kMaxRandomSeed),
341 
342  // We deliberately don't test GetNextRandomSeed() with invalid
343  // inputs, as that requires death tests, which are expensive. This
344  // is fine as GetNextRandomSeed() is internal and has a
345  // straightforward definition.
346 }
347 
348 static void ClearCurrentTestPartResults() {
349  TestResultAccessor::ClearTestPartResults(
350  GetUnitTestImpl()->current_test_result());
351 }
352 
353 // Tests GetTypeId.
354 
355 TEST(GetTypeIdTest, ReturnsSameValueForSameType) {
356  EXPECT_EQ(GetTypeId<int>(), GetTypeId<int>());
357  EXPECT_EQ(GetTypeId<Test>(), GetTypeId<Test>());
358 }
359 
360 class SubClassOfTest : public Test {};
361 class AnotherSubClassOfTest : public Test {};
362 
363 TEST(GetTypeIdTest, ReturnsDifferentValuesForDifferentTypes) {
364  EXPECT_NE(GetTypeId<int>(), GetTypeId<const int>());
365  EXPECT_NE(GetTypeId<int>(), GetTypeId<char>());
366  EXPECT_NE(GetTypeId<int>(), GetTestTypeId());
367  EXPECT_NE(GetTypeId<SubClassOfTest>(), GetTestTypeId());
368  EXPECT_NE(GetTypeId<AnotherSubClassOfTest>(), GetTestTypeId());
369  EXPECT_NE(GetTypeId<AnotherSubClassOfTest>(), GetTypeId<SubClassOfTest>());
370 }
371 
372 // Verifies that GetTestTypeId() returns the same value, no matter it
373 // is called from inside Google Test or outside of it.
374 TEST(GetTestTypeIdTest, ReturnsTheSameValueInsideOrOutsideOfGoogleTest) {
376 }
377 
378 // Tests CanonicalizeForStdLibVersioning.
379 
381 
382 TEST(CanonicalizeForStdLibVersioning, LeavesUnversionedNamesUnchanged) {
383  EXPECT_EQ("std::bind", CanonicalizeForStdLibVersioning("std::bind"));
384  EXPECT_EQ("std::_", CanonicalizeForStdLibVersioning("std::_"));
385  EXPECT_EQ("std::__foo", CanonicalizeForStdLibVersioning("std::__foo"));
386  EXPECT_EQ("gtl::__1::x", CanonicalizeForStdLibVersioning("gtl::__1::x"));
387  EXPECT_EQ("__1::x", CanonicalizeForStdLibVersioning("__1::x"));
388  EXPECT_EQ("::__1::x", CanonicalizeForStdLibVersioning("::__1::x"));
389 }
390 
391 TEST(CanonicalizeForStdLibVersioning, ElidesDoubleUnderNames) {
392  EXPECT_EQ("std::bind", CanonicalizeForStdLibVersioning("std::__1::bind"));
393  EXPECT_EQ("std::_", CanonicalizeForStdLibVersioning("std::__1::_"));
394 
395  EXPECT_EQ("std::bind", CanonicalizeForStdLibVersioning("std::__g::bind"));
396  EXPECT_EQ("std::_", CanonicalizeForStdLibVersioning("std::__g::_"));
397 
398  EXPECT_EQ("std::bind",
399  CanonicalizeForStdLibVersioning("std::__google::bind"));
400  EXPECT_EQ("std::_", CanonicalizeForStdLibVersioning("std::__google::_"));
401 }
402 
403 // Tests FormatTimeInMillisAsSeconds().
404 
405 TEST(FormatTimeInMillisAsSecondsTest, FormatsZero) {
407 }
408 
409 TEST(FormatTimeInMillisAsSecondsTest, FormatsPositiveNumber) {
415 }
416 
417 TEST(FormatTimeInMillisAsSecondsTest, FormatsNegativeNumber) {
418  EXPECT_EQ("-0.003", FormatTimeInMillisAsSeconds(-3));
419  EXPECT_EQ("-0.01", FormatTimeInMillisAsSeconds(-10));
420  EXPECT_EQ("-0.2", FormatTimeInMillisAsSeconds(-200));
421  EXPECT_EQ("-1.2", FormatTimeInMillisAsSeconds(-1200));
423 }
424 
425 // Tests FormatEpochTimeInMillisAsIso8601(). The correctness of conversion
426 // for particular dates below was verified in Python using
427 // datetime.datetime.fromutctimestamp(<timetamp>/1000).
428 
429 // FormatEpochTimeInMillisAsIso8601 depends on the current timezone, so we
430 // have to set up a particular timezone to obtain predictable results.
431 class FormatEpochTimeInMillisAsIso8601Test : public Test {
432  public:
433  // On Cygwin, GCC doesn't allow unqualified integer literals to exceed
434  // 32 bits, even when 64-bit integer types are available. We have to
435  // force the constants to have a 64-bit type here.
436  static const TimeInMillis kMillisPerSec = 1000;
437 
438  private:
439  void SetUp() override {
440  saved_tz_ = nullptr;
441 
442  GTEST_DISABLE_MSC_DEPRECATED_PUSH_(/* getenv, strdup: deprecated */)
443  if (getenv("TZ"))
444  saved_tz_ = strdup(getenv("TZ"));
446 
447  // Set up the time zone for FormatEpochTimeInMillisAsIso8601 to use. We
448  // cannot use the local time zone because the function's output depends
449  // on the time zone.
450  SetTimeZone("UTC+00");
451  }
452 
453  void TearDown() override {
454  SetTimeZone(saved_tz_);
455  free(const_cast<char*>(saved_tz_));
456  saved_tz_ = nullptr;
457  }
458 
459  static void SetTimeZone(const char* time_zone) {
460  // tzset() distinguishes between the TZ variable being present and empty
461  // and not being present, so we have to consider the case of time_zone
462  // being NULL.
463 #if _MSC_VER || GTEST_OS_WINDOWS_MINGW
464  // ...Unless it's MSVC, whose standard library's _putenv doesn't
465  // distinguish between an empty and a missing variable.
466  const std::string env_var =
467  std::string("TZ=") + (time_zone ? time_zone : "");
468  _putenv(env_var.c_str());
469  GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996 /* deprecated function */)
470  tzset();
472 #else
473  if (time_zone) {
474  setenv(("TZ"), time_zone, 1);
475  } else {
476  unsetenv("TZ");
477  }
478  tzset();
479 #endif
480  }
481 
482  const char* saved_tz_;
483 };
484 
485 const TimeInMillis FormatEpochTimeInMillisAsIso8601Test::kMillisPerSec;
486 
487 TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsTwoDigitSegments) {
488  EXPECT_EQ("2011-10-31T18:52:42",
489  FormatEpochTimeInMillisAsIso8601(1320087162 * kMillisPerSec));
490 }
491 
492 TEST_F(FormatEpochTimeInMillisAsIso8601Test, MillisecondsDoNotAffectResult) {
493  EXPECT_EQ(
494  "2011-10-31T18:52:42",
495  FormatEpochTimeInMillisAsIso8601(1320087162 * kMillisPerSec + 234));
496 }
497 
498 TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsLeadingZeroes) {
499  EXPECT_EQ("2011-09-03T05:07:02",
500  FormatEpochTimeInMillisAsIso8601(1315026422 * kMillisPerSec));
501 }
502 
503 TEST_F(FormatEpochTimeInMillisAsIso8601Test, Prints24HourTime) {
504  EXPECT_EQ("2011-09-28T17:08:22",
505  FormatEpochTimeInMillisAsIso8601(1317229702 * kMillisPerSec));
506 }
507 
508 TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsEpochStart) {
509  EXPECT_EQ("1970-01-01T00:00:00", FormatEpochTimeInMillisAsIso8601(0));
510 }
511 
512 # ifdef __BORLANDC__
513 // Silences warnings: "Condition is always true", "Unreachable code"
514 # pragma option push -w-ccc -w-rch
515 # endif
516 
517 // Tests that the LHS of EXPECT_EQ or ASSERT_EQ can be used as a null literal
518 // when the RHS is a pointer type.
519 TEST(NullLiteralTest, LHSAllowsNullLiterals) {
520  EXPECT_EQ(0, static_cast<void*>(nullptr)); // NOLINT
521  ASSERT_EQ(0, static_cast<void*>(nullptr)); // NOLINT
522  EXPECT_EQ(NULL, static_cast<void*>(nullptr)); // NOLINT
523  ASSERT_EQ(NULL, static_cast<void*>(nullptr)); // NOLINT
524  EXPECT_EQ(nullptr, static_cast<void*>(nullptr));
525  ASSERT_EQ(nullptr, static_cast<void*>(nullptr));
526 
527  const int* const p = nullptr;
528  EXPECT_EQ(0, p); // NOLINT
529  ASSERT_EQ(0, p); // NOLINT
530  EXPECT_EQ(NULL, p); // NOLINT
531  ASSERT_EQ(NULL, p); // NOLINT
532  EXPECT_EQ(nullptr, p);
533  ASSERT_EQ(nullptr, p);
534 }
535 
536 struct ConvertToAll {
537  template <typename T>
538  operator T() const { // NOLINT
539  return T();
540  }
541 };
542 
543 struct ConvertToPointer {
544  template <class T>
545  operator T*() const { // NOLINT
546  return nullptr;
547  }
548 };
549 
550 struct ConvertToAllButNoPointers {
551  template <typename T,
553  operator T() const { // NOLINT
554  return T();
555  }
556 };
557 
558 struct MyType {};
559 inline bool operator==(MyType const&, MyType const&) { return true; }
560 
561 TEST(NullLiteralTest, ImplicitConversion) {
562  EXPECT_EQ(ConvertToPointer{}, static_cast<void*>(nullptr));
563 #if !defined(__GNUC__) || defined(__clang__)
564  // Disabled due to GCC bug gcc.gnu.org/PR89580
565  EXPECT_EQ(ConvertToAll{}, static_cast<void*>(nullptr));
566 #endif
567  EXPECT_EQ(ConvertToAll{}, MyType{});
568  EXPECT_EQ(ConvertToAllButNoPointers{}, MyType{});
569 }
570 
571 #ifdef __clang__
572 #pragma clang diagnostic push
573 #if __has_warning("-Wzero-as-null-pointer-constant")
574 #pragma clang diagnostic error "-Wzero-as-null-pointer-constant"
575 #endif
576 #endif
577 
578 TEST(NullLiteralTest, NoConversionNoWarning) {
579  // Test that gtests detection and handling of null pointer constants
580  // doesn't trigger a warning when '0' isn't actually used as null.
581  EXPECT_EQ(0, 0);
582  ASSERT_EQ(0, 0);
583 }
584 
585 #ifdef __clang__
586 #pragma clang diagnostic pop
587 #endif
588 
589 # ifdef __BORLANDC__
590 // Restores warnings after previous "#pragma option push" suppressed them.
591 # pragma option pop
592 # endif
593 
594 //
595 // Tests CodePointToUtf8().
596 
597 // Tests that the NUL character L'\0' is encoded correctly.
598 TEST(CodePointToUtf8Test, CanEncodeNul) {
599  EXPECT_EQ("", CodePointToUtf8(L'\0'));
600 }
601 
602 // Tests that ASCII characters are encoded correctly.
603 TEST(CodePointToUtf8Test, CanEncodeAscii) {
604  EXPECT_EQ("a", CodePointToUtf8(L'a'));
605  EXPECT_EQ("Z", CodePointToUtf8(L'Z'));
606  EXPECT_EQ("&", CodePointToUtf8(L'&'));
607  EXPECT_EQ("\x7F", CodePointToUtf8(L'\x7F'));
608 }
609 
610 // Tests that Unicode code-points that have 8 to 11 bits are encoded
611 // as 110xxxxx 10xxxxxx.
612 TEST(CodePointToUtf8Test, CanEncode8To11Bits) {
613  // 000 1101 0011 => 110-00011 10-010011
614  EXPECT_EQ("\xC3\x93", CodePointToUtf8(L'\xD3'));
615 
616  // 101 0111 0110 => 110-10101 10-110110
617  // Some compilers (e.g., GCC on MinGW) cannot handle non-ASCII codepoints
618  // in wide strings and wide chars. In order to accommodate them, we have to
619  // introduce such character constants as integers.
620  EXPECT_EQ("\xD5\xB6",
621  CodePointToUtf8(static_cast<wchar_t>(0x576)));
622 }
623 
624 // Tests that Unicode code-points that have 12 to 16 bits are encoded
625 // as 1110xxxx 10xxxxxx 10xxxxxx.
626 TEST(CodePointToUtf8Test, CanEncode12To16Bits) {
627  // 0000 1000 1101 0011 => 1110-0000 10-100011 10-010011
628  EXPECT_EQ("\xE0\xA3\x93",
629  CodePointToUtf8(static_cast<wchar_t>(0x8D3)));
630 
631  // 1100 0111 0100 1101 => 1110-1100 10-011101 10-001101
632  EXPECT_EQ("\xEC\x9D\x8D",
633  CodePointToUtf8(static_cast<wchar_t>(0xC74D)));
634 }
635 
636 #if !GTEST_WIDE_STRING_USES_UTF16_
637 // Tests in this group require a wchar_t to hold > 16 bits, and thus
638 // are skipped on Windows, and Cygwin, where a wchar_t is
639 // 16-bit wide. This code may not compile on those systems.
640 
641 // Tests that Unicode code-points that have 17 to 21 bits are encoded
642 // as 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx.
643 TEST(CodePointToUtf8Test, CanEncode17To21Bits) {
644  // 0 0001 0000 1000 1101 0011 => 11110-000 10-010000 10-100011 10-010011
645  EXPECT_EQ("\xF0\x90\xA3\x93", CodePointToUtf8(L'\x108D3'));
646 
647  // 0 0001 0000 0100 0000 0000 => 11110-000 10-010000 10-010000 10-000000
648  EXPECT_EQ("\xF0\x90\x90\x80", CodePointToUtf8(L'\x10400'));
649 
650  // 1 0000 1000 0110 0011 0100 => 11110-100 10-001000 10-011000 10-110100
651  EXPECT_EQ("\xF4\x88\x98\xB4", CodePointToUtf8(L'\x108634'));
652 }
653 
654 // Tests that encoding an invalid code-point generates the expected result.
655 TEST(CodePointToUtf8Test, CanEncodeInvalidCodePoint) {
656  EXPECT_EQ("(Invalid Unicode 0x1234ABCD)", CodePointToUtf8(L'\x1234ABCD'));
657 }
658 
659 #endif // !GTEST_WIDE_STRING_USES_UTF16_
660 
661 // Tests WideStringToUtf8().
662 
663 // Tests that the NUL character L'\0' is encoded correctly.
664 TEST(WideStringToUtf8Test, CanEncodeNul) {
665  EXPECT_STREQ("", WideStringToUtf8(L"", 0).c_str());
666  EXPECT_STREQ("", WideStringToUtf8(L"", -1).c_str());
667 }
668 
669 // Tests that ASCII strings are encoded correctly.
670 TEST(WideStringToUtf8Test, CanEncodeAscii) {
671  EXPECT_STREQ("a", WideStringToUtf8(L"a", 1).c_str());
672  EXPECT_STREQ("ab", WideStringToUtf8(L"ab", 2).c_str());
673  EXPECT_STREQ("a", WideStringToUtf8(L"a", -1).c_str());
674  EXPECT_STREQ("ab", WideStringToUtf8(L"ab", -1).c_str());
675 }
676 
677 // Tests that Unicode code-points that have 8 to 11 bits are encoded
678 // as 110xxxxx 10xxxxxx.
679 TEST(WideStringToUtf8Test, CanEncode8To11Bits) {
680  // 000 1101 0011 => 110-00011 10-010011
681  EXPECT_STREQ("\xC3\x93", WideStringToUtf8(L"\xD3", 1).c_str());
682  EXPECT_STREQ("\xC3\x93", WideStringToUtf8(L"\xD3", -1).c_str());
683 
684  // 101 0111 0110 => 110-10101 10-110110
685  const wchar_t s[] = { 0x576, '\0' };
686  EXPECT_STREQ("\xD5\xB6", WideStringToUtf8(s, 1).c_str());
687  EXPECT_STREQ("\xD5\xB6", WideStringToUtf8(s, -1).c_str());
688 }
689 
690 // Tests that Unicode code-points that have 12 to 16 bits are encoded
691 // as 1110xxxx 10xxxxxx 10xxxxxx.
692 TEST(WideStringToUtf8Test, CanEncode12To16Bits) {
693  // 0000 1000 1101 0011 => 1110-0000 10-100011 10-010011
694  const wchar_t s1[] = { 0x8D3, '\0' };
695  EXPECT_STREQ("\xE0\xA3\x93", WideStringToUtf8(s1, 1).c_str());
696  EXPECT_STREQ("\xE0\xA3\x93", WideStringToUtf8(s1, -1).c_str());
697 
698  // 1100 0111 0100 1101 => 1110-1100 10-011101 10-001101
699  const wchar_t s2[] = { 0xC74D, '\0' };
700  EXPECT_STREQ("\xEC\x9D\x8D", WideStringToUtf8(s2, 1).c_str());
701  EXPECT_STREQ("\xEC\x9D\x8D", WideStringToUtf8(s2, -1).c_str());
702 }
703 
704 // Tests that the conversion stops when the function encounters \0 character.
705 TEST(WideStringToUtf8Test, StopsOnNulCharacter) {
706  EXPECT_STREQ("ABC", WideStringToUtf8(L"ABC\0XYZ", 100).c_str());
707 }
708 
709 // Tests that the conversion stops when the function reaches the limit
710 // specified by the 'length' parameter.
711 TEST(WideStringToUtf8Test, StopsWhenLengthLimitReached) {
712  EXPECT_STREQ("ABC", WideStringToUtf8(L"ABCDEF", 3).c_str());
713 }
714 
715 #if !GTEST_WIDE_STRING_USES_UTF16_
716 // Tests that Unicode code-points that have 17 to 21 bits are encoded
717 // as 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx. This code may not compile
718 // on the systems using UTF-16 encoding.
719 TEST(WideStringToUtf8Test, CanEncode17To21Bits) {
720  // 0 0001 0000 1000 1101 0011 => 11110-000 10-010000 10-100011 10-010011
721  EXPECT_STREQ("\xF0\x90\xA3\x93", WideStringToUtf8(L"\x108D3", 1).c_str());
722  EXPECT_STREQ("\xF0\x90\xA3\x93", WideStringToUtf8(L"\x108D3", -1).c_str());
723 
724  // 1 0000 1000 0110 0011 0100 => 11110-100 10-001000 10-011000 10-110100
725  EXPECT_STREQ("\xF4\x88\x98\xB4", WideStringToUtf8(L"\x108634", 1).c_str());
726  EXPECT_STREQ("\xF4\x88\x98\xB4", WideStringToUtf8(L"\x108634", -1).c_str());
727 }
728 
729 // Tests that encoding an invalid code-point generates the expected result.
730 TEST(WideStringToUtf8Test, CanEncodeInvalidCodePoint) {
731  EXPECT_STREQ("(Invalid Unicode 0xABCDFF)",
732  WideStringToUtf8(L"\xABCDFF", -1).c_str());
733 }
734 #else // !GTEST_WIDE_STRING_USES_UTF16_
735 // Tests that surrogate pairs are encoded correctly on the systems using
736 // UTF-16 encoding in the wide strings.
737 TEST(WideStringToUtf8Test, CanEncodeValidUtf16SUrrogatePairs) {
738  const wchar_t s[] = { 0xD801, 0xDC00, '\0' };
739  EXPECT_STREQ("\xF0\x90\x90\x80", WideStringToUtf8(s, -1).c_str());
740 }
741 
742 // Tests that encoding an invalid UTF-16 surrogate pair
743 // generates the expected result.
744 TEST(WideStringToUtf8Test, CanEncodeInvalidUtf16SurrogatePair) {
745  // Leading surrogate is at the end of the string.
746  const wchar_t s1[] = { 0xD800, '\0' };
747  EXPECT_STREQ("\xED\xA0\x80", WideStringToUtf8(s1, -1).c_str());
748  // Leading surrogate is not followed by the trailing surrogate.
749  const wchar_t s2[] = { 0xD800, 'M', '\0' };
750  EXPECT_STREQ("\xED\xA0\x80M", WideStringToUtf8(s2, -1).c_str());
751  // Trailing surrogate appearas without a leading surrogate.
752  const wchar_t s3[] = { 0xDC00, 'P', 'Q', 'R', '\0' };
753  EXPECT_STREQ("\xED\xB0\x80PQR", WideStringToUtf8(s3, -1).c_str());
754 }
755 #endif // !GTEST_WIDE_STRING_USES_UTF16_
756 
757 // Tests that codepoint concatenation works correctly.
758 #if !GTEST_WIDE_STRING_USES_UTF16_
759 TEST(WideStringToUtf8Test, ConcatenatesCodepointsCorrectly) {
760  const wchar_t s[] = { 0x108634, 0xC74D, '\n', 0x576, 0x8D3, 0x108634, '\0'};
761  EXPECT_STREQ(
762  "\xF4\x88\x98\xB4"
763  "\xEC\x9D\x8D"
764  "\n"
765  "\xD5\xB6"
766  "\xE0\xA3\x93"
767  "\xF4\x88\x98\xB4",
768  WideStringToUtf8(s, -1).c_str());
769 }
770 #else
771 TEST(WideStringToUtf8Test, ConcatenatesCodepointsCorrectly) {
772  const wchar_t s[] = { 0xC74D, '\n', 0x576, 0x8D3, '\0'};
773  EXPECT_STREQ(
774  "\xEC\x9D\x8D" "\n" "\xD5\xB6" "\xE0\xA3\x93",
775  WideStringToUtf8(s, -1).c_str());
776 }
777 #endif // !GTEST_WIDE_STRING_USES_UTF16_
778 
779 // Tests the Random class.
780 
781 TEST(RandomDeathTest, GeneratesCrashesOnInvalidRange) {
782  testing::internal::Random random(42);
784  random.Generate(0),
785  "Cannot generate a number in the range \\[0, 0\\)");
787  random.Generate(testing::internal::Random::kMaxRange + 1),
788  "Generation of a number in \\[0, 2147483649\\) was requested, "
789  "but this can only generate numbers in \\[0, 2147483648\\)");
790 }
791 
792 TEST(RandomTest, GeneratesNumbersWithinRange) {
793  const UInt32 kRange = 10000;
794  testing::internal::Random random(12345);
795  for (int i = 0; i < 10; i++) {
796  EXPECT_LT(random.Generate(kRange), kRange) << " for iteration " << i;
797  }
798 
800  for (int i = 0; i < 10; i++) {
801  EXPECT_LT(random2.Generate(kRange), kRange) << " for iteration " << i;
802  }
803 }
804 
805 TEST(RandomTest, RepeatsWhenReseeded) {
806  const int kSeed = 123;
807  const int kArraySize = 10;
808  const UInt32 kRange = 10000;
809  UInt32 values[kArraySize];
810 
811  testing::internal::Random random(kSeed);
812  for (int i = 0; i < kArraySize; i++) {
813  values[i] = random.Generate(kRange);
814  }
815 
816  random.Reseed(kSeed);
817  for (int i = 0; i < kArraySize; i++) {
818  EXPECT_EQ(values[i], random.Generate(kRange)) << " for iteration " << i;
819  }
820 }
821 
822 // Tests STL container utilities.
823 
824 // Tests CountIf().
825 
826 static bool IsPositive(int n) { return n > 0; }
827 
828 TEST(ContainerUtilityTest, CountIf) {
829  std::vector<int> v;
830  EXPECT_EQ(0, CountIf(v, IsPositive)); // Works for an empty container.
831 
832  v.push_back(-1);
833  v.push_back(0);
834  EXPECT_EQ(0, CountIf(v, IsPositive)); // Works when no value satisfies.
835 
836  v.push_back(2);
837  v.push_back(-10);
838  v.push_back(10);
839  EXPECT_EQ(2, CountIf(v, IsPositive));
840 }
841 
842 // Tests ForEach().
843 
844 static int g_sum = 0;
845 static void Accumulate(int n) { g_sum += n; }
846 
847 TEST(ContainerUtilityTest, ForEach) {
848  std::vector<int> v;
849  g_sum = 0;
850  ForEach(v, Accumulate);
851  EXPECT_EQ(0, g_sum); // Works for an empty container;
852 
853  g_sum = 0;
854  v.push_back(1);
855  ForEach(v, Accumulate);
856  EXPECT_EQ(1, g_sum); // Works for a container with one element.
857 
858  g_sum = 0;
859  v.push_back(20);
860  v.push_back(300);
861  ForEach(v, Accumulate);
862  EXPECT_EQ(321, g_sum);
863 }
864 
865 // Tests GetElementOr().
866 TEST(ContainerUtilityTest, GetElementOr) {
867  std::vector<char> a;
868  EXPECT_EQ('x', GetElementOr(a, 0, 'x'));
869 
870  a.push_back('a');
871  a.push_back('b');
872  EXPECT_EQ('a', GetElementOr(a, 0, 'x'));
873  EXPECT_EQ('b', GetElementOr(a, 1, 'x'));
874  EXPECT_EQ('x', GetElementOr(a, -2, 'x'));
875  EXPECT_EQ('x', GetElementOr(a, 2, 'x'));
876 }
877 
878 TEST(ContainerUtilityDeathTest, ShuffleRange) {
879  std::vector<int> a;
880  a.push_back(0);
881  a.push_back(1);
882  a.push_back(2);
883  testing::internal::Random random(1);
884 
886  ShuffleRange(&random, -1, 1, &a),
887  "Invalid shuffle range start -1: must be in range \\[0, 3\\]");
889  ShuffleRange(&random, 4, 4, &a),
890  "Invalid shuffle range start 4: must be in range \\[0, 3\\]");
892  ShuffleRange(&random, 3, 2, &a),
893  "Invalid shuffle range finish 2: must be in range \\[3, 3\\]");
895  ShuffleRange(&random, 3, 4, &a),
896  "Invalid shuffle range finish 4: must be in range \\[3, 3\\]");
897 }
898 
899 class VectorShuffleTest : public Test {
900  protected:
901  static const size_t kVectorSize = 20;
902 
903  VectorShuffleTest() : random_(1) {
904  for (int i = 0; i < static_cast<int>(kVectorSize); i++) {
905  vector_.push_back(i);
906  }
907  }
908 
909  static bool VectorIsCorrupt(const TestingVector& vector) {
910  if (kVectorSize != vector.size()) {
911  return true;
912  }
913 
914  bool found_in_vector[kVectorSize] = { false };
915  for (size_t i = 0; i < vector.size(); i++) {
916  const int e = vector[i];
917  if (e < 0 || e >= static_cast<int>(kVectorSize) || found_in_vector[e]) {
918  return true;
919  }
920  found_in_vector[e] = true;
921  }
922 
923  // Vector size is correct, elements' range is correct, no
924  // duplicate elements. Therefore no corruption has occurred.
925  return false;
926  }
927 
928  static bool VectorIsNotCorrupt(const TestingVector& vector) {
929  return !VectorIsCorrupt(vector);
930  }
931 
932  static bool RangeIsShuffled(const TestingVector& vector, int begin, int end) {
933  for (int i = begin; i < end; i++) {
934  if (i != vector[static_cast<size_t>(i)]) {
935  return true;
936  }
937  }
938  return false;
939  }
940 
941  static bool RangeIsUnshuffled(
942  const TestingVector& vector, int begin, int end) {
943  return !RangeIsShuffled(vector, begin, end);
944  }
945 
946  static bool VectorIsShuffled(const TestingVector& vector) {
947  return RangeIsShuffled(vector, 0, static_cast<int>(vector.size()));
948  }
949 
950  static bool VectorIsUnshuffled(const TestingVector& vector) {
951  return !VectorIsShuffled(vector);
952  }
953 
955  TestingVector vector_;
956 }; // class VectorShuffleTest
957 
958 const size_t VectorShuffleTest::kVectorSize;
959 
960 TEST_F(VectorShuffleTest, HandlesEmptyRange) {
961  // Tests an empty range at the beginning...
962  ShuffleRange(&random_, 0, 0, &vector_);
963  ASSERT_PRED1(VectorIsNotCorrupt, vector_);
964  ASSERT_PRED1(VectorIsUnshuffled, vector_);
965 
966  // ...in the middle...
967  ShuffleRange(&random_, kVectorSize/2, kVectorSize/2, &vector_);
968  ASSERT_PRED1(VectorIsNotCorrupt, vector_);
969  ASSERT_PRED1(VectorIsUnshuffled, vector_);
970 
971  // ...at the end...
972  ShuffleRange(&random_, kVectorSize - 1, kVectorSize - 1, &vector_);
973  ASSERT_PRED1(VectorIsNotCorrupt, vector_);
974  ASSERT_PRED1(VectorIsUnshuffled, vector_);
975 
976  // ...and past the end.
977  ShuffleRange(&random_, kVectorSize, kVectorSize, &vector_);
978  ASSERT_PRED1(VectorIsNotCorrupt, vector_);
979  ASSERT_PRED1(VectorIsUnshuffled, vector_);
980 }
981 
982 TEST_F(VectorShuffleTest, HandlesRangeOfSizeOne) {
983  // Tests a size one range at the beginning...
984  ShuffleRange(&random_, 0, 1, &vector_);
985  ASSERT_PRED1(VectorIsNotCorrupt, vector_);
986  ASSERT_PRED1(VectorIsUnshuffled, vector_);
987 
988  // ...in the middle...
989  ShuffleRange(&random_, kVectorSize/2, kVectorSize/2 + 1, &vector_);
990  ASSERT_PRED1(VectorIsNotCorrupt, vector_);
991  ASSERT_PRED1(VectorIsUnshuffled, vector_);
992 
993  // ...and at the end.
994  ShuffleRange(&random_, kVectorSize - 1, kVectorSize, &vector_);
995  ASSERT_PRED1(VectorIsNotCorrupt, vector_);
996  ASSERT_PRED1(VectorIsUnshuffled, vector_);
997 }
998 
999 // Because we use our own random number generator and a fixed seed,
1000 // we can guarantee that the following "random" tests will succeed.
1001 
1002 TEST_F(VectorShuffleTest, ShufflesEntireVector) {
1003  Shuffle(&random_, &vector_);
1004  ASSERT_PRED1(VectorIsNotCorrupt, vector_);
1005  EXPECT_FALSE(VectorIsUnshuffled(vector_)) << vector_;
1006 
1007  // Tests the first and last elements in particular to ensure that
1008  // there are no off-by-one problems in our shuffle algorithm.
1009  EXPECT_NE(0, vector_[0]);
1010  EXPECT_NE(static_cast<int>(kVectorSize - 1), vector_[kVectorSize - 1]);
1011 }
1012 
1013 TEST_F(VectorShuffleTest, ShufflesStartOfVector) {
1014  const int kRangeSize = kVectorSize/2;
1015 
1016  ShuffleRange(&random_, 0, kRangeSize, &vector_);
1017 
1018  ASSERT_PRED1(VectorIsNotCorrupt, vector_);
1019  EXPECT_PRED3(RangeIsShuffled, vector_, 0, kRangeSize);
1020  EXPECT_PRED3(RangeIsUnshuffled, vector_, kRangeSize,
1021  static_cast<int>(kVectorSize));
1022 }
1023 
1024 TEST_F(VectorShuffleTest, ShufflesEndOfVector) {
1025  const int kRangeSize = kVectorSize / 2;
1026  ShuffleRange(&random_, kRangeSize, kVectorSize, &vector_);
1027 
1028  ASSERT_PRED1(VectorIsNotCorrupt, vector_);
1029  EXPECT_PRED3(RangeIsUnshuffled, vector_, 0, kRangeSize);
1030  EXPECT_PRED3(RangeIsShuffled, vector_, kRangeSize,
1031  static_cast<int>(kVectorSize));
1032 }
1033 
1034 TEST_F(VectorShuffleTest, ShufflesMiddleOfVector) {
1035  const int kRangeSize = static_cast<int>(kVectorSize) / 3;
1036  ShuffleRange(&random_, kRangeSize, 2*kRangeSize, &vector_);
1037 
1038  ASSERT_PRED1(VectorIsNotCorrupt, vector_);
1039  EXPECT_PRED3(RangeIsUnshuffled, vector_, 0, kRangeSize);
1040  EXPECT_PRED3(RangeIsShuffled, vector_, kRangeSize, 2*kRangeSize);
1041  EXPECT_PRED3(RangeIsUnshuffled, vector_, 2 * kRangeSize,
1042  static_cast<int>(kVectorSize));
1043 }
1044 
1045 TEST_F(VectorShuffleTest, ShufflesRepeatably) {
1046  TestingVector vector2;
1047  for (size_t i = 0; i < kVectorSize; i++) {
1048  vector2.push_back(static_cast<int>(i));
1049  }
1050 
1051  random_.Reseed(1234);
1052  Shuffle(&random_, &vector_);
1053  random_.Reseed(1234);
1054  Shuffle(&random_, &vector2);
1055 
1056  ASSERT_PRED1(VectorIsNotCorrupt, vector_);
1057  ASSERT_PRED1(VectorIsNotCorrupt, vector2);
1058 
1059  for (size_t i = 0; i < kVectorSize; i++) {
1060  EXPECT_EQ(vector_[i], vector2[i]) << " where i is " << i;
1061  }
1062 }
1063 
1064 // Tests the size of the AssertHelper class.
1065 
1066 TEST(AssertHelperTest, AssertHelperIsSmall) {
1067  // To avoid breaking clients that use lots of assertions in one
1068  // function, we cannot grow the size of AssertHelper.
1069  EXPECT_LE(sizeof(testing::internal::AssertHelper), sizeof(void*));
1070 }
1071 
1072 // Tests String::EndsWithCaseInsensitive().
1073 TEST(StringTest, EndsWithCaseInsensitive) {
1074  EXPECT_TRUE(String::EndsWithCaseInsensitive("foobar", "BAR"));
1075  EXPECT_TRUE(String::EndsWithCaseInsensitive("foobaR", "bar"));
1076  EXPECT_TRUE(String::EndsWithCaseInsensitive("foobar", ""));
1077  EXPECT_TRUE(String::EndsWithCaseInsensitive("", ""));
1078 
1079  EXPECT_FALSE(String::EndsWithCaseInsensitive("Foobar", "foo"));
1080  EXPECT_FALSE(String::EndsWithCaseInsensitive("foobar", "Foo"));
1081  EXPECT_FALSE(String::EndsWithCaseInsensitive("", "foo"));
1082 }
1083 
1084 // C++Builder's preprocessor is buggy; it fails to expand macros that
1085 // appear in macro parameters after wide char literals. Provide an alias
1086 // for NULL as a workaround.
1087 static const wchar_t* const kNull = nullptr;
1088 
1089 // Tests String::CaseInsensitiveWideCStringEquals
1090 TEST(StringTest, CaseInsensitiveWideCStringEquals) {
1091  EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(nullptr, nullptr));
1092  EXPECT_FALSE(String::CaseInsensitiveWideCStringEquals(kNull, L""));
1093  EXPECT_FALSE(String::CaseInsensitiveWideCStringEquals(L"", kNull));
1094  EXPECT_FALSE(String::CaseInsensitiveWideCStringEquals(kNull, L"foobar"));
1095  EXPECT_FALSE(String::CaseInsensitiveWideCStringEquals(L"foobar", kNull));
1096  EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(L"foobar", L"foobar"));
1097  EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(L"foobar", L"FOOBAR"));
1098  EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(L"FOOBAR", L"foobar"));
1099 }
1100 
1101 #if GTEST_OS_WINDOWS
1102 
1103 // Tests String::ShowWideCString().
1104 TEST(StringTest, ShowWideCString) {
1105  EXPECT_STREQ("(null)",
1106  String::ShowWideCString(NULL).c_str());
1107  EXPECT_STREQ("", String::ShowWideCString(L"").c_str());
1108  EXPECT_STREQ("foo", String::ShowWideCString(L"foo").c_str());
1109 }
1110 
1111 # if GTEST_OS_WINDOWS_MOBILE
1112 TEST(StringTest, AnsiAndUtf16Null) {
1113  EXPECT_EQ(NULL, String::AnsiToUtf16(NULL));
1114  EXPECT_EQ(NULL, String::Utf16ToAnsi(NULL));
1115 }
1116 
1117 TEST(StringTest, AnsiAndUtf16ConvertBasic) {
1118  const char* ansi = String::Utf16ToAnsi(L"str");
1119  EXPECT_STREQ("str", ansi);
1120  delete [] ansi;
1121  const WCHAR* utf16 = String::AnsiToUtf16("str");
1122  EXPECT_EQ(0, wcsncmp(L"str", utf16, 3));
1123  delete [] utf16;
1124 }
1125 
1126 TEST(StringTest, AnsiAndUtf16ConvertPathChars) {
1127  const char* ansi = String::Utf16ToAnsi(L".:\\ \"*?");
1128  EXPECT_STREQ(".:\\ \"*?", ansi);
1129  delete [] ansi;
1130  const WCHAR* utf16 = String::AnsiToUtf16(".:\\ \"*?");
1131  EXPECT_EQ(0, wcsncmp(L".:\\ \"*?", utf16, 3));
1132  delete [] utf16;
1133 }
1134 # endif // GTEST_OS_WINDOWS_MOBILE
1135 
1136 #endif // GTEST_OS_WINDOWS
1137 
1138 // Tests TestProperty construction.
1139 TEST(TestPropertyTest, StringValue) {
1140  TestProperty property("key", "1");
1141  EXPECT_STREQ("key", property.key());
1142  EXPECT_STREQ("1", property.value());
1143 }
1144 
1145 // Tests TestProperty replacing a value.
1146 TEST(TestPropertyTest, ReplaceStringValue) {
1147  TestProperty property("key", "1");
1148  EXPECT_STREQ("1", property.value());
1149  property.SetValue("2");
1150  EXPECT_STREQ("2", property.value());
1151 }
1152 
1153 // AddFatalFailure() and AddNonfatalFailure() must be stand-alone
1154 // functions (i.e. their definitions cannot be inlined at the call
1155 // sites), or C++Builder won't compile the code.
1156 static void AddFatalFailure() {
1157  FAIL() << "Expected fatal failure.";
1158 }
1159 
1160 static void AddNonfatalFailure() {
1161  ADD_FAILURE() << "Expected non-fatal failure.";
1162 }
1163 
1164 class ScopedFakeTestPartResultReporterTest : public Test {
1165  public: // Must be public and not protected due to a bug in g++ 3.4.2.
1166  enum FailureMode {
1167  FATAL_FAILURE,
1168  NONFATAL_FAILURE
1169  };
1170  static void AddFailure(FailureMode failure) {
1171  if (failure == FATAL_FAILURE) {
1172  AddFatalFailure();
1173  } else {
1174  AddNonfatalFailure();
1175  }
1176  }
1177 };
1178 
1179 // Tests that ScopedFakeTestPartResultReporter intercepts test
1180 // failures.
1181 TEST_F(ScopedFakeTestPartResultReporterTest, InterceptsTestFailures) {
1183  {
1185  ScopedFakeTestPartResultReporter::INTERCEPT_ONLY_CURRENT_THREAD,
1186  &results);
1187  AddFailure(NONFATAL_FAILURE);
1188  AddFailure(FATAL_FAILURE);
1189  }
1190 
1191  EXPECT_EQ(2, results.size());
1192  EXPECT_TRUE(results.GetTestPartResult(0).nonfatally_failed());
1193  EXPECT_TRUE(results.GetTestPartResult(1).fatally_failed());
1194 }
1195 
1196 TEST_F(ScopedFakeTestPartResultReporterTest, DeprecatedConstructor) {
1198  {
1199  // Tests, that the deprecated constructor still works.
1201  AddFailure(NONFATAL_FAILURE);
1202  }
1203  EXPECT_EQ(1, results.size());
1204 }
1205 
1206 #if GTEST_IS_THREADSAFE
1207 
1208 class ScopedFakeTestPartResultReporterWithThreadsTest
1209  : public ScopedFakeTestPartResultReporterTest {
1210  protected:
1211  static void AddFailureInOtherThread(FailureMode failure) {
1212  ThreadWithParam<FailureMode> thread(&AddFailure, failure, nullptr);
1213  thread.Join();
1214  }
1215 };
1216 
1217 TEST_F(ScopedFakeTestPartResultReporterWithThreadsTest,
1218  InterceptsTestFailuresInAllThreads) {
1220  {
1222  ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS, &results);
1223  AddFailure(NONFATAL_FAILURE);
1224  AddFailure(FATAL_FAILURE);
1225  AddFailureInOtherThread(NONFATAL_FAILURE);
1226  AddFailureInOtherThread(FATAL_FAILURE);
1227  }
1228 
1229  EXPECT_EQ(4, results.size());
1230  EXPECT_TRUE(results.GetTestPartResult(0).nonfatally_failed());
1231  EXPECT_TRUE(results.GetTestPartResult(1).fatally_failed());
1232  EXPECT_TRUE(results.GetTestPartResult(2).nonfatally_failed());
1233  EXPECT_TRUE(results.GetTestPartResult(3).fatally_failed());
1234 }
1235 
1236 #endif // GTEST_IS_THREADSAFE
1237 
1238 // Tests EXPECT_FATAL_FAILURE{,ON_ALL_THREADS}. Makes sure that they
1239 // work even if the failure is generated in a called function rather than
1240 // the current context.
1241 
1242 typedef ScopedFakeTestPartResultReporterTest ExpectFatalFailureTest;
1243 
1244 TEST_F(ExpectFatalFailureTest, CatchesFatalFaliure) {
1245  EXPECT_FATAL_FAILURE(AddFatalFailure(), "Expected fatal failure.");
1246 }
1247 
1248 TEST_F(ExpectFatalFailureTest, AcceptsStdStringObject) {
1249  EXPECT_FATAL_FAILURE(AddFatalFailure(),
1250  ::std::string("Expected fatal failure."));
1251 }
1252 
1253 TEST_F(ExpectFatalFailureTest, CatchesFatalFailureOnAllThreads) {
1254  // We have another test below to verify that the macro catches fatal
1255  // failures generated on another thread.
1256  EXPECT_FATAL_FAILURE_ON_ALL_THREADS(AddFatalFailure(),
1257  "Expected fatal failure.");
1258 }
1259 
1260 #ifdef __BORLANDC__
1261 // Silences warnings: "Condition is always true"
1262 # pragma option push -w-ccc
1263 #endif
1264 
1265 // Tests that EXPECT_FATAL_FAILURE() can be used in a non-void
1266 // function even when the statement in it contains ASSERT_*.
1267 
1268 int NonVoidFunction() {
1269  EXPECT_FATAL_FAILURE(ASSERT_TRUE(false), "");
1271  return 0;
1272 }
1273 
1274 TEST_F(ExpectFatalFailureTest, CanBeUsedInNonVoidFunction) {
1275  NonVoidFunction();
1276 }
1277 
1278 // Tests that EXPECT_FATAL_FAILURE(statement, ...) doesn't abort the
1279 // current function even though 'statement' generates a fatal failure.
1280 
1281 void DoesNotAbortHelper(bool* aborted) {
1282  EXPECT_FATAL_FAILURE(ASSERT_TRUE(false), "");
1284 
1285  *aborted = false;
1286 }
1287 
1288 #ifdef __BORLANDC__
1289 // Restores warnings after previous "#pragma option push" suppressed them.
1290 # pragma option pop
1291 #endif
1292 
1293 TEST_F(ExpectFatalFailureTest, DoesNotAbort) {
1294  bool aborted = true;
1295  DoesNotAbortHelper(&aborted);
1296  EXPECT_FALSE(aborted);
1297 }
1298 
1299 // Tests that the EXPECT_FATAL_FAILURE{,_ON_ALL_THREADS} accepts a
1300 // statement that contains a macro which expands to code containing an
1301 // unprotected comma.
1302 
1303 static int global_var = 0;
1304 #define GTEST_USE_UNPROTECTED_COMMA_ global_var++, global_var++
1305 
1306 TEST_F(ExpectFatalFailureTest, AcceptsMacroThatExpandsToUnprotectedComma) {
1307 #ifndef __BORLANDC__
1308  // ICE's in C++Builder.
1311  AddFatalFailure();
1312  }, "");
1313 #endif
1314 
1317  AddFatalFailure();
1318  }, "");
1319 }
1320 
1321 // Tests EXPECT_NONFATAL_FAILURE{,ON_ALL_THREADS}.
1322 
1323 typedef ScopedFakeTestPartResultReporterTest ExpectNonfatalFailureTest;
1324 
1325 TEST_F(ExpectNonfatalFailureTest, CatchesNonfatalFailure) {
1326  EXPECT_NONFATAL_FAILURE(AddNonfatalFailure(),
1327  "Expected non-fatal failure.");
1328 }
1329 
1330 TEST_F(ExpectNonfatalFailureTest, AcceptsStdStringObject) {
1331  EXPECT_NONFATAL_FAILURE(AddNonfatalFailure(),
1332  ::std::string("Expected non-fatal failure."));
1333 }
1334 
1335 TEST_F(ExpectNonfatalFailureTest, CatchesNonfatalFailureOnAllThreads) {
1336  // We have another test below to verify that the macro catches
1337  // non-fatal failures generated on another thread.
1338  EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(AddNonfatalFailure(),
1339  "Expected non-fatal failure.");
1340 }
1341 
1342 // Tests that the EXPECT_NONFATAL_FAILURE{,_ON_ALL_THREADS} accepts a
1343 // statement that contains a macro which expands to code containing an
1344 // unprotected comma.
1345 TEST_F(ExpectNonfatalFailureTest, AcceptsMacroThatExpandsToUnprotectedComma) {
1348  AddNonfatalFailure();
1349  }, "");
1350 
1353  AddNonfatalFailure();
1354  }, "");
1355 }
1356 
1357 #if GTEST_IS_THREADSAFE
1358 
1359 typedef ScopedFakeTestPartResultReporterWithThreadsTest
1360  ExpectFailureWithThreadsTest;
1361 
1362 TEST_F(ExpectFailureWithThreadsTest, ExpectFatalFailureOnAllThreads) {
1363  EXPECT_FATAL_FAILURE_ON_ALL_THREADS(AddFailureInOtherThread(FATAL_FAILURE),
1364  "Expected fatal failure.");
1365 }
1366 
1367 TEST_F(ExpectFailureWithThreadsTest, ExpectNonFatalFailureOnAllThreads) {
1369  AddFailureInOtherThread(NONFATAL_FAILURE), "Expected non-fatal failure.");
1370 }
1371 
1372 #endif // GTEST_IS_THREADSAFE
1373 
1374 // Tests the TestProperty class.
1375 
1376 TEST(TestPropertyTest, ConstructorWorks) {
1377  const TestProperty property("key", "value");
1378  EXPECT_STREQ("key", property.key());
1379  EXPECT_STREQ("value", property.value());
1380 }
1381 
1382 TEST(TestPropertyTest, SetValue) {
1383  TestProperty property("key", "value_1");
1384  EXPECT_STREQ("key", property.key());
1385  property.SetValue("value_2");
1386  EXPECT_STREQ("key", property.key());
1387  EXPECT_STREQ("value_2", property.value());
1388 }
1389 
1390 // Tests the TestResult class
1391 
1392 // The test fixture for testing TestResult.
1393 class TestResultTest : public Test {
1394  protected:
1395  typedef std::vector<TestPartResult> TPRVector;
1396 
1397  // We make use of 2 TestPartResult objects,
1398  TestPartResult * pr1, * pr2;
1399 
1400  // ... and 3 TestResult objects.
1401  TestResult * r0, * r1, * r2;
1402 
1403  void SetUp() override {
1404  // pr1 is for success.
1405  pr1 = new TestPartResult(TestPartResult::kSuccess,
1406  "foo/bar.cc",
1407  10,
1408  "Success!");
1409 
1410  // pr2 is for fatal failure.
1411  pr2 = new TestPartResult(TestPartResult::kFatalFailure,
1412  "foo/bar.cc",
1413  -1, // This line number means "unknown"
1414  "Failure!");
1415 
1416  // Creates the TestResult objects.
1417  r0 = new TestResult();
1418  r1 = new TestResult();
1419  r2 = new TestResult();
1420 
1421  // In order to test TestResult, we need to modify its internal
1422  // state, in particular the TestPartResult vector it holds.
1423  // test_part_results() returns a const reference to this vector.
1424  // We cast it to a non-const object s.t. it can be modified
1425  TPRVector* results1 = const_cast<TPRVector*>(
1426  &TestResultAccessor::test_part_results(*r1));
1427  TPRVector* results2 = const_cast<TPRVector*>(
1428  &TestResultAccessor::test_part_results(*r2));
1429 
1430  // r0 is an empty TestResult.
1431 
1432  // r1 contains a single SUCCESS TestPartResult.
1433  results1->push_back(*pr1);
1434 
1435  // r2 contains a SUCCESS, and a FAILURE.
1436  results2->push_back(*pr1);
1437  results2->push_back(*pr2);
1438  }
1439 
1440  void TearDown() override {
1441  delete pr1;
1442  delete pr2;
1443 
1444  delete r0;
1445  delete r1;
1446  delete r2;
1447  }
1448 
1449  // Helper that compares two TestPartResults.
1450  static void CompareTestPartResult(const TestPartResult& expected,
1451  const TestPartResult& actual) {
1452  EXPECT_EQ(expected.type(), actual.type());
1453  EXPECT_STREQ(expected.file_name(), actual.file_name());
1454  EXPECT_EQ(expected.line_number(), actual.line_number());
1455  EXPECT_STREQ(expected.summary(), actual.summary());
1456  EXPECT_STREQ(expected.message(), actual.message());
1457  EXPECT_EQ(expected.passed(), actual.passed());
1458  EXPECT_EQ(expected.failed(), actual.failed());
1459  EXPECT_EQ(expected.nonfatally_failed(), actual.nonfatally_failed());
1460  EXPECT_EQ(expected.fatally_failed(), actual.fatally_failed());
1461  }
1462 };
1463 
1464 // Tests TestResult::total_part_count().
1465 TEST_F(TestResultTest, total_part_count) {
1466  ASSERT_EQ(0, r0->total_part_count());
1467  ASSERT_EQ(1, r1->total_part_count());
1468  ASSERT_EQ(2, r2->total_part_count());
1469 }
1470 
1471 // Tests TestResult::Passed().
1472 TEST_F(TestResultTest, Passed) {
1473  ASSERT_TRUE(r0->Passed());
1474  ASSERT_TRUE(r1->Passed());
1475  ASSERT_FALSE(r2->Passed());
1476 }
1477 
1478 // Tests TestResult::Failed().
1479 TEST_F(TestResultTest, Failed) {
1480  ASSERT_FALSE(r0->Failed());
1481  ASSERT_FALSE(r1->Failed());
1482  ASSERT_TRUE(r2->Failed());
1483 }
1484 
1485 // Tests TestResult::GetTestPartResult().
1486 
1487 typedef TestResultTest TestResultDeathTest;
1488 
1489 TEST_F(TestResultDeathTest, GetTestPartResult) {
1490  CompareTestPartResult(*pr1, r2->GetTestPartResult(0));
1491  CompareTestPartResult(*pr2, r2->GetTestPartResult(1));
1494 }
1495 
1496 // Tests TestResult has no properties when none are added.
1497 TEST(TestResultPropertyTest, NoPropertiesFoundWhenNoneAreAdded) {
1499  ASSERT_EQ(0, test_result.test_property_count());
1500 }
1501 
1502 // Tests TestResult has the expected property when added.
1503 TEST(TestResultPropertyTest, OnePropertyFoundWhenAdded) {
1505  TestProperty property("key_1", "1");
1506  TestResultAccessor::RecordProperty(&test_result, "testcase", property);
1507  ASSERT_EQ(1, test_result.test_property_count());
1508  const TestProperty& actual_property = test_result.GetTestProperty(0);
1509  EXPECT_STREQ("key_1", actual_property.key());
1510  EXPECT_STREQ("1", actual_property.value());
1511 }
1512 
1513 // Tests TestResult has multiple properties when added.
1514 TEST(TestResultPropertyTest, MultiplePropertiesFoundWhenAdded) {
1516  TestProperty property_1("key_1", "1");
1517  TestProperty property_2("key_2", "2");
1518  TestResultAccessor::RecordProperty(&test_result, "testcase", property_1);
1519  TestResultAccessor::RecordProperty(&test_result, "testcase", property_2);
1520  ASSERT_EQ(2, test_result.test_property_count());
1521  const TestProperty& actual_property_1 = test_result.GetTestProperty(0);
1522  EXPECT_STREQ("key_1", actual_property_1.key());
1523  EXPECT_STREQ("1", actual_property_1.value());
1524 
1525  const TestProperty& actual_property_2 = test_result.GetTestProperty(1);
1526  EXPECT_STREQ("key_2", actual_property_2.key());
1527  EXPECT_STREQ("2", actual_property_2.value());
1528 }
1529 
1530 // Tests TestResult::RecordProperty() overrides values for duplicate keys.
1531 TEST(TestResultPropertyTest, OverridesValuesForDuplicateKeys) {
1533  TestProperty property_1_1("key_1", "1");
1534  TestProperty property_2_1("key_2", "2");
1535  TestProperty property_1_2("key_1", "12");
1536  TestProperty property_2_2("key_2", "22");
1537  TestResultAccessor::RecordProperty(&test_result, "testcase", property_1_1);
1538  TestResultAccessor::RecordProperty(&test_result, "testcase", property_2_1);
1539  TestResultAccessor::RecordProperty(&test_result, "testcase", property_1_2);
1540  TestResultAccessor::RecordProperty(&test_result, "testcase", property_2_2);
1541 
1542  ASSERT_EQ(2, test_result.test_property_count());
1543  const TestProperty& actual_property_1 = test_result.GetTestProperty(0);
1544  EXPECT_STREQ("key_1", actual_property_1.key());
1545  EXPECT_STREQ("12", actual_property_1.value());
1546 
1547  const TestProperty& actual_property_2 = test_result.GetTestProperty(1);
1548  EXPECT_STREQ("key_2", actual_property_2.key());
1549  EXPECT_STREQ("22", actual_property_2.value());
1550 }
1551 
1552 // Tests TestResult::GetTestProperty().
1553 TEST(TestResultPropertyTest, GetTestProperty) {
1555  TestProperty property_1("key_1", "1");
1556  TestProperty property_2("key_2", "2");
1557  TestProperty property_3("key_3", "3");
1558  TestResultAccessor::RecordProperty(&test_result, "testcase", property_1);
1559  TestResultAccessor::RecordProperty(&test_result, "testcase", property_2);
1560  TestResultAccessor::RecordProperty(&test_result, "testcase", property_3);
1561 
1562  const TestProperty& fetched_property_1 = test_result.GetTestProperty(0);
1563  const TestProperty& fetched_property_2 = test_result.GetTestProperty(1);
1564  const TestProperty& fetched_property_3 = test_result.GetTestProperty(2);
1565 
1566  EXPECT_STREQ("key_1", fetched_property_1.key());
1567  EXPECT_STREQ("1", fetched_property_1.value());
1568 
1569  EXPECT_STREQ("key_2", fetched_property_2.key());
1570  EXPECT_STREQ("2", fetched_property_2.value());
1571 
1572  EXPECT_STREQ("key_3", fetched_property_3.key());
1573  EXPECT_STREQ("3", fetched_property_3.value());
1574 
1575  EXPECT_DEATH_IF_SUPPORTED(test_result.GetTestProperty(3), "");
1576  EXPECT_DEATH_IF_SUPPORTED(test_result.GetTestProperty(-1), "");
1577 }
1578 
1579 // Tests the Test class.
1580 //
1581 // It's difficult to test every public method of this class (we are
1582 // already stretching the limit of Google Test by using it to test itself!).
1583 // Fortunately, we don't have to do that, as we are already testing
1584 // the functionalities of the Test class extensively by using Google Test
1585 // alone.
1586 //
1587 // Therefore, this section only contains one test.
1588 
1589 // Tests that GTestFlagSaver works on Windows and Mac.
1590 
1591 class GTestFlagSaverTest : public Test {
1592  protected:
1593  // Saves the Google Test flags such that we can restore them later, and
1594  // then sets them to their default values. This will be called
1595  // before the first test in this test case is run.
1596  static void SetUpTestSuite() {
1597  saver_ = new GTestFlagSaver;
1598 
1599  GTEST_FLAG(also_run_disabled_tests) = false;
1600  GTEST_FLAG(break_on_failure) = false;
1601  GTEST_FLAG(catch_exceptions) = false;
1602  GTEST_FLAG(death_test_use_fork) = false;
1603  GTEST_FLAG(color) = "auto";
1604  GTEST_FLAG(filter) = "";
1605  GTEST_FLAG(list_tests) = false;
1606  GTEST_FLAG(output) = "";
1607  GTEST_FLAG(print_time) = true;
1608  GTEST_FLAG(random_seed) = 0;
1609  GTEST_FLAG(repeat) = 1;
1610  GTEST_FLAG(shuffle) = false;
1611  GTEST_FLAG(stack_trace_depth) = kMaxStackTraceDepth;
1612  GTEST_FLAG(stream_result_to) = "";
1613  GTEST_FLAG(throw_on_failure) = false;
1614  }
1615 
1616  // Restores the Google Test flags that the tests have modified. This will
1617  // be called after the last test in this test case is run.
1618  static void TearDownTestSuite() {
1619  delete saver_;
1620  saver_ = nullptr;
1621  }
1622 
1623  // Verifies that the Google Test flags have their default values, and then
1624  // modifies each of them.
1625  void VerifyAndModifyFlags() {
1626  EXPECT_FALSE(GTEST_FLAG(also_run_disabled_tests));
1627  EXPECT_FALSE(GTEST_FLAG(break_on_failure));
1628  EXPECT_FALSE(GTEST_FLAG(catch_exceptions));
1629  EXPECT_STREQ("auto", GTEST_FLAG(color).c_str());
1630  EXPECT_FALSE(GTEST_FLAG(death_test_use_fork));
1631  EXPECT_STREQ("", GTEST_FLAG(filter).c_str());
1632  EXPECT_FALSE(GTEST_FLAG(list_tests));
1634  EXPECT_TRUE(GTEST_FLAG(print_time));
1635  EXPECT_EQ(0, GTEST_FLAG(random_seed));
1636  EXPECT_EQ(1, GTEST_FLAG(repeat));
1637  EXPECT_FALSE(GTEST_FLAG(shuffle));
1638  EXPECT_EQ(kMaxStackTraceDepth, GTEST_FLAG(stack_trace_depth));
1639  EXPECT_STREQ("", GTEST_FLAG(stream_result_to).c_str());
1640  EXPECT_FALSE(GTEST_FLAG(throw_on_failure));
1641 
1642  GTEST_FLAG(also_run_disabled_tests) = true;
1643  GTEST_FLAG(break_on_failure) = true;
1644  GTEST_FLAG(catch_exceptions) = true;
1645  GTEST_FLAG(color) = "no";
1646  GTEST_FLAG(death_test_use_fork) = true;
1647  GTEST_FLAG(filter) = "abc";
1648  GTEST_FLAG(list_tests) = true;
1649  GTEST_FLAG(output) = "xml:foo.xml";
1650  GTEST_FLAG(print_time) = false;
1651  GTEST_FLAG(random_seed) = 1;
1652  GTEST_FLAG(repeat) = 100;
1653  GTEST_FLAG(shuffle) = true;
1654  GTEST_FLAG(stack_trace_depth) = 1;
1655  GTEST_FLAG(stream_result_to) = "localhost:1234";
1656  GTEST_FLAG(throw_on_failure) = true;
1657  }
1658 
1659  private:
1660  // For saving Google Test flags during this test case.
1661  static GTestFlagSaver* saver_;
1662 };
1663 
1664 GTestFlagSaver* GTestFlagSaverTest::saver_ = nullptr;
1665 
1666 // Google Test doesn't guarantee the order of tests. The following two
1667 // tests are designed to work regardless of their order.
1668 
1669 // Modifies the Google Test flags in the test body.
1670 TEST_F(GTestFlagSaverTest, ModifyGTestFlags) {
1671  VerifyAndModifyFlags();
1672 }
1673 
1674 // Verifies that the Google Test flags in the body of the previous test were
1675 // restored to their original values.
1676 TEST_F(GTestFlagSaverTest, VerifyGTestFlags) {
1677  VerifyAndModifyFlags();
1678 }
1679 
1680 // Sets an environment variable with the given name to the given
1681 // value. If the value argument is "", unsets the environment
1682 // variable. The caller must ensure that both arguments are not NULL.
1683 static void SetEnv(const char* name, const char* value) {
1684 #if GTEST_OS_WINDOWS_MOBILE
1685  // Environment variables are not supported on Windows CE.
1686  return;
1687 #elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9)
1688  // C++Builder's putenv only stores a pointer to its parameter; we have to
1689  // ensure that the string remains valid as long as it might be needed.
1690  // We use an std::map to do so.
1691  static std::map<std::string, std::string*> added_env;
1692 
1693  // Because putenv stores a pointer to the string buffer, we can't delete the
1694  // previous string (if present) until after it's replaced.
1695  std::string *prev_env = NULL;
1696  if (added_env.find(name) != added_env.end()) {
1697  prev_env = added_env[name];
1698  }
1699  added_env[name] = new std::string(
1700  (Message() << name << "=" << value).GetString());
1701 
1702  // The standard signature of putenv accepts a 'char*' argument. Other
1703  // implementations, like C++Builder's, accept a 'const char*'.
1704  // We cast away the 'const' since that would work for both variants.
1705  putenv(const_cast<char*>(added_env[name]->c_str()));
1706  delete prev_env;
1707 #elif GTEST_OS_WINDOWS // If we are on Windows proper.
1708  _putenv((Message() << name << "=" << value).GetString().c_str());
1709 #else
1710  if (*value == '\0') {
1711  unsetenv(name);
1712  } else {
1713  setenv(name, value, 1);
1714  }
1715 #endif // GTEST_OS_WINDOWS_MOBILE
1716 }
1717 
1718 #if !GTEST_OS_WINDOWS_MOBILE
1719 // Environment variables are not supported on Windows CE.
1720 
1722 
1723 // Tests Int32FromGTestEnv().
1724 
1725 // Tests that Int32FromGTestEnv() returns the default value when the
1726 // environment variable is not set.
1727 TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenVariableIsNotSet) {
1728  SetEnv(GTEST_FLAG_PREFIX_UPPER_ "TEMP", "");
1729  EXPECT_EQ(10, Int32FromGTestEnv("temp", 10));
1730 }
1731 
1732 # if !defined(GTEST_GET_INT32_FROM_ENV_)
1733 
1734 // Tests that Int32FromGTestEnv() returns the default value when the
1735 // environment variable overflows as an Int32.
1736 TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenValueOverflows) {
1737  printf("(expecting 2 warnings)\n");
1738 
1739  SetEnv(GTEST_FLAG_PREFIX_UPPER_ "TEMP", "12345678987654321");
1740  EXPECT_EQ(20, Int32FromGTestEnv("temp", 20));
1741 
1742  SetEnv(GTEST_FLAG_PREFIX_UPPER_ "TEMP", "-12345678987654321");
1743  EXPECT_EQ(30, Int32FromGTestEnv("temp", 30));
1744 }
1745 
1746 // Tests that Int32FromGTestEnv() returns the default value when the
1747 // environment variable does not represent a valid decimal integer.
1748 TEST(Int32FromGTestEnvTest, ReturnsDefaultWhenValueIsInvalid) {
1749  printf("(expecting 2 warnings)\n");
1750 
1751  SetEnv(GTEST_FLAG_PREFIX_UPPER_ "TEMP", "A1");
1752  EXPECT_EQ(40, Int32FromGTestEnv("temp", 40));
1753 
1754  SetEnv(GTEST_FLAG_PREFIX_UPPER_ "TEMP", "12X");
1755  EXPECT_EQ(50, Int32FromGTestEnv("temp", 50));
1756 }
1757 
1758 # endif // !defined(GTEST_GET_INT32_FROM_ENV_)
1759 
1760 // Tests that Int32FromGTestEnv() parses and returns the value of the
1761 // environment variable when it represents a valid decimal integer in
1762 // the range of an Int32.
1763 TEST(Int32FromGTestEnvTest, ParsesAndReturnsValidValue) {
1764  SetEnv(GTEST_FLAG_PREFIX_UPPER_ "TEMP", "123");
1765  EXPECT_EQ(123, Int32FromGTestEnv("temp", 0));
1766 
1767  SetEnv(GTEST_FLAG_PREFIX_UPPER_ "TEMP", "-321");
1768  EXPECT_EQ(-321, Int32FromGTestEnv("temp", 0));
1769 }
1770 #endif // !GTEST_OS_WINDOWS_MOBILE
1771 
1772 // Tests ParseInt32Flag().
1773 
1774 // Tests that ParseInt32Flag() returns false and doesn't change the
1775 // output value when the flag has wrong format
1776 TEST(ParseInt32FlagTest, ReturnsFalseForInvalidFlag) {
1777  Int32 value = 123;
1778  EXPECT_FALSE(ParseInt32Flag("--a=100", "b", &value));
1779  EXPECT_EQ(123, value);
1780 
1781  EXPECT_FALSE(ParseInt32Flag("a=100", "a", &value));
1782  EXPECT_EQ(123, value);
1783 }
1784 
1785 // Tests that ParseInt32Flag() returns false and doesn't change the
1786 // output value when the flag overflows as an Int32.
1787 TEST(ParseInt32FlagTest, ReturnsDefaultWhenValueOverflows) {
1788  printf("(expecting 2 warnings)\n");
1789 
1790  Int32 value = 123;
1791  EXPECT_FALSE(ParseInt32Flag("--abc=12345678987654321", "abc", &value));
1792  EXPECT_EQ(123, value);
1793 
1794  EXPECT_FALSE(ParseInt32Flag("--abc=-12345678987654321", "abc", &value));
1795  EXPECT_EQ(123, value);
1796 }
1797 
1798 // Tests that ParseInt32Flag() returns false and doesn't change the
1799 // output value when the flag does not represent a valid decimal
1800 // integer.
1801 TEST(ParseInt32FlagTest, ReturnsDefaultWhenValueIsInvalid) {
1802  printf("(expecting 2 warnings)\n");
1803 
1804  Int32 value = 123;
1805  EXPECT_FALSE(ParseInt32Flag("--abc=A1", "abc", &value));
1806  EXPECT_EQ(123, value);
1807 
1808  EXPECT_FALSE(ParseInt32Flag("--abc=12X", "abc", &value));
1809  EXPECT_EQ(123, value);
1810 }
1811 
1812 // Tests that ParseInt32Flag() parses the value of the flag and
1813 // returns true when the flag represents a valid decimal integer in
1814 // the range of an Int32.
1815 TEST(ParseInt32FlagTest, ParsesAndReturnsValidValue) {
1816  Int32 value = 123;
1817  EXPECT_TRUE(ParseInt32Flag("--" GTEST_FLAG_PREFIX_ "abc=456", "abc", &value));
1818  EXPECT_EQ(456, value);
1819 
1821  "abc", &value));
1822  EXPECT_EQ(-789, value);
1823 }
1824 
1825 // Tests that Int32FromEnvOrDie() parses the value of the var or
1826 // returns the correct default.
1827 // Environment variables are not supported on Windows CE.
1828 #if !GTEST_OS_WINDOWS_MOBILE
1829 TEST(Int32FromEnvOrDieTest, ParsesAndReturnsValidValue) {
1830  EXPECT_EQ(333, Int32FromEnvOrDie(GTEST_FLAG_PREFIX_UPPER_ "UnsetVar", 333));
1831  SetEnv(GTEST_FLAG_PREFIX_UPPER_ "UnsetVar", "123");
1832  EXPECT_EQ(123, Int32FromEnvOrDie(GTEST_FLAG_PREFIX_UPPER_ "UnsetVar", 333));
1833  SetEnv(GTEST_FLAG_PREFIX_UPPER_ "UnsetVar", "-123");
1834  EXPECT_EQ(-123, Int32FromEnvOrDie(GTEST_FLAG_PREFIX_UPPER_ "UnsetVar", 333));
1835 }
1836 #endif // !GTEST_OS_WINDOWS_MOBILE
1837 
1838 // Tests that Int32FromEnvOrDie() aborts with an error message
1839 // if the variable is not an Int32.
1840 TEST(Int32FromEnvOrDieDeathTest, AbortsOnFailure) {
1841  SetEnv(GTEST_FLAG_PREFIX_UPPER_ "VAR", "xxx");
1844  ".*");
1845 }
1846 
1847 // Tests that Int32FromEnvOrDie() aborts with an error message
1848 // if the variable cannot be represented by an Int32.
1849 TEST(Int32FromEnvOrDieDeathTest, AbortsOnInt32Overflow) {
1850  SetEnv(GTEST_FLAG_PREFIX_UPPER_ "VAR", "1234567891234567891234");
1853  ".*");
1854 }
1855 
1856 // Tests that ShouldRunTestOnShard() selects all tests
1857 // where there is 1 shard.
1858 TEST(ShouldRunTestOnShardTest, IsPartitionWhenThereIsOneShard) {
1864 }
1865 
1866 class ShouldShardTest : public testing::Test {
1867  protected:
1868  void SetUp() override {
1869  index_var_ = GTEST_FLAG_PREFIX_UPPER_ "INDEX";
1870  total_var_ = GTEST_FLAG_PREFIX_UPPER_ "TOTAL";
1871  }
1872 
1873  void TearDown() override {
1874  SetEnv(index_var_, "");
1875  SetEnv(total_var_, "");
1876  }
1877 
1878  const char* index_var_;
1879  const char* total_var_;
1880 };
1881 
1882 // Tests that sharding is disabled if neither of the environment variables
1883 // are set.
1884 TEST_F(ShouldShardTest, ReturnsFalseWhenNeitherEnvVarIsSet) {
1885  SetEnv(index_var_, "");
1886  SetEnv(total_var_, "");
1887 
1888  EXPECT_FALSE(ShouldShard(total_var_, index_var_, false));
1889  EXPECT_FALSE(ShouldShard(total_var_, index_var_, true));
1890 }
1891 
1892 // Tests that sharding is not enabled if total_shards == 1.
1893 TEST_F(ShouldShardTest, ReturnsFalseWhenTotalShardIsOne) {
1894  SetEnv(index_var_, "0");
1895  SetEnv(total_var_, "1");
1896  EXPECT_FALSE(ShouldShard(total_var_, index_var_, false));
1897  EXPECT_FALSE(ShouldShard(total_var_, index_var_, true));
1898 }
1899 
1900 // Tests that sharding is enabled if total_shards > 1 and
1901 // we are not in a death test subprocess.
1902 // Environment variables are not supported on Windows CE.
1903 #if !GTEST_OS_WINDOWS_MOBILE
1904 TEST_F(ShouldShardTest, WorksWhenShardEnvVarsAreValid) {
1905  SetEnv(index_var_, "4");
1906  SetEnv(total_var_, "22");
1907  EXPECT_TRUE(ShouldShard(total_var_, index_var_, false));
1908  EXPECT_FALSE(ShouldShard(total_var_, index_var_, true));
1909 
1910  SetEnv(index_var_, "8");
1911  SetEnv(total_var_, "9");
1912  EXPECT_TRUE(ShouldShard(total_var_, index_var_, false));
1913  EXPECT_FALSE(ShouldShard(total_var_, index_var_, true));
1914 
1915  SetEnv(index_var_, "0");
1916  SetEnv(total_var_, "9");
1917  EXPECT_TRUE(ShouldShard(total_var_, index_var_, false));
1918  EXPECT_FALSE(ShouldShard(total_var_, index_var_, true));
1919 }
1920 #endif // !GTEST_OS_WINDOWS_MOBILE
1921 
1922 // Tests that we exit in error if the sharding values are not valid.
1923 
1924 typedef ShouldShardTest ShouldShardDeathTest;
1925 
1926 TEST_F(ShouldShardDeathTest, AbortsWhenShardingEnvVarsAreInvalid) {
1927  SetEnv(index_var_, "4");
1928  SetEnv(total_var_, "4");
1929  EXPECT_DEATH_IF_SUPPORTED(ShouldShard(total_var_, index_var_, false), ".*");
1930 
1931  SetEnv(index_var_, "4");
1932  SetEnv(total_var_, "-2");
1933  EXPECT_DEATH_IF_SUPPORTED(ShouldShard(total_var_, index_var_, false), ".*");
1934 
1935  SetEnv(index_var_, "5");
1936  SetEnv(total_var_, "");
1937  EXPECT_DEATH_IF_SUPPORTED(ShouldShard(total_var_, index_var_, false), ".*");
1938 
1939  SetEnv(index_var_, "");
1940  SetEnv(total_var_, "5");
1941  EXPECT_DEATH_IF_SUPPORTED(ShouldShard(total_var_, index_var_, false), ".*");
1942 }
1943 
1944 // Tests that ShouldRunTestOnShard is a partition when 5
1945 // shards are used.
1946 TEST(ShouldRunTestOnShardTest, IsPartitionWhenThereAreFiveShards) {
1947  // Choose an arbitrary number of tests and shards.
1948  const int num_tests = 17;
1949  const int num_shards = 5;
1950 
1951  // Check partitioning: each test should be on exactly 1 shard.
1952  for (int test_id = 0; test_id < num_tests; test_id++) {
1953  int prev_selected_shard_index = -1;
1954  for (int shard_index = 0; shard_index < num_shards; shard_index++) {
1955  if (ShouldRunTestOnShard(num_shards, shard_index, test_id)) {
1956  if (prev_selected_shard_index < 0) {
1957  prev_selected_shard_index = shard_index;
1958  } else {
1959  ADD_FAILURE() << "Shard " << prev_selected_shard_index << " and "
1960  << shard_index << " are both selected to run test " << test_id;
1961  }
1962  }
1963  }
1964  }
1965 
1966  // Check balance: This is not required by the sharding protocol, but is a
1967  // desirable property for performance.
1968  for (int shard_index = 0; shard_index < num_shards; shard_index++) {
1969  int num_tests_on_shard = 0;
1970  for (int test_id = 0; test_id < num_tests; test_id++) {
1971  num_tests_on_shard +=
1972  ShouldRunTestOnShard(num_shards, shard_index, test_id);
1973  }
1974  EXPECT_GE(num_tests_on_shard, num_tests / num_shards);
1975  }
1976 }
1977 
1978 // For the same reason we are not explicitly testing everything in the
1979 // Test class, there are no separate tests for the following classes
1980 // (except for some trivial cases):
1981 //
1982 // TestSuite, UnitTest, UnitTestResultPrinter.
1983 //
1984 // Similarly, there are no separate tests for the following macros:
1985 //
1986 // TEST, TEST_F, RUN_ALL_TESTS
1987 
1988 TEST(UnitTestTest, CanGetOriginalWorkingDir) {
1989  ASSERT_TRUE(UnitTest::GetInstance()->original_working_dir() != nullptr);
1990  EXPECT_STRNE(UnitTest::GetInstance()->original_working_dir(), "");
1991 }
1992 
1993 TEST(UnitTestTest, ReturnsPlausibleTimestamp) {
1994  EXPECT_LT(0, UnitTest::GetInstance()->start_timestamp());
1995  EXPECT_LE(UnitTest::GetInstance()->start_timestamp(), GetTimeInMillis());
1996 }
1997 
1998 // When a property using a reserved key is supplied to this function, it
1999 // tests that a non-fatal failure is added, a fatal failure is not added,
2000 // and that the property is not recorded.
2001 void ExpectNonFatalFailureRecordingPropertyWithReservedKey(
2002  const TestResult& test_result, const char* key) {
2003  EXPECT_NONFATAL_FAILURE(Test::RecordProperty(key, "1"), "Reserved key");
2004  ASSERT_EQ(0, test_result.test_property_count()) << "Property for key '" << key
2005  << "' recorded unexpectedly.";
2006 }
2007 
2008 void ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2009  const char* key) {
2010  const TestInfo* test_info = UnitTest::GetInstance()->current_test_info();
2011  ASSERT_TRUE(test_info != nullptr);
2012  ExpectNonFatalFailureRecordingPropertyWithReservedKey(*test_info->result(),
2013  key);
2014 }
2015 
2016 void ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2017  const char* key) {
2019  UnitTest::GetInstance()->current_test_suite();
2020  ASSERT_TRUE(test_suite != nullptr);
2021  ExpectNonFatalFailureRecordingPropertyWithReservedKey(
2022  test_suite->ad_hoc_test_result(), key);
2023 }
2024 
2025 void ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2026  const char* key) {
2027  ExpectNonFatalFailureRecordingPropertyWithReservedKey(
2028  UnitTest::GetInstance()->ad_hoc_test_result(), key);
2029 }
2030 
2031 // Tests that property recording functions in UnitTest outside of tests
2032 // functions correcly. Creating a separate instance of UnitTest ensures it
2033 // is in a state similar to the UnitTest's singleton's between tests.
2034 class UnitTestRecordPropertyTest :
2036  public:
2037  static void SetUpTestSuite() {
2038  ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2039  "disabled");
2040  ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2041  "errors");
2042  ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2043  "failures");
2044  ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2045  "name");
2046  ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2047  "tests");
2048  ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestSuite(
2049  "time");
2050 
2051  Test::RecordProperty("test_case_key_1", "1");
2052 
2054  UnitTest::GetInstance()->current_test_suite();
2055 
2056  ASSERT_TRUE(test_suite != nullptr);
2057 
2058  ASSERT_EQ(1, test_suite->ad_hoc_test_result().test_property_count());
2059  EXPECT_STREQ("test_case_key_1",
2060  test_suite->ad_hoc_test_result().GetTestProperty(0).key());
2061  EXPECT_STREQ("1",
2062  test_suite->ad_hoc_test_result().GetTestProperty(0).value());
2063  }
2064 };
2065 
2066 // Tests TestResult has the expected property when added.
2067 TEST_F(UnitTestRecordPropertyTest, OnePropertyFoundWhenAdded) {
2068  UnitTestRecordProperty("key_1", "1");
2069 
2070  ASSERT_EQ(1, unit_test_.ad_hoc_test_result().test_property_count());
2071 
2072  EXPECT_STREQ("key_1",
2073  unit_test_.ad_hoc_test_result().GetTestProperty(0).key());
2074  EXPECT_STREQ("1",
2075  unit_test_.ad_hoc_test_result().GetTestProperty(0).value());
2076 }
2077 
2078 // Tests TestResult has multiple properties when added.
2079 TEST_F(UnitTestRecordPropertyTest, MultiplePropertiesFoundWhenAdded) {
2080  UnitTestRecordProperty("key_1", "1");
2081  UnitTestRecordProperty("key_2", "2");
2082 
2083  ASSERT_EQ(2, unit_test_.ad_hoc_test_result().test_property_count());
2084 
2085  EXPECT_STREQ("key_1",
2086  unit_test_.ad_hoc_test_result().GetTestProperty(0).key());
2087  EXPECT_STREQ("1", unit_test_.ad_hoc_test_result().GetTestProperty(0).value());
2088 
2089  EXPECT_STREQ("key_2",
2090  unit_test_.ad_hoc_test_result().GetTestProperty(1).key());
2091  EXPECT_STREQ("2", unit_test_.ad_hoc_test_result().GetTestProperty(1).value());
2092 }
2093 
2094 // Tests TestResult::RecordProperty() overrides values for duplicate keys.
2095 TEST_F(UnitTestRecordPropertyTest, OverridesValuesForDuplicateKeys) {
2096  UnitTestRecordProperty("key_1", "1");
2097  UnitTestRecordProperty("key_2", "2");
2098  UnitTestRecordProperty("key_1", "12");
2099  UnitTestRecordProperty("key_2", "22");
2100 
2101  ASSERT_EQ(2, unit_test_.ad_hoc_test_result().test_property_count());
2102 
2103  EXPECT_STREQ("key_1",
2104  unit_test_.ad_hoc_test_result().GetTestProperty(0).key());
2105  EXPECT_STREQ("12",
2106  unit_test_.ad_hoc_test_result().GetTestProperty(0).value());
2107 
2108  EXPECT_STREQ("key_2",
2109  unit_test_.ad_hoc_test_result().GetTestProperty(1).key());
2110  EXPECT_STREQ("22",
2111  unit_test_.ad_hoc_test_result().GetTestProperty(1).value());
2112 }
2113 
2114 TEST_F(UnitTestRecordPropertyTest,
2115  AddFailureInsideTestsWhenUsingTestSuiteReservedKeys) {
2116  ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2117  "name");
2118  ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2119  "value_param");
2120  ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2121  "type_param");
2122  ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2123  "status");
2124  ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2125  "time");
2126  ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest(
2127  "classname");
2128 }
2129 
2130 TEST_F(UnitTestRecordPropertyTest,
2131  AddRecordWithReservedKeysGeneratesCorrectPropertyList) {
2133  Test::RecordProperty("name", "1"),
2134  "'classname', 'name', 'status', 'time', 'type_param', 'value_param',"
2135  " 'file', and 'line' are reserved");
2136 }
2137 
2138 class UnitTestRecordPropertyTestEnvironment : public Environment {
2139  public:
2140  void TearDown() override {
2141  ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2142  "tests");
2143  ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2144  "failures");
2145  ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2146  "disabled");
2147  ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2148  "errors");
2149  ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2150  "name");
2151  ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2152  "timestamp");
2153  ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2154  "time");
2155  ExpectNonFatalFailureRecordingPropertyWithReservedKeyOutsideOfTestSuite(
2156  "random_seed");
2157  }
2158 };
2159 
2160 // This will test property recording outside of any test or test case.
2161 static Environment* record_property_env GTEST_ATTRIBUTE_UNUSED_ =
2162  AddGlobalTestEnvironment(new UnitTestRecordPropertyTestEnvironment);
2163 
2164 // This group of tests is for predicate assertions (ASSERT_PRED*, etc)
2165 // of various arities. They do not attempt to be exhaustive. Rather,
2166 // view them as smoke tests that can be easily reviewed and verified.
2167 // A more complete set of tests for predicate assertions can be found
2168 // in gtest_pred_impl_unittest.cc.
2169 
2170 // First, some predicates and predicate-formatters needed by the tests.
2171 
2172 // Returns true if the argument is an even number.
2173 bool IsEven(int n) {
2174  return (n % 2) == 0;
2175 }
2176 
2177 // A functor that returns true if the argument is an even number.
2178 struct IsEvenFunctor {
2179  bool operator()(int n) { return IsEven(n); }
2180 };
2181 
2182 // A predicate-formatter function that asserts the argument is an even
2183 // number.
2184 AssertionResult AssertIsEven(const char* expr, int n) {
2185  if (IsEven(n)) {
2186  return AssertionSuccess();
2187  }
2188 
2189  Message msg;
2190  msg << expr << " evaluates to " << n << ", which is not even.";
2191  return AssertionFailure(msg);
2192 }
2193 
2194 // A predicate function that returns AssertionResult for use in
2195 // EXPECT/ASSERT_TRUE/FALSE.
2196 AssertionResult ResultIsEven(int n) {
2197  if (IsEven(n))
2198  return AssertionSuccess() << n << " is even";
2199  else
2200  return AssertionFailure() << n << " is odd";
2201 }
2202 
2203 // A predicate function that returns AssertionResult but gives no
2204 // explanation why it succeeds. Needed for testing that
2205 // EXPECT/ASSERT_FALSE handles such functions correctly.
2206 AssertionResult ResultIsEvenNoExplanation(int n) {
2207  if (IsEven(n))
2208  return AssertionSuccess();
2209  else
2210  return AssertionFailure() << n << " is odd";
2211 }
2212 
2213 // A predicate-formatter functor that asserts the argument is an even
2214 // number.
2215 struct AssertIsEvenFunctor {
2216  AssertionResult operator()(const char* expr, int n) {
2217  return AssertIsEven(expr, n);
2218  }
2219 };
2220 
2221 // Returns true if the sum of the arguments is an even number.
2222 bool SumIsEven2(int n1, int n2) {
2223  return IsEven(n1 + n2);
2224 }
2225 
2226 // A functor that returns true if the sum of the arguments is an even
2227 // number.
2228 struct SumIsEven3Functor {
2229  bool operator()(int n1, int n2, int n3) {
2230  return IsEven(n1 + n2 + n3);
2231  }
2232 };
2233 
2234 // A predicate-formatter function that asserts the sum of the
2235 // arguments is an even number.
2236 AssertionResult AssertSumIsEven4(
2237  const char* e1, const char* e2, const char* e3, const char* e4,
2238  int n1, int n2, int n3, int n4) {
2239  const int sum = n1 + n2 + n3 + n4;
2240  if (IsEven(sum)) {
2241  return AssertionSuccess();
2242  }
2243 
2244  Message msg;
2245  msg << e1 << " + " << e2 << " + " << e3 << " + " << e4
2246  << " (" << n1 << " + " << n2 << " + " << n3 << " + " << n4
2247  << ") evaluates to " << sum << ", which is not even.";
2248  return AssertionFailure(msg);
2249 }
2250 
2251 // A predicate-formatter functor that asserts the sum of the arguments
2252 // is an even number.
2253 struct AssertSumIsEven5Functor {
2254  AssertionResult operator()(
2255  const char* e1, const char* e2, const char* e3, const char* e4,
2256  const char* e5, int n1, int n2, int n3, int n4, int n5) {
2257  const int sum = n1 + n2 + n3 + n4 + n5;
2258  if (IsEven(sum)) {
2259  return AssertionSuccess();
2260  }
2261 
2262  Message msg;
2263  msg << e1 << " + " << e2 << " + " << e3 << " + " << e4 << " + " << e5
2264  << " ("
2265  << n1 << " + " << n2 << " + " << n3 << " + " << n4 << " + " << n5
2266  << ") evaluates to " << sum << ", which is not even.";
2267  return AssertionFailure(msg);
2268  }
2269 };
2270 
2271 
2272 // Tests unary predicate assertions.
2273 
2274 // Tests unary predicate assertions that don't use a custom formatter.
2275 TEST(Pred1Test, WithoutFormat) {
2276  // Success cases.
2277  EXPECT_PRED1(IsEvenFunctor(), 2) << "This failure is UNEXPECTED!";
2278  ASSERT_PRED1(IsEven, 4);
2279 
2280  // Failure cases.
2281  EXPECT_NONFATAL_FAILURE({ // NOLINT
2282  EXPECT_PRED1(IsEven, 5) << "This failure is expected.";
2283  }, "This failure is expected.");
2284  EXPECT_FATAL_FAILURE(ASSERT_PRED1(IsEvenFunctor(), 5),
2285  "evaluates to false");
2286 }
2287 
2288 // Tests unary predicate assertions that use a custom formatter.
2289 TEST(Pred1Test, WithFormat) {
2290  // Success cases.
2291  EXPECT_PRED_FORMAT1(AssertIsEven, 2);
2292  ASSERT_PRED_FORMAT1(AssertIsEvenFunctor(), 4)
2293  << "This failure is UNEXPECTED!";
2294 
2295  // Failure cases.
2296  const int n = 5;
2297  EXPECT_NONFATAL_FAILURE(EXPECT_PRED_FORMAT1(AssertIsEvenFunctor(), n),
2298  "n evaluates to 5, which is not even.");
2299  EXPECT_FATAL_FAILURE({ // NOLINT
2300  ASSERT_PRED_FORMAT1(AssertIsEven, 5) << "This failure is expected.";
2301  }, "This failure is expected.");
2302 }
2303 
2304 // Tests that unary predicate assertions evaluates their arguments
2305 // exactly once.
2306 TEST(Pred1Test, SingleEvaluationOnFailure) {
2307  // A success case.
2308  static int n = 0;
2309  EXPECT_PRED1(IsEven, n++);
2310  EXPECT_EQ(1, n) << "The argument is not evaluated exactly once.";
2311 
2312  // A failure case.
2313  EXPECT_FATAL_FAILURE({ // NOLINT
2314  ASSERT_PRED_FORMAT1(AssertIsEvenFunctor(), n++)
2315  << "This failure is expected.";
2316  }, "This failure is expected.");
2317  EXPECT_EQ(2, n) << "The argument is not evaluated exactly once.";
2318 }
2319 
2320 
2321 // Tests predicate assertions whose arity is >= 2.
2322 
2323 // Tests predicate assertions that don't use a custom formatter.
2324 TEST(PredTest, WithoutFormat) {
2325  // Success cases.
2326  ASSERT_PRED2(SumIsEven2, 2, 4) << "This failure is UNEXPECTED!";
2327  EXPECT_PRED3(SumIsEven3Functor(), 4, 6, 8);
2328 
2329  // Failure cases.
2330  const int n1 = 1;
2331  const int n2 = 2;
2332  EXPECT_NONFATAL_FAILURE({ // NOLINT
2333  EXPECT_PRED2(SumIsEven2, n1, n2) << "This failure is expected.";
2334  }, "This failure is expected.");
2335  EXPECT_FATAL_FAILURE({ // NOLINT
2336  ASSERT_PRED3(SumIsEven3Functor(), 1, 2, 4);
2337  }, "evaluates to false");
2338 }
2339 
2340 // Tests predicate assertions that use a custom formatter.
2341 TEST(PredTest, WithFormat) {
2342  // Success cases.
2343  ASSERT_PRED_FORMAT4(AssertSumIsEven4, 4, 6, 8, 10) <<
2344  "This failure is UNEXPECTED!";
2345  EXPECT_PRED_FORMAT5(AssertSumIsEven5Functor(), 2, 4, 6, 8, 10);
2346 
2347  // Failure cases.
2348  const int n1 = 1;
2349  const int n2 = 2;
2350  const int n3 = 4;
2351  const int n4 = 6;
2352  EXPECT_NONFATAL_FAILURE({ // NOLINT
2353  EXPECT_PRED_FORMAT4(AssertSumIsEven4, n1, n2, n3, n4);
2354  }, "evaluates to 13, which is not even.");
2355  EXPECT_FATAL_FAILURE({ // NOLINT
2356  ASSERT_PRED_FORMAT5(AssertSumIsEven5Functor(), 1, 2, 4, 6, 8)
2357  << "This failure is expected.";
2358  }, "This failure is expected.");
2359 }
2360 
2361 // Tests that predicate assertions evaluates their arguments
2362 // exactly once.
2363 TEST(PredTest, SingleEvaluationOnFailure) {
2364  // A success case.
2365  int n1 = 0;
2366  int n2 = 0;
2367  EXPECT_PRED2(SumIsEven2, n1++, n2++);
2368  EXPECT_EQ(1, n1) << "Argument 1 is not evaluated exactly once.";
2369  EXPECT_EQ(1, n2) << "Argument 2 is not evaluated exactly once.";
2370 
2371  // Another success case.
2372  n1 = n2 = 0;
2373  int n3 = 0;
2374  int n4 = 0;
2375  int n5 = 0;
2376  ASSERT_PRED_FORMAT5(AssertSumIsEven5Functor(),
2377  n1++, n2++, n3++, n4++, n5++)
2378  << "This failure is UNEXPECTED!";
2379  EXPECT_EQ(1, n1) << "Argument 1 is not evaluated exactly once.";
2380  EXPECT_EQ(1, n2) << "Argument 2 is not evaluated exactly once.";
2381  EXPECT_EQ(1, n3) << "Argument 3 is not evaluated exactly once.";
2382  EXPECT_EQ(1, n4) << "Argument 4 is not evaluated exactly once.";
2383  EXPECT_EQ(1, n5) << "Argument 5 is not evaluated exactly once.";
2384 
2385  // A failure case.
2386  n1 = n2 = n3 = 0;
2387  EXPECT_NONFATAL_FAILURE({ // NOLINT
2388  EXPECT_PRED3(SumIsEven3Functor(), ++n1, n2++, n3++)
2389  << "This failure is expected.";
2390  }, "This failure is expected.");
2391  EXPECT_EQ(1, n1) << "Argument 1 is not evaluated exactly once.";
2392  EXPECT_EQ(1, n2) << "Argument 2 is not evaluated exactly once.";
2393  EXPECT_EQ(1, n3) << "Argument 3 is not evaluated exactly once.";
2394 
2395  // Another failure case.
2396  n1 = n2 = n3 = n4 = 0;
2397  EXPECT_NONFATAL_FAILURE({ // NOLINT
2398  EXPECT_PRED_FORMAT4(AssertSumIsEven4, ++n1, n2++, n3++, n4++);
2399  }, "evaluates to 1, which is not even.");
2400  EXPECT_EQ(1, n1) << "Argument 1 is not evaluated exactly once.";
2401  EXPECT_EQ(1, n2) << "Argument 2 is not evaluated exactly once.";
2402  EXPECT_EQ(1, n3) << "Argument 3 is not evaluated exactly once.";
2403  EXPECT_EQ(1, n4) << "Argument 4 is not evaluated exactly once.";
2404 }
2405 
2406 // Test predicate assertions for sets
2407 TEST(PredTest, ExpectPredEvalFailure) {
2408  std::set<int> set_a = {2, 1, 3, 4, 5};
2409  std::set<int> set_b = {0, 4, 8};
2410  const auto compare_sets = [] (std::set<int>, std::set<int>) { return false; };
2412  EXPECT_PRED2(compare_sets, set_a, set_b),
2413  "compare_sets(set_a, set_b) evaluates to false, where\nset_a evaluates "
2414  "to { 1, 2, 3, 4, 5 }\nset_b evaluates to { 0, 4, 8 }");
2415 }
2416 
2417 // Some helper functions for testing using overloaded/template
2418 // functions with ASSERT_PREDn and EXPECT_PREDn.
2419 
2420 bool IsPositive(double x) {
2421  return x > 0;
2422 }
2423 
2424 template <typename T>
2425 bool IsNegative(T x) {
2426  return x < 0;
2427 }
2428 
2429 template <typename T1, typename T2>
2430 bool GreaterThan(T1 x1, T2 x2) {
2431  return x1 > x2;
2432 }
2433 
2434 // Tests that overloaded functions can be used in *_PRED* as long as
2435 // their types are explicitly specified.
2436 TEST(PredicateAssertionTest, AcceptsOverloadedFunction) {
2437  // C++Builder requires C-style casts rather than static_cast.
2438  EXPECT_PRED1((bool (*)(int))(IsPositive), 5); // NOLINT
2439  ASSERT_PRED1((bool (*)(double))(IsPositive), 6.0); // NOLINT
2440 }
2441 
2442 // Tests that template functions can be used in *_PRED* as long as
2443 // their types are explicitly specified.
2444 TEST(PredicateAssertionTest, AcceptsTemplateFunction) {
2445  EXPECT_PRED1(IsNegative<int>, -5);
2446  // Makes sure that we can handle templates with more than one
2447  // parameter.
2448  ASSERT_PRED2((GreaterThan<int, int>), 5, 0);
2449 }
2450 
2451 
2452 // Some helper functions for testing using overloaded/template
2453 // functions with ASSERT_PRED_FORMATn and EXPECT_PRED_FORMATn.
2454 
2455 AssertionResult IsPositiveFormat(const char* /* expr */, int n) {
2456  return n > 0 ? AssertionSuccess() :
2457  AssertionFailure(Message() << "Failure");
2458 }
2459 
2460 AssertionResult IsPositiveFormat(const char* /* expr */, double x) {
2461  return x > 0 ? AssertionSuccess() :
2462  AssertionFailure(Message() << "Failure");
2463 }
2464 
2465 template <typename T>
2466 AssertionResult IsNegativeFormat(const char* /* expr */, T x) {
2467  return x < 0 ? AssertionSuccess() :
2468  AssertionFailure(Message() << "Failure");
2469 }
2470 
2471 template <typename T1, typename T2>
2472 AssertionResult EqualsFormat(const char* /* expr1 */, const char* /* expr2 */,
2473  const T1& x1, const T2& x2) {
2474  return x1 == x2 ? AssertionSuccess() :
2475  AssertionFailure(Message() << "Failure");
2476 }
2477 
2478 // Tests that overloaded functions can be used in *_PRED_FORMAT*
2479 // without explicitly specifying their types.
2480 TEST(PredicateFormatAssertionTest, AcceptsOverloadedFunction) {
2481  EXPECT_PRED_FORMAT1(IsPositiveFormat, 5);
2482  ASSERT_PRED_FORMAT1(IsPositiveFormat, 6.0);
2483 }
2484 
2485 // Tests that template functions can be used in *_PRED_FORMAT* without
2486 // explicitly specifying their types.
2487 TEST(PredicateFormatAssertionTest, AcceptsTemplateFunction) {
2488  EXPECT_PRED_FORMAT1(IsNegativeFormat, -5);
2489  ASSERT_PRED_FORMAT2(EqualsFormat, 3, 3);
2490 }
2491 
2492 
2493 // Tests string assertions.
2494 
2495 // Tests ASSERT_STREQ with non-NULL arguments.
2496 TEST(StringAssertionTest, ASSERT_STREQ) {
2497  const char * const p1 = "good";
2498  ASSERT_STREQ(p1, p1);
2499 
2500  // Let p2 have the same content as p1, but be at a different address.
2501  const char p2[] = "good";
2502  ASSERT_STREQ(p1, p2);
2503 
2504  EXPECT_FATAL_FAILURE(ASSERT_STREQ("bad", "good"),
2505  " \"bad\"\n \"good\"");
2506 }
2507 
2508 // Tests ASSERT_STREQ with NULL arguments.
2509 TEST(StringAssertionTest, ASSERT_STREQ_Null) {
2510  ASSERT_STREQ(static_cast<const char*>(nullptr), nullptr);
2511  EXPECT_FATAL_FAILURE(ASSERT_STREQ(nullptr, "non-null"), "non-null");
2512 }
2513 
2514 // Tests ASSERT_STREQ with NULL arguments.
2515 TEST(StringAssertionTest, ASSERT_STREQ_Null2) {
2516  EXPECT_FATAL_FAILURE(ASSERT_STREQ("non-null", nullptr), "non-null");
2517 }
2518 
2519 // Tests ASSERT_STRNE.
2520 TEST(StringAssertionTest, ASSERT_STRNE) {
2521  ASSERT_STRNE("hi", "Hi");
2522  ASSERT_STRNE("Hi", nullptr);
2523  ASSERT_STRNE(nullptr, "Hi");
2524  ASSERT_STRNE("", nullptr);
2525  ASSERT_STRNE(nullptr, "");
2526  ASSERT_STRNE("", "Hi");
2527  ASSERT_STRNE("Hi", "");
2528  EXPECT_FATAL_FAILURE(ASSERT_STRNE("Hi", "Hi"),
2529  "\"Hi\" vs \"Hi\"");
2530 }
2531 
2532 // Tests ASSERT_STRCASEEQ.
2533 TEST(StringAssertionTest, ASSERT_STRCASEEQ) {
2534  ASSERT_STRCASEEQ("hi", "Hi");
2535  ASSERT_STRCASEEQ(static_cast<const char*>(nullptr), nullptr);
2536 
2537  ASSERT_STRCASEEQ("", "");
2539  "Ignoring case");
2540 }
2541 
2542 // Tests ASSERT_STRCASENE.
2543 TEST(StringAssertionTest, ASSERT_STRCASENE) {
2544  ASSERT_STRCASENE("hi1", "Hi2");
2545  ASSERT_STRCASENE("Hi", nullptr);
2546  ASSERT_STRCASENE(nullptr, "Hi");
2547  ASSERT_STRCASENE("", nullptr);
2548  ASSERT_STRCASENE(nullptr, "");
2549  ASSERT_STRCASENE("", "Hi");
2550  ASSERT_STRCASENE("Hi", "");
2552  "(ignoring case)");
2553 }
2554 
2555 // Tests *_STREQ on wide strings.
2556 TEST(StringAssertionTest, STREQ_Wide) {
2557  // NULL strings.
2558  ASSERT_STREQ(static_cast<const wchar_t*>(nullptr), nullptr);
2559 
2560  // Empty strings.
2561  ASSERT_STREQ(L"", L"");
2562 
2563  // Non-null vs NULL.
2564  EXPECT_NONFATAL_FAILURE(EXPECT_STREQ(L"non-null", nullptr), "non-null");
2565 
2566  // Equal strings.
2567  EXPECT_STREQ(L"Hi", L"Hi");
2568 
2569  // Unequal strings.
2571  "Abc");
2572 
2573  // Strings containing wide characters.
2574  EXPECT_NONFATAL_FAILURE(EXPECT_STREQ(L"abc\x8119", L"abc\x8120"),
2575  "abc");
2576 
2577  // The streaming variation.
2578  EXPECT_NONFATAL_FAILURE({ // NOLINT
2579  EXPECT_STREQ(L"abc\x8119", L"abc\x8121") << "Expected failure";
2580  }, "Expected failure");
2581 }
2582 
2583 // Tests *_STRNE on wide strings.
2584 TEST(StringAssertionTest, STRNE_Wide) {
2585  // NULL strings.
2587  { // NOLINT
2588  EXPECT_STRNE(static_cast<const wchar_t*>(nullptr), nullptr);
2589  },
2590  "");
2591 
2592  // Empty strings.
2594  "L\"\"");
2595 
2596  // Non-null vs NULL.
2597  ASSERT_STRNE(L"non-null", nullptr);
2598 
2599  // Equal strings.
2601  "L\"Hi\"");
2602 
2603  // Unequal strings.
2604  EXPECT_STRNE(L"abc", L"Abc");
2605 
2606  // Strings containing wide characters.
2607  EXPECT_NONFATAL_FAILURE(EXPECT_STRNE(L"abc\x8119", L"abc\x8119"),
2608  "abc");
2609 
2610  // The streaming variation.
2611  ASSERT_STRNE(L"abc\x8119", L"abc\x8120") << "This shouldn't happen";
2612 }
2613 
2614 // Tests for ::testing::IsSubstring().
2615 
2616 // Tests that IsSubstring() returns the correct result when the input
2617 // argument type is const char*.
2618 TEST(IsSubstringTest, ReturnsCorrectResultForCString) {
2619  EXPECT_FALSE(IsSubstring("", "", nullptr, "a"));
2620  EXPECT_FALSE(IsSubstring("", "", "b", nullptr));
2621  EXPECT_FALSE(IsSubstring("", "", "needle", "haystack"));
2622 
2623  EXPECT_TRUE(IsSubstring("", "", static_cast<const char*>(nullptr), nullptr));
2624  EXPECT_TRUE(IsSubstring("", "", "needle", "two needles"));
2625 }
2626 
2627 // Tests that IsSubstring() returns the correct result when the input
2628 // argument type is const wchar_t*.
2629 TEST(IsSubstringTest, ReturnsCorrectResultForWideCString) {
2630  EXPECT_FALSE(IsSubstring("", "", kNull, L"a"));
2631  EXPECT_FALSE(IsSubstring("", "", L"b", kNull));
2632  EXPECT_FALSE(IsSubstring("", "", L"needle", L"haystack"));
2633 
2634  EXPECT_TRUE(
2635  IsSubstring("", "", static_cast<const wchar_t*>(nullptr), nullptr));
2636  EXPECT_TRUE(IsSubstring("", "", L"needle", L"two needles"));
2637 }
2638 
2639 // Tests that IsSubstring() generates the correct message when the input
2640 // argument type is const char*.
2641 TEST(IsSubstringTest, GeneratesCorrectMessageForCString) {
2642  EXPECT_STREQ("Value of: needle_expr\n"
2643  " Actual: \"needle\"\n"
2644  "Expected: a substring of haystack_expr\n"
2645  "Which is: \"haystack\"",
2646  IsSubstring("needle_expr", "haystack_expr",
2647  "needle", "haystack").failure_message());
2648 }
2649 
2650 // Tests that IsSubstring returns the correct result when the input
2651 // argument type is ::std::string.
2652 TEST(IsSubstringTest, ReturnsCorrectResultsForStdString) {
2653  EXPECT_TRUE(IsSubstring("", "", std::string("hello"), "ahellob"));
2654  EXPECT_FALSE(IsSubstring("", "", "hello", std::string("world")));
2655 }
2656 
2657 #if GTEST_HAS_STD_WSTRING
2658 // Tests that IsSubstring returns the correct result when the input
2659 // argument type is ::std::wstring.
2660 TEST(IsSubstringTest, ReturnsCorrectResultForStdWstring) {
2661  EXPECT_TRUE(IsSubstring("", "", ::std::wstring(L"needle"), L"two needles"));
2662  EXPECT_FALSE(IsSubstring("", "", L"needle", ::std::wstring(L"haystack")));
2663 }
2664 
2665 // Tests that IsSubstring() generates the correct message when the input
2666 // argument type is ::std::wstring.
2667 TEST(IsSubstringTest, GeneratesCorrectMessageForWstring) {
2668  EXPECT_STREQ("Value of: needle_expr\n"
2669  " Actual: L\"needle\"\n"
2670  "Expected: a substring of haystack_expr\n"
2671  "Which is: L\"haystack\"",
2672  IsSubstring(
2673  "needle_expr", "haystack_expr",
2674  ::std::wstring(L"needle"), L"haystack").failure_message());
2675 }
2676 
2677 #endif // GTEST_HAS_STD_WSTRING
2678 
2679 // Tests for ::testing::IsNotSubstring().
2680 
2681 // Tests that IsNotSubstring() returns the correct result when the input
2682 // argument type is const char*.
2683 TEST(IsNotSubstringTest, ReturnsCorrectResultForCString) {
2684  EXPECT_TRUE(IsNotSubstring("", "", "needle", "haystack"));
2685  EXPECT_FALSE(IsNotSubstring("", "", "needle", "two needles"));
2686 }
2687 
2688 // Tests that IsNotSubstring() returns the correct result when the input
2689 // argument type is const wchar_t*.
2690 TEST(IsNotSubstringTest, ReturnsCorrectResultForWideCString) {
2691  EXPECT_TRUE(IsNotSubstring("", "", L"needle", L"haystack"));
2692  EXPECT_FALSE(IsNotSubstring("", "", L"needle", L"two needles"));
2693 }
2694 
2695 // Tests that IsNotSubstring() generates the correct message when the input
2696 // argument type is const wchar_t*.
2697 TEST(IsNotSubstringTest, GeneratesCorrectMessageForWideCString) {
2698  EXPECT_STREQ("Value of: needle_expr\n"
2699  " Actual: L\"needle\"\n"
2700  "Expected: not a substring of haystack_expr\n"
2701  "Which is: L\"two needles\"",
2703  "needle_expr", "haystack_expr",
2704  L"needle", L"two needles").failure_message());
2705 }
2706 
2707 // Tests that IsNotSubstring returns the correct result when the input
2708 // argument type is ::std::string.
2709 TEST(IsNotSubstringTest, ReturnsCorrectResultsForStdString) {
2710  EXPECT_FALSE(IsNotSubstring("", "", std::string("hello"), "ahellob"));
2711  EXPECT_TRUE(IsNotSubstring("", "", "hello", std::string("world")));
2712 }
2713 
2714 // Tests that IsNotSubstring() generates the correct message when the input
2715 // argument type is ::std::string.
2716 TEST(IsNotSubstringTest, GeneratesCorrectMessageForStdString) {
2717  EXPECT_STREQ("Value of: needle_expr\n"
2718  " Actual: \"needle\"\n"
2719  "Expected: not a substring of haystack_expr\n"
2720  "Which is: \"two needles\"",
2722  "needle_expr", "haystack_expr",
2723  ::std::string("needle"), "two needles").failure_message());
2724 }
2725 
2726 #if GTEST_HAS_STD_WSTRING
2727 
2728 // Tests that IsNotSubstring returns the correct result when the input
2729 // argument type is ::std::wstring.
2730 TEST(IsNotSubstringTest, ReturnsCorrectResultForStdWstring) {
2731  EXPECT_FALSE(
2732  IsNotSubstring("", "", ::std::wstring(L"needle"), L"two needles"));
2733  EXPECT_TRUE(IsNotSubstring("", "", L"needle", ::std::wstring(L"haystack")));
2734 }
2735 
2736 #endif // GTEST_HAS_STD_WSTRING
2737 
2738 // Tests floating-point assertions.
2739 
2740 template <typename RawType>
2741 class FloatingPointTest : public Test {
2742  protected:
2743  // Pre-calculated numbers to be used by the tests.
2744  struct TestValues {
2745  RawType close_to_positive_zero;
2746  RawType close_to_negative_zero;
2747  RawType further_from_negative_zero;
2748 
2749  RawType close_to_one;
2750  RawType further_from_one;
2751 
2752  RawType infinity;
2753  RawType close_to_infinity;
2754  RawType further_from_infinity;
2755 
2756  RawType nan1;
2757  RawType nan2;
2758  };
2759 
2760  typedef typename testing::internal::FloatingPoint<RawType> Floating;
2761  typedef typename Floating::Bits Bits;
2762 
2763  void SetUp() override {
2764  const size_t max_ulps = Floating::kMaxUlps;
2765 
2766  // The bits that represent 0.0.
2767  const Bits zero_bits = Floating(0).bits();
2768 
2769  // Makes some numbers close to 0.0.
2770  values_.close_to_positive_zero = Floating::ReinterpretBits(
2771  zero_bits + max_ulps/2);
2772  values_.close_to_negative_zero = -Floating::ReinterpretBits(
2773  zero_bits + max_ulps - max_ulps/2);
2774  values_.further_from_negative_zero = -Floating::ReinterpretBits(
2775  zero_bits + max_ulps + 1 - max_ulps/2);
2776 
2777  // The bits that represent 1.0.
2778  const Bits one_bits = Floating(1).bits();
2779 
2780  // Makes some numbers close to 1.0.
2781  values_.close_to_one = Floating::ReinterpretBits(one_bits + max_ulps);
2782  values_.further_from_one = Floating::ReinterpretBits(
2783  one_bits + max_ulps + 1);
2784 
2785  // +infinity.
2786  values_.infinity = Floating::Infinity();
2787 
2788  // The bits that represent +infinity.
2789  const Bits infinity_bits = Floating(values_.infinity).bits();
2790 
2791  // Makes some numbers close to infinity.
2792  values_.close_to_infinity = Floating::ReinterpretBits(
2793  infinity_bits - max_ulps);
2794  values_.further_from_infinity = Floating::ReinterpretBits(
2795  infinity_bits - max_ulps - 1);
2796 
2797  // Makes some NAN's. Sets the most significant bit of the fraction so that
2798  // our NaN's are quiet; trying to process a signaling NaN would raise an
2799  // exception if our environment enables floating point exceptions.
2800  values_.nan1 = Floating::ReinterpretBits(Floating::kExponentBitMask
2801  | (static_cast<Bits>(1) << (Floating::kFractionBitCount - 1)) | 1);
2802  values_.nan2 = Floating::ReinterpretBits(Floating::kExponentBitMask
2803  | (static_cast<Bits>(1) << (Floating::kFractionBitCount - 1)) | 200);
2804  }
2805 
2806  void TestSize() {
2807  EXPECT_EQ(sizeof(RawType), sizeof(Bits));
2808  }
2809 
2810  static TestValues values_;
2811 };
2812 
2813 template <typename RawType>
2814 typename FloatingPointTest<RawType>::TestValues
2815  FloatingPointTest<RawType>::values_;
2816 
2817 // Instantiates FloatingPointTest for testing *_FLOAT_EQ.
2818 typedef FloatingPointTest<float> FloatTest;
2819 
2820 // Tests that the size of Float::Bits matches the size of float.
2821 TEST_F(FloatTest, Size) {
2822  TestSize();
2823 }
2824 
2825 // Tests comparing with +0 and -0.
2826 TEST_F(FloatTest, Zeros) {
2827  EXPECT_FLOAT_EQ(0.0, -0.0);
2829  "1.0");
2831  "1.5");
2832 }
2833 
2834 // Tests comparing numbers close to 0.
2835 //
2836 // This ensures that *_FLOAT_EQ handles the sign correctly and no
2837 // overflow occurs when comparing numbers whose absolute value is very
2838 // small.
2839 TEST_F(FloatTest, AlmostZeros) {
2840  // In C++Builder, names within local classes (such as used by
2841  // EXPECT_FATAL_FAILURE) cannot be resolved against static members of the
2842  // scoping class. Use a static local alias as a workaround.
2843  // We use the assignment syntax since some compilers, like Sun Studio,
2844  // don't allow initializing references using construction syntax
2845  // (parentheses).
2846  static const FloatTest::TestValues& v = this->values_;
2847 
2848  EXPECT_FLOAT_EQ(0.0, v.close_to_positive_zero);
2849  EXPECT_FLOAT_EQ(-0.0, v.close_to_negative_zero);
2850  EXPECT_FLOAT_EQ(v.close_to_positive_zero, v.close_to_negative_zero);
2851 
2852  EXPECT_FATAL_FAILURE({ // NOLINT
2853  ASSERT_FLOAT_EQ(v.close_to_positive_zero,
2854  v.further_from_negative_zero);
2855  }, "v.further_from_negative_zero");
2856 }
2857 
2858 // Tests comparing numbers close to each other.
2859 TEST_F(FloatTest, SmallDiff) {
2860  EXPECT_FLOAT_EQ(1.0, values_.close_to_one);
2861  EXPECT_NONFATAL_FAILURE(EXPECT_FLOAT_EQ(1.0, values_.further_from_one),
2862  "values_.further_from_one");
2863 }
2864 
2865 // Tests comparing numbers far apart.
2866 TEST_F(FloatTest, LargeDiff) {
2868  "3.0");
2869 }
2870 
2871 // Tests comparing with infinity.
2872 //
2873 // This ensures that no overflow occurs when comparing numbers whose
2874 // absolute value is very large.
2875 TEST_F(FloatTest, Infinity) {
2876  EXPECT_FLOAT_EQ(values_.infinity, values_.close_to_infinity);
2877  EXPECT_FLOAT_EQ(-values_.infinity, -values_.close_to_infinity);
2878  EXPECT_NONFATAL_FAILURE(EXPECT_FLOAT_EQ(values_.infinity, -values_.infinity),
2879  "-values_.infinity");
2880 
2881  // This is interesting as the representations of infinity and nan1
2882  // are only 1 DLP apart.
2883  EXPECT_NONFATAL_FAILURE(EXPECT_FLOAT_EQ(values_.infinity, values_.nan1),
2884  "values_.nan1");
2885 }
2886 
2887 // Tests that comparing with NAN always returns false.
2888 TEST_F(FloatTest, NaN) {
2889  // In C++Builder, names within local classes (such as used by
2890  // EXPECT_FATAL_FAILURE) cannot be resolved against static members of the
2891  // scoping class. Use a static local alias as a workaround.
2892  // We use the assignment syntax since some compilers, like Sun Studio,
2893  // don't allow initializing references using construction syntax
2894  // (parentheses).
2895  static const FloatTest::TestValues& v = this->values_;
2896 
2898  "v.nan1");
2900  "v.nan2");
2902  "v.nan1");
2903 
2904  EXPECT_FATAL_FAILURE(ASSERT_FLOAT_EQ(v.nan1, v.infinity),
2905  "v.infinity");
2906 }
2907 
2908 // Tests that *_FLOAT_EQ are reflexive.
2909 TEST_F(FloatTest, Reflexive) {
2910  EXPECT_FLOAT_EQ(0.0, 0.0);
2911  EXPECT_FLOAT_EQ(1.0, 1.0);
2912  ASSERT_FLOAT_EQ(values_.infinity, values_.infinity);
2913 }
2914 
2915 // Tests that *_FLOAT_EQ are commutative.
2916 TEST_F(FloatTest, Commutative) {
2917  // We already tested EXPECT_FLOAT_EQ(1.0, values_.close_to_one).
2918  EXPECT_FLOAT_EQ(values_.close_to_one, 1.0);
2919 
2920  // We already tested EXPECT_FLOAT_EQ(1.0, values_.further_from_one).
2921  EXPECT_NONFATAL_FAILURE(EXPECT_FLOAT_EQ(values_.further_from_one, 1.0),
2922  "1.0");
2923 }
2924 
2925 // Tests EXPECT_NEAR.
2926 TEST_F(FloatTest, EXPECT_NEAR) {
2927  EXPECT_NEAR(-1.0f, -1.1f, 0.2f);
2928  EXPECT_NEAR(2.0f, 3.0f, 1.0f);
2929  EXPECT_NONFATAL_FAILURE(EXPECT_NEAR(1.0f,1.5f, 0.25f), // NOLINT
2930  "The difference between 1.0f and 1.5f is 0.5, "
2931  "which exceeds 0.25f");
2932  // To work around a bug in gcc 2.95.0, there is intentionally no
2933  // space after the first comma in the previous line.
2934 }
2935 
2936 // Tests ASSERT_NEAR.
2937 TEST_F(FloatTest, ASSERT_NEAR) {
2938  ASSERT_NEAR(-1.0f, -1.1f, 0.2f);
2939  ASSERT_NEAR(2.0f, 3.0f, 1.0f);
2940  EXPECT_FATAL_FAILURE(ASSERT_NEAR(1.0f,1.5f, 0.25f), // NOLINT
2941  "The difference between 1.0f and 1.5f is 0.5, "
2942  "which exceeds 0.25f");
2943  // To work around a bug in gcc 2.95.0, there is intentionally no
2944  // space after the first comma in the previous line.
2945 }
2946 
2947 // Tests the cases where FloatLE() should succeed.
2948 TEST_F(FloatTest, FloatLESucceeds) {
2949  EXPECT_PRED_FORMAT2(FloatLE, 1.0f, 2.0f); // When val1 < val2,
2950  ASSERT_PRED_FORMAT2(FloatLE, 1.0f, 1.0f); // val1 == val2,
2951 
2952  // or when val1 is greater than, but almost equals to, val2.
2953  EXPECT_PRED_FORMAT2(FloatLE, values_.close_to_positive_zero, 0.0f);
2954 }
2955 
2956 // Tests the cases where FloatLE() should fail.
2957 TEST_F(FloatTest, FloatLEFails) {
2958  // When val1 is greater than val2 by a large margin,
2960  "(2.0f) <= (1.0f)");
2961 
2962  // or by a small yet non-negligible margin,
2963  EXPECT_NONFATAL_FAILURE({ // NOLINT
2964  EXPECT_PRED_FORMAT2(FloatLE, values_.further_from_one, 1.0f);
2965  }, "(values_.further_from_one) <= (1.0f)");
2966 
2967  EXPECT_NONFATAL_FAILURE({ // NOLINT
2968  EXPECT_PRED_FORMAT2(FloatLE, values_.nan1, values_.infinity);
2969  }, "(values_.nan1) <= (values_.infinity)");
2970  EXPECT_NONFATAL_FAILURE({ // NOLINT
2971  EXPECT_PRED_FORMAT2(FloatLE, -values_.infinity, values_.nan1);
2972  }, "(-values_.infinity) <= (values_.nan1)");
2973  EXPECT_FATAL_FAILURE({ // NOLINT
2974  ASSERT_PRED_FORMAT2(FloatLE, values_.nan1, values_.nan1);
2975  }, "(values_.nan1) <= (values_.nan1)");
2976 }
2977 
2978 // Instantiates FloatingPointTest for testing *_DOUBLE_EQ.
2979 typedef FloatingPointTest<double> DoubleTest;
2980 
2981 // Tests that the size of Double::Bits matches the size of double.
2982 TEST_F(DoubleTest, Size) {
2983  TestSize();
2984 }
2985 
2986 // Tests comparing with +0 and -0.
2987 TEST_F(DoubleTest, Zeros) {
2988  EXPECT_DOUBLE_EQ(0.0, -0.0);
2990  "1.0");
2992  "1.0");
2993 }
2994 
2995 // Tests comparing numbers close to 0.
2996 //
2997 // This ensures that *_DOUBLE_EQ handles the sign correctly and no
2998 // overflow occurs when comparing numbers whose absolute value is very
2999 // small.
3000 TEST_F(DoubleTest, AlmostZeros) {
3001  // In C++Builder, names within local classes (such as used by
3002  // EXPECT_FATAL_FAILURE) cannot be resolved against static members of the
3003  // scoping class. Use a static local alias as a workaround.
3004  // We use the assignment syntax since some compilers, like Sun Studio,
3005  // don't allow initializing references using construction syntax
3006  // (parentheses).
3007  static const DoubleTest::TestValues& v = this->values_;
3008 
3009  EXPECT_DOUBLE_EQ(0.0, v.close_to_positive_zero);
3010  EXPECT_DOUBLE_EQ(-0.0, v.close_to_negative_zero);
3011  EXPECT_DOUBLE_EQ(v.close_to_positive_zero, v.close_to_negative_zero);
3012 
3013  EXPECT_FATAL_FAILURE({ // NOLINT
3014  ASSERT_DOUBLE_EQ(v.close_to_positive_zero,
3015  v.further_from_negative_zero);
3016  }, "v.further_from_negative_zero");
3017 }
3018 
3019 // Tests comparing numbers close to each other.
3020 TEST_F(DoubleTest, SmallDiff) {
3021  EXPECT_DOUBLE_EQ(1.0, values_.close_to_one);
3022  EXPECT_NONFATAL_FAILURE(EXPECT_DOUBLE_EQ(1.0, values_.further_from_one),
3023  "values_.further_from_one");
3024 }
3025 
3026 // Tests comparing numbers far apart.
3027 TEST_F(DoubleTest, LargeDiff) {
3029  "3.0");
3030 }
3031 
3032 // Tests comparing with infinity.
3033 //
3034 // This ensures that no overflow occurs when comparing numbers whose
3035 // absolute value is very large.
3036 TEST_F(DoubleTest, Infinity) {
3037  EXPECT_DOUBLE_EQ(values_.infinity, values_.close_to_infinity);
3038  EXPECT_DOUBLE_EQ(-values_.infinity, -values_.close_to_infinity);
3039  EXPECT_NONFATAL_FAILURE(EXPECT_DOUBLE_EQ(values_.infinity, -values_.infinity),
3040  "-values_.infinity");
3041 
3042  // This is interesting as the representations of infinity_ and nan1_
3043  // are only 1 DLP apart.
3044  EXPECT_NONFATAL_FAILURE(EXPECT_DOUBLE_EQ(values_.infinity, values_.nan1),
3045  "values_.nan1");
3046 }
3047 
3048 // Tests that comparing with NAN always returns false.
3049 TEST_F(DoubleTest, NaN) {
3050  static const DoubleTest::TestValues& v = this->values_;
3051 
3052  // Nokia's STLport crashes if we try to output infinity or NaN.
3054  "v.nan1");
3055  EXPECT_NONFATAL_FAILURE(EXPECT_DOUBLE_EQ(v.nan1, v.nan2), "v.nan2");
3056  EXPECT_NONFATAL_FAILURE(EXPECT_DOUBLE_EQ(1.0, v.nan1), "v.nan1");
3057  EXPECT_FATAL_FAILURE(ASSERT_DOUBLE_EQ(v.nan1, v.infinity),
3058  "v.infinity");
3059 }
3060 
3061 // Tests that *_DOUBLE_EQ are reflexive.
3062 TEST_F(DoubleTest, Reflexive) {
3063  EXPECT_DOUBLE_EQ(0.0, 0.0);
3064  EXPECT_DOUBLE_EQ(1.0, 1.0);
3065  ASSERT_DOUBLE_EQ(values_.infinity, values_.infinity);
3066 }
3067 
3068 // Tests that *_DOUBLE_EQ are commutative.
3069 TEST_F(DoubleTest, Commutative) {
3070  // We already tested EXPECT_DOUBLE_EQ(1.0, values_.close_to_one).
3071  EXPECT_DOUBLE_EQ(values_.close_to_one, 1.0);
3072 
3073  // We already tested EXPECT_DOUBLE_EQ(1.0, values_.further_from_one).
3074  EXPECT_NONFATAL_FAILURE(EXPECT_DOUBLE_EQ(values_.further_from_one, 1.0),
3075  "1.0");
3076 }
3077 
3078 // Tests EXPECT_NEAR.
3079 TEST_F(DoubleTest, EXPECT_NEAR) {
3080  EXPECT_NEAR(-1.0, -1.1, 0.2);
3081  EXPECT_NEAR(2.0, 3.0, 1.0);
3082  EXPECT_NONFATAL_FAILURE(EXPECT_NEAR(1.0, 1.5, 0.25), // NOLINT
3083  "The difference between 1.0 and 1.5 is 0.5, "
3084  "which exceeds 0.25");
3085  // To work around a bug in gcc 2.95.0, there is intentionally no
3086  // space after the first comma in the previous statement.
3087 }
3088 
3089 // Tests ASSERT_NEAR.
3090 TEST_F(DoubleTest, ASSERT_NEAR) {
3091  ASSERT_NEAR(-1.0, -1.1, 0.2);
3092  ASSERT_NEAR(2.0, 3.0, 1.0);
3093  EXPECT_FATAL_FAILURE(ASSERT_NEAR(1.0, 1.5, 0.25), // NOLINT
3094  "The difference between 1.0 and 1.5 is 0.5, "
3095  "which exceeds 0.25");
3096  // To work around a bug in gcc 2.95.0, there is intentionally no
3097  // space after the first comma in the previous statement.
3098 }
3099 
3100 // Tests the cases where DoubleLE() should succeed.
3101 TEST_F(DoubleTest, DoubleLESucceeds) {
3102  EXPECT_PRED_FORMAT2(DoubleLE, 1.0, 2.0); // When val1 < val2,
3103  ASSERT_PRED_FORMAT2(DoubleLE, 1.0, 1.0); // val1 == val2,
3104 
3105  // or when val1 is greater than, but almost equals to, val2.
3106  EXPECT_PRED_FORMAT2(DoubleLE, values_.close_to_positive_zero, 0.0);
3107 }
3108 
3109 // Tests the cases where DoubleLE() should fail.
3110 TEST_F(DoubleTest, DoubleLEFails) {
3111  // When val1 is greater than val2 by a large margin,
3113  "(2.0) <= (1.0)");
3114 
3115  // or by a small yet non-negligible margin,
3116  EXPECT_NONFATAL_FAILURE({ // NOLINT
3117  EXPECT_PRED_FORMAT2(DoubleLE, values_.further_from_one, 1.0);
3118  }, "(values_.further_from_one) <= (1.0)");
3119 
3120  EXPECT_NONFATAL_FAILURE({ // NOLINT
3121  EXPECT_PRED_FORMAT2(DoubleLE, values_.nan1, values_.infinity);
3122  }, "(values_.nan1) <= (values_.infinity)");
3123  EXPECT_NONFATAL_FAILURE({ // NOLINT
3124  EXPECT_PRED_FORMAT2(DoubleLE, -values_.infinity, values_.nan1);
3125  }, " (-values_.infinity) <= (values_.nan1)");
3126  EXPECT_FATAL_FAILURE({ // NOLINT
3127  ASSERT_PRED_FORMAT2(DoubleLE, values_.nan1, values_.nan1);
3128  }, "(values_.nan1) <= (values_.nan1)");
3129 }
3130 
3131 
3132 // Verifies that a test or test case whose name starts with DISABLED_ is
3133 // not run.
3134 
3135 // A test whose name starts with DISABLED_.
3136 // Should not run.
3137 TEST(DisabledTest, DISABLED_TestShouldNotRun) {
3138  FAIL() << "Unexpected failure: Disabled test should not be run.";
3139 }
3140 
3141 // A test whose name does not start with DISABLED_.
3142 // Should run.
3143 TEST(DisabledTest, NotDISABLED_TestShouldRun) {
3144  EXPECT_EQ(1, 1);
3145 }
3146 
3147 // A test case whose name starts with DISABLED_.
3148 // Should not run.
3149 TEST(DISABLED_TestSuite, TestShouldNotRun) {
3150  FAIL() << "Unexpected failure: Test in disabled test case should not be run.";
3151 }
3152 
3153 // A test case and test whose names start with DISABLED_.
3154 // Should not run.
3155 TEST(DISABLED_TestSuite, DISABLED_TestShouldNotRun) {
3156  FAIL() << "Unexpected failure: Test in disabled test case should not be run.";
3157 }
3158 
3159 // Check that when all tests in a test case are disabled, SetUpTestSuite() and
3160 // TearDownTestSuite() are not called.
3161 class DisabledTestsTest : public Test {
3162  protected:
3163  static void SetUpTestSuite() {
3164  FAIL() << "Unexpected failure: All tests disabled in test case. "
3165  "SetUpTestSuite() should not be called.";
3166  }
3167 
3168  static void TearDownTestSuite() {
3169  FAIL() << "Unexpected failure: All tests disabled in test case. "
3170  "TearDownTestSuite() should not be called.";
3171  }
3172 };
3173 
3174 TEST_F(DisabledTestsTest, DISABLED_TestShouldNotRun_1) {
3175  FAIL() << "Unexpected failure: Disabled test should not be run.";
3176 }
3177 
3178 TEST_F(DisabledTestsTest, DISABLED_TestShouldNotRun_2) {
3179  FAIL() << "Unexpected failure: Disabled test should not be run.";
3180 }
3181 
3182 // Tests that disabled typed tests aren't run.
3183 
3184 #if GTEST_HAS_TYPED_TEST
3185 
3186 template <typename T>
3187 class TypedTest : public Test {
3188 };
3189 
3192 
3193 TYPED_TEST(TypedTest, DISABLED_ShouldNotRun) {
3194  FAIL() << "Unexpected failure: Disabled typed test should not run.";
3195 }
3196 
3197 template <typename T>
3198 class DISABLED_TypedTest : public Test {
3199 };
3200 
3201 TYPED_TEST_SUITE(DISABLED_TypedTest, NumericTypes);
3202 
3203 TYPED_TEST(DISABLED_TypedTest, ShouldNotRun) {
3204  FAIL() << "Unexpected failure: Disabled typed test should not run.";
3205 }
3206 
3207 #endif // GTEST_HAS_TYPED_TEST
3208 
3209 // Tests that disabled type-parameterized tests aren't run.
3210 
3211 #if GTEST_HAS_TYPED_TEST_P
3212 
3213 template <typename T>
3214 class TypedTestP : public Test {
3215 };
3216 
3218 
3219 TYPED_TEST_P(TypedTestP, DISABLED_ShouldNotRun) {
3220  FAIL() << "Unexpected failure: "
3221  << "Disabled type-parameterized test should not run.";
3222 }
3223 
3224 REGISTER_TYPED_TEST_SUITE_P(TypedTestP, DISABLED_ShouldNotRun);
3225 
3227 
3228 template <typename T>
3229 class DISABLED_TypedTestP : public Test {
3230 };
3231 
3232 TYPED_TEST_SUITE_P(DISABLED_TypedTestP);
3233 
3234 TYPED_TEST_P(DISABLED_TypedTestP, ShouldNotRun) {
3235  FAIL() << "Unexpected failure: "
3236  << "Disabled type-parameterized test should not run.";
3237 }
3238 
3239 REGISTER_TYPED_TEST_SUITE_P(DISABLED_TypedTestP, ShouldNotRun);
3240 
3241 INSTANTIATE_TYPED_TEST_SUITE_P(My, DISABLED_TypedTestP, NumericTypes);
3242 
3243 #endif // GTEST_HAS_TYPED_TEST_P
3244 
3245 // Tests that assertion macros evaluate their arguments exactly once.
3246 
3247 class SingleEvaluationTest : public Test {
3248  public: // Must be public and not protected due to a bug in g++ 3.4.2.
3249  // This helper function is needed by the FailedASSERT_STREQ test
3250  // below. It's public to work around C++Builder's bug with scoping local
3251  // classes.
3252  static void CompareAndIncrementCharPtrs() {
3253  ASSERT_STREQ(p1_++, p2_++);
3254  }
3255 
3256  // This helper function is needed by the FailedASSERT_NE test below. It's
3257  // public to work around C++Builder's bug with scoping local classes.
3258  static void CompareAndIncrementInts() {
3259  ASSERT_NE(a_++, b_++);
3260  }
3261 
3262  protected:
3263  SingleEvaluationTest() {
3264  p1_ = s1_;
3265  p2_ = s2_;
3266  a_ = 0;
3267  b_ = 0;
3268  }
3269 
3270  static const char* const s1_;
3271  static const char* const s2_;
3272  static const char* p1_;
3273  static const char* p2_;
3274 
3275  static int a_;
3276  static int b_;
3277 };
3278 
3279 const char* const SingleEvaluationTest::s1_ = "01234";
3280 const char* const SingleEvaluationTest::s2_ = "abcde";
3281 const char* SingleEvaluationTest::p1_;
3282 const char* SingleEvaluationTest::p2_;
3285 
3286 // Tests that when ASSERT_STREQ fails, it evaluates its arguments
3287 // exactly once.
3288 TEST_F(SingleEvaluationTest, FailedASSERT_STREQ) {
3289  EXPECT_FATAL_FAILURE(SingleEvaluationTest::CompareAndIncrementCharPtrs(),
3290  "p2_++");
3291  EXPECT_EQ(s1_ + 1, p1_);
3292  EXPECT_EQ(s2_ + 1, p2_);
3293 }
3294 
3295 // Tests that string assertion arguments are evaluated exactly once.
3296 TEST_F(SingleEvaluationTest, ASSERT_STR) {
3297  // successful EXPECT_STRNE
3298  EXPECT_STRNE(p1_++, p2_++);
3299  EXPECT_EQ(s1_ + 1, p1_);
3300  EXPECT_EQ(s2_ + 1, p2_);
3301 
3302  // failed EXPECT_STRCASEEQ
3304  "Ignoring case");
3305  EXPECT_EQ(s1_ + 2, p1_);
3306  EXPECT_EQ(s2_ + 2, p2_);
3307 }
3308 
3309 // Tests that when ASSERT_NE fails, it evaluates its arguments exactly
3310 // once.
3311 TEST_F(SingleEvaluationTest, FailedASSERT_NE) {
3312  EXPECT_FATAL_FAILURE(SingleEvaluationTest::CompareAndIncrementInts(),
3313  "(a_++) != (b_++)");
3314  EXPECT_EQ(1, a_);
3315  EXPECT_EQ(1, b_);
3316 }
3317 
3318 // Tests that assertion arguments are evaluated exactly once.
3319 TEST_F(SingleEvaluationTest, OtherCases) {
3320  // successful EXPECT_TRUE
3321  EXPECT_TRUE(0 == a_++); // NOLINT
3322  EXPECT_EQ(1, a_);
3323 
3324  // failed EXPECT_TRUE
3325  EXPECT_NONFATAL_FAILURE(EXPECT_TRUE(-1 == a_++), "-1 == a_++");
3326  EXPECT_EQ(2, a_);
3327 
3328  // successful EXPECT_GT
3329  EXPECT_GT(a_++, b_++);
3330  EXPECT_EQ(3, a_);
3331  EXPECT_EQ(1, b_);
3332 
3333  // failed EXPECT_LT
3334  EXPECT_NONFATAL_FAILURE(EXPECT_LT(a_++, b_++), "(a_++) < (b_++)");
3335  EXPECT_EQ(4, a_);
3336  EXPECT_EQ(2, b_);
3337 
3338  // successful ASSERT_TRUE
3339  ASSERT_TRUE(0 < a_++); // NOLINT
3340  EXPECT_EQ(5, a_);
3341 
3342  // successful ASSERT_GT
3343  ASSERT_GT(a_++, b_++);
3344  EXPECT_EQ(6, a_);
3345  EXPECT_EQ(3, b_);
3346 }
3347 
3348 #if GTEST_HAS_EXCEPTIONS
3349 
3350 void ThrowAnInteger() {
3351  throw 1;
3352 }
3353 
3354 // Tests that assertion arguments are evaluated exactly once.
3355 TEST_F(SingleEvaluationTest, ExceptionTests) {
3356  // successful EXPECT_THROW
3357  EXPECT_THROW({ // NOLINT
3358  a_++;
3359  ThrowAnInteger();
3360  }, int);
3361  EXPECT_EQ(1, a_);
3362 
3363  // failed EXPECT_THROW, throws different
3365  a_++;
3366  ThrowAnInteger();
3367  }, bool), "throws a different type");
3368  EXPECT_EQ(2, a_);
3369 
3370  // failed EXPECT_THROW, throws nothing
3371  EXPECT_NONFATAL_FAILURE(EXPECT_THROW(a_++, bool), "throws nothing");
3372  EXPECT_EQ(3, a_);
3373 
3374  // successful EXPECT_NO_THROW
3375  EXPECT_NO_THROW(a_++);
3376  EXPECT_EQ(4, a_);
3377 
3378  // failed EXPECT_NO_THROW
3380  a_++;
3381  ThrowAnInteger();
3382  }), "it throws");
3383  EXPECT_EQ(5, a_);
3384 
3385  // successful EXPECT_ANY_THROW
3386  EXPECT_ANY_THROW({ // NOLINT
3387  a_++;
3388  ThrowAnInteger();
3389  });
3390  EXPECT_EQ(6, a_);
3391 
3392  // failed EXPECT_ANY_THROW
3393  EXPECT_NONFATAL_FAILURE(EXPECT_ANY_THROW(a_++), "it doesn't");
3394  EXPECT_EQ(7, a_);
3395 }
3396 
3397 #endif // GTEST_HAS_EXCEPTIONS
3398 
3399 // Tests {ASSERT|EXPECT}_NO_FATAL_FAILURE.
3400 class NoFatalFailureTest : public Test {
3401  protected:
3402  void Succeeds() {}
3403  void FailsNonFatal() {
3404  ADD_FAILURE() << "some non-fatal failure";
3405  }
3406  void Fails() {
3407  FAIL() << "some fatal failure";
3408  }
3409 
3410  void DoAssertNoFatalFailureOnFails() {
3411  ASSERT_NO_FATAL_FAILURE(Fails());
3412  ADD_FAILURE() << "should not reach here.";
3413  }
3414 
3415  void DoExpectNoFatalFailureOnFails() {
3416  EXPECT_NO_FATAL_FAILURE(Fails());
3417  ADD_FAILURE() << "other failure";
3418  }
3419 };
3420 
3421 TEST_F(NoFatalFailureTest, NoFailure) {
3422  EXPECT_NO_FATAL_FAILURE(Succeeds());
3423  ASSERT_NO_FATAL_FAILURE(Succeeds());
3424 }
3425 
3426 TEST_F(NoFatalFailureTest, NonFatalIsNoFailure) {
3428  EXPECT_NO_FATAL_FAILURE(FailsNonFatal()),
3429  "some non-fatal failure");
3431  ASSERT_NO_FATAL_FAILURE(FailsNonFatal()),
3432  "some non-fatal failure");
3433 }
3434 
3435 TEST_F(NoFatalFailureTest, AssertNoFatalFailureOnFatalFailure) {
3436  TestPartResultArray gtest_failures;
3437  {
3438  ScopedFakeTestPartResultReporter gtest_reporter(&gtest_failures);
3439  DoAssertNoFatalFailureOnFails();
3440  }
3441  ASSERT_EQ(2, gtest_failures.size());
3442  EXPECT_EQ(TestPartResult::kFatalFailure,
3443  gtest_failures.GetTestPartResult(0).type());
3444  EXPECT_EQ(TestPartResult::kFatalFailure,
3445  gtest_failures.GetTestPartResult(1).type());
3446  EXPECT_PRED_FORMAT2(testing::IsSubstring, "some fatal failure",
3447  gtest_failures.GetTestPartResult(0).message());
3449  gtest_failures.GetTestPartResult(1).message());
3450 }
3451 
3452 TEST_F(NoFatalFailureTest, ExpectNoFatalFailureOnFatalFailure) {
3453  TestPartResultArray gtest_failures;
3454  {
3455  ScopedFakeTestPartResultReporter gtest_reporter(&gtest_failures);
3456  DoExpectNoFatalFailureOnFails();
3457  }
3458  ASSERT_EQ(3, gtest_failures.size());
3459  EXPECT_EQ(TestPartResult::kFatalFailure,
3460  gtest_failures.GetTestPartResult(0).type());
3461  EXPECT_EQ(TestPartResult::kNonFatalFailure,
3462  gtest_failures.GetTestPartResult(1).type());
3463  EXPECT_EQ(TestPartResult::kNonFatalFailure,
3464  gtest_failures.GetTestPartResult(2).type());
3465  EXPECT_PRED_FORMAT2(testing::IsSubstring, "some fatal failure",
3466  gtest_failures.GetTestPartResult(0).message());
3468  gtest_failures.GetTestPartResult(1).message());
3469  EXPECT_PRED_FORMAT2(testing::IsSubstring, "other failure",
3470  gtest_failures.GetTestPartResult(2).message());
3471 }
3472 
3473 TEST_F(NoFatalFailureTest, MessageIsStreamable) {
3474  TestPartResultArray gtest_failures;
3475  {
3476  ScopedFakeTestPartResultReporter gtest_reporter(&gtest_failures);
3477  EXPECT_NO_FATAL_FAILURE(FAIL() << "foo") << "my message";
3478  }
3479  ASSERT_EQ(2, gtest_failures.size());
3480  EXPECT_EQ(TestPartResult::kNonFatalFailure,
3481  gtest_failures.GetTestPartResult(0).type());
3482  EXPECT_EQ(TestPartResult::kNonFatalFailure,
3483  gtest_failures.GetTestPartResult(1).type());
3485  gtest_failures.GetTestPartResult(0).message());
3487  gtest_failures.GetTestPartResult(1).message());
3488 }
3489 
3490 // Tests non-string assertions.
3491 
3492 std::string EditsToString(const std::vector<EditType>& edits) {
3493  std::string out;
3494  for (size_t i = 0; i < edits.size(); ++i) {
3495  static const char kEdits[] = " +-/";
3496  out.append(1, kEdits[edits[i]]);
3497  }
3498  return out;
3499 }
3500 
3501 std::vector<size_t> CharsToIndices(const std::string& str) {
3502  std::vector<size_t> out;
3503  for (size_t i = 0; i < str.size(); ++i) {
3504  out.push_back(static_cast<size_t>(str[i]));
3505  }
3506  return out;
3507 }
3508 
3509 std::vector<std::string> CharsToLines(const std::string& str) {
3510  std::vector<std::string> out;
3511  for (size_t i = 0; i < str.size(); ++i) {
3512  out.push_back(str.substr(i, 1));
3513  }
3514  return out;
3515 }
3516 
3517 TEST(EditDistance, TestSuites) {
3518  struct Case {
3519  int line;
3520  const char* left;
3521  const char* right;
3522  const char* expected_edits;
3523  const char* expected_diff;
3524  };
3525  static const Case kCases[] = {
3526  // No change.
3527  {__LINE__, "A", "A", " ", ""},
3528  {__LINE__, "ABCDE", "ABCDE", " ", ""},
3529  // Simple adds.
3530  {__LINE__, "X", "XA", " +", "@@ +1,2 @@\n X\n+A\n"},
3531  {__LINE__, "X", "XABCD", " ++++", "@@ +1,5 @@\n X\n+A\n+B\n+C\n+D\n"},
3532  // Simple removes.
3533  {__LINE__, "XA", "X", " -", "@@ -1,2 @@\n X\n-A\n"},
3534  {__LINE__, "XABCD", "X", " ----", "@@ -1,5 @@\n X\n-A\n-B\n-C\n-D\n"},
3535  // Simple replaces.
3536  {__LINE__, "A", "a", "/", "@@ -1,1 +1,1 @@\n-A\n+a\n"},
3537  {__LINE__, "ABCD", "abcd", "////",
3538  "@@ -1,4 +1,4 @@\n-A\n-B\n-C\n-D\n+a\n+b\n+c\n+d\n"},
3539  // Path finding.
3540  {__LINE__, "ABCDEFGH", "ABXEGH1", " -/ - +",
3541  "@@ -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"},
3542  {__LINE__, "AAAABCCCC", "ABABCDCDC", "- / + / ",
3543  "@@ -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"},
3544  {__LINE__, "ABCDE", "BCDCD", "- +/",
3545  "@@ -1,5 +1,5 @@\n-A\n B\n C\n D\n-E\n+C\n+D\n"},
3546  {__LINE__, "ABCDEFGHIJKL", "BCDCDEFGJKLJK", "- ++ -- ++",
3547  "@@ -1,4 +1,5 @@\n-A\n B\n+C\n+D\n C\n D\n"
3548  "@@ -6,7 +7,7 @@\n F\n G\n-H\n-I\n J\n K\n L\n+J\n+K\n"},
3549  {}};
3550  for (const Case* c = kCases; c->left; ++c) {
3551  EXPECT_TRUE(c->expected_edits ==
3552  EditsToString(CalculateOptimalEdits(CharsToIndices(c->left),
3553  CharsToIndices(c->right))))
3554  << "Left <" << c->left << "> Right <" << c->right << "> Edits <"
3555  << EditsToString(CalculateOptimalEdits(
3556  CharsToIndices(c->left), CharsToIndices(c->right))) << ">";
3557  EXPECT_TRUE(c->expected_diff == CreateUnifiedDiff(CharsToLines(c->left),
3558  CharsToLines(c->right)))
3559  << "Left <" << c->left << "> Right <" << c->right << "> Diff <"
3560  << CreateUnifiedDiff(CharsToLines(c->left), CharsToLines(c->right))
3561  << ">";
3562  }
3563 }
3564 
3565 // Tests EqFailure(), used for implementing *EQ* assertions.
3566 TEST(AssertionTest, EqFailure) {
3567  const std::string foo_val("5"), bar_val("6");
3568  const std::string msg1(
3569  EqFailure("foo", "bar", foo_val, bar_val, false)
3570  .failure_message());
3571  EXPECT_STREQ(
3572  "Expected equality of these values:\n"
3573  " foo\n"
3574  " Which is: 5\n"
3575  " bar\n"
3576  " Which is: 6",
3577  msg1.c_str());
3578 
3579  const std::string msg2(
3580  EqFailure("foo", "6", foo_val, bar_val, false)
3581  .failure_message());
3582  EXPECT_STREQ(
3583  "Expected equality of these values:\n"
3584  " foo\n"
3585  " Which is: 5\n"
3586  " 6",
3587  msg2.c_str());
3588 
3589  const std::string msg3(
3590  EqFailure("5", "bar", foo_val, bar_val, false)
3591  .failure_message());
3592  EXPECT_STREQ(
3593  "Expected equality of these values:\n"
3594  " 5\n"
3595  " bar\n"
3596  " Which is: 6",
3597  msg3.c_str());
3598 
3599  const std::string msg4(
3600  EqFailure("5", "6", foo_val, bar_val, false).failure_message());
3601  EXPECT_STREQ(
3602  "Expected equality of these values:\n"
3603  " 5\n"
3604  " 6",
3605  msg4.c_str());
3606 
3607  const std::string msg5(
3608  EqFailure("foo", "bar",
3609  std::string("\"x\""), std::string("\"y\""),
3610  true).failure_message());
3611  EXPECT_STREQ(
3612  "Expected equality of these values:\n"
3613  " foo\n"
3614  " Which is: \"x\"\n"
3615  " bar\n"
3616  " Which is: \"y\"\n"
3617  "Ignoring case",
3618  msg5.c_str());
3619 }
3620 
3621 TEST(AssertionTest, EqFailureWithDiff) {
3622  const std::string left(
3623  "1\\n2XXX\\n3\\n5\\n6\\n7\\n8\\n9\\n10\\n11\\n12XXX\\n13\\n14\\n15");
3624  const std::string right(
3625  "1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n11\\n12\\n13\\n14");
3626  const std::string msg1(
3627  EqFailure("left", "right", left, right, false).failure_message());
3628  EXPECT_STREQ(
3629  "Expected equality of these values:\n"
3630  " left\n"
3631  " Which is: "
3632  "1\\n2XXX\\n3\\n5\\n6\\n7\\n8\\n9\\n10\\n11\\n12XXX\\n13\\n14\\n15\n"
3633  " right\n"
3634  " Which is: 1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n11\\n12\\n13\\n14\n"
3635  "With diff:\n@@ -1,5 +1,6 @@\n 1\n-2XXX\n+2\n 3\n+4\n 5\n 6\n"
3636  "@@ -7,8 +8,6 @@\n 8\n 9\n-10\n 11\n-12XXX\n+12\n 13\n 14\n-15\n",
3637  msg1.c_str());
3638 }
3639 
3640 // Tests AppendUserMessage(), used for implementing the *EQ* macros.
3641 TEST(AssertionTest, AppendUserMessage) {
3642  const std::string foo("foo");
3643 
3644  Message msg;
3645  EXPECT_STREQ("foo",
3647 
3648  msg << "bar";
3649  EXPECT_STREQ("foo\nbar",
3651 }
3652 
3653 #ifdef __BORLANDC__
3654 // Silences warnings: "Condition is always true", "Unreachable code"
3655 # pragma option push -w-ccc -w-rch
3656 #endif
3657 
3658 // Tests ASSERT_TRUE.
3659 TEST(AssertionTest, ASSERT_TRUE) {
3660  ASSERT_TRUE(2 > 1); // NOLINT
3662  "2 < 1");
3663 }
3664 
3665 // Tests ASSERT_TRUE(predicate) for predicates returning AssertionResult.
3666 TEST(AssertionTest, AssertTrueWithAssertionResult) {
3667  ASSERT_TRUE(ResultIsEven(2));
3668 #ifndef __BORLANDC__
3669  // ICE's in C++Builder.
3670  EXPECT_FATAL_FAILURE(ASSERT_TRUE(ResultIsEven(3)),
3671  "Value of: ResultIsEven(3)\n"
3672  " Actual: false (3 is odd)\n"
3673  "Expected: true");
3674 #endif
3675  ASSERT_TRUE(ResultIsEvenNoExplanation(2));
3676  EXPECT_FATAL_FAILURE(ASSERT_TRUE(ResultIsEvenNoExplanation(3)),
3677  "Value of: ResultIsEvenNoExplanation(3)\n"
3678  " Actual: false (3 is odd)\n"
3679  "Expected: true");
3680 }
3681 
3682 // Tests ASSERT_FALSE.
3683 TEST(AssertionTest, ASSERT_FALSE) {
3684  ASSERT_FALSE(2 < 1); // NOLINT
3686  "Value of: 2 > 1\n"
3687  " Actual: true\n"
3688  "Expected: false");
3689 }
3690 
3691 // Tests ASSERT_FALSE(predicate) for predicates returning AssertionResult.
3692 TEST(AssertionTest, AssertFalseWithAssertionResult) {
3693  ASSERT_FALSE(ResultIsEven(3));
3694 #ifndef __BORLANDC__
3695  // ICE's in C++Builder.
3696  EXPECT_FATAL_FAILURE(ASSERT_FALSE(ResultIsEven(2)),
3697  "Value of: ResultIsEven(2)\n"
3698  " Actual: true (2 is even)\n"
3699  "Expected: false");
3700 #endif
3701  ASSERT_FALSE(ResultIsEvenNoExplanation(3));
3702  EXPECT_FATAL_FAILURE(ASSERT_FALSE(ResultIsEvenNoExplanation(2)),
3703  "Value of: ResultIsEvenNoExplanation(2)\n"
3704  " Actual: true\n"
3705  "Expected: false");
3706 }
3707 
3708 #ifdef __BORLANDC__
3709 // Restores warnings after previous "#pragma option push" suppressed them
3710 # pragma option pop
3711 #endif
3712 
3713 // Tests using ASSERT_EQ on double values. The purpose is to make
3714 // sure that the specialization we did for integer and anonymous enums
3715 // isn't used for double arguments.
3716 TEST(ExpectTest, ASSERT_EQ_Double) {
3717  // A success.
3718  ASSERT_EQ(5.6, 5.6);
3719 
3720  // A failure.
3721  EXPECT_FATAL_FAILURE(ASSERT_EQ(5.1, 5.2),
3722  "5.1");
3723 }
3724 
3725 // Tests ASSERT_EQ.
3726 TEST(AssertionTest, ASSERT_EQ) {
3727  ASSERT_EQ(5, 2 + 3);
3729  "Expected equality of these values:\n"
3730  " 5\n"
3731  " 2*3\n"
3732  " Which is: 6");
3733 }
3734 
3735 // Tests ASSERT_EQ(NULL, pointer).
3736 TEST(AssertionTest, ASSERT_EQ_NULL) {
3737  // A success.
3738  const char* p = nullptr;
3739  // Some older GCC versions may issue a spurious warning in this or the next
3740  // assertion statement. This warning should not be suppressed with
3741  // static_cast since the test verifies the ability to use bare NULL as the
3742  // expected parameter to the macro.
3743  ASSERT_EQ(nullptr, p);
3744 
3745  // A failure.
3746  static int n = 0;
3747  EXPECT_FATAL_FAILURE(ASSERT_EQ(nullptr, &n), " &n\n Which is:");
3748 }
3749 
3750 // Tests ASSERT_EQ(0, non_pointer). Since the literal 0 can be
3751 // treated as a null pointer by the compiler, we need to make sure
3752 // that ASSERT_EQ(0, non_pointer) isn't interpreted by Google Test as
3753 // ASSERT_EQ(static_cast<void*>(NULL), non_pointer).
3754 TEST(ExpectTest, ASSERT_EQ_0) {
3755  int n = 0;
3756 
3757  // A success.
3758  ASSERT_EQ(0, n);
3759 
3760  // A failure.
3762  " 0\n 5.6");
3763 }
3764 
3765 // Tests ASSERT_NE.
3766 TEST(AssertionTest, ASSERT_NE) {
3767  ASSERT_NE(6, 7);
3768  EXPECT_FATAL_FAILURE(ASSERT_NE('a', 'a'),
3769  "Expected: ('a') != ('a'), "
3770  "actual: 'a' (97, 0x61) vs 'a' (97, 0x61)");
3771 }
3772 
3773 // Tests ASSERT_LE.
3774 TEST(AssertionTest, ASSERT_LE) {
3775  ASSERT_LE(2, 3);
3776  ASSERT_LE(2, 2);
3778  "Expected: (2) <= (0), actual: 2 vs 0");
3779 }
3780 
3781 // Tests ASSERT_LT.
3782 TEST(AssertionTest, ASSERT_LT) {
3783  ASSERT_LT(2, 3);
3785  "Expected: (2) < (2), actual: 2 vs 2");
3786 }
3787 
3788 // Tests ASSERT_GE.
3789 TEST(AssertionTest, ASSERT_GE) {
3790  ASSERT_GE(2, 1);
3791  ASSERT_GE(2, 2);
3793  "Expected: (2) >= (3), actual: 2 vs 3");
3794 }
3795 
3796 // Tests ASSERT_GT.
3797 TEST(AssertionTest, ASSERT_GT) {
3798  ASSERT_GT(2, 1);
3800  "Expected: (2) > (2), actual: 2 vs 2");
3801 }
3802 
3803 #if GTEST_HAS_EXCEPTIONS
3804 
3805 void ThrowNothing() {}
3806 
3807 // Tests ASSERT_THROW.
3808 TEST(AssertionTest, ASSERT_THROW) {
3809  ASSERT_THROW(ThrowAnInteger(), int);
3810 
3811 # ifndef __BORLANDC__
3812 
3813  // ICE's in C++Builder 2007 and 2009.
3815  ASSERT_THROW(ThrowAnInteger(), bool),
3816  "Expected: ThrowAnInteger() throws an exception of type bool.\n"
3817  " Actual: it throws a different type.");
3818 # endif
3819 
3821  ASSERT_THROW(ThrowNothing(), bool),
3822  "Expected: ThrowNothing() throws an exception of type bool.\n"
3823  " Actual: it throws nothing.");
3824 }
3825 
3826 // Tests ASSERT_NO_THROW.
3827 TEST(AssertionTest, ASSERT_NO_THROW) {
3828  ASSERT_NO_THROW(ThrowNothing());
3829  EXPECT_FATAL_FAILURE(ASSERT_NO_THROW(ThrowAnInteger()),
3830  "Expected: ThrowAnInteger() doesn't throw an exception."
3831  "\n Actual: it throws.");
3832 }
3833 
3834 // Tests ASSERT_ANY_THROW.
3835 TEST(AssertionTest, ASSERT_ANY_THROW) {
3836  ASSERT_ANY_THROW(ThrowAnInteger());
3838  ASSERT_ANY_THROW(ThrowNothing()),
3839  "Expected: ThrowNothing() throws an exception.\n"
3840  " Actual: it doesn't.");
3841 }
3842 
3843 #endif // GTEST_HAS_EXCEPTIONS
3844 
3845 // Makes sure we deal with the precedence of <<. This test should
3846 // compile.
3847 TEST(AssertionTest, AssertPrecedence) {
3848  ASSERT_EQ(1 < 2, true);
3849  bool false_value = false;
3850  ASSERT_EQ(true && false_value, false);
3851 }
3852 
3853 // A subroutine used by the following test.
3854 void TestEq1(int x) {
3855  ASSERT_EQ(1, x);
3856 }
3857 
3858 // Tests calling a test subroutine that's not part of a fixture.
3859 TEST(AssertionTest, NonFixtureSubroutine) {
3861  " x\n Which is: 2");
3862 }
3863 
3864 // An uncopyable class.
3865 class Uncopyable {
3866  public:
3867  explicit Uncopyable(int a_value) : value_(a_value) {}
3868 
3869  int value() const { return value_; }
3870  bool operator==(const Uncopyable& rhs) const {
3871  return value() == rhs.value();
3872  }
3873  private:
3874  // This constructor deliberately has no implementation, as we don't
3875  // want this class to be copyable.
3876  Uncopyable(const Uncopyable&); // NOLINT
3877 
3878  int value_;
3879 };
3880 
3881 ::std::ostream& operator<<(::std::ostream& os, const Uncopyable& value) {
3882  return os << value.value();
3883 }
3884 
3885 
3886 bool IsPositiveUncopyable(const Uncopyable& x) {
3887  return x.value() > 0;
3888 }
3889 
3890 // A subroutine used by the following test.
3891 void TestAssertNonPositive() {
3892  Uncopyable y(-1);
3893  ASSERT_PRED1(IsPositiveUncopyable, y);
3894 }
3895 // A subroutine used by the following test.
3896 void TestAssertEqualsUncopyable() {
3897  Uncopyable x(5);
3898  Uncopyable y(-1);
3899  ASSERT_EQ(x, y);
3900 }
3901 
3902 // Tests that uncopyable objects can be used in assertions.
3903 TEST(AssertionTest, AssertWorksWithUncopyableObject) {
3904  Uncopyable x(5);
3905  ASSERT_PRED1(IsPositiveUncopyable, x);
3906  ASSERT_EQ(x, x);
3907  EXPECT_FATAL_FAILURE(TestAssertNonPositive(),
3908  "IsPositiveUncopyable(y) evaluates to false, where\ny evaluates to -1");
3909  EXPECT_FATAL_FAILURE(TestAssertEqualsUncopyable(),
3910  "Expected equality of these values:\n"
3911  " x\n Which is: 5\n y\n Which is: -1");
3912 }
3913 
3914 // Tests that uncopyable objects can be used in expects.
3915 TEST(AssertionTest, ExpectWorksWithUncopyableObject) {
3916  Uncopyable x(5);
3917  EXPECT_PRED1(IsPositiveUncopyable, x);
3918  Uncopyable y(-1);
3919  EXPECT_NONFATAL_FAILURE(EXPECT_PRED1(IsPositiveUncopyable, y),
3920  "IsPositiveUncopyable(y) evaluates to false, where\ny evaluates to -1");
3921  EXPECT_EQ(x, x);
3923  "Expected equality of these values:\n"
3924  " x\n Which is: 5\n y\n Which is: -1");
3925 }
3926 
3927 enum NamedEnum {
3928  kE1 = 0,
3929  kE2 = 1
3930 };
3931 
3932 TEST(AssertionTest, NamedEnum) {
3933  EXPECT_EQ(kE1, kE1);
3934  EXPECT_LT(kE1, kE2);
3935  EXPECT_NONFATAL_FAILURE(EXPECT_EQ(kE1, kE2), "Which is: 0");
3936  EXPECT_NONFATAL_FAILURE(EXPECT_EQ(kE1, kE2), "Which is: 1");
3937 }
3938 
3939 // Sun Studio and HP aCC2reject this code.
3940 #if !defined(__SUNPRO_CC) && !defined(__HP_aCC)
3941 
3942 // Tests using assertions with anonymous enums.
3943 enum {
3944  kCaseA = -1,
3945 
3946 # if GTEST_OS_LINUX
3947 
3948  // We want to test the case where the size of the anonymous enum is
3949  // larger than sizeof(int), to make sure our implementation of the
3950  // assertions doesn't truncate the enums. However, MSVC
3951  // (incorrectly) doesn't allow an enum value to exceed the range of
3952  // an int, so this has to be conditionally compiled.
3953  //
3954  // On Linux, kCaseB and kCaseA have the same value when truncated to
3955  // int size. We want to test whether this will confuse the
3956  // assertions.
3958 
3959 # else
3960 
3961  kCaseB = INT_MAX,
3962 
3963 # endif // GTEST_OS_LINUX
3964 
3965  kCaseC = 42
3966 };
3967 
3968 TEST(AssertionTest, AnonymousEnum) {
3969 # if GTEST_OS_LINUX
3970 
3971  EXPECT_EQ(static_cast<int>(kCaseA), static_cast<int>(kCaseB));
3972 
3973 # endif // GTEST_OS_LINUX
3974 
3975  EXPECT_EQ(kCaseA, kCaseA);
3976  EXPECT_NE(kCaseA, kCaseB);
3977  EXPECT_LT(kCaseA, kCaseB);
3978  EXPECT_LE(kCaseA, kCaseB);
3979  EXPECT_GT(kCaseB, kCaseA);
3980  EXPECT_GE(kCaseA, kCaseA);
3981  EXPECT_NONFATAL_FAILURE(EXPECT_GE(kCaseA, kCaseB),
3982  "(kCaseA) >= (kCaseB)");
3983  EXPECT_NONFATAL_FAILURE(EXPECT_GE(kCaseA, kCaseC),
3984  "-1 vs 42");
3985 
3986  ASSERT_EQ(kCaseA, kCaseA);
3987  ASSERT_NE(kCaseA, kCaseB);
3988  ASSERT_LT(kCaseA, kCaseB);
3989  ASSERT_LE(kCaseA, kCaseB);
3990  ASSERT_GT(kCaseB, kCaseA);
3991  ASSERT_GE(kCaseA, kCaseA);
3992 
3993 # ifndef __BORLANDC__
3994 
3995  // ICE's in C++Builder.
3996  EXPECT_FATAL_FAILURE(ASSERT_EQ(kCaseA, kCaseB),
3997  " kCaseB\n Which is: ");
3998  EXPECT_FATAL_FAILURE(ASSERT_EQ(kCaseA, kCaseC),
3999  "\n Which is: 42");
4000 # endif
4001 
4002  EXPECT_FATAL_FAILURE(ASSERT_EQ(kCaseA, kCaseC),
4003  "\n Which is: -1");
4004 }
4005 
4006 #endif // !GTEST_OS_MAC && !defined(__SUNPRO_CC)
4007 
4008 #if GTEST_OS_WINDOWS
4009 
4010 static HRESULT UnexpectedHRESULTFailure() {
4011  return E_UNEXPECTED;
4012 }
4013 
4014 static HRESULT OkHRESULTSuccess() {
4015  return S_OK;
4016 }
4017 
4018 static HRESULT FalseHRESULTSuccess() {
4019  return S_FALSE;
4020 }
4021 
4022 // HRESULT assertion tests test both zero and non-zero
4023 // success codes as well as failure message for each.
4024 //
4025 // Windows CE doesn't support message texts.
4026 TEST(HRESULTAssertionTest, EXPECT_HRESULT_SUCCEEDED) {
4027  EXPECT_HRESULT_SUCCEEDED(S_OK);
4028  EXPECT_HRESULT_SUCCEEDED(S_FALSE);
4029 
4030  EXPECT_NONFATAL_FAILURE(EXPECT_HRESULT_SUCCEEDED(UnexpectedHRESULTFailure()),
4031  "Expected: (UnexpectedHRESULTFailure()) succeeds.\n"
4032  " Actual: 0x8000FFFF");
4033 }
4034 
4035 TEST(HRESULTAssertionTest, ASSERT_HRESULT_SUCCEEDED) {
4036  ASSERT_HRESULT_SUCCEEDED(S_OK);
4037  ASSERT_HRESULT_SUCCEEDED(S_FALSE);
4038 
4039  EXPECT_FATAL_FAILURE(ASSERT_HRESULT_SUCCEEDED(UnexpectedHRESULTFailure()),
4040  "Expected: (UnexpectedHRESULTFailure()) succeeds.\n"
4041  " Actual: 0x8000FFFF");
4042 }
4043 
4044 TEST(HRESULTAssertionTest, EXPECT_HRESULT_FAILED) {
4045  EXPECT_HRESULT_FAILED(E_UNEXPECTED);
4046 
4047  EXPECT_NONFATAL_FAILURE(EXPECT_HRESULT_FAILED(OkHRESULTSuccess()),
4048  "Expected: (OkHRESULTSuccess()) fails.\n"
4049  " Actual: 0x0");
4050  EXPECT_NONFATAL_FAILURE(EXPECT_HRESULT_FAILED(FalseHRESULTSuccess()),
4051  "Expected: (FalseHRESULTSuccess()) fails.\n"
4052  " Actual: 0x1");
4053 }
4054 
4055 TEST(HRESULTAssertionTest, ASSERT_HRESULT_FAILED) {
4056  ASSERT_HRESULT_FAILED(E_UNEXPECTED);
4057 
4058 # ifndef __BORLANDC__
4059 
4060  // ICE's in C++Builder 2007 and 2009.
4061  EXPECT_FATAL_FAILURE(ASSERT_HRESULT_FAILED(OkHRESULTSuccess()),
4062  "Expected: (OkHRESULTSuccess()) fails.\n"
4063  " Actual: 0x0");
4064 # endif
4065 
4066  EXPECT_FATAL_FAILURE(ASSERT_HRESULT_FAILED(FalseHRESULTSuccess()),
4067  "Expected: (FalseHRESULTSuccess()) fails.\n"
4068  " Actual: 0x1");
4069 }
4070 
4071 // Tests that streaming to the HRESULT macros works.
4072 TEST(HRESULTAssertionTest, Streaming) {
4073  EXPECT_HRESULT_SUCCEEDED(S_OK) << "unexpected failure";
4074  ASSERT_HRESULT_SUCCEEDED(S_OK) << "unexpected failure";
4075  EXPECT_HRESULT_FAILED(E_UNEXPECTED) << "unexpected failure";
4076  ASSERT_HRESULT_FAILED(E_UNEXPECTED) << "unexpected failure";
4077 
4079  EXPECT_HRESULT_SUCCEEDED(E_UNEXPECTED) << "expected failure",
4080  "expected failure");
4081 
4082 # ifndef __BORLANDC__
4083 
4084  // ICE's in C++Builder 2007 and 2009.
4086  ASSERT_HRESULT_SUCCEEDED(E_UNEXPECTED) << "expected failure",
4087  "expected failure");
4088 # endif
4089 
4091  EXPECT_HRESULT_FAILED(S_OK) << "expected failure",
4092  "expected failure");
4093 
4095  ASSERT_HRESULT_FAILED(S_OK) << "expected failure",
4096  "expected failure");
4097 }
4098 
4099 #endif // GTEST_OS_WINDOWS
4100 
4101 #ifdef __BORLANDC__
4102 // Silences warnings: "Condition is always true", "Unreachable code"
4103 # pragma option push -w-ccc -w-rch
4104 #endif
4105 
4106 // Tests that the assertion macros behave like single statements.
4107 TEST(AssertionSyntaxTest, BasicAssertionsBehavesLikeSingleStatement) {
4108  if (AlwaysFalse())
4109  ASSERT_TRUE(false) << "This should never be executed; "
4110  "It's a compilation test only.";
4111 
4112  if (AlwaysTrue())
4113  EXPECT_FALSE(false);
4114  else
4115  ; // NOLINT
4116 
4117  if (AlwaysFalse())
4118  ASSERT_LT(1, 3);
4119 
4120  if (AlwaysFalse())
4121  ; // NOLINT
4122  else
4123  EXPECT_GT(3, 2) << "";
4124 }
4125 
4126 #if GTEST_HAS_EXCEPTIONS
4127 // Tests that the compiler will not complain about unreachable code in the
4128 // EXPECT_THROW/EXPECT_ANY_THROW/EXPECT_NO_THROW macros.
4129 TEST(ExpectThrowTest, DoesNotGenerateUnreachableCodeWarning) {
4130  int n = 0;
4131 
4132  EXPECT_THROW(throw 1, int);
4133  EXPECT_NONFATAL_FAILURE(EXPECT_THROW(n++, int), "");
4134  EXPECT_NONFATAL_FAILURE(EXPECT_THROW(throw 1, const char*), "");
4135  EXPECT_NO_THROW(n++);
4137  EXPECT_ANY_THROW(throw 1);
4139 }
4140 
4141 TEST(AssertionSyntaxTest, ExceptionAssertionsBehavesLikeSingleStatement) {
4142  if (AlwaysFalse())
4143  EXPECT_THROW(ThrowNothing(), bool);
4144 
4145  if (AlwaysTrue())
4146  EXPECT_THROW(ThrowAnInteger(), int);
4147  else
4148  ; // NOLINT
4149 
4150  if (AlwaysFalse())
4151  EXPECT_NO_THROW(ThrowAnInteger());
4152 
4153  if (AlwaysTrue())
4154  EXPECT_NO_THROW(ThrowNothing());
4155  else
4156  ; // NOLINT
4157 
4158  if (AlwaysFalse())
4159  EXPECT_ANY_THROW(ThrowNothing());
4160 
4161  if (AlwaysTrue())
4162  EXPECT_ANY_THROW(ThrowAnInteger());
4163  else
4164  ; // NOLINT
4165 }
4166 #endif // GTEST_HAS_EXCEPTIONS
4167 
4168 TEST(AssertionSyntaxTest, NoFatalFailureAssertionsBehavesLikeSingleStatement) {
4169  if (AlwaysFalse())
4170  EXPECT_NO_FATAL_FAILURE(FAIL()) << "This should never be executed. "
4171  << "It's a compilation test only.";
4172  else
4173  ; // NOLINT
4174 
4175  if (AlwaysFalse())
4176  ASSERT_NO_FATAL_FAILURE(FAIL()) << "";
4177  else
4178  ; // NOLINT
4179 
4180  if (AlwaysTrue())
4182  else
4183  ; // NOLINT
4184 
4185  if (AlwaysFalse())
4186  ; // NOLINT
4187  else
4189 }
4190 
4191 // Tests that the assertion macros work well with switch statements.
4192 TEST(AssertionSyntaxTest, WorksWithSwitch) {
4193  switch (0) {
4194  case 1:
4195  break;
4196  default:
4197  ASSERT_TRUE(true);
4198  }
4199 
4200  switch (0)
4201  case 0:
4202  EXPECT_FALSE(false) << "EXPECT_FALSE failed in switch case";
4203 
4204  // Binary assertions are implemented using a different code path
4205  // than the Boolean assertions. Hence we test them separately.
4206  switch (0) {
4207  case 1:
4208  default:
4209  ASSERT_EQ(1, 1) << "ASSERT_EQ failed in default switch handler";
4210  }
4211 
4212  switch (0)
4213  case 0:
4214  EXPECT_NE(1, 2);
4215 }
4216 
4217 #if GTEST_HAS_EXCEPTIONS
4218 
4219 void ThrowAString() {
4220  throw "std::string";
4221 }
4222 
4223 // Test that the exception assertion macros compile and work with const
4224 // type qualifier.
4225 TEST(AssertionSyntaxTest, WorksWithConst) {
4226  ASSERT_THROW(ThrowAString(), const char*);
4227 
4228  EXPECT_THROW(ThrowAString(), const char*);
4229 }
4230 
4231 #endif // GTEST_HAS_EXCEPTIONS
4232 
4233 } // namespace
4234 
4235 namespace testing {
4236 
4237 // Tests that Google Test tracks SUCCEED*.
4238 TEST(SuccessfulAssertionTest, SUCCEED) {
4239  SUCCEED();
4240  SUCCEED() << "OK";
4241  EXPECT_EQ(2, GetUnitTestImpl()->current_test_result()->total_part_count());
4242 }
4243 
4244 // Tests that Google Test doesn't track successful EXPECT_*.
4245 TEST(SuccessfulAssertionTest, EXPECT) {
4246  EXPECT_TRUE(true);
4247  EXPECT_EQ(0, GetUnitTestImpl()->current_test_result()->total_part_count());
4248 }
4249 
4250 // Tests that Google Test doesn't track successful EXPECT_STR*.
4251 TEST(SuccessfulAssertionTest, EXPECT_STR) {
4252  EXPECT_STREQ("", "");
4253  EXPECT_EQ(0, GetUnitTestImpl()->current_test_result()->total_part_count());
4254 }
4255 
4256 // Tests that Google Test doesn't track successful ASSERT_*.
4257 TEST(SuccessfulAssertionTest, ASSERT) {
4258  ASSERT_TRUE(true);
4259  EXPECT_EQ(0, GetUnitTestImpl()->current_test_result()->total_part_count());
4260 }
4261 
4262 // Tests that Google Test doesn't track successful ASSERT_STR*.
4263 TEST(SuccessfulAssertionTest, ASSERT_STR) {
4264  ASSERT_STREQ("", "");
4265  EXPECT_EQ(0, GetUnitTestImpl()->current_test_result()->total_part_count());
4266 }
4267 
4268 } // namespace testing
4269 
4270 namespace {
4271 
4272 // Tests the message streaming variation of assertions.
4273 
4274 TEST(AssertionWithMessageTest, EXPECT) {
4275  EXPECT_EQ(1, 1) << "This should succeed.";
4276  EXPECT_NONFATAL_FAILURE(EXPECT_NE(1, 1) << "Expected failure #1.",
4277  "Expected failure #1");
4278  EXPECT_LE(1, 2) << "This should succeed.";
4279  EXPECT_NONFATAL_FAILURE(EXPECT_LT(1, 0) << "Expected failure #2.",
4280  "Expected failure #2.");
4281  EXPECT_GE(1, 0) << "This should succeed.";
4282  EXPECT_NONFATAL_FAILURE(EXPECT_GT(1, 2) << "Expected failure #3.",
4283  "Expected failure #3.");
4284 
4285  EXPECT_STREQ("1", "1") << "This should succeed.";
4286  EXPECT_NONFATAL_FAILURE(EXPECT_STRNE("1", "1") << "Expected failure #4.",
4287  "Expected failure #4.");
4288  EXPECT_STRCASEEQ("a", "A") << "This should succeed.";
4289  EXPECT_NONFATAL_FAILURE(EXPECT_STRCASENE("a", "A") << "Expected failure #5.",
4290  "Expected failure #5.");
4291 
4292  EXPECT_FLOAT_EQ(1, 1) << "This should succeed.";
4293  EXPECT_NONFATAL_FAILURE(EXPECT_DOUBLE_EQ(1, 1.2) << "Expected failure #6.",
4294  "Expected failure #6.");
4295  EXPECT_NEAR(1, 1.1, 0.2) << "This should succeed.";
4296 }
4297 
4298 TEST(AssertionWithMessageTest, ASSERT) {
4299  ASSERT_EQ(1, 1) << "This should succeed.";
4300  ASSERT_NE(1, 2) << "This should succeed.";
4301  ASSERT_LE(1, 2) << "This should succeed.";
4302  ASSERT_LT(1, 2) << "This should succeed.";
4303  ASSERT_GE(1, 0) << "This should succeed.";
4304  EXPECT_FATAL_FAILURE(ASSERT_GT(1, 2) << "Expected failure.",
4305  "Expected failure.");
4306 }
4307 
4308 TEST(AssertionWithMessageTest, ASSERT_STR) {
4309  ASSERT_STREQ("1", "1") << "This should succeed.";
4310  ASSERT_STRNE("1", "2") << "This should succeed.";
4311  ASSERT_STRCASEEQ("a", "A") << "This should succeed.";
4312  EXPECT_FATAL_FAILURE(ASSERT_STRCASENE("a", "A") << "Expected failure.",
4313  "Expected failure.");
4314 }
4315 
4316 TEST(AssertionWithMessageTest, ASSERT_FLOATING) {
4317  ASSERT_FLOAT_EQ(1, 1) << "This should succeed.";
4318  ASSERT_DOUBLE_EQ(1, 1) << "This should succeed.";
4319  EXPECT_FATAL_FAILURE(ASSERT_NEAR(1,1.2, 0.1) << "Expect failure.", // NOLINT
4320  "Expect failure.");
4321  // To work around a bug in gcc 2.95.0, there is intentionally no
4322  // space after the first comma in the previous statement.
4323 }
4324 
4325 // Tests using ASSERT_FALSE with a streamed message.
4326 TEST(AssertionWithMessageTest, ASSERT_FALSE) {
4327  ASSERT_FALSE(false) << "This shouldn't fail.";
4328  EXPECT_FATAL_FAILURE({ // NOLINT
4329  ASSERT_FALSE(true) << "Expected failure: " << 2 << " > " << 1
4330  << " evaluates to " << true;
4331  }, "Expected failure");
4332 }
4333 
4334 // Tests using FAIL with a streamed message.
4335 TEST(AssertionWithMessageTest, FAIL) {
4336  EXPECT_FATAL_FAILURE(FAIL() << 0,
4337  "0");
4338 }
4339 
4340 // Tests using SUCCEED with a streamed message.
4341 TEST(AssertionWithMessageTest, SUCCEED) {
4342  SUCCEED() << "Success == " << 1;
4343 }
4344 
4345 // Tests using ASSERT_TRUE with a streamed message.
4346 TEST(AssertionWithMessageTest, ASSERT_TRUE) {
4347  ASSERT_TRUE(true) << "This should succeed.";
4348  ASSERT_TRUE(true) << true;
4350  { // NOLINT
4351  ASSERT_TRUE(false) << static_cast<const char*>(nullptr)
4352  << static_cast<char*>(nullptr);
4353  },
4354  "(null)(null)");
4355 }
4356 
4357 #if GTEST_OS_WINDOWS
4358 // Tests using wide strings in assertion messages.
4359 TEST(AssertionWithMessageTest, WideStringMessage) {
4360  EXPECT_NONFATAL_FAILURE({ // NOLINT
4361  EXPECT_TRUE(false) << L"This failure is expected.\x8119";
4362  }, "This failure is expected.");
4363  EXPECT_FATAL_FAILURE({ // NOLINT
4364  ASSERT_EQ(1, 2) << "This failure is "
4365  << L"expected too.\x8120";
4366  }, "This failure is expected too.");
4367 }
4368 #endif // GTEST_OS_WINDOWS
4369 
4370 // Tests EXPECT_TRUE.
4371 TEST(ExpectTest, EXPECT_TRUE) {
4372  EXPECT_TRUE(true) << "Intentional success";
4373  EXPECT_NONFATAL_FAILURE(EXPECT_TRUE(false) << "Intentional failure #1.",
4374  "Intentional failure #1.");
4375  EXPECT_NONFATAL_FAILURE(EXPECT_TRUE(false) << "Intentional failure #2.",
4376  "Intentional failure #2.");
4377  EXPECT_TRUE(2 > 1); // NOLINT
4379  "Value of: 2 < 1\n"
4380  " Actual: false\n"
4381  "Expected: true");
4383  "2 > 3");
4384 }
4385 
4386 // Tests EXPECT_TRUE(predicate) for predicates returning AssertionResult.
4387 TEST(ExpectTest, ExpectTrueWithAssertionResult) {
4388  EXPECT_TRUE(ResultIsEven(2));
4389  EXPECT_NONFATAL_FAILURE(EXPECT_TRUE(ResultIsEven(3)),
4390  "Value of: ResultIsEven(3)\n"
4391  " Actual: false (3 is odd)\n"
4392  "Expected: true");
4393  EXPECT_TRUE(ResultIsEvenNoExplanation(2));
4394  EXPECT_NONFATAL_FAILURE(EXPECT_TRUE(ResultIsEvenNoExplanation(3)),
4395  "Value of: ResultIsEvenNoExplanation(3)\n"
4396  " Actual: false (3 is odd)\n"
4397  "Expected: true");
4398 }
4399 
4400 // Tests EXPECT_FALSE with a streamed message.
4401 TEST(ExpectTest, EXPECT_FALSE) {
4402  EXPECT_FALSE(2 < 1); // NOLINT
4403  EXPECT_FALSE(false) << "Intentional success";
4404  EXPECT_NONFATAL_FAILURE(EXPECT_FALSE(true) << "Intentional failure #1.",
4405  "Intentional failure #1.");
4406  EXPECT_NONFATAL_FAILURE(EXPECT_FALSE(true) << "Intentional failure #2.",
4407  "Intentional failure #2.");
4409  "Value of: 2 > 1\n"
4410  " Actual: true\n"
4411  "Expected: false");
4413  "2 < 3");
4414 }
4415 
4416 // Tests EXPECT_FALSE(predicate) for predicates returning AssertionResult.
4417 TEST(ExpectTest, ExpectFalseWithAssertionResult) {
4418  EXPECT_FALSE(ResultIsEven(3));
4419  EXPECT_NONFATAL_FAILURE(EXPECT_FALSE(ResultIsEven(2)),
4420  "Value of: ResultIsEven(2)\n"
4421  " Actual: true (2 is even)\n"
4422  "Expected: false");
4423  EXPECT_FALSE(ResultIsEvenNoExplanation(3));
4424  EXPECT_NONFATAL_FAILURE(EXPECT_FALSE(ResultIsEvenNoExplanation(2)),
4425  "Value of: ResultIsEvenNoExplanation(2)\n"
4426  " Actual: true\n"
4427  "Expected: false");
4428 }
4429 
4430 #ifdef __BORLANDC__
4431 // Restores warnings after previous "#pragma option push" suppressed them
4432 # pragma option pop
4433 #endif
4434 
4435 // Tests EXPECT_EQ.
4436 TEST(ExpectTest, EXPECT_EQ) {
4437  EXPECT_EQ(5, 2 + 3);
4439  "Expected equality of these values:\n"
4440  " 5\n"
4441  " 2*3\n"
4442  " Which is: 6");
4444  "2 - 3");
4445 }
4446 
4447 // Tests using EXPECT_EQ on double values. The purpose is to make
4448 // sure that the specialization we did for integer and anonymous enums
4449 // isn't used for double arguments.
4450 TEST(ExpectTest, EXPECT_EQ_Double) {
4451  // A success.
4452  EXPECT_EQ(5.6, 5.6);
4453 
4454  // A failure.
4456  "5.1");
4457 }
4458 
4459 // Tests EXPECT_EQ(NULL, pointer).
4460 TEST(ExpectTest, EXPECT_EQ_NULL) {
4461  // A success.
4462  const char* p = nullptr;
4463  // Some older GCC versions may issue a spurious warning in this or the next
4464  // assertion statement. This warning should not be suppressed with
4465  // static_cast since the test verifies the ability to use bare NULL as the
4466  // expected parameter to the macro.
4467  EXPECT_EQ(nullptr, p);
4468 
4469  // A failure.
4470  int n = 0;
4471  EXPECT_NONFATAL_FAILURE(EXPECT_EQ(nullptr, &n), " &n\n Which is:");
4472 }
4473 
4474 // Tests EXPECT_EQ(0, non_pointer). Since the literal 0 can be
4475 // treated as a null pointer by the compiler, we need to make sure
4476 // that EXPECT_EQ(0, non_pointer) isn't interpreted by Google Test as
4477 // EXPECT_EQ(static_cast<void*>(NULL), non_pointer).
4478 TEST(ExpectTest, EXPECT_EQ_0) {
4479  int n = 0;
4480 
4481  // A success.
4482  EXPECT_EQ(0, n);
4483 
4484  // A failure.
4486  " 0\n 5.6");
4487 }
4488 
4489 // Tests EXPECT_NE.
4490 TEST(ExpectTest, EXPECT_NE) {
4491  EXPECT_NE(6, 7);
4492 
4494  "Expected: ('a') != ('a'), "
4495  "actual: 'a' (97, 0x61) vs 'a' (97, 0x61)");
4497  "2");
4498  char* const p0 = nullptr;
4500  "p0");
4501  // Only way to get the Nokia compiler to compile the cast
4502  // is to have a separate void* variable first. Putting
4503  // the two casts on the same line doesn't work, neither does
4504  // a direct C-style to char*.
4505  void* pv1 = (void*)0x1234; // NOLINT
4506  char* const p1 = reinterpret_cast<char*>(pv1);
4508  "p1");
4509 }
4510 
4511 // Tests EXPECT_LE.
4512 TEST(ExpectTest, EXPECT_LE) {
4513  EXPECT_LE(2, 3);
4514  EXPECT_LE(2, 2);
4516  "Expected: (2) <= (0), actual: 2 vs 0");
4518  "(1.1) <= (0.9)");
4519 }
4520 
4521 // Tests EXPECT_LT.
4522 TEST(ExpectTest, EXPECT_LT) {
4523  EXPECT_LT(2, 3);
4525  "Expected: (2) < (2), actual: 2 vs 2");
4527  "(2) < (1)");
4528 }
4529 
4530 // Tests EXPECT_GE.
4531 TEST(ExpectTest, EXPECT_GE) {
4532  EXPECT_GE(2, 1);
4533  EXPECT_GE(2, 2);
4535  "Expected: (2) >= (3), actual: 2 vs 3");
4537  "(0.9) >= (1.1)");
4538 }
4539 
4540 // Tests EXPECT_GT.
4541 TEST(ExpectTest, EXPECT_GT) {
4542  EXPECT_GT(2, 1);
4544  "Expected: (2) > (2), actual: 2 vs 2");
4546  "(2) > (3)");
4547 }
4548 
4549 #if GTEST_HAS_EXCEPTIONS
4550 
4551 // Tests EXPECT_THROW.
4552 TEST(ExpectTest, EXPECT_THROW) {
4553  EXPECT_THROW(ThrowAnInteger(), int);
4554  EXPECT_NONFATAL_FAILURE(EXPECT_THROW(ThrowAnInteger(), bool),
4555  "Expected: ThrowAnInteger() throws an exception of "
4556  "type bool.\n Actual: it throws a different type.");
4558  EXPECT_THROW(ThrowNothing(), bool),
4559  "Expected: ThrowNothing() throws an exception of type bool.\n"
4560  " Actual: it throws nothing.");
4561 }
4562 
4563 // Tests EXPECT_NO_THROW.
4564 TEST(ExpectTest, EXPECT_NO_THROW) {
4565  EXPECT_NO_THROW(ThrowNothing());
4566  EXPECT_NONFATAL_FAILURE(EXPECT_NO_THROW(ThrowAnInteger()),
4567  "Expected: ThrowAnInteger() doesn't throw an "
4568  "exception.\n Actual: it throws.");
4569 }
4570 
4571 // Tests EXPECT_ANY_THROW.
4572 TEST(ExpectTest, EXPECT_ANY_THROW) {
4573  EXPECT_ANY_THROW(ThrowAnInteger());
4575  EXPECT_ANY_THROW(ThrowNothing()),
4576  "Expected: ThrowNothing() throws an exception.\n"
4577  " Actual: it doesn't.");
4578 }
4579 
4580 #endif // GTEST_HAS_EXCEPTIONS
4581 
4582 // Make sure we deal with the precedence of <<.
4583 TEST(ExpectTest, ExpectPrecedence) {
4584  EXPECT_EQ(1 < 2, true);
4585  EXPECT_NONFATAL_FAILURE(EXPECT_EQ(true, true && false),
4586  " true && false\n Which is: false");
4587 }
4588 
4589 
4590 // Tests the StreamableToString() function.
4591 
4592 // Tests using StreamableToString() on a scalar.
4593 TEST(StreamableToStringTest, Scalar) {
4595 }
4596 
4597 // Tests using StreamableToString() on a non-char pointer.
4598 TEST(StreamableToStringTest, Pointer) {
4599  int n = 0;
4600  int* p = &n;
4601  EXPECT_STRNE("(null)", StreamableToString(p).c_str());
4602 }
4603 
4604 // Tests using StreamableToString() on a NULL non-char pointer.
4605 TEST(StreamableToStringTest, NullPointer) {
4606  int* p = nullptr;
4607  EXPECT_STREQ("(null)", StreamableToString(p).c_str());
4608 }
4609 
4610 // Tests using StreamableToString() on a C string.
4611 TEST(StreamableToStringTest, CString) {
4612  EXPECT_STREQ("Foo", StreamableToString("Foo").c_str());
4613 }
4614 
4615 // Tests using StreamableToString() on a NULL C string.
4616 TEST(StreamableToStringTest, NullCString) {
4617  char* p = nullptr;
4618  EXPECT_STREQ("(null)", StreamableToString(p).c_str());
4619 }
4620 
4621 // Tests using streamable values as assertion messages.
4622 
4623 // Tests using std::string as an assertion message.
4624 TEST(StreamableTest, string) {
4625  static const std::string str(
4626  "This failure message is a std::string, and is expected.");
4628  str.c_str());
4629 }
4630 
4631 // Tests that we can output strings containing embedded NULs.
4632 // Limited to Linux because we can only do this with std::string's.
4633 TEST(StreamableTest, stringWithEmbeddedNUL) {
4634  static const char char_array_with_nul[] =
4635  "Here's a NUL\0 and some more string";
4636  static const std::string string_with_nul(char_array_with_nul,
4637  sizeof(char_array_with_nul)
4638  - 1); // drops the trailing NUL
4639  EXPECT_FATAL_FAILURE(FAIL() << string_with_nul,
4640  "Here's a NUL\\0 and some more string");
4641 }
4642 
4643 // Tests that we can output a NUL char.
4644 TEST(StreamableTest, NULChar) {
4645  EXPECT_FATAL_FAILURE({ // NOLINT
4646  FAIL() << "A NUL" << '\0' << " and some more string";
4647  }, "A NUL\\0 and some more string");
4648 }
4649 
4650 // Tests using int as an assertion message.
4651 TEST(StreamableTest, int) {
4652  EXPECT_FATAL_FAILURE(FAIL() << 900913,
4653  "900913");
4654 }
4655 
4656 // Tests using NULL char pointer as an assertion message.
4657 //
4658 // In MSVC, streaming a NULL char * causes access violation. Google Test
4659 // implemented a workaround (substituting "(null)" for NULL). This
4660 // tests whether the workaround works.
4661 TEST(StreamableTest, NullCharPtr) {
4662  EXPECT_FATAL_FAILURE(FAIL() << static_cast<const char*>(nullptr), "(null)");
4663 }
4664 
4665 // Tests that basic IO manipulators (endl, ends, and flush) can be
4666 // streamed to testing::Message.
4667 TEST(StreamableTest, BasicIoManip) {
4668  EXPECT_FATAL_FAILURE({ // NOLINT
4669  FAIL() << "Line 1." << std::endl
4670  << "A NUL char " << std::ends << std::flush << " in line 2.";
4671  }, "Line 1.\nA NUL char \\0 in line 2.");
4672 }
4673 
4674 // Tests the macros that haven't been covered so far.
4675 
4676 void AddFailureHelper(bool* aborted) {
4677  *aborted = true;
4678  ADD_FAILURE() << "Intentional failure.";
4679  *aborted = false;
4680 }
4681 
4682 // Tests ADD_FAILURE.
4683 TEST(MacroTest, ADD_FAILURE) {
4684  bool aborted = true;
4685  EXPECT_NONFATAL_FAILURE(AddFailureHelper(&aborted),
4686  "Intentional failure.");
4687  EXPECT_FALSE(aborted);
4688 }
4689 
4690 // Tests ADD_FAILURE_AT.
4691 TEST(MacroTest, ADD_FAILURE_AT) {
4692  // Verifies that ADD_FAILURE_AT does generate a nonfatal failure and
4693  // the failure message contains the user-streamed part.
4694  EXPECT_NONFATAL_FAILURE(ADD_FAILURE_AT("foo.cc", 42) << "Wrong!", "Wrong!");
4695 
4696  // Verifies that the user-streamed part is optional.
4697  EXPECT_NONFATAL_FAILURE(ADD_FAILURE_AT("foo.cc", 42), "Failed");
4698 
4699  // Unfortunately, we cannot verify that the failure message contains
4700  // the right file path and line number the same way, as
4701  // EXPECT_NONFATAL_FAILURE() doesn't get to see the file path and
4702  // line number. Instead, we do that in googletest-output-test_.cc.
4703 }
4704 
4705 // Tests FAIL.
4706 TEST(MacroTest, FAIL) {
4708  "Failed");
4709  EXPECT_FATAL_FAILURE(FAIL() << "Intentional failure.",
4710  "Intentional failure.");
4711 }
4712 
4713 // Tests GTEST_FAIL_AT.
4714 TEST(MacroTest, GTEST_FAIL_AT) {
4715  // Verifies that GTEST_FAIL_AT does generate a fatal failure and
4716  // the failure message contains the user-streamed part.
4717  EXPECT_FATAL_FAILURE(GTEST_FAIL_AT("foo.cc", 42) << "Wrong!", "Wrong!");
4718 
4719  // Verifies that the user-streamed part is optional.
4720  EXPECT_FATAL_FAILURE(GTEST_FAIL_AT("foo.cc", 42), "Failed");
4721 
4722  // See the ADD_FAIL_AT test above to see how we test that the failure message
4723  // contains the right filename and line number -- the same applies here.
4724 }
4725 
4726 // Tests SUCCEED
4727 TEST(MacroTest, SUCCEED) {
4728  SUCCEED();
4729  SUCCEED() << "Explicit success.";
4730 }
4731 
4732 // Tests for EXPECT_EQ() and ASSERT_EQ().
4733 //
4734 // These tests fail *intentionally*, s.t. the failure messages can be
4735 // generated and tested.
4736 //
4737 // We have different tests for different argument types.
4738 
4739 // Tests using bool values in {EXPECT|ASSERT}_EQ.
4740 TEST(EqAssertionTest, Bool) {
4741  EXPECT_EQ(true, true);
4743  bool false_value = false;
4744  ASSERT_EQ(false_value, true);
4745  }, " false_value\n Which is: false\n true");
4746 }
4747 
4748 // Tests using int values in {EXPECT|ASSERT}_EQ.
4749 TEST(EqAssertionTest, Int) {
4750  ASSERT_EQ(32, 32);
4752  " 32\n 33");
4753 }
4754 
4755 // Tests using time_t values in {EXPECT|ASSERT}_EQ.
4756 TEST(EqAssertionTest, Time_T) {
4757  EXPECT_EQ(static_cast<time_t>(0),
4758  static_cast<time_t>(0));
4759  EXPECT_FATAL_FAILURE(ASSERT_EQ(static_cast<time_t>(0),
4760  static_cast<time_t>(1234)),
4761  "1234");
4762 }
4763 
4764 // Tests using char values in {EXPECT|ASSERT}_EQ.
4765 TEST(EqAssertionTest, Char) {
4766  ASSERT_EQ('z', 'z');
4767  const char ch = 'b';
4769  " ch\n Which is: 'b'");
4771  " ch\n Which is: 'b'");
4772 }
4773 
4774 // Tests using wchar_t values in {EXPECT|ASSERT}_EQ.
4775 TEST(EqAssertionTest, WideChar) {
4776  EXPECT_EQ(L'b', L'b');
4777 
4779  "Expected equality of these values:\n"
4780  " L'\0'\n"
4781  " Which is: L'\0' (0, 0x0)\n"
4782  " L'x'\n"
4783  " Which is: L'x' (120, 0x78)");
4784 
4785  static wchar_t wchar;
4786  wchar = L'b';
4787  EXPECT_NONFATAL_FAILURE(EXPECT_EQ(L'a', wchar),
4788  "wchar");
4789  wchar = 0x8119;
4790  EXPECT_FATAL_FAILURE(ASSERT_EQ(static_cast<wchar_t>(0x8120), wchar),
4791  " wchar\n Which is: L'");
4792 }
4793 
4794 // Tests using ::std::string values in {EXPECT|ASSERT}_EQ.
4795 TEST(EqAssertionTest, StdString) {
4796  // Compares a const char* to an std::string that has identical
4797  // content.
4798  ASSERT_EQ("Test", ::std::string("Test"));
4799 
4800  // Compares two identical std::strings.
4801  static const ::std::string str1("A * in the middle");
4802  static const ::std::string str2(str1);
4803  EXPECT_EQ(str1, str2);
4804 
4805  // Compares a const char* to an std::string that has different
4806  // content
4807  EXPECT_NONFATAL_FAILURE(EXPECT_EQ("Test", ::std::string("test")),
4808  "\"test\"");
4809 
4810  // Compares an std::string to a char* that has different content.
4811  char* const p1 = const_cast<char*>("foo");
4813  "p1");
4814 
4815  // Compares two std::strings that have different contents, one of
4816  // which having a NUL character in the middle. This should fail.
4817  static ::std::string str3(str1);
4818  str3.at(2) = '\0';
4819  EXPECT_FATAL_FAILURE(ASSERT_EQ(str1, str3),
4820  " str3\n Which is: \"A \\0 in the middle\"");
4821 }
4822 
4823 #if GTEST_HAS_STD_WSTRING
4824 
4825 // Tests using ::std::wstring values in {EXPECT|ASSERT}_EQ.
4826 TEST(EqAssertionTest, StdWideString) {
4827  // Compares two identical std::wstrings.
4828  const ::std::wstring wstr1(L"A * in the middle");
4829  const ::std::wstring wstr2(wstr1);
4830  ASSERT_EQ(wstr1, wstr2);
4831 
4832  // Compares an std::wstring to a const wchar_t* that has identical
4833  // content.
4834  const wchar_t kTestX8119[] = { 'T', 'e', 's', 't', 0x8119, '\0' };
4835  EXPECT_EQ(::std::wstring(kTestX8119), kTestX8119);
4836 
4837  // Compares an std::wstring to a const wchar_t* that has different
4838  // content.
4839  const wchar_t kTestX8120[] = { 'T', 'e', 's', 't', 0x8120, '\0' };
4840  EXPECT_NONFATAL_FAILURE({ // NOLINT
4841  EXPECT_EQ(::std::wstring(kTestX8119), kTestX8120);
4842  }, "kTestX8120");
4843 
4844  // Compares two std::wstrings that have different contents, one of
4845  // which having a NUL character in the middle.
4846  ::std::wstring wstr3(wstr1);
4847  wstr3.at(2) = L'\0';
4848  EXPECT_NONFATAL_FAILURE(EXPECT_EQ(wstr1, wstr3),
4849  "wstr3");
4850 
4851  // Compares a wchar_t* to an std::wstring that has different
4852  // content.
4853  EXPECT_FATAL_FAILURE({ // NOLINT
4854  ASSERT_EQ(const_cast<wchar_t*>(L"foo"), ::std::wstring(L"bar"));
4855  }, "");
4856 }
4857 
4858 #endif // GTEST_HAS_STD_WSTRING
4859 
4860 // Tests using char pointers in {EXPECT|ASSERT}_EQ.
4861 TEST(EqAssertionTest, CharPointer) {
4862  char* const p0 = nullptr;
4863  // Only way to get the Nokia compiler to compile the cast
4864  // is to have a separate void* variable first. Putting
4865  // the two casts on the same line doesn't work, neither does
4866  // a direct C-style to char*.
4867  void* pv1 = (void*)0x1234; // NOLINT
4868  void* pv2 = (void*)0xABC0; // NOLINT
4869  char* const p1 = reinterpret_cast<char*>(pv1);
4870  char* const p2 = reinterpret_cast<char*>(pv2);
4871  ASSERT_EQ(p1, p1);
4872 
4874  " p2\n Which is:");
4876  " p2\n Which is:");
4877  EXPECT_FATAL_FAILURE(ASSERT_EQ(reinterpret_cast<char*>(0x1234),
4878  reinterpret_cast<char*>(0xABC0)),
4879  "ABC0");
4880 }
4881 
4882 // Tests using wchar_t pointers in {EXPECT|ASSERT}_EQ.
4883 TEST(EqAssertionTest, WideCharPointer) {
4884  wchar_t* const p0 = nullptr;
4885  // Only way to get the Nokia compiler to compile the cast
4886  // is to have a separate void* variable first. Putting
4887  // the two casts on the same line doesn't work, neither does
4888  // a direct C-style to char*.
4889  void* pv1 = (void*)0x1234; // NOLINT
4890  void* pv2 = (void*)0xABC0; // NOLINT
4891  wchar_t* const p1 = reinterpret_cast<wchar_t*>(pv1);
4892  wchar_t* const p2 = reinterpret_cast<wchar_t*>(pv2);
4893  EXPECT_EQ(p0, p0);
4894 
4896  " p2\n Which is:");
4898  " p2\n Which is:");
4899  void* pv3 = (void*)0x1234; // NOLINT
4900  void* pv4 = (void*)0xABC0; // NOLINT
4901  const wchar_t* p3 = reinterpret_cast<const wchar_t*>(pv3);
4902  const wchar_t* p4 = reinterpret_cast<const wchar_t*>(pv4);
4904  "p4");
4905 }
4906 
4907 // Tests using other types of pointers in {EXPECT|ASSERT}_EQ.
4908 TEST(EqAssertionTest, OtherPointer) {
4909  ASSERT_EQ(static_cast<const int*>(nullptr), static_cast<const int*>(nullptr));
4910  EXPECT_FATAL_FAILURE(ASSERT_EQ(static_cast<const int*>(nullptr),
4911  reinterpret_cast<const int*>(0x1234)),
4912  "0x1234");
4913 }
4914 
4915 // A class that supports binary comparison operators but not streaming.
4916 class UnprintableChar {
4917  public:
4918  explicit UnprintableChar(char ch) : char_(ch) {}
4919 
4920  bool operator==(const UnprintableChar& rhs) const {
4921  return char_ == rhs.char_;
4922  }
4923  bool operator!=(const UnprintableChar& rhs) const {
4924  return char_ != rhs.char_;
4925  }
4926  bool operator<(const UnprintableChar& rhs) const {
4927  return char_ < rhs.char_;
4928  }
4929  bool operator<=(const UnprintableChar& rhs) const {
4930  return char_ <= rhs.char_;
4931  }
4932  bool operator>(const UnprintableChar& rhs) const {
4933  return char_ > rhs.char_;
4934  }
4935  bool operator>=(const UnprintableChar& rhs) const {
4936  return char_ >= rhs.char_;
4937  }
4938 
4939  private:
4940  char char_;
4941 };
4942 
4943 // Tests that ASSERT_EQ() and friends don't require the arguments to
4944 // be printable.
4945 TEST(ComparisonAssertionTest, AcceptsUnprintableArgs) {
4946  const UnprintableChar x('x'), y('y');
4947  ASSERT_EQ(x, x);
4948  EXPECT_NE(x, y);
4949  ASSERT_LT(x, y);
4950  EXPECT_LE(x, y);
4951  ASSERT_GT(y, x);
4952  EXPECT_GE(x, x);
4953 
4954  EXPECT_NONFATAL_FAILURE(EXPECT_EQ(x, y), "1-byte object <78>");
4955  EXPECT_NONFATAL_FAILURE(EXPECT_EQ(x, y), "1-byte object <79>");
4956  EXPECT_NONFATAL_FAILURE(EXPECT_LT(y, y), "1-byte object <79>");
4957  EXPECT_NONFATAL_FAILURE(EXPECT_GT(x, y), "1-byte object <78>");
4958  EXPECT_NONFATAL_FAILURE(EXPECT_GT(x, y), "1-byte object <79>");
4959 
4960  // Code tested by EXPECT_FATAL_FAILURE cannot reference local
4961  // variables, so we have to write UnprintableChar('x') instead of x.
4962 #ifndef __BORLANDC__
4963  // ICE's in C++Builder.
4964  EXPECT_FATAL_FAILURE(ASSERT_NE(UnprintableChar('x'), UnprintableChar('x')),
4965  "1-byte object <78>");
4966  EXPECT_FATAL_FAILURE(ASSERT_LE(UnprintableChar('y'), UnprintableChar('x')),
4967  "1-byte object <78>");
4968 #endif
4969  EXPECT_FATAL_FAILURE(ASSERT_LE(UnprintableChar('y'), UnprintableChar('x')),
4970  "1-byte object <79>");
4971  EXPECT_FATAL_FAILURE(ASSERT_GE(UnprintableChar('x'), UnprintableChar('y')),
4972  "1-byte object <78>");
4973  EXPECT_FATAL_FAILURE(ASSERT_GE(UnprintableChar('x'), UnprintableChar('y')),
4974  "1-byte object <79>");
4975 }
4976 
4977 // Tests the FRIEND_TEST macro.
4978 
4979 // This class has a private member we want to test. We will test it
4980 // both in a TEST and in a TEST_F.
4981 class Foo {
4982  public:
4983  Foo() {}
4984 
4985  private:
4986  int Bar() const { return 1; }
4987 
4988  // Declares the friend tests that can access the private member
4989  // Bar().
4990  FRIEND_TEST(FRIEND_TEST_Test, TEST);
4991  FRIEND_TEST(FRIEND_TEST_Test2, TEST_F);
4992 };
4993 
4994 // Tests that the FRIEND_TEST declaration allows a TEST to access a
4995 // class's private members. This should compile.
4996 TEST(FRIEND_TEST_Test, TEST) {
4997  ASSERT_EQ(1, Foo().Bar());
4998 }
4999 
5000 // The fixture needed to test using FRIEND_TEST with TEST_F.
5001 class FRIEND_TEST_Test2 : public Test {
5002  protected:
5003  Foo foo;
5004 };
5005 
5006 // Tests that the FRIEND_TEST declaration allows a TEST_F to access a
5007 // class's private members. This should compile.
5008 TEST_F(FRIEND_TEST_Test2, TEST_F) {
5009  ASSERT_EQ(1, foo.Bar());
5010 }
5011 
5012 // Tests the life cycle of Test objects.
5013 
5014 // The test fixture for testing the life cycle of Test objects.
5015 //
5016 // This class counts the number of live test objects that uses this
5017 // fixture.
5018 class TestLifeCycleTest : public Test {
5019  protected:
5020  // Constructor. Increments the number of test objects that uses
5021  // this fixture.
5022  TestLifeCycleTest() { count_++; }
5023 
5024  // Destructor. Decrements the number of test objects that uses this
5025  // fixture.
5026  ~TestLifeCycleTest() override { count_--; }
5027 
5028  // Returns the number of live test objects that uses this fixture.
5029  int count() const { return count_; }
5030 
5031  private:
5032  static int count_;
5033 };
5034 
5036 
5037 // Tests the life cycle of test objects.
5038 TEST_F(TestLifeCycleTest, Test1) {
5039  // There should be only one test object in this test case that's
5040  // currently alive.
5041  ASSERT_EQ(1, count());
5042 }
5043 
5044 // Tests the life cycle of test objects.
5045 TEST_F(TestLifeCycleTest, Test2) {
5046  // After Test1 is done and Test2 is started, there should still be
5047  // only one live test object, as the object for Test1 should've been
5048  // deleted.
5049  ASSERT_EQ(1, count());
5050 }
5051 
5052 } // namespace
5053 
5054 // Tests that the copy constructor works when it is NOT optimized away by
5055 // the compiler.
5056 TEST(AssertionResultTest, CopyConstructorWorksWhenNotOptimied) {
5057  // Checks that the copy constructor doesn't try to dereference NULL pointers
5058  // in the source object.
5060  AssertionResult r2 = r1;
5061  // The following line is added to prevent the compiler from optimizing
5062  // away the constructor call.
5063  r1 << "abc";
5064 
5065  AssertionResult r3 = r1;
5066  EXPECT_EQ(static_cast<bool>(r3), static_cast<bool>(r1));
5067  EXPECT_STREQ("abc", r1.message());
5068 }
5069 
5070 // Tests that AssertionSuccess and AssertionFailure construct
5071 // AssertionResult objects as expected.
5072 TEST(AssertionResultTest, ConstructionWorks) {
5074  EXPECT_TRUE(r1);
5075  EXPECT_STREQ("", r1.message());
5076 
5077  AssertionResult r2 = AssertionSuccess() << "abc";
5078  EXPECT_TRUE(r2);
5079  EXPECT_STREQ("abc", r2.message());
5080 
5082  EXPECT_FALSE(r3);
5083  EXPECT_STREQ("", r3.message());
5084 
5085  AssertionResult r4 = AssertionFailure() << "def";
5086  EXPECT_FALSE(r4);
5087  EXPECT_STREQ("def", r4.message());
5088 
5089  AssertionResult r5 = AssertionFailure(Message() << "ghi");
5090  EXPECT_FALSE(r5);
5091  EXPECT_STREQ("ghi", r5.message());
5092 }
5093 
5094 // Tests that the negation flips the predicate result but keeps the message.
5095 TEST(AssertionResultTest, NegationWorks) {
5096  AssertionResult r1 = AssertionSuccess() << "abc";
5097  EXPECT_FALSE(!r1);
5098  EXPECT_STREQ("abc", (!r1).message());
5099 
5100  AssertionResult r2 = AssertionFailure() << "def";
5101  EXPECT_TRUE(!r2);
5102  EXPECT_STREQ("def", (!r2).message());
5103 }
5104 
5105 TEST(AssertionResultTest, StreamingWorks) {
5107  r << "abc" << 'd' << 0 << true;
5108  EXPECT_STREQ("abcd0true", r.message());
5109 }
5110 
5111 TEST(AssertionResultTest, CanStreamOstreamManipulators) {
5113  r << "Data" << std::endl << std::flush << std::ends << "Will be visible";
5114  EXPECT_STREQ("Data\n\\0Will be visible", r.message());
5115 }
5116 
5117 // The next test uses explicit conversion operators
5118 
5119 TEST(AssertionResultTest, ConstructibleFromContextuallyConvertibleToBool) {
5120  struct ExplicitlyConvertibleToBool {
5121  explicit operator bool() const { return value; }
5122  bool value;
5123  };
5124  ExplicitlyConvertibleToBool v1 = {false};
5125  ExplicitlyConvertibleToBool v2 = {true};
5126  EXPECT_FALSE(v1);
5127  EXPECT_TRUE(v2);
5128 }
5129 
5131  operator AssertionResult() const { return AssertionResult(true); }
5132 };
5133 
5134 TEST(AssertionResultTest, ConstructibleFromImplicitlyConvertible) {
5136  EXPECT_TRUE(obj);
5137 }
5138 
5139 // Tests streaming a user type whose definition and operator << are
5140 // both in the global namespace.
5141 class Base {
5142  public:
5143  explicit Base(int an_x) : x_(an_x) {}
5144  int x() const { return x_; }
5145  private:
5146  int x_;
5147 };
5148 std::ostream& operator<<(std::ostream& os,
5149  const Base& val) {
5150  return os << val.x();
5151 }
5152 std::ostream& operator<<(std::ostream& os,
5153  const Base* pointer) {
5154  return os << "(" << pointer->x() << ")";
5155 }
5156 
5157 TEST(MessageTest, CanStreamUserTypeInGlobalNameSpace) {
5158  Message msg;
5159  Base a(1);
5160 
5161  msg << a << &a; // Uses ::operator<<.
5162  EXPECT_STREQ("1(1)", msg.GetString().c_str());
5163 }
5164 
5165 // Tests streaming a user type whose definition and operator<< are
5166 // both in an unnamed namespace.
5167 namespace {
5168 class MyTypeInUnnamedNameSpace : public Base {
5169  public:
5170  explicit MyTypeInUnnamedNameSpace(int an_x): Base(an_x) {}
5171 };
5172 std::ostream& operator<<(std::ostream& os,
5173  const MyTypeInUnnamedNameSpace& val) {
5174  return os << val.x();
5175 }
5176 std::ostream& operator<<(std::ostream& os,
5177  const MyTypeInUnnamedNameSpace* pointer) {
5178  return os << "(" << pointer->x() << ")";
5179 }
5180 } // namespace
5181 
5182 TEST(MessageTest, CanStreamUserTypeInUnnamedNameSpace) {
5183  Message msg;
5184  MyTypeInUnnamedNameSpace a(1);
5185 
5186  msg << a << &a; // Uses <unnamed_namespace>::operator<<.
5187  EXPECT_STREQ("1(1)", msg.GetString().c_str());
5188 }
5189 
5190 // Tests streaming a user type whose definition and operator<< are
5191 // both in a user namespace.
5192 namespace namespace1 {
5193 class MyTypeInNameSpace1 : public Base {
5194  public:
5195  explicit MyTypeInNameSpace1(int an_x): Base(an_x) {}
5196 };
5197 std::ostream& operator<<(std::ostream& os,
5198  const MyTypeInNameSpace1& val) {
5199  return os << val.x();
5200 }
5201 std::ostream& operator<<(std::ostream& os,
5202  const MyTypeInNameSpace1* pointer) {
5203  return os << "(" << pointer->x() << ")";
5204 }
5205 } // namespace namespace1
5206 
5207 TEST(MessageTest, CanStreamUserTypeInUserNameSpace) {
5208  Message msg;
5210 
5211  msg << a << &a; // Uses namespace1::operator<<.
5212  EXPECT_STREQ("1(1)", msg.GetString().c_str());
5213 }
5214 
5215 // Tests streaming a user type whose definition is in a user namespace
5216 // but whose operator<< is in the global namespace.
5217 namespace namespace2 {
5218 class MyTypeInNameSpace2 : public ::Base {
5219  public:
5220  explicit MyTypeInNameSpace2(int an_x): Base(an_x) {}
5221 };
5222 } // namespace namespace2
5223 std::ostream& operator<<(std::ostream& os,
5224  const namespace2::MyTypeInNameSpace2& val) {
5225  return os << val.x();
5226 }
5227 std::ostream& operator<<(std::ostream& os,
5228  const namespace2::MyTypeInNameSpace2* pointer) {
5229  return os << "(" << pointer->x() << ")";
5230 }
5231 
5232 TEST(MessageTest, CanStreamUserTypeInUserNameSpaceWithStreamOperatorInGlobal) {
5233  Message msg;
5235 
5236  msg << a << &a; // Uses ::operator<<.
5237  EXPECT_STREQ("1(1)", msg.GetString().c_str());
5238 }
5239 
5240 // Tests streaming NULL pointers to testing::Message.
5241 TEST(MessageTest, NullPointers) {
5242  Message msg;
5243  char* const p1 = nullptr;
5244  unsigned char* const p2 = nullptr;
5245  int* p3 = nullptr;
5246  double* p4 = nullptr;
5247  bool* p5 = nullptr;
5248  Message* p6 = nullptr;
5249 
5250  msg << p1 << p2 << p3 << p4 << p5 << p6;
5251  ASSERT_STREQ("(null)(null)(null)(null)(null)(null)",
5252  msg.GetString().c_str());
5253 }
5254 
5255 // Tests streaming wide strings to testing::Message.
5256 TEST(MessageTest, WideStrings) {
5257  // Streams a NULL of type const wchar_t*.
5258  const wchar_t* const_wstr = nullptr;
5259  EXPECT_STREQ("(null)",
5260  (Message() << const_wstr).GetString().c_str());
5261 
5262  // Streams a NULL of type wchar_t*.
5263  wchar_t* wstr = nullptr;
5264  EXPECT_STREQ("(null)",
5265  (Message() << wstr).GetString().c_str());
5266 
5267  // Streams a non-NULL of type const wchar_t*.
5268  const_wstr = L"abc\x8119";
5269  EXPECT_STREQ("abc\xe8\x84\x99",
5270  (Message() << const_wstr).GetString().c_str());
5271 
5272  // Streams a non-NULL of type wchar_t*.
5273  wstr = const_cast<wchar_t*>(const_wstr);
5274  EXPECT_STREQ("abc\xe8\x84\x99",
5275  (Message() << wstr).GetString().c_str());
5276 }
5277 
5278 
5279 // This line tests that we can define tests in the testing namespace.
5280 namespace testing {
5281 
5282 // Tests the TestInfo class.
5283 
5284 class TestInfoTest : public Test {
5285  protected:
5286  static const TestInfo* GetTestInfo(const char* test_name) {
5287  const TestSuite* const test_suite =
5288  GetUnitTestImpl()->GetTestSuite("TestInfoTest", "", nullptr, nullptr);
5289 
5290  for (int i = 0; i < test_suite->total_test_count(); ++i) {
5291  const TestInfo* const test_info = test_suite->GetTestInfo(i);
5292  if (strcmp(test_name, test_info->name()) == 0)
5293  return test_info;
5294  }
5295  return nullptr;
5296  }
5297 
5298  static const TestResult* GetTestResult(
5299  const TestInfo* test_info) {
5300  return test_info->result();
5301  }
5302 };
5303 
5304 // Tests TestInfo::test_case_name() and TestInfo::name().
5306  const TestInfo* const test_info = GetTestInfo("Names");
5307 
5308  ASSERT_STREQ("TestInfoTest", test_info->test_case_name());
5309  ASSERT_STREQ("Names", test_info->name());
5310 }
5311 
5312 // Tests TestInfo::result().
5314  const TestInfo* const test_info = GetTestInfo("result");
5315 
5316  // Initially, there is no TestPartResult for this test.
5317  ASSERT_EQ(0, GetTestResult(test_info)->total_part_count());
5318 
5319  // After the previous assertion, there is still none.
5320  ASSERT_EQ(0, GetTestResult(test_info)->total_part_count());
5321 }
5322 
5323 #define VERIFY_CODE_LOCATION \
5324  const int expected_line = __LINE__ - 1; \
5325  const TestInfo* const test_info = GetUnitTestImpl()->current_test_info(); \
5326  ASSERT_TRUE(test_info); \
5327  EXPECT_STREQ(__FILE__, test_info->file()); \
5328  EXPECT_EQ(expected_line, test_info->line())
5329 
5330 TEST(CodeLocationForTEST, Verify) {
5332 }
5333 
5334 class CodeLocationForTESTF : public Test {
5335 };
5336 
5339 }
5340 
5342 };
5343 
5346 }
5347 
5348 INSTANTIATE_TEST_SUITE_P(, CodeLocationForTESTP, Values(0));
5349 
5350 template <typename T>
5352 };
5353 
5355 
5358 }
5359 
5360 template <typename T>
5362 };
5363 
5365 
5368 }
5369 
5370 REGISTER_TYPED_TEST_SUITE_P(CodeLocationForTYPEDTESTP, Verify);
5371 
5372 INSTANTIATE_TYPED_TEST_SUITE_P(My, CodeLocationForTYPEDTESTP, int);
5373 
5374 #undef VERIFY_CODE_LOCATION
5375 
5376 // Tests setting up and tearing down a test case.
5377 // Legacy API is deprecated but still available
5378 #ifndef REMOVE_LEGACY_TEST_CASEAPI
5379 class SetUpTestCaseTest : public Test {
5380  protected:
5381  // This will be called once before the first test in this test case
5382  // is run.
5383  static void SetUpTestCase() {
5384  printf("Setting up the test case . . .\n");
5385 
5386  // Initializes some shared resource. In this simple example, we
5387  // just create a C string. More complex stuff can be done if
5388  // desired.
5389  shared_resource_ = "123";
5390 
5391  // Increments the number of test cases that have been set up.
5392  counter_++;
5393 
5394  // SetUpTestCase() should be called only once.
5395  EXPECT_EQ(1, counter_);
5396  }
5397 
5398  // This will be called once after the last test in this test case is
5399  // run.
5400  static void TearDownTestCase() {
5401  printf("Tearing down the test case . . .\n");
5402 
5403  // Decrements the number of test cases that have been set up.
5404  counter_--;
5405 
5406  // TearDownTestCase() should be called only once.
5407  EXPECT_EQ(0, counter_);
5408 
5409  // Cleans up the shared resource.
5410  shared_resource_ = nullptr;
5411  }
5412 
5413  // This will be called before each test in this test case.
5414  void SetUp() override {
5415  // SetUpTestCase() should be called only once, so counter_ should
5416  // always be 1.
5417  EXPECT_EQ(1, counter_);
5418  }
5419 
5420  // Number of test cases that have been set up.
5421  static int counter_;
5422 
5423  // Some resource to be shared by all tests in this test case.
5424  static const char* shared_resource_;
5425 };
5426 
5428 const char* SetUpTestCaseTest::shared_resource_ = nullptr;
5429 
5430 // A test that uses the shared resource.
5431 TEST_F(SetUpTestCaseTest, Test1) { EXPECT_STRNE(nullptr, shared_resource_); }
5432 
5433 // Another test that uses the shared resource.
5435  EXPECT_STREQ("123", shared_resource_);
5436 }
5437 #endif // REMOVE_LEGACY_TEST_CASEAPI
5438 
5439 // Tests SetupTestSuite/TearDown TestSuite
5440 class SetUpTestSuiteTest : public Test {
5441  protected:
5442  // This will be called once before the first test in this test case
5443  // is run.
5444  static void SetUpTestSuite() {
5445  printf("Setting up the test suite . . .\n");
5446 
5447  // Initializes some shared resource. In this simple example, we
5448  // just create a C string. More complex stuff can be done if
5449  // desired.
5450  shared_resource_ = "123";
5451 
5452  // Increments the number of test cases that have been set up.
5453  counter_++;
5454 
5455  // SetUpTestSuite() should be called only once.
5456  EXPECT_EQ(1, counter_);
5457  }
5458 
5459  // This will be called once after the last test in this test case is
5460  // run.
5461  static void TearDownTestSuite() {
5462  printf("Tearing down the test suite . . .\n");
5463 
5464  // Decrements the number of test suites that have been set up.
5465  counter_--;
5466 
5467  // TearDownTestSuite() should be called only once.
5468  EXPECT_EQ(0, counter_);
5469 
5470  // Cleans up the shared resource.
5471  shared_resource_ = nullptr;
5472  }
5473 
5474  // This will be called before each test in this test case.
5475  void SetUp() override {
5476  // SetUpTestSuite() should be called only once, so counter_ should
5477  // always be 1.
5478  EXPECT_EQ(1, counter_);
5479  }
5480 
5481  // Number of test suites that have been set up.
5482  static int counter_;
5483 
5484  // Some resource to be shared by all tests in this test case.
5485  static const char* shared_resource_;
5486 };
5487 
5489 const char* SetUpTestSuiteTest::shared_resource_ = nullptr;
5490 
5491 // A test that uses the shared resource.
5492 TEST_F(SetUpTestSuiteTest, TestSetupTestSuite1) {
5493  EXPECT_STRNE(nullptr, shared_resource_);
5494 }
5495 
5496 // Another test that uses the shared resource.
5497 TEST_F(SetUpTestSuiteTest, TestSetupTestSuite2) {
5498  EXPECT_STREQ("123", shared_resource_);
5499 }
5500 
5501 // The ParseFlagsTest test case tests ParseGoogleTestFlagsOnly.
5502 
5503 // The Flags struct stores a copy of all Google Test flags.
5504 struct Flags {
5505  // Constructs a Flags struct where each flag has its default value.
5510  filter(""),
5511  list_tests(false),
5512  output(""),
5513  print_time(true),
5514  random_seed(0),
5515  repeat(1),
5516  shuffle(false),
5518  stream_result_to(""),
5520 
5521  // Factory methods.
5522 
5523  // Creates a Flags struct where the gtest_also_run_disabled_tests flag has
5524  // the given value.
5526  Flags flags;
5527  flags.also_run_disabled_tests = also_run_disabled_tests;
5528  return flags;
5529  }
5530 
5531  // Creates a Flags struct where the gtest_break_on_failure flag has
5532  // the given value.
5534  Flags flags;
5535  flags.break_on_failure = break_on_failure;
5536  return flags;
5537  }
5538 
5539  // Creates a Flags struct where the gtest_catch_exceptions flag has
5540  // the given value.
5542  Flags flags;
5543  flags.catch_exceptions = catch_exceptions;
5544  return flags;
5545  }
5546 
5547  // Creates a Flags struct where the gtest_death_test_use_fork flag has
5548  // the given value.
5550  Flags flags;
5551  flags.death_test_use_fork = death_test_use_fork;
5552  return flags;
5553  }
5554 
5555  // Creates a Flags struct where the gtest_filter flag has the given
5556  // value.
5557  static Flags Filter(const char* filter) {
5558  Flags flags;
5559  flags.filter = filter;
5560  return flags;
5561  }
5562 
5563  // Creates a Flags struct where the gtest_list_tests flag has the
5564  // given value.
5565  static Flags ListTests(bool list_tests) {
5566  Flags flags;
5567  flags.list_tests = list_tests;
5568  return flags;
5569  }
5570 
5571  // Creates a Flags struct where the gtest_output flag has the given
5572  // value.
5573  static Flags Output(const char* output) {
5574  Flags flags;
5575  flags.output = output;
5576  return flags;
5577  }
5578 
5579  // Creates a Flags struct where the gtest_print_time flag has the given
5580  // value.
5581  static Flags PrintTime(bool print_time) {
5582  Flags flags;
5583  flags.print_time = print_time;
5584  return flags;
5585  }
5586 
5587  // Creates a Flags struct where the gtest_random_seed flag has the given
5588  // value.
5590  Flags flags;
5591  flags.random_seed = random_seed;
5592  return flags;
5593  }
5594 
5595  // Creates a Flags struct where the gtest_repeat flag has the given
5596  // value.
5598  Flags flags;
5599  flags.repeat = repeat;
5600  return flags;
5601  }
5602 
5603  // Creates a Flags struct where the gtest_shuffle flag has the given
5604  // value.
5605  static Flags Shuffle(bool shuffle) {
5606  Flags flags;
5607  flags.shuffle = shuffle;
5608  return flags;
5609  }
5610 
5611  // Creates a Flags struct where the GTEST_FLAG(stack_trace_depth) flag has
5612  // the given value.
5614  Flags flags;
5615  flags.stack_trace_depth = stack_trace_depth;
5616  return flags;
5617  }
5618 
5619  // Creates a Flags struct where the GTEST_FLAG(stream_result_to) flag has
5620  // the given value.
5621  static Flags StreamResultTo(const char* stream_result_to) {
5622  Flags flags;
5623  flags.stream_result_to = stream_result_to;
5624  return flags;
5625  }
5626 
5627  // Creates a Flags struct where the gtest_throw_on_failure flag has
5628  // the given value.
5630  Flags flags;
5631  flags.throw_on_failure = throw_on_failure;
5632  return flags;
5633  }
5634 
5635  // These fields store the flag values.
5640  const char* filter;
5642  const char* output;
5646  bool shuffle;
5648  const char* stream_result_to;
5650 };
5651 
5652 // Fixture for testing ParseGoogleTestFlagsOnly().
5653 class ParseFlagsTest : public Test {
5654  protected:
5655  // Clears the flags before each test.
5656  void SetUp() override {
5657  GTEST_FLAG(also_run_disabled_tests) = false;
5658  GTEST_FLAG(break_on_failure) = false;
5659  GTEST_FLAG(catch_exceptions) = false;
5660  GTEST_FLAG(death_test_use_fork) = false;
5661  GTEST_FLAG(filter) = "";
5662  GTEST_FLAG(list_tests) = false;
5663  GTEST_FLAG(output) = "";
5664  GTEST_FLAG(print_time) = true;
5665  GTEST_FLAG(random_seed) = 0;
5666  GTEST_FLAG(repeat) = 1;
5667  GTEST_FLAG(shuffle) = false;
5668  GTEST_FLAG(stack_trace_depth) = kMaxStackTraceDepth;
5669  GTEST_FLAG(stream_result_to) = "";
5670  GTEST_FLAG(throw_on_failure) = false;
5671  }
5672 
5673  // Asserts that two narrow or wide string arrays are equal.
5674  template <typename CharType>
5675  static void AssertStringArrayEq(int size1, CharType** array1, int size2,
5676  CharType** array2) {
5677  ASSERT_EQ(size1, size2) << " Array sizes different.";
5678 
5679  for (int i = 0; i != size1; i++) {
5680  ASSERT_STREQ(array1[i], array2[i]) << " where i == " << i;
5681  }
5682  }
5683 
5684  // Verifies that the flag values match the expected values.
5685  static void CheckFlags(const Flags& expected) {
5687  GTEST_FLAG(also_run_disabled_tests));
5688  EXPECT_EQ(expected.break_on_failure, GTEST_FLAG(break_on_failure));
5689  EXPECT_EQ(expected.catch_exceptions, GTEST_FLAG(catch_exceptions));
5690  EXPECT_EQ(expected.death_test_use_fork, GTEST_FLAG(death_test_use_fork));
5691  EXPECT_STREQ(expected.filter, GTEST_FLAG(filter).c_str());
5692  EXPECT_EQ(expected.list_tests, GTEST_FLAG(list_tests));
5693  EXPECT_STREQ(expected.output, GTEST_FLAG(output).c_str());
5694  EXPECT_EQ(expected.print_time, GTEST_FLAG(print_time));
5695  EXPECT_EQ(expected.random_seed, GTEST_FLAG(random_seed));
5696  EXPECT_EQ(expected.repeat, GTEST_FLAG(repeat));
5697  EXPECT_EQ(expected.shuffle, GTEST_FLAG(shuffle));
5698  EXPECT_EQ(expected.stack_trace_depth, GTEST_FLAG(stack_trace_depth));
5699  EXPECT_STREQ(expected.stream_result_to,
5700  GTEST_FLAG(stream_result_to).c_str());
5701  EXPECT_EQ(expected.throw_on_failure, GTEST_FLAG(throw_on_failure));
5702  }
5703 
5704  // Parses a command line (specified by argc1 and argv1), then
5705  // verifies that the flag values are expected and that the
5706  // recognized flags are removed from the command line.
5707  template <typename CharType>
5708  static void TestParsingFlags(int argc1, const CharType** argv1,
5709  int argc2, const CharType** argv2,
5710  const Flags& expected, bool should_print_help) {
5711  const bool saved_help_flag = ::testing::internal::g_help_flag;
5713 
5714 # if GTEST_HAS_STREAM_REDIRECTION
5715  CaptureStdout();
5716 # endif
5717 
5718  // Parses the command line.
5719  internal::ParseGoogleTestFlagsOnly(&argc1, const_cast<CharType**>(argv1));
5720 
5721 # if GTEST_HAS_STREAM_REDIRECTION
5722  const std::string captured_stdout = GetCapturedStdout();
5723 # endif
5724 
5725  // Verifies the flag values.
5726  CheckFlags(expected);
5727 
5728  // Verifies that the recognized flags are removed from the command
5729  // line.
5730  AssertStringArrayEq(argc1 + 1, argv1, argc2 + 1, argv2);
5731 
5732  // ParseGoogleTestFlagsOnly should neither set g_help_flag nor print the
5733  // help message for the flags it recognizes.
5734  EXPECT_EQ(should_print_help, ::testing::internal::g_help_flag);
5735 
5736 # if GTEST_HAS_STREAM_REDIRECTION
5737  const char* const expected_help_fragment =
5738  "This program contains tests written using";
5739  if (should_print_help) {
5740  EXPECT_PRED_FORMAT2(IsSubstring, expected_help_fragment, captured_stdout);
5741  } else {
5743  expected_help_fragment, captured_stdout);
5744  }
5745 # endif // GTEST_HAS_STREAM_REDIRECTION
5746 
5747  ::testing::internal::g_help_flag = saved_help_flag;
5748  }
5749 
5750  // This macro wraps TestParsingFlags s.t. the user doesn't need
5751  // to specify the array sizes.
5752 
5753 # define GTEST_TEST_PARSING_FLAGS_(argv1, argv2, expected, should_print_help) \
5754  TestParsingFlags(sizeof(argv1)/sizeof(*argv1) - 1, argv1, \
5755  sizeof(argv2)/sizeof(*argv2) - 1, argv2, \
5756  expected, should_print_help)
5757 };
5758 
5759 // Tests parsing an empty command line.
5761  const char* argv[] = {nullptr};
5762 
5763  const char* argv2[] = {nullptr};
5764 
5765  GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags(), false);
5766 }
5767 
5768 // Tests parsing a command line that has no flag.
5770  const char* argv[] = {"foo.exe", nullptr};
5771 
5772  const char* argv2[] = {"foo.exe", nullptr};
5773 
5774  GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags(), false);
5775 }
5776 
5777 // Tests parsing a bad --gtest_filter flag.
5778 TEST_F(ParseFlagsTest, FilterBad) {
5779  const char* argv[] = {"foo.exe", "--gtest_filter", nullptr};
5780 
5781  const char* argv2[] = {"foo.exe", "--gtest_filter", nullptr};
5782 
5783  GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Filter(""), true);
5784 }
5785 
5786 // Tests parsing an empty --gtest_filter flag.
5787 TEST_F(ParseFlagsTest, FilterEmpty) {
5788  const char* argv[] = {"foo.exe", "--gtest_filter=", nullptr};
5789 
5790  const char* argv2[] = {"foo.exe", nullptr};
5791 
5792  GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Filter(""), false);
5793 }
5794 
5795 // Tests parsing a non-empty --gtest_filter flag.
5796 TEST_F(ParseFlagsTest, FilterNonEmpty) {
5797  const char* argv[] = {"foo.exe", "--gtest_filter=abc", nullptr};
5798 
5799  const char* argv2[] = {"foo.exe", nullptr};
5800 
5801  GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Filter("abc"), false);
5802 }
5803 
5804 // Tests parsing --gtest_break_on_failure.
5805 TEST_F(ParseFlagsTest, BreakOnFailureWithoutValue) {
5806  const char* argv[] = {"foo.exe", "--gtest_break_on_failure", nullptr};
5807 
5808  const char* argv2[] = {"foo.exe", nullptr};
5809 
5810  GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::BreakOnFailure(true), false);
5811 }
5812 
5813 // Tests parsing --gtest_break_on_failure=0.
5814 TEST_F(ParseFlagsTest, BreakOnFailureFalse_0) {
5815  const char* argv[] = {"foo.exe", "--gtest_break_on_failure=0", nullptr};
5816 
5817  const char* argv2[] = {"foo.exe", nullptr};
5818 
5819  GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::BreakOnFailure(false), false);
5820 }
5821 
5822 // Tests parsing --gtest_break_on_failure=f.
5823 TEST_F(ParseFlagsTest, BreakOnFailureFalse_f) {
5824  const char* argv[] = {"foo.exe", "--gtest_break_on_failure=f", nullptr};
5825 
5826  const char* argv2[] = {"foo.exe", nullptr};
5827 
5828  GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::BreakOnFailure(false), false);
5829 }
5830 
5831 // Tests parsing --gtest_break_on_failure=F.
5832 TEST_F(ParseFlagsTest, BreakOnFailureFalse_F) {
5833  const char* argv[] = {"foo.exe", "--gtest_break_on_failure=F", nullptr};
5834 
5835  const char* argv2[] = {"foo.exe", nullptr};
5836 
5837  GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::BreakOnFailure(false), false);
5838 }
5839 
5840 // Tests parsing a --gtest_break_on_failure flag that has a "true"
5841 // definition.
5842 TEST_F(ParseFlagsTest, BreakOnFailureTrue) {
5843  const char* argv[] = {"foo.exe", "--gtest_break_on_failure=1", nullptr};
5844 
5845  const char* argv2[] = {"foo.exe", nullptr};
5846 
5847  GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::BreakOnFailure(true), false);
5848 }
5849 
5850 // Tests parsing --gtest_catch_exceptions.
5851 TEST_F(ParseFlagsTest, CatchExceptions) {
5852  const char* argv[] = {"foo.exe", "--gtest_catch_exceptions", nullptr};
5853 
5854  const char* argv2[] = {"foo.exe", nullptr};
5855 
5856  GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::CatchExceptions(true), false);
5857 }
5858 
5859 // Tests parsing --gtest_death_test_use_fork.
5860 TEST_F(ParseFlagsTest, DeathTestUseFork) {
5861  const char* argv[] = {"foo.exe", "--gtest_death_test_use_fork", nullptr};
5862 
5863  const char* argv2[] = {"foo.exe", nullptr};
5864 
5865  GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::DeathTestUseFork(true), false);
5866 }
5867 
5868 // Tests having the same flag twice with different values. The
5869 // expected behavior is that the one coming last takes precedence.
5870 TEST_F(ParseFlagsTest, DuplicatedFlags) {
5871  const char* argv[] = {"foo.exe", "--gtest_filter=a", "--gtest_filter=b",
5872  nullptr};
5873 
5874  const char* argv2[] = {"foo.exe", nullptr};
5875 
5876  GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Filter("b"), false);
5877 }
5878 
5879 // Tests having an unrecognized flag on the command line.
5880 TEST_F(ParseFlagsTest, UnrecognizedFlag) {
5881  const char* argv[] = {"foo.exe", "--gtest_break_on_failure",
5882  "bar", // Unrecognized by Google Test.
5883  "--gtest_filter=b", nullptr};
5884 
5885  const char* argv2[] = {"foo.exe", "bar", nullptr};
5886 
5887  Flags flags;
5888  flags.break_on_failure = true;
5889  flags.filter = "b";
5890  GTEST_TEST_PARSING_FLAGS_(argv, argv2, flags, false);
5891 }
5892 
5893 // Tests having a --gtest_list_tests flag
5894 TEST_F(ParseFlagsTest, ListTestsFlag) {
5895  const char* argv[] = {"foo.exe", "--gtest_list_tests", nullptr};
5896 
5897  const char* argv2[] = {"foo.exe", nullptr};
5898 
5899  GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::ListTests(true), false);
5900 }
5901 
5902 // Tests having a --gtest_list_tests flag with a "true" value
5903 TEST_F(ParseFlagsTest, ListTestsTrue) {
5904  const char* argv[] = {"foo.exe", "--gtest_list_tests=1", nullptr};
5905 
5906  const char* argv2[] = {"foo.exe", nullptr};
5907 
5908  GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::ListTests(true), false);
5909 }
5910 
5911 // Tests having a --gtest_list_tests flag with a "false" value
5912 TEST_F(ParseFlagsTest, ListTestsFalse) {
5913  const char* argv[] = {"foo.exe", "--gtest_list_tests=0", nullptr};
5914 
5915  const char* argv2[] = {"foo.exe", nullptr};
5916 
5917  GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::ListTests(false), false);
5918 }
5919 
5920 // Tests parsing --gtest_list_tests=f.
5921 TEST_F(ParseFlagsTest, ListTestsFalse_f) {
5922  const char* argv[] = {"foo.exe", "--gtest_list_tests=f", nullptr};
5923 
5924  const char* argv2[] = {"foo.exe", nullptr};
5925 
5926  GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::ListTests(false), false);
5927 }
5928 
5929 // Tests parsing --gtest_list_tests=F.
5930 TEST_F(ParseFlagsTest, ListTestsFalse_F) {
5931  const char* argv[] = {"foo.exe", "--gtest_list_tests=F", nullptr};
5932 
5933  const char* argv2[] = {"foo.exe", nullptr};
5934 
5935  GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::ListTests(false), false);
5936 }
5937 
5938 // Tests parsing --gtest_output (invalid).
5939 TEST_F(ParseFlagsTest, OutputEmpty) {
5940  const char* argv[] = {"foo.exe", "--gtest_output", nullptr};
5941 
5942  const char* argv2[] = {"foo.exe", "--gtest_output", nullptr};
5943 
5944  GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags(), true);
5945 }
5946 
5947 // Tests parsing --gtest_output=xml
5948 TEST_F(ParseFlagsTest, OutputXml) {
5949  const char* argv[] = {"foo.exe", "--gtest_output=xml", nullptr};
5950 
5951  const char* argv2[] = {"foo.exe", nullptr};
5952 
5953  GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Output("xml"), false);
5954 }
5955 
5956 // Tests parsing --gtest_output=xml:file
5957 TEST_F(ParseFlagsTest, OutputXmlFile) {
5958  const char* argv[] = {"foo.exe", "--gtest_output=xml:file", nullptr};
5959 
5960  const char* argv2[] = {"foo.exe", nullptr};
5961 
5962  GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Output("xml:file"), false);
5963 }
5964 
5965 // Tests parsing --gtest_output=xml:directory/path/
5966 TEST_F(ParseFlagsTest, OutputXmlDirectory) {
5967  const char* argv[] = {"foo.exe", "--gtest_output=xml:directory/path/",
5968  nullptr};
5969 
5970  const char* argv2[] = {"foo.exe", nullptr};
5971 
5972  GTEST_TEST_PARSING_FLAGS_(argv, argv2,
5973  Flags::Output("xml:directory/path/"), false);
5974 }
5975 
5976 // Tests having a --gtest_print_time flag
5977 TEST_F(ParseFlagsTest, PrintTimeFlag) {
5978  const char* argv[] = {"foo.exe", "--gtest_print_time", nullptr};
5979 
5980  const char* argv2[] = {"foo.exe", nullptr};
5981 
5982  GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::PrintTime(true), false);
5983 }
5984 
5985 // Tests having a --gtest_print_time flag with a "true" value
5986 TEST_F(ParseFlagsTest, PrintTimeTrue) {
5987  const char* argv[] = {"foo.exe", "--gtest_print_time=1", nullptr};
5988 
5989  const char* argv2[] = {"foo.exe", nullptr};
5990 
5991  GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::PrintTime(true), false);
5992 }
5993 
5994 // Tests having a --gtest_print_time flag with a "false" value
5995 TEST_F(ParseFlagsTest, PrintTimeFalse) {
5996  const char* argv[] = {"foo.exe", "--gtest_print_time=0", nullptr};
5997 
5998  const char* argv2[] = {"foo.exe", nullptr};
5999 
6000  GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::PrintTime(false), false);
6001 }
6002 
6003 // Tests parsing --gtest_print_time=f.
6004 TEST_F(ParseFlagsTest, PrintTimeFalse_f) {
6005  const char* argv[] = {"foo.exe", "--gtest_print_time=f", nullptr};
6006 
6007  const char* argv2[] = {"foo.exe", nullptr};
6008 
6009  GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::PrintTime(false), false);
6010 }
6011 
6012 // Tests parsing --gtest_print_time=F.
6013 TEST_F(ParseFlagsTest, PrintTimeFalse_F) {
6014  const char* argv[] = {"foo.exe", "--gtest_print_time=F", nullptr};
6015 
6016  const char* argv2[] = {"foo.exe", nullptr};
6017 
6018  GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::PrintTime(false), false);
6019 }
6020 
6021 // Tests parsing --gtest_random_seed=number
6023  const char* argv[] = {"foo.exe", "--gtest_random_seed=1000", nullptr};
6024 
6025  const char* argv2[] = {"foo.exe", nullptr};
6026 
6027  GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::RandomSeed(1000), false);
6028 }
6029 
6030 // Tests parsing --gtest_repeat=number
6032  const char* argv[] = {"foo.exe", "--gtest_repeat=1000", nullptr};
6033 
6034  const char* argv2[] = {"foo.exe", nullptr};
6035 
6036  GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Repeat(1000), false);
6037 }
6038 
6039 // Tests having a --gtest_also_run_disabled_tests flag
6041  const char* argv[] = {"foo.exe", "--gtest_also_run_disabled_tests", nullptr};
6042 
6043  const char* argv2[] = {"foo.exe", nullptr};
6044 
6046  false);
6047 }
6048 
6049 // Tests having a --gtest_also_run_disabled_tests flag with a "true" value
6050 TEST_F(ParseFlagsTest, AlsoRunDisabledTestsTrue) {
6051  const char* argv[] = {"foo.exe", "--gtest_also_run_disabled_tests=1",
6052  nullptr};
6053 
6054  const char* argv2[] = {"foo.exe", nullptr};
6055 
6057  false);
6058 }
6059 
6060 // Tests having a --gtest_also_run_disabled_tests flag with a "false" value
6061 TEST_F(ParseFlagsTest, AlsoRunDisabledTestsFalse) {
6062  const char* argv[] = {"foo.exe", "--gtest_also_run_disabled_tests=0",
6063  nullptr};
6064 
6065  const char* argv2[] = {"foo.exe", nullptr};
6066 
6068  false);
6069 }
6070 
6071 // Tests parsing --gtest_shuffle.
6072 TEST_F(ParseFlagsTest, ShuffleWithoutValue) {
6073  const char* argv[] = {"foo.exe", "--gtest_shuffle", nullptr};
6074 
6075  const char* argv2[] = {"foo.exe", nullptr};
6076 
6077  GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Shuffle(true), false);
6078 }
6079 
6080 // Tests parsing --gtest_shuffle=0.
6081 TEST_F(ParseFlagsTest, ShuffleFalse_0) {
6082  const char* argv[] = {"foo.exe", "--gtest_shuffle=0", nullptr};
6083 
6084  const char* argv2[] = {"foo.exe", nullptr};
6085 
6086  GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Shuffle(false), false);
6087 }
6088 
6089 // Tests parsing a --gtest_shuffle flag that has a "true" definition.
6090 TEST_F(ParseFlagsTest, ShuffleTrue) {
6091  const char* argv[] = {"foo.exe", "--gtest_shuffle=1", nullptr};
6092 
6093  const char* argv2[] = {"foo.exe", nullptr};
6094 
6095  GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Shuffle(true), false);
6096 }
6097 
6098 // Tests parsing --gtest_stack_trace_depth=number.
6099 TEST_F(ParseFlagsTest, StackTraceDepth) {
6100  const char* argv[] = {"foo.exe", "--gtest_stack_trace_depth=5", nullptr};
6101 
6102  const char* argv2[] = {"foo.exe", nullptr};
6103 
6104  GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::StackTraceDepth(5), false);
6105 }
6106 
6107 TEST_F(ParseFlagsTest, StreamResultTo) {
6108  const char* argv[] = {"foo.exe", "--gtest_stream_result_to=localhost:1234",
6109  nullptr};
6110 
6111  const char* argv2[] = {"foo.exe", nullptr};
6112 
6114  argv, argv2, Flags::StreamResultTo("localhost:1234"), false);
6115 }
6116 
6117 // Tests parsing --gtest_throw_on_failure.
6118 TEST_F(ParseFlagsTest, ThrowOnFailureWithoutValue) {
6119  const char* argv[] = {"foo.exe", "--gtest_throw_on_failure", nullptr};
6120 
6121  const char* argv2[] = {"foo.exe", nullptr};
6122 
6123  GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::ThrowOnFailure(true), false);
6124 }
6125 
6126 // Tests parsing --gtest_throw_on_failure=0.
6127 TEST_F(ParseFlagsTest, ThrowOnFailureFalse_0) {
6128  const char* argv[] = {"foo.exe", "--gtest_throw_on_failure=0", nullptr};
6129 
6130  const char* argv2[] = {"foo.exe", nullptr};
6131 
6132  GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::ThrowOnFailure(false), false);
6133 }
6134 
6135 // Tests parsing a --gtest_throw_on_failure flag that has a "true"
6136 // definition.
6137 TEST_F(ParseFlagsTest, ThrowOnFailureTrue) {
6138  const char* argv[] = {"foo.exe", "--gtest_throw_on_failure=1", nullptr};
6139 
6140  const char* argv2[] = {"foo.exe", nullptr};
6141 
6142  GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::ThrowOnFailure(true), false);
6143 }
6144 
6145 # if GTEST_OS_WINDOWS
6146 // Tests parsing wide strings.
6147 TEST_F(ParseFlagsTest, WideStrings) {
6148  const wchar_t* argv[] = {
6149  L"foo.exe",
6150  L"--gtest_filter=Foo*",
6151  L"--gtest_list_tests=1",
6152  L"--gtest_break_on_failure",
6153  L"--non_gtest_flag",
6154  NULL
6155  };
6156 
6157  const wchar_t* argv2[] = {
6158  L"foo.exe",
6159  L"--non_gtest_flag",
6160  NULL
6161  };
6162 
6163  Flags expected_flags;
6164  expected_flags.break_on_failure = true;
6165  expected_flags.filter = "Foo*";
6166  expected_flags.list_tests = true;
6167 
6168  GTEST_TEST_PARSING_FLAGS_(argv, argv2, expected_flags, false);
6169 }
6170 # endif // GTEST_OS_WINDOWS
6171 
6172 #if GTEST_USE_OWN_FLAGFILE_FLAG_
6173 class FlagfileTest : public ParseFlagsTest {
6174  public:
6175  virtual void SetUp() {
6177 
6180  "_flagfile_test"));
6182  EXPECT_TRUE(testdata_path_.CreateFolder());
6183  }
6184 
6185  virtual void TearDown() {
6188  }
6189 
6190  internal::FilePath CreateFlagfile(const char* contents) {
6192  testdata_path_, internal::FilePath("unique"), "txt"));
6193  FILE* f = testing::internal::posix::FOpen(file_path.c_str(), "w");
6194  fprintf(f, "%s", contents);
6195  fclose(f);
6196  return file_path;
6197  }
6198 
6199  private:
6201 };
6202 
6203 // Tests an empty flagfile.
6204 TEST_F(FlagfileTest, Empty) {
6205  internal::FilePath flagfile_path(CreateFlagfile(""));
6206  std::string flagfile_flag =
6207  std::string("--" GTEST_FLAG_PREFIX_ "flagfile=") + flagfile_path.c_str();
6208 
6209  const char* argv[] = {"foo.exe", flagfile_flag.c_str(), nullptr};
6210 
6211  const char* argv2[] = {"foo.exe", nullptr};
6212 
6213  GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags(), false);
6214 }
6215 
6216 // Tests passing a non-empty --gtest_filter flag via --gtest_flagfile.
6217 TEST_F(FlagfileTest, FilterNonEmpty) {
6218  internal::FilePath flagfile_path(CreateFlagfile(
6219  "--" GTEST_FLAG_PREFIX_ "filter=abc"));
6220  std::string flagfile_flag =
6221  std::string("--" GTEST_FLAG_PREFIX_ "flagfile=") + flagfile_path.c_str();
6222 
6223  const char* argv[] = {"foo.exe", flagfile_flag.c_str(), nullptr};
6224 
6225  const char* argv2[] = {"foo.exe", nullptr};
6226 
6227  GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Filter("abc"), false);
6228 }
6229 
6230 // Tests passing several flags via --gtest_flagfile.
6231 TEST_F(FlagfileTest, SeveralFlags) {
6232  internal::FilePath flagfile_path(CreateFlagfile(
6233  "--" GTEST_FLAG_PREFIX_ "filter=abc\n"
6234  "--" GTEST_FLAG_PREFIX_ "break_on_failure\n"
6235  "--" GTEST_FLAG_PREFIX_ "list_tests"));
6236  std::string flagfile_flag =
6237  std::string("--" GTEST_FLAG_PREFIX_ "flagfile=") + flagfile_path.c_str();
6238 
6239  const char* argv[] = {"foo.exe", flagfile_flag.c_str(), nullptr};
6240 
6241  const char* argv2[] = {"foo.exe", nullptr};
6242 
6243  Flags expected_flags;
6244  expected_flags.break_on_failure = true;
6245  expected_flags.filter = "abc";
6246  expected_flags.list_tests = true;
6247 
6248  GTEST_TEST_PARSING_FLAGS_(argv, argv2, expected_flags, false);
6249 }
6250 #endif // GTEST_USE_OWN_FLAGFILE_FLAG_
6251 
6252 // Tests current_test_info() in UnitTest.
6253 class CurrentTestInfoTest : public Test {
6254  protected:
6255  // Tests that current_test_info() returns NULL before the first test in
6256  // the test case is run.
6257  static void SetUpTestSuite() {
6258  // There should be no tests running at this point.
6259  const TestInfo* test_info =
6261  EXPECT_TRUE(test_info == nullptr)
6262  << "There should be no tests running at this point.";
6263  }
6264 
6265  // Tests that current_test_info() returns NULL after the last test in
6266  // the test case has run.
6267  static void TearDownTestSuite() {
6268  const TestInfo* test_info =
6270  EXPECT_TRUE(test_info == nullptr)
6271  << "There should be no tests running at this point.";
6272  }
6273 };
6274 
6275 // Tests that current_test_info() returns TestInfo for currently running
6276 // test by checking the expected test name against the actual one.
6277 TEST_F(CurrentTestInfoTest, WorksForFirstTestInATestSuite) {
6278  const TestInfo* test_info =
6280  ASSERT_TRUE(nullptr != test_info)
6281  << "There is a test running so we should have a valid TestInfo.";
6282  EXPECT_STREQ("CurrentTestInfoTest", test_info->test_case_name())
6283  << "Expected the name of the currently running test case.";
6284  EXPECT_STREQ("WorksForFirstTestInATestSuite", test_info->name())
6285  << "Expected the name of the currently running test.";
6286 }
6287 
6288 // Tests that current_test_info() returns TestInfo for currently running
6289 // test by checking the expected test name against the actual one. We
6290 // use this test to see that the TestInfo object actually changed from
6291 // the previous invocation.
6292 TEST_F(CurrentTestInfoTest, WorksForSecondTestInATestSuite) {
6293  const TestInfo* test_info =
6295  ASSERT_TRUE(nullptr != test_info)
6296  << "There is a test running so we should have a valid TestInfo.";
6297  EXPECT_STREQ("CurrentTestInfoTest", test_info->test_case_name())
6298  << "Expected the name of the currently running test case.";
6299  EXPECT_STREQ("WorksForSecondTestInATestSuite", test_info->name())
6300  << "Expected the name of the currently running test.";
6301 }
6302 
6303 } // namespace testing
6304 
6305 
6306 // These two lines test that we can define tests in a namespace that
6307 // has the name "testing" and is nested in another namespace.
6308 namespace my_namespace {
6309 namespace testing {
6310 
6311 // Makes sure that TEST knows to use ::testing::Test instead of
6312 // ::my_namespace::testing::Test.
6313 class Test {};
6314 
6315 // Makes sure that an assertion knows to use ::testing::Message instead of
6316 // ::my_namespace::testing::Message.
6317 class Message {};
6318 
6319 // Makes sure that an assertion knows to use
6320 // ::testing::AssertionResult instead of
6321 // ::my_namespace::testing::AssertionResult.
6323 
6324 // Tests that an assertion that should succeed works as expected.
6325 TEST(NestedTestingNamespaceTest, Success) {
6326  EXPECT_EQ(1, 1) << "This shouldn't fail.";
6327 }
6328 
6329 // Tests that an assertion that should fail works as expected.
6330 TEST(NestedTestingNamespaceTest, Failure) {
6331  EXPECT_FATAL_FAILURE(FAIL() << "This failure is expected.",
6332  "This failure is expected.");
6333 }
6334 
6335 } // namespace testing
6336 } // namespace my_namespace
6337 
6338 // Tests that one can call superclass SetUp and TearDown methods--
6339 // that is, that they are not private.
6340 // No tests are based on this fixture; the test "passes" if it compiles
6341 // successfully.
6343  protected:
6344  void SetUp() override { Test::SetUp(); }
6345  void TearDown() override { Test::TearDown(); }
6346 };
6347 
6348 // StreamingAssertionsTest tests the streaming versions of a representative
6349 // sample of assertions.
6350 TEST(StreamingAssertionsTest, Unconditional) {
6351  SUCCEED() << "expected success";
6352  EXPECT_NONFATAL_FAILURE(ADD_FAILURE() << "expected failure",
6353  "expected failure");
6354  EXPECT_FATAL_FAILURE(FAIL() << "expected failure",
6355  "expected failure");
6356 }
6357 
6358 #ifdef __BORLANDC__
6359 // Silences warnings: "Condition is always true", "Unreachable code"
6360 # pragma option push -w-ccc -w-rch
6361 #endif
6362 
6363 TEST(StreamingAssertionsTest, Truth) {
6364  EXPECT_TRUE(true) << "unexpected failure";
6365  ASSERT_TRUE(true) << "unexpected failure";
6366  EXPECT_NONFATAL_FAILURE(EXPECT_TRUE(false) << "expected failure",
6367  "expected failure");
6368  EXPECT_FATAL_FAILURE(ASSERT_TRUE(false) << "expected failure",
6369  "expected failure");
6370 }
6371 
6372 TEST(StreamingAssertionsTest, Truth2) {
6373  EXPECT_FALSE(false) << "unexpected failure";
6374  ASSERT_FALSE(false) << "unexpected failure";
6375  EXPECT_NONFATAL_FAILURE(EXPECT_FALSE(true) << "expected failure",
6376  "expected failure");
6377  EXPECT_FATAL_FAILURE(ASSERT_FALSE(true) << "expected failure",
6378  "expected failure");
6379 }
6380 
6381 #ifdef __BORLANDC__
6382 // Restores warnings after previous "#pragma option push" suppressed them
6383 # pragma option pop
6384 #endif
6385 
6386 TEST(StreamingAssertionsTest, IntegerEquals) {
6387  EXPECT_EQ(1, 1) << "unexpected failure";
6388  ASSERT_EQ(1, 1) << "unexpected failure";
6389  EXPECT_NONFATAL_FAILURE(EXPECT_EQ(1, 2) << "expected failure",
6390  "expected failure");
6391  EXPECT_FATAL_FAILURE(ASSERT_EQ(1, 2) << "expected failure",
6392  "expected failure");
6393 }
6394 
6395 TEST(StreamingAssertionsTest, IntegerLessThan) {
6396  EXPECT_LT(1, 2) << "unexpected failure";
6397  ASSERT_LT(1, 2) << "unexpected failure";
6398  EXPECT_NONFATAL_FAILURE(EXPECT_LT(2, 1) << "expected failure",
6399  "expected failure");
6400  EXPECT_FATAL_FAILURE(ASSERT_LT(2, 1) << "expected failure",
6401  "expected failure");
6402 }
6403 
6404 TEST(StreamingAssertionsTest, StringsEqual) {
6405  EXPECT_STREQ("foo", "foo") << "unexpected failure";
6406  ASSERT_STREQ("foo", "foo") << "unexpected failure";
6407  EXPECT_NONFATAL_FAILURE(EXPECT_STREQ("foo", "bar") << "expected failure",
6408  "expected failure");
6409  EXPECT_FATAL_FAILURE(ASSERT_STREQ("foo", "bar") << "expected failure",
6410  "expected failure");
6411 }
6412 
6413 TEST(StreamingAssertionsTest, StringsNotEqual) {
6414  EXPECT_STRNE("foo", "bar") << "unexpected failure";
6415  ASSERT_STRNE("foo", "bar") << "unexpected failure";
6416  EXPECT_NONFATAL_FAILURE(EXPECT_STRNE("foo", "foo") << "expected failure",
6417  "expected failure");
6418  EXPECT_FATAL_FAILURE(ASSERT_STRNE("foo", "foo") << "expected failure",
6419  "expected failure");
6420 }
6421 
6422 TEST(StreamingAssertionsTest, StringsEqualIgnoringCase) {
6423  EXPECT_STRCASEEQ("foo", "FOO") << "unexpected failure";
6424  ASSERT_STRCASEEQ("foo", "FOO") << "unexpected failure";
6425  EXPECT_NONFATAL_FAILURE(EXPECT_STRCASEEQ("foo", "bar") << "expected failure",
6426  "expected failure");
6427  EXPECT_FATAL_FAILURE(ASSERT_STRCASEEQ("foo", "bar") << "expected failure",
6428  "expected failure");
6429 }
6430 
6431 TEST(StreamingAssertionsTest, StringNotEqualIgnoringCase) {
6432  EXPECT_STRCASENE("foo", "bar") << "unexpected failure";
6433  ASSERT_STRCASENE("foo", "bar") << "unexpected failure";
6434  EXPECT_NONFATAL_FAILURE(EXPECT_STRCASENE("foo", "FOO") << "expected failure",
6435  "expected failure");
6436  EXPECT_FATAL_FAILURE(ASSERT_STRCASENE("bar", "BAR") << "expected failure",
6437  "expected failure");
6438 }
6439 
6440 TEST(StreamingAssertionsTest, FloatingPointEquals) {
6441  EXPECT_FLOAT_EQ(1.0, 1.0) << "unexpected failure";
6442  ASSERT_FLOAT_EQ(1.0, 1.0) << "unexpected failure";
6443  EXPECT_NONFATAL_FAILURE(EXPECT_FLOAT_EQ(0.0, 1.0) << "expected failure",
6444  "expected failure");
6445  EXPECT_FATAL_FAILURE(ASSERT_FLOAT_EQ(0.0, 1.0) << "expected failure",
6446  "expected failure");
6447 }
6448 
6449 #if GTEST_HAS_EXCEPTIONS
6450 
6451 TEST(StreamingAssertionsTest, Throw) {
6452  EXPECT_THROW(ThrowAnInteger(), int) << "unexpected failure";
6453  ASSERT_THROW(ThrowAnInteger(), int) << "unexpected failure";
6454  EXPECT_NONFATAL_FAILURE(EXPECT_THROW(ThrowAnInteger(), bool) <<
6455  "expected failure", "expected failure");
6456  EXPECT_FATAL_FAILURE(ASSERT_THROW(ThrowAnInteger(), bool) <<
6457  "expected failure", "expected failure");
6458 }
6459 
6460 TEST(StreamingAssertionsTest, NoThrow) {
6461  EXPECT_NO_THROW(ThrowNothing()) << "unexpected failure";
6462  ASSERT_NO_THROW(ThrowNothing()) << "unexpected failure";
6463  EXPECT_NONFATAL_FAILURE(EXPECT_NO_THROW(ThrowAnInteger()) <<
6464  "expected failure", "expected failure");
6465  EXPECT_FATAL_FAILURE(ASSERT_NO_THROW(ThrowAnInteger()) <<
6466  "expected failure", "expected failure");
6467 }
6468 
6469 TEST(StreamingAssertionsTest, AnyThrow) {
6470  EXPECT_ANY_THROW(ThrowAnInteger()) << "unexpected failure";
6471  ASSERT_ANY_THROW(ThrowAnInteger()) << "unexpected failure";
6472  EXPECT_NONFATAL_FAILURE(EXPECT_ANY_THROW(ThrowNothing()) <<
6473  "expected failure", "expected failure");
6474  EXPECT_FATAL_FAILURE(ASSERT_ANY_THROW(ThrowNothing()) <<
6475  "expected failure", "expected failure");
6476 }
6477 
6478 #endif // GTEST_HAS_EXCEPTIONS
6479 
6480 // Tests that Google Test correctly decides whether to use colors in the output.
6481 
6482 TEST(ColoredOutputTest, UsesColorsWhenGTestColorFlagIsYes) {
6483  GTEST_FLAG(color) = "yes";
6484 
6485  SetEnv("TERM", "xterm"); // TERM supports colors.
6486  EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY.
6487  EXPECT_TRUE(ShouldUseColor(false)); // Stdout is not a TTY.
6488 
6489  SetEnv("TERM", "dumb"); // TERM doesn't support colors.
6490  EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY.
6491  EXPECT_TRUE(ShouldUseColor(false)); // Stdout is not a TTY.
6492 }
6493 
6494 TEST(ColoredOutputTest, UsesColorsWhenGTestColorFlagIsAliasOfYes) {
6495  SetEnv("TERM", "dumb"); // TERM doesn't support colors.
6496 
6497  GTEST_FLAG(color) = "True";
6498  EXPECT_TRUE(ShouldUseColor(false)); // Stdout is not a TTY.
6499 
6500  GTEST_FLAG(color) = "t";
6501  EXPECT_TRUE(ShouldUseColor(false)); // Stdout is not a TTY.
6502 
6503  GTEST_FLAG(color) = "1";
6504  EXPECT_TRUE(ShouldUseColor(false)); // Stdout is not a TTY.
6505 }
6506 
6507 TEST(ColoredOutputTest, UsesNoColorWhenGTestColorFlagIsNo) {
6508  GTEST_FLAG(color) = "no";
6509 
6510  SetEnv("TERM", "xterm"); // TERM supports colors.
6511  EXPECT_FALSE(ShouldUseColor(true)); // Stdout is a TTY.
6512  EXPECT_FALSE(ShouldUseColor(false)); // Stdout is not a TTY.
6513 
6514  SetEnv("TERM", "dumb"); // TERM doesn't support colors.
6515  EXPECT_FALSE(ShouldUseColor(true)); // Stdout is a TTY.
6516  EXPECT_FALSE(ShouldUseColor(false)); // Stdout is not a TTY.
6517 }
6518 
6519 TEST(ColoredOutputTest, UsesNoColorWhenGTestColorFlagIsInvalid) {
6520  SetEnv("TERM", "xterm"); // TERM supports colors.
6521 
6522  GTEST_FLAG(color) = "F";
6523  EXPECT_FALSE(ShouldUseColor(true)); // Stdout is a TTY.
6524 
6525  GTEST_FLAG(color) = "0";
6526  EXPECT_FALSE(ShouldUseColor(true)); // Stdout is a TTY.
6527 
6528  GTEST_FLAG(color) = "unknown";
6529  EXPECT_FALSE(ShouldUseColor(true)); // Stdout is a TTY.
6530 }
6531 
6532 TEST(ColoredOutputTest, UsesColorsWhenStdoutIsTty) {
6533  GTEST_FLAG(color) = "auto";
6534 
6535  SetEnv("TERM", "xterm"); // TERM supports colors.
6536  EXPECT_FALSE(ShouldUseColor(false)); // Stdout is not a TTY.
6537  EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY.
6538 }
6539 
6540 TEST(ColoredOutputTest, UsesColorsWhenTermSupportsColors) {
6541  GTEST_FLAG(color) = "auto";
6542 
6543 #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW
6544  // On Windows, we ignore the TERM variable as it's usually not set.
6545 
6546  SetEnv("TERM", "dumb");
6547  EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY.
6548 
6549  SetEnv("TERM", "");
6550  EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY.
6551 
6552  SetEnv("TERM", "xterm");
6553  EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY.
6554 #else
6555  // On non-Windows platforms, we rely on TERM to determine if the
6556  // terminal supports colors.
6557 
6558  SetEnv("TERM", "dumb"); // TERM doesn't support colors.
6559  EXPECT_FALSE(ShouldUseColor(true)); // Stdout is a TTY.
6560 
6561  SetEnv("TERM", "emacs"); // TERM doesn't support colors.
6562  EXPECT_FALSE(ShouldUseColor(true)); // Stdout is a TTY.
6563 
6564  SetEnv("TERM", "vt100"); // TERM doesn't support colors.
6565  EXPECT_FALSE(ShouldUseColor(true)); // Stdout is a TTY.
6566 
6567  SetEnv("TERM", "xterm-mono"); // TERM doesn't support colors.
6568  EXPECT_FALSE(ShouldUseColor(true)); // Stdout is a TTY.
6569 
6570  SetEnv("TERM", "xterm"); // TERM supports colors.
6571  EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY.
6572 
6573  SetEnv("TERM", "xterm-color"); // TERM supports colors.
6574  EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY.
6575 
6576  SetEnv("TERM", "xterm-256color"); // TERM supports colors.
6577  EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY.
6578 
6579  SetEnv("TERM", "screen"); // TERM supports colors.
6580  EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY.
6581 
6582  SetEnv("TERM", "screen-256color"); // TERM supports colors.
6583  EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY.
6584 
6585  SetEnv("TERM", "tmux"); // TERM supports colors.
6586  EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY.
6587 
6588  SetEnv("TERM", "tmux-256color"); // TERM supports colors.
6589  EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY.
6590 
6591  SetEnv("TERM", "rxvt-unicode"); // TERM supports colors.
6592  EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY.
6593 
6594  SetEnv("TERM", "rxvt-unicode-256color"); // TERM supports colors.
6595  EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY.
6596 
6597  SetEnv("TERM", "linux"); // TERM supports colors.
6598  EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY.
6599 
6600  SetEnv("TERM", "cygwin"); // TERM supports colors.
6601  EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY.
6602 #endif // GTEST_OS_WINDOWS
6603 }
6604 
6605 // Verifies that StaticAssertTypeEq works in a namespace scope.
6606 
6607 static bool dummy1 GTEST_ATTRIBUTE_UNUSED_ = StaticAssertTypeEq<bool, bool>();
6608 static bool dummy2 GTEST_ATTRIBUTE_UNUSED_ =
6609  StaticAssertTypeEq<const int, const int>();
6610 
6611 // Verifies that StaticAssertTypeEq works in a class.
6612 
6613 template <typename T>
6615  public:
6616  StaticAssertTypeEqTestHelper() { StaticAssertTypeEq<bool, T>(); }
6617 };
6618 
6619 TEST(StaticAssertTypeEqTest, WorksInClass) {
6621 }
6622 
6623 // Verifies that StaticAssertTypeEq works inside a function.
6624 
6625 typedef int IntAlias;
6626 
6627 TEST(StaticAssertTypeEqTest, CompilesForEqualTypes) {
6628  StaticAssertTypeEq<int, IntAlias>();
6629  StaticAssertTypeEq<int*, IntAlias*>();
6630 }
6631 
6632 TEST(HasNonfatalFailureTest, ReturnsFalseWhenThereIsNoFailure) {
6633  EXPECT_FALSE(HasNonfatalFailure());
6634 }
6635 
6636 static void FailFatally() { FAIL(); }
6637 
6638 TEST(HasNonfatalFailureTest, ReturnsFalseWhenThereIsOnlyFatalFailure) {
6639  FailFatally();
6640  const bool has_nonfatal_failure = HasNonfatalFailure();
6641  ClearCurrentTestPartResults();
6642  EXPECT_FALSE(has_nonfatal_failure);
6643 }
6644 
6645 TEST(HasNonfatalFailureTest, ReturnsTrueWhenThereIsNonfatalFailure) {
6646  ADD_FAILURE();
6647  const bool has_nonfatal_failure = HasNonfatalFailure();
6648  ClearCurrentTestPartResults();
6649  EXPECT_TRUE(has_nonfatal_failure);
6650 }
6651 
6652 TEST(HasNonfatalFailureTest, ReturnsTrueWhenThereAreFatalAndNonfatalFailures) {
6653  FailFatally();
6654  ADD_FAILURE();
6655  const bool has_nonfatal_failure = HasNonfatalFailure();
6656  ClearCurrentTestPartResults();
6657  EXPECT_TRUE(has_nonfatal_failure);
6658 }
6659 
6660 // A wrapper for calling HasNonfatalFailure outside of a test body.
6663 }
6664 
6665 TEST(HasNonfatalFailureTest, WorksOutsideOfTestBody) {
6667 }
6668 
6669 TEST(HasNonfatalFailureTest, WorksOutsideOfTestBody2) {
6670  ADD_FAILURE();
6671  const bool has_nonfatal_failure = HasNonfatalFailureHelper();
6672  ClearCurrentTestPartResults();
6673  EXPECT_TRUE(has_nonfatal_failure);
6674 }
6675 
6676 TEST(HasFailureTest, ReturnsFalseWhenThereIsNoFailure) {
6677  EXPECT_FALSE(HasFailure());
6678 }
6679 
6680 TEST(HasFailureTest, ReturnsTrueWhenThereIsFatalFailure) {
6681  FailFatally();
6682  const bool has_failure = HasFailure();
6683  ClearCurrentTestPartResults();
6684  EXPECT_TRUE(has_failure);
6685 }
6686 
6687 TEST(HasFailureTest, ReturnsTrueWhenThereIsNonfatalFailure) {
6688  ADD_FAILURE();
6689  const bool has_failure = HasFailure();
6690  ClearCurrentTestPartResults();
6691  EXPECT_TRUE(has_failure);
6692 }
6693 
6694 TEST(HasFailureTest, ReturnsTrueWhenThereAreFatalAndNonfatalFailures) {
6695  FailFatally();
6696  ADD_FAILURE();
6697  const bool has_failure = HasFailure();
6698  ClearCurrentTestPartResults();
6699  EXPECT_TRUE(has_failure);
6700 }
6701 
6702 // A wrapper for calling HasFailure outside of a test body.
6703 static bool HasFailureHelper() { return testing::Test::HasFailure(); }
6704 
6705 TEST(HasFailureTest, WorksOutsideOfTestBody) {
6707 }
6708 
6709 TEST(HasFailureTest, WorksOutsideOfTestBody2) {
6710  ADD_FAILURE();
6711  const bool has_failure = HasFailureHelper();
6712  ClearCurrentTestPartResults();
6713  EXPECT_TRUE(has_failure);
6714 }
6715 
6717  public:
6719  TestListener(int* on_start_counter, bool* is_destroyed)
6720  : on_start_counter_(on_start_counter),
6721  is_destroyed_(is_destroyed) {}
6722 
6723  ~TestListener() override {
6724  if (is_destroyed_)
6725  *is_destroyed_ = true;
6726  }
6727 
6728  protected:
6729  void OnTestProgramStart(const UnitTest& /*unit_test*/) override {
6730  if (on_start_counter_ != nullptr) (*on_start_counter_)++;
6731  }
6732 
6733  private:
6736 };
6737 
6738 // Tests the constructor.
6739 TEST(TestEventListenersTest, ConstructionWorks) {
6740  TestEventListeners listeners;
6741 
6742  EXPECT_TRUE(TestEventListenersAccessor::GetRepeater(&listeners) != nullptr);
6743  EXPECT_TRUE(listeners.default_result_printer() == nullptr);
6744  EXPECT_TRUE(listeners.default_xml_generator() == nullptr);
6745 }
6746 
6747 // Tests that the TestEventListeners destructor deletes all the listeners it
6748 // owns.
6749 TEST(TestEventListenersTest, DestructionWorks) {
6750  bool default_result_printer_is_destroyed = false;
6751  bool default_xml_printer_is_destroyed = false;
6752  bool extra_listener_is_destroyed = false;
6753  TestListener* default_result_printer =
6754  new TestListener(nullptr, &default_result_printer_is_destroyed);
6755  TestListener* default_xml_printer =
6756  new TestListener(nullptr, &default_xml_printer_is_destroyed);
6757  TestListener* extra_listener =
6758  new TestListener(nullptr, &extra_listener_is_destroyed);
6759 
6760  {
6761  TestEventListeners listeners;
6762  TestEventListenersAccessor::SetDefaultResultPrinter(&listeners,
6763  default_result_printer);
6764  TestEventListenersAccessor::SetDefaultXmlGenerator(&listeners,
6765  default_xml_printer);
6766  listeners.Append(extra_listener);
6767  }
6768  EXPECT_TRUE(default_result_printer_is_destroyed);
6769  EXPECT_TRUE(default_xml_printer_is_destroyed);
6770  EXPECT_TRUE(extra_listener_is_destroyed);
6771 }
6772 
6773 // Tests that a listener Append'ed to a TestEventListeners list starts
6774 // receiving events.
6775 TEST(TestEventListenersTest, Append) {
6776  int on_start_counter = 0;
6777  bool is_destroyed = false;
6778  TestListener* listener = new TestListener(&on_start_counter, &is_destroyed);
6779  {
6780  TestEventListeners listeners;
6781  listeners.Append(listener);
6782  TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
6783  *UnitTest::GetInstance());
6784  EXPECT_EQ(1, on_start_counter);
6785  }
6786  EXPECT_TRUE(is_destroyed);
6787 }
6788 
6789 // Tests that listeners receive events in the order they were appended to
6790 // the list, except for *End requests, which must be received in the reverse
6791 // order.
6793  public:
6794  SequenceTestingListener(std::vector<std::string>* vector, const char* id)
6795  : vector_(vector), id_(id) {}
6796 
6797  protected:
6798  void OnTestProgramStart(const UnitTest& /*unit_test*/) override {
6799  vector_->push_back(GetEventDescription("OnTestProgramStart"));
6800  }
6801 
6802  void OnTestProgramEnd(const UnitTest& /*unit_test*/) override {
6803  vector_->push_back(GetEventDescription("OnTestProgramEnd"));
6804  }
6805 
6806  void OnTestIterationStart(const UnitTest& /*unit_test*/,
6807  int /*iteration*/) override {
6808  vector_->push_back(GetEventDescription("OnTestIterationStart"));
6809  }
6810 
6811  void OnTestIterationEnd(const UnitTest& /*unit_test*/,
6812  int /*iteration*/) override {
6813  vector_->push_back(GetEventDescription("OnTestIterationEnd"));
6814  }
6815 
6816  private:
6818  Message message;
6819  message << id_ << "." << method;
6820  return message.GetString();
6821  }
6822 
6823  std::vector<std::string>* vector_;
6824  const char* const id_;
6825 
6827 };
6828 
6829 TEST(EventListenerTest, AppendKeepsOrder) {
6830  std::vector<std::string> vec;
6831  TestEventListeners listeners;
6832  listeners.Append(new SequenceTestingListener(&vec, "1st"));
6833  listeners.Append(new SequenceTestingListener(&vec, "2nd"));
6834  listeners.Append(new SequenceTestingListener(&vec, "3rd"));
6835 
6836  TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
6837  *UnitTest::GetInstance());
6838  ASSERT_EQ(3U, vec.size());
6839  EXPECT_STREQ("1st.OnTestProgramStart", vec[0].c_str());
6840  EXPECT_STREQ("2nd.OnTestProgramStart", vec[1].c_str());
6841  EXPECT_STREQ("3rd.OnTestProgramStart", vec[2].c_str());
6842 
6843  vec.clear();
6844  TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramEnd(
6845  *UnitTest::GetInstance());
6846  ASSERT_EQ(3U, vec.size());
6847  EXPECT_STREQ("3rd.OnTestProgramEnd", vec[0].c_str());
6848  EXPECT_STREQ("2nd.OnTestProgramEnd", vec[1].c_str());
6849  EXPECT_STREQ("1st.OnTestProgramEnd", vec[2].c_str());
6850 
6851  vec.clear();
6852  TestEventListenersAccessor::GetRepeater(&listeners)->OnTestIterationStart(
6853  *UnitTest::GetInstance(), 0);
6854  ASSERT_EQ(3U, vec.size());
6855  EXPECT_STREQ("1st.OnTestIterationStart", vec[0].c_str());
6856  EXPECT_STREQ("2nd.OnTestIterationStart", vec[1].c_str());
6857  EXPECT_STREQ("3rd.OnTestIterationStart", vec[2].c_str());
6858 
6859  vec.clear();
6860  TestEventListenersAccessor::GetRepeater(&listeners)->OnTestIterationEnd(
6861  *UnitTest::GetInstance(), 0);
6862  ASSERT_EQ(3U, vec.size());
6863  EXPECT_STREQ("3rd.OnTestIterationEnd", vec[0].c_str());
6864  EXPECT_STREQ("2nd.OnTestIterationEnd", vec[1].c_str());
6865  EXPECT_STREQ("1st.OnTestIterationEnd", vec[2].c_str());
6866 }
6867 
6868 // Tests that a listener removed from a TestEventListeners list stops receiving
6869 // events and is not deleted when the list is destroyed.
6870 TEST(TestEventListenersTest, Release) {
6871  int on_start_counter = 0;
6872  bool is_destroyed = false;
6873  // Although Append passes the ownership of this object to the list,
6874  // the following calls release it, and we need to delete it before the
6875  // test ends.
6876  TestListener* listener = new TestListener(&on_start_counter, &is_destroyed);
6877  {
6878  TestEventListeners listeners;
6879  listeners.Append(listener);
6880  EXPECT_EQ(listener, listeners.Release(listener));
6881  TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
6882  *UnitTest::GetInstance());
6883  EXPECT_TRUE(listeners.Release(listener) == nullptr);
6884  }
6885  EXPECT_EQ(0, on_start_counter);
6886  EXPECT_FALSE(is_destroyed);
6887  delete listener;
6888 }
6889 
6890 // Tests that no events are forwarded when event forwarding is disabled.
6891 TEST(EventListenerTest, SuppressEventForwarding) {
6892  int on_start_counter = 0;
6893  TestListener* listener = new TestListener(&on_start_counter, nullptr);
6894 
6895  TestEventListeners listeners;
6896  listeners.Append(listener);
6897  ASSERT_TRUE(TestEventListenersAccessor::EventForwardingEnabled(listeners));
6898  TestEventListenersAccessor::SuppressEventForwarding(&listeners);
6899  ASSERT_FALSE(TestEventListenersAccessor::EventForwardingEnabled(listeners));
6900  TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
6901  *UnitTest::GetInstance());
6902  EXPECT_EQ(0, on_start_counter);
6903 }
6904 
6905 // Tests that events generated by Google Test are not forwarded in
6906 // death test subprocesses.
6907 TEST(EventListenerDeathTest, EventsNotForwardedInDeathTestSubprecesses) {
6909  GTEST_CHECK_(TestEventListenersAccessor::EventForwardingEnabled(
6910  *GetUnitTestImpl()->listeners())) << "expected failure";},
6911  "expected failure");
6912 }
6913 
6914 // Tests that a listener installed via SetDefaultResultPrinter() starts
6915 // receiving events and is returned via default_result_printer() and that
6916 // the previous default_result_printer is removed from the list and deleted.
6917 TEST(EventListenerTest, default_result_printer) {
6918  int on_start_counter = 0;
6919  bool is_destroyed = false;
6920  TestListener* listener = new TestListener(&on_start_counter, &is_destroyed);
6921 
6922  TestEventListeners listeners;
6923  TestEventListenersAccessor::SetDefaultResultPrinter(&listeners, listener);
6924 
6925  EXPECT_EQ(listener, listeners.default_result_printer());
6926 
6927  TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
6928  *UnitTest::GetInstance());
6929 
6930  EXPECT_EQ(1, on_start_counter);
6931 
6932  // Replacing default_result_printer with something else should remove it
6933  // from the list and destroy it.
6934  TestEventListenersAccessor::SetDefaultResultPrinter(&listeners, nullptr);
6935 
6936  EXPECT_TRUE(listeners.default_result_printer() == nullptr);
6937  EXPECT_TRUE(is_destroyed);
6938 
6939  // After broadcasting an event the counter is still the same, indicating
6940  // the listener is not in the list anymore.
6941  TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
6942  *UnitTest::GetInstance());
6943  EXPECT_EQ(1, on_start_counter);
6944 }
6945 
6946 // Tests that the default_result_printer listener stops receiving events
6947 // when removed via Release and that is not owned by the list anymore.
6948 TEST(EventListenerTest, RemovingDefaultResultPrinterWorks) {
6949  int on_start_counter = 0;
6950  bool is_destroyed = false;
6951  // Although Append passes the ownership of this object to the list,
6952  // the following calls release it, and we need to delete it before the
6953  // test ends.
6954  TestListener* listener = new TestListener(&on_start_counter, &is_destroyed);
6955  {
6956  TestEventListeners listeners;
6957  TestEventListenersAccessor::SetDefaultResultPrinter(&listeners, listener);
6958 
6959  EXPECT_EQ(listener, listeners.Release(listener));
6960  EXPECT_TRUE(listeners.default_result_printer() == nullptr);
6961  EXPECT_FALSE(is_destroyed);
6962 
6963  // Broadcasting events now should not affect default_result_printer.
6964  TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
6965  *UnitTest::GetInstance());
6966  EXPECT_EQ(0, on_start_counter);
6967  }
6968  // Destroying the list should not affect the listener now, too.
6969  EXPECT_FALSE(is_destroyed);
6970  delete listener;
6971 }
6972 
6973 // Tests that a listener installed via SetDefaultXmlGenerator() starts
6974 // receiving events and is returned via default_xml_generator() and that
6975 // the previous default_xml_generator is removed from the list and deleted.
6976 TEST(EventListenerTest, default_xml_generator) {
6977  int on_start_counter = 0;
6978  bool is_destroyed = false;
6979  TestListener* listener = new TestListener(&on_start_counter, &is_destroyed);
6980 
6981  TestEventListeners listeners;
6982  TestEventListenersAccessor::SetDefaultXmlGenerator(&listeners, listener);
6983 
6984  EXPECT_EQ(listener, listeners.default_xml_generator());
6985 
6986  TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
6987  *UnitTest::GetInstance());
6988 
6989  EXPECT_EQ(1, on_start_counter);
6990 
6991  // Replacing default_xml_generator with something else should remove it
6992  // from the list and destroy it.
6993  TestEventListenersAccessor::SetDefaultXmlGenerator(&listeners, nullptr);
6994 
6995  EXPECT_TRUE(listeners.default_xml_generator() == nullptr);
6996  EXPECT_TRUE(is_destroyed);
6997 
6998  // After broadcasting an event the counter is still the same, indicating
6999  // the listener is not in the list anymore.
7000  TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
7001  *UnitTest::GetInstance());
7002  EXPECT_EQ(1, on_start_counter);
7003 }
7004 
7005 // Tests that the default_xml_generator listener stops receiving events
7006 // when removed via Release and that is not owned by the list anymore.
7007 TEST(EventListenerTest, RemovingDefaultXmlGeneratorWorks) {
7008  int on_start_counter = 0;
7009  bool is_destroyed = false;
7010  // Although Append passes the ownership of this object to the list,
7011  // the following calls release it, and we need to delete it before the
7012  // test ends.
7013  TestListener* listener = new TestListener(&on_start_counter, &is_destroyed);
7014  {
7015  TestEventListeners listeners;
7016  TestEventListenersAccessor::SetDefaultXmlGenerator(&listeners, listener);
7017 
7018  EXPECT_EQ(listener, listeners.Release(listener));
7019  EXPECT_TRUE(listeners.default_xml_generator() == nullptr);
7020  EXPECT_FALSE(is_destroyed);
7021 
7022  // Broadcasting events now should not affect default_xml_generator.
7023  TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
7024  *UnitTest::GetInstance());
7025  EXPECT_EQ(0, on_start_counter);
7026  }
7027  // Destroying the list should not affect the listener now, too.
7028  EXPECT_FALSE(is_destroyed);
7029  delete listener;
7030 }
7031 
7032 // Sanity tests to ensure that the alternative, verbose spellings of
7033 // some of the macros work. We don't test them thoroughly as that
7034 // would be quite involved. Since their implementations are
7035 // straightforward, and they are rarely used, we'll just rely on the
7036 // users to tell us when they are broken.
7037 GTEST_TEST(AlternativeNameTest, Works) { // GTEST_TEST is the same as TEST.
7038  GTEST_SUCCEED() << "OK"; // GTEST_SUCCEED is the same as SUCCEED.
7039 
7040  // GTEST_FAIL is the same as FAIL.
7041  EXPECT_FATAL_FAILURE(GTEST_FAIL() << "An expected failure",
7042  "An expected failure");
7043 
7044  // GTEST_ASSERT_XY is the same as ASSERT_XY.
7045 
7046  GTEST_ASSERT_EQ(0, 0);
7047  EXPECT_FATAL_FAILURE(GTEST_ASSERT_EQ(0, 1) << "An expected failure",
7048  "An expected failure");
7049  EXPECT_FATAL_FAILURE(GTEST_ASSERT_EQ(1, 0) << "An expected failure",
7050  "An expected failure");
7051 
7052  GTEST_ASSERT_NE(0, 1);
7053  GTEST_ASSERT_NE(1, 0);
7054  EXPECT_FATAL_FAILURE(GTEST_ASSERT_NE(0, 0) << "An expected failure",
7055  "An expected failure");
7056 
7057  GTEST_ASSERT_LE(0, 0);
7058  GTEST_ASSERT_LE(0, 1);
7059  EXPECT_FATAL_FAILURE(GTEST_ASSERT_LE(1, 0) << "An expected failure",
7060  "An expected failure");
7061 
7062  GTEST_ASSERT_LT(0, 1);
7063  EXPECT_FATAL_FAILURE(GTEST_ASSERT_LT(0, 0) << "An expected failure",
7064  "An expected failure");
7065  EXPECT_FATAL_FAILURE(GTEST_ASSERT_LT(1, 0) << "An expected failure",
7066  "An expected failure");
7067 
7068  GTEST_ASSERT_GE(0, 0);
7069  GTEST_ASSERT_GE(1, 0);
7070  EXPECT_FATAL_FAILURE(GTEST_ASSERT_GE(0, 1) << "An expected failure",
7071  "An expected failure");
7072 
7073  GTEST_ASSERT_GT(1, 0);
7074  EXPECT_FATAL_FAILURE(GTEST_ASSERT_GT(0, 1) << "An expected failure",
7075  "An expected failure");
7076  EXPECT_FATAL_FAILURE(GTEST_ASSERT_GT(1, 1) << "An expected failure",
7077  "An expected failure");
7078 }
7079 
7080 // Tests for internal utilities necessary for implementation of the universal
7081 // printing.
7082 
7085 
7086 // Tests that IsAProtocolMessage<T>::value is a compile-time constant.
7087 TEST(IsAProtocolMessageTest, ValueIsCompileTimeConstant) {
7089  const_true);
7091 }
7092 
7093 // Tests that IsAProtocolMessage<T>::value is true when T is
7094 // proto2::Message or a sub-class of it.
7095 TEST(IsAProtocolMessageTest, ValueIsTrueWhenTypeIsAProtocolMessage) {
7097 }
7098 
7099 // Tests that IsAProtocolMessage<T>::value is false when T is neither
7100 // ::proto2::Message nor a sub-class of it.
7101 TEST(IsAProtocolMessageTest, ValueIsFalseWhenTypeIsNotAProtocolMessage) {
7104 }
7105 
7106 // Tests that CompileAssertTypesEqual compiles when the type arguments are
7107 // equal.
7108 TEST(CompileAssertTypesEqual, CompilesWhenTypesAreEqual) {
7111 }
7112 
7113 // Tests that RemoveReference does not affect non-reference types.
7114 TEST(RemoveReferenceTest, DoesNotAffectNonReferenceType) {
7117 }
7118 
7119 // Tests that RemoveReference removes reference from reference types.
7120 TEST(RemoveReferenceTest, RemovesReference) {
7123 }
7124 
7125 // Tests GTEST_REMOVE_REFERENCE_.
7126 
7127 template <typename T1, typename T2>
7130 }
7131 
7132 TEST(RemoveReferenceTest, MacroVersion) {
7133  TestGTestRemoveReference<int, int>();
7134  TestGTestRemoveReference<const char, const char&>();
7135 }
7136 
7137 // Tests GTEST_REMOVE_REFERENCE_AND_CONST_.
7138 
7139 template <typename T1, typename T2>
7142 }
7143 
7144 TEST(RemoveReferenceToConstTest, Works) {
7145  TestGTestRemoveReferenceAndConst<int, int>();
7146  TestGTestRemoveReferenceAndConst<double, double&>();
7147  TestGTestRemoveReferenceAndConst<char, const char>();
7148  TestGTestRemoveReferenceAndConst<char, const char&>();
7149  TestGTestRemoveReferenceAndConst<const char*, const char*>();
7150 }
7151 
7152 // Tests GTEST_REFERENCE_TO_CONST_.
7153 
7154 template <typename T1, typename T2>
7157 }
7158 
7159 TEST(GTestReferenceToConstTest, Works) {
7160  TestGTestReferenceToConst<const char&, char>();
7161  TestGTestReferenceToConst<const int&, const int>();
7162  TestGTestReferenceToConst<const double&, double>();
7163  TestGTestReferenceToConst<const std::string&, const std::string&>();
7164 }
7165 
7166 
7167 // Tests IsContainerTest.
7168 
7169 class NonContainer {};
7170 
7171 TEST(IsContainerTestTest, WorksForNonContainer) {
7172  EXPECT_EQ(sizeof(IsNotContainer), sizeof(IsContainerTest<int>(0)));
7173  EXPECT_EQ(sizeof(IsNotContainer), sizeof(IsContainerTest<char[5]>(0)));
7174  EXPECT_EQ(sizeof(IsNotContainer), sizeof(IsContainerTest<NonContainer>(0)));
7175 }
7176 
7177 TEST(IsContainerTestTest, WorksForContainer) {
7178  EXPECT_EQ(sizeof(IsContainer),
7179  sizeof(IsContainerTest<std::vector<bool> >(0)));
7180  EXPECT_EQ(sizeof(IsContainer),
7181  sizeof(IsContainerTest<std::map<int, double> >(0)));
7182 }
7183 
7185  using const_iterator = int*;
7186  const_iterator begin() const;
7187  const_iterator end() const;
7188 };
7189 
7192  const int& operator*() const;
7193  const_iterator& operator++(/* pre-increment */);
7194  };
7195  const_iterator begin() const;
7196  const_iterator end() const;
7197 };
7198 
7199 TEST(IsContainerTestTest, ConstOnlyContainer) {
7200  EXPECT_EQ(sizeof(IsContainer),
7201  sizeof(IsContainerTest<ConstOnlyContainerWithPointerIterator>(0)));
7202  EXPECT_EQ(sizeof(IsContainer),
7203  sizeof(IsContainerTest<ConstOnlyContainerWithClassIterator>(0)));
7204 }
7205 
7206 // Tests IsHashTable.
7207 struct AHashTable {
7208  typedef void hasher;
7209 };
7211  typedef void hasher;
7212  typedef void reverse_iterator;
7213 };
7214 TEST(IsHashTable, Basic) {
7218  EXPECT_TRUE(testing::internal::IsHashTable<std::unordered_set<int>>::value);
7219 }
7220 
7221 // Tests ArrayEq().
7222 
7223 TEST(ArrayEqTest, WorksForDegeneratedArrays) {
7224  EXPECT_TRUE(ArrayEq(5, 5L));
7225  EXPECT_FALSE(ArrayEq('a', 0));
7226 }
7227 
7228 TEST(ArrayEqTest, WorksForOneDimensionalArrays) {
7229  // Note that a and b are distinct but compatible types.
7230  const int a[] = { 0, 1 };
7231  long b[] = { 0, 1 };
7232  EXPECT_TRUE(ArrayEq(a, b));
7233  EXPECT_TRUE(ArrayEq(a, 2, b));
7234 
7235  b[0] = 2;
7236  EXPECT_FALSE(ArrayEq(a, b));
7237  EXPECT_FALSE(ArrayEq(a, 1, b));
7238 }
7239 
7240 TEST(ArrayEqTest, WorksForTwoDimensionalArrays) {
7241  const char a[][3] = { "hi", "lo" };
7242  const char b[][3] = { "hi", "lo" };
7243  const char c[][3] = { "hi", "li" };
7244 
7245  EXPECT_TRUE(ArrayEq(a, b));
7246  EXPECT_TRUE(ArrayEq(a, 2, b));
7247 
7248  EXPECT_FALSE(ArrayEq(a, c));
7249  EXPECT_FALSE(ArrayEq(a, 2, c));
7250 }
7251 
7252 // Tests ArrayAwareFind().
7253 
7254 TEST(ArrayAwareFindTest, WorksForOneDimensionalArray) {
7255  const char a[] = "hello";
7256  EXPECT_EQ(a + 4, ArrayAwareFind(a, a + 5, 'o'));
7257  EXPECT_EQ(a + 5, ArrayAwareFind(a, a + 5, 'x'));
7258 }
7259 
7260 TEST(ArrayAwareFindTest, WorksForTwoDimensionalArray) {
7261  int a[][2] = { { 0, 1 }, { 2, 3 }, { 4, 5 } };
7262  const int b[2] = { 2, 3 };
7263  EXPECT_EQ(a + 1, ArrayAwareFind(a, a + 3, b));
7264 
7265  const int c[2] = { 6, 7 };
7266  EXPECT_EQ(a + 3, ArrayAwareFind(a, a + 3, c));
7267 }
7268 
7269 // Tests CopyArray().
7270 
7271 TEST(CopyArrayTest, WorksForDegeneratedArrays) {
7272  int n = 0;
7273  CopyArray('a', &n);
7274  EXPECT_EQ('a', n);
7275 }
7276 
7277 TEST(CopyArrayTest, WorksForOneDimensionalArrays) {
7278  const char a[3] = "hi";
7279  int b[3];
7280 #ifndef __BORLANDC__ // C++Builder cannot compile some array size deductions.
7281  CopyArray(a, &b);
7282  EXPECT_TRUE(ArrayEq(a, b));
7283 #endif
7284 
7285  int c[3];
7286  CopyArray(a, 3, c);
7287  EXPECT_TRUE(ArrayEq(a, c));
7288 }
7289 
7290 TEST(CopyArrayTest, WorksForTwoDimensionalArrays) {
7291  const int a[2][3] = { { 0, 1, 2 }, { 3, 4, 5 } };
7292  int b[2][3];
7293 #ifndef __BORLANDC__ // C++Builder cannot compile some array size deductions.
7294  CopyArray(a, &b);
7295  EXPECT_TRUE(ArrayEq(a, b));
7296 #endif
7297 
7298  int c[2][3];
7299  CopyArray(a, 2, c);
7300  EXPECT_TRUE(ArrayEq(a, c));
7301 }
7302 
7303 // Tests NativeArray.
7304 
7305 TEST(NativeArrayTest, ConstructorFromArrayWorks) {
7306  const int a[3] = { 0, 1, 2 };
7308  EXPECT_EQ(3U, na.size());
7309  EXPECT_EQ(a, na.begin());
7310 }
7311 
7312 TEST(NativeArrayTest, CreatesAndDeletesCopyOfArrayWhenAskedTo) {
7313  typedef int Array[2];
7314  Array* a = new Array[1];
7315  (*a)[0] = 0;
7316  (*a)[1] = 1;
7318  EXPECT_NE(*a, na.begin());
7319  delete[] a;
7320  EXPECT_EQ(0, na.begin()[0]);
7321  EXPECT_EQ(1, na.begin()[1]);
7322 
7323  // We rely on the heap checker to verify that na deletes the copy of
7324  // array.
7325 }
7326 
7327 TEST(NativeArrayTest, TypeMembersAreCorrect) {
7330 
7331  StaticAssertTypeEq<const char*, NativeArray<char>::const_iterator>();
7333 }
7334 
7335 TEST(NativeArrayTest, MethodsWork) {
7336  const int a[3] = { 0, 1, 2 };
7338  ASSERT_EQ(3U, na.size());
7339  EXPECT_EQ(3, na.end() - na.begin());
7340 
7342  EXPECT_EQ(0, *it);
7343  ++it;
7344  EXPECT_EQ(1, *it);
7345  it++;
7346  EXPECT_EQ(2, *it);
7347  ++it;
7348  EXPECT_EQ(na.end(), it);
7349 
7350  EXPECT_TRUE(na == na);
7351 
7353  EXPECT_TRUE(na == na2);
7354 
7355  const int b1[3] = { 0, 1, 1 };
7356  const int b2[4] = { 0, 1, 2, 3 };
7359 }
7360 
7361 TEST(NativeArrayTest, WorksForTwoDimensionalArray) {
7362  const char a[2][3] = { "hi", "lo" };
7364  ASSERT_EQ(2U, na.size());
7365  EXPECT_EQ(a, na.begin());
7366 }
7367 
7368 // IndexSequence
7369 TEST(IndexSequence, MakeIndexSequence) {
7372  EXPECT_TRUE(
7374  EXPECT_TRUE(
7375  (std::is_same<IndexSequence<0>, MakeIndexSequence<1>::type>::value));
7376  EXPECT_TRUE(
7377  (std::is_same<IndexSequence<0, 1>, MakeIndexSequence<2>::type>::value));
7378  EXPECT_TRUE((
7379  std::is_same<IndexSequence<0, 1, 2>, MakeIndexSequence<3>::type>::value));
7380  EXPECT_TRUE(
7381  (std::is_base_of<IndexSequence<0, 1, 2>, MakeIndexSequence<3>>::value));
7382 }
7383 
7384 // ElemFromList
7385 TEST(ElemFromList, Basic) {
7388  EXPECT_TRUE((
7390  EXPECT_TRUE(
7391  (std::is_same<double,
7393  EXPECT_TRUE(
7394  (std::is_same<char,
7396  EXPECT_TRUE(
7397  (std::is_same<
7398  char, ElemFromList<7, testing::internal::MakeIndexSequence<12>::type,
7399  int, int, int, int, int, int, int, char, int, int,
7400  int, int>::type>::value));
7401 }
7402 
7403 // FlatTuple
7404 TEST(FlatTuple, Basic) {
7406 
7407  FlatTuple<int, double, const char*> tuple = {};
7408  EXPECT_EQ(0, tuple.Get<0>());
7409  EXPECT_EQ(0.0, tuple.Get<1>());
7410  EXPECT_EQ(nullptr, tuple.Get<2>());
7411 
7412  tuple = FlatTuple<int, double, const char*>(7, 3.2, "Foo");
7413  EXPECT_EQ(7, tuple.Get<0>());
7414  EXPECT_EQ(3.2, tuple.Get<1>());
7415  EXPECT_EQ(std::string("Foo"), tuple.Get<2>());
7416 
7417  tuple.Get<1>() = 5.1;
7418  EXPECT_EQ(5.1, tuple.Get<1>());
7419 }
7420 
7421 TEST(FlatTuple, ManyTypes) {
7423 
7424  // Instantiate FlatTuple with 257 ints.
7425  // Tests show that we can do it with thousands of elements, but very long
7426  // compile times makes it unusuitable for this test.
7427 #define GTEST_FLAT_TUPLE_INT8 int, int, int, int, int, int, int, int,
7428 #define GTEST_FLAT_TUPLE_INT16 GTEST_FLAT_TUPLE_INT8 GTEST_FLAT_TUPLE_INT8
7429 #define GTEST_FLAT_TUPLE_INT32 GTEST_FLAT_TUPLE_INT16 GTEST_FLAT_TUPLE_INT16
7430 #define GTEST_FLAT_TUPLE_INT64 GTEST_FLAT_TUPLE_INT32 GTEST_FLAT_TUPLE_INT32
7431 #define GTEST_FLAT_TUPLE_INT128 GTEST_FLAT_TUPLE_INT64 GTEST_FLAT_TUPLE_INT64
7432 #define GTEST_FLAT_TUPLE_INT256 GTEST_FLAT_TUPLE_INT128 GTEST_FLAT_TUPLE_INT128
7433 
7434  // Let's make sure that we can have a very long list of types without blowing
7435  // up the template instantiation depth.
7436  FlatTuple<GTEST_FLAT_TUPLE_INT256 int> tuple;
7437 
7438  tuple.Get<0>() = 7;
7439  tuple.Get<99>() = 17;
7440  tuple.Get<256>() = 1000;
7441  EXPECT_EQ(7, tuple.Get<0>());
7442  EXPECT_EQ(17, tuple.Get<99>());
7443  EXPECT_EQ(1000, tuple.Get<256>());
7444 }
7445 
7446 // Tests SkipPrefix().
7447 
7448 TEST(SkipPrefixTest, SkipsWhenPrefixMatches) {
7449  const char* const str = "hello";
7450 
7451  const char* p = str;
7452  EXPECT_TRUE(SkipPrefix("", &p));
7453  EXPECT_EQ(str, p);
7454 
7455  p = str;
7456  EXPECT_TRUE(SkipPrefix("hell", &p));
7457  EXPECT_EQ(str + 4, p);
7458 }
7459 
7460 TEST(SkipPrefixTest, DoesNotSkipWhenPrefixDoesNotMatch) {
7461  const char* const str = "world";
7462 
7463  const char* p = str;
7464  EXPECT_FALSE(SkipPrefix("W", &p));
7465  EXPECT_EQ(str, p);
7466 
7467  p = str;
7468  EXPECT_FALSE(SkipPrefix("world!", &p));
7469  EXPECT_EQ(str, p);
7470 }
7471 
7472 // Tests ad_hoc_test_result().
7473 
7475  protected:
7476  static void SetUpTestSuite() {
7477  FAIL() << "A failure happened inside SetUpTestSuite().";
7478  }
7479 };
7480 
7481 TEST_F(AdHocTestResultTest, AdHocTestResultForTestSuiteShowsFailure) {
7483  ->current_test_suite()
7484  ->ad_hoc_test_result();
7485  EXPECT_TRUE(test_result.Failed());
7486 }
7487 
7488 TEST_F(AdHocTestResultTest, AdHocTestResultTestForUnitTestDoesNotShowFailure) {
7491  EXPECT_FALSE(test_result.Failed());
7492 }
7493 
7495 
7496 class DynamicTest : public DynamicUnitTestFixture {
7497  void TestBody() override { EXPECT_TRUE(true); }
7498 };
7499 
7501  "DynamicUnitTestFixture", "DynamicTest", "TYPE", "VALUE", __FILE__,
7502  __LINE__, []() -> DynamicUnitTestFixture* { return new DynamicTest; });
7503 
7504 TEST(RegisterTest, WasRegistered) {
7506  for (int i = 0; i < unittest->total_test_suite_count(); ++i) {
7507  auto* tests = unittest->GetTestSuite(i);
7508  if (tests->name() != std::string("DynamicUnitTestFixture")) continue;
7509  for (int j = 0; j < tests->total_test_count(); ++j) {
7510  if (tests->GetTestInfo(j)->name() != std::string("DynamicTest")) continue;
7511  // Found it.
7512  EXPECT_STREQ(tests->GetTestInfo(j)->value_param(), "VALUE");
7513  EXPECT_STREQ(tests->GetTestInfo(j)->type_param(), "TYPE");
7514  return;
7515  }
7516  }
7517 
7518  FAIL() << "Didn't find the test!";
7519 }
testing::ParseFlagsTest::CheckFlags
static void CheckFlags(const Flags &expected)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5685
NonContainer
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:7169
NotReallyAHashTable::hasher
void hasher
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:7211
xds_interop_client.str
str
Definition: xds_interop_client.py:487
StaticAssertTypeEqTestHelper::StaticAssertTypeEqTestHelper
StaticAssertTypeEqTestHelper()
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:6616
EXPECT_FALSE
#define EXPECT_FALSE(condition)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1970
testing::TEST_F
TEST_F(TestInfoTest, Names)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5305
testing::TYPED_TEST_SUITE_P
TYPED_TEST_SUITE_P(CodeLocationForTYPEDTESTP)
testing::TestInfoTest::GetTestResult
static const TestResult * GetTestResult(const TestInfo *test_info)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5298
testing::internal::GetTypeId
TypeId GetTypeId()
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-internal.h:423
_gevent_test_main.result
result
Definition: _gevent_test_main.py:96
obj
OPENSSL_EXPORT const ASN1_OBJECT * obj
Definition: x509.h:1671
testing
Definition: aws_request_signer_test.cc:25
testing::ParseFlagsTest::SetUp
void SetUp() override
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5656
testing::SetUpTestSuiteTest::SetUp
void SetUp() override
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5475
testing::AssertionFailure
AssertionResult AssertionFailure()
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:1028
testing::internal::TestResultAccessor
Definition: gmock-gtest-all.cc:1421
EXPECT_PRED_FORMAT2
#define EXPECT_PRED_FORMAT2(pred_format, v1, v2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest_pred_impl.h:163
ASSERT_NE
#define ASSERT_NE(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2060
ASSERT_STRNE
#define ASSERT_STRNE(s1, s2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2106
testing::TestPartResult
Definition: cares/cares/test/gmock-1.8.0/gtest/gtest.h:18272
ASSERT_NO_THROW
#define ASSERT_NO_THROW(statement)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1959
TestEq1
void TestEq1(int x)
Definition: bloaty/third_party/googletest/googletest/test/googletest-output-test_.cc:59
testing::internal::TestEventListenersAccessor::SetDefaultXmlGenerator
static void SetDefaultXmlGenerator(TestEventListeners *listeners, TestEventListener *listener)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:163
SequenceTestingListener::OnTestIterationStart
void OnTestIterationStart(const UnitTest &, int) override
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:6806
gen_build_yaml.out
dictionary out
Definition: src/benchmark/gen_build_yaml.py:24
AHashTable
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:7207
GTEST_ASSERT_GE
#define GTEST_ASSERT_GE(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2047
testing::TestInfo
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:695
VERIFY_CODE_LOCATION
#define VERIFY_CODE_LOCATION
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5323
regen-readme.it
it
Definition: regen-readme.py:15
testing::Flags::DeathTestUseFork
static Flags DeathTestUseFork(bool death_test_use_fork)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5549
testing::internal::TestEventListenersAccessor
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:153
testing::TempDir
GTEST_API_ std::string TempDir()
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:6140
Test
void Test(StringPiece pattern, const RE2::Options &options, StringPiece text)
Definition: bloaty/third_party/re2/re2/fuzzing/re2_fuzzer.cc:20
testing::Flags::random_seed
Int32 random_seed
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5644
env_var
Definition: win/process.c:40
ProtectedFixtureMethodsTest::TearDown
void TearDown() override
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:6345
NotReallyAHashTable::reverse_iterator
void reverse_iterator
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:7212
grpc_event_engine::experimental::slice_detail::operator==
bool operator==(const BaseSlice &a, const BaseSlice &b)
Definition: include/grpc/event_engine/slice.h:117
testing::internal::FloatingPoint
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-internal.h:238
testing::TestPartResult::type
Type type() const
Definition: cares/cares/test/gmock-1.8.0/gtest/gtest.h:18297
testing::internal::ShouldRunTestOnShard
bool ShouldRunTestOnShard(int total_shards, int shard_index, int test_id)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:5485
testing::internal::CompileAssertTypesEqual
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-internal.h:853
ASSERT_PRED2
#define ASSERT_PRED2(pred, v1, v2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest_pred_impl.h:169
GTEST_DISABLE_MSC_DEPRECATED_POP_
#define GTEST_DISABLE_MSC_DEPRECATED_POP_()
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:324
bool
bool
Definition: setup_once.h:312
testing::UnitTest::current_test_info
const TestInfo * current_test_info() const GTEST_LOCK_EXCLUDED_(mutex_)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:4961
GTEST_USE_UNPROTECTED_COMMA_
#define GTEST_USE_UNPROTECTED_COMMA_
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:1304
testing::SetUpTestCaseTest::SetUpTestCase
static void SetUpTestCase()
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5383
GTEST_DISABLE_MSC_WARNINGS_PUSH_
#define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:308
testing::internal::kMaxBiggestInt
const BiggestInt kMaxBiggestInt
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:2104
testing::internal::Int32
TypeWithSize< 4 >::Int Int32
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:2159
SequenceTestingListener::OnTestProgramStart
void OnTestProgramStart(const UnitTest &) override
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:6798
EXPECT_ANY_THROW
#define EXPECT_ANY_THROW(statement)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1955
GTEST_ASSERT_LE
#define GTEST_ASSERT_LE(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2043
testing::TestEventListeners::default_xml_generator
TestEventListener * default_xml_generator() const
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1201
EXPECT_FATAL_FAILURE_ON_ALL_THREADS
#define EXPECT_FATAL_FAILURE_ON_ALL_THREADS(statement, substr)
begin
char * begin
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1007
FRIEND_TEST
#define FRIEND_TEST(test_case_name, test_name)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest_prod.h:58
testing::SetUpTestCaseTest::TearDownTestCase
static void TearDownTestCase()
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5400
Bool
Definition: bloaty/third_party/googletest/googletest/test/gtest_pred_impl_unittest.cc:56
testing::internal::RelationToSourceCopy
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-internal.h:1047
testing::TestInfoTest::GetTestInfo
static const TestInfo * GetTestInfo(const char *test_name)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5286
TestListener::on_start_counter_
int * on_start_counter_
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:6734
testing::SetUpTestCaseTest::SetUp
void SetUp() override
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5414
testing::internal::GetCapturedStdout
GTEST_API_ std::string GetCapturedStdout()
Definition: gmock-gtest-all.cc:9596
false
#define false
Definition: setup_once.h:323
testing::TestPartResult::nonfatally_failed
bool nonfatally_failed() const
Definition: cares/cares/test/gmock-1.8.0/gtest/gtest.h:18322
ASSERT_STREQ
#define ASSERT_STREQ(s1, s2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2104
DynamicUnitTestFixture
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:7494
testing::TestResult
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:562
ConversionHelperBase
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:7083
ASSERT_NEAR
#define ASSERT_NEAR(val1, val2, abs_error)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2147
testing::TestPartResult::summary
const char * summary() const
Definition: cares/cares/test/gmock-1.8.0/gtest/gtest.h:18310
testing::internal::UnitTestRecordPropertyTestHelper::UnitTestRecordPropertyTestHelper
UnitTestRecordPropertyTestHelper()
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:179
ASSERT_PRED_FORMAT2
#define ASSERT_PRED_FORMAT2(pred_format, v1, v2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest_pred_impl.h:167
testing::internal::NativeArray::begin
const_iterator begin() const
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-internal.h:1087
testing::TestResult::total_part_count
int total_part_count() const
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:2237
y
const double y
Definition: bloaty/third_party/googletest/googlemock/test/gmock-matchers_test.cc:3611
testing::ScopedFakeTestPartResultReporter
Definition: gmock-gtest-all.cc:124
testing::INSTANTIATE_TYPED_TEST_SUITE_P
INSTANTIATE_TYPED_TEST_SUITE_P(My, CodeLocationForTYPEDTESTP, int)
EXPECT_FATAL_FAILURE
#define EXPECT_FATAL_FAILURE(statement, substr)
grpc::testing::sum
double sum(const T &container, F functor)
Definition: test/cpp/qps/stats.h:30
testing::internal::AssertHelper
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1766
testing::TestPartResult::passed
bool passed() const
Definition: cares/cares/test/gmock-1.8.0/gtest/gtest.h:18316
GTEST_FAIL_AT
#define GTEST_FAIL_AT(file, line)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1923
testing::TestPartResult::kFatalFailure
@ kFatalFailure
Definition: cares/cares/test/gmock-1.8.0/gtest/gtest.h:18279
string.h
testing::internal::TestEventListenersAccessor::SuppressEventForwarding
static void SuppressEventForwarding(TestEventListeners *listeners)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:172
testing::internal::TestEventListenersAccessor::SetDefaultResultPrinter
static void SetDefaultResultPrinter(TestEventListeners *listeners, TestEventListener *listener)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:159
seed
static const uint8_t seed[20]
Definition: dsa_test.cc:79
ADD_FAILURE_AT
#define ADD_FAILURE_AT(file, line)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1915
testing::internal::GetUnitTestImpl
UnitTestImpl * GetUnitTestImpl()
Definition: gmock-gtest-all.cc:1334
testing::internal::IsContainerTest
IsContainer IsContainerTest(int)
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-internal.h:915
printf
_Use_decl_annotations_ int __cdecl printf(const char *_Format,...)
Definition: cs_driver.c:91
EXPECT_GT
#define EXPECT_GT(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2036
testing::Flags::print_time
bool print_time
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5643
testing::ParseFlagsTest
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5653
HasNonfatalFailureHelper
static bool HasNonfatalFailureHelper()
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:6661
GTEST_FLAG_PREFIX_UPPER_
#define GTEST_FLAG_PREFIX_UPPER_
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:279
x_
X x_
Definition: abseil-cpp/absl/strings/internal/str_format/arg_test.cc:35
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
testing::Flags::Output
static Flags Output(const char *output)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5573
testing::internal::edit_distance::CalculateOptimalEdits
GTEST_API_ std::vector< EditType > CalculateOptimalEdits(const std::vector< size_t > &left, const std::vector< size_t > &right)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:1041
grpc::protobuf::Message
GRPC_CUSTOM_MESSAGE Message
Definition: include/grpcpp/impl/codegen/config_protobuf.h:78
testing::Flags::StackTraceDepth
static Flags StackTraceDepth(Int32 stack_trace_depth)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5613
testing::internal::GetNextRandomSeed
int GetNextRandomSeed(int seed)
Definition: gmock-gtest-all.cc:559
GTEST_SUCCEED
#define GTEST_SUCCEED()
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1934
SequenceTestingListener
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:6792
testing::internal::Int32FromGTestEnv
GTEST_API_ Int32 Int32FromGTestEnv(const char *flag, Int32 default_val)
Definition: bloaty/third_party/googletest/googletest/src/gtest-port.cc:1348
ASSERT
#define ASSERT(expr)
Definition: task.h:102
re2::RandomTest
static void RandomTest(int maxatoms, int maxops, const std::vector< std::string > &alphabet, const std::vector< std::string > &ops, int maxstrlen, const std::vector< std::string > &stralphabet, const std::string &wrapper)
Definition: bloaty/third_party/re2/re2/testing/random_test.cc:24
absl::debugging_internal::Append
static void Append(State *state, const char *const str, const int length)
Definition: abseil-cpp/absl/debugging/internal/demangle.cc:359
TestListener::~TestListener
~TestListener() override
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:6723
ASSERT_GE
#define ASSERT_GE(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2072
testing::Flags::AlsoRunDisabledTests
static Flags AlsoRunDisabledTests(bool also_run_disabled_tests)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5525
Base::x_
int x_
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5146
GTEST_COMPILE_ASSERT_
#define GTEST_COMPILE_ASSERT_(expr, msg)
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:854
foo
Definition: bloaty/third_party/googletest/googletest/test/googletest-output-test_.cc:546
testing::Flags::stream_result_to
const char * stream_result_to
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5648
testing::ParseFlagsTest::AssertStringArrayEq
static void AssertStringArrayEq(int size1, CharType **array1, int size2, CharType **array2)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5675
testing::TestEventListeners::Append
void Append(TestEventListener *listener)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:4548
testing::TestInfo::test_case_name
const char * test_case_name() const
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:706
setup.name
name
Definition: setup.py:542
ASSERT_PRED3
#define ASSERT_PRED3(pred, v1, v2, v3)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest_pred_impl.h:224
testing::internal::OsStackTraceGetterInterface
Definition: gmock-gtest-all.cc:825
absl::FormatConversionChar::s
@ s
ConstOnlyContainerWithClassIterator::const_iterator
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:7191
testing::TestPartResultArray
Definition: cares/cares/test/gmock-1.8.0/gtest/gtest.h:18351
testing::internal::FloatingPoint::bits
const Bits & bits() const
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-internal.h:310
a
int a
Definition: abseil-cpp/absl/container/internal/hash_policy_traits_test.cc:88
ASSERT_LE
#define ASSERT_LE(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2064
grpc_core::ForEach
for_each_detail::ForEach< Reader, Action > ForEach(Reader reader, Action action)
For each item acquired by calling Reader::Next, run the promise Action.
Definition: for_each.h:133
EXPECT_LE
#define EXPECT_LE(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2030
SequenceTestingListener::id_
const char *const id_
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:6824
testing::internal::edit_distance::EditType
EditType
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-internal.h:156
xds_manager.p
p
Definition: xds_manager.py:60
testing::TestEventListeners::SetDefaultResultPrinter
void SetDefaultResultPrinter(TestEventListener *listener)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:4572
testing::TestEventListeners
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1170
EXPECT_STRCASENE
#define EXPECT_STRCASENE(s1, s2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2101
testing::internal::GetCurrentOsStackTraceExceptTop
GTEST_API_ std::string GetCurrentOsStackTraceExceptTop(UnitTest *unit_test, int skip_count)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:5697
testing::internal::CaptureStdout
GTEST_API_ void CaptureStdout()
Definition: gmock-gtest-all.cc:9586
testing::ParseFlagsTest::TestParsingFlags
static void TestParsingFlags(int argc1, const CharType **argv1, int argc2, const CharType **argv2, const Flags &expected, bool should_print_help)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5708
grpc::testing::test_result
test_result
Definition: h2_ssl_cert_test.cc:201
AdHocTestResultTest
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:7474
env.new
def new
Definition: env.py:51
testing::internal::UInt32
TypeWithSize< 4 >::UInt UInt32
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:2160
ConstOnlyContainerWithPointerIterator
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:7184
testing::internal::GetElementOr
E GetElementOr(const std::vector< E > &v, int i, E default_value)
Definition: gmock-gtest-all.cc:710
testing::CodeLocationForTYPEDTESTP
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5361
testing::Flags::BreakOnFailure
static Flags BreakOnFailure(bool break_on_failure)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5533
AnonymousEnum
AnonymousEnum
Definition: bloaty/third_party/googletest/googletest/test/googletest-printers-test.cc:57
ASSERT_STRCASEEQ
#define ASSERT_STRCASEEQ(s1, s2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2108
SequenceTestingListener::OnTestIterationEnd
void OnTestIterationEnd(const UnitTest &, int) override
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:6811
testing::internal::String
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-string.h:58
EXPECT_PRED3
#define EXPECT_PRED3(pred, v1, v2, v3)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest_pred_impl.h:220
testing::RegisterTest
TestInfo * RegisterTest(const char *test_suite_name, const char *test_name, const char *type_param, const char *value_param, const char *file, int line, Factory factory)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2437
message
char * message
Definition: libuv/docs/code/tty-gravity/main.c:12
T
#define T(upbtypeconst, upbtype, ctype, default_value)
namespace1::MyTypeInNameSpace1
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5193
testing::Message
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest-message.h:90
GTEST_ASSERT_LT
#define GTEST_ASSERT_LT(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2045
GTEST_ATTRIBUTE_UNUSED_
static bool dummy1 GTEST_ATTRIBUTE_UNUSED_
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:6607
ConstOnlyContainerWithClassIterator::end
const_iterator end() const
true
#define true
Definition: setup_once.h:324
testing::TestResult::GetTestPartResult
const TestPartResult & GetTestPartResult(int i) const
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:2044
testing::Test
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:402
TEST
TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:39
GTEST_FAIL
#define GTEST_FAIL()
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1920
TestListener
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:6716
testing::internal::IndexSequence
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-internal.h:1125
testing::Flags::break_on_failure
bool break_on_failure
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5637
testing::AddGlobalTestEnvironment
Environment * AddGlobalTestEnvironment(Environment *env)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1474
testing::TestWithParam
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1883
testing::internal::RemoveReference
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-internal.h:863
testing::gmock_generated_actions_test::Char
char Char(char ch)
Definition: bloaty/third_party/googletest/googlemock/test/gmock-generated-actions_test.cc:63
TestingVector
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:295
testing::internal::GTestFlagSaver
Definition: gmock-gtest-all.cc:569
EXPECT_EQ
#define EXPECT_EQ(a, b)
Definition: iomgr/time_averaged_stats_test.cc:27
grpc::operator>=
bool operator>=(string_ref x, string_ref y)
Definition: grpcpp/impl/codegen/string_ref.h:143
testing::internal::IsContainer
int IsContainer
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-internal.h:908
namespace1::operator<<
std::ostream & operator<<(std::ostream &os, const MyTypeInNameSpace1 &val)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5197
testing::TEST_P
TEST_P(CodeLocationForTESTP, Verify)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5344
testing::internal::ShouldUseColor
bool ShouldUseColor(bool stdout_is_tty)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:2996
testing::internal::ShouldShard
bool ShouldShard(const char *total_shards_env, const char *shard_index_env, bool in_subprocess_for_death_test)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:5422
GTEST_FLAG_PREFIX_
#define GTEST_FLAG_PREFIX_
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:277
testing::Test::TearDown
virtual void TearDown()
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:2270
grpc::operator<
bool operator<(string_ref x, string_ref y)
Definition: grpcpp/impl/codegen/string_ref.h:140
EXPECT_PRED_FORMAT4
#define EXPECT_PRED_FORMAT4(pred_format, v1, v2, v3, v4)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest_pred_impl.h:279
testing::internal::NativeArray::size
size_t size() const
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-internal.h:1086
testing::internal::posix::RmDir
int RmDir(const char *dir)
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:2013
re2::T1
@ T1
Definition: bloaty/third_party/re2/util/rune.cc:31
my_namespace::testing::TEST
TEST(NestedTestingNamespaceTest, Success)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:6325
testing::internal::StreamableToString
std::string StreamableToString(const T &streamable)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest-message.h:209
testing::internal::ProxyTypeList
Definition: googletest/googletest/include/gtest/internal/gtest-type-util.h:155
testing::Flags::StreamResultTo
static Flags StreamResultTo(const char *stream_result_to)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5621
grpc::operator<=
bool operator<=(string_ref x, string_ref y)
Definition: grpcpp/impl/codegen/string_ref.h:141
testing::TestPartResult::line_number
int line_number() const
Definition: cares/cares/test/gmock-1.8.0/gtest/gtest.h:18307
EXPECT_PRED_FORMAT5
#define EXPECT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest_pred_impl.h:346
SequenceTestingListener::vector_
std::vector< std::string > * vector_
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:6823
ASSERT_FLOAT_EQ
#define ASSERT_FLOAT_EQ(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2135
absl::FormatConversionChar::e
@ e
testing::Flags::catch_exceptions
bool catch_exceptions
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5638
c
void c(T a)
Definition: miscompile_with_no_unique_address_test.cc:40
autogen_x86imm.f
f
Definition: autogen_x86imm.py:9
testing::Flags
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5504
EXPECT_THROW
#define EXPECT_THROW(statement, expected_exception)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1951
GTEST_ASSERT_NE
#define GTEST_ASSERT_NE(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2041
TestGTestRemoveReferenceAndConst
void TestGTestRemoveReferenceAndConst()
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:7140
xds_interop_client.int
int
Definition: xds_interop_client.py:113
my_namespace
Definition: abseil-cpp/absl/strings/internal/str_format/extension_test.cc:26
end
char * end
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1008
Array
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:258
ASSERT_LT
#define ASSERT_LT(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2068
SequenceTestingListener::GTEST_DISALLOW_COPY_AND_ASSIGN_
GTEST_DISALLOW_COPY_AND_ASSIGN_(SequenceTestingListener)
testing::TestInfoTest
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5284
testing::internal::kTestTypeIdInGoogleTest
const TypeId kTestTypeIdInGoogleTest
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/src/gtest.cc:653
ASSERT_PRED1
#define ASSERT_PRED1(pred, v1)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest_pred_impl.h:120
Foo
Definition: abseil-cpp/absl/debugging/symbolize_test.cc:65
gen_stats_data.c_str
def c_str(s, encoding='ascii')
Definition: gen_stats_data.py:38
testing::internal::FormatTimeInMillisAsSeconds
std::string FormatTimeInMillisAsSeconds(TimeInMillis ms)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:3715
b2
T::second_type b2
Definition: abseil-cpp/absl/container/internal/hash_function_defaults_test.cc:308
testing::internal::FlatTuple
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-internal.h:1172
gmock_output_test.output
output
Definition: bloaty/third_party/googletest/googlemock/test/gmock_output_test.py:175
ConstOnlyContainerWithPointerIterator::const_iterator
int * const_iterator
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:7185
ASSERT_STRCASENE
#define ASSERT_STRCASENE(s1, s2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2110
testing::internal::UnitTestRecordPropertyTestHelper::UnitTestRecordProperty
void UnitTestRecordProperty(const char *key, const std::string &value)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:182
EXPECT_NE
#define EXPECT_NE(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2028
ASSERT_DOUBLE_EQ
#define ASSERT_DOUBLE_EQ(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2139
testdata_path_
FilePath testdata_path_
Definition: bloaty/third_party/googletest/googletest/test/googletest-filepath-test.cc:513
ConstOnlyContainerWithClassIterator::const_iterator::operator*
const int & operator*() const
testing::internal::SkipPrefix
GTEST_API_ bool SkipPrefix(const char *prefix, const char **pstr)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:5725
grpc.beta.interfaces.FATAL_FAILURE
FATAL_FAILURE
Definition: interfaces.py:23
TestListener::is_destroyed_
bool * is_destroyed_
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:6735
namespace1::MyTypeInNameSpace1::MyTypeInNameSpace1
MyTypeInNameSpace1(int an_x)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5195
testing::TestPartResultArray::size
int size() const
Definition: bloaty/third_party/googletest/googletest/src/gtest-test-part.cc:77
testing::Flags::death_test_use_fork
bool death_test_use_fork
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5639
ASSERT_PRED_FORMAT4
#define ASSERT_PRED_FORMAT4(pred_format, v1, v2, v3, v4)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest_pred_impl.h:283
testing::internal::CodePointToUtf8
std::string CodePointToUtf8(UInt32 code_point)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:1770
testing::Test::HasFailure
static bool HasFailure()
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:446
namespace1
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5192
setup.v
v
Definition: third_party/bloaty/third_party/capstone/bindings/python/setup.py:42
testing::internal::Random::kMaxRange
static const UInt32 kMaxRange
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-internal.h:835
Verify
static int Verify(X509 *leaf, const std::vector< X509 * > &roots, const std::vector< X509 * > &intermediates, const std::vector< X509_CRL * > &crls, unsigned long flags=0, std::function< void(X509_VERIFY_PARAM *)> configure_callback=nullptr, int(*verify_callback)(int, X509_STORE_CTX *)=nullptr)
Definition: x509_test.cc:1111
benchmarks.python.py_benchmark.results
list results
Definition: bloaty/third_party/protobuf/benchmarks/python/py_benchmark.py:145
testing::UnitTest::current_test_suite
const TestSuite * current_test_suite() const GTEST_LOCK_EXCLUDED_(mutex_)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:4944
testing::internal::RelationToSourceReference
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-internal.h:1046
GTEST_TEST
GTEST_TEST(AlternativeNameTest, Works)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:7037
testing::internal::MakeIndexSequence
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-internal.h:1144
ConstOnlyContainerWithClassIterator::const_iterator::operator++
const_iterator & operator++()
testing::internal::posix::FOpen
FILE * FOpen(const char *path, const char *mode)
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:2033
ConstOnlyContainerWithPointerIterator::begin
const_iterator begin() const
testing::Flags::shuffle
bool shuffle
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5646
grpc::operator>
bool operator>(string_ref x, string_ref y)
Definition: grpcpp/impl/codegen/string_ref.h:142
testing::Environment
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1045
SequenceTestingListener::OnTestProgramEnd
void OnTestProgramEnd(const UnitTest &) override
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:6802
testing::AssertionResult
Definition: cares/cares/test/gmock-1.8.0/gtest/gtest.h:18855
ConversionHelperDerived
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:7084
testing::TestEventListeners::SetDefaultXmlGenerator
void SetDefaultXmlGenerator(TestEventListener *listener)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:4587
testing::internal::NativeArray
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-internal.h:1058
testing::Flags::Flags
Flags()
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5506
StaticAssertTypeEqTestHelper
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:6614
testing::internal::FilePath::GenerateUniqueFileName
static FilePath GenerateUniqueFileName(const FilePath &directory, const FilePath &base_name, const char *extension)
Definition: bloaty/third_party/googletest/googletest/src/gtest-filepath.cc:279
testing::TYPED_TEST_P
TYPED_TEST_P(CodeLocationForTYPEDTESTP, Verify)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5366
testing::TestEventListeners::EventForwardingEnabled
bool EventForwardingEnabled() const
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:4599
testing::SetUpTestSuiteTest::counter_
static int counter_
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5482
absl::inlined_vector_internal::Pointer
typename AllocatorTraits< A >::pointer Pointer
Definition: abseil-cpp/absl/container/internal/inlined_vector.h:52
testing::internal::WideStringToUtf8
std::string WideStringToUtf8(const wchar_t *str, int num_chars)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:1837
absl::compare_internal::value_type
int8_t value_type
Definition: abseil-cpp/absl/types/compare.h:45
testing::internal::AlwaysTrue
GTEST_API_ bool AlwaysTrue()
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:5712
operator!=
bool operator!=(const Bytes &a, const Bytes &b)
Definition: boringssl-with-bazel/src/crypto/test/test_util.h:58
Base
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5141
FAIL
@ FAIL
Definition: call_creds.cc:42
testing::TimeInMillis
internal::TimeInMillis TimeInMillis
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:519
testing::internal::wstring
::std::wstring wstring
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:887
StringValue
Definition: bloaty/third_party/protobuf/src/google/protobuf/wrappers.pb.h:1158
testing::internal::AlwaysFalse
bool AlwaysFalse()
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-internal.h:817
testing::TestProperty
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:525
EXPECT_STRNE
#define EXPECT_STRNE(s1, s2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2097
testing::CurrentTestInfoTest::SetUpTestSuite
static void SetUpTestSuite()
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:6257
testing::TestProperty::key
const char * key() const
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:535
testing::AssertionSuccess
AssertionResult AssertionSuccess()
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:1023
ConstOnlyContainerWithClassIterator
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:7190
testing::SetUpTestSuiteTest
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5440
ConstOnlyContainerWithPointerIterator::end
const_iterator end() const
x
int x
Definition: bloaty/third_party/googletest/googlemock/test/gmock-matchers_test.cc:3610
testing::internal::Int32FromEnvOrDie
Int32 Int32FromEnvOrDie(const char *var, Int32 default_val)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:5467
EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS
#define EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(statement, substr)
testing::Flags::also_run_disabled_tests
bool also_run_disabled_tests
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5636
testing::TestPartResult::failed
bool failed() const
Definition: cares/cares/test/gmock-1.8.0/gtest/gtest.h:18319
a_
arena< N > & a_
Definition: cxa_demangle.cpp:4778
testing::internal::Random
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-internal.h:833
testing::CurrentTestInfoTest
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:6253
testing::internal::ArrayEq
bool ArrayEq(const T *lhs, size_t size, const U *rhs)
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-internal.h:996
testing::TestPartResult::message
const char * message() const
Definition: cares/cares/test/gmock-1.8.0/gtest/gtest.h:18313
testing::internal::MakeIndexSequence
typename MakeIndexSequenceImpl< N >::type MakeIndexSequence
Definition: boringssl-with-bazel/src/third_party/googletest/include/gtest/internal/gtest-internal.h:1189
b
uint64_t b
Definition: abseil-cpp/absl/container/internal/layout_test.cc:53
testing::Flags::repeat
Int32 repeat
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5645
ADD_FAILURE
#define ADD_FAILURE()
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1911
Json::Int
int Int
Definition: third_party/bloaty/third_party/protobuf/conformance/third_party/jsoncpp/json.h:228
testing::TestInfo::result
const TestResult * result() const
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:761
testing::internal::TEST_F
TEST_F(ListenerTest, DoesFoo)
Definition: bloaty/third_party/googletest/googletest/test/googletest-listener-test.cc:226
testing::internal::GetCurrentExecutableName
FilePath GetCurrentExecutableName()
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:429
testing::Flags::list_tests
bool list_tests
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5641
TestGTestRemoveReference
void TestGTestRemoveReference()
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:7128
testing::internal::CanonicalizeForStdLibVersioning
std::string CanonicalizeForStdLibVersioning(std::string s)
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-type-util.h:64
TypedTest
Definition: bloaty/third_party/googletest/googletest/test/googletest-list-tests-unittest_.cc:116
testing::internal::GetTestTypeId
GTEST_API_ TypeId GetTestTypeId()
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:648
testing::internal::GetTimeInMillis
TimeInMillis GetTimeInMillis()
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:836
my_namespace::testing::AssertionResult
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:6322
testing::TestEventListeners::SuppressEventForwarding
void SuppressEventForwarding()
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:4603
n
int n
Definition: abseil-cpp/absl/container/btree_test.cc:1080
ASSERT_ANY_THROW
#define ASSERT_ANY_THROW(statement)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1961
EXPECT_DEATH_IF_SUPPORTED
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest-death-test.h:335
msg
std::string msg
Definition: client_interceptors_end2end_test.cc:372
ASSERT_PRED_FORMAT5
#define ASSERT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest_pred_impl.h:350
Empty
Definition: abseil-cpp/absl/container/internal/compressed_tuple_test.cc:33
testing::internal::UnitTestRecordPropertyTestHelper::unit_test_
UnitTest unit_test_
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:186
EXPECT_NO_FATAL_FAILURE
#define EXPECT_NO_FATAL_FAILURE(statement)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2201
absl::str_format_internal::Flags
Flags
Definition: abseil-cpp/absl/strings/internal/str_format/extension.h:134
kNull
static const int kNull
Definition: stack_test.cc:58
testing::internal::ParseGoogleTestFlagsOnly
void ParseGoogleTestFlagsOnly(int *argc, char **argv)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:6053
testing::CodeLocationForTESTF
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5334
testing::Test::HasNonfatalFailure
static bool HasNonfatalFailure()
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:2532
my_namespace::testing::Test
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:6313
DynamicTest::TestBody
void TestBody() override
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:7497
value_
int value_
Definition: orphanable_test.cc:38
value
const char * value
Definition: hpack_parser_table.cc:165
SequenceTestingListener::GetEventDescription
std::string GetEventDescription(const char *method)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:6817
TestListener::TestListener
TestListener(int *on_start_counter, bool *is_destroyed)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:6719
EXPECT_STREQ
#define EXPECT_STREQ(s1, s2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2095
absl::container_internal::RandomSeed
size_t RandomSeed()
Definition: abseil-cpp/absl/container/internal/raw_hash_set.cc:39
testing::SetUpTestCaseTest
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5379
testing::internal::UnitTestImpl
Definition: gmock-gtest-all.cc:906
testing::StaticAssertTypeEq
bool StaticAssertTypeEq()
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2300
count_
int * count_
Definition: connectivity_state_test.cc:65
b1
T::second_type b1
Definition: abseil-cpp/absl/container/internal/hash_function_defaults_test.cc:306
output_
std::string output_
Definition: json_writer.cc:76
testing::SetUpTestSuiteTest::SetUpTestSuite
static void SetUpTestSuite()
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5444
GTEST_FLAG
#define GTEST_FLAG(name)
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:2169
namespace2
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5217
testing::internal::AppendUserMessage
GTEST_API_ std::string AppendUserMessage(const std::string &gtest_msg, const Message &user_msg)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:2018
testing::TestPartResultArray::GetTestPartResult
const TestPartResult & GetTestPartResult(int index) const
Definition: bloaty/third_party/googletest/googletest/src/gtest-test-part.cc:67
EXPECT_PRED1
#define EXPECT_PRED1(pred, v1)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest_pred_impl.h:116
Test::name
const char * name
Definition: third_party/bloaty/third_party/re2/util/test.cc:13
contents
string_view contents
Definition: elf.cc:597
AdHocTestResultTest::SetUpTestSuite
static void SetUpTestSuite()
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:7476
testing::kMaxStackTraceDepth
const int kMaxStackTraceDepth
Definition: cares/cares/test/gmock-1.8.0/gtest/gtest.h:18746
foo
int foo
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/statusor_test.cc:66
testing::REGISTER_TYPED_TEST_SUITE_P
REGISTER_TYPED_TEST_SUITE_P(CodeLocationForTYPEDTESTP, Verify)
ASSERT_NO_FATAL_FAILURE
#define ASSERT_NO_FATAL_FAILURE(statement)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2199
GetString
static bool GetString(std::string *out, CBS *cbs)
Definition: ssl_ctx_api.cc:228
testing::TYPED_TEST_SUITE
TYPED_TEST_SUITE(CodeLocationForTYPEDTEST, int)
TestListener::TestListener
TestListener()
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:6718
testing::internal::EqFailure
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)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:1326
GTEST_CHECK_
#define GTEST_CHECK_(condition)
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:999
key
const char * key
Definition: hpack_parser_table.cc:164
dynamic_test
auto * dynamic_test
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:7500
benchmark.FILE
FILE
Definition: benchmark.py:21
testing::Values
internal::ValueArray< T... > Values(T... v)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest-param-test.h:335
testing::internal::OsStackTraceGetter
Definition: gmock-gtest-all.cc:852
ConstOnlyContainerWithClassIterator::begin
const_iterator begin() const
testing::TestInfo::name
const char * name() const
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:710
testing::internal::Shuffle
void Shuffle(internal::Random *random, std::vector< E > *v)
Definition: gmock-gtest-all.cc:740
tests
Definition: src/python/grpcio_tests/tests/__init__.py:1
Base::x
int x() const
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5144
GTEST_DISABLE_MSC_DEPRECATED_PUSH_
#define GTEST_DISABLE_MSC_DEPRECATED_PUSH_()
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:322
absl::flags_internal
Definition: abseil-cpp/absl/flags/commandlineflag.h:40
SUCCEED
#define SUCCEED()
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1939
testing::internal::IsAProtocolMessage
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-internal.h:879
count
int * count
Definition: bloaty/third_party/googletest/googlemock/test/gmock_stress_test.cc:96
testing::internal::NativeArray::end
const_iterator end() const
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-internal.h:1088
testing::TestEventListeners::default_result_printer
TestEventListener * default_result_printer() const
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1190
namespace2::MyTypeInNameSpace2::MyTypeInNameSpace2
MyTypeInNameSpace2(int an_x)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5220
grpc::fclose
fclose(creds_file)
protobuf_unittest
Definition: bloaty/third_party/protobuf/src/google/protobuf/map_test_util_impl.h:39
testing::internal::kMaxRandomSeed
const int kMaxRandomSeed
Definition: gmock-gtest-all.cc:513
testing::UnitTest
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1257
IntAlias
int IntAlias
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:6625
TypedTestP
Definition: googletest/googletest/test/googletest-output-test_.cc:784
re2::T2
@ T2
Definition: bloaty/third_party/re2/util/rune.cc:33
testing::internal::ShuffleRange
void ShuffleRange(internal::Random *random, int begin, int end, std::vector< E > *v)
Definition: gmock-gtest-all.cc:719
testing::SetUpTestSuiteTest::shared_resource_
static const char * shared_resource_
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5485
testing::Flags::Shuffle
static Flags Shuffle(bool shuffle)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5605
GTEST_TEST_PARSING_FLAGS_
#define GTEST_TEST_PARSING_FLAGS_(argv1, argv2, expected, should_print_help)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5753
testing::internal::ArrayAwareFind
Iter ArrayAwareFind(Iter begin, Iter end, const Element &elem)
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-internal.h:1007
AHashTable::hasher
void hasher
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:7208
TestListener::OnTestProgramStart
void OnTestProgramStart(const UnitTest &) override
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:6729
testing::internal::ForEach
void ForEach(const Container &c, Functor functor)
Definition: gmock-gtest-all.cc:703
testing::internal::IsNotContainer
char IsNotContainer
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-internal.h:919
EXPECT_STRCASEEQ
#define EXPECT_STRCASEEQ(s1, s2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2099
L
lua_State * L
Definition: upb/upb/bindings/lua/main.c:35
fix_build_deps.r
r
Definition: fix_build_deps.py:491
testing::TestEventListeners::repeater
TestEventListener * repeater()
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:4565
googletest-shuffle-test.AlsoRunDisabledTestsFlag
def AlsoRunDisabledTestsFlag()
Definition: bloaty/third_party/googletest/googletest/test/googletest-shuffle-test.py:56
EXPECT_LT
#define EXPECT_LT(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2032
testing::SetUpTestCaseTest::shared_resource_
static const char * shared_resource_
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5424
testing::INSTANTIATE_TEST_SUITE_P
INSTANTIATE_TEST_SUITE_P(, CodeLocationForTESTP, Values(0))
testing::internal::CopyArray
void CopyArray(const T *from, size_t size, U *to)
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-internal.h:1036
HasFailureHelper
static bool HasFailureHelper()
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:6703
testing::TEST
TEST(GrpcAwsRequestSignerTest, AWSOfficialExample)
Definition: aws_request_signer_test.cc:68
testing::IsSubstring
GTEST_API_ AssertionResult IsSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:1617
values
std::array< int64_t, Size > values
Definition: abseil-cpp/absl/container/btree_benchmark.cc:608
TestGTestReferenceToConst
void TestGTestReferenceToConst()
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:7155
my_namespace::testing::Message
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:6317
testing::Flags::Filter
static Flags Filter(const char *filter)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5557
testing::TestEventListeners::Release
TestEventListener * Release(TestEventListener *listener)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:4555
regen-readme.line
line
Definition: regen-readme.py:30
ASSERT_TRUE
#define ASSERT_TRUE(condition)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1973
ASSERT_FALSE
#define ASSERT_FALSE(condition)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1976
testing::IsNotSubstring
GTEST_API_ AssertionResult IsNotSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:1629
DisabledTest
Definition: bloaty/third_party/googletest/googletest/test/gtest_xml_output_unittest_.cc:63
testing::Flags::ThrowOnFailure
static Flags ThrowOnFailure(bool throw_on_failure)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5629
testing::Flags::filter
const char * filter
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5640
testing::UnitTest::ad_hoc_test_result
const TestResult & ad_hoc_test_result() const
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:4734
testing::UnitTest::GetInstance
static UnitTest * GetInstance()
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:4616
testing::CurrentTestInfoTest::TearDownTestSuite
static void TearDownTestSuite()
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:6267
testing::EmptyTestEventListener
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1141
testing::TestResult::Passed
bool Passed() const
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:578
testing::CodeLocationForTYPEDTEST
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5351
EXPECT_NO_THROW
#define EXPECT_NO_THROW(statement)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1953
EXPECT_PRED2
#define EXPECT_PRED2(pred, v1, v2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest_pred_impl.h:165
absl::ABSL_NAMESPACE_BEGIN::dummy
int dummy
Definition: function_type_benchmark.cc:28
ProtectedFixtureMethodsTest
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:6342
testing::Flags::CatchExceptions
static Flags CatchExceptions(bool catch_exceptions)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5541
EXPECT_GE
#define EXPECT_GE(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2034
GTEST_DISABLE_MSC_WARNINGS_POP_
#define GTEST_DISABLE_MSC_WARNINGS_POP_()
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:309
GTEST_ASSERT_EQ
#define GTEST_ASSERT_EQ(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2039
TEST_F
TEST_F(AdHocTestResultTest, AdHocTestResultForTestSuiteShowsFailure)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:7481
EXPECT_TRUE
#define EXPECT_TRUE(condition)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1967
testing::TestResult::Failed
bool Failed() const
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:2207
EXPECT_DOUBLE_EQ
#define EXPECT_DOUBLE_EQ(a, b)
Definition: iomgr/time_averaged_stats_test.cc:28
EXPECT_NEAR
#define EXPECT_NEAR(val1, val2, abs_error)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2143
bloaty::Throw
ABSL_ATTRIBUTE_NORETURN void Throw(const char *str, int line)
Definition: third_party/bloaty/src/util.cc:22
testing::internal::edit_distance::CreateUnifiedDiff
GTEST_API_ std::string CreateUnifiedDiff(const std::vector< std::string > &left, const std::vector< std::string > &right, size_t context=2)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:1216
testing::TestSuite::ad_hoc_test_result
const TestResult & ad_hoc_test_result() const
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:907
testing::FloatLE
GTEST_API_ AssertionResult FloatLE(const char *expr1, const char *expr2, float val1, float val2)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:1434
b_
const char * b_
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/common_unittest.cc:194
FailFatally
static void FailFatally()
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:6636
testing::SetUpTestCaseTest::counter_
static int counter_
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5421
ASSERT_THROW
#define ASSERT_THROW(statement, expected_exception)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1957
testing::Flags::Repeat
static Flags Repeat(Int32 repeat)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5597
testing::TestCase
TestSuite TestCase
Definition: googletest/googletest/include/gtest/gtest.h:203
testing::internal::CountIf
int CountIf(const Container &c, Predicate predicate)
Definition: gmock-gtest-all.cc:690
internal
Definition: benchmark/test/output_test_helper.cc:20
ConvertibleToAssertionResult
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5130
testing::UnitTest::RecordProperty
void RecordProperty(const std::string &key, const std::string &value)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:4843
testing::TestProperty::value
const char * value() const
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:540
flags
uint32_t flags
Definition: retry_filter.cc:632
testing::Flags::output
const char * output
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5642
asyncio_get_stats.type
type
Definition: asyncio_get_stats.py:37
ch
char ch
Definition: bloaty/third_party/googletest/googlemock/test/gmock-matchers_test.cc:3621
testing::SetUpTestSuiteTest::TearDownTestSuite
static void TearDownTestSuite()
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5461
testing::internal::FlatTuple::Get
const ElemFromList< I, Indices, T... >::type & Get() const
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-internal.h:1219
testing::internal::ElemFromList
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-internal.h:1165
testing::Flags::stack_trace_depth
Int32 stack_trace_depth
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5647
operator<<
::std::ostream & operator<<(::std::ostream &os, const TestingVector &vector)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:298
EXPECT_FLOAT_EQ
#define EXPECT_FLOAT_EQ(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2127
EXPECT_NONFATAL_FAILURE
#define EXPECT_NONFATAL_FAILURE(statement, substr)
ASSERT_GT
#define ASSERT_GT(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2076
benchmark::ParseInt32Flag
bool ParseInt32Flag(const char *str, const char *flag, int32_t *value)
Definition: benchmark/src/commandlineflags.cc:216
EXPECT_PRED_FORMAT1
#define EXPECT_PRED_FORMAT1(pred_format, v1)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest_pred_impl.h:114
testing::TYPED_TEST
TYPED_TEST(CodeLocationForTYPEDTEST, Verify)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5356
testing::internal::FormatEpochTimeInMillisAsIso8601
std::string FormatEpochTimeInMillisAsIso8601(TimeInMillis ms)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:3738
testing::TestPartResult::file_name
const char * file_name() const
Definition: cares/cares/test/gmock-1.8.0/gtest/gtest.h:18301
GTEST_ASSERT_GT
#define GTEST_ASSERT_GT(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2049
method
NSString * method
Definition: ProtoMethod.h:28
google::protobuf::compiler::objectivec::FilePath
string FilePath(const FileDescriptor *file)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc:404
testing::TestPartResult::fatally_failed
bool fatally_failed() const
Definition: cares/cares/test/gmock-1.8.0/gtest/gtest.h:18325
dummy2
int dummy2
Definition: benchmark/test/register_benchmark_test.cc:93
getenv
#define getenv(ptr)
Definition: ares_private.h:106
testing::internal::ParseInt32Flag
bool ParseInt32Flag(const char *str, const char *flag, Int32 *value)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:5793
testing::Flags::throw_on_failure
bool throw_on_failure
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5649
namespace2::MyTypeInNameSpace2
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5218
testing::AssertionResult::message
const char * message() const
Definition: cares/cares/test/gmock-1.8.0/gtest/gtest.h:18896
library1::NumericTypes
Types< int, long > NumericTypes
Definition: googletest/googletest/test/gtest-typed-test_test.cc:161
testing::Flags::PrintTime
static Flags PrintTime(bool print_time)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5581
testing::DoubleLE
GTEST_API_ AssertionResult DoubleLE(const char *expr1, const char *expr2, double val1, double val2)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:1441
SequenceTestingListener::SequenceTestingListener
SequenceTestingListener(std::vector< std::string > *vector, const char *id)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:6794
ProtectedFixtureMethodsTest::SetUp
void SetUp() override
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:6344
thread
static uv_thread_t thread
Definition: test-async-null-cb.c:29
Test
Definition: hpack_parser_test.cc:43
testing::internal::g_help_flag
bool g_help_flag
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:182
if
if(p->owned &&p->wrapped !=NULL)
Definition: call.c:42
testing::internal::TestEventListenersAccessor::GetRepeater
static TestEventListener * GetRepeater(TestEventListeners *listeners)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:155
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
testing::internal::GetRandomSeedFromFlag
int GetRandomSeedFromFlag(Int32 random_seed_flag)
Definition: gmock-gtest-all.cc:543
testing::Flags::ListTests
static Flags ListTests(bool list_tests)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5565
setup.test_suite
test_suite
Definition: src/python/grpcio_tests/setup.py:108
NotReallyAHashTable
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:7210
id
uint32_t id
Definition: flow_control_fuzzer.cc:70
ASSERT_EQ
#define ASSERT_EQ(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2056
testing::internal::TestEventListenersAccessor::EventForwardingEnabled
static bool EventForwardingEnabled(const TestEventListeners &listeners)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:168
testing::TestEventListener
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1076
ASSERT_PRED_FORMAT1
#define ASSERT_PRED_FORMAT1(pred_format, v1)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest_pred_impl.h:118
testing::TestSuite
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:830
testing::internal::UnitTestRecordPropertyTestHelper
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:177
absl::types_internal::AlwaysFalse
std::false_type AlwaysFalse
Definition: abseil-cpp/absl/types/internal/conformance_profile.h:367
strdup
#define strdup(ptr)
Definition: acountry.c:55
testing::internal::UnitTestImpl::GetTestSuite
const TestSuite * GetTestSuite(int i) const
Definition: googletest/googletest/src/gtest-internal-inl.h:577
testing::CodeLocationForTESTP
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5341
testing::Flags::RandomSeed
static Flags RandomSeed(Int32 random_seed)
Definition: bloaty/third_party/googletest/googletest/test/gtest_unittest.cc:5589
testing::internal::IsHashTable
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-internal.h:928
DynamicTest
Definition: bloaty/third_party/googletest/googletest/test/googletest-output-test_.cc:1053


grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:56