/
iutest_switch_cmphelper.hpp
277 lines (247 loc) · 9.2 KB
/
iutest_switch_cmphelper.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
//======================================================================
//-----------------------------------------------------------------------
/**
* @file iutest_switch_cmphelper.hpp
* @brief gtest 用 比較ヘルパー関数 ファイル
*
* @author t.shirayanagi
* @par copyright
* Copyright (C) 2012-2019, Takazumi Shirayanagi\n
* This software is released under the new BSD License,
* see LICENSE
*/
//-----------------------------------------------------------------------
//======================================================================
#ifndef INCG_IRIS_IUTEST_SWITCH_CMPHELPER_HPP_0378DF29_2DE7_4C60_8E12_32FEA8BEAA7C_
#define INCG_IRIS_IUTEST_SWITCH_CMPHELPER_HPP_0378DF29_2DE7_4C60_8E12_32FEA8BEAA7C_
#if !defined(IUTEST_USE_GTEST)
//======================================================================
// define
#else // !defined(IUTEST_USE_GTEST)
namespace testing
{
namespace internal
{
#if GTEST_VER > 0x01080100 || GTEST_LATEST
using ::std::is_pointer;
#endif
#if GTEST_MINORVER < 0x06
template<bool> struct EnableIf;
template<> struct EnableIf<true> { typedef void type; };
#endif
//======================================================================
// class
namespace backward
{
#if defined(GTEST_IS_NULL_LITERAL_)
template<bool lhs_is_null_literal>
class EqHelper : public internal::EqHelper<lhs_is_null_literal> {};
#else
template<bool lhs_is_null_literal>
class EqHelper : public internal::EqHelper {};
#endif
template<bool lhs_is_null_literal>
class NeHelper {
public:
template<typename T1, typename T2>
static AssertionResult Compare(const char* expected_expression,
const char* actual_expression,
const T1& expected,
const T2& actual) {
return CmpHelperNE(expected_expression, actual_expression, expected,
actual);
}
static AssertionResult Compare(const char* expected_expression,
const char* actual_expression,
BiggestInt expected,
BiggestInt actual) {
return CmpHelperNE(expected_expression, actual_expression, expected,
actual);
}
};
template<>
class NeHelper<true> {
public:
template<typename T1, typename T2>
static AssertionResult Compare(
const char* expected_expression,
const char* actual_expression,
const T1& expected,
const T2& actual,
typename EnableIf<!is_pointer<T2>::value>::type* = 0) {
return CmpHelperNE(expected_expression, actual_expression, expected,
actual);
}
template<typename T>
static AssertionResult Compare(
const char* expected_expression,
const char* actual_expression,
Secret* /* expected (NULL) */,
T* actual) {
return CmpHelperNE(expected_expression, actual_expression,
static_cast<T*>(NULL), actual);
}
};
template<bool lhs_is_null_literal>
class AlmostEqHelper : public internal::EqHelper<lhs_is_null_literal>
{
public:
template<typename T1, typename T2>
static AssertionResult Compare(const char* expr1, const char* expr2, const T1& val1, const T2& val2)
{
return EqHelper<false>::Compare(expr1, expr2, val1, (T1)val2);
}
template<typename T>
static AssertionResult Compare(const char* expr1, const char* expr2, const float& val1, const T& val2)
{
return CmpHelperFloatingPointEQ<float>(expr1, expr2, val1, (float)val2);
}
template<typename T>
static AssertionResult Compare(const char* expr1, const char* expr2, const double& val1, const T& val2)
{
return CmpHelperFloatingPointEQ<double>(expr1, expr2, val1, (double)val2);
}
};
template<>
class AlmostEqHelper<true> : public internal::EqHelper<true>
{
};
} // end of namespace backward
//======================================================================
// function
template<typename T1, typename T2>
inline AssertionResult CmpHelperSame(const char* expected_str, const char* actual_str
, const T1& expected, const T2& actual)
{
return ::testing::internal::backward::EqHelper<false>::Compare(expected_str, actual_str, &expected, &actual);
}
template<typename Elem, typename Traits, typename Ax>
inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTREQ(const char* expr1, const char* expr2
, const ::std::basic_string<Elem, Traits, Ax>& val1
, const ::std::basic_string<Elem, Traits, Ax>& val2)
{
return CmpHelperSTREQ(expr1, expr2, val1.c_str(), val2.c_str());
}
template<typename Elem, typename Traits, typename Ax>
inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTREQ(const char* expr1, const char* expr2
, const Elem* val1
, const ::std::basic_string<Elem, Traits, Ax>& val2)
{
return CmpHelperSTREQ(expr1, expr2, val1, val2.c_str());
}
template<typename Elem, typename Traits, typename Ax>
inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTREQ(const char* expr1, const char* expr2
, const ::std::basic_string<Elem, Traits, Ax>& val1
, const Elem* val2)
{
return CmpHelperSTREQ(expr1, expr2, val1.c_str(), val2);
}
template<typename Elem, typename Traits, typename Ax>
inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRNE(const char* expr1, const char* expr2
, const ::std::basic_string<Elem, Traits, Ax>& val1
, const ::std::basic_string<Elem, Traits, Ax>& val2)
{
return CmpHelperSTRNE(expr1, expr2, val1.c_str(), val2.c_str());
}
template<typename Elem, typename Traits, typename Ax>
inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRNE(const char* expr1, const char* expr2
, const Elem* val1
, const ::std::basic_string<Elem, Traits, Ax>& val2)
{
return CmpHelperSTRNE(expr1, expr2, val1, val2.c_str());
}
template<typename Elem, typename Traits, typename Ax>
inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRNE(const char* expr1, const char* expr2
, const ::std::basic_string<Elem, Traits, Ax>& val1
, const Elem* val2)
{
return CmpHelperSTRNE(expr1, expr2, val1.c_str(), val2);
}
inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRCASEEQ(const char* expr1, const char* expr2
, const wchar_t* val1, const wchar_t* val2)
{
if( val1 == NULL || val2 == NULL )
{
if( val1 == val2 )
{
return AssertionSuccess();
}
}
else
{
if( iu_wcsicmp(val1, val2) == 0 )
{
return AssertionSuccess();
}
}
return EqFailure(expr1, expr2
, FormatForComparisonFailureMessage(val1, val2).c_str()
, FormatForComparisonFailureMessage(val2, val1).c_str()
, true);
}
template<typename Elem, typename Traits, typename Ax>
inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRCASEEQ(const char* expr1, const char* expr2
, const ::std::basic_string<Elem, Traits, Ax>& val1
, const ::std::basic_string<Elem, Traits, Ax>& val2)
{
return CmpHelperSTRCASEEQ(expr1, expr2, val1.c_str(), val2.c_str());
}
template<typename Elem, typename Traits, typename Ax>
inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRCASEEQ(const char* expr1, const char* expr2
, const Elem* val1
, const ::std::basic_string<Elem, Traits, Ax>& val2)
{
return CmpHelperSTRCASEEQ(expr1, expr2, val1, val2.c_str());
}
template<typename Elem, typename Traits, typename Ax>
inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRCASEEQ(const char* expr1, const char* expr2
, const ::std::basic_string<Elem, Traits, Ax>& val1
, const Elem* val2)
{
return CmpHelperSTRCASEEQ(expr1, expr2, val1.c_str(), val2);
}
inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRCASENE(const char* expr1, const char* expr2
, const wchar_t* val1, const wchar_t* val2)
{
if( val1 == NULL || val2 == NULL )
{
if( val1 != val2 )
{
return AssertionSuccess();
}
}
else
{
if( iu_wcsicmp(val1, val2) != 0 )
{
return AssertionSuccess();
}
}
return AssertionFailure() << "error: Value of: " << expr1 << " != " << expr2
<< "\n Actual: " << FormatForComparisonFailureMessage(val2, val1) << "\nExpected: " << FormatForComparisonFailureMessage(val1, val2);
}
template<typename Elem, typename Traits, typename Ax>
inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRCASENE(const char* expr1, const char* expr2
, const ::std::basic_string<Elem, Traits, Ax>& val1
, const ::std::basic_string<Elem, Traits, Ax>& val2)
{
return CmpHelperSTRCASENE(expr1, expr2, val1.c_str(), val2.c_str());
}
template<typename Elem, typename Traits, typename Ax>
inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRCASENE(const char* expr1, const char* expr2
, const Elem* val1
, const ::std::basic_string<Elem, Traits, Ax>& val2)
{
return CmpHelperSTRCASENE(expr1, expr2, val1, val2.c_str());
}
template<typename Elem, typename Traits, typename Ax>
inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRCASENE(const char* expr1, const char* expr2
, const ::std::basic_string<Elem, Traits, Ax>& val1
, const Elem* val2)
{
return CmpHelperSTRCASENE(expr1, expr2, val1.c_str(), val2);
}
} // end of namespace internal
} // end of namespace testing
#endif // !defined(IUTEST_USE_GTEST)
#endif // INCG_IRIS_IUTEST_SWITCH_CMPHELPER_HPP_0378DF29_2DE7_4C60_8E12_32FEA8BEAA7C_