gucoordinates
GUWrapperTests.hpp
Go to the documentation of this file.
1/*
2 * GUWrapperTests.hpp
3 * tests
4 *
5 * Created by Callum McColl on 24/06/2020.
6 * Copyright © 2020 Callum McColl. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer in the documentation and/or other materials
18 * provided with the distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgement:
22 *
23 * This product includes software developed by Callum McColl.
24 *
25 * 4. Neither the name of the author nor the names of contributors
26 * may be used to endorse or promote products derived from this
27 * software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
33 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
34 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
35 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
36 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
37 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
38 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
39 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * -----------------------------------------------------------------------
42 * This program is free software; you can redistribute it and/or
43 * modify it under the above terms or under the terms of the GNU
44 * General Public License as published by the Free Software Foundation;
45 * either version 2 of the License, or (at your option) any later version.
46 *
47 * This program is distributed in the hope that it will be useful,
48 * but WITHOUT ANY WARRANTY; without even the implied warranty of
49 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
50 * GNU General Public License for more details.
51 *
52 * You should have received a copy of the GNU General Public License
53 * along with this program; if not, see http://www.gnu.org/licenses/
54 * or write to the Free Software Foundation, Inc., 51 Franklin Street,
55 * Fifth Floor, Boston, MA 02110-1301, USA.
56 *
57 */
58
59#ifndef GUWRAPPERTESTS_HPP
60#define GUWRAPPERTESTS_HPP
61
63
64#define C_CONVERTIBLE_TEST_F(className) \
65 TEST2_F(testclassname(className), ConvertibleToC) { \
66 c_convertible_test(); \
67 }
68
69#define EQUALS_TEST_F(className, strctName) \
70 TEST2_F(testclassname(className), Equality) { \
71 equals_fake(strctName).return_val = true; \
72 const GU::className obj = initial(); \
73 const GU::className obj2 = empty(); \
74 ASSERT_EQ(obj, obj); \
75 ASSERT_EQ(equals_fake(strctName).call_count, 1); \
76 equals_reset(strctName) \
77 equals_fake(strctName).return_val = false; \
78 ASSERT_NE(obj, obj2); \
79 ASSERT_EQ(equals_fake(strctName).call_count, 1); \
80 equals_reset(strctName) \
81 equals_fake(strctName).return_val = true; \
82 const GU::className obj3 = initial(); \
83 const strctName obj4 = cempty(); \
84 const strctName obj5 = obj; \
85 ASSERT_EQ(obj3, obj5); \
86 ASSERT_EQ(equals_fake(strctName).call_count, 1); \
87 equals_reset(strctName) \
88 equals_fake(strctName).return_val = false; \
89 ASSERT_TRUE(obj3 != obj4); \
90 ASSERT_EQ(equals_fake(strctName).call_count, 1); \
91 }
92
93#define TO_C_TEST_F(className, strctName) \
94 TEST2_F(testclassname(className), TO_C) { \
95 const GU::className obj = initial(); \
96 const strctName converted = obj; \
97 equals(obj, converted); \
98 }
99
100#define WRAPPER_TEST_Fs(className, strctName) \
101 RO5_TEST_Fs(className) \
102 C_CONVERTIBLE_TEST_F(className) \
103 EQUALS_TEST_F(className, strctName) \
104 TO_C_TEST_F(className, strctName)
105
106#define GETTER_TEST_NAME_F(className, testName, resultType, call, get) \
107 TEST2_F(testclassname(className), testName) {\
108 const GU::resultType result = GU::resultType(call##_result); \
109 call##_fake.return_val = result; \
110 equals(initial().get, result); \
111 ASSERT_EQ(call##_fake.call_count, 1); \
112 call##_reset(); \
113 }
114
115#define GETTER_TEST_F(className, resultType, call, get) \
116 GETTER_TEST_NAME_F(className, resultType, resultType, call, get)
117
118#define GETTER_IM_TEST_NAME_F(className, testName, resultType, call, imType, imCall, get) \
119 TEST2_F(testclassname(className), testName) {\
120 const GU::imType imResult = GU::imType(imCall##_result); \
121 imCall##_fake.return_val = imResult; \
122 const GU::resultType result = GU::resultType(call##_result); \
123 call##_fake.return_val = result; \
124 equals(initial().get, result); \
125 ASSERT_EQ(call##_fake.call_count, 1); \
126 call##_reset(); \
127 imCall##_reset(); \
128 }
129
130#define GETTER_IM_TEST_F(className, resultType, call, imType, imCall, get) \
131 GETTER_IM_TEST_NAME_F(className, resultType, resultType, call, imType, imCall, get)
132
133#define GETTER_BOOL_TEST_NAME_F(className, testName, resultType, call, get) \
134 TEST2_F(testclassname(className), testName) {\
135 call##_fake.custom_fake = call##_custom_fake_true; \
136 const GU::Optional##resultType result = GU::Optional##resultType(true, call##_custom_fake_result); \
137 const GU::Optional##resultType temp = initial().get; \
138 ASSERT_TRUE(temp.has_value()); \
139 equals(temp.value(), result.value()); \
140 ASSERT_EQ(call##_fake.call_count, 1); \
141 call##_reset(); \
142 call##_fake.custom_fake = call##_custom_fake_false; \
143 const GU::Optional##resultType temp2 = initial().get; \
144 ASSERT_FALSE(temp2.has_value()); \
145 ASSERT_EQ(call##_fake.call_count, 1); \
146 call##_reset(); \
147 }
148
149#define GETTER_BOOL_TEST_F(className, resultType, call, get) \
150 GETTER_BOOL_TEST_NAME_F(className, resultType##Bool, resultType, call, get)
151
152#define GETTER_BOOL_IM_TEST_NAME_F(className, testName, resultType, failCall, resultCall, get) \
153 TEST2_F(testclassname(className), testName) {\
154 failCall##_fake.custom_fake = failCall##_custom_fake_true; \
155 resultCall##_fake.return_val = resultCall##_result; \
156 const GU::Optional##resultType result = GU::Optional##resultType(true, resultCall##_result); \
157 const GU::Optional##resultType temp = initial().get; \
158 ASSERT_TRUE(temp.has_value()); \
159 equals(temp.value(), result.value()); \
160 ASSERT_EQ(failCall##_fake.call_count, 1); \
161 ASSERT_EQ(resultCall##_fake.call_count, 1); \
162 failCall##_reset(); \
163 resultCall##_reset(); \
164 failCall##_fake.custom_fake = failCall##_custom_fake_false; \
165 const GU::Optional##resultType temp2 = initial().get; \
166 ASSERT_FALSE(temp2.has_value()); \
167 ASSERT_EQ(failCall##_fake.call_count, 1); \
168 ASSERT_EQ(resultCall##_fake.call_count, 1); \
169 failCall##_reset(); \
170 resultCall##_reset(); \
171 }
172
173#define GETTER_BOOL_IM_TEST_F(className, resultType, failCall, resultCall, get) \
174 GETTER_BOOL_IM_TEST_NAME_F(className, resultType##Bool, resultType, failCall, resultCall, get)
175
176#if __cplusplus >= 201703L
177#define GETTER_OPT_TEST_NAME_F(className, testName, resultType, call, get) \
178 TEST2_F(testclassname(className), testName) {\
179 call##_fake.custom_fake = call##_custom_fake_true; \
180 const GU::resultType result = GU::resultType(call##_custom_fake_result); \
181 const std::optional<GU::resultType> out = initial().get; \
182 if (out.has_value()) \
183 { \
184 equals(out.value(), result); \
185 ASSERT_EQ(call##_fake.call_count, 1); \
186 call##_reset(); \
187 } else { \
188 FAIL() << "Result is nullopt from initial().get"; \
189 } \
190 call##_fake.custom_fake = call##_custom_fake_false; \
191 const std::optional<GU::resultType> out2 = initial().get; \
192 ASSERT_FALSE(out2.has_value()); \
193 }
194
195#define GETTER_OPT_TEST_F(className, resultType, call, get) \
196 GETTER_OPT_TEST_NAME_F(className, resultType, resultType, call, get)
197
198#define GETTER_OPT_IM_TEST_NAME_F(className, testName, resultType, failCall, resultCall, get) \
199 TEST2_F(testclassname(className), testName) { \
200 failCall##_fake.custom_fake = failCall##_custom_fake_true; \
201 resultCall##_fake.return_val = resultCall##_result; \
202 const GU::resultType result = GU::resultType(resultCall##_result); \
203 const std::optional<GU::resultType> out = initial().get; \
204 if (out.has_value()) \
205 { \
206 equals(out.value(), result); \
207 ASSERT_EQ(failCall##_fake.call_count, 1); \
208 ASSERT_EQ(resultCall##_fake.call_count, 1); \
209 } else { \
210 FAIL() << "Result is nullopt from initial().get"; \
211 } \
212 failCall##_reset(); \
213 resultCall##_reset(); \
214 failCall##_fake.custom_fake = failCall##_custom_fake_false; \
215 const std::optional<GU::resultType> out2 = initial().get; \
216 ASSERT_FALSE(out2.has_value()); \
217 }
218
219#define GETTER_OPT_IM_TEST_F(className, resultType, failCall, resultCall, get) \
220 GETTER_OPT_IM_TEST_NAME_F(className, resultType, resultType, failCall, resultCall, get)
221#else
222#define GETTER_OPT_TEST_NAME_F(className, testName, resultType, call, get)
223#define GETTER_OPT_TEST_F(className, resultType, call, get)
224#define GETTER_OPT_IM_TEST_NAME_F(className, testName, resultType, failCall, resultCall, get)
225#define GETTER_OPT_IM_TEST_F(className, resultType, failCall, resultCall, get)
226#endif
227
228namespace CGTEST {
229
230 template <typename Class, typename Strct>
232 {
233 protected:
234
235 virtual void cchange(Strct &) = 0;
236
237 virtual Strct cempty() = 0;
238
240 {
241 Strct obj = {};
242 cchange(obj);
243 Class obj2 = obj;
244 Class obj3;
245 obj3 = obj;
246 this->equals(obj, obj2);
247 this->equals(obj, obj3);
248 this->equals(obj2, obj3);
249 Class obj4 = std::move(obj);
250 Strct temp = {};
251 cchange(temp);
252 Class obj5 = Class();
253 obj5 = std::move(temp);
254 this->equals(obj4, obj3);
255 this->equals(obj5, obj3);
256 Strct * obj6 = &obj3;
257 obj3 = *obj6;
258 this->equals(obj3, *obj6);
259 }
260
261 };
262
263}
264
265#endif /* GUWRAPPERTESTS_HPP */
void equals(const GU::CameraCoordinate lhs, const GU::CameraCoordinate rhs)
virtual void cchange(Strct &)=0
virtual Strct cempty()=0