test_variant.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. /*************************************************************************/
  2. /* test_variant.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  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. TEST_CASE("[Variant] Writer and parser integer") {
  37. int64_t a32 = 2147483648; // 2^31, so out of bounds for 32-bit signed int [-2^31,-2^31-1].
  38. String a32_str;
  39. VariantWriter::write_to_string(a32, a32_str);
  40. CHECK_MESSAGE(a32_str != "-2147483648", "Should not wrap around");
  41. int64_t b64 = 9223372036854775807; // 2^63-1, upper bound for signed 64-bit int.
  42. String b64_str;
  43. VariantWriter::write_to_string(b64, b64_str);
  44. CHECK_MESSAGE(b64_str == "9223372036854775807", "Should not wrap around.");
  45. VariantParser::StreamString ss;
  46. String errs;
  47. int line;
  48. Variant b64_parsed;
  49. int64_t b64_int_parsed;
  50. ss.s = b64_str;
  51. VariantParser::parse(&ss, b64_parsed, errs, line);
  52. b64_int_parsed = b64_parsed;
  53. CHECK_MESSAGE(b64_int_parsed == 9223372036854775807, "Should parse back.");
  54. ss.s = "9223372036854775808"; // Overflowed by one.
  55. VariantParser::parse(&ss, b64_parsed, errs, line);
  56. b64_int_parsed = b64_parsed;
  57. CHECK_MESSAGE(b64_int_parsed == 9223372036854775807, "The result should be clamped to max value.");
  58. ss.s = "1e100"; // Googol! Scientific notation.
  59. VariantParser::parse(&ss, b64_parsed, errs, line);
  60. b64_int_parsed = b64_parsed;
  61. CHECK_MESSAGE(b64_int_parsed == 9223372036854775807, "The result should be clamped to max value.");
  62. }
  63. TEST_CASE("[Variant] Writer and parser float") {
  64. // Assuming real_t is double.
  65. real_t a64 = 340282346638528859811704183484516925440.0; // std::numeric_limits<real_t>::max()
  66. String a64_str;
  67. VariantWriter::write_to_string(a64, a64_str);
  68. CHECK_MESSAGE(a64_str == "3.40282e+38", "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. VariantParser::StreamString ss;
  72. String errs;
  73. int line;
  74. Variant b64_parsed;
  75. real_t b64_float_parsed;
  76. ss.s = a64_str;
  77. VariantParser::parse(&ss, b64_parsed, errs, line);
  78. b64_float_parsed = b64_parsed;
  79. CHECK_MESSAGE(b64_float_parsed == 340282001837565597733306976381245063168.0, "Should parse back.");
  80. // Loses precision, but that's alright.
  81. ss.s = "1.0e+100"; // Float version of Googol!
  82. VariantParser::parse(&ss, b64_parsed, errs, line);
  83. b64_float_parsed = b64_parsed;
  84. CHECK_MESSAGE(b64_float_parsed == 340282001837565597733306976381245063168.0, "Should not overflow.");
  85. }
  86. TEST_CASE("[Variant] Assignment To Bool from Int,Float,String,Vec2,Vec2i,Vec3,Vec3i and Color") {
  87. Variant int_v = 0;
  88. Variant bool_v = true;
  89. int_v = bool_v; // int_v is now a bool
  90. CHECK(int_v == Variant(true));
  91. bool_v = false;
  92. int_v = bool_v;
  93. CHECK(int_v.get_type() == Variant::BOOL);
  94. Variant float_v = 0.0f;
  95. bool_v = true;
  96. float_v = bool_v;
  97. CHECK(float_v == Variant(true));
  98. bool_v = false;
  99. float_v = bool_v;
  100. CHECK(float_v.get_type() == Variant::BOOL);
  101. Variant string_v = "";
  102. bool_v = true;
  103. string_v = bool_v;
  104. CHECK(string_v == Variant(true));
  105. bool_v = false;
  106. string_v = bool_v;
  107. CHECK(string_v.get_type() == Variant::BOOL);
  108. Variant vec2_v = Vector2(0, 0);
  109. bool_v = true;
  110. vec2_v = bool_v;
  111. CHECK(vec2_v == Variant(true));
  112. bool_v = false;
  113. vec2_v = bool_v;
  114. CHECK(vec2_v.get_type() == Variant::BOOL);
  115. Variant vec2i_v = Vector2i(0, 0);
  116. bool_v = true;
  117. vec2i_v = bool_v;
  118. CHECK(vec2i_v == Variant(true));
  119. bool_v = false;
  120. vec2i_v = bool_v;
  121. CHECK(vec2i_v.get_type() == Variant::BOOL);
  122. Variant vec3_v = Vector3(0, 0, 0);
  123. bool_v = true;
  124. vec3_v = bool_v;
  125. CHECK(vec3_v == Variant(true));
  126. bool_v = false;
  127. vec3_v = bool_v;
  128. CHECK(vec3_v.get_type() == Variant::BOOL);
  129. Variant vec3i_v = Vector3i(0, 0, 0);
  130. bool_v = true;
  131. vec3i_v = bool_v;
  132. CHECK(vec3i_v == Variant(true));
  133. bool_v = false;
  134. vec3i_v = bool_v;
  135. CHECK(vec3i_v.get_type() == Variant::BOOL);
  136. Variant col_v = Color(0.5f, 0.2f, 0.75f);
  137. bool_v = true;
  138. col_v = bool_v;
  139. CHECK(col_v == Variant(true));
  140. bool_v = false;
  141. col_v = bool_v;
  142. CHECK(col_v.get_type() == Variant::BOOL);
  143. }
  144. TEST_CASE("[Variant] Assignment To Int from Bool,Float,String,Vec2,Vec2i,Vec3,Vec3i and Color") {
  145. Variant bool_v = false;
  146. Variant int_v = 2;
  147. bool_v = int_v; // Now bool_v is int
  148. CHECK(bool_v == Variant(2));
  149. int_v = -3;
  150. bool_v = int_v;
  151. CHECK(bool_v.get_type() == Variant::INT);
  152. Variant float_v = 0.0f;
  153. int_v = 2;
  154. float_v = int_v;
  155. CHECK(float_v == Variant(2));
  156. int_v = -3;
  157. float_v = int_v;
  158. CHECK(float_v.get_type() == Variant::INT);
  159. Variant string_v = "";
  160. int_v = 2;
  161. string_v = int_v;
  162. CHECK(string_v == Variant(2));
  163. int_v = -3;
  164. string_v = int_v;
  165. CHECK(string_v.get_type() == Variant::INT);
  166. Variant vec2_v = Vector2(0, 0);
  167. int_v = 2;
  168. vec2_v = int_v;
  169. CHECK(vec2_v == Variant(2));
  170. int_v = -3;
  171. vec2_v = int_v;
  172. CHECK(vec2_v.get_type() == Variant::INT);
  173. Variant vec2i_v = Vector2i(0, 0);
  174. int_v = 2;
  175. vec2i_v = int_v;
  176. CHECK(vec2i_v == Variant(2));
  177. int_v = -3;
  178. vec2i_v = int_v;
  179. CHECK(vec2i_v.get_type() == Variant::INT);
  180. Variant vec3_v = Vector3(0, 0, 0);
  181. int_v = 2;
  182. vec3_v = int_v;
  183. CHECK(vec3_v == Variant(2));
  184. int_v = -3;
  185. vec3_v = int_v;
  186. CHECK(vec3_v.get_type() == Variant::INT);
  187. Variant vec3i_v = Vector3i(0, 0, 0);
  188. int_v = 2;
  189. vec3i_v = int_v;
  190. CHECK(vec3i_v == Variant(2));
  191. int_v = -3;
  192. vec3i_v = int_v;
  193. CHECK(vec3i_v.get_type() == Variant::INT);
  194. Variant col_v = Color(0.5f, 0.2f, 0.75f);
  195. int_v = 2;
  196. col_v = int_v;
  197. CHECK(col_v == Variant(2));
  198. int_v = -3;
  199. col_v = int_v;
  200. CHECK(col_v.get_type() == Variant::INT);
  201. }
  202. TEST_CASE("[Variant] Assignment To Float from Bool,Int,String,Vec2,Vec2i,Vec3,Vec3i and Color") {
  203. Variant bool_v = false;
  204. Variant float_v = 1.5f;
  205. bool_v = float_v; // Now bool_v is float
  206. CHECK(bool_v == Variant(1.5f));
  207. float_v = -4.6f;
  208. bool_v = float_v;
  209. CHECK(bool_v.get_type() == Variant::FLOAT);
  210. Variant int_v = 1;
  211. float_v = 1.5f;
  212. int_v = float_v;
  213. CHECK(int_v == Variant(1.5f));
  214. float_v = -4.6f;
  215. int_v = float_v;
  216. CHECK(int_v.get_type() == Variant::FLOAT);
  217. Variant string_v = "";
  218. float_v = 1.5f;
  219. string_v = float_v;
  220. CHECK(string_v == Variant(1.5f));
  221. float_v = -4.6f;
  222. string_v = float_v;
  223. CHECK(string_v.get_type() == Variant::FLOAT);
  224. Variant vec2_v = Vector2(0, 0);
  225. float_v = 1.5f;
  226. vec2_v = float_v;
  227. CHECK(vec2_v == Variant(1.5f));
  228. float_v = -4.6f;
  229. vec2_v = float_v;
  230. CHECK(vec2_v.get_type() == Variant::FLOAT);
  231. Variant vec2i_v = Vector2i(0, 0);
  232. float_v = 1.5f;
  233. vec2i_v = float_v;
  234. CHECK(vec2i_v == Variant(1.5f));
  235. float_v = -4.6f;
  236. vec2i_v = float_v;
  237. CHECK(vec2i_v.get_type() == Variant::FLOAT);
  238. Variant vec3_v = Vector3(0, 0, 0);
  239. float_v = 1.5f;
  240. vec3_v = float_v;
  241. CHECK(vec3_v == Variant(1.5f));
  242. float_v = -4.6f;
  243. vec3_v = float_v;
  244. CHECK(vec3_v.get_type() == Variant::FLOAT);
  245. Variant vec3i_v = Vector3i(0, 0, 0);
  246. float_v = 1.5f;
  247. vec3i_v = float_v;
  248. CHECK(vec3i_v == Variant(1.5f));
  249. float_v = -4.6f;
  250. vec3i_v = float_v;
  251. CHECK(vec3i_v.get_type() == Variant::FLOAT);
  252. Variant col_v = Color(0.5f, 0.2f, 0.75f);
  253. float_v = 1.5f;
  254. col_v = float_v;
  255. CHECK(col_v == Variant(1.5f));
  256. float_v = -4.6f;
  257. col_v = float_v;
  258. CHECK(col_v.get_type() == Variant::FLOAT);
  259. }
  260. TEST_CASE("[Variant] Assignment To String from Bool,Int,Float,Vec2,Vec2i,Vec3,Vec3i and Color") {
  261. Variant bool_v = false;
  262. Variant string_v = "Hello";
  263. bool_v = string_v; // Now bool_v is string
  264. CHECK(bool_v == Variant("Hello"));
  265. string_v = "Hello there";
  266. bool_v = string_v;
  267. CHECK(bool_v.get_type() == Variant::STRING);
  268. Variant int_v = 0;
  269. string_v = "Hello";
  270. int_v = string_v;
  271. CHECK(int_v == Variant("Hello"));
  272. string_v = "Hello there";
  273. int_v = string_v;
  274. CHECK(int_v.get_type() == Variant::STRING);
  275. Variant float_v = 0.0f;
  276. string_v = "Hello";
  277. float_v = string_v;
  278. CHECK(float_v == Variant("Hello"));
  279. string_v = "Hello there";
  280. float_v = string_v;
  281. CHECK(float_v.get_type() == Variant::STRING);
  282. Variant vec2_v = Vector2(0, 0);
  283. string_v = "Hello";
  284. vec2_v = string_v;
  285. CHECK(vec2_v == Variant("Hello"));
  286. string_v = "Hello there";
  287. vec2_v = string_v;
  288. CHECK(vec2_v.get_type() == Variant::STRING);
  289. Variant vec2i_v = Vector2i(0, 0);
  290. string_v = "Hello";
  291. vec2i_v = string_v;
  292. CHECK(vec2i_v == Variant("Hello"));
  293. string_v = "Hello there";
  294. vec2i_v = string_v;
  295. CHECK(vec2i_v.get_type() == Variant::STRING);
  296. Variant vec3_v = Vector3(0, 0, 0);
  297. string_v = "Hello";
  298. vec3_v = string_v;
  299. CHECK(vec3_v == Variant("Hello"));
  300. string_v = "Hello there";
  301. vec3_v = string_v;
  302. CHECK(vec3_v.get_type() == Variant::STRING);
  303. Variant vec3i_v = Vector3i(0, 0, 0);
  304. string_v = "Hello";
  305. vec3i_v = string_v;
  306. CHECK(vec3i_v == Variant("Hello"));
  307. string_v = "Hello there";
  308. vec3i_v = string_v;
  309. CHECK(vec3i_v.get_type() == Variant::STRING);
  310. Variant col_v = Color(0.5f, 0.2f, 0.75f);
  311. string_v = "Hello";
  312. col_v = string_v;
  313. CHECK(col_v == Variant("Hello"));
  314. string_v = "Hello there";
  315. col_v = string_v;
  316. CHECK(col_v.get_type() == Variant::STRING);
  317. }
  318. TEST_CASE("[Variant] Assignment To Vec2 from Bool,Int,Float,String,Vec2i,Vec3,Vec3i and Color") {
  319. Variant bool_v = false;
  320. Variant vec2_v = Vector2(2.2f, 3.5f);
  321. bool_v = vec2_v; // Now bool_v is Vector2
  322. CHECK(bool_v == Variant(Vector2(2.2f, 3.5f)));
  323. vec2_v = Vector2(-5.4f, -7.9f);
  324. bool_v = vec2_v;
  325. CHECK(bool_v.get_type() == Variant::VECTOR2);
  326. Variant int_v = 0;
  327. vec2_v = Vector2(2.2f, 3.5f);
  328. int_v = vec2_v;
  329. CHECK(int_v == Variant(Vector2(2.2f, 3.5f)));
  330. vec2_v = Vector2(-5.4f, -7.9f);
  331. int_v = vec2_v;
  332. CHECK(int_v.get_type() == Variant::VECTOR2);
  333. Variant float_v = 0.0f;
  334. vec2_v = Vector2(2.2f, 3.5f);
  335. float_v = vec2_v;
  336. CHECK(float_v == Variant(Vector2(2.2f, 3.5f)));
  337. vec2_v = Vector2(-5.4f, -7.9f);
  338. float_v = vec2_v;
  339. CHECK(float_v.get_type() == Variant::VECTOR2);
  340. Variant string_v = "";
  341. vec2_v = Vector2(2.2f, 3.5f);
  342. string_v = vec2_v;
  343. CHECK(string_v == Variant(Vector2(2.2f, 3.5f)));
  344. vec2_v = Vector2(-5.4f, -7.9f);
  345. string_v = vec2_v;
  346. CHECK(string_v.get_type() == Variant::VECTOR2);
  347. Variant vec2i_v = Vector2i(0, 0);
  348. vec2_v = Vector2(2.2f, 3.5f);
  349. vec2i_v = vec2_v;
  350. CHECK(vec2i_v == Variant(Vector2(2.2f, 3.5f)));
  351. vec2_v = Vector2(-5.4f, -7.9f);
  352. vec2i_v = vec2_v;
  353. CHECK(vec2i_v.get_type() == Variant::VECTOR2);
  354. Variant vec3_v = Vector3(0, 0, 0);
  355. vec2_v = Vector2(2.2f, 3.5f);
  356. vec3_v = vec2_v;
  357. CHECK(vec3_v == Variant(Vector2(2.2f, 3.5f)));
  358. vec2_v = Vector2(-5.4f, -7.9f);
  359. vec3_v = vec2_v;
  360. CHECK(vec3_v.get_type() == Variant::VECTOR2);
  361. Variant vec3i_v = Vector3i(0, 0, 0);
  362. vec2_v = Vector2(2.2f, 3.5f);
  363. vec3i_v = vec2_v;
  364. CHECK(vec3i_v == Variant(Vector2(2.2f, 3.5f)));
  365. vec2_v = Vector2(-5.4f, -7.9f);
  366. vec3i_v = vec2_v;
  367. CHECK(vec3i_v.get_type() == Variant::VECTOR2);
  368. Variant col_v = Color(0.5f, 0.2f, 0.75f);
  369. vec2_v = Vector2(2.2f, 3.5f);
  370. col_v = vec2_v;
  371. CHECK(col_v == Variant(Vector2(2.2f, 3.5f)));
  372. vec2_v = Vector2(-5.4f, -7.9f);
  373. col_v = vec2_v;
  374. CHECK(col_v.get_type() == Variant::VECTOR2);
  375. }
  376. TEST_CASE("[Variant] Assignment To Vec2i from Bool,Int,Float,String,Vec2,Vec3,Vec3i and Color") {
  377. Variant bool_v = false;
  378. Variant vec2i_v = Vector2i(2, 3);
  379. bool_v = vec2i_v; // Now bool_v is Vector2i
  380. CHECK(bool_v == Variant(Vector2i(2, 3)));
  381. vec2i_v = Vector2i(-5, -7);
  382. bool_v = vec2i_v;
  383. CHECK(bool_v.get_type() == Variant::VECTOR2I);
  384. Variant int_v = 0;
  385. vec2i_v = Vector2i(2, 3);
  386. int_v = vec2i_v;
  387. CHECK(int_v == Variant(Vector2i(2, 3)));
  388. vec2i_v = Vector2i(-5, -7);
  389. int_v = vec2i_v;
  390. CHECK(int_v.get_type() == Variant::VECTOR2I);
  391. Variant float_v = 0.0f;
  392. vec2i_v = Vector2i(2, 3);
  393. float_v = vec2i_v;
  394. CHECK(float_v == Variant(Vector2i(2, 3)));
  395. vec2i_v = Vector2i(-5, -7);
  396. float_v = vec2i_v;
  397. CHECK(float_v.get_type() == Variant::VECTOR2I);
  398. Variant string_v = "";
  399. vec2i_v = Vector2i(2, 3);
  400. string_v = vec2i_v;
  401. CHECK(string_v == Variant(Vector2i(2, 3)));
  402. vec2i_v = Vector2i(-5, -7);
  403. string_v = vec2i_v;
  404. CHECK(string_v.get_type() == Variant::VECTOR2I);
  405. Variant vec2_v = Vector2(0, 0);
  406. vec2i_v = Vector2i(2, 3);
  407. vec2_v = vec2i_v;
  408. CHECK(vec2_v == Variant(Vector2i(2, 3)));
  409. vec2i_v = Vector2i(-5, -7);
  410. vec2_v = vec2i_v;
  411. CHECK(vec2i_v.get_type() == Variant::VECTOR2I);
  412. Variant vec3_v = Vector3(0, 0, 0);
  413. vec2i_v = Vector2i(2, 3);
  414. vec3_v = vec2i_v;
  415. CHECK(vec3_v == Variant(Vector2i(2, 3)));
  416. vec2i_v = Vector2i(-5, -7);
  417. vec3_v = vec2i_v;
  418. CHECK(vec3_v.get_type() == Variant::VECTOR2I);
  419. Variant vec3i_v = Vector3i(0, 0, 0);
  420. vec2i_v = Vector2i(2, 3);
  421. vec3i_v = vec2i_v;
  422. CHECK(vec3i_v == Variant(Vector2i(2, 3)));
  423. vec2i_v = Vector2i(-5, -7);
  424. vec3i_v = vec2i_v;
  425. CHECK(vec3i_v.get_type() == Variant::VECTOR2I);
  426. Variant col_v = Color(0.5f, 0.2f, 0.75f);
  427. vec2i_v = Vector2i(2, 3);
  428. col_v = vec2i_v;
  429. CHECK(col_v == Variant(Vector2i(2, 3)));
  430. vec2i_v = Vector2i(-5, -7);
  431. col_v = vec2i_v;
  432. CHECK(col_v.get_type() == Variant::VECTOR2I);
  433. }
  434. TEST_CASE("[Variant] Assignment To Vec3 from Bool,Int,Float,String,Vec2,Vec2i,Vec3i and Color") {
  435. Variant bool_v = false;
  436. Variant vec3_v = Vector3(2.2f, 3.5f, 5.3f);
  437. bool_v = vec3_v; // Now bool_v is Vector3
  438. CHECK(bool_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
  439. vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
  440. bool_v = vec3_v;
  441. CHECK(bool_v.get_type() == Variant::VECTOR3);
  442. Variant int_v = 0;
  443. vec3_v = Vector3(2.2f, 3.5f, 5.3f);
  444. int_v = vec3_v;
  445. CHECK(int_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
  446. vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
  447. int_v = vec3_v;
  448. CHECK(int_v.get_type() == Variant::VECTOR3);
  449. Variant float_v = 0.0f;
  450. vec3_v = Vector3(2.2f, 3.5f, 5.3f);
  451. float_v = vec3_v;
  452. CHECK(float_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
  453. vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
  454. float_v = vec3_v;
  455. CHECK(float_v.get_type() == Variant::VECTOR3);
  456. Variant string_v = "";
  457. vec3_v = Vector3(2.2f, 3.5f, 5.3f);
  458. string_v = vec3_v;
  459. CHECK(string_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
  460. vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
  461. string_v = vec3_v;
  462. CHECK(string_v.get_type() == Variant::VECTOR3);
  463. Variant vec2_v = Vector2(0, 0);
  464. vec3_v = Vector3(2.2f, 3.5f, 5.3f);
  465. vec2_v = vec3_v;
  466. CHECK(vec2_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
  467. vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
  468. vec2_v = vec3_v;
  469. CHECK(vec2_v.get_type() == Variant::VECTOR3);
  470. Variant vec2i_v = Vector2i(0, 0);
  471. vec3_v = Vector3(2.2f, 3.5f, 5.3f);
  472. vec2i_v = vec3_v;
  473. CHECK(vec2i_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
  474. vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
  475. vec2i_v = vec3_v;
  476. CHECK(vec2i_v.get_type() == Variant::VECTOR3);
  477. Variant vec3i_v = Vector3i(0, 0, 0);
  478. vec3_v = Vector3(2.2f, 3.5f, 5.3f);
  479. vec3i_v = vec3_v;
  480. CHECK(vec3i_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
  481. vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
  482. vec3i_v = vec3_v;
  483. CHECK(vec3i_v.get_type() == Variant::VECTOR3);
  484. Variant col_v = Color(0.5f, 0.2f, 0.75f);
  485. vec3_v = Vector3(2.2f, 3.5f, 5.3f);
  486. col_v = vec3_v;
  487. CHECK(col_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
  488. vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
  489. col_v = vec3_v;
  490. CHECK(col_v.get_type() == Variant::VECTOR3);
  491. }
  492. TEST_CASE("[Variant] Assignment To Vec3i from Bool,Int,Float,String,Vec2,Vec2i,Vec3 and Color") {
  493. Variant bool_v = false;
  494. Variant vec3i_v = Vector3i(2, 3, 5);
  495. bool_v = vec3i_v; // Now bool_v is Vector3i
  496. CHECK(bool_v == Variant(Vector3i(2, 3, 5)));
  497. vec3i_v = Vector3i(-5, -7, -2);
  498. bool_v = vec3i_v;
  499. CHECK(bool_v.get_type() == Variant::VECTOR3I);
  500. Variant int_v = 0;
  501. vec3i_v = Vector3i(2, 3, 5);
  502. int_v = vec3i_v;
  503. CHECK(int_v == Variant(Vector3i(2, 3, 5)));
  504. vec3i_v = Vector3i(-5, -7, -2);
  505. int_v = vec3i_v;
  506. CHECK(int_v.get_type() == Variant::VECTOR3I);
  507. Variant float_v = 0.0f;
  508. vec3i_v = Vector3i(2, 3, 5);
  509. float_v = vec3i_v;
  510. CHECK(float_v == Variant(Vector3i(2, 3, 5)));
  511. vec3i_v = Vector3i(-5, -7, -2);
  512. float_v = vec3i_v;
  513. CHECK(float_v.get_type() == Variant::VECTOR3I);
  514. Variant string_v = "";
  515. vec3i_v = Vector3i(2, 3, 5);
  516. string_v = vec3i_v;
  517. CHECK(string_v == Variant(Vector3i(2, 3, 5)));
  518. vec3i_v = Vector3i(-5, -7, -2);
  519. string_v = vec3i_v;
  520. CHECK(string_v.get_type() == Variant::VECTOR3I);
  521. Variant vec2_v = Vector2(0, 0);
  522. vec3i_v = Vector3i(2, 3, 5);
  523. vec2_v = vec3i_v;
  524. CHECK(vec2_v == Variant(Vector3i(2, 3, 5)));
  525. vec3i_v = Vector3i(-5, -7, -2);
  526. vec2_v = vec3i_v;
  527. CHECK(vec2_v.get_type() == Variant::VECTOR3I);
  528. Variant vec2i_v = Vector2i(0, 0);
  529. vec3i_v = Vector3i(2, 3, 5);
  530. vec2i_v = vec3i_v;
  531. CHECK(vec2i_v == Variant(Vector3i(2, 3, 5)));
  532. vec3i_v = Vector3i(-5, -7, -2);
  533. vec2i_v = vec3i_v;
  534. CHECK(vec2i_v.get_type() == Variant::VECTOR3I);
  535. Variant vec3_v = Vector3(0, 0, 0);
  536. vec3i_v = Vector3i(2, 3, 5);
  537. vec3_v = vec3i_v;
  538. CHECK(vec3_v == Variant(Vector3i(2, 3, 5)));
  539. vec3i_v = Vector3i(-5, -7, -2);
  540. vec3_v = vec3i_v;
  541. CHECK(vec3_v.get_type() == Variant::VECTOR3I);
  542. Variant col_v = Color(0.5f, 0.2f, 0.75f);
  543. vec3i_v = Vector3i(2, 3, 5);
  544. col_v = vec3i_v;
  545. CHECK(col_v == Variant(Vector3i(2, 3, 5)));
  546. vec3i_v = Vector3i(-5, -7, -2);
  547. col_v = vec3i_v;
  548. CHECK(col_v.get_type() == Variant::VECTOR3I);
  549. }
  550. TEST_CASE("[Variant] Assignment To Color from Bool,Int,Float,String,Vec2,Vec2i,Vec3 and Vec3i") {
  551. Variant bool_v = false;
  552. Variant col_v = Color(0.25f, 0.4f, 0.78f);
  553. bool_v = col_v; // Now bool_v is Color
  554. CHECK(bool_v == Variant(Color(0.25f, 0.4f, 0.78f)));
  555. col_v = Color(0.33f, 0.75f, 0.21f);
  556. bool_v = col_v;
  557. CHECK(bool_v.get_type() == Variant::COLOR);
  558. Variant int_v = 0;
  559. col_v = Color(0.25f, 0.4f, 0.78f);
  560. int_v = col_v;
  561. CHECK(int_v == Variant(Color(0.25f, 0.4f, 0.78f)));
  562. col_v = Color(0.33f, 0.75f, 0.21f);
  563. int_v = col_v;
  564. CHECK(int_v.get_type() == Variant::COLOR);
  565. Variant float_v = 0.0f;
  566. col_v = Color(0.25f, 0.4f, 0.78f);
  567. float_v = col_v;
  568. CHECK(float_v == Variant(Color(0.25f, 0.4f, 0.78f)));
  569. col_v = Color(0.33f, 0.75f, 0.21f);
  570. float_v = col_v;
  571. CHECK(float_v.get_type() == Variant::COLOR);
  572. Variant string_v = "";
  573. col_v = Color(0.25f, 0.4f, 0.78f);
  574. string_v = col_v;
  575. CHECK(string_v == Variant(Color(0.25f, 0.4f, 0.78f)));
  576. col_v = Color(0.33f, 0.75f, 0.21f);
  577. string_v = col_v;
  578. CHECK(string_v.get_type() == Variant::COLOR);
  579. Variant vec2_v = Vector2(0, 0);
  580. col_v = Color(0.25f, 0.4f, 0.78f);
  581. vec2_v = col_v;
  582. CHECK(vec2_v == Variant(Color(0.25f, 0.4f, 0.78f)));
  583. col_v = Color(0.33f, 0.75f, 0.21f);
  584. vec2_v = col_v;
  585. CHECK(vec2_v.get_type() == Variant::COLOR);
  586. Variant vec2i_v = Vector2i(0, 0);
  587. col_v = Color(0.25f, 0.4f, 0.78f);
  588. vec2i_v = col_v;
  589. CHECK(vec2i_v == Variant(Color(0.25f, 0.4f, 0.78f)));
  590. col_v = Color(0.33f, 0.75f, 0.21f);
  591. vec2i_v = col_v;
  592. CHECK(vec2i_v.get_type() == Variant::COLOR);
  593. Variant vec3_v = Vector3(0, 0, 0);
  594. col_v = Color(0.25f, 0.4f, 0.78f);
  595. vec3_v = col_v;
  596. CHECK(vec3_v == Variant(Color(0.25f, 0.4f, 0.78f)));
  597. col_v = Color(0.33f, 0.75f, 0.21f);
  598. vec3_v = col_v;
  599. CHECK(vec3_v.get_type() == Variant::COLOR);
  600. Variant vec3i_v = Vector3i(0, 0, 0);
  601. col_v = Color(0.25f, 0.4f, 0.78f);
  602. vec3i_v = col_v;
  603. CHECK(vec3i_v == Variant(Color(0.25f, 0.4f, 0.78f)));
  604. col_v = Color(0.33f, 0.75f, 0.21f);
  605. vec3i_v = col_v;
  606. CHECK(vec3i_v.get_type() == Variant::COLOR);
  607. }
  608. } // namespace TestVariant
  609. #endif // TEST_VARIANT_H