gtest_pred_impl.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. // Copyright 2006, 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. // This file is AUTOMATICALLY GENERATED on 01/02/2019 by command
  30. // 'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND!
  31. //
  32. // Implements a family of generic predicate assertion macros.
  33. // GOOGLETEST_CM0001 DO NOT DELETE
  34. #ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
  35. #define GOOGLETEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
  36. #include "gtest/gtest.h"
  37. namespace testing {
  38. // This header implements a family of generic predicate assertion
  39. // macros:
  40. //
  41. // ASSERT_PRED_FORMAT1(pred_format, v1)
  42. // ASSERT_PRED_FORMAT2(pred_format, v1, v2)
  43. // ...
  44. //
  45. // where pred_format is a function or functor that takes n (in the
  46. // case of ASSERT_PRED_FORMATn) values and their source expression
  47. // text, and returns a testing::AssertionResult. See the definition
  48. // of ASSERT_EQ in gtest.h for an example.
  49. //
  50. // If you don't care about formatting, you can use the more
  51. // restrictive version:
  52. //
  53. // ASSERT_PRED1(pred, v1)
  54. // ASSERT_PRED2(pred, v1, v2)
  55. // ...
  56. //
  57. // where pred is an n-ary function or functor that returns bool,
  58. // and the values v1, v2, ..., must support the << operator for
  59. // streaming to std::ostream.
  60. //
  61. // We also define the EXPECT_* variations.
  62. //
  63. // For now we only support predicates whose arity is at most 5.
  64. // Please email googletestframework@googlegroups.com if you need
  65. // support for higher arities.
  66. // GTEST_ASSERT_ is the basic statement to which all of the assertions
  67. // in this file reduce. Don't use this in your code.
  68. #define GTEST_ASSERT_(expression, on_failure) \
  69. GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
  70. if (const ::testing::AssertionResult gtest_ar = (expression)) \
  71. ; \
  72. else \
  73. on_failure(gtest_ar.failure_message())
  74. // Helper function for implementing {EXPECT|ASSERT}_PRED1. Don't use
  75. // this in your code.
  76. template <typename Pred,
  77. typename T1>
  78. AssertionResult AssertPred1Helper(const char* pred_text,
  79. const char* e1,
  80. Pred pred,
  81. const T1& v1) {
  82. if (pred(v1)) return AssertionSuccess();
  83. return AssertionFailure()
  84. << pred_text << "(" << e1 << ") evaluates to false, where"
  85. << "\n"
  86. << e1 << " evaluates to " << ::testing::PrintToString(v1);
  87. }
  88. // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT1.
  89. // Don't use this in your code.
  90. #define GTEST_PRED_FORMAT1_(pred_format, v1, on_failure)\
  91. GTEST_ASSERT_(pred_format(#v1, v1), \
  92. on_failure)
  93. // Internal macro for implementing {EXPECT|ASSERT}_PRED1. Don't use
  94. // this in your code.
  95. #define GTEST_PRED1_(pred, v1, on_failure)\
  96. GTEST_ASSERT_(::testing::AssertPred1Helper(#pred, \
  97. #v1, \
  98. pred, \
  99. v1), on_failure)
  100. // Unary predicate assertion macros.
  101. #define EXPECT_PRED_FORMAT1(pred_format, v1) \
  102. GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_NONFATAL_FAILURE_)
  103. #define EXPECT_PRED1(pred, v1) \
  104. GTEST_PRED1_(pred, v1, GTEST_NONFATAL_FAILURE_)
  105. #define ASSERT_PRED_FORMAT1(pred_format, v1) \
  106. GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_FATAL_FAILURE_)
  107. #define ASSERT_PRED1(pred, v1) \
  108. GTEST_PRED1_(pred, v1, GTEST_FATAL_FAILURE_)
  109. // Helper function for implementing {EXPECT|ASSERT}_PRED2. Don't use
  110. // this in your code.
  111. template <typename Pred,
  112. typename T1,
  113. typename T2>
  114. AssertionResult AssertPred2Helper(const char* pred_text,
  115. const char* e1,
  116. const char* e2,
  117. Pred pred,
  118. const T1& v1,
  119. const T2& v2) {
  120. if (pred(v1, v2)) return AssertionSuccess();
  121. return AssertionFailure()
  122. << pred_text << "(" << e1 << ", " << e2
  123. << ") evaluates to false, where"
  124. << "\n"
  125. << e1 << " evaluates to " << ::testing::PrintToString(v1) << "\n"
  126. << e2 << " evaluates to " << ::testing::PrintToString(v2);
  127. }
  128. // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT2.
  129. // Don't use this in your code.
  130. #define GTEST_PRED_FORMAT2_(pred_format, v1, v2, on_failure)\
  131. GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2), \
  132. on_failure)
  133. // Internal macro for implementing {EXPECT|ASSERT}_PRED2. Don't use
  134. // this in your code.
  135. #define GTEST_PRED2_(pred, v1, v2, on_failure)\
  136. GTEST_ASSERT_(::testing::AssertPred2Helper(#pred, \
  137. #v1, \
  138. #v2, \
  139. pred, \
  140. v1, \
  141. v2), on_failure)
  142. // Binary predicate assertion macros.
  143. #define EXPECT_PRED_FORMAT2(pred_format, v1, v2) \
  144. GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_NONFATAL_FAILURE_)
  145. #define EXPECT_PRED2(pred, v1, v2) \
  146. GTEST_PRED2_(pred, v1, v2, GTEST_NONFATAL_FAILURE_)
  147. #define ASSERT_PRED_FORMAT2(pred_format, v1, v2) \
  148. GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_FATAL_FAILURE_)
  149. #define ASSERT_PRED2(pred, v1, v2) \
  150. GTEST_PRED2_(pred, v1, v2, GTEST_FATAL_FAILURE_)
  151. // Helper function for implementing {EXPECT|ASSERT}_PRED3. Don't use
  152. // this in your code.
  153. template <typename Pred,
  154. typename T1,
  155. typename T2,
  156. typename T3>
  157. AssertionResult AssertPred3Helper(const char* pred_text,
  158. const char* e1,
  159. const char* e2,
  160. const char* e3,
  161. Pred pred,
  162. const T1& v1,
  163. const T2& v2,
  164. const T3& v3) {
  165. if (pred(v1, v2, v3)) return AssertionSuccess();
  166. return AssertionFailure()
  167. << pred_text << "(" << e1 << ", " << e2 << ", " << e3
  168. << ") evaluates to false, where"
  169. << "\n"
  170. << e1 << " evaluates to " << ::testing::PrintToString(v1) << "\n"
  171. << e2 << " evaluates to " << ::testing::PrintToString(v2) << "\n"
  172. << e3 << " evaluates to " << ::testing::PrintToString(v3);
  173. }
  174. // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT3.
  175. // Don't use this in your code.
  176. #define GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, on_failure)\
  177. GTEST_ASSERT_(pred_format(#v1, #v2, #v3, v1, v2, v3), \
  178. on_failure)
  179. // Internal macro for implementing {EXPECT|ASSERT}_PRED3. Don't use
  180. // this in your code.
  181. #define GTEST_PRED3_(pred, v1, v2, v3, on_failure)\
  182. GTEST_ASSERT_(::testing::AssertPred3Helper(#pred, \
  183. #v1, \
  184. #v2, \
  185. #v3, \
  186. pred, \
  187. v1, \
  188. v2, \
  189. v3), on_failure)
  190. // Ternary predicate assertion macros.
  191. #define EXPECT_PRED_FORMAT3(pred_format, v1, v2, v3) \
  192. GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, GTEST_NONFATAL_FAILURE_)
  193. #define EXPECT_PRED3(pred, v1, v2, v3) \
  194. GTEST_PRED3_(pred, v1, v2, v3, GTEST_NONFATAL_FAILURE_)
  195. #define ASSERT_PRED_FORMAT3(pred_format, v1, v2, v3) \
  196. GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, GTEST_FATAL_FAILURE_)
  197. #define ASSERT_PRED3(pred, v1, v2, v3) \
  198. GTEST_PRED3_(pred, v1, v2, v3, GTEST_FATAL_FAILURE_)
  199. // Helper function for implementing {EXPECT|ASSERT}_PRED4. Don't use
  200. // this in your code.
  201. template <typename Pred,
  202. typename T1,
  203. typename T2,
  204. typename T3,
  205. typename T4>
  206. AssertionResult AssertPred4Helper(const char* pred_text,
  207. const char* e1,
  208. const char* e2,
  209. const char* e3,
  210. const char* e4,
  211. Pred pred,
  212. const T1& v1,
  213. const T2& v2,
  214. const T3& v3,
  215. const T4& v4) {
  216. if (pred(v1, v2, v3, v4)) return AssertionSuccess();
  217. return AssertionFailure()
  218. << pred_text << "(" << e1 << ", " << e2 << ", " << e3 << ", " << e4
  219. << ") evaluates to false, where"
  220. << "\n"
  221. << e1 << " evaluates to " << ::testing::PrintToString(v1) << "\n"
  222. << e2 << " evaluates to " << ::testing::PrintToString(v2) << "\n"
  223. << e3 << " evaluates to " << ::testing::PrintToString(v3) << "\n"
  224. << e4 << " evaluates to " << ::testing::PrintToString(v4);
  225. }
  226. // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT4.
  227. // Don't use this in your code.
  228. #define GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, on_failure)\
  229. GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, v1, v2, v3, v4), \
  230. on_failure)
  231. // Internal macro for implementing {EXPECT|ASSERT}_PRED4. Don't use
  232. // this in your code.
  233. #define GTEST_PRED4_(pred, v1, v2, v3, v4, on_failure)\
  234. GTEST_ASSERT_(::testing::AssertPred4Helper(#pred, \
  235. #v1, \
  236. #v2, \
  237. #v3, \
  238. #v4, \
  239. pred, \
  240. v1, \
  241. v2, \
  242. v3, \
  243. v4), on_failure)
  244. // 4-ary predicate assertion macros.
  245. #define EXPECT_PRED_FORMAT4(pred_format, v1, v2, v3, v4) \
  246. GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, GTEST_NONFATAL_FAILURE_)
  247. #define EXPECT_PRED4(pred, v1, v2, v3, v4) \
  248. GTEST_PRED4_(pred, v1, v2, v3, v4, GTEST_NONFATAL_FAILURE_)
  249. #define ASSERT_PRED_FORMAT4(pred_format, v1, v2, v3, v4) \
  250. GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, GTEST_FATAL_FAILURE_)
  251. #define ASSERT_PRED4(pred, v1, v2, v3, v4) \
  252. GTEST_PRED4_(pred, v1, v2, v3, v4, GTEST_FATAL_FAILURE_)
  253. // Helper function for implementing {EXPECT|ASSERT}_PRED5. Don't use
  254. // this in your code.
  255. template <typename Pred,
  256. typename T1,
  257. typename T2,
  258. typename T3,
  259. typename T4,
  260. typename T5>
  261. AssertionResult AssertPred5Helper(const char* pred_text,
  262. const char* e1,
  263. const char* e2,
  264. const char* e3,
  265. const char* e4,
  266. const char* e5,
  267. Pred pred,
  268. const T1& v1,
  269. const T2& v2,
  270. const T3& v3,
  271. const T4& v4,
  272. const T5& v5) {
  273. if (pred(v1, v2, v3, v4, v5)) return AssertionSuccess();
  274. return AssertionFailure()
  275. << pred_text << "(" << e1 << ", " << e2 << ", " << e3 << ", " << e4
  276. << ", " << e5 << ") evaluates to false, where"
  277. << "\n"
  278. << e1 << " evaluates to " << ::testing::PrintToString(v1) << "\n"
  279. << e2 << " evaluates to " << ::testing::PrintToString(v2) << "\n"
  280. << e3 << " evaluates to " << ::testing::PrintToString(v3) << "\n"
  281. << e4 << " evaluates to " << ::testing::PrintToString(v4) << "\n"
  282. << e5 << " evaluates to " << ::testing::PrintToString(v5);
  283. }
  284. // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT5.
  285. // Don't use this in your code.
  286. #define GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, on_failure)\
  287. GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, #v5, v1, v2, v3, v4, v5), \
  288. on_failure)
  289. // Internal macro for implementing {EXPECT|ASSERT}_PRED5. Don't use
  290. // this in your code.
  291. #define GTEST_PRED5_(pred, v1, v2, v3, v4, v5, on_failure)\
  292. GTEST_ASSERT_(::testing::AssertPred5Helper(#pred, \
  293. #v1, \
  294. #v2, \
  295. #v3, \
  296. #v4, \
  297. #v5, \
  298. pred, \
  299. v1, \
  300. v2, \
  301. v3, \
  302. v4, \
  303. v5), on_failure)
  304. // 5-ary predicate assertion macros.
  305. #define EXPECT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5) \
  306. GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, GTEST_NONFATAL_FAILURE_)
  307. #define EXPECT_PRED5(pred, v1, v2, v3, v4, v5) \
  308. GTEST_PRED5_(pred, v1, v2, v3, v4, v5, GTEST_NONFATAL_FAILURE_)
  309. #define ASSERT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5) \
  310. GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, GTEST_FATAL_FAILURE_)
  311. #define ASSERT_PRED5(pred, v1, v2, v3, v4, v5) \
  312. GTEST_PRED5_(pred, v1, v2, v3, v4, v5, GTEST_FATAL_FAILURE_)
  313. } // namespace testing
  314. #endif // GOOGLETEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_