gmock-generated-internal-utils_test.cc 5.3 KB

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