test_variant.h 66 KB

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