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/2018 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 GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
  35. #define GTEST_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. // GTEST_ASSERT_ is the basic statement to which all of the assertions
  65. // in this file reduce. Don't use this in your code.
  66. #define GTEST_ASSERT_(expression, on_failure) \
  67. GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
  68. if (const ::testing::AssertionResult gtest_ar = (expression)) \
  69. ; \
  70. else \
  71. on_failure(gtest_ar.failure_message())
  72. // Helper function for implementing {EXPECT|ASSERT}_PRED1. Don't use
  73. // this in your code.
  74. template <typename Pred,
  75. typename T1>
  76. AssertionResult AssertPred1Helper(const char* pred_text,
  77. const char* e1,
  78. Pred pred,
  79. const T1& v1) {
  80. if (pred(v1)) return AssertionSuccess();
  81. return AssertionFailure() << pred_text << "("
  82. << e1 << ") evaluates to false, where"
  83. << "\n" << e1 << " evaluates to " << v1;
  84. }
  85. // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT1.
  86. // Don't use this in your code.
  87. #define GTEST_PRED_FORMAT1_(pred_format, v1, on_failure)\
  88. GTEST_ASSERT_(pred_format(#v1, v1), \
  89. on_failure)
  90. // Internal macro for implementing {EXPECT|ASSERT}_PRED1. Don't use
  91. // this in your code.
  92. #define GTEST_PRED1_(pred, v1, on_failure)\
  93. GTEST_ASSERT_(::testing::AssertPred1Helper(#pred, \
  94. #v1, \
  95. pred, \
  96. v1), on_failure)
  97. // Unary predicate assertion macros.
  98. #define EXPECT_PRED_FORMAT1(pred_format, v1) \
  99. GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_NONFATAL_FAILURE_)
  100. #define EXPECT_PRED1(pred, v1) \
  101. GTEST_PRED1_(pred, v1, GTEST_NONFATAL_FAILURE_)
  102. #define ASSERT_PRED_FORMAT1(pred_format, v1) \
  103. GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_FATAL_FAILURE_)
  104. #define ASSERT_PRED1(pred, v1) \
  105. GTEST_PRED1_(pred, v1, GTEST_FATAL_FAILURE_)
  106. // Helper function for implementing {EXPECT|ASSERT}_PRED2. Don't use
  107. // this in your code.
  108. template <typename Pred,
  109. typename T1,
  110. typename T2>
  111. AssertionResult AssertPred2Helper(const char* pred_text,
  112. const char* e1,
  113. const char* e2,
  114. Pred pred,
  115. const T1& v1,
  116. const T2& v2) {
  117. if (pred(v1, v2)) return AssertionSuccess();
  118. return AssertionFailure() << pred_text << "("
  119. << e1 << ", "
  120. << e2 << ") evaluates to false, where"
  121. << "\n" << e1 << " evaluates to " << v1
  122. << "\n" << e2 << " evaluates to " << v2;
  123. }
  124. // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT2.
  125. // Don't use this in your code.
  126. #define GTEST_PRED_FORMAT2_(pred_format, v1, v2, on_failure)\
  127. GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2), \
  128. on_failure)
  129. // Internal macro for implementing {EXPECT|ASSERT}_PRED2. Don't use
  130. // this in your code.
  131. #define GTEST_PRED2_(pred, v1, v2, on_failure)\
  132. GTEST_ASSERT_(::testing::AssertPred2Helper(#pred, \
  133. #v1, \
  134. #v2, \
  135. pred, \
  136. v1, \
  137. v2), on_failure)
  138. // Binary predicate assertion macros.
  139. #define EXPECT_PRED_FORMAT2(pred_format, v1, v2) \
  140. GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_NONFATAL_FAILURE_)
  141. #define EXPECT_PRED2(pred, v1, v2) \
  142. GTEST_PRED2_(pred, v1, v2, GTEST_NONFATAL_FAILURE_)
  143. #define ASSERT_PRED_FORMAT2(pred_format, v1, v2) \
  144. GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_FATAL_FAILURE_)
  145. #define ASSERT_PRED2(pred, v1, v2) \
  146. GTEST_PRED2_(pred, v1, v2, GTEST_FATAL_FAILURE_)
  147. // Helper function for implementing {EXPECT|ASSERT}_PRED3. Don't use
  148. // this in your code.
  149. template <typename Pred,
  150. typename T1,
  151. typename T2,
  152. typename T3>
  153. AssertionResult AssertPred3Helper(const char* pred_text,
  154. const char* e1,
  155. const char* e2,
  156. const char* e3,
  157. Pred pred,
  158. const T1& v1,
  159. const T2& v2,
  160. const T3& v3) {
  161. if (pred(v1, v2, v3)) return AssertionSuccess();
  162. return AssertionFailure() << pred_text << "("
  163. << e1 << ", "
  164. << e2 << ", "
  165. << e3 << ") evaluates to false, where"
  166. << "\n" << e1 << " evaluates to " << v1
  167. << "\n" << e2 << " evaluates to " << v2
  168. << "\n" << e3 << " evaluates to " << v3;
  169. }
  170. // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT3.
  171. // Don't use this in your code.
  172. #define GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, on_failure)\
  173. GTEST_ASSERT_(pred_format(#v1, #v2, #v3, v1, v2, v3), \
  174. on_failure)
  175. // Internal macro for implementing {EXPECT|ASSERT}_PRED3. Don't use
  176. // this in your code.
  177. #define GTEST_PRED3_(pred, v1, v2, v3, on_failure)\
  178. GTEST_ASSERT_(::testing::AssertPred3Helper(#pred, \
  179. #v1, \
  180. #v2, \
  181. #v3, \
  182. pred, \
  183. v1, \
  184. v2, \
  185. v3), on_failure)
  186. // Ternary predicate assertion macros.
  187. #define EXPECT_PRED_FORMAT3(pred_format, v1, v2, v3) \
  188. GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, GTEST_NONFATAL_FAILURE_)
  189. #define EXPECT_PRED3(pred, v1, v2, v3) \
  190. GTEST_PRED3_(pred, v1, v2, v3, GTEST_NONFATAL_FAILURE_)
  191. #define ASSERT_PRED_FORMAT3(pred_format, v1, v2, v3) \
  192. GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, GTEST_FATAL_FAILURE_)
  193. #define ASSERT_PRED3(pred, v1, v2, v3) \
  194. GTEST_PRED3_(pred, v1, v2, v3, GTEST_FATAL_FAILURE_)
  195. // Helper function for implementing {EXPECT|ASSERT}_PRED4. Don't use
  196. // this in your code.
  197. template <typename Pred,
  198. typename T1,
  199. typename T2,
  200. typename T3,
  201. typename T4>
  202. AssertionResult AssertPred4Helper(const char* pred_text,
  203. const char* e1,
  204. const char* e2,
  205. const char* e3,
  206. const char* e4,
  207. Pred pred,
  208. const T1& v1,
  209. const T2& v2,
  210. const T3& v3,
  211. const T4& v4) {
  212. if (pred(v1, v2, v3, v4)) return AssertionSuccess();
  213. return AssertionFailure() << pred_text << "("
  214. << e1 << ", "
  215. << e2 << ", "
  216. << e3 << ", "
  217. << e4 << ") evaluates to false, where"
  218. << "\n" << e1 << " evaluates to " << v1
  219. << "\n" << e2 << " evaluates to " << v2
  220. << "\n" << e3 << " evaluates to " << v3
  221. << "\n" << e4 << " evaluates to " << v4;
  222. }
  223. // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT4.
  224. // Don't use this in your code.
  225. #define GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, on_failure)\
  226. GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, v1, v2, v3, v4), \
  227. on_failure)
  228. // Internal macro for implementing {EXPECT|ASSERT}_PRED4. Don't use
  229. // this in your code.
  230. #define GTEST_PRED4_(pred, v1, v2, v3, v4, on_failure)\
  231. GTEST_ASSERT_(::testing::AssertPred4Helper(#pred, \
  232. #v1, \
  233. #v2, \
  234. #v3, \
  235. #v4, \
  236. pred, \
  237. v1, \
  238. v2, \
  239. v3, \
  240. v4), on_failure)
  241. // 4-ary predicate assertion macros.
  242. #define EXPECT_PRED_FORMAT4(pred_format, v1, v2, v3, v4) \
  243. GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, GTEST_NONFATAL_FAILURE_)
  244. #define EXPECT_PRED4(pred, v1, v2, v3, v4) \
  245. GTEST_PRED4_(pred, v1, v2, v3, v4, GTEST_NONFATAL_FAILURE_)
  246. #define ASSERT_PRED_FORMAT4(pred_format, v1, v2, v3, v4) \
  247. GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, GTEST_FATAL_FAILURE_)
  248. #define ASSERT_PRED4(pred, v1, v2, v3, v4) \
  249. GTEST_PRED4_(pred, v1, v2, v3, v4, GTEST_FATAL_FAILURE_)
  250. // Helper function for implementing {EXPECT|ASSERT}_PRED5. Don't use
  251. // this in your code.
  252. template <typename Pred,
  253. typename T1,
  254. typename T2,
  255. typename T3,
  256. typename T4,
  257. typename T5>
  258. AssertionResult AssertPred5Helper(const char* pred_text,
  259. const char* e1,
  260. const char* e2,
  261. const char* e3,
  262. const char* e4,
  263. const char* e5,
  264. Pred pred,
  265. const T1& v1,
  266. const T2& v2,
  267. const T3& v3,
  268. const T4& v4,
  269. const T5& v5) {
  270. if (pred(v1, v2, v3, v4, v5)) return AssertionSuccess();
  271. return AssertionFailure() << pred_text << "("
  272. << e1 << ", "
  273. << e2 << ", "
  274. << e3 << ", "
  275. << e4 << ", "
  276. << e5 << ") evaluates to false, where"
  277. << "\n" << e1 << " evaluates to " << v1
  278. << "\n" << e2 << " evaluates to " << v2
  279. << "\n" << e3 << " evaluates to " << v3
  280. << "\n" << e4 << " evaluates to " << v4
  281. << "\n" << e5 << " evaluates to " << v5;
  282. }
  283. // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT5.
  284. // Don't use this in your code.
  285. #define GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, on_failure)\
  286. GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, #v5, v1, v2, v3, v4, v5), \
  287. on_failure)
  288. // Internal macro for implementing {EXPECT|ASSERT}_PRED5. Don't use
  289. // this in your code.
  290. #define GTEST_PRED5_(pred, v1, v2, v3, v4, v5, on_failure)\
  291. GTEST_ASSERT_(::testing::AssertPred5Helper(#pred, \
  292. #v1, \
  293. #v2, \
  294. #v3, \
  295. #v4, \
  296. #v5, \
  297. pred, \
  298. v1, \
  299. v2, \
  300. v3, \
  301. v4, \
  302. v5), on_failure)
  303. // 5-ary predicate assertion macros.
  304. #define EXPECT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5) \
  305. GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, GTEST_NONFATAL_FAILURE_)
  306. #define EXPECT_PRED5(pred, v1, v2, v3, v4, v5) \
  307. GTEST_PRED5_(pred, v1, v2, v3, v4, v5, GTEST_NONFATAL_FAILURE_)
  308. #define ASSERT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5) \
  309. GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, GTEST_FATAL_FAILURE_)
  310. #define ASSERT_PRED5(pred, v1, v2, v3, v4, v5) \
  311. GTEST_PRED5_(pred, v1, v2, v3, v4, v5, GTEST_FATAL_FAILURE_)
  312. } // namespace testing
  313. #endif // GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_