test_validate_testing.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /**************************************************************************/
  2. /* test_validate_testing.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_VALIDATE_TESTING_H
  31. #define TEST_VALIDATE_TESTING_H
  32. #include "core/core_globals.h"
  33. #include "core/os/os.h"
  34. #include "tests/test_macros.h"
  35. #include "tests/test_tools.h"
  36. TEST_SUITE("Validate tests") {
  37. TEST_CASE("Always pass") {
  38. CHECK(true);
  39. }
  40. TEST_CASE_PENDING("Pending tests are skipped") {
  41. if (!doctest::getContextOptions()->no_skip) { // Normal run.
  42. FAIL("This should be skipped if `--no-skip` is NOT set (missing `doctest::skip()` decorator?)");
  43. } else {
  44. CHECK_MESSAGE(true, "Pending test is run with `--no-skip`");
  45. }
  46. }
  47. TEST_CASE("Muting Godot error messages") {
  48. ERR_PRINT_OFF;
  49. CHECK_MESSAGE(!CoreGlobals::print_error_enabled, "Error printing should be disabled.");
  50. ERR_PRINT("Still waiting for Godot!"); // This should never get printed!
  51. ERR_PRINT_ON;
  52. CHECK_MESSAGE(CoreGlobals::print_error_enabled, "Error printing should be re-enabled.");
  53. }
  54. TEST_CASE("Stringify Variant types") {
  55. Variant var;
  56. INFO(var);
  57. String string("Godot is finally here!");
  58. INFO(string);
  59. Vector2 vec2(0.5, 1.0);
  60. INFO(vec2);
  61. Vector2i vec2i(1, 2);
  62. INFO(vec2i);
  63. Rect2 rect2(0.5, 0.5, 100.5, 100.5);
  64. INFO(rect2);
  65. Rect2i rect2i(0, 0, 100, 100);
  66. INFO(rect2i);
  67. Vector3 vec3(0.5, 1.0, 2.0);
  68. INFO(vec3);
  69. Vector3i vec3i(1, 2, 3);
  70. INFO(vec3i);
  71. Transform2D trans2d(0.5, Vector2(100, 100));
  72. INFO(trans2d);
  73. Plane plane(Vector3(1, 1, 1), 1.0);
  74. INFO(plane);
  75. Quaternion quat = Quaternion::from_euler(Vector3(0.5, 1.0, 2.0));
  76. INFO(quat);
  77. AABB aabb(Vector3(), Vector3(100, 100, 100));
  78. INFO(aabb);
  79. Basis basis(quat);
  80. INFO(basis);
  81. Transform3D trans(basis);
  82. INFO(trans);
  83. Color color(1, 0.5, 0.2, 0.3);
  84. INFO(color);
  85. StringName string_name("has_method");
  86. INFO(string_name);
  87. NodePath node_path("godot/sprite");
  88. INFO(node_path);
  89. INFO(RID());
  90. Object *obj = memnew(Object);
  91. INFO(obj);
  92. Callable callable(obj, "has_method");
  93. INFO(callable);
  94. Signal signal(obj, "script_changed");
  95. INFO(signal);
  96. memdelete(obj);
  97. Dictionary dict;
  98. dict["string"] = string;
  99. dict["color"] = color;
  100. INFO(dict);
  101. Array arr;
  102. arr.push_back(string);
  103. arr.push_back(color);
  104. INFO(arr);
  105. PackedByteArray byte_arr;
  106. byte_arr.push_back(0);
  107. byte_arr.push_back(1);
  108. byte_arr.push_back(2);
  109. INFO(byte_arr);
  110. PackedInt32Array int32_arr;
  111. int32_arr.push_back(0);
  112. int32_arr.push_back(1);
  113. int32_arr.push_back(2);
  114. INFO(int32_arr);
  115. PackedInt64Array int64_arr;
  116. int64_arr.push_back(0);
  117. int64_arr.push_back(1);
  118. int64_arr.push_back(2);
  119. INFO(int64_arr);
  120. PackedFloat32Array float32_arr;
  121. float32_arr.push_back(0.5);
  122. float32_arr.push_back(1.5);
  123. float32_arr.push_back(2.5);
  124. INFO(float32_arr);
  125. PackedFloat64Array float64_arr;
  126. float64_arr.push_back(0.5);
  127. float64_arr.push_back(1.5);
  128. float64_arr.push_back(2.5);
  129. INFO(float64_arr);
  130. PackedStringArray str_arr = string.split(" ");
  131. INFO(str_arr);
  132. PackedVector2Array vec2_arr;
  133. vec2_arr.push_back(Vector2(0, 0));
  134. vec2_arr.push_back(Vector2(1, 1));
  135. vec2_arr.push_back(Vector2(2, 2));
  136. INFO(vec2_arr);
  137. PackedVector3Array vec3_arr;
  138. vec3_arr.push_back(Vector3(0, 0, 0));
  139. vec3_arr.push_back(Vector3(1, 1, 1));
  140. vec3_arr.push_back(Vector3(2, 2, 2));
  141. INFO(vec3_arr);
  142. PackedColorArray color_arr;
  143. color_arr.push_back(Color(0, 0, 0));
  144. color_arr.push_back(Color(1, 1, 1));
  145. color_arr.push_back(Color(2, 2, 2));
  146. INFO(color_arr);
  147. PackedVector4Array vec4_arr;
  148. vec4_arr.push_back(Vector4(0, 0, 0, 0));
  149. vec4_arr.push_back(Vector4(1, 1, 1, 1));
  150. vec4_arr.push_back(Vector4(2, 2, 2, 2));
  151. vec4_arr.push_back(Vector4(3, 3, 3, 3));
  152. INFO(vec4_arr);
  153. // doctest string concatenation.
  154. CHECK_MESSAGE(true, var, " ", vec2, " ", rect2, " ", color);
  155. }
  156. TEST_CASE("Detect error messages") {
  157. ErrorDetector ed;
  158. REQUIRE_FALSE(ed.has_error);
  159. ERR_PRINT_OFF;
  160. ERR_PRINT("Still waiting for Godot!");
  161. ERR_PRINT_ON;
  162. REQUIRE(ed.has_error);
  163. }
  164. }
  165. #endif // TEST_VALIDATE_TESTING_H