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