You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

358 lines
15 KiB

  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 09/24/2010 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. #ifndef GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
  34. #define GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
  35. // Makes sure this header is not included before gtest.h.
  36. #ifndef GTEST_INCLUDE_GTEST_GTEST_H_
  37. # error Do not include gtest_pred_impl.h directly. Include gtest.h instead.
  38. #endif // GTEST_INCLUDE_GTEST_GTEST_H_
  39. // This header implements a family of generic predicate assertion
  40. // macros:
  41. //
  42. // ASSERT_PRED_FORMAT1(pred_format, v1)
  43. // ASSERT_PRED_FORMAT2(pred_format, v1, v2)
  44. // ...
  45. //
  46. // where pred_format is a function or functor that takes n (in the
  47. // case of ASSERT_PRED_FORMATn) values and their source expression
  48. // text, and returns a testing::AssertionResult. See the definition
  49. // of ASSERT_EQ in gtest.h for an example.
  50. //
  51. // If you don't care about formatting, you can use the more
  52. // restrictive version:
  53. //
  54. // ASSERT_PRED1(pred, v1)
  55. // ASSERT_PRED2(pred, v1, v2)
  56. // ...
  57. //
  58. // where pred is an n-ary function or functor that returns bool,
  59. // and the values v1, v2, ..., must support the << operator for
  60. // streaming to std::ostream.
  61. //
  62. // We also define the EXPECT_* variations.
  63. //
  64. // For now we only support predicates whose arity is at most 5.
  65. // Please email googletestframework@googlegroups.com if you need
  66. // support for higher arities.
  67. // GTEST_ASSERT_ is the basic statement to which all of the assertions
  68. // in this file reduce. Don't use this in your code.
  69. #define GTEST_ASSERT_(expression, on_failure) \
  70. GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
  71. if (const ::testing::AssertionResult gtest_ar = (expression)) \
  72. ; \
  73. else \
  74. on_failure(gtest_ar.failure_message())
  75. // Helper function for implementing {EXPECT|ASSERT}_PRED1. Don't use
  76. // this in your code.
  77. template <typename Pred,
  78. typename T1>
  79. AssertionResult AssertPred1Helper(const char* pred_text,
  80. const char* e1,
  81. Pred pred,
  82. const T1& v1) {
  83. if (pred(v1)) return AssertionSuccess();
  84. return AssertionFailure() << pred_text << "("
  85. << e1 << ") evaluates to false, where"
  86. << "\n" << e1 << " evaluates to " << 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() << pred_text << "("
  122. << e1 << ", "
  123. << e2 << ") evaluates to false, where"
  124. << "\n" << e1 << " evaluates to " << v1
  125. << "\n" << e2 << " evaluates to " << v2;
  126. }
  127. // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT2.
  128. // Don't use this in your code.
  129. #define GTEST_PRED_FORMAT2_(pred_format, v1, v2, on_failure)\
  130. GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2),\
  131. on_failure)
  132. // Internal macro for implementing {EXPECT|ASSERT}_PRED2. Don't use
  133. // this in your code.
  134. #define GTEST_PRED2_(pred, v1, v2, on_failure)\
  135. GTEST_ASSERT_(::testing::AssertPred2Helper(#pred, \
  136. #v1, \
  137. #v2, \
  138. pred, \
  139. v1, \
  140. v2), on_failure)
  141. // Binary predicate assertion macros.
  142. #define EXPECT_PRED_FORMAT2(pred_format, v1, v2) \
  143. GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_NONFATAL_FAILURE_)
  144. #define EXPECT_PRED2(pred, v1, v2) \
  145. GTEST_PRED2_(pred, v1, v2, GTEST_NONFATAL_FAILURE_)
  146. #define ASSERT_PRED_FORMAT2(pred_format, v1, v2) \
  147. GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_FATAL_FAILURE_)
  148. #define ASSERT_PRED2(pred, v1, v2) \
  149. GTEST_PRED2_(pred, v1, v2, GTEST_FATAL_FAILURE_)
  150. // Helper function for implementing {EXPECT|ASSERT}_PRED3. Don't use
  151. // this in your code.
  152. template <typename Pred,
  153. typename T1,
  154. typename T2,
  155. typename T3>
  156. AssertionResult AssertPred3Helper(const char* pred_text,
  157. const char* e1,
  158. const char* e2,
  159. const char* e3,
  160. Pred pred,
  161. const T1& v1,
  162. const T2& v2,
  163. const T3& v3) {
  164. if (pred(v1, v2, v3)) return AssertionSuccess();
  165. return AssertionFailure() << pred_text << "("
  166. << e1 << ", "
  167. << e2 << ", "
  168. << e3 << ") evaluates to false, where"
  169. << "\n" << e1 << " evaluates to " << v1
  170. << "\n" << e2 << " evaluates to " << v2
  171. << "\n" << e3 << " evaluates to " << v3;
  172. }
  173. // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT3.
  174. // Don't use this in your code.
  175. #define GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, on_failure)\
  176. GTEST_ASSERT_(pred_format(#v1, #v2, #v3, v1, v2, v3),\
  177. on_failure)
  178. // Internal macro for implementing {EXPECT|ASSERT}_PRED3. Don't use
  179. // this in your code.
  180. #define GTEST_PRED3_(pred, v1, v2, v3, on_failure)\
  181. GTEST_ASSERT_(::testing::AssertPred3Helper(#pred, \
  182. #v1, \
  183. #v2, \
  184. #v3, \
  185. pred, \
  186. v1, \
  187. v2, \
  188. v3), on_failure)
  189. // Ternary predicate assertion macros.
  190. #define EXPECT_PRED_FORMAT3(pred_format, v1, v2, v3) \
  191. GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, GTEST_NONFATAL_FAILURE_)
  192. #define EXPECT_PRED3(pred, v1, v2, v3) \
  193. GTEST_PRED3_(pred, v1, v2, v3, GTEST_NONFATAL_FAILURE_)
  194. #define ASSERT_PRED_FORMAT3(pred_format, v1, v2, v3) \
  195. GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, GTEST_FATAL_FAILURE_)
  196. #define ASSERT_PRED3(pred, v1, v2, v3) \
  197. GTEST_PRED3_(pred, v1, v2, v3, GTEST_FATAL_FAILURE_)
  198. // Helper function for implementing {EXPECT|ASSERT}_PRED4. Don't use
  199. // this in your code.
  200. template <typename Pred,
  201. typename T1,
  202. typename T2,
  203. typename T3,
  204. typename T4>
  205. AssertionResult AssertPred4Helper(const char* pred_text,
  206. const char* e1,
  207. const char* e2,
  208. const char* e3,
  209. const char* e4,
  210. Pred pred,
  211. const T1& v1,
  212. const T2& v2,
  213. const T3& v3,
  214. const T4& v4) {
  215. if (pred(v1, v2, v3, v4)) return AssertionSuccess();
  216. return AssertionFailure() << pred_text << "("
  217. << e1 << ", "
  218. << e2 << ", "
  219. << e3 << ", "
  220. << e4 << ") evaluates to false, where"
  221. << "\n" << e1 << " evaluates to " << v1
  222. << "\n" << e2 << " evaluates to " << v2
  223. << "\n" << e3 << " evaluates to " << v3
  224. << "\n" << e4 << " evaluates to " << 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() << pred_text << "("
  275. << e1 << ", "
  276. << e2 << ", "
  277. << e3 << ", "
  278. << e4 << ", "
  279. << e5 << ") evaluates to false, where"
  280. << "\n" << e1 << " evaluates to " << v1
  281. << "\n" << e2 << " evaluates to " << v2
  282. << "\n" << e3 << " evaluates to " << v3
  283. << "\n" << e4 << " evaluates to " << v4
  284. << "\n" << e5 << " evaluates to " << v5;
  285. }
  286. // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT5.
  287. // Don't use this in your code.
  288. #define GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, on_failure)\
  289. GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, #v5, v1, v2, v3, v4, v5),\
  290. on_failure)
  291. // Internal macro for implementing {EXPECT|ASSERT}_PRED5. Don't use
  292. // this in your code.
  293. #define GTEST_PRED5_(pred, v1, v2, v3, v4, v5, on_failure)\
  294. GTEST_ASSERT_(::testing::AssertPred5Helper(#pred, \
  295. #v1, \
  296. #v2, \
  297. #v3, \
  298. #v4, \
  299. #v5, \
  300. pred, \
  301. v1, \
  302. v2, \
  303. v3, \
  304. v4, \
  305. v5), on_failure)
  306. // 5-ary predicate assertion macros.
  307. #define EXPECT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5) \
  308. GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, GTEST_NONFATAL_FAILURE_)
  309. #define EXPECT_PRED5(pred, v1, v2, v3, v4, v5) \
  310. GTEST_PRED5_(pred, v1, v2, v3, v4, v5, GTEST_NONFATAL_FAILURE_)
  311. #define ASSERT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5) \
  312. GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, GTEST_FATAL_FAILURE_)
  313. #define ASSERT_PRED5(pred, v1, v2, v3, v4, v5) \
  314. GTEST_PRED5_(pred, v1, v2, v3, v4, v5, GTEST_FATAL_FAILURE_)
  315. #endif // GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_