1 | #include <gtest/gtest.h> |
---|
2 | #include "util/MultiType.h" |
---|
3 | |
---|
4 | namespace orxonox |
---|
5 | { |
---|
6 | // x constructor() |
---|
7 | // x constructor(value) |
---|
8 | // x constructor(other) |
---|
9 | |
---|
10 | // x assignment(value) |
---|
11 | // ? assignment(pointer) |
---|
12 | // x assignment(other) |
---|
13 | |
---|
14 | // x set(value) |
---|
15 | // ? set(pointer) |
---|
16 | // x force<type>(value) |
---|
17 | |
---|
18 | // x convert<type>() |
---|
19 | // x reset |
---|
20 | // x reset<type>() |
---|
21 | // x resetValue |
---|
22 | |
---|
23 | // x isType<type>() |
---|
24 | |
---|
25 | // x (type) conversion |
---|
26 | // ? (pointer class) conversion |
---|
27 | // x getValue(pointer) |
---|
28 | // x get<type>() |
---|
29 | // ? getPointer() |
---|
30 | |
---|
31 | // x lastConversionSuccessful() |
---|
32 | // x null() |
---|
33 | |
---|
34 | ///////////////////////// |
---|
35 | // Default Constructor // |
---|
36 | ///////////////////////// |
---|
37 | TEST(MultiType, DefaultConstructor) |
---|
38 | { |
---|
39 | MultiType mt; |
---|
40 | EXPECT_TRUE(mt.null()); |
---|
41 | EXPECT_TRUE(mt.isType<void>()); |
---|
42 | } |
---|
43 | |
---|
44 | ///////////////// |
---|
45 | // Constructor // |
---|
46 | ///////////////// |
---|
47 | TEST(MultiType, ValueChar) { char value = -100; MultiType mt(value); EXPECT_TRUE(mt.isType<char>()); EXPECT_EQ(-100, mt.get<char>()); } |
---|
48 | TEST(MultiType, ValueUnsignedChar) { unsigned char value = 255u; MultiType mt(value); EXPECT_TRUE(mt.isType<unsigned char>()); EXPECT_EQ(255u, mt.get<unsigned char>()); } |
---|
49 | TEST(MultiType, ValueShort) { short value = -10000; MultiType mt(value); EXPECT_TRUE(mt.isType<short>()); EXPECT_EQ(-10000, mt.get<short>()); } |
---|
50 | TEST(MultiType, ValueUnsignedShort) { unsigned short value = 65535u; MultiType mt(value); EXPECT_TRUE(mt.isType<unsigned short>()); EXPECT_EQ(65535u, mt.get<unsigned short>()); } |
---|
51 | TEST(MultiType, ValueInt) { int value = -1000000000; MultiType mt(value); EXPECT_TRUE(mt.isType<int>()); EXPECT_EQ(-1000000000, mt.get<int>()); } |
---|
52 | TEST(MultiType, ValueUnsignedInt) { unsigned int value = 4000000000u; MultiType mt(value); EXPECT_TRUE(mt.isType<unsigned int>()); EXPECT_EQ(4000000000u, mt.get<unsigned int>()); } |
---|
53 | TEST(MultiType, ValueLong) { long value = -1000000000; MultiType mt(value); EXPECT_TRUE(mt.isType<long>()); EXPECT_EQ(-1000000000, mt.get<long>()); } |
---|
54 | TEST(MultiType, ValueUnsignedLong) { unsigned long value = 4000000000u; MultiType mt(value); EXPECT_TRUE(mt.isType<unsigned long>()); EXPECT_EQ(4000000000u, mt.get<unsigned long>()); } |
---|
55 | TEST(MultiType, ValueLongLong) { long long value = -1000000000000000000L; MultiType mt(value); EXPECT_TRUE(mt.isType<long long>()); EXPECT_EQ(-1000000000000000000L, mt.get<long long>()); } |
---|
56 | TEST(MultiType, ValueUnsignedLongLong) { unsigned long long value = 4000000000000000000UL; MultiType mt(value); EXPECT_TRUE(mt.isType<unsigned long long>()); EXPECT_EQ(4000000000000000000UL, mt.get<unsigned long long>()); } |
---|
57 | TEST(MultiType, ValueFloat) { float value = 0.123456f; MultiType mt(value); EXPECT_TRUE(mt.isType<float>()); EXPECT_EQ(0.123456f, mt.get<float>()); } |
---|
58 | TEST(MultiType, ValueDouble) { double value = 0.123456789; MultiType mt(value); EXPECT_TRUE(mt.isType<double>()); EXPECT_EQ(0.123456789, mt.get<double>()); } |
---|
59 | TEST(MultiType, ValueLongDouble) { long double value = 0.123456789123456789; MultiType mt(value); EXPECT_TRUE(mt.isType<long double>()); EXPECT_EQ(0.123456789123456789, mt.get<long double>()); } |
---|
60 | TEST(MultiType, ValueBool) { bool value = true; MultiType mt(value); EXPECT_TRUE(mt.isType<bool>()); EXPECT_EQ(true, mt.get<bool>()); } |
---|
61 | TEST(MultiType, ValueVoidpointer) { int* pointer = new int; void* value = pointer; MultiType mt(value); EXPECT_TRUE(mt.isType<void*>()); EXPECT_EQ(value, mt.get<void*>()); delete pointer; } |
---|
62 | TEST(MultiType, ValueSomepointer) { int* value = new int; MultiType mt(value); EXPECT_TRUE(mt.isType<void*>()); EXPECT_EQ(value, mt.get<int*>()); delete value; } |
---|
63 | TEST(MultiType, ValueString) { std::string value = "Hello World"; MultiType mt(value); EXPECT_TRUE(mt.isType<std::string>()); EXPECT_EQ("Hello World", mt.get<std::string>()); } |
---|
64 | TEST(MultiType, ValueVector2) { Vector2 value = Vector2(11, 22); MultiType mt(value); EXPECT_TRUE(mt.isType<Vector2>()); EXPECT_EQ(Vector2(11, 22), mt.get<Vector2>()); } |
---|
65 | TEST(MultiType, ValueVector3) { Vector3 value = Vector3(11, 22, 33); MultiType mt(value); EXPECT_TRUE(mt.isType<Vector3>()); EXPECT_EQ(Vector3(11, 22, 33), mt.get<Vector3>()); } |
---|
66 | TEST(MultiType, ValueVector4) { Vector4 value = Vector4(11, 22, 33, 44); MultiType mt(value); EXPECT_TRUE(mt.isType<Vector4>()); EXPECT_EQ(Vector4(11, 22, 33, 44), mt.get<Vector4>()); } |
---|
67 | TEST(MultiType, ValueColourValue) { ColourValue value = ColourValue(11, 22, 33, 44); MultiType mt(value); EXPECT_TRUE(mt.isType<ColourValue>()); EXPECT_EQ(ColourValue(11, 22, 33, 44), mt.get<ColourValue>()); } |
---|
68 | TEST(MultiType, ValueQuaternion) { Quaternion value = Quaternion(11, 22, 33, 44); MultiType mt(value); EXPECT_TRUE(mt.isType<Quaternion>()); EXPECT_EQ(Quaternion(11, 22, 33, 44), mt.get<Quaternion>()); } |
---|
69 | TEST(MultiType, ValueRadian) { Radian value = Radian(0.123); MultiType mt(value); EXPECT_TRUE(mt.isType<Radian>()); EXPECT_EQ(Radian(0.123), mt.get<Radian>()); } |
---|
70 | TEST(MultiType, ValueDegree) { Degree value = Degree(123); MultiType mt(value); EXPECT_TRUE(mt.isType<Degree>()); EXPECT_EQ(Degree(123), mt.get<Degree>()); } |
---|
71 | TEST(MultiType, ValueMbool) { mbool value = mbool(true); MultiType mt(value); EXPECT_TRUE(mt.isType<bool>()); EXPECT_EQ(mbool(true), mt.get<bool>()); } |
---|
72 | TEST(MultiType, ValueCharPointer) { const char* value = "Hello World"; MultiType mt(value); EXPECT_TRUE(mt.isType<std::string>()); EXPECT_EQ("Hello World", mt.get<std::string>()); } |
---|
73 | |
---|
74 | ////////////////////// |
---|
75 | // Copy-Constructor // |
---|
76 | ////////////////////// |
---|
77 | TEST(MultiType, CopyConstructorEmpty) |
---|
78 | { |
---|
79 | MultiType mt1; |
---|
80 | MultiType mt2(mt1); |
---|
81 | |
---|
82 | EXPECT_TRUE(mt2.null()); |
---|
83 | } |
---|
84 | |
---|
85 | TEST(MultiType, CopyConstructorFloat) |
---|
86 | { |
---|
87 | MultiType mt1(0.1234f); |
---|
88 | MultiType mt2(mt1); |
---|
89 | |
---|
90 | EXPECT_TRUE(mt2.isType<float>()); |
---|
91 | EXPECT_EQ(0.1234f, mt2.get<float>()); |
---|
92 | } |
---|
93 | |
---|
94 | ////////////////////// |
---|
95 | // Assignment Value // |
---|
96 | ////////////////////// |
---|
97 | TEST(MultiType, AssignmentIntToEmpty) |
---|
98 | { |
---|
99 | MultiType mt; |
---|
100 | |
---|
101 | EXPECT_TRUE(mt.null()); |
---|
102 | |
---|
103 | mt = 55; |
---|
104 | |
---|
105 | EXPECT_FALSE(mt.null()); |
---|
106 | EXPECT_TRUE(mt.isType<int>()); |
---|
107 | EXPECT_EQ(55, mt.get<int>()); |
---|
108 | } |
---|
109 | |
---|
110 | TEST(MultiType, AssignmentFloatToInt) |
---|
111 | { |
---|
112 | MultiType mt(66); |
---|
113 | |
---|
114 | EXPECT_TRUE(mt.isType<int>()); |
---|
115 | EXPECT_EQ(66, mt.get<int>()); |
---|
116 | |
---|
117 | mt = 77.7f; // will be converted to int |
---|
118 | |
---|
119 | EXPECT_TRUE(mt.isType<int>()); |
---|
120 | EXPECT_EQ(77, mt.get<int>()); |
---|
121 | EXPECT_EQ(77.0f, mt.get<float>()); |
---|
122 | } |
---|
123 | |
---|
124 | TEST(MultiType, AssignmentFloatToFloat) |
---|
125 | { |
---|
126 | MultiType mt(66.6f); |
---|
127 | |
---|
128 | EXPECT_TRUE(mt.isType<float>()); |
---|
129 | EXPECT_EQ(66, mt.get<int>()); |
---|
130 | EXPECT_EQ(66.6f, mt.get<float>()); |
---|
131 | |
---|
132 | mt = 77.7f; |
---|
133 | |
---|
134 | EXPECT_TRUE(mt.isType<float>()); |
---|
135 | EXPECT_EQ(77, mt.get<int>()); |
---|
136 | EXPECT_EQ(77.7f, mt.get<float>()); |
---|
137 | } |
---|
138 | |
---|
139 | TEST(MultiType, AssignmentFloatToVector3) |
---|
140 | { |
---|
141 | MultiType mt(Vector3(1, 2, 3)); |
---|
142 | |
---|
143 | EXPECT_TRUE(mt.isType<Vector3>()); |
---|
144 | EXPECT_EQ(Vector3(1, 2, 3), mt.get<Vector3>()); |
---|
145 | EXPECT_TRUE(mt.lastConversionSuccessful()); |
---|
146 | |
---|
147 | mt = 77.7f; |
---|
148 | |
---|
149 | EXPECT_TRUE(mt.isType<Vector3>()); |
---|
150 | EXPECT_EQ(Vector3::ZERO, mt.get<Vector3>()); |
---|
151 | EXPECT_FALSE(mt.lastConversionSuccessful()); |
---|
152 | } |
---|
153 | |
---|
154 | ////////////////////// |
---|
155 | // Assignment Other // |
---|
156 | ////////////////////// |
---|
157 | TEST(MultiType, AssignmentOther) |
---|
158 | { |
---|
159 | MultiType mt1(33); |
---|
160 | MultiType mt2(44.4f); |
---|
161 | |
---|
162 | EXPECT_TRUE(mt1.isType<int>()); |
---|
163 | EXPECT_TRUE(mt2.isType<float>()); |
---|
164 | |
---|
165 | EXPECT_EQ(33, mt1.get<int>()); |
---|
166 | EXPECT_EQ(33.0f, mt1.get<float>()); |
---|
167 | EXPECT_EQ(44.4f, mt2.get<float>()); |
---|
168 | |
---|
169 | mt1 = mt2; |
---|
170 | |
---|
171 | EXPECT_TRUE(mt1.isType<int>()); |
---|
172 | EXPECT_TRUE(mt2.isType<float>()); |
---|
173 | |
---|
174 | EXPECT_EQ(44, mt1.get<int>()); |
---|
175 | EXPECT_EQ(44.0f, mt1.get<float>()); |
---|
176 | EXPECT_EQ(44.4f, mt2.get<float>()); |
---|
177 | } |
---|
178 | |
---|
179 | //////////////// |
---|
180 | // set(value) // |
---|
181 | //////////////// |
---|
182 | TEST(MultiType, SetValueBoolToEmpty) |
---|
183 | { |
---|
184 | MultiType mt; |
---|
185 | |
---|
186 | mt.set(true); |
---|
187 | |
---|
188 | EXPECT_TRUE(mt.isType<bool>()); |
---|
189 | EXPECT_EQ(true, mt.get<bool>()); |
---|
190 | } |
---|
191 | |
---|
192 | TEST(MultiType, SetValueIntToString) |
---|
193 | { |
---|
194 | MultiType mt("Hello"); |
---|
195 | |
---|
196 | EXPECT_TRUE(mt.isType<std::string>()); |
---|
197 | EXPECT_EQ("Hello", mt.get<std::string>()); |
---|
198 | |
---|
199 | mt.set(1234); |
---|
200 | |
---|
201 | EXPECT_TRUE(mt.isType<std::string>()); |
---|
202 | EXPECT_EQ("1234", mt.get<std::string>()); |
---|
203 | } |
---|
204 | |
---|
205 | ////////////////////// |
---|
206 | // force<type>(value) // |
---|
207 | ////////////////////// |
---|
208 | TEST(MultiType, SetValueWithTypeIntToString) |
---|
209 | { |
---|
210 | MultiType mt("Hello"); |
---|
211 | |
---|
212 | EXPECT_TRUE(mt.isType<std::string>()); |
---|
213 | EXPECT_EQ("Hello", mt.get<std::string>()); |
---|
214 | |
---|
215 | mt.force<int>(1234); |
---|
216 | |
---|
217 | EXPECT_TRUE(mt.isType<int>()); |
---|
218 | EXPECT_EQ(1234, mt.get<int>()); |
---|
219 | } |
---|
220 | |
---|
221 | TEST(MultiType, SetValueWithTypeIntAsStringToString) |
---|
222 | { |
---|
223 | MultiType mt("Hello"); |
---|
224 | |
---|
225 | EXPECT_TRUE(mt.isType<std::string>()); |
---|
226 | EXPECT_EQ("Hello", mt.get<std::string>()); |
---|
227 | |
---|
228 | mt.force<int>("1234"); |
---|
229 | |
---|
230 | EXPECT_TRUE(mt.isType<int>()); |
---|
231 | EXPECT_EQ(1234, mt.get<int>()); |
---|
232 | } |
---|
233 | |
---|
234 | TEST(MultiType, SetValueWithTypeIntToInt) |
---|
235 | { |
---|
236 | MultiType mt(4321); |
---|
237 | |
---|
238 | EXPECT_TRUE(mt.isType<int>()); |
---|
239 | EXPECT_EQ(4321, mt.get<int>()); |
---|
240 | |
---|
241 | mt.force<int>(1234); |
---|
242 | |
---|
243 | EXPECT_TRUE(mt.isType<int>()); |
---|
244 | EXPECT_EQ(1234, mt.get<int>()); |
---|
245 | } |
---|
246 | |
---|
247 | ///////////////////// |
---|
248 | // convert<type>() // |
---|
249 | ///////////////////// |
---|
250 | TEST(MultiType, ConvertEmptyToInt) |
---|
251 | { |
---|
252 | MultiType mt; |
---|
253 | mt.convert<int>(); |
---|
254 | |
---|
255 | EXPECT_TRUE(mt.isType<int>()); |
---|
256 | EXPECT_EQ(0, mt.get<int>()); |
---|
257 | } |
---|
258 | |
---|
259 | TEST(MultiType, ConvertFloatToInt) |
---|
260 | { |
---|
261 | MultiType mt(1.234f); |
---|
262 | |
---|
263 | EXPECT_TRUE(mt.isType<float>()); |
---|
264 | EXPECT_EQ(1.234f, mt.get<float>()); |
---|
265 | EXPECT_EQ(1, mt.get<int>()); |
---|
266 | |
---|
267 | mt.convert<int>(); |
---|
268 | |
---|
269 | EXPECT_TRUE(mt.isType<int>()); |
---|
270 | EXPECT_EQ(1.0f, mt.get<float>()); |
---|
271 | EXPECT_EQ(1, mt.get<int>()); |
---|
272 | } |
---|
273 | |
---|
274 | TEST(MultiType, ConvertFloatToVector3) |
---|
275 | { |
---|
276 | MultiType mt(1.234f); |
---|
277 | |
---|
278 | EXPECT_TRUE(mt.isType<float>()); |
---|
279 | EXPECT_EQ(1.234f, mt.get<float>()); |
---|
280 | EXPECT_EQ(Vector3::ZERO, mt.get<Vector3>()); |
---|
281 | |
---|
282 | mt.convert<Vector3>(); |
---|
283 | |
---|
284 | EXPECT_TRUE(mt.isType<Vector3>()); |
---|
285 | EXPECT_EQ(0.0f, mt.get<float>()); |
---|
286 | EXPECT_EQ(Vector3::ZERO, mt.get<Vector3>()); |
---|
287 | |
---|
288 | EXPECT_FALSE(mt.lastConversionSuccessful()); |
---|
289 | } |
---|
290 | |
---|
291 | /////////// |
---|
292 | // reset // |
---|
293 | /////////// |
---|
294 | TEST(MultiType, Reset) |
---|
295 | { |
---|
296 | MultiType mt(10); |
---|
297 | |
---|
298 | EXPECT_TRUE(mt.isType<int>()); |
---|
299 | EXPECT_FALSE(mt.isType<void>()); |
---|
300 | EXPECT_FALSE(mt.null()); |
---|
301 | EXPECT_EQ(10, mt.get<int>()); |
---|
302 | |
---|
303 | mt.reset(); |
---|
304 | |
---|
305 | EXPECT_FALSE(mt.isType<int>()); |
---|
306 | EXPECT_TRUE(mt.isType<void>()); |
---|
307 | EXPECT_TRUE(mt.null()); |
---|
308 | EXPECT_EQ(0, mt.get<int>()); |
---|
309 | } |
---|
310 | |
---|
311 | /////////////////// |
---|
312 | // reset<type>() // |
---|
313 | /////////////////// |
---|
314 | TEST(MultiType, SetType) |
---|
315 | { |
---|
316 | MultiType mt(10); |
---|
317 | |
---|
318 | EXPECT_TRUE(mt.isType<int>()); |
---|
319 | EXPECT_FALSE(mt.isType<float>()); |
---|
320 | EXPECT_EQ(10, mt.get<int>()); |
---|
321 | |
---|
322 | mt.reset<float>(); |
---|
323 | |
---|
324 | EXPECT_FALSE(mt.isType<int>()); |
---|
325 | EXPECT_TRUE(mt.isType<float>()); |
---|
326 | EXPECT_EQ(0, mt.get<int>()); |
---|
327 | } |
---|
328 | |
---|
329 | //////////////// |
---|
330 | // resetValue // |
---|
331 | //////////////// |
---|
332 | TEST(MultiType, resetValue) |
---|
333 | { |
---|
334 | MultiType mt(10); |
---|
335 | |
---|
336 | EXPECT_TRUE(mt.isType<int>()); |
---|
337 | EXPECT_EQ(10, mt.get<int>()); |
---|
338 | |
---|
339 | mt.resetValue(); |
---|
340 | |
---|
341 | EXPECT_TRUE(mt.isType<int>()); |
---|
342 | EXPECT_EQ(0, mt.get<int>()); |
---|
343 | } |
---|
344 | |
---|
345 | ///////////////////// |
---|
346 | // type operator() // |
---|
347 | ///////////////////// |
---|
348 | TEST(MultiType, ConversionOperatorFloatToFloat) |
---|
349 | { |
---|
350 | MultiType mt(12.34f); |
---|
351 | float value = mt; |
---|
352 | EXPECT_EQ(12.34f, value); |
---|
353 | } |
---|
354 | |
---|
355 | TEST(MultiType, ConversionOperatorFloatToInt) |
---|
356 | { |
---|
357 | MultiType mt(12.34f); |
---|
358 | int value = mt; |
---|
359 | EXPECT_EQ(12, value); |
---|
360 | } |
---|
361 | |
---|
362 | TEST(MultiType, ConversionOperatorIntToFloat) |
---|
363 | { |
---|
364 | MultiType mt(123); |
---|
365 | float value = mt; |
---|
366 | EXPECT_EQ(123, value); |
---|
367 | } |
---|
368 | |
---|
369 | TEST(MultiType, ConversionOperatorIntToString) |
---|
370 | { |
---|
371 | MultiType mt(123); |
---|
372 | std::string value = mt; |
---|
373 | EXPECT_EQ("123", value); |
---|
374 | } |
---|
375 | |
---|
376 | TEST(MultiType, ConversionOperatorStringToInt) |
---|
377 | { |
---|
378 | MultiType mt("321"); |
---|
379 | int value = mt; |
---|
380 | EXPECT_EQ(321, value); |
---|
381 | } |
---|
382 | |
---|
383 | namespace |
---|
384 | { |
---|
385 | void helper_function(const std::string& a, float b, int c) |
---|
386 | { |
---|
387 | EXPECT_EQ("555.555", a); |
---|
388 | EXPECT_EQ(555.555f, b); |
---|
389 | EXPECT_EQ(555, c); |
---|
390 | } |
---|
391 | } |
---|
392 | |
---|
393 | TEST(MultiType, ConversionOperatorPassToFunction) |
---|
394 | { |
---|
395 | MultiType mt("555.555"); |
---|
396 | |
---|
397 | helper_function(mt, mt, mt); |
---|
398 | } |
---|
399 | |
---|
400 | /////////////////////// |
---|
401 | // getValue(pointer) // |
---|
402 | /////////////////////// |
---|
403 | TEST(MultiType, GetValueIntToInt) |
---|
404 | { |
---|
405 | MultiType mt(33); |
---|
406 | |
---|
407 | int value = 0; |
---|
408 | EXPECT_TRUE(mt.getValue(&value)); |
---|
409 | EXPECT_EQ(33, value); |
---|
410 | } |
---|
411 | |
---|
412 | TEST(MultiType, GetValueIntToFloat) |
---|
413 | { |
---|
414 | MultiType mt(33); |
---|
415 | |
---|
416 | float value = 0; |
---|
417 | EXPECT_TRUE(mt.getValue(&value)); |
---|
418 | EXPECT_EQ(33.0f, value); |
---|
419 | } |
---|
420 | |
---|
421 | TEST(MultiType, GetValueIntToVector3) |
---|
422 | { |
---|
423 | MultiType mt(33); |
---|
424 | |
---|
425 | Vector3 value = Vector3::ZERO; |
---|
426 | EXPECT_FALSE(mt.getValue(&value)); |
---|
427 | EXPECT_EQ(Vector3::ZERO, value); |
---|
428 | } |
---|
429 | |
---|
430 | ////////////// |
---|
431 | // get<type>() // |
---|
432 | ////////////// |
---|
433 | TEST(MultiType, GetValueFromInt) |
---|
434 | { |
---|
435 | MultiType mt(256); |
---|
436 | |
---|
437 | EXPECT_EQ(0, mt.get<char>()); |
---|
438 | EXPECT_EQ(0u, mt.get<unsigned char>()); |
---|
439 | EXPECT_EQ(256, mt.get<short>()); |
---|
440 | EXPECT_EQ(256u, mt.get<unsigned short>()); |
---|
441 | EXPECT_EQ(256, mt.get<int>()); |
---|
442 | EXPECT_EQ(256u, mt.get<unsigned int>()); |
---|
443 | EXPECT_EQ(256, mt.get<long>()); |
---|
444 | EXPECT_EQ(256u, mt.get<unsigned long>()); |
---|
445 | EXPECT_EQ(256, mt.get<long long>()); |
---|
446 | EXPECT_EQ(256u, mt.get<unsigned long long>()); |
---|
447 | EXPECT_EQ(256.0f, mt.get<float>()); |
---|
448 | EXPECT_EQ(256.0, mt.get<double>()); |
---|
449 | EXPECT_EQ(256.0, mt.get<long double>()); |
---|
450 | EXPECT_TRUE(mt.get<bool>()); |
---|
451 | EXPECT_EQ("256", mt.get<std::string>()); |
---|
452 | } |
---|
453 | |
---|
454 | TEST(MultiType, GetValueFromFloat) |
---|
455 | { |
---|
456 | MultiType mt(128.821); |
---|
457 | |
---|
458 | EXPECT_EQ(-128, mt.get<char>()); |
---|
459 | EXPECT_EQ(128u, mt.get<unsigned char>()); |
---|
460 | EXPECT_EQ(128, mt.get<short>()); |
---|
461 | EXPECT_EQ(128u, mt.get<unsigned short>()); |
---|
462 | EXPECT_EQ(128, mt.get<int>()); |
---|
463 | EXPECT_EQ(128u, mt.get<unsigned int>()); |
---|
464 | EXPECT_EQ(128, mt.get<long>()); |
---|
465 | EXPECT_EQ(128u, mt.get<unsigned long>()); |
---|
466 | EXPECT_EQ(128, mt.get<long long>()); |
---|
467 | EXPECT_EQ(128u, mt.get<unsigned long long>()); |
---|
468 | EXPECT_EQ(128.821f, mt.get<float>()); |
---|
469 | EXPECT_EQ(128.821, mt.get<double>()); |
---|
470 | EXPECT_EQ(128.821, mt.get<long double>()); |
---|
471 | EXPECT_TRUE(mt.get<bool>()); |
---|
472 | EXPECT_EQ("128.821", mt.get<std::string>()); |
---|
473 | } |
---|
474 | |
---|
475 | TEST(MultiType, GetValueFromString) |
---|
476 | { |
---|
477 | MultiType mt("0.123"); |
---|
478 | |
---|
479 | EXPECT_EQ('0', mt.get<char>()); |
---|
480 | EXPECT_EQ('0', mt.get<unsigned char>()); |
---|
481 | EXPECT_EQ(0, mt.get<short>()); |
---|
482 | EXPECT_EQ(0u, mt.get<unsigned short>()); |
---|
483 | EXPECT_EQ(0, mt.get<int>()); |
---|
484 | EXPECT_EQ(0u, mt.get<unsigned int>()); |
---|
485 | EXPECT_EQ(0, mt.get<long>()); |
---|
486 | EXPECT_EQ(0u, mt.get<unsigned long>()); |
---|
487 | EXPECT_EQ(0, mt.get<long long>()); |
---|
488 | EXPECT_EQ(0u, mt.get<unsigned long long>()); |
---|
489 | EXPECT_EQ(0.123f, mt.get<float>()); |
---|
490 | EXPECT_EQ(0.123, mt.get<double>()); |
---|
491 | EXPECT_DOUBLE_EQ(0.123, mt.get<long double>()); |
---|
492 | EXPECT_FALSE(mt.get<bool>()); |
---|
493 | EXPECT_EQ("0.123", mt.get<std::string>()); |
---|
494 | } |
---|
495 | |
---|
496 | //////////////////// |
---|
497 | // isType<type>() // |
---|
498 | //////////////////// |
---|
499 | TEST(MultiType, IsTypeInt) |
---|
500 | { |
---|
501 | MultiType mt(1); |
---|
502 | |
---|
503 | EXPECT_FALSE(mt.isType<void>()); |
---|
504 | EXPECT_FALSE(mt.isType<char>()); |
---|
505 | EXPECT_FALSE(mt.isType<unsigned char>()); |
---|
506 | EXPECT_FALSE(mt.isType<short>()); |
---|
507 | EXPECT_FALSE(mt.isType<unsigned short>()); |
---|
508 | EXPECT_TRUE(mt.isType<int>()); |
---|
509 | EXPECT_FALSE(mt.isType<unsigned int>()); |
---|
510 | EXPECT_FALSE(mt.isType<long>()); |
---|
511 | EXPECT_FALSE(mt.isType<unsigned long>()); |
---|
512 | EXPECT_FALSE(mt.isType<long long>()); |
---|
513 | EXPECT_FALSE(mt.isType<unsigned long long>()); |
---|
514 | EXPECT_FALSE(mt.isType<float>()); |
---|
515 | EXPECT_FALSE(mt.isType<double>()); |
---|
516 | EXPECT_FALSE(mt.isType<long double>()); |
---|
517 | EXPECT_FALSE(mt.isType<bool>()); |
---|
518 | EXPECT_FALSE(mt.isType<void*>()); |
---|
519 | EXPECT_FALSE(mt.isType<std::string>()); |
---|
520 | EXPECT_FALSE(mt.isType<orxonox::Vector2>()); |
---|
521 | EXPECT_FALSE(mt.isType<orxonox::Vector3>()); |
---|
522 | EXPECT_FALSE(mt.isType<orxonox::Vector4>()); |
---|
523 | EXPECT_FALSE(mt.isType<orxonox::ColourValue>()); |
---|
524 | EXPECT_FALSE(mt.isType<orxonox::Quaternion>()); |
---|
525 | EXPECT_FALSE(mt.isType<orxonox::Radian>()); |
---|
526 | EXPECT_FALSE(mt.isType<orxonox::Degree>()); |
---|
527 | } |
---|
528 | |
---|
529 | TEST(MultiType, IsTypeUnsignedInt) |
---|
530 | { |
---|
531 | MultiType mt(1u); |
---|
532 | |
---|
533 | EXPECT_FALSE(mt.isType<void>()); |
---|
534 | EXPECT_FALSE(mt.isType<char>()); |
---|
535 | EXPECT_FALSE(mt.isType<unsigned char>()); |
---|
536 | EXPECT_FALSE(mt.isType<short>()); |
---|
537 | EXPECT_FALSE(mt.isType<unsigned short>()); |
---|
538 | EXPECT_FALSE(mt.isType<int>()); |
---|
539 | EXPECT_TRUE(mt.isType<unsigned int>()); |
---|
540 | EXPECT_FALSE(mt.isType<long>()); |
---|
541 | EXPECT_FALSE(mt.isType<unsigned long>()); |
---|
542 | EXPECT_FALSE(mt.isType<long long>()); |
---|
543 | EXPECT_FALSE(mt.isType<unsigned long long>()); |
---|
544 | EXPECT_FALSE(mt.isType<float>()); |
---|
545 | EXPECT_FALSE(mt.isType<double>()); |
---|
546 | EXPECT_FALSE(mt.isType<long double>()); |
---|
547 | EXPECT_FALSE(mt.isType<bool>()); |
---|
548 | EXPECT_FALSE(mt.isType<void*>()); |
---|
549 | EXPECT_FALSE(mt.isType<std::string>()); |
---|
550 | EXPECT_FALSE(mt.isType<orxonox::Vector2>()); |
---|
551 | EXPECT_FALSE(mt.isType<orxonox::Vector3>()); |
---|
552 | EXPECT_FALSE(mt.isType<orxonox::Vector4>()); |
---|
553 | EXPECT_FALSE(mt.isType<orxonox::ColourValue>()); |
---|
554 | EXPECT_FALSE(mt.isType<orxonox::Quaternion>()); |
---|
555 | EXPECT_FALSE(mt.isType<orxonox::Radian>()); |
---|
556 | EXPECT_FALSE(mt.isType<orxonox::Degree>()); |
---|
557 | } |
---|
558 | |
---|
559 | TEST(MultiType, IsTypeDouble) |
---|
560 | { |
---|
561 | MultiType mt(1.0); |
---|
562 | |
---|
563 | EXPECT_FALSE(mt.isType<void>()); |
---|
564 | EXPECT_FALSE(mt.isType<char>()); |
---|
565 | EXPECT_FALSE(mt.isType<unsigned char>()); |
---|
566 | EXPECT_FALSE(mt.isType<short>()); |
---|
567 | EXPECT_FALSE(mt.isType<unsigned short>()); |
---|
568 | EXPECT_FALSE(mt.isType<int>()); |
---|
569 | EXPECT_FALSE(mt.isType<unsigned int>()); |
---|
570 | EXPECT_FALSE(mt.isType<long>()); |
---|
571 | EXPECT_FALSE(mt.isType<unsigned long>()); |
---|
572 | EXPECT_FALSE(mt.isType<long long>()); |
---|
573 | EXPECT_FALSE(mt.isType<unsigned long long>()); |
---|
574 | EXPECT_FALSE(mt.isType<float>()); |
---|
575 | EXPECT_TRUE(mt.isType<double>()); |
---|
576 | EXPECT_FALSE(mt.isType<long double>()); |
---|
577 | EXPECT_FALSE(mt.isType<bool>()); |
---|
578 | EXPECT_FALSE(mt.isType<void*>()); |
---|
579 | EXPECT_FALSE(mt.isType<std::string>()); |
---|
580 | EXPECT_FALSE(mt.isType<orxonox::Vector2>()); |
---|
581 | EXPECT_FALSE(mt.isType<orxonox::Vector3>()); |
---|
582 | EXPECT_FALSE(mt.isType<orxonox::Vector4>()); |
---|
583 | EXPECT_FALSE(mt.isType<orxonox::ColourValue>()); |
---|
584 | EXPECT_FALSE(mt.isType<orxonox::Quaternion>()); |
---|
585 | EXPECT_FALSE(mt.isType<orxonox::Radian>()); |
---|
586 | EXPECT_FALSE(mt.isType<orxonox::Degree>()); |
---|
587 | } |
---|
588 | |
---|
589 | TEST(MultiType, IsTypeString) |
---|
590 | { |
---|
591 | MultiType mt("1"); |
---|
592 | |
---|
593 | EXPECT_FALSE(mt.isType<void>()); |
---|
594 | EXPECT_FALSE(mt.isType<char>()); |
---|
595 | EXPECT_FALSE(mt.isType<unsigned char>()); |
---|
596 | EXPECT_FALSE(mt.isType<short>()); |
---|
597 | EXPECT_FALSE(mt.isType<unsigned short>()); |
---|
598 | EXPECT_FALSE(mt.isType<int>()); |
---|
599 | EXPECT_FALSE(mt.isType<unsigned int>()); |
---|
600 | EXPECT_FALSE(mt.isType<long>()); |
---|
601 | EXPECT_FALSE(mt.isType<unsigned long>()); |
---|
602 | EXPECT_FALSE(mt.isType<long long>()); |
---|
603 | EXPECT_FALSE(mt.isType<unsigned long long>()); |
---|
604 | EXPECT_FALSE(mt.isType<float>()); |
---|
605 | EXPECT_FALSE(mt.isType<double>()); |
---|
606 | EXPECT_FALSE(mt.isType<long double>()); |
---|
607 | EXPECT_FALSE(mt.isType<bool>()); |
---|
608 | EXPECT_FALSE(mt.isType<void*>()); |
---|
609 | EXPECT_TRUE(mt.isType<std::string>()); |
---|
610 | EXPECT_FALSE(mt.isType<orxonox::Vector2>()); |
---|
611 | EXPECT_FALSE(mt.isType<orxonox::Vector3>()); |
---|
612 | EXPECT_FALSE(mt.isType<orxonox::Vector4>()); |
---|
613 | EXPECT_FALSE(mt.isType<orxonox::ColourValue>()); |
---|
614 | EXPECT_FALSE(mt.isType<orxonox::Quaternion>()); |
---|
615 | EXPECT_FALSE(mt.isType<orxonox::Radian>()); |
---|
616 | EXPECT_FALSE(mt.isType<orxonox::Degree>()); |
---|
617 | } |
---|
618 | |
---|
619 | TEST(MultiType, IsTypeDegree) |
---|
620 | { |
---|
621 | MultiType mt(Degree(1)); |
---|
622 | |
---|
623 | EXPECT_FALSE(mt.isType<void>()); |
---|
624 | EXPECT_FALSE(mt.isType<char>()); |
---|
625 | EXPECT_FALSE(mt.isType<unsigned char>()); |
---|
626 | EXPECT_FALSE(mt.isType<short>()); |
---|
627 | EXPECT_FALSE(mt.isType<unsigned short>()); |
---|
628 | EXPECT_FALSE(mt.isType<int>()); |
---|
629 | EXPECT_FALSE(mt.isType<unsigned int>()); |
---|
630 | EXPECT_FALSE(mt.isType<long>()); |
---|
631 | EXPECT_FALSE(mt.isType<unsigned long>()); |
---|
632 | EXPECT_FALSE(mt.isType<long long>()); |
---|
633 | EXPECT_FALSE(mt.isType<unsigned long long>()); |
---|
634 | EXPECT_FALSE(mt.isType<float>()); |
---|
635 | EXPECT_FALSE(mt.isType<double>()); |
---|
636 | EXPECT_FALSE(mt.isType<long double>()); |
---|
637 | EXPECT_FALSE(mt.isType<bool>()); |
---|
638 | EXPECT_FALSE(mt.isType<void*>()); |
---|
639 | EXPECT_FALSE(mt.isType<std::string>()); |
---|
640 | EXPECT_FALSE(mt.isType<orxonox::Vector2>()); |
---|
641 | EXPECT_FALSE(mt.isType<orxonox::Vector3>()); |
---|
642 | EXPECT_FALSE(mt.isType<orxonox::Vector4>()); |
---|
643 | EXPECT_FALSE(mt.isType<orxonox::ColourValue>()); |
---|
644 | EXPECT_FALSE(mt.isType<orxonox::Quaternion>()); |
---|
645 | EXPECT_FALSE(mt.isType<orxonox::Radian>()); |
---|
646 | EXPECT_TRUE(mt.isType<orxonox::Degree>()); |
---|
647 | } |
---|
648 | |
---|
649 | //////////////////////////////// |
---|
650 | // lastConversionSuccessful() // |
---|
651 | //////////////////////////////// |
---|
652 | TEST(MultiType, LastConversionSuccessful) |
---|
653 | { |
---|
654 | MultiType mt; |
---|
655 | |
---|
656 | EXPECT_TRUE(mt.lastConversionSuccessful()); |
---|
657 | |
---|
658 | mt = 5.55; |
---|
659 | |
---|
660 | EXPECT_TRUE(mt.lastConversionSuccessful()); |
---|
661 | |
---|
662 | mt.convert<int>(); |
---|
663 | |
---|
664 | EXPECT_TRUE(mt.lastConversionSuccessful()); |
---|
665 | |
---|
666 | mt.convert<Vector3>(); |
---|
667 | |
---|
668 | EXPECT_FALSE(mt.lastConversionSuccessful()); |
---|
669 | |
---|
670 | mt.convert<std::string>(); |
---|
671 | |
---|
672 | EXPECT_TRUE(mt.lastConversionSuccessful()); |
---|
673 | } |
---|
674 | |
---|
675 | //////////// |
---|
676 | // null() // |
---|
677 | //////////// |
---|
678 | TEST(MultiType, Null1) |
---|
679 | { |
---|
680 | MultiType mt; |
---|
681 | |
---|
682 | EXPECT_TRUE(mt.null()); |
---|
683 | |
---|
684 | mt = 5; |
---|
685 | |
---|
686 | EXPECT_FALSE(mt.null()); |
---|
687 | } |
---|
688 | |
---|
689 | TEST(MultiType, Null2) |
---|
690 | { |
---|
691 | MultiType mt(5); |
---|
692 | |
---|
693 | EXPECT_FALSE(mt.null()); |
---|
694 | |
---|
695 | mt.reset(); |
---|
696 | |
---|
697 | EXPECT_TRUE(mt.null()); |
---|
698 | } |
---|
699 | } |
---|