Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/tests/core/variant/test_variant.cpp
23450 views
1
/**************************************************************************/
2
/* test_variant.cpp */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#include "tests/test_macros.h"
32
33
TEST_FORCE_LINK(test_variant)
34
35
#include "core/variant/variant.h"
36
#include "core/variant/variant_parser.h"
37
38
namespace TestVariant {
39
40
TEST_CASE("[Variant] Writer and parser integer") {
41
int64_t a32 = 2147483648; // 2^31, so out of bounds for 32-bit signed int [-2^31, +2^31-1].
42
String a32_str;
43
VariantWriter::write_to_string(a32, a32_str);
44
45
CHECK_MESSAGE(a32_str != "-2147483648", "Should not wrap around");
46
47
int64_t b64 = 9223372036854775807; // 2^63-1, upper bound for signed 64-bit int.
48
String b64_str;
49
VariantWriter::write_to_string(b64, b64_str);
50
51
CHECK_MESSAGE(b64_str == "9223372036854775807", "Should not wrap around.");
52
53
VariantParser::StreamString ss;
54
String errs;
55
int line;
56
Variant b64_parsed;
57
int64_t b64_int_parsed;
58
59
ss.s = b64_str;
60
VariantParser::parse(&ss, b64_parsed, errs, line);
61
b64_int_parsed = b64_parsed;
62
63
CHECK_MESSAGE(b64_int_parsed == 9223372036854775807, "Should parse back.");
64
65
ss.s = "9223372036854775808"; // Overflowed by one.
66
VariantParser::parse(&ss, b64_parsed, errs, line);
67
b64_int_parsed = b64_parsed;
68
69
CHECK_MESSAGE(b64_int_parsed == 9223372036854775807, "The result should be clamped to max value.");
70
71
ss.s = "1e100"; // Googol! Scientific notation.
72
VariantParser::parse(&ss, b64_parsed, errs, line);
73
b64_int_parsed = b64_parsed;
74
75
CHECK_MESSAGE(b64_int_parsed == 9223372036854775807, "The result should be clamped to max value.");
76
}
77
78
TEST_CASE("[Variant] Writer and parser Variant::FLOAT") {
79
// Variant::FLOAT is always 64-bit (C++ double).
80
// This is the maximum non-infinity double-precision float.
81
double a64 = 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0;
82
String a64_str;
83
VariantWriter::write_to_string(a64, a64_str);
84
85
CHECK_MESSAGE(a64_str == "1.7976931348623157e+308", "Writes in scientific notation.");
86
CHECK_MESSAGE(a64_str != "inf", "Should not overflow.");
87
CHECK_MESSAGE(a64_str != "nan", "The result should be defined.");
88
89
String errs;
90
int line;
91
Variant variant_parsed;
92
double float_parsed;
93
94
VariantParser::StreamString bss;
95
bss.s = a64_str;
96
VariantParser::parse(&bss, variant_parsed, errs, line);
97
float_parsed = variant_parsed;
98
// Loses precision, but that's alright.
99
CHECK_MESSAGE(float_parsed == 1.797693134862315708145274237317e+308, "Should parse back.");
100
101
// Approximation of Googol with a double-precision float.
102
VariantParser::StreamString css;
103
css.s = "1.0e+100";
104
VariantParser::parse(&css, variant_parsed, errs, line);
105
float_parsed = variant_parsed;
106
CHECK_MESSAGE(float_parsed == 1.0e+100, "Should match the double literal.");
107
}
108
109
TEST_CASE("[Variant] Assignment To Bool from Int,Float,String,Vec2,Vec2i,Vec3,Vec3i,Vec4,Vec4i,Rect2,Rect2i,Trans2d,Trans3d,Color,Call,Plane,Basis,AABB,Quant,Proj,RID,and Object") {
110
Variant int_v = 0;
111
Variant bool_v = true;
112
int_v = bool_v; // int_v is now a bool
113
CHECK(int_v == Variant(true));
114
bool_v = false;
115
int_v = bool_v;
116
CHECK(int_v.get_type() == Variant::BOOL);
117
118
Variant float_v = 0.0f;
119
bool_v = true;
120
float_v = bool_v;
121
CHECK(float_v == Variant(true));
122
bool_v = false;
123
float_v = bool_v;
124
CHECK(float_v.get_type() == Variant::BOOL);
125
126
Variant string_v = "";
127
bool_v = true;
128
string_v = bool_v;
129
CHECK(string_v == Variant(true));
130
bool_v = false;
131
string_v = bool_v;
132
CHECK(string_v.get_type() == Variant::BOOL);
133
134
Variant vec2_v = Vector2(0, 0);
135
bool_v = true;
136
vec2_v = bool_v;
137
CHECK(vec2_v == Variant(true));
138
bool_v = false;
139
vec2_v = bool_v;
140
CHECK(vec2_v.get_type() == Variant::BOOL);
141
142
Variant vec2i_v = Vector2i(0, 0);
143
bool_v = true;
144
vec2i_v = bool_v;
145
CHECK(vec2i_v == Variant(true));
146
bool_v = false;
147
vec2i_v = bool_v;
148
CHECK(vec2i_v.get_type() == Variant::BOOL);
149
150
Variant vec3_v = Vector3(0, 0, 0);
151
bool_v = true;
152
vec3_v = bool_v;
153
CHECK(vec3_v == Variant(true));
154
bool_v = false;
155
vec3_v = bool_v;
156
CHECK(vec3_v.get_type() == Variant::BOOL);
157
158
Variant vec3i_v = Vector3i(0, 0, 0);
159
bool_v = true;
160
vec3i_v = bool_v;
161
CHECK(vec3i_v == Variant(true));
162
bool_v = false;
163
vec3i_v = bool_v;
164
CHECK(vec3i_v.get_type() == Variant::BOOL);
165
166
Variant vec4_v = Vector4(0, 0, 0, 0);
167
bool_v = true;
168
vec4_v = bool_v;
169
CHECK(vec4_v == Variant(true));
170
bool_v = false;
171
vec4_v = bool_v;
172
CHECK(vec4_v.get_type() == Variant::BOOL);
173
174
Variant vec4i_v = Vector4i(0, 0, 0, 0);
175
bool_v = true;
176
vec4i_v = bool_v;
177
CHECK(vec4i_v == Variant(true));
178
bool_v = false;
179
vec4i_v = bool_v;
180
CHECK(vec4i_v.get_type() == Variant::BOOL);
181
182
Variant rect2_v = Rect2();
183
bool_v = true;
184
rect2_v = bool_v;
185
CHECK(rect2_v == Variant(true));
186
bool_v = false;
187
rect2_v = bool_v;
188
CHECK(rect2_v.get_type() == Variant::BOOL);
189
190
Variant rect2i_v = Rect2i();
191
bool_v = true;
192
rect2i_v = bool_v;
193
CHECK(rect2i_v == Variant(true));
194
bool_v = false;
195
rect2i_v = bool_v;
196
CHECK(rect2i_v.get_type() == Variant::BOOL);
197
198
Variant transform2d_v = Transform2D();
199
bool_v = true;
200
transform2d_v = bool_v;
201
CHECK(transform2d_v == Variant(true));
202
bool_v = false;
203
transform2d_v = bool_v;
204
CHECK(transform2d_v.get_type() == Variant::BOOL);
205
206
Variant transform3d_v = Transform3D();
207
bool_v = true;
208
transform3d_v = bool_v;
209
CHECK(transform3d_v == Variant(true));
210
bool_v = false;
211
transform3d_v = bool_v;
212
CHECK(transform3d_v.get_type() == Variant::BOOL);
213
214
Variant col_v = Color(0.5f, 0.2f, 0.75f);
215
bool_v = true;
216
col_v = bool_v;
217
CHECK(col_v == Variant(true));
218
bool_v = false;
219
col_v = bool_v;
220
CHECK(col_v.get_type() == Variant::BOOL);
221
222
Variant call_v = Callable();
223
bool_v = true;
224
call_v = bool_v;
225
CHECK(call_v == Variant(true));
226
bool_v = false;
227
call_v = bool_v;
228
CHECK(call_v.get_type() == Variant::BOOL);
229
230
Variant plane_v = Plane();
231
bool_v = true;
232
plane_v = bool_v;
233
CHECK(plane_v == Variant(true));
234
bool_v = false;
235
plane_v = bool_v;
236
CHECK(plane_v.get_type() == Variant::BOOL);
237
238
Variant basis_v = Basis();
239
bool_v = true;
240
basis_v = bool_v;
241
CHECK(basis_v == Variant(true));
242
bool_v = false;
243
basis_v = bool_v;
244
CHECK(basis_v.get_type() == Variant::BOOL);
245
246
Variant aabb_v = AABB();
247
bool_v = true;
248
aabb_v = bool_v;
249
CHECK(aabb_v == Variant(true));
250
bool_v = false;
251
aabb_v = bool_v;
252
CHECK(aabb_v.get_type() == Variant::BOOL);
253
254
Variant quaternion_v = Quaternion();
255
bool_v = true;
256
quaternion_v = bool_v;
257
CHECK(quaternion_v == Variant(true));
258
bool_v = false;
259
quaternion_v = bool_v;
260
CHECK(quaternion_v.get_type() == Variant::BOOL);
261
262
Variant projection_v = Projection();
263
bool_v = true;
264
projection_v = bool_v;
265
CHECK(projection_v == Variant(true));
266
bool_v = false;
267
projection_v = bool_v;
268
CHECK(projection_v.get_type() == Variant::BOOL);
269
270
Variant rid_v = RID();
271
bool_v = true;
272
rid_v = bool_v;
273
CHECK(rid_v == Variant(true));
274
bool_v = false;
275
rid_v = bool_v;
276
CHECK(rid_v.get_type() == Variant::BOOL);
277
278
Object obj_one = Object();
279
Variant object_v = &obj_one;
280
bool_v = true;
281
object_v = bool_v;
282
CHECK(object_v == Variant(true));
283
bool_v = false;
284
object_v = bool_v;
285
CHECK(object_v.get_type() == Variant::BOOL);
286
}
287
288
TEST_CASE("[Variant] Assignment To Int from Bool,Float,String,Vec2,Vec2i,Vec3,Vec3i Vec4,Vec4i,Rect2,Rect2i,Trans2d,Trans3d,Color,Call,Plane,Basis,AABB,Quant,Proj,RID,and Object") {
289
Variant bool_v = false;
290
Variant int_v = 2;
291
bool_v = int_v; // Now bool_v is int
292
CHECK(bool_v == Variant(2));
293
int_v = -3;
294
bool_v = int_v;
295
CHECK(bool_v.get_type() == Variant::INT);
296
297
Variant float_v = 0.0f;
298
int_v = 2;
299
float_v = int_v;
300
CHECK(float_v == Variant(2));
301
int_v = -3;
302
float_v = int_v;
303
CHECK(float_v.get_type() == Variant::INT);
304
305
Variant string_v = "";
306
int_v = 2;
307
string_v = int_v;
308
CHECK(string_v == Variant(2));
309
int_v = -3;
310
string_v = int_v;
311
CHECK(string_v.get_type() == Variant::INT);
312
313
Variant vec2_v = Vector2(0, 0);
314
int_v = 2;
315
vec2_v = int_v;
316
CHECK(vec2_v == Variant(2));
317
int_v = -3;
318
vec2_v = int_v;
319
CHECK(vec2_v.get_type() == Variant::INT);
320
321
Variant vec2i_v = Vector2i(0, 0);
322
int_v = 2;
323
vec2i_v = int_v;
324
CHECK(vec2i_v == Variant(2));
325
int_v = -3;
326
vec2i_v = int_v;
327
CHECK(vec2i_v.get_type() == Variant::INT);
328
329
Variant vec3_v = Vector3(0, 0, 0);
330
int_v = 2;
331
vec3_v = int_v;
332
CHECK(vec3_v == Variant(2));
333
int_v = -3;
334
vec3_v = int_v;
335
CHECK(vec3_v.get_type() == Variant::INT);
336
337
Variant vec3i_v = Vector3i(0, 0, 0);
338
int_v = 2;
339
vec3i_v = int_v;
340
CHECK(vec3i_v == Variant(2));
341
int_v = -3;
342
vec3i_v = int_v;
343
CHECK(vec3i_v.get_type() == Variant::INT);
344
345
Variant vec4_v = Vector4(0, 0, 0, 0);
346
int_v = 2;
347
vec4_v = int_v;
348
CHECK(vec4_v == Variant(2));
349
int_v = -3;
350
vec4_v = int_v;
351
CHECK(vec4_v.get_type() == Variant::INT);
352
353
Variant vec4i_v = Vector4i(0, 0, 0, 0);
354
int_v = 2;
355
vec4i_v = int_v;
356
CHECK(vec4i_v == Variant(2));
357
int_v = -3;
358
vec4i_v = int_v;
359
CHECK(vec4i_v.get_type() == Variant::INT);
360
361
Variant rect2_v = Rect2();
362
int_v = 2;
363
rect2_v = int_v;
364
CHECK(rect2_v == Variant(2));
365
int_v = -3;
366
rect2_v = int_v;
367
CHECK(rect2_v.get_type() == Variant::INT);
368
369
Variant rect2i_v = Rect2i();
370
int_v = 2;
371
rect2i_v = int_v;
372
CHECK(rect2i_v == Variant(2));
373
int_v = -3;
374
rect2i_v = int_v;
375
CHECK(rect2i_v.get_type() == Variant::INT);
376
377
Variant transform2d_v = Transform2D();
378
int_v = 2;
379
transform2d_v = int_v;
380
CHECK(transform2d_v == Variant(2));
381
int_v = -3;
382
transform2d_v = int_v;
383
CHECK(transform2d_v.get_type() == Variant::INT);
384
385
Variant transform3d_v = Transform3D();
386
int_v = 2;
387
transform3d_v = int_v;
388
CHECK(transform3d_v == Variant(2));
389
int_v = -3;
390
transform3d_v = int_v;
391
CHECK(transform3d_v.get_type() == Variant::INT);
392
393
Variant col_v = Color(0.5f, 0.2f, 0.75f);
394
int_v = 2;
395
col_v = int_v;
396
CHECK(col_v == Variant(2));
397
int_v = -3;
398
col_v = int_v;
399
CHECK(col_v.get_type() == Variant::INT);
400
401
Variant call_v = Callable();
402
int_v = 2;
403
call_v = int_v;
404
CHECK(call_v == Variant(2));
405
int_v = -3;
406
call_v = int_v;
407
CHECK(call_v.get_type() == Variant::INT);
408
409
Variant plane_v = Plane();
410
int_v = 2;
411
plane_v = int_v;
412
CHECK(plane_v == Variant(2));
413
int_v = -3;
414
plane_v = int_v;
415
CHECK(plane_v.get_type() == Variant::INT);
416
417
Variant basis_v = Basis();
418
int_v = 2;
419
basis_v = int_v;
420
CHECK(basis_v == Variant(2));
421
int_v = -3;
422
basis_v = int_v;
423
CHECK(basis_v.get_type() == Variant::INT);
424
425
Variant aabb_v = AABB();
426
int_v = 2;
427
aabb_v = int_v;
428
CHECK(aabb_v == Variant(2));
429
int_v = -3;
430
aabb_v = int_v;
431
CHECK(aabb_v.get_type() == Variant::INT);
432
433
Variant quaternion_v = Quaternion();
434
int_v = 2;
435
quaternion_v = int_v;
436
CHECK(quaternion_v == Variant(2));
437
int_v = -3;
438
quaternion_v = int_v;
439
CHECK(quaternion_v.get_type() == Variant::INT);
440
441
Variant projection_v = Projection();
442
int_v = 2;
443
projection_v = int_v;
444
CHECK(projection_v == Variant(2));
445
int_v = -3;
446
projection_v = int_v;
447
CHECK(projection_v.get_type() == Variant::INT);
448
449
Variant rid_v = RID();
450
int_v = 2;
451
rid_v = int_v;
452
CHECK(rid_v == Variant(2));
453
bool_v = -3;
454
rid_v = int_v;
455
CHECK(rid_v.get_type() == Variant::INT);
456
457
Object obj_one = Object();
458
Variant object_v = &obj_one;
459
int_v = 2;
460
object_v = int_v;
461
CHECK(object_v == Variant(2));
462
int_v = -3;
463
object_v = int_v;
464
CHECK(object_v.get_type() == Variant::INT);
465
}
466
467
TEST_CASE("[Variant] Assignment To Float from Bool,Int,String,Vec2,Vec2i,Vec3,Vec3i,Vec4,Vec4i,Rect2,Rect2i,Trans2d,Trans3d,Color,Call,Plane,Basis,AABB,Quant,Proj,RID,and Object") {
468
Variant bool_v = false;
469
Variant float_v = 1.5f;
470
bool_v = float_v; // Now bool_v is float
471
CHECK(bool_v == Variant(1.5f));
472
float_v = -4.6f;
473
bool_v = float_v;
474
CHECK(bool_v.get_type() == Variant::FLOAT);
475
476
Variant int_v = 1;
477
float_v = 1.5f;
478
int_v = float_v;
479
CHECK(int_v == Variant(1.5f));
480
float_v = -4.6f;
481
int_v = float_v;
482
CHECK(int_v.get_type() == Variant::FLOAT);
483
484
Variant string_v = "";
485
float_v = 1.5f;
486
string_v = float_v;
487
CHECK(string_v == Variant(1.5f));
488
float_v = -4.6f;
489
string_v = float_v;
490
CHECK(string_v.get_type() == Variant::FLOAT);
491
492
Variant vec2_v = Vector2(0, 0);
493
float_v = 1.5f;
494
vec2_v = float_v;
495
CHECK(vec2_v == Variant(1.5f));
496
float_v = -4.6f;
497
vec2_v = float_v;
498
CHECK(vec2_v.get_type() == Variant::FLOAT);
499
500
Variant vec2i_v = Vector2i(0, 0);
501
float_v = 1.5f;
502
vec2i_v = float_v;
503
CHECK(vec2i_v == Variant(1.5f));
504
float_v = -4.6f;
505
vec2i_v = float_v;
506
CHECK(vec2i_v.get_type() == Variant::FLOAT);
507
508
Variant vec3_v = Vector3(0, 0, 0);
509
float_v = 1.5f;
510
vec3_v = float_v;
511
CHECK(vec3_v == Variant(1.5f));
512
float_v = -4.6f;
513
vec3_v = float_v;
514
CHECK(vec3_v.get_type() == Variant::FLOAT);
515
516
Variant vec3i_v = Vector3i(0, 0, 0);
517
float_v = 1.5f;
518
vec3i_v = float_v;
519
CHECK(vec3i_v == Variant(1.5f));
520
float_v = -4.6f;
521
vec3i_v = float_v;
522
CHECK(vec3i_v.get_type() == Variant::FLOAT);
523
524
Variant vec4_v = Vector4(0, 0, 0, 0);
525
float_v = 1.5f;
526
vec4_v = float_v;
527
CHECK(vec4_v == Variant(1.5f));
528
float_v = -4.6f;
529
vec4_v = float_v;
530
CHECK(vec4_v.get_type() == Variant::FLOAT);
531
532
Variant vec4i_v = Vector4i(0, 0, 0, 0);
533
float_v = 1.5f;
534
vec4i_v = float_v;
535
CHECK(vec4i_v == Variant(1.5f));
536
float_v = -4.6f;
537
vec4i_v = float_v;
538
CHECK(vec4i_v.get_type() == Variant::FLOAT);
539
540
Variant rect2_v = Rect2();
541
float_v = 1.5f;
542
rect2_v = float_v;
543
CHECK(rect2_v == Variant(1.5f));
544
float_v = -4.6f;
545
rect2_v = float_v;
546
CHECK(rect2_v.get_type() == Variant::FLOAT);
547
548
Variant rect2i_v = Rect2i();
549
float_v = 1.5f;
550
rect2i_v = float_v;
551
CHECK(rect2i_v == Variant(1.5f));
552
float_v = -4.6f;
553
rect2i_v = float_v;
554
CHECK(rect2i_v.get_type() == Variant::FLOAT);
555
556
Variant transform2d_v = Transform2D();
557
float_v = 1.5f;
558
transform2d_v = float_v;
559
CHECK(transform2d_v == Variant(1.5f));
560
float_v = -4.6f;
561
transform2d_v = float_v;
562
CHECK(transform2d_v.get_type() == Variant::FLOAT);
563
564
Variant transform3d_v = Transform3D();
565
float_v = 1.5f;
566
transform3d_v = float_v;
567
CHECK(transform3d_v == Variant(1.5f));
568
float_v = -4.6f;
569
transform3d_v = float_v;
570
CHECK(transform2d_v.get_type() == Variant::FLOAT);
571
572
Variant col_v = Color(0.5f, 0.2f, 0.75f);
573
float_v = 1.5f;
574
col_v = float_v;
575
CHECK(col_v == Variant(1.5f));
576
float_v = -4.6f;
577
col_v = float_v;
578
CHECK(col_v.get_type() == Variant::FLOAT);
579
580
Variant call_v = Callable();
581
float_v = 1.5f;
582
call_v = float_v;
583
CHECK(call_v == Variant(1.5f));
584
float_v = -4.6f;
585
call_v = float_v;
586
CHECK(call_v.get_type() == Variant::FLOAT);
587
588
Variant plane_v = Plane();
589
float_v = 1.5f;
590
plane_v = float_v;
591
CHECK(plane_v == Variant(1.5f));
592
float_v = -4.6f;
593
plane_v = float_v;
594
CHECK(plane_v.get_type() == Variant::FLOAT);
595
596
Variant basis_v = Basis();
597
float_v = 1.5f;
598
basis_v = float_v;
599
CHECK(basis_v == Variant(1.5f));
600
float_v = -4.6f;
601
basis_v = float_v;
602
CHECK(basis_v.get_type() == Variant::FLOAT);
603
604
Variant aabb_v = AABB();
605
float_v = 1.5f;
606
aabb_v = float_v;
607
CHECK(aabb_v == Variant(1.5f));
608
float_v = -4.6f;
609
aabb_v = float_v;
610
CHECK(aabb_v.get_type() == Variant::FLOAT);
611
612
Variant quaternion_v = Quaternion();
613
float_v = 1.5f;
614
quaternion_v = float_v;
615
CHECK(quaternion_v == Variant(1.5f));
616
float_v = -4.6f;
617
quaternion_v = float_v;
618
CHECK(quaternion_v.get_type() == Variant::FLOAT);
619
620
Variant projection_v = Projection();
621
float_v = 1.5f;
622
projection_v = float_v;
623
CHECK(projection_v == Variant(1.5f));
624
float_v = -4.6f;
625
projection_v = float_v;
626
CHECK(projection_v.get_type() == Variant::FLOAT);
627
628
Variant rid_v = RID();
629
float_v = 1.5f;
630
rid_v = float_v;
631
CHECK(rid_v == Variant(1.5f));
632
float_v = -4.6f;
633
rid_v = float_v;
634
CHECK(rid_v.get_type() == Variant::FLOAT);
635
636
Object obj_one = Object();
637
Variant object_v = &obj_one;
638
float_v = 1.5f;
639
object_v = float_v;
640
CHECK(object_v == Variant(1.5f));
641
float_v = -4.6f;
642
object_v = float_v;
643
CHECK(object_v.get_type() == Variant::FLOAT);
644
}
645
646
TEST_CASE("[Variant] Assignment To String from Bool,Int,Float,Vec2,Vec2i,Vec3,Vec3i,Vec4,Vec4i,Rect2,Rect2i,Trans2d,Trans3d,Color,Call,Plane,Basis,AABB,Quant,Proj,RID,and Object") {
647
Variant bool_v = false;
648
Variant string_v = "Hello";
649
bool_v = string_v; // Now bool_v is string
650
CHECK(bool_v == Variant("Hello"));
651
string_v = "Hello there";
652
bool_v = string_v;
653
CHECK(bool_v.get_type() == Variant::STRING);
654
655
Variant int_v = 0;
656
string_v = "Hello";
657
int_v = string_v;
658
CHECK(int_v == Variant("Hello"));
659
string_v = "Hello there";
660
int_v = string_v;
661
CHECK(int_v.get_type() == Variant::STRING);
662
663
Variant float_v = 0.0f;
664
string_v = "Hello";
665
float_v = string_v;
666
CHECK(float_v == Variant("Hello"));
667
string_v = "Hello there";
668
float_v = string_v;
669
CHECK(float_v.get_type() == Variant::STRING);
670
671
Variant vec2_v = Vector2(0, 0);
672
string_v = "Hello";
673
vec2_v = string_v;
674
CHECK(vec2_v == Variant("Hello"));
675
string_v = "Hello there";
676
vec2_v = string_v;
677
CHECK(vec2_v.get_type() == Variant::STRING);
678
679
Variant vec2i_v = Vector2i(0, 0);
680
string_v = "Hello";
681
vec2i_v = string_v;
682
CHECK(vec2i_v == Variant("Hello"));
683
string_v = "Hello there";
684
vec2i_v = string_v;
685
CHECK(vec2i_v.get_type() == Variant::STRING);
686
687
Variant vec3_v = Vector3(0, 0, 0);
688
string_v = "Hello";
689
vec3_v = string_v;
690
CHECK(vec3_v == Variant("Hello"));
691
string_v = "Hello there";
692
vec3_v = string_v;
693
CHECK(vec3_v.get_type() == Variant::STRING);
694
695
Variant vec3i_v = Vector3i(0, 0, 0);
696
string_v = "Hello";
697
vec3i_v = string_v;
698
CHECK(vec3i_v == Variant("Hello"));
699
string_v = "Hello there";
700
vec3i_v = string_v;
701
CHECK(vec3i_v.get_type() == Variant::STRING);
702
703
Variant vec4_v = Vector4(0, 0, 0, 0);
704
string_v = "Hello";
705
vec4_v = string_v;
706
CHECK(vec4_v == Variant("Hello"));
707
string_v = "Hello there";
708
vec4_v = string_v;
709
CHECK(vec4_v.get_type() == Variant::STRING);
710
711
Variant vec4i_v = Vector4i(0, 0, 0, 0);
712
string_v = "Hello";
713
vec4i_v = string_v;
714
CHECK(vec4i_v == Variant("Hello"));
715
string_v = "Hello there";
716
vec4i_v = string_v;
717
CHECK(vec4i_v.get_type() == Variant::STRING);
718
719
Variant rect2_v = Rect2();
720
string_v = "Hello";
721
rect2_v = string_v;
722
CHECK(rect2_v == Variant("Hello"));
723
string_v = "Hello there";
724
rect2_v = string_v;
725
CHECK(rect2_v.get_type() == Variant::STRING);
726
727
Variant rect2i_v = Rect2i();
728
string_v = "Hello";
729
rect2i_v = string_v;
730
CHECK(rect2i_v == Variant("Hello"));
731
string_v = "Hello there";
732
rect2i_v = string_v;
733
CHECK(rect2i_v.get_type() == Variant::STRING);
734
735
Variant transform2d_v = Transform2D();
736
string_v = "Hello";
737
transform2d_v = string_v;
738
CHECK(transform2d_v == Variant("Hello"));
739
string_v = "Hello there";
740
transform2d_v = string_v;
741
CHECK(transform2d_v.get_type() == Variant::STRING);
742
743
Variant transform3d_v = Transform3D();
744
string_v = "Hello";
745
transform3d_v = string_v;
746
CHECK(transform3d_v == Variant("Hello"));
747
string_v = "Hello there";
748
transform3d_v = string_v;
749
CHECK(transform3d_v.get_type() == Variant::STRING);
750
751
Variant col_v = Color(0.5f, 0.2f, 0.75f);
752
string_v = "Hello";
753
col_v = string_v;
754
CHECK(col_v == Variant("Hello"));
755
string_v = "Hello there";
756
col_v = string_v;
757
CHECK(col_v.get_type() == Variant::STRING);
758
759
Variant call_v = Callable();
760
string_v = "Hello";
761
call_v = string_v;
762
CHECK(call_v == Variant("Hello"));
763
string_v = "Hello there";
764
call_v = string_v;
765
CHECK(call_v.get_type() == Variant::STRING);
766
767
Variant plane_v = Plane();
768
string_v = "Hello";
769
plane_v = string_v;
770
CHECK(plane_v == Variant("Hello"));
771
string_v = "Hello there";
772
plane_v = string_v;
773
CHECK(plane_v.get_type() == Variant::STRING);
774
775
Variant basis_v = Basis();
776
string_v = "Hello";
777
basis_v = string_v;
778
CHECK(basis_v == Variant("Hello"));
779
string_v = "Hello there";
780
basis_v = string_v;
781
CHECK(basis_v.get_type() == Variant::STRING);
782
783
Variant aabb_v = AABB();
784
string_v = "Hello";
785
aabb_v = string_v;
786
CHECK(aabb_v == Variant("Hello"));
787
string_v = "Hello there";
788
aabb_v = string_v;
789
CHECK(aabb_v.get_type() == Variant::STRING);
790
791
Variant quaternion_v = Quaternion();
792
string_v = "Hello";
793
quaternion_v = string_v;
794
CHECK(quaternion_v == Variant("Hello"));
795
string_v = "Hello there";
796
quaternion_v = string_v;
797
CHECK(quaternion_v.get_type() == Variant::STRING);
798
799
Variant projection_v = Projection();
800
string_v = "Hello";
801
projection_v = string_v;
802
CHECK(projection_v == Variant("Hello"));
803
string_v = "Hello there";
804
projection_v = string_v;
805
CHECK(projection_v.get_type() == Variant::STRING);
806
807
Variant rid_v = RID();
808
string_v = "Hello";
809
rid_v = string_v;
810
CHECK(rid_v == Variant("Hello"));
811
string_v = "Hello there";
812
rid_v = string_v;
813
CHECK(rid_v.get_type() == Variant::STRING);
814
815
Object obj_one = Object();
816
Variant object_v = &obj_one;
817
string_v = "Hello";
818
object_v = string_v;
819
CHECK(object_v == Variant("Hello"));
820
string_v = "Hello there";
821
object_v = string_v;
822
CHECK(object_v.get_type() == Variant::STRING);
823
}
824
825
TEST_CASE("[Variant] Assignment To Vec2 from Bool,Int,Float,String,Vec2i,Vec3,Vec3i,Vec4,Vec4i,Rect2,Rect2i,Trans2d,Trans3d,Color,Call,Plane,Basis,AABB,Quant,Proj,RID,and Object") {
826
Variant bool_v = false;
827
Variant vec2_v = Vector2(2.2f, 3.5f);
828
bool_v = vec2_v; // Now bool_v is Vector2
829
CHECK(bool_v == Variant(Vector2(2.2f, 3.5f)));
830
vec2_v = Vector2(-5.4f, -7.9f);
831
bool_v = vec2_v;
832
CHECK(bool_v.get_type() == Variant::VECTOR2);
833
834
Variant int_v = 0;
835
vec2_v = Vector2(2.2f, 3.5f);
836
int_v = vec2_v;
837
CHECK(int_v == Variant(Vector2(2.2f, 3.5f)));
838
vec2_v = Vector2(-5.4f, -7.9f);
839
int_v = vec2_v;
840
CHECK(int_v.get_type() == Variant::VECTOR2);
841
842
Variant float_v = 0.0f;
843
vec2_v = Vector2(2.2f, 3.5f);
844
float_v = vec2_v;
845
CHECK(float_v == Variant(Vector2(2.2f, 3.5f)));
846
vec2_v = Vector2(-5.4f, -7.9f);
847
float_v = vec2_v;
848
CHECK(float_v.get_type() == Variant::VECTOR2);
849
850
Variant string_v = "";
851
vec2_v = Vector2(2.2f, 3.5f);
852
string_v = vec2_v;
853
CHECK(string_v == Variant(Vector2(2.2f, 3.5f)));
854
vec2_v = Vector2(-5.4f, -7.9f);
855
string_v = vec2_v;
856
CHECK(string_v.get_type() == Variant::VECTOR2);
857
858
Variant vec2i_v = Vector2i(0, 0);
859
vec2_v = Vector2(2.2f, 3.5f);
860
vec2i_v = vec2_v;
861
CHECK(vec2i_v == Variant(Vector2(2.2f, 3.5f)));
862
vec2_v = Vector2(-5.4f, -7.9f);
863
vec2i_v = vec2_v;
864
CHECK(vec2i_v.get_type() == Variant::VECTOR2);
865
866
Variant vec3_v = Vector3(0, 0, 0);
867
vec2_v = Vector2(2.2f, 3.5f);
868
vec3_v = vec2_v;
869
CHECK(vec3_v == Variant(Vector2(2.2f, 3.5f)));
870
vec2_v = Vector2(-5.4f, -7.9f);
871
vec3_v = vec2_v;
872
CHECK(vec3_v.get_type() == Variant::VECTOR2);
873
874
Variant vec3i_v = Vector3i(0, 0, 0);
875
vec2_v = Vector2(2.2f, 3.5f);
876
vec3i_v = vec2_v;
877
CHECK(vec3i_v == Variant(Vector2(2.2f, 3.5f)));
878
vec2_v = Vector2(-5.4f, -7.9f);
879
vec3i_v = vec2_v;
880
CHECK(vec3i_v.get_type() == Variant::VECTOR2);
881
882
Variant vec4_v = Vector4(0, 0, 0, 0);
883
vec2_v = Vector2(2.2f, 3.5f);
884
vec4_v = vec2_v;
885
CHECK(vec4_v == Variant(Vector2(2.2f, 3.5f)));
886
vec2_v = Vector2(-5.4f, -7.9f);
887
vec4_v = vec2_v;
888
CHECK(vec4_v.get_type() == Variant::VECTOR2);
889
890
Variant vec4i_v = Vector4i(0, 0, 0, 0);
891
vec2_v = Vector2(2.2f, 3.5f);
892
vec4i_v = vec2_v;
893
CHECK(vec4i_v == Variant(Vector2(2.2f, 3.5f)));
894
vec2_v = Vector2(-5.4f, -7.9f);
895
vec4i_v = vec2_v;
896
CHECK(vec4i_v.get_type() == Variant::VECTOR2);
897
898
Variant rect2_v = Rect2();
899
vec2_v = Vector2(2.2f, 3.5f);
900
rect2_v = vec2_v;
901
CHECK(rect2_v == Variant(Vector2(2.2f, 3.5f)));
902
vec2_v = Vector2(-5.4f, -7.9f);
903
rect2_v = vec2_v;
904
CHECK(rect2_v.get_type() == Variant::VECTOR2);
905
906
Variant rect2i_v = Rect2i();
907
vec2_v = Vector2(2.2f, 3.5f);
908
rect2i_v = vec2_v;
909
CHECK(rect2i_v == Variant(Vector2(2.2f, 3.5f)));
910
vec2_v = Vector2(-5.4f, -7.9f);
911
rect2i_v = vec2_v;
912
CHECK(rect2i_v.get_type() == Variant::VECTOR2);
913
914
Variant transform2d_v = Transform2D();
915
vec2_v = Vector2(2.2f, 3.5f);
916
transform2d_v = vec2_v;
917
CHECK(transform2d_v == Variant(Vector2(2.2f, 3.5f)));
918
vec2_v = Vector2(-5.4f, -7.9f);
919
transform2d_v = vec2_v;
920
CHECK(transform2d_v.get_type() == Variant::VECTOR2);
921
922
Variant transform3d_v = Transform3D();
923
vec2_v = Vector2(2.2f, 3.5f);
924
transform3d_v = vec2_v;
925
CHECK(transform3d_v == Variant(Vector2(2.2f, 3.5f)));
926
vec2_v = Vector2(-5.4f, -7.9f);
927
transform3d_v = vec2_v;
928
CHECK(transform3d_v.get_type() == Variant::VECTOR2);
929
930
Variant col_v = Color(0.5f, 0.2f, 0.75f);
931
vec2_v = Vector2(2.2f, 3.5f);
932
col_v = vec2_v;
933
CHECK(col_v == Variant(Vector2(2.2f, 3.5f)));
934
vec2_v = Vector2(-5.4f, -7.9f);
935
col_v = vec2_v;
936
CHECK(col_v.get_type() == Variant::VECTOR2);
937
938
Variant call_v = Callable();
939
vec2_v = Vector2(2.2f, 3.5f);
940
call_v = vec2_v;
941
CHECK(call_v == Variant(Vector2(2.2f, 3.5f)));
942
vec2_v = Vector2(-5.4f, -7.9f);
943
call_v = vec2_v;
944
CHECK(call_v.get_type() == Variant::VECTOR2);
945
946
Variant plane_v = Plane();
947
vec2_v = Vector2(2.2f, 3.5f);
948
plane_v = vec2_v;
949
CHECK(plane_v == Variant(Vector2(2.2f, 3.5f)));
950
vec2_v = Vector2(-5.4f, -7.9f);
951
plane_v = vec2_v;
952
CHECK(plane_v.get_type() == Variant::VECTOR2);
953
954
Variant basis_v = Basis();
955
vec2_v = Vector2(2.2f, 3.5f);
956
basis_v = vec2_v;
957
CHECK(basis_v == Variant(Vector2(2.2f, 3.5f)));
958
vec2_v = Vector2(-5.4f, -7.9f);
959
basis_v = vec2_v;
960
CHECK(basis_v.get_type() == Variant::VECTOR2);
961
962
Variant aabb_v = AABB();
963
vec2_v = Vector2(2.2f, 3.5f);
964
aabb_v = vec2_v;
965
CHECK(aabb_v == Variant(Vector2(2.2f, 3.5f)));
966
vec2_v = Vector2(-5.4f, -7.9f);
967
aabb_v = vec2_v;
968
CHECK(aabb_v.get_type() == Variant::VECTOR2);
969
970
Variant quaternion_v = Quaternion();
971
vec2_v = Vector2(2.2f, 3.5f);
972
quaternion_v = vec2_v;
973
CHECK(quaternion_v == Variant(Vector2(2.2f, 3.5f)));
974
vec2_v = Vector2(-5.4f, -7.9f);
975
quaternion_v = vec2_v;
976
CHECK(quaternion_v.get_type() == Variant::VECTOR2);
977
978
Variant projection_v = Projection();
979
vec2_v = Vector2(2.2f, 3.5f);
980
projection_v = vec2_v;
981
CHECK(projection_v == Variant(Vector2(2.2f, 3.5f)));
982
vec2_v = Vector2(-5.4f, -7.9f);
983
projection_v = vec2_v;
984
CHECK(projection_v.get_type() == Variant::VECTOR2);
985
986
Variant rid_v = RID();
987
vec2_v = Vector2(2.2f, 3.5f);
988
rid_v = vec2_v;
989
CHECK(rid_v == Variant(Vector2(2.2f, 3.5f)));
990
vec2_v = Vector2(-5.4f, -7.9f);
991
rid_v = vec2_v;
992
CHECK(rid_v.get_type() == Variant::VECTOR2);
993
994
Object obj_one = Object();
995
Variant object_v = &obj_one;
996
vec2_v = Vector2(2.2f, 3.5f);
997
object_v = vec2_v;
998
CHECK(object_v == Variant(Vector2(2.2f, 3.5f)));
999
vec2_v = Vector2(-5.4f, -7.9f);
1000
object_v = vec2_v;
1001
CHECK(object_v.get_type() == Variant::VECTOR2);
1002
}
1003
1004
TEST_CASE("[Variant] Assignment To Vec2i from Bool,Int,Float,String,Vec2,Vec3,Vec3i,Vec4,Vec4i,Rect2,Rect2i,Trans2d,Trans3d,Color,Call,Plane,Basis,AABB,Quant,Proj,RID,and Object") {
1005
Variant bool_v = false;
1006
Variant vec2i_v = Vector2i(2, 3);
1007
bool_v = vec2i_v; // Now bool_v is Vector2i
1008
CHECK(bool_v == Variant(Vector2i(2, 3)));
1009
vec2i_v = Vector2i(-5, -7);
1010
bool_v = vec2i_v;
1011
CHECK(bool_v.get_type() == Variant::VECTOR2I);
1012
1013
Variant int_v = 0;
1014
vec2i_v = Vector2i(2, 3);
1015
int_v = vec2i_v;
1016
CHECK(int_v == Variant(Vector2i(2, 3)));
1017
vec2i_v = Vector2i(-5, -7);
1018
int_v = vec2i_v;
1019
CHECK(int_v.get_type() == Variant::VECTOR2I);
1020
1021
Variant float_v = 0.0f;
1022
vec2i_v = Vector2i(2, 3);
1023
float_v = vec2i_v;
1024
CHECK(float_v == Variant(Vector2i(2, 3)));
1025
vec2i_v = Vector2i(-5, -7);
1026
float_v = vec2i_v;
1027
CHECK(float_v.get_type() == Variant::VECTOR2I);
1028
1029
Variant string_v = "";
1030
vec2i_v = Vector2i(2, 3);
1031
string_v = vec2i_v;
1032
CHECK(string_v == Variant(Vector2i(2, 3)));
1033
vec2i_v = Vector2i(-5, -7);
1034
string_v = vec2i_v;
1035
CHECK(string_v.get_type() == Variant::VECTOR2I);
1036
1037
Variant vec2_v = Vector2(0, 0);
1038
vec2i_v = Vector2i(2, 3);
1039
vec2_v = vec2i_v;
1040
CHECK(vec2_v == Variant(Vector2i(2, 3)));
1041
vec2i_v = Vector2i(-5, -7);
1042
vec2_v = vec2i_v;
1043
CHECK(vec2i_v.get_type() == Variant::VECTOR2I);
1044
1045
Variant vec3_v = Vector3(0, 0, 0);
1046
vec2i_v = Vector2i(2, 3);
1047
vec3_v = vec2i_v;
1048
CHECK(vec3_v == Variant(Vector2i(2, 3)));
1049
vec2i_v = Vector2i(-5, -7);
1050
vec3_v = vec2i_v;
1051
CHECK(vec3_v.get_type() == Variant::VECTOR2I);
1052
1053
Variant vec3i_v = Vector3i(0, 0, 0);
1054
vec2i_v = Vector2i(2, 3);
1055
vec3i_v = vec2i_v;
1056
CHECK(vec3i_v == Variant(Vector2i(2, 3)));
1057
vec2i_v = Vector2i(-5, -7);
1058
vec3i_v = vec2i_v;
1059
CHECK(vec3i_v.get_type() == Variant::VECTOR2I);
1060
1061
Variant vec4_v = Vector4(0, 0, 0, 0);
1062
vec2i_v = Vector2i(2, 3);
1063
vec4_v = vec2i_v;
1064
CHECK(vec4_v == Variant(Vector2i(2, 3)));
1065
vec2i_v = Vector2i(-5, -7);
1066
vec4_v = vec2i_v;
1067
CHECK(vec4_v.get_type() == Variant::VECTOR2I);
1068
1069
Variant vec4i_v = Vector4i(0, 0, 0, 0);
1070
vec2i_v = Vector2i(2, 3);
1071
vec4i_v = vec2i_v;
1072
CHECK(vec4i_v == Variant(Vector2i(2, 3)));
1073
vec2i_v = Vector2i(-5, -7);
1074
vec4i_v = vec2i_v;
1075
CHECK(vec4i_v.get_type() == Variant::VECTOR2I);
1076
1077
Variant rect2_v = Rect2();
1078
vec2i_v = Vector2i(2, 3);
1079
rect2_v = vec2i_v;
1080
CHECK(rect2_v == Variant(Vector2i(2, 3)));
1081
vec2i_v = Vector2i(-5, -7);
1082
rect2_v = vec2i_v;
1083
CHECK(rect2_v.get_type() == Variant::VECTOR2I);
1084
1085
Variant rect2i_v = Rect2i();
1086
vec2i_v = Vector2i(2, 3);
1087
rect2i_v = vec2i_v;
1088
CHECK(rect2i_v == Variant(Vector2i(2, 3)));
1089
vec2i_v = Vector2i(-5, -7);
1090
rect2i_v = vec2i_v;
1091
CHECK(rect2i_v.get_type() == Variant::VECTOR2I);
1092
1093
Variant transform2d_v = Transform2D();
1094
vec2i_v = Vector2i(2, 3);
1095
transform2d_v = vec2i_v;
1096
CHECK(transform2d_v == Variant(Vector2i(2, 3)));
1097
vec2i_v = Vector2i(-5, -7);
1098
transform2d_v = vec2i_v;
1099
CHECK(transform2d_v.get_type() == Variant::VECTOR2I);
1100
1101
Variant transform3d_v = Transform3D();
1102
vec2i_v = Vector2i(2, 3);
1103
transform3d_v = vec2i_v;
1104
CHECK(transform3d_v == Variant(Vector2i(2, 3)));
1105
vec2i_v = Vector2i(-5, -7);
1106
transform3d_v = vec2i_v;
1107
CHECK(transform3d_v.get_type() == Variant::VECTOR2I);
1108
1109
Variant col_v = Color(0.5f, 0.2f, 0.75f);
1110
vec2i_v = Vector2i(2, 3);
1111
col_v = vec2i_v;
1112
CHECK(col_v == Variant(Vector2i(2, 3)));
1113
vec2i_v = Vector2i(-5, -7);
1114
col_v = vec2i_v;
1115
CHECK(col_v.get_type() == Variant::VECTOR2I);
1116
1117
Variant call_v = Callable();
1118
vec2i_v = Vector2i(2, 3);
1119
call_v = vec2i_v;
1120
CHECK(call_v == Variant(Vector2i(2, 3)));
1121
vec2i_v = Vector2i(-5, -7);
1122
call_v = vec2i_v;
1123
CHECK(call_v.get_type() == Variant::VECTOR2I);
1124
1125
Variant plane_v = Plane();
1126
vec2i_v = Vector2i(2, 3);
1127
plane_v = vec2i_v;
1128
CHECK(plane_v == Variant(Vector2i(2, 3)));
1129
vec2i_v = Vector2i(-5, -7);
1130
plane_v = vec2i_v;
1131
CHECK(plane_v.get_type() == Variant::VECTOR2I);
1132
1133
Variant basis_v = Basis();
1134
vec2i_v = Vector2i(2, 3);
1135
basis_v = vec2i_v;
1136
CHECK(basis_v == Variant(Vector2i(2, 3)));
1137
vec2i_v = Vector2i(-5, -7);
1138
basis_v = vec2i_v;
1139
CHECK(basis_v.get_type() == Variant::VECTOR2I);
1140
1141
Variant aabb_v = AABB();
1142
vec2i_v = Vector2i(2, 3);
1143
aabb_v = vec2i_v;
1144
CHECK(aabb_v == Variant(Vector2i(2, 3)));
1145
vec2i_v = Vector2i(-5, -7);
1146
aabb_v = vec2i_v;
1147
CHECK(aabb_v.get_type() == Variant::VECTOR2I);
1148
1149
Variant quaternion_v = Quaternion();
1150
vec2i_v = Vector2i(2, 3);
1151
quaternion_v = vec2i_v;
1152
CHECK(quaternion_v == Variant(Vector2i(2, 3)));
1153
vec2i_v = Vector2i(-5, -7);
1154
quaternion_v = vec2i_v;
1155
CHECK(quaternion_v.get_type() == Variant::VECTOR2I);
1156
1157
Variant projection_v = Projection();
1158
vec2i_v = Vector2i(2, 3);
1159
projection_v = vec2i_v;
1160
CHECK(projection_v == Variant(Vector2i(2, 3)));
1161
vec2i_v = Vector2i(-5, -7);
1162
projection_v = vec2i_v;
1163
CHECK(projection_v.get_type() == Variant::VECTOR2I);
1164
1165
Variant rid_v = RID();
1166
vec2i_v = Vector2i(2, 3);
1167
rid_v = vec2i_v;
1168
CHECK(rid_v == Variant(Vector2i(2, 3)));
1169
vec2i_v = Vector2i(-5, -7);
1170
rid_v = vec2i_v;
1171
CHECK(rid_v.get_type() == Variant::VECTOR2I);
1172
1173
Object obj_one = Object();
1174
Variant object_v = &obj_one;
1175
vec2i_v = Vector2i(2, 3);
1176
object_v = vec2i_v;
1177
CHECK(object_v == Variant(Vector2i(2, 3)));
1178
vec2i_v = Vector2i(-5, -7);
1179
object_v = vec2i_v;
1180
CHECK(object_v.get_type() == Variant::VECTOR2I);
1181
}
1182
1183
TEST_CASE("[Variant] Assignment To Vec3 from Bool,Int,Float,String,Vec2,Vec2i,Vec3i,Vec4,Vec4i,Rect2,Rect2i,Trans2d,Trans3d,Color,Call,Plane,Basis,AABB,Quant,Proj,RID,and Object") {
1184
Variant bool_v = false;
1185
Variant vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1186
bool_v = vec3_v; // Now bool_v is Vector3
1187
CHECK(bool_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1188
vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1189
bool_v = vec3_v;
1190
CHECK(bool_v.get_type() == Variant::VECTOR3);
1191
1192
Variant int_v = 0;
1193
vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1194
int_v = vec3_v;
1195
CHECK(int_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1196
vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1197
int_v = vec3_v;
1198
CHECK(int_v.get_type() == Variant::VECTOR3);
1199
1200
Variant float_v = 0.0f;
1201
vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1202
float_v = vec3_v;
1203
CHECK(float_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1204
vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1205
float_v = vec3_v;
1206
CHECK(float_v.get_type() == Variant::VECTOR3);
1207
1208
Variant string_v = "";
1209
vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1210
string_v = vec3_v;
1211
CHECK(string_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1212
vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1213
string_v = vec3_v;
1214
CHECK(string_v.get_type() == Variant::VECTOR3);
1215
1216
Variant vec2_v = Vector2(0, 0);
1217
vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1218
vec2_v = vec3_v;
1219
CHECK(vec2_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1220
vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1221
vec2_v = vec3_v;
1222
CHECK(vec2_v.get_type() == Variant::VECTOR3);
1223
1224
Variant vec2i_v = Vector2i(0, 0);
1225
vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1226
vec2i_v = vec3_v;
1227
CHECK(vec2i_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1228
vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1229
vec2i_v = vec3_v;
1230
CHECK(vec2i_v.get_type() == Variant::VECTOR3);
1231
1232
Variant vec3i_v = Vector3i(0, 0, 0);
1233
vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1234
vec3i_v = vec3_v;
1235
CHECK(vec3i_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1236
vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1237
vec3i_v = vec3_v;
1238
CHECK(vec3i_v.get_type() == Variant::VECTOR3);
1239
1240
Variant vec4_v = Vector4(0, 0, 0, 0);
1241
vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1242
vec4_v = vec3_v;
1243
CHECK(vec4_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1244
vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1245
vec4_v = vec3_v;
1246
CHECK(vec4_v.get_type() == Variant::VECTOR3);
1247
1248
Variant vec4i_v = Vector4i(0, 0, 0, 0);
1249
vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1250
vec4i_v = vec3_v;
1251
CHECK(vec4i_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1252
vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1253
vec4i_v = vec3_v;
1254
CHECK(vec4i_v.get_type() == Variant::VECTOR3);
1255
1256
Variant rect2_v = Rect2();
1257
vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1258
rect2_v = vec3_v;
1259
CHECK(rect2_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1260
vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1261
rect2_v = vec3_v;
1262
CHECK(rect2_v.get_type() == Variant::VECTOR3);
1263
1264
Variant rect2i_v = Rect2i();
1265
vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1266
rect2i_v = vec3_v;
1267
CHECK(rect2i_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1268
vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1269
rect2i_v = vec3_v;
1270
CHECK(rect2i_v.get_type() == Variant::VECTOR3);
1271
1272
Variant transform2d_v = Transform2D();
1273
vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1274
transform2d_v = vec3_v;
1275
CHECK(transform2d_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1276
vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1277
transform2d_v = vec3_v;
1278
CHECK(transform2d_v.get_type() == Variant::VECTOR3);
1279
1280
Variant transform3d_v = Transform3D();
1281
vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1282
transform3d_v = vec3_v;
1283
CHECK(transform3d_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1284
vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1285
transform3d_v = vec3_v;
1286
CHECK(transform3d_v.get_type() == Variant::VECTOR3);
1287
1288
Variant col_v = Color(0.5f, 0.2f, 0.75f);
1289
vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1290
col_v = vec3_v;
1291
CHECK(col_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1292
vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1293
col_v = vec3_v;
1294
CHECK(col_v.get_type() == Variant::VECTOR3);
1295
1296
Variant call_v = Callable();
1297
vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1298
call_v = vec3_v;
1299
CHECK(call_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1300
vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1301
call_v = vec3_v;
1302
CHECK(call_v.get_type() == Variant::VECTOR3);
1303
1304
Variant plane_v = Plane();
1305
vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1306
plane_v = vec3_v;
1307
CHECK(plane_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1308
vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1309
plane_v = vec3_v;
1310
CHECK(plane_v.get_type() == Variant::VECTOR3);
1311
1312
Variant basis_v = Basis();
1313
vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1314
basis_v = vec3_v;
1315
CHECK(basis_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1316
vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1317
basis_v = vec3_v;
1318
CHECK(basis_v.get_type() == Variant::VECTOR3);
1319
1320
Variant aabb_v = AABB();
1321
vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1322
aabb_v = vec3_v;
1323
CHECK(aabb_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1324
vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1325
aabb_v = vec3_v;
1326
CHECK(aabb_v.get_type() == Variant::VECTOR3);
1327
1328
Variant quaternion_v = Quaternion();
1329
vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1330
quaternion_v = vec3_v;
1331
CHECK(quaternion_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1332
vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1333
quaternion_v = vec3_v;
1334
CHECK(quaternion_v.get_type() == Variant::VECTOR3);
1335
1336
Variant projection_v = Projection();
1337
vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1338
quaternion_v = vec3_v;
1339
CHECK(quaternion_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1340
vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1341
quaternion_v = vec3_v;
1342
CHECK(quaternion_v.get_type() == Variant::VECTOR3);
1343
1344
Variant rid_v = RID();
1345
vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1346
rid_v = vec3_v;
1347
CHECK(rid_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1348
vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1349
rid_v = vec3_v;
1350
CHECK(rid_v.get_type() == Variant::VECTOR3);
1351
1352
Object obj_one = Object();
1353
Variant object_v = &obj_one;
1354
vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1355
object_v = vec3_v;
1356
CHECK(object_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1357
vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1358
object_v = vec3_v;
1359
CHECK(object_v.get_type() == Variant::VECTOR3);
1360
}
1361
1362
TEST_CASE("[Variant] Assignment To Vec3i from Bool,Int,Float,String,Vec2,Vec2i,Vec3 and Color") {
1363
Variant bool_v = false;
1364
Variant vec3i_v = Vector3i(2, 3, 5);
1365
bool_v = vec3i_v; // Now bool_v is Vector3i
1366
CHECK(bool_v == Variant(Vector3i(2, 3, 5)));
1367
vec3i_v = Vector3i(-5, -7, -2);
1368
bool_v = vec3i_v;
1369
CHECK(bool_v.get_type() == Variant::VECTOR3I);
1370
1371
Variant int_v = 0;
1372
vec3i_v = Vector3i(2, 3, 5);
1373
int_v = vec3i_v;
1374
CHECK(int_v == Variant(Vector3i(2, 3, 5)));
1375
vec3i_v = Vector3i(-5, -7, -2);
1376
int_v = vec3i_v;
1377
CHECK(int_v.get_type() == Variant::VECTOR3I);
1378
1379
Variant float_v = 0.0f;
1380
vec3i_v = Vector3i(2, 3, 5);
1381
float_v = vec3i_v;
1382
CHECK(float_v == Variant(Vector3i(2, 3, 5)));
1383
vec3i_v = Vector3i(-5, -7, -2);
1384
float_v = vec3i_v;
1385
CHECK(float_v.get_type() == Variant::VECTOR3I);
1386
1387
Variant string_v = "";
1388
vec3i_v = Vector3i(2, 3, 5);
1389
string_v = vec3i_v;
1390
CHECK(string_v == Variant(Vector3i(2, 3, 5)));
1391
vec3i_v = Vector3i(-5, -7, -2);
1392
string_v = vec3i_v;
1393
CHECK(string_v.get_type() == Variant::VECTOR3I);
1394
1395
Variant vec2_v = Vector2(0, 0);
1396
vec3i_v = Vector3i(2, 3, 5);
1397
vec2_v = vec3i_v;
1398
CHECK(vec2_v == Variant(Vector3i(2, 3, 5)));
1399
vec3i_v = Vector3i(-5, -7, -2);
1400
vec2_v = vec3i_v;
1401
CHECK(vec2_v.get_type() == Variant::VECTOR3I);
1402
1403
Variant vec2i_v = Vector2i(0, 0);
1404
vec3i_v = Vector3i(2, 3, 5);
1405
vec2i_v = vec3i_v;
1406
CHECK(vec2i_v == Variant(Vector3i(2, 3, 5)));
1407
vec3i_v = Vector3i(-5, -7, -2);
1408
vec2i_v = vec3i_v;
1409
CHECK(vec2i_v.get_type() == Variant::VECTOR3I);
1410
1411
Variant vec3_v = Vector3(0, 0, 0);
1412
vec3i_v = Vector3i(2, 3, 5);
1413
vec3_v = vec3i_v;
1414
CHECK(vec3_v == Variant(Vector3i(2, 3, 5)));
1415
vec3i_v = Vector3i(-5, -7, -2);
1416
vec3_v = vec3i_v;
1417
CHECK(vec3_v.get_type() == Variant::VECTOR3I);
1418
1419
Variant vec4_v = Vector4(0, 0, 0, 0);
1420
vec3i_v = Vector3i(2, 3, 5);
1421
vec4_v = vec3i_v;
1422
CHECK(vec4_v == Variant(Vector3i(2, 3, 5)));
1423
vec3i_v = Vector3i(-5, -7, -2);
1424
vec4_v = vec3i_v;
1425
CHECK(vec4_v.get_type() == Variant::VECTOR3I);
1426
1427
Variant vec4i_v = Vector4i(0, 0, 0, 0);
1428
vec3i_v = Vector3i(2, 3, 5);
1429
vec4i_v = vec3i_v;
1430
CHECK(vec4i_v == Variant(Vector3i(2, 3, 5)));
1431
vec3i_v = Vector3i(-5, -7, -2);
1432
vec4i_v = vec3i_v;
1433
CHECK(vec4i_v.get_type() == Variant::VECTOR3I);
1434
1435
Variant rect2_v = Rect2();
1436
vec3i_v = Vector3i(2, 3, 5);
1437
rect2_v = vec3i_v;
1438
CHECK(rect2_v == Variant(Vector3i(2, 3, 5)));
1439
vec3i_v = Vector3i(-5, -7, -2);
1440
rect2_v = vec3i_v;
1441
CHECK(rect2_v.get_type() == Variant::VECTOR3I);
1442
1443
Variant rect2i_v = Rect2i();
1444
vec3i_v = Vector3i(2, 3, 5);
1445
rect2i_v = vec3i_v;
1446
CHECK(rect2i_v == Variant(Vector3i(2, 3, 5)));
1447
vec3i_v = Vector3i(-5, -7, -2);
1448
rect2i_v = vec3i_v;
1449
CHECK(rect2i_v.get_type() == Variant::VECTOR3I);
1450
1451
Variant transform2d_v = Transform2D();
1452
vec3i_v = Vector3i(2, 3, 5);
1453
transform2d_v = vec3i_v;
1454
CHECK(transform2d_v == Variant(Vector3i(2, 3, 5)));
1455
vec3i_v = Vector3i(-5, -7, -2);
1456
transform2d_v = vec3i_v;
1457
CHECK(transform2d_v.get_type() == Variant::VECTOR3I);
1458
1459
Variant transform3d_v = Transform3D();
1460
vec3i_v = Vector3i(2, 3, 5);
1461
transform3d_v = vec3i_v;
1462
CHECK(transform3d_v == Variant(Vector3i(2, 3, 5)));
1463
vec3i_v = Vector3i(-5, -7, -2);
1464
transform3d_v = vec3i_v;
1465
CHECK(transform3d_v.get_type() == Variant::VECTOR3I);
1466
1467
Variant col_v = Color(0.5f, 0.2f, 0.75f);
1468
vec3i_v = Vector3i(2, 3, 5);
1469
col_v = vec3i_v;
1470
CHECK(col_v == Variant(Vector3i(2, 3, 5)));
1471
vec3i_v = Vector3i(-5, -7, -2);
1472
col_v = vec3i_v;
1473
CHECK(col_v.get_type() == Variant::VECTOR3I);
1474
1475
Variant call_v = Callable();
1476
vec3i_v = Vector3i(2, 3, 5);
1477
call_v = vec3i_v;
1478
CHECK(call_v == Variant(Vector3i(2, 3, 5)));
1479
vec3i_v = Vector3i(-5, -7, -2);
1480
call_v = vec3i_v;
1481
CHECK(call_v.get_type() == Variant::VECTOR3I);
1482
1483
Variant plane_v = Plane();
1484
vec3i_v = Vector3i(2, 3, 5);
1485
plane_v = vec3i_v;
1486
CHECK(plane_v == Variant(Vector3i(2, 3, 5)));
1487
vec3i_v = Vector3i(-5, -7, -2);
1488
plane_v = vec3i_v;
1489
CHECK(plane_v.get_type() == Variant::VECTOR3I);
1490
1491
Variant basis_v = Basis();
1492
vec3i_v = Vector3i(2, 3, 5);
1493
basis_v = vec3i_v;
1494
CHECK(basis_v == Variant(Vector3i(2, 3, 5)));
1495
vec3i_v = Vector3i(-5, -7, -2);
1496
basis_v = vec3i_v;
1497
CHECK(basis_v.get_type() == Variant::VECTOR3I);
1498
1499
Variant aabb_v = AABB();
1500
vec3i_v = Vector3i(2, 3, 5);
1501
aabb_v = vec3i_v;
1502
CHECK(aabb_v == Variant(Vector3i(2, 3, 5)));
1503
vec3i_v = Vector3i(-5, -7, -2);
1504
aabb_v = vec3i_v;
1505
CHECK(aabb_v.get_type() == Variant::VECTOR3I);
1506
1507
Variant quaternion_v = Quaternion();
1508
vec3i_v = Vector3i(2, 3, 5);
1509
quaternion_v = vec3i_v;
1510
CHECK(quaternion_v == Variant(Vector3i(2, 3, 5)));
1511
vec3i_v = Vector3i(-5, -7, -2);
1512
quaternion_v = vec3i_v;
1513
CHECK(quaternion_v.get_type() == Variant::VECTOR3I);
1514
1515
Variant projection_v = Projection();
1516
vec3i_v = Vector3i(2, 3, 5);
1517
projection_v = vec3i_v;
1518
CHECK(projection_v == Variant(Vector3i(2, 3, 5)));
1519
vec3i_v = Vector3i(-5, -7, -2);
1520
projection_v = vec3i_v;
1521
CHECK(projection_v.get_type() == Variant::VECTOR3I);
1522
1523
Variant rid_v = RID();
1524
vec3i_v = Vector3i(2, 3, 5);
1525
rid_v = vec3i_v;
1526
CHECK(rid_v == Variant(Vector3i(2, 3, 5)));
1527
vec3i_v = Vector3i(-5, -7, -2);
1528
rid_v = vec3i_v;
1529
CHECK(rid_v.get_type() == Variant::VECTOR3I);
1530
1531
Object obj_one = Object();
1532
Variant object_v = &obj_one;
1533
vec3i_v = Vector3i(2, 3, 5);
1534
object_v = vec3i_v;
1535
CHECK(object_v == Variant(Vector3i(2, 3, 5)));
1536
vec3i_v = Vector3i(-5, -7, -2);
1537
object_v = vec3i_v;
1538
CHECK(object_v.get_type() == Variant::VECTOR3I);
1539
}
1540
1541
TEST_CASE("[Variant] Assignment To Color from Bool,Int,Float,String,Vec2,Vec2i,Vec3,Vec3i,Vec4,Vec4i,Rect2,Rect2i,Trans2d,Trans3d,Color,Call,Plane,Basis,AABB,Quant,Proj,RID,and Object") {
1542
Variant bool_v = false;
1543
Variant col_v = Color(0.25f, 0.4f, 0.78f);
1544
bool_v = col_v; // Now bool_v is Color
1545
CHECK(bool_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1546
col_v = Color(0.33f, 0.75f, 0.21f);
1547
bool_v = col_v;
1548
CHECK(bool_v.get_type() == Variant::COLOR);
1549
1550
Variant int_v = 0;
1551
col_v = Color(0.25f, 0.4f, 0.78f);
1552
int_v = col_v;
1553
CHECK(int_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1554
col_v = Color(0.33f, 0.75f, 0.21f);
1555
int_v = col_v;
1556
CHECK(int_v.get_type() == Variant::COLOR);
1557
1558
Variant float_v = 0.0f;
1559
col_v = Color(0.25f, 0.4f, 0.78f);
1560
float_v = col_v;
1561
CHECK(float_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1562
col_v = Color(0.33f, 0.75f, 0.21f);
1563
float_v = col_v;
1564
CHECK(float_v.get_type() == Variant::COLOR);
1565
1566
Variant string_v = "";
1567
col_v = Color(0.25f, 0.4f, 0.78f);
1568
string_v = col_v;
1569
CHECK(string_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1570
col_v = Color(0.33f, 0.75f, 0.21f);
1571
string_v = col_v;
1572
CHECK(string_v.get_type() == Variant::COLOR);
1573
1574
Variant vec2_v = Vector2(0, 0);
1575
col_v = Color(0.25f, 0.4f, 0.78f);
1576
vec2_v = col_v;
1577
CHECK(vec2_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1578
col_v = Color(0.33f, 0.75f, 0.21f);
1579
vec2_v = col_v;
1580
CHECK(vec2_v.get_type() == Variant::COLOR);
1581
1582
Variant vec2i_v = Vector2i(0, 0);
1583
col_v = Color(0.25f, 0.4f, 0.78f);
1584
vec2i_v = col_v;
1585
CHECK(vec2i_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1586
col_v = Color(0.33f, 0.75f, 0.21f);
1587
vec2i_v = col_v;
1588
CHECK(vec2i_v.get_type() == Variant::COLOR);
1589
1590
Variant vec3_v = Vector3(0, 0, 0);
1591
col_v = Color(0.25f, 0.4f, 0.78f);
1592
vec3_v = col_v;
1593
CHECK(vec3_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1594
col_v = Color(0.33f, 0.75f, 0.21f);
1595
vec3_v = col_v;
1596
CHECK(vec3_v.get_type() == Variant::COLOR);
1597
1598
Variant vec3i_v = Vector3i(0, 0, 0);
1599
col_v = Color(0.25f, 0.4f, 0.78f);
1600
vec3i_v = col_v;
1601
CHECK(vec3i_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1602
col_v = Color(0.33f, 0.75f, 0.21f);
1603
vec3i_v = col_v;
1604
CHECK(vec3i_v.get_type() == Variant::COLOR);
1605
1606
Variant vec4_v = Vector4(0, 0, 0, 0);
1607
col_v = Color(0.25f, 0.4f, 0.78f);
1608
vec4_v = col_v;
1609
CHECK(vec4_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1610
col_v = Color(0.33f, 0.75f, 0.21f);
1611
vec4_v = col_v;
1612
CHECK(vec4_v.get_type() == Variant::COLOR);
1613
1614
Variant vec4i_v = Vector4i(0, 0, 0, 0);
1615
col_v = Color(0.25f, 0.4f, 0.78f);
1616
vec4i_v = col_v;
1617
CHECK(vec4i_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1618
col_v = Color(0.33f, 0.75f, 0.21f);
1619
vec4i_v = col_v;
1620
CHECK(vec4i_v.get_type() == Variant::COLOR);
1621
1622
Variant rect2_v = Rect2();
1623
col_v = Color(0.25f, 0.4f, 0.78f);
1624
rect2_v = col_v;
1625
CHECK(rect2_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1626
col_v = Color(0.33f, 0.75f, 0.21f);
1627
rect2_v = col_v;
1628
CHECK(rect2_v.get_type() == Variant::COLOR);
1629
1630
Variant rect2i_v = Rect2i();
1631
col_v = Color(0.25f, 0.4f, 0.78f);
1632
rect2i_v = col_v;
1633
CHECK(rect2i_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1634
col_v = Color(0.33f, 0.75f, 0.21f);
1635
rect2i_v = col_v;
1636
CHECK(rect2i_v.get_type() == Variant::COLOR);
1637
1638
Variant transform2d_v = Transform2D();
1639
col_v = Color(0.25f, 0.4f, 0.78f);
1640
transform2d_v = col_v;
1641
CHECK(transform2d_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1642
col_v = Color(0.33f, 0.75f, 0.21f);
1643
transform2d_v = col_v;
1644
CHECK(transform2d_v.get_type() == Variant::COLOR);
1645
1646
Variant transform3d_v = Transform3D();
1647
col_v = Color(0.25f, 0.4f, 0.78f);
1648
transform3d_v = col_v;
1649
CHECK(transform3d_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1650
col_v = Color(0.33f, 0.75f, 0.21f);
1651
transform3d_v = col_v;
1652
CHECK(transform3d_v.get_type() == Variant::COLOR);
1653
1654
Variant call_v = Callable();
1655
col_v = Color(0.25f, 0.4f, 0.78f);
1656
call_v = col_v;
1657
CHECK(call_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1658
col_v = Color(0.33f, 0.75f, 0.21f);
1659
call_v = col_v;
1660
CHECK(call_v.get_type() == Variant::COLOR);
1661
1662
Variant plane_v = Plane();
1663
col_v = Color(0.25f, 0.4f, 0.78f);
1664
plane_v = col_v;
1665
CHECK(plane_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1666
col_v = Color(0.33f, 0.75f, 0.21f);
1667
plane_v = col_v;
1668
CHECK(plane_v.get_type() == Variant::COLOR);
1669
1670
Variant basis_v = Basis();
1671
col_v = Color(0.25f, 0.4f, 0.78f);
1672
basis_v = col_v;
1673
CHECK(basis_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1674
col_v = Color(0.33f, 0.75f, 0.21f);
1675
basis_v = col_v;
1676
CHECK(basis_v.get_type() == Variant::COLOR);
1677
1678
Variant aabb_v = AABB();
1679
col_v = Color(0.25f, 0.4f, 0.78f);
1680
aabb_v = col_v;
1681
CHECK(aabb_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1682
col_v = Color(0.33f, 0.75f, 0.21f);
1683
aabb_v = col_v;
1684
CHECK(aabb_v.get_type() == Variant::COLOR);
1685
1686
Variant quaternion_v = Quaternion();
1687
col_v = Color(0.25f, 0.4f, 0.78f);
1688
quaternion_v = col_v;
1689
CHECK(quaternion_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1690
col_v = Color(0.33f, 0.75f, 0.21f);
1691
quaternion_v = col_v;
1692
CHECK(quaternion_v.get_type() == Variant::COLOR);
1693
1694
Variant projection_v = Projection();
1695
col_v = Color(0.25f, 0.4f, 0.78f);
1696
projection_v = col_v;
1697
CHECK(projection_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1698
col_v = Color(0.33f, 0.75f, 0.21f);
1699
projection_v = col_v;
1700
CHECK(projection_v.get_type() == Variant::COLOR);
1701
1702
Variant rid_v = RID();
1703
col_v = Color(0.25f, 0.4f, 0.78f);
1704
rid_v = col_v;
1705
CHECK(rid_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1706
col_v = Color(0.33f, 0.75f, 0.21f);
1707
rid_v = col_v;
1708
CHECK(rid_v.get_type() == Variant::COLOR);
1709
1710
Object obj_one = Object();
1711
Variant object_v = &obj_one;
1712
col_v = Color(0.25f, 0.4f, 0.78f);
1713
object_v = col_v;
1714
CHECK(object_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1715
col_v = Color(0.33f, 0.75f, 0.21f);
1716
object_v = col_v;
1717
CHECK(object_v.get_type() == Variant::COLOR);
1718
}
1719
1720
TEST_CASE("[Variant] array initializer list") {
1721
Variant arr_v = { 0, 1, "test", true, { 0.0, 1.0 } };
1722
CHECK(arr_v.get_type() == Variant::ARRAY);
1723
Array arr = (Array)arr_v;
1724
CHECK(arr.size() == 5);
1725
CHECK(arr[0] == Variant(0));
1726
CHECK(arr[1] == Variant(1));
1727
CHECK(arr[2] == Variant("test"));
1728
CHECK(arr[3] == Variant(true));
1729
CHECK(arr[4] == Variant({ 0.0, 1.0 }));
1730
1731
PackedInt32Array packed_arr = { 2, 1, 0 };
1732
CHECK(packed_arr.size() == 3);
1733
CHECK(packed_arr[0] == 2);
1734
CHECK(packed_arr[1] == 1);
1735
CHECK(packed_arr[2] == 0);
1736
}
1737
1738
TEST_CASE("[Variant] Writer and parser Vector2") {
1739
Variant vec2_parsed;
1740
String vec2_str;
1741
String errs;
1742
int line;
1743
// Variant::VECTOR2 and Vector2 can be either 32-bit or 64-bit depending on the precision level of real_t.
1744
{
1745
Vector2 vec2 = Vector2(1.2, 3.4);
1746
VariantWriter::write_to_string(vec2, vec2_str);
1747
// Reminder: "1.2" and "3.4" are not exactly those decimal numbers. They are the closest float to them.
1748
CHECK_MESSAGE(vec2_str == "Vector2(1.2, 3.4)", "Should write with enough digits to ensure parsing back is exact.");
1749
VariantParser::StreamString stream;
1750
stream.s = vec2_str;
1751
VariantParser::parse(&stream, vec2_parsed, errs, line);
1752
CHECK_MESSAGE(Vector2(vec2_parsed) == vec2, "Should parse back to the same Vector2.");
1753
}
1754
// Check with big numbers and small numbers.
1755
{
1756
Vector2 vec2 = Vector2(1.234567898765432123456789e30, 1.234567898765432123456789e-10);
1757
VariantWriter::write_to_string(vec2, vec2_str);
1758
#ifdef REAL_T_IS_DOUBLE
1759
CHECK_MESSAGE(vec2_str == "Vector2(1.2345678987654322e+30, 1.2345678987654322e-10)", "Should write with enough digits to ensure parsing back is exact.");
1760
#else
1761
CHECK_MESSAGE(vec2_str == "Vector2(1.2345679e+30, 1.2345679e-10)", "Should write with enough digits to ensure parsing back is exact.");
1762
#endif
1763
VariantParser::StreamString stream;
1764
stream.s = vec2_str;
1765
VariantParser::parse(&stream, vec2_parsed, errs, line);
1766
CHECK_MESSAGE(Vector2(vec2_parsed) == vec2, "Should parse back to the same Vector2.");
1767
}
1768
}
1769
1770
TEST_CASE("[Variant] Writer and parser array") {
1771
Array a = { 1, String("hello"), Array({ Variant() }) };
1772
String a_str;
1773
VariantWriter::write_to_string(a, a_str);
1774
1775
CHECK_EQ(a_str, "[1, \"hello\", [null]]");
1776
1777
VariantParser::StreamString ss;
1778
String errs;
1779
int line;
1780
Variant a_parsed;
1781
1782
ss.s = a_str;
1783
VariantParser::parse(&ss, a_parsed, errs, line);
1784
1785
CHECK_MESSAGE(a_parsed == Variant(a), "Should parse back.");
1786
}
1787
1788
TEST_CASE("[Variant] Writer recursive array") {
1789
// There is no way to accurately represent a recursive array,
1790
// the only thing we can do is make sure the writer doesn't blow up
1791
1792
// Self recursive
1793
Array a;
1794
a.push_back(a);
1795
1796
// Writer should it recursion limit while visiting the array
1797
ERR_PRINT_OFF;
1798
String a_str;
1799
VariantWriter::write_to_string(a, a_str);
1800
ERR_PRINT_ON;
1801
1802
// Nested recursive
1803
Array a1;
1804
Array a2;
1805
a1.push_back(a2);
1806
a2.push_back(a1);
1807
1808
// Writer should it recursion limit while visiting the array
1809
ERR_PRINT_OFF;
1810
String a1_str;
1811
VariantWriter::write_to_string(a1, a1_str);
1812
ERR_PRINT_ON;
1813
1814
// Break the recursivity otherwise Dictionary tearndown will leak memory
1815
a.clear();
1816
a1.clear();
1817
a2.clear();
1818
}
1819
1820
TEST_CASE("[Variant] Writer and parser dictionary") {
1821
// d = {{1: 2}: 3, 4: "hello", 5: {null: []}}
1822
Dictionary d = { { Dictionary({ { 1, 2 } }), 3 }, { 4, String("hello") }, { 5, Dictionary({ { Variant(), Array() } }) } };
1823
String d_str;
1824
VariantWriter::write_to_string(d, d_str);
1825
1826
CHECK_EQ(d_str, "{\n4: \"hello\",\n5: {\nnull: []\n},\n{\n1: 2\n}: 3\n}");
1827
1828
VariantParser::StreamString ss;
1829
String errs;
1830
int line;
1831
Variant d_parsed;
1832
1833
ss.s = d_str;
1834
VariantParser::parse(&ss, d_parsed, errs, line);
1835
1836
CHECK_MESSAGE(d_parsed == Variant(d), "Should parse back.");
1837
}
1838
1839
TEST_CASE("[Variant] Writer key sorting") {
1840
Dictionary d = { { StringName("C"), 3 }, { "A", 1 }, { StringName("B"), 2 }, { "D", 4 } };
1841
String d_str;
1842
VariantWriter::write_to_string(d, d_str);
1843
1844
CHECK_EQ(d_str, "{\n\"A\": 1,\n&\"B\": 2,\n&\"C\": 3,\n\"D\": 4\n}");
1845
}
1846
1847
TEST_CASE("[Variant] Writer recursive dictionary") {
1848
// There is no way to accurately represent a recursive dictionary,
1849
// the only thing we can do is make sure the writer doesn't blow up
1850
1851
// Self recursive
1852
Dictionary d;
1853
d[1] = d;
1854
1855
// Writer should it recursion limit while visiting the dictionary
1856
ERR_PRINT_OFF;
1857
String d_str;
1858
VariantWriter::write_to_string(d, d_str);
1859
ERR_PRINT_ON;
1860
1861
// Nested recursive
1862
Dictionary d1;
1863
Dictionary d2;
1864
d1[2] = d2;
1865
d2[1] = d1;
1866
1867
// Writer should it recursion limit while visiting the dictionary
1868
ERR_PRINT_OFF;
1869
String d1_str;
1870
VariantWriter::write_to_string(d1, d1_str);
1871
ERR_PRINT_ON;
1872
1873
// Break the recursivity otherwise Dictionary tearndown will leak memory
1874
d.clear();
1875
d1.clear();
1876
d2.clear();
1877
}
1878
1879
#if 0 // TODO: recursion in dict key is currently buggy
1880
TEST_CASE("[Variant] Writer recursive dictionary on keys") {
1881
// There is no way to accurately represent a recursive dictionary,
1882
// the only thing we can do is make sure the writer doesn't blow up
1883
1884
// Self recursive
1885
Dictionary d;
1886
d[d] = 1;
1887
1888
// Writer should it recursion limit while visiting the dictionary
1889
ERR_PRINT_OFF;
1890
String d_str;
1891
VariantWriter::write_to_string(d, d_str);
1892
ERR_PRINT_ON;
1893
1894
// Nested recursive
1895
Dictionary d1;
1896
Dictionary d2;
1897
d1[d2] = 2;
1898
d2[d1] = 1;
1899
1900
// Writer should it recursion limit while visiting the dictionary
1901
ERR_PRINT_OFF;
1902
String d1_str;
1903
VariantWriter::write_to_string(d1, d1_str);
1904
ERR_PRINT_ON;
1905
1906
// Break the recursivity otherwise Dictionary tearndown will leak memory
1907
d.clear();
1908
d1.clear();
1909
d2.clear();
1910
}
1911
#endif
1912
1913
TEST_CASE("[Variant] Basic comparison") {
1914
CHECK_EQ(Variant(1), Variant(1));
1915
CHECK_FALSE(Variant(1) != Variant(1));
1916
CHECK_NE(Variant(1), Variant(2));
1917
CHECK_EQ(Variant(String("foo")), Variant(String("foo")));
1918
CHECK_NE(Variant(String("foo")), Variant(String("bar")));
1919
// Check "empty" version of different types are not equivalents
1920
CHECK_NE(Variant(0), Variant());
1921
CHECK_NE(Variant(String()), Variant());
1922
CHECK_NE(Variant(Array()), Variant());
1923
CHECK_NE(Variant(Dictionary()), Variant());
1924
}
1925
1926
TEST_CASE("[Variant] Identity comparison") {
1927
// Value types are compared by value
1928
Variant aabb = AABB();
1929
CHECK(aabb.identity_compare(aabb));
1930
CHECK(aabb.identity_compare(AABB()));
1931
CHECK_FALSE(aabb.identity_compare(AABB(Vector3(1, 2, 3), Vector3(1, 2, 3))));
1932
1933
Variant basis = Basis();
1934
CHECK(basis.identity_compare(basis));
1935
CHECK(basis.identity_compare(Basis()));
1936
CHECK_FALSE(basis.identity_compare(Basis(Quaternion(Vector3(1, 2, 3).normalized(), 45))));
1937
1938
Variant bool_var = true;
1939
CHECK(bool_var.identity_compare(bool_var));
1940
CHECK(bool_var.identity_compare(true));
1941
CHECK_FALSE(bool_var.identity_compare(false));
1942
1943
Variant callable = Callable();
1944
CHECK(callable.identity_compare(callable));
1945
CHECK(callable.identity_compare(Callable()));
1946
CHECK_FALSE(callable.identity_compare(Callable(ObjectID(), StringName("lambda"))));
1947
1948
Variant color = Color();
1949
CHECK(color.identity_compare(color));
1950
CHECK(color.identity_compare(Color()));
1951
CHECK_FALSE(color.identity_compare(Color(255, 0, 255)));
1952
1953
Variant float_var = 1.0;
1954
CHECK(float_var.identity_compare(float_var));
1955
CHECK(float_var.identity_compare(1.0));
1956
CHECK_FALSE(float_var.identity_compare(2.0));
1957
1958
Variant int_var = 1;
1959
CHECK(int_var.identity_compare(int_var));
1960
CHECK(int_var.identity_compare(1));
1961
CHECK_FALSE(int_var.identity_compare(2));
1962
1963
Variant nil = Variant();
1964
CHECK(nil.identity_compare(nil));
1965
CHECK(nil.identity_compare(Variant()));
1966
CHECK_FALSE(nil.identity_compare(true));
1967
1968
Variant node_path = NodePath("godot");
1969
CHECK(node_path.identity_compare(node_path));
1970
CHECK(node_path.identity_compare(NodePath("godot")));
1971
CHECK_FALSE(node_path.identity_compare(NodePath("waiting")));
1972
1973
Variant plane = Plane();
1974
CHECK(plane.identity_compare(plane));
1975
CHECK(plane.identity_compare(Plane()));
1976
CHECK_FALSE(plane.identity_compare(Plane(Vector3(1, 2, 3), 42)));
1977
1978
Variant projection = Projection();
1979
CHECK(projection.identity_compare(projection));
1980
CHECK(projection.identity_compare(Projection()));
1981
CHECK_FALSE(projection.identity_compare(Projection(Transform3D(Basis(Vector3(1, 2, 3).normalized(), 45), Vector3(1, 2, 3)))));
1982
1983
Variant quaternion = Quaternion();
1984
CHECK(quaternion.identity_compare(quaternion));
1985
CHECK(quaternion.identity_compare(Quaternion()));
1986
CHECK_FALSE(quaternion.identity_compare(Quaternion(Vector3(1, 2, 3).normalized(), 45)));
1987
1988
Variant rect2 = Rect2();
1989
CHECK(rect2.identity_compare(rect2));
1990
CHECK(rect2.identity_compare(Rect2()));
1991
CHECK_FALSE(rect2.identity_compare(Rect2(Point2(Vector2(1, 2)), Size2(Vector2(1, 2)))));
1992
1993
Variant rect2i = Rect2i();
1994
CHECK(rect2i.identity_compare(rect2i));
1995
CHECK(rect2i.identity_compare(Rect2i()));
1996
CHECK_FALSE(rect2i.identity_compare(Rect2i(Point2i(Vector2i(1, 2)), Size2i(Vector2i(1, 2)))));
1997
1998
Variant rid = RID();
1999
CHECK(rid.identity_compare(rid));
2000
CHECK(rid.identity_compare(RID()));
2001
CHECK_FALSE(rid.identity_compare(RID::from_uint64(123)));
2002
2003
Variant signal = Signal();
2004
CHECK(signal.identity_compare(signal));
2005
CHECK(signal.identity_compare(Signal()));
2006
CHECK_FALSE(signal.identity_compare(Signal(ObjectID(), StringName("lambda"))));
2007
2008
Variant str = "godot";
2009
CHECK(str.identity_compare(str));
2010
CHECK(str.identity_compare("godot"));
2011
CHECK_FALSE(str.identity_compare("waiting"));
2012
2013
Variant str_name = StringName("godot");
2014
CHECK(str_name.identity_compare(str_name));
2015
CHECK(str_name.identity_compare(StringName("godot")));
2016
CHECK_FALSE(str_name.identity_compare(StringName("waiting")));
2017
2018
Variant transform2d = Transform2D();
2019
CHECK(transform2d.identity_compare(transform2d));
2020
CHECK(transform2d.identity_compare(Transform2D()));
2021
CHECK_FALSE(transform2d.identity_compare(Transform2D(45, Vector2(1, 2))));
2022
2023
Variant transform3d = Transform3D();
2024
CHECK(transform3d.identity_compare(transform3d));
2025
CHECK(transform3d.identity_compare(Transform3D()));
2026
CHECK_FALSE(transform3d.identity_compare(Transform3D(Basis(Quaternion(Vector3(1, 2, 3).normalized(), 45)), Vector3(1, 2, 3))));
2027
2028
Variant vect2 = Vector2();
2029
CHECK(vect2.identity_compare(vect2));
2030
CHECK(vect2.identity_compare(Vector2()));
2031
CHECK_FALSE(vect2.identity_compare(Vector2(1, 2)));
2032
2033
Variant vect2i = Vector2i();
2034
CHECK(vect2i.identity_compare(vect2i));
2035
CHECK(vect2i.identity_compare(Vector2i()));
2036
CHECK_FALSE(vect2i.identity_compare(Vector2i(1, 2)));
2037
2038
Variant vect3 = Vector3();
2039
CHECK(vect3.identity_compare(vect3));
2040
CHECK(vect3.identity_compare(Vector3()));
2041
CHECK_FALSE(vect3.identity_compare(Vector3(1, 2, 3)));
2042
2043
Variant vect3i = Vector3i();
2044
CHECK(vect3i.identity_compare(vect3i));
2045
CHECK(vect3i.identity_compare(Vector3i()));
2046
CHECK_FALSE(vect3i.identity_compare(Vector3i(1, 2, 3)));
2047
2048
Variant vect4 = Vector4();
2049
CHECK(vect4.identity_compare(vect4));
2050
CHECK(vect4.identity_compare(Vector4()));
2051
CHECK_FALSE(vect4.identity_compare(Vector4(1, 2, 3, 4)));
2052
2053
Variant vect4i = Vector4i();
2054
CHECK(vect4i.identity_compare(vect4i));
2055
CHECK(vect4i.identity_compare(Vector4i()));
2056
CHECK_FALSE(vect4i.identity_compare(Vector4i(1, 2, 3, 4)));
2057
2058
// Reference types are compared by reference
2059
Variant array = Array();
2060
CHECK(array.identity_compare(array));
2061
CHECK_FALSE(array.identity_compare(Array()));
2062
2063
Variant dictionary = Dictionary();
2064
CHECK(dictionary.identity_compare(dictionary));
2065
CHECK_FALSE(dictionary.identity_compare(Dictionary()));
2066
2067
Variant packed_byte_array = PackedByteArray();
2068
CHECK(packed_byte_array.identity_compare(packed_byte_array));
2069
CHECK_FALSE(packed_byte_array.identity_compare(PackedByteArray()));
2070
2071
Variant packed_color_array = PackedColorArray();
2072
CHECK(packed_color_array.identity_compare(packed_color_array));
2073
CHECK_FALSE(packed_color_array.identity_compare(PackedColorArray()));
2074
2075
Variant packed_vector4_array = PackedVector4Array();
2076
CHECK(packed_vector4_array.identity_compare(packed_vector4_array));
2077
CHECK_FALSE(packed_vector4_array.identity_compare(PackedVector4Array()));
2078
2079
Variant packed_float32_array = PackedFloat32Array();
2080
CHECK(packed_float32_array.identity_compare(packed_float32_array));
2081
CHECK_FALSE(packed_float32_array.identity_compare(PackedFloat32Array()));
2082
2083
Variant packed_float64_array = PackedFloat64Array();
2084
CHECK(packed_float64_array.identity_compare(packed_float64_array));
2085
CHECK_FALSE(packed_float64_array.identity_compare(PackedFloat64Array()));
2086
2087
Variant packed_int32_array = PackedInt32Array();
2088
CHECK(packed_int32_array.identity_compare(packed_int32_array));
2089
CHECK_FALSE(packed_int32_array.identity_compare(PackedInt32Array()));
2090
2091
Variant packed_int64_array = PackedInt64Array();
2092
CHECK(packed_int64_array.identity_compare(packed_int64_array));
2093
CHECK_FALSE(packed_int64_array.identity_compare(PackedInt64Array()));
2094
2095
Variant packed_string_array = PackedStringArray();
2096
CHECK(packed_string_array.identity_compare(packed_string_array));
2097
CHECK_FALSE(packed_string_array.identity_compare(PackedStringArray()));
2098
2099
Variant packed_vector2_array = PackedVector2Array();
2100
CHECK(packed_vector2_array.identity_compare(packed_vector2_array));
2101
CHECK_FALSE(packed_vector2_array.identity_compare(PackedVector2Array()));
2102
2103
Variant packed_vector3_array = PackedVector3Array();
2104
CHECK(packed_vector3_array.identity_compare(packed_vector3_array));
2105
CHECK_FALSE(packed_vector3_array.identity_compare(PackedVector3Array()));
2106
2107
Object obj_one = Object();
2108
Variant obj_one_var = &obj_one;
2109
Object obj_two = Object();
2110
Variant obj_two_var = &obj_two;
2111
CHECK(obj_one_var.identity_compare(obj_one_var));
2112
CHECK_FALSE(obj_one_var.identity_compare(obj_two_var));
2113
2114
Variant obj_null_one_var = Variant((Object *)nullptr);
2115
Variant obj_null_two_var = Variant((Object *)nullptr);
2116
CHECK(obj_null_one_var.identity_compare(obj_null_one_var));
2117
CHECK(obj_null_one_var.identity_compare(obj_null_two_var));
2118
2119
Object *freed_one = new Object();
2120
Variant freed_one_var = freed_one;
2121
delete freed_one;
2122
Object *freed_two = new Object();
2123
Variant freed_two_var = freed_two;
2124
delete freed_two;
2125
CHECK_FALSE(freed_one_var.identity_compare(freed_two_var));
2126
}
2127
2128
TEST_CASE("[Variant] Nested array comparison") {
2129
Array a1 = { 1, { 2, 3 } };
2130
Array a2 = { 1, { 2, 3 } };
2131
Array a_other = { 1, { 2, 4 } };
2132
Variant v_a1 = a1;
2133
Variant v_a1_ref2 = a1;
2134
Variant v_a2 = a2;
2135
Variant v_a_other = a_other;
2136
2137
// test both operator== and operator!=
2138
CHECK_EQ(v_a1, v_a1);
2139
CHECK_FALSE(v_a1 != v_a1);
2140
CHECK_EQ(v_a1, v_a1_ref2);
2141
CHECK_FALSE(v_a1 != v_a1_ref2);
2142
CHECK_EQ(v_a1, v_a2);
2143
CHECK_FALSE(v_a1 != v_a2);
2144
CHECK_NE(v_a1, v_a_other);
2145
CHECK_FALSE(v_a1 == v_a_other);
2146
}
2147
2148
TEST_CASE("[Variant] Nested dictionary comparison") {
2149
Dictionary d1 = { { Dictionary({ { 1, 2 } }), Dictionary({ { 3, 4 } }) } };
2150
Dictionary d2 = { { Dictionary({ { 1, 2 } }), Dictionary({ { 3, 4 } }) } };
2151
Dictionary d_other_key = { { Dictionary({ { 1, 0 } }), Dictionary({ { 3, 4 } }) } };
2152
Dictionary d_other_val = { { Dictionary({ { 1, 2 } }), Dictionary({ { 3, 0 } }) } };
2153
Variant v_d1 = d1;
2154
Variant v_d1_ref2 = d1;
2155
Variant v_d2 = d2;
2156
Variant v_d_other_key = d_other_key;
2157
Variant v_d_other_val = d_other_val;
2158
2159
// test both operator== and operator!=
2160
CHECK_EQ(v_d1, v_d1);
2161
CHECK_FALSE(v_d1 != v_d1);
2162
CHECK_EQ(v_d1, v_d1_ref2);
2163
CHECK_FALSE(v_d1 != v_d1_ref2);
2164
CHECK_EQ(v_d1, v_d2);
2165
CHECK_FALSE(v_d1 != v_d2);
2166
CHECK_NE(v_d1, v_d_other_key);
2167
CHECK_FALSE(v_d1 == v_d_other_key);
2168
CHECK_NE(v_d1, v_d_other_val);
2169
CHECK_FALSE(v_d1 == v_d_other_val);
2170
}
2171
2172
struct ArgumentData {
2173
Variant::Type type;
2174
String name;
2175
bool has_defval = false;
2176
Variant defval;
2177
int position;
2178
};
2179
2180
struct MethodData {
2181
StringName name;
2182
Variant::Type return_type;
2183
List<ArgumentData> arguments;
2184
bool is_virtual = false;
2185
bool is_vararg = false;
2186
};
2187
2188
TEST_CASE("[Variant] Utility functions") {
2189
List<MethodData> functions;
2190
2191
List<StringName> function_names;
2192
Variant::get_utility_function_list(&function_names);
2193
function_names.sort_custom<StringName::AlphCompare>();
2194
2195
for (const StringName &E : function_names) {
2196
MethodData md;
2197
md.name = E;
2198
2199
// Utility function's return type.
2200
if (Variant::has_utility_function_return_value(E)) {
2201
md.return_type = Variant::get_utility_function_return_type(E);
2202
}
2203
2204
// Utility function's arguments.
2205
if (Variant::is_utility_function_vararg(E)) {
2206
md.is_vararg = true;
2207
} else {
2208
for (int i = 0; i < Variant::get_utility_function_argument_count(E); i++) {
2209
ArgumentData arg;
2210
arg.type = Variant::get_utility_function_argument_type(E, i);
2211
arg.name = Variant::get_utility_function_argument_name(E, i);
2212
arg.position = i;
2213
2214
md.arguments.push_back(arg);
2215
}
2216
}
2217
2218
functions.push_back(md);
2219
}
2220
2221
SUBCASE("[Variant] Validate utility functions") {
2222
for (const MethodData &E : functions) {
2223
for (const ArgumentData &F : E.arguments) {
2224
const ArgumentData &arg = F;
2225
2226
TEST_COND((arg.name.is_empty() || arg.name.begins_with("_unnamed_arg")),
2227
vformat("Unnamed argument in position %d of function '%s'.", arg.position, E.name));
2228
}
2229
}
2230
}
2231
}
2232
2233
TEST_CASE("[Variant] Operator NOT") {
2234
// Verify that operator NOT works for all types and is consistent with booleanize().
2235
for (int i = 0; i < Variant::VARIANT_MAX; i++) {
2236
Variant value;
2237
Callable::CallError err;
2238
Variant::construct((Variant::Type)i, value, nullptr, 0, err);
2239
2240
REQUIRE_EQ(err.error, Callable::CallError::CALL_OK);
2241
2242
Variant result = Variant::evaluate(Variant::OP_NOT, value, Variant());
2243
2244
REQUIRE_EQ(result.get_type(), Variant::BOOL);
2245
CHECK_EQ(!value.booleanize(), result.operator bool());
2246
}
2247
}
2248
2249
} // namespace TestVariant
2250
2251