test_variant.h 65 KB

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