gmock-generated-internal-utils_test.cc 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. // Google Mock - a framework for writing C++ mock classes.
  30. //
  31. // This file tests the internal utilities.
  32. #include "gmock/internal/gmock-generated-internal-utils.h"
  33. #include "gmock/internal/gmock-internal-utils.h"
  34. #include "gtest/gtest.h"
  35. namespace {
  36. using ::testing::tuple;
  37. using ::testing::Matcher;
  38. using ::testing::internal::CompileAssertTypesEqual;
  39. using ::testing::internal::MatcherTuple;
  40. using ::testing::internal::Function;
  41. using ::testing::internal::IgnoredValue;
  42. // Tests the MatcherTuple template struct.
  43. TEST(MatcherTupleTest, ForSize0) {
  44. CompileAssertTypesEqual<tuple<>, MatcherTuple<tuple<> >::type>();
  45. }
  46. TEST(MatcherTupleTest, ForSize1) {
  47. CompileAssertTypesEqual<tuple<Matcher<int> >,
  48. MatcherTuple<tuple<int> >::type>();
  49. }
  50. TEST(MatcherTupleTest, ForSize2) {
  51. CompileAssertTypesEqual<tuple<Matcher<int>, Matcher<char> >,
  52. MatcherTuple<tuple<int, char> >::type>();
  53. }
  54. TEST(MatcherTupleTest, ForSize5) {
  55. CompileAssertTypesEqual<
  56. tuple<Matcher<int>, Matcher<char>, Matcher<bool>, Matcher<double>,
  57. Matcher<char*> >,
  58. MatcherTuple<tuple<int, char, bool, double, char*> >::type>();
  59. }
  60. // Tests the Function template struct.
  61. TEST(FunctionTest, Nullary) {
  62. typedef Function<int()> F; // NOLINT
  63. CompileAssertTypesEqual<int, F::Result>();
  64. CompileAssertTypesEqual<tuple<>, F::ArgumentTuple>();
  65. CompileAssertTypesEqual<tuple<>, F::ArgumentMatcherTuple>();
  66. CompileAssertTypesEqual<void(), F::MakeResultVoid>();
  67. CompileAssertTypesEqual<IgnoredValue(), F::MakeResultIgnoredValue>();
  68. }
  69. TEST(FunctionTest, Unary) {
  70. typedef Function<int(bool)> F; // NOLINT
  71. CompileAssertTypesEqual<int, F::Result>();
  72. CompileAssertTypesEqual<bool, F::Argument1>();
  73. CompileAssertTypesEqual<tuple<bool>, F::ArgumentTuple>();
  74. CompileAssertTypesEqual<tuple<Matcher<bool> >, F::ArgumentMatcherTuple>();
  75. CompileAssertTypesEqual<void(bool), F::MakeResultVoid>(); // NOLINT
  76. CompileAssertTypesEqual<IgnoredValue(bool), // NOLINT
  77. F::MakeResultIgnoredValue>();
  78. }
  79. TEST(FunctionTest, Binary) {
  80. typedef Function<int(bool, const long&)> F; // NOLINT
  81. CompileAssertTypesEqual<int, F::Result>();
  82. CompileAssertTypesEqual<bool, F::Argument1>();
  83. CompileAssertTypesEqual<const long&, F::Argument2>(); // NOLINT
  84. CompileAssertTypesEqual<tuple<bool, const long&>, F::ArgumentTuple>(); // NOLINT
  85. CompileAssertTypesEqual<
  86. tuple<Matcher<bool>, Matcher<const long&> >, // NOLINT
  87. F::ArgumentMatcherTuple>();
  88. CompileAssertTypesEqual<void(bool, const long&), F::MakeResultVoid>(); // NOLINT
  89. CompileAssertTypesEqual<IgnoredValue(bool, const long&), // NOLINT
  90. F::MakeResultIgnoredValue>();
  91. }
  92. TEST(FunctionTest, LongArgumentList) {
  93. typedef Function<char(bool, int, char*, int&, const long&)> F; // NOLINT
  94. CompileAssertTypesEqual<char, F::Result>();
  95. CompileAssertTypesEqual<bool, F::Argument1>();
  96. CompileAssertTypesEqual<int, F::Argument2>();
  97. CompileAssertTypesEqual<char*, F::Argument3>();
  98. CompileAssertTypesEqual<int&, F::Argument4>();
  99. CompileAssertTypesEqual<const long&, F::Argument5>(); // NOLINT
  100. CompileAssertTypesEqual<tuple<bool, int, char*, int&, const long&>, // NOLINT
  101. F::ArgumentTuple>();
  102. CompileAssertTypesEqual<
  103. tuple<Matcher<bool>, Matcher<int>, Matcher<char*>, Matcher<int&>,
  104. Matcher<const long&> >, // NOLINT
  105. F::ArgumentMatcherTuple>();
  106. CompileAssertTypesEqual<void(bool, int, char*, int&, const long&), // NOLINT
  107. F::MakeResultVoid>();
  108. CompileAssertTypesEqual<
  109. IgnoredValue(bool, int, char*, int&, const long&), // NOLINT
  110. F::MakeResultIgnoredValue>();
  111. }
  112. } // Unnamed namespace