nlib
Pred.h
Go to the documentation of this file.
1 
2 /*--------------------------------------------------------------------------------*
3  Project: CrossRoad
4  Copyright (C)Nintendo All rights reserved.
5 
6  These coded instructions, statements, and computer programs contain proprietary
7  information of Nintendo and/or its licensed developers and are protected by
8  national and international copyright laws. They may not be disclosed to third
9  parties or copied or duplicated in any form, in whole or in part, without the
10  prior written consent of Nintendo.
11 
12  The content herein is highly confidential and should be handled accordingly.
13  *--------------------------------------------------------------------------------*/
14 
15 #pragma once
16 #ifndef INCLUDE_NN_NLIB_TESTING_PRED_H_
17 #define INCLUDE_NN_NLIB_TESTING_PRED_H_
18 
19 #include "nn/nlib/testing/NTest.h"
20 
21 NLIB_NAMESPACE_BEGIN
22 namespace testing {
23 
24 template<class Pred, class T1>
25 AssertionResult EvalPred1(const char* pred_text, const char* e1, Pred pred, const T1& v1) {
26  return pred(v1) ? AssertionResult(true)
27  : AssertionResult(false)
28  << pred_text << "(" << e1 << ") evaluates to false, where"
29  << "\n"
30  << e1 << " evaluates to " << v1;
31 }
32 
33 template<class Pred, class T1, class T2>
34 AssertionResult EvalPred2(const char* pred_text, const char* e1, const char* e2, Pred pred,
35  const T1& v1, const T2& v2) {
36  return pred(v1, v2) ? AssertionResult(true)
37  : AssertionResult(false) << pred_text << "(" << e1 << ", " << e2
38  << ") evaluates to false, where"
39  << "\n"
40  << e1 << " evaluates to " << v1 << "\n"
41  << e2 << " evaluates to " << v2;
42 }
43 
44 template<class Pred, class T1, class T2, class T3>
45 AssertionResult EvalPred3(const char* pred_text, const char* e1, const char* e2, const char* e3,
46  Pred pred, const T1& v1, const T2& v2, const T3& v3) {
47  return pred(v1, v2, v3) ? AssertionResult(true)
48  : AssertionResult(false) << pred_text << "(" << e1 << ", " << e2 << ", "
49  << e3 << ") evaluates to false, where"
50  << "\n"
51  << e1 << " evaluates to " << v1 << "\n"
52  << e2 << " evaluates to " << v2 << "\n"
53  << e3 << " evaluates to " << v3;
54 }
55 
56 template<class Pred, class T1, class T2, class T3, class T4>
57 AssertionResult
58 EvalPred4(const char* pred_text, const char* e1, const char* e2, const char* e3, const char* e4,
59  Pred pred, const T1& v1, const T2& v2, const T3& v3, const T4& v4) {
60  return pred(v1, v2, v3, v4) ? AssertionResult(true)
61  : AssertionResult(false)
62  << pred_text << "(" << e1 << ", " << e2 << ", " << e3 << ", "
63  << e4 << ") evaluates to false, where"
64  << "\n"
65  << e1 << " evaluates to " << v1 << "\n"
66  << e2 << " evaluates to " << v2 << "\n"
67  << e3 << " evaluates to " << v3 << "\n"
68  << e4 << " evaluates to " << v4;
69 }
70 
71 template<class Pred, class T1, class T2, class T3, class T4, class T5>
72 AssertionResult EvalPred5(const char* pred_text, const char* e1, const char* e2, const char* e3,
73  const char* e4, const char* e5, Pred pred, const T1& v1, const T2& v2,
74  const T3& v3, const T4& v4, const T5& v5) {
75  return pred(v1, v2, v3, v4, v5) ? AssertionResult(true)
76  : AssertionResult(false) << pred_text << "(" << e1 << ", " << e2
77  << ", " << e3 << ", " << e4 << ", "
78  << e5 << ") evaluates to false, where"
79  << "\n"
80  << e1 << " evaluates to " << v1 << "\n"
81  << e2 << " evaluates to " << v2 << "\n"
82  << e3 << " evaluates to " << v3 << "\n"
83  << e4 << " evaluates to " << v4 << "\n"
84  << e5 << " evaluates to " << v5;
85 }
86 
87 } // namespace testing
88 NLIB_NAMESPACE_END
89 
90 #define NLIB_TESTING_PRED1_(pred, v1, iffail) \
91  switch (0) \
92  case 0: \
93  default: \
94  if (::nlib_ns::testing::AssertionResult ar = \
95  ::nlib_ns::testing::EvalPred1(#pred, #v1, pred, v1)) \
96  ; \
97  else \
98  iffail = ar
99 
100 #define NLIB_TESTING_PRED2_(pred, v1, v2, iffail) \
101  switch (0) \
102  case 0: \
103  default: \
104  if (::nlib_ns::testing::AssertionResult ar = \
105  ::nlib_ns::testing::EvalPred2(#pred, #v1, #v2, pred, v1, v2)) \
106  ; \
107  else \
108  iffail = ar
109 
110 #define NLIB_TESTING_PRED3_(pred, v1, v2, v3, iffail) \
111  switch (0) \
112  case 0: \
113  default: \
114  if (::nlib_ns::testing::AssertionResult ar = \
115  ::nlib_ns::testing::EvalPred3(#pred, #v1, #v2, #v3, pred, v1, v2, v3)) \
116  ; \
117  else \
118  iffail = ar
119 
120 #define NLIB_TESTING_PRED4_(pred, v1, v2, v3, v4, iffail) \
121  switch (0) \
122  case 0: \
123  default: \
124  if (::nlib_ns::testing::AssertionResult ar = \
125  ::nlib_ns::testing::EvalPred4(#pred, #v1, #v2, #v3, #v4, pred, v1, v2, v3, v4)) \
126  ; \
127  else \
128  iffail = ar
129 
130 #define NLIB_TESTING_PRED5_(pred, v1, v2, v3, v4, v5, iffail) \
131  switch (0) \
132  case 0: \
133  default: \
134  if (::nlib_ns::testing::AssertionResult ar = ::nlib_ns::testing::EvalPred5( \
135  #pred, #v1, #v2, #v3, #v4, #v5, pred, v1, v2, v3, v4, v5)) \
136  ; \
137  else \
138  iffail = ar
139 
140 #define NLIB_TESTING_PRED_FORMAT1_(pred_format, v1, iffail) \
141  switch (0) \
142  case 0: \
143  default: \
144  if (::nlib_ns::testing::AssertionResult ar = pred_format(#v1, v1)) \
145  ; \
146  else \
147  iffail = ar
148 
149 #define NLIB_TESTING_PRED_FORMAT2_(pred_format, v1, v2, iffail) \
150  switch (0) \
151  case 0: \
152  default: \
153  if (::nlib_ns::testing::AssertionResult ar = pred_format(#v1, #v2, v1, v2)) \
154  ; \
155  else \
156  iffail = ar
157 
158 #define NLIB_TESTING_PRED_FORMAT3_(pred_format, v1, v2, v3, iffail) \
159  switch (0) \
160  case 0: \
161  default: \
162  if (::nlib_ns::testing::AssertionResult ar = pred_format(#v1, #v2, #v3, v1, v2, v3)) \
163  ; \
164  else \
165  iffail = ar
166 
167 #define NLIB_TESTING_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, iffail) \
168  switch (0) \
169  case 0: \
170  default: \
171  if (::nlib_ns::testing::AssertionResult ar = \
172  pred_format(#v1, #v2, #v3, #v4, v1, v2, v3, v4)) \
173  ; \
174  else \
175  iffail = ar
176 
177 #define NLIB_TESTING_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, iffail) \
178  switch (0) \
179  case 0: \
180  default: \
181  if (::nlib_ns::testing::AssertionResult ar = \
182  pred_format(#v1, #v2, #v3, #v4, #v5, v1, v2, v3, v4, v5)) \
183  ; \
184  else \
185  iffail = ar
186 
187 #define ASSERT_PRED1(pred, v1) NLIB_TESTING_PRED1_(pred, v1, NLIB_TESTING_FATAL_)
188 #define EXPECT_PRED1(pred, v1) NLIB_TESTING_PRED1_(pred, v1, NLIB_TESTING_NONFATAL_)
189 #define ASSERT_PRED_FORMAT1(pred_format, v1) \
190  NLIB_TESTING_PRED_FORMAT1_(pred_format, v1, NLIB_TESTING_FATAL_)
191 #define EXPECT_PRED_FORMAT1(pred_format, v1) \
192  NLIB_TESTING_PRED_FORMAT1_(pred_format, v1, NLIB_TESTING_NONFATAL_)
193 
194 #define ASSERT_PRED2(pred, v1, v2) NLIB_TESTING_PRED2_(pred, v1, v2, NLIB_TESTING_FATAL_)
195 #define EXPECT_PRED2(pred, v1, v2) NLIB_TESTING_PRED2_(pred, v1, v2, NLIB_TESTING_NONFATAL_)
196 #define ASSERT_PRED_FORMAT2(pred_format, v1, v2) \
197  NLIB_TESTING_PRED_FORMAT2_(pred_format, v1, v2, NLIB_TESTING_FATAL_)
198 #define EXPECT_PRED_FORMAT2(pred_format, v1, v2) \
199  NLIB_TESTING_PRED_FORMAT2_(pred_format, v1, v2, NLIB_TESTING_NONFATAL_)
200 
201 #define ASSERT_PRED3(pred, v1, v2, v3) NLIB_TESTING_PRED3_(pred, v1, v2, v3, NLIB_TESTING_FATAL_)
202 #define EXPECT_PRED3(pred, v1, v2, v3) NLIB_TESTING_PRED3_(pred, v1, v2, v3, NLIB_TESTING_NONFATAL_)
203 #define ASSERT_PRED_FORMAT3(pred_format, v1, v2, v3) \
204  NLIB_TESTING_PRED_FORMAT3_(pred_format, v1, v2, v3, NLIB_TESTING_FATAL_)
205 #define EXPECT_PRED_FORMAT3(pred_format, v1, v2, v3) \
206  NLIB_TESTING_PRED_FORMAT3_(pred_format, v1, v2, v3, NLIB_TESTING_NONFATAL_)
207 
208 #define ASSERT_PRED4(pred, v1, v2, v3, v4) \
209  NLIB_TESTING_PRED4_(pred, v1, v2, v3, v4, NLIB_TESTING_FATAL_)
210 #define EXPECT_PRED4(pred, v1, v2, v3, v4) \
211  NLIB_TESTING_PRED4_(pred, v1, v2, v3, v4, NLIB_TESTING_NONFATAL_)
212 #define ASSERT_PRED_FORMAT4(pred_format, v1, v2, v3, v4) \
213  NLIB_TESTING_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, NLIB_TESTING_FATAL_)
214 #define EXPECT_PRED_FORMAT4(pred_format, v1, v2, v3, v4) \
215  NLIB_TESTING_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, NLIB_TESTING_NONFATAL_)
216 
217 #define ASSERT_PRED5(pred, v1, v2, v3, v4, v5) \
218  NLIB_TESTING_PRED5_(pred, v1, v2, v3, v4, v5, NLIB_TESTING_FATAL_)
219 #define EXPECT_PRED5(pred, v1, v2, v3, v4, v5) \
220  NLIB_TESTING_PRED5_(pred, v1, v2, v3, v4, v5, NLIB_TESTING_NONFATAL_)
221 #define ASSERT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5) \
222  NLIB_TESTING_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, NLIB_TESTING_FATAL_)
223 #define EXPECT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5) \
224  NLIB_TESTING_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, NLIB_TESTING_NONFATAL_)
225 
226 #endif // INCLUDE_NN_NLIB_TESTING_PRED_H_
Defines the macro for a basic, simple test.