bloaty/third_party/googletest/googlemock/test/gmock-internal-utils_test.cc
Go to the documentation of this file.
1 // Copyright 2007, 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 // Google Mock - a framework for writing C++ mock classes.
32 //
33 // This file tests the internal utilities.
34 
35 #include "gmock/internal/gmock-internal-utils.h"
36 
37 #include <stdlib.h>
38 
39 #include <map>
40 #include <memory>
41 #include <sstream>
42 #include <string>
43 #include <type_traits>
44 #include <vector>
45 
46 #include "gmock/gmock.h"
47 #include "gmock/internal/gmock-port.h"
48 #include "gtest/gtest-spi.h"
49 #include "gtest/gtest.h"
50 
51 // Indicates that this translation unit is part of Google Test's
52 // implementation. It must come before gtest-internal-inl.h is
53 // included, or there will be a compiler error. This trick is to
54 // prevent a user from accidentally including gtest-internal-inl.h in
55 // their code.
56 #define GTEST_IMPLEMENTATION_ 1
57 #include "src/gtest-internal-inl.h"
58 #undef GTEST_IMPLEMENTATION_
59 
60 #if GTEST_OS_CYGWIN
61 # include <sys/types.h> // For ssize_t. NOLINT
62 #endif
63 
64 namespace proto2 {
65 class Message;
66 } // namespace proto2
67 
68 namespace testing {
69 namespace internal {
70 
71 namespace {
72 
73 TEST(JoinAsTupleTest, JoinsEmptyTuple) {
75 }
76 
77 TEST(JoinAsTupleTest, JoinsOneTuple) {
78  const char* fields[] = {"1"};
80 }
81 
82 TEST(JoinAsTupleTest, JoinsTwoTuple) {
83  const char* fields[] = {"1", "a"};
84  EXPECT_EQ("(1, a)", JoinAsTuple(Strings(fields, fields + 2)));
85 }
86 
87 TEST(JoinAsTupleTest, JoinsTenTuple) {
88  const char* fields[] = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
89  EXPECT_EQ("(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)",
91 }
92 
93 TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsNoWord) {
97 }
98 
99 TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsDigits) {
103  EXPECT_EQ("34 56", ConvertIdentifierNameToWords("_34_56"));
104 }
105 
106 TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsCamelCaseWords) {
107  EXPECT_EQ("a big word", ConvertIdentifierNameToWords("ABigWord"));
108  EXPECT_EQ("foo bar", ConvertIdentifierNameToWords("FooBar"));
109  EXPECT_EQ("foo", ConvertIdentifierNameToWords("Foo_"));
110  EXPECT_EQ("foo bar", ConvertIdentifierNameToWords("_Foo_Bar_"));
111  EXPECT_EQ("foo and bar", ConvertIdentifierNameToWords("_Foo__And_Bar"));
112 }
113 
114 TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContains_SeparatedWords) {
115  EXPECT_EQ("foo bar", ConvertIdentifierNameToWords("foo_bar"));
116  EXPECT_EQ("foo", ConvertIdentifierNameToWords("_foo_"));
117  EXPECT_EQ("foo bar", ConvertIdentifierNameToWords("_foo_bar_"));
118  EXPECT_EQ("foo and bar", ConvertIdentifierNameToWords("_foo__and_bar"));
119 }
120 
121 TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameIsMixture) {
122  EXPECT_EQ("foo bar 123", ConvertIdentifierNameToWords("Foo_bar123"));
123  EXPECT_EQ("chapter 11 section 1",
124  ConvertIdentifierNameToWords("_Chapter11Section_1_"));
125 }
126 
127 TEST(PointeeOfTest, WorksForSmartPointers) {
128  CompileAssertTypesEqual<int, PointeeOf<std::unique_ptr<int> >::type>();
129  CompileAssertTypesEqual<std::string,
130  PointeeOf<std::shared_ptr<std::string> >::type>();
131 }
132 
133 TEST(PointeeOfTest, WorksForRawPointers) {
137 }
138 
139 TEST(GetRawPointerTest, WorksForSmartPointers) {
140  const char* const raw_p1 = new const char('a'); // NOLINT
141  const std::unique_ptr<const char> p1(raw_p1);
142  EXPECT_EQ(raw_p1, GetRawPointer(p1));
143  double* const raw_p2 = new double(2.5); // NOLINT
144  const std::shared_ptr<double> p2(raw_p2);
145  EXPECT_EQ(raw_p2, GetRawPointer(p2));
146 }
147 
148 TEST(GetRawPointerTest, WorksForRawPointers) {
149  int* p = nullptr;
150  EXPECT_TRUE(nullptr == GetRawPointer(p));
151  int n = 1;
152  EXPECT_EQ(&n, GetRawPointer(&n));
153 }
154 
155 // Tests KindOf<T>.
156 
157 class Base {};
158 class Derived : public Base {};
159 
160 TEST(KindOfTest, Bool) {
161  EXPECT_EQ(kBool, GMOCK_KIND_OF_(bool)); // NOLINT
162 }
163 
164 TEST(KindOfTest, Integer) {
165  EXPECT_EQ(kInteger, GMOCK_KIND_OF_(char)); // NOLINT
166  EXPECT_EQ(kInteger, GMOCK_KIND_OF_(signed char)); // NOLINT
167  EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned char)); // NOLINT
168  EXPECT_EQ(kInteger, GMOCK_KIND_OF_(short)); // NOLINT
169  EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned short)); // NOLINT
170  EXPECT_EQ(kInteger, GMOCK_KIND_OF_(int)); // NOLINT
171  EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned int)); // NOLINT
172  EXPECT_EQ(kInteger, GMOCK_KIND_OF_(long)); // NOLINT
173  EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned long)); // NOLINT
174  EXPECT_EQ(kInteger, GMOCK_KIND_OF_(wchar_t)); // NOLINT
175  EXPECT_EQ(kInteger, GMOCK_KIND_OF_(Int64)); // NOLINT
177  EXPECT_EQ(kInteger, GMOCK_KIND_OF_(size_t)); // NOLINT
178 #if GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_CYGWIN
179  // ssize_t is not defined on Windows and possibly some other OSes.
181 #endif
182 }
183 
184 TEST(KindOfTest, FloatingPoint) {
185  EXPECT_EQ(kFloatingPoint, GMOCK_KIND_OF_(float)); // NOLINT
186  EXPECT_EQ(kFloatingPoint, GMOCK_KIND_OF_(double)); // NOLINT
187  EXPECT_EQ(kFloatingPoint, GMOCK_KIND_OF_(long double)); // NOLINT
188 }
189 
190 TEST(KindOfTest, Other) {
191  EXPECT_EQ(kOther, GMOCK_KIND_OF_(void*)); // NOLINT
192  EXPECT_EQ(kOther, GMOCK_KIND_OF_(char**)); // NOLINT
193  EXPECT_EQ(kOther, GMOCK_KIND_OF_(Base)); // NOLINT
194 }
195 
196 // Tests LosslessArithmeticConvertible<T, U>.
197 
198 TEST(LosslessArithmeticConvertibleTest, BoolToBool) {
200 }
201 
202 TEST(LosslessArithmeticConvertibleTest, BoolToInteger) {
205  EXPECT_TRUE(
207 }
208 
209 TEST(LosslessArithmeticConvertibleTest, BoolToFloatingPoint) {
212 }
213 
214 TEST(LosslessArithmeticConvertibleTest, IntegerToBool) {
217 }
218 
219 TEST(LosslessArithmeticConvertibleTest, IntegerToInteger) {
220  // Unsigned => larger signed is fine.
222 
223  // Unsigned => larger unsigned is fine.
224  EXPECT_TRUE(
226 
227  // Signed => unsigned is not fine.
230  signed char, unsigned int>::value)); // NOLINT
231 
232  // Same size and same signedness: fine too.
234  unsigned char, unsigned char>::value));
238  unsigned long, unsigned long>::value)); // NOLINT
239 
240  // Same size, different signedness: not fine.
242  unsigned char, signed char>::value));
245 
246  // Larger size => smaller size is not fine.
250 }
251 
252 TEST(LosslessArithmeticConvertibleTest, IntegerToFloatingPoint) {
253  // Integers cannot be losslessly converted to floating-points, as
254  // the format of the latter is implementation-defined.
258  short, long double>::value)); // NOLINT
259 }
260 
261 TEST(LosslessArithmeticConvertibleTest, FloatingPointToBool) {
264 }
265 
266 TEST(LosslessArithmeticConvertibleTest, FloatingPointToInteger) {
270 }
271 
272 TEST(LosslessArithmeticConvertibleTest, FloatingPointToFloatingPoint) {
273  // Smaller size => larger size is fine.
277 
278  // Same size: fine.
281 
282  // Larger size => smaller size is not fine.
285  if (sizeof(double) == sizeof(long double)) { // NOLINT
287  // In some implementations (e.g. MSVC), double and long double
288  // have the same size.
289  EXPECT_TRUE((LosslessArithmeticConvertible<long double, double>::value));
290  } else {
292  }
293 }
294 
295 // Tests the TupleMatches() template function.
296 
297 TEST(TupleMatchesTest, WorksForSize0) {
298  std::tuple<> matchers;
299  std::tuple<> values;
300 
302 }
303 
304 TEST(TupleMatchesTest, WorksForSize1) {
305  std::tuple<Matcher<int> > matchers(Eq(1));
306  std::tuple<int> values1(1), values2(2);
307 
308  EXPECT_TRUE(TupleMatches(matchers, values1));
310 }
311 
312 TEST(TupleMatchesTest, WorksForSize2) {
313  std::tuple<Matcher<int>, Matcher<char> > matchers(Eq(1), Eq('a'));
314  std::tuple<int, char> values1(1, 'a'), values2(1, 'b'), values3(2, 'a'),
315  values4(2, 'b');
316 
317  EXPECT_TRUE(TupleMatches(matchers, values1));
321 }
322 
323 TEST(TupleMatchesTest, WorksForSize5) {
324  std::tuple<Matcher<int>, Matcher<char>, Matcher<bool>,
325  Matcher<long>, // NOLINT
326  Matcher<std::string> >
327  matchers(Eq(1), Eq('a'), Eq(true), Eq(2L), Eq("hi"));
328  std::tuple<int, char, bool, long, std::string> // NOLINT
329  values1(1, 'a', true, 2L, "hi"), values2(1, 'a', true, 2L, "hello"),
330  values3(2, 'a', true, 2L, "hi");
331 
332  EXPECT_TRUE(TupleMatches(matchers, values1));
335 }
336 
337 // Tests that Assert(true, ...) succeeds.
338 TEST(AssertTest, SucceedsOnTrue) {
339  Assert(true, __FILE__, __LINE__, "This should succeed.");
340  Assert(true, __FILE__, __LINE__); // This should succeed too.
341 }
342 
343 // Tests that Assert(false, ...) generates a fatal failure.
344 TEST(AssertTest, FailsFatallyOnFalse) {
346  Assert(false, __FILE__, __LINE__, "This should fail.");
347  }, "");
348 
350  Assert(false, __FILE__, __LINE__);
351  }, "");
352 }
353 
354 // Tests that Expect(true, ...) succeeds.
355 TEST(ExpectTest, SucceedsOnTrue) {
356  Expect(true, __FILE__, __LINE__, "This should succeed.");
357  Expect(true, __FILE__, __LINE__); // This should succeed too.
358 }
359 
360 // Tests that Expect(false, ...) generates a non-fatal failure.
361 TEST(ExpectTest, FailsNonfatallyOnFalse) {
362  EXPECT_NONFATAL_FAILURE({ // NOLINT
363  Expect(false, __FILE__, __LINE__, "This should fail.");
364  }, "This should fail");
365 
366  EXPECT_NONFATAL_FAILURE({ // NOLINT
367  Expect(false, __FILE__, __LINE__);
368  }, "Expectation failed");
369 }
370 
371 // Tests LogIsVisible().
372 
373 class LogIsVisibleTest : public ::testing::Test {
374  protected:
375  void SetUp() override { original_verbose_ = GMOCK_FLAG(verbose); }
376 
377  void TearDown() override { GMOCK_FLAG(verbose) = original_verbose_; }
378 
380 };
381 
382 TEST_F(LogIsVisibleTest, AlwaysReturnsTrueIfVerbosityIsInfo) {
386 }
387 
388 TEST_F(LogIsVisibleTest, AlwaysReturnsFalseIfVerbosityIsError) {
392 }
393 
394 TEST_F(LogIsVisibleTest, WorksWhenVerbosityIsWarning) {
398 }
399 
400 #if GTEST_HAS_STREAM_REDIRECTION
401 
402 // Tests the Log() function.
403 
404 // Verifies that Log() behaves correctly for the given verbosity level
405 // and log severity.
406 void TestLogWithSeverity(const std::string& verbosity, LogSeverity severity,
407  bool should_print) {
408  const std::string old_flag = GMOCK_FLAG(verbose);
410  CaptureStdout();
411  Log(severity, "Test log.\n", 0);
412  if (should_print) {
415  severity == kWarning ?
416  "^\nGMOCK WARNING:\nTest log\\.\nStack trace:\n" :
417  "^\nTest log\\.\nStack trace:\n"));
418  } else {
420  }
421  GMOCK_FLAG(verbose) = old_flag;
422 }
423 
424 // Tests that when the stack_frames_to_skip parameter is negative,
425 // Log() doesn't include the stack trace in the output.
426 TEST(LogTest, NoStackTraceWhenStackFramesToSkipIsNegative) {
427  const std::string saved_flag = GMOCK_FLAG(verbose);
429  CaptureStdout();
430  Log(kInfo, "Test log.\n", -1);
431  EXPECT_STREQ("\nTest log.\n", GetCapturedStdout().c_str());
432  GMOCK_FLAG(verbose) = saved_flag;
433 }
434 
435 struct MockStackTraceGetter : testing::internal::OsStackTraceGetterInterface {
436  std::string CurrentStackTrace(int max_depth, int skip_count) override {
437  return (testing::Message() << max_depth << "::" << skip_count << "\n")
438  .GetString();
439  }
440  void UponLeavingGTest() override {}
441 };
442 
443 // Tests that in opt mode, a positive stack_frames_to_skip argument is
444 // treated as 0.
445 TEST(LogTest, NoSkippingStackFrameInOptMode) {
446  MockStackTraceGetter* mock_os_stack_trace_getter = new MockStackTraceGetter;
447  GetUnitTestImpl()->set_os_stack_trace_getter(mock_os_stack_trace_getter);
448 
449  CaptureStdout();
450  Log(kWarning, "Test log.\n", 100);
452 
453  std::string expected_trace =
454  (testing::Message() << GTEST_FLAG(stack_trace_depth) << "::").GetString();
455  std::string expected_message =
456  "\nGMOCK WARNING:\n"
457  "Test log.\n"
458  "Stack trace:\n" +
459  expected_trace;
460  EXPECT_THAT(log, HasSubstr(expected_message));
461  int skip_count = atoi(log.substr(expected_message.size()).c_str());
462 
463 # if defined(NDEBUG)
464  // In opt mode, no stack frame should be skipped.
465  const int expected_skip_count = 0;
466 # else
467  // In dbg mode, the stack frames should be skipped.
468  const int expected_skip_count = 100;
469 # endif
470 
471  // Note that each inner implementation layer will +1 the number to remove
472  // itself from the trace. This means that the value is a little higher than
473  // expected, but close enough.
474  EXPECT_THAT(skip_count,
475  AllOf(Ge(expected_skip_count), Le(expected_skip_count + 10)));
476 
477  // Restores the default OS stack trace getter.
479 }
480 
481 // Tests that all logs are printed when the value of the
482 // --gmock_verbose flag is "info".
483 TEST(LogTest, AllLogsArePrintedWhenVerbosityIsInfo) {
484  TestLogWithSeverity(kInfoVerbosity, kInfo, true);
485  TestLogWithSeverity(kInfoVerbosity, kWarning, true);
486 }
487 
488 // Tests that only warnings are printed when the value of the
489 // --gmock_verbose flag is "warning".
490 TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsWarning) {
491  TestLogWithSeverity(kWarningVerbosity, kInfo, false);
492  TestLogWithSeverity(kWarningVerbosity, kWarning, true);
493 }
494 
495 // Tests that no logs are printed when the value of the
496 // --gmock_verbose flag is "error".
497 TEST(LogTest, NoLogsArePrintedWhenVerbosityIsError) {
498  TestLogWithSeverity(kErrorVerbosity, kInfo, false);
499  TestLogWithSeverity(kErrorVerbosity, kWarning, false);
500 }
501 
502 // Tests that only warnings are printed when the value of the
503 // --gmock_verbose flag is invalid.
504 TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsInvalid) {
505  TestLogWithSeverity("invalid", kInfo, false);
506  TestLogWithSeverity("invalid", kWarning, true);
507 }
508 
509 #endif // GTEST_HAS_STREAM_REDIRECTION
510 
511 TEST(TypeTraitsTest, remove_reference) {
512  EXPECT_TRUE((std::is_same<char, remove_reference<char&>::type>::value));
513  EXPECT_TRUE(
514  (std::is_same<const int, remove_reference<const int&>::type>::value));
515  EXPECT_TRUE((std::is_same<int, remove_reference<int>::type>::value));
516  EXPECT_TRUE((std::is_same<double*, remove_reference<double*>::type>::value));
517 }
518 
519 #if GTEST_HAS_STREAM_REDIRECTION
520 
521 // Verifies that Log() behaves correctly for the given verbosity level
522 // and log severity.
523 std::string GrabOutput(void(*logger)(), const char* verbosity) {
524  const std::string saved_flag = GMOCK_FLAG(verbose);
526  CaptureStdout();
527  logger();
528  GMOCK_FLAG(verbose) = saved_flag;
529  return GetCapturedStdout();
530 }
531 
532 class DummyMock {
533  public:
534  MOCK_METHOD0(TestMethod, void());
535  MOCK_METHOD1(TestMethodArg, void(int dummy));
536 };
537 
538 void ExpectCallLogger() {
539  DummyMock mock;
540  EXPECT_CALL(mock, TestMethod());
541  mock.TestMethod();
542 }
543 
544 // Verifies that EXPECT_CALL logs if the --gmock_verbose flag is set to "info".
545 TEST(ExpectCallTest, LogsWhenVerbosityIsInfo) {
546  EXPECT_THAT(std::string(GrabOutput(ExpectCallLogger, kInfoVerbosity)),
547  HasSubstr("EXPECT_CALL(mock, TestMethod())"));
548 }
549 
550 // Verifies that EXPECT_CALL doesn't log
551 // if the --gmock_verbose flag is set to "warning".
552 TEST(ExpectCallTest, DoesNotLogWhenVerbosityIsWarning) {
553  EXPECT_STREQ("", GrabOutput(ExpectCallLogger, kWarningVerbosity).c_str());
554 }
555 
556 // Verifies that EXPECT_CALL doesn't log
557 // if the --gmock_verbose flag is set to "error".
558 TEST(ExpectCallTest, DoesNotLogWhenVerbosityIsError) {
559  EXPECT_STREQ("", GrabOutput(ExpectCallLogger, kErrorVerbosity).c_str());
560 }
561 
562 void OnCallLogger() {
563  DummyMock mock;
564  ON_CALL(mock, TestMethod());
565 }
566 
567 // Verifies that ON_CALL logs if the --gmock_verbose flag is set to "info".
568 TEST(OnCallTest, LogsWhenVerbosityIsInfo) {
569  EXPECT_THAT(std::string(GrabOutput(OnCallLogger, kInfoVerbosity)),
570  HasSubstr("ON_CALL(mock, TestMethod())"));
571 }
572 
573 // Verifies that ON_CALL doesn't log
574 // if the --gmock_verbose flag is set to "warning".
575 TEST(OnCallTest, DoesNotLogWhenVerbosityIsWarning) {
576  EXPECT_STREQ("", GrabOutput(OnCallLogger, kWarningVerbosity).c_str());
577 }
578 
579 // Verifies that ON_CALL doesn't log if
580 // the --gmock_verbose flag is set to "error".
581 TEST(OnCallTest, DoesNotLogWhenVerbosityIsError) {
582  EXPECT_STREQ("", GrabOutput(OnCallLogger, kErrorVerbosity).c_str());
583 }
584 
585 void OnCallAnyArgumentLogger() {
586  DummyMock mock;
587  ON_CALL(mock, TestMethodArg(_));
588 }
589 
590 // Verifies that ON_CALL prints provided _ argument.
591 TEST(OnCallTest, LogsAnythingArgument) {
592  EXPECT_THAT(std::string(GrabOutput(OnCallAnyArgumentLogger, kInfoVerbosity)),
593  HasSubstr("ON_CALL(mock, TestMethodArg(_)"));
594 }
595 
596 #endif // GTEST_HAS_STREAM_REDIRECTION
597 
598 // Tests StlContainerView.
599 
600 TEST(StlContainerViewTest, WorksForStlContainer) {
601  StaticAssertTypeEq<std::vector<int>,
602  StlContainerView<std::vector<int> >::type>();
603  StaticAssertTypeEq<const std::vector<double>&,
604  StlContainerView<std::vector<double> >::const_reference>();
605 
606  typedef std::vector<char> Chars;
607  Chars v1;
608  const Chars& v2(StlContainerView<Chars>::ConstReference(v1));
609  EXPECT_EQ(&v1, &v2);
610 
611  v1.push_back('a');
612  Chars v3 = StlContainerView<Chars>::Copy(v1);
613  EXPECT_THAT(v3, Eq(v3));
614 }
615 
616 TEST(StlContainerViewTest, WorksForStaticNativeArray) {
617  StaticAssertTypeEq<NativeArray<int>,
619  StaticAssertTypeEq<NativeArray<double>,
621  StaticAssertTypeEq<NativeArray<char[3]>,
623 
624  StaticAssertTypeEq<const NativeArray<int>,
626 
627  int a1[3] = { 0, 1, 2 };
628  NativeArray<int> a2 = StlContainerView<int[3]>::ConstReference(a1);
629  EXPECT_EQ(3U, a2.size());
630  EXPECT_EQ(a1, a2.begin());
631 
632  const NativeArray<int> a3 = StlContainerView<int[3]>::Copy(a1);
633  ASSERT_EQ(3U, a3.size());
634  EXPECT_EQ(0, a3.begin()[0]);
635  EXPECT_EQ(1, a3.begin()[1]);
636  EXPECT_EQ(2, a3.begin()[2]);
637 
638  // Makes sure a1 and a3 aren't aliases.
639  a1[0] = 3;
640  EXPECT_EQ(0, a3.begin()[0]);
641 }
642 
643 TEST(StlContainerViewTest, WorksForDynamicNativeArray) {
644  StaticAssertTypeEq<NativeArray<int>,
645  StlContainerView<std::tuple<const int*, size_t> >::type>();
647  NativeArray<double>,
648  StlContainerView<std::tuple<std::shared_ptr<double>, int> >::type>();
649 
651  const NativeArray<int>,
652  StlContainerView<std::tuple<const int*, int> >::const_reference>();
653 
654  int a1[3] = { 0, 1, 2 };
655  const int* const p1 = a1;
656  NativeArray<int> a2 =
657  StlContainerView<std::tuple<const int*, int> >::ConstReference(
658  std::make_tuple(p1, 3));
659  EXPECT_EQ(3U, a2.size());
660  EXPECT_EQ(a1, a2.begin());
661 
662  const NativeArray<int> a3 = StlContainerView<std::tuple<int*, size_t> >::Copy(
663  std::make_tuple(static_cast<int*>(a1), 3));
664  ASSERT_EQ(3U, a3.size());
665  EXPECT_EQ(0, a3.begin()[0]);
666  EXPECT_EQ(1, a3.begin()[1]);
667  EXPECT_EQ(2, a3.begin()[2]);
668 
669  // Makes sure a1 and a3 aren't aliases.
670  a1[0] = 3;
671  EXPECT_EQ(0, a3.begin()[0]);
672 }
673 
674 // Tests the Function template struct.
675 
676 TEST(FunctionTest, Nullary) {
677  typedef Function<int()> F; // NOLINT
678  EXPECT_EQ(0u, F::ArgumentCount);
679  CompileAssertTypesEqual<int, F::Result>();
680  CompileAssertTypesEqual<std::tuple<>, F::ArgumentTuple>();
681  CompileAssertTypesEqual<std::tuple<>, F::ArgumentMatcherTuple>();
682  CompileAssertTypesEqual<void(), F::MakeResultVoid>();
683  CompileAssertTypesEqual<IgnoredValue(), F::MakeResultIgnoredValue>();
684 }
685 
686 TEST(FunctionTest, Unary) {
687  typedef Function<int(bool)> F; // NOLINT
688  EXPECT_EQ(1u, F::ArgumentCount);
689  CompileAssertTypesEqual<int, F::Result>();
691  CompileAssertTypesEqual<std::tuple<bool>, F::ArgumentTuple>();
692  CompileAssertTypesEqual<std::tuple<Matcher<bool> >,
693  F::ArgumentMatcherTuple>();
694  CompileAssertTypesEqual<void(bool), F::MakeResultVoid>(); // NOLINT
695  CompileAssertTypesEqual<IgnoredValue(bool), // NOLINT
696  F::MakeResultIgnoredValue>();
697 }
698 
699 TEST(FunctionTest, Binary) {
700  typedef Function<int(bool, const long&)> F; // NOLINT
701  EXPECT_EQ(2u, F::ArgumentCount);
702  CompileAssertTypesEqual<int, F::Result>();
705  CompileAssertTypesEqual<std::tuple<bool, const long&>, // NOLINT
706  F::ArgumentTuple>();
707  CompileAssertTypesEqual<
708  std::tuple<Matcher<bool>, Matcher<const long&> >, // NOLINT
709  F::ArgumentMatcherTuple>();
710  CompileAssertTypesEqual<void(bool, const long&), F::MakeResultVoid>(); // NOLINT
711  CompileAssertTypesEqual<IgnoredValue(bool, const long&), // NOLINT
712  F::MakeResultIgnoredValue>();
713 }
714 
715 TEST(FunctionTest, LongArgumentList) {
716  typedef Function<char(bool, int, char*, int&, const long&)> F; // NOLINT
717  EXPECT_EQ(5u, F::ArgumentCount);
718  CompileAssertTypesEqual<char, F::Result>();
724  CompileAssertTypesEqual<
725  std::tuple<bool, int, char*, int&, const long&>, // NOLINT
726  F::ArgumentTuple>();
727  CompileAssertTypesEqual<
728  std::tuple<Matcher<bool>, Matcher<int>, Matcher<char*>, Matcher<int&>,
729  Matcher<const long&> >, // NOLINT
730  F::ArgumentMatcherTuple>();
731  CompileAssertTypesEqual<void(bool, int, char*, int&, const long&), // NOLINT
732  F::MakeResultVoid>();
733  CompileAssertTypesEqual<
734  IgnoredValue(bool, int, char*, int&, const long&), // NOLINT
735  F::MakeResultIgnoredValue>();
736 }
737 
738 } // namespace
739 } // namespace internal
740 } // namespace testing
EXPECT_FALSE
#define EXPECT_FALSE(condition)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1970
testing
Definition: aws_request_signer_test.cc:25
testing::ContainsRegex
PolymorphicMatcher< internal::MatchesRegexMatcher > ContainsRegex(const internal::RE *regex)
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:8835
bloat_diff.severity
def severity
Definition: bloat_diff.py:143
testing::gmock_generated_actions_test::Nullary
int Nullary()
Definition: bloaty/third_party/googletest/googlemock/test/gmock-generated-actions_test.cc:66
Bool
Definition: bloaty/third_party/googletest/googletest/test/gtest_pred_impl_unittest.cc:56
testing::internal::kErrorVerbosity
const char kErrorVerbosity[]
Definition: bloaty/third_party/googletest/googlemock/include/gmock/internal/gmock-internal-utils.h:306
EXPECT_THAT
#define EXPECT_THAT(value, matcher)
testing::internal::GetCapturedStdout
GTEST_API_ std::string GetCapturedStdout()
Definition: gmock-gtest-all.cc:9596
testing::internal::Log
GTEST_API_ void Log(LogSeverity severity, const std::string &message, int stack_frames_to_skip)
Definition: bloaty/third_party/googletest/googlemock/src/gmock-internal-utils.cc:149
std::tr1::make_tuple
tuple make_tuple()
Definition: cares/cares/test/gmock-1.8.0/gtest/gtest.h:1619
server.logger
logger
Definition: examples/python/xds/server.py:35
testing::internal::GetUnitTestImpl
UnitTestImpl * GetUnitTestImpl()
Definition: gmock-gtest-all.cc:1334
matchers
XdsRouteConfigResource::Route::Matchers matchers
Definition: xds_server_config_fetcher.cc:317
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
grpc::protobuf::Message
GRPC_CUSTOM_MESSAGE Message
Definition: include/grpcpp/impl/codegen/config_protobuf.h:78
testing::internal::UInt64
TypeWithSize< 8 >::UInt UInt64
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:2162
testing::gmock_more_actions_test::Unary
bool Unary(int x)
Definition: bloaty/third_party/googletest/googlemock/test/gmock-more-actions_test.cc:85
testing::internal::ConvertIdentifierNameToWords
GTEST_API_ std::string ConvertIdentifierNameToWords(const char *id_name)
Definition: bloaty/third_party/googletest/googlemock/src/gmock-internal-utils.cc:72
testing::internal::OsStackTraceGetterInterface
Definition: gmock-gtest-all.cc:825
testing::Ge
internal::GeMatcher< Rhs > Ge(Rhs x)
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:8585
xds_manager.p
p
Definition: xds_manager.py:60
testing::internal::StlContainerView::Copy
static type Copy(const RawContainer &container)
Definition: bloaty/third_party/googletest/googlemock/include/gmock/internal/gmock-internal-utils.h:396
testing::internal::CaptureStdout
GTEST_API_ void CaptureStdout()
Definition: gmock-gtest-all.cc:9586
MOCK_METHOD0
#define MOCK_METHOD0(m,...)
Definition: bloaty/third_party/googletest/googlemock/include/gmock/gmock-generated-function-mockers.h:599
testing::internal::kWarning
@ kWarning
Definition: bloaty/third_party/googletest/googlemock/include/gmock/internal/gmock-internal-utils.h:296
testing::Message
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest-message.h:90
testing::Test
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:402
EXPECT_EQ
#define EXPECT_EQ(a, b)
Definition: iomgr/time_averaged_stats_test.cc:27
testing::internal::kInfoVerbosity
const char kInfoVerbosity[]
Definition: bloaty/third_party/googletest/googlemock/include/gmock/internal/gmock-internal-utils.h:302
ssize_t
intptr_t ssize_t
Definition: win.h:27
a2
T::first_type a2
Definition: abseil-cpp/absl/container/internal/hash_function_defaults_test.cc:307
xds_interop_client.int
int
Definition: xds_interop_client.py:113
gen_stats_data.c_str
def c_str(s, encoding='ascii')
Definition: gen_stats_data.py:38
MOCK_METHOD1
#define MOCK_METHOD1(m,...)
Definition: bloaty/third_party/googletest/googlemock/include/gmock/gmock-generated-function-mockers.h:600
testing::internal::TupleMatches
bool TupleMatches(const MatcherTuple &matcher_tuple, const ValueTuple &value_tuple)
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:5615
testing::Eq
internal::EqMatcher< T > Eq(T x)
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:8561
GMOCK_FLAG
#define GMOCK_FLAG(name)
Definition: bloaty/third_party/googletest/googlemock/include/gmock/internal/gmock-port.h:66
original_verbose_
std::string original_verbose_
Definition: bloaty/third_party/googletest/googlemock/test/gmock-internal-utils_test.cc:379
testing::internal::kFloatingPoint
@ kFloatingPoint
Definition: bloaty/third_party/googletest/googlemock/include/gmock/internal/gmock-internal-utils.h:115
testing::internal::kWarningVerbosity
const char kWarningVerbosity[]
Definition: bloaty/third_party/googletest/googlemock/include/gmock/internal/gmock-internal-utils.h:304
benchmark::internal::Function
void() Function(State &)
Definition: benchmark/include/benchmark/benchmark.h:826
a1
T::first_type a1
Definition: abseil-cpp/absl/container/internal/hash_function_defaults_test.cc:305
testing::internal::remove_reference::type
T type
Definition: bloaty/third_party/googletest/googlemock/include/gmock/internal/gmock-internal-utils.h:340
log
Definition: bloaty/third_party/zlib/examples/gzlog.c:289
testing::internal::TEST_F
TEST_F(ListenerTest, DoesFoo)
Definition: bloaty/third_party/googletest/googletest/test/googletest-listener-test.cc:226
proto2
Definition: bloaty/third_party/googletest/googlemock/test/gmock-internal-utils_test.cc:64
F
#define F(b, c, d)
Definition: md4.c:112
n
int n
Definition: abseil-cpp/absl/container/btree_test.cc:1080
EXPECT_DEATH_IF_SUPPORTED
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest-death-test.h:335
testing::internal::LogSeverity
LogSeverity
Definition: bloaty/third_party/googletest/googlemock/include/gmock/internal/gmock-internal-utils.h:294
EXPECT_CALL
#define EXPECT_CALL(obj, call)
ON_CALL
#define ON_CALL(obj, call)
value
const char * value
Definition: hpack_parser_table.cc:165
EXPECT_STREQ
#define EXPECT_STREQ(s1, s2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2095
verbose
bool verbose
Definition: bloaty/third_party/protobuf/conformance/conformance_cpp.cc:70
testing::internal::kBool
@ kBool
Definition: bloaty/third_party/googletest/googlemock/include/gmock/internal/gmock-internal-utils.h:115
testing::StaticAssertTypeEq
bool StaticAssertTypeEq()
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2300
testing::internal::kInteger
@ kInteger
Definition: bloaty/third_party/googletest/googlemock/include/gmock/internal/gmock-internal-utils.h:115
GMOCK_KIND_OF_
#define GMOCK_KIND_OF_(type)
Definition: bloaty/third_party/googletest/googlemock/include/gmock/internal/gmock-internal-utils.h:156
GTEST_FLAG
#define GTEST_FLAG(name)
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:2169
testing::internal::JoinAsTuple
GTEST_API_ std::string JoinAsTuple(const Strings &fields)
Definition: bloaty/third_party/googletest/googlemock/src/gmock-internal-utils.cc:51
testing::internal::GetRawPointer
const Pointer::element_type * GetRawPointer(const Pointer &p)
Definition: bloaty/third_party/googletest/googlemock/include/gmock/internal/gmock-internal-utils.h:92
testing::_
const internal::AnythingMatcher _
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:8548
GetString
static bool GetString(std::string *out, CBS *cbs)
Definition: ssl_ctx_api.cc:228
testing::internal::StlContainerView::ConstReference
static const_reference ConstReference(const RawContainer &container)
Definition: bloaty/third_party/googletest/googlemock/include/gmock/internal/gmock-internal-utils.h:390
testing::internal::Assert
void Assert(bool condition, const char *file, int line)
Definition: bloaty/third_party/googletest/googlemock/include/gmock/internal/gmock-internal-utils.h:276
GTEST_INTENTIONAL_CONST_COND_POP_
#define GTEST_INTENTIONAL_CONST_COND_POP_()
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:708
testing::internal::kInfo
@ kInfo
Definition: bloaty/third_party/googletest/googlemock/include/gmock/internal/gmock-internal-utils.h:295
testing::internal::LosslessArithmeticConvertible
LosslessArithmeticConvertibleImpl< GMOCK_KIND_OF_(From), From, GMOCK_KIND_OF_(To), To > LosslessArithmeticConvertible
Definition: googletest/googlemock/include/gmock/internal/gmock-internal-utils.h:200
testing::Le
internal::LeMatcher< Rhs > Le(Rhs x)
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:8597
profile_analyzer.fields
list fields
Definition: profile_analyzer.py:266
Copy
@ Copy
Definition: upb/benchmarks/benchmark.cc:200
values
std::array< int64_t, Size > values
Definition: abseil-cpp/absl/container/btree_benchmark.cc:608
testing::internal::UnitTestImpl::set_os_stack_trace_getter
void set_os_stack_trace_getter(OsStackTraceGetterInterface *getter)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:5627
absl::ABSL_NAMESPACE_BEGIN::dummy
int dummy
Definition: function_type_benchmark.cc:28
testing::internal::TEST
TEST(IsXDigitTest, WorksForNarrowAscii)
Definition: bloaty/third_party/googletest/googletest/test/googletest-port-test.cc:54
testing::internal::Strings
::std::vector< ::std::string > Strings
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest-printers.h:872
EXPECT_TRUE
#define EXPECT_TRUE(condition)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1967
GTEST_INTENTIONAL_CONST_COND_PUSH_
#define GTEST_INTENTIONAL_CONST_COND_PUSH_()
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:706
testing::internal::LogIsVisible
GTEST_API_ bool LogIsVisible(LogSeverity severity)
Definition: bloaty/third_party/googletest/googlemock/src/gmock-internal-utils.cc:128
testing::AllOf
internal::AllOfResult2< M1, M2 >::type AllOf(M1 m1, M2 m2)
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:13472
internal
Definition: benchmark/test/output_test_helper.cc:20
testing::internal::Int64
TypeWithSize< 8 >::Int Int64
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:2161
testing::gmock_generated_actions_test::Binary
const char * Binary(const char *input, short n)
Definition: bloaty/third_party/googletest/googlemock/test/gmock-generated-actions_test.cc:79
asyncio_get_stats.type
type
Definition: asyncio_get_stats.py:37
EXPECT_NONFATAL_FAILURE
#define EXPECT_NONFATAL_FAILURE(statement, substr)
absl::inlined_vector_internal::ConstReference
const ValueType< A > & ConstReference
Definition: abseil-cpp/absl/container/internal/inlined_vector.h:62
const_reference
const typedef T & const_reference
Definition: cxa_demangle.cpp:4831
testing::HasSubstr
PolymorphicMatcher< internal::HasSubstrMatcher< internal::string > > HasSubstr(const internal::string &substring)
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:8803
_auth_example_test.verbosity
verbosity
Definition: _auth_example_test.py:69
if
if(p->owned &&p->wrapped !=NULL)
Definition: call.c:42
testing::internal::Expect
void Expect(bool condition, const char *file, int line, const std::string &msg)
Definition: bloaty/third_party/googletest/googlemock/include/gmock/internal/gmock-internal-utils.h:282
testing::internal::kOther
@ kOther
Definition: bloaty/third_party/googletest/googlemock/include/gmock/internal/gmock-internal-utils.h:115
Message
Definition: protobuf/php/ext/google/protobuf/message.c:53
ASSERT_EQ
#define ASSERT_EQ(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2056
testing::internal::StlContainerView::const_reference
const typedef type & const_reference
Definition: bloaty/third_party/googletest/googlemock/include/gmock/internal/gmock-internal-utils.h:388
testing::internal::StlContainerView::type
RawContainer type
Definition: bloaty/third_party/googletest/googlemock/include/gmock/internal/gmock-internal-utils.h:387


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