test_sky.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /**************************************************************************/
  2. /* test_sky.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_SKY_H
  31. #define TEST_SKY_H
  32. #include "scene/resources/sky.h"
  33. #include "tests/test_macros.h"
  34. namespace TestSky {
  35. TEST_CASE("[SceneTree][Sky] Constructor") {
  36. Ref<Sky> test_sky;
  37. test_sky.instantiate();
  38. CHECK(test_sky->get_process_mode() == Sky::PROCESS_MODE_AUTOMATIC);
  39. CHECK(test_sky->get_radiance_size() == Sky::RADIANCE_SIZE_256);
  40. CHECK(test_sky->get_material().is_null());
  41. }
  42. TEST_CASE("[SceneTree][Sky] Radiance size setter and getter") {
  43. Ref<Sky> test_sky;
  44. test_sky.instantiate();
  45. // Check default.
  46. CHECK(test_sky->get_radiance_size() == Sky::RADIANCE_SIZE_256);
  47. test_sky->set_radiance_size(Sky::RADIANCE_SIZE_1024);
  48. CHECK(test_sky->get_radiance_size() == Sky::RADIANCE_SIZE_1024);
  49. ERR_PRINT_OFF;
  50. // Check setting invalid radiance size.
  51. test_sky->set_radiance_size(Sky::RADIANCE_SIZE_MAX);
  52. ERR_PRINT_ON;
  53. CHECK(test_sky->get_radiance_size() == Sky::RADIANCE_SIZE_1024);
  54. }
  55. TEST_CASE("[SceneTree][Sky] Process mode setter and getter") {
  56. Ref<Sky> test_sky;
  57. test_sky.instantiate();
  58. // Check default.
  59. CHECK(test_sky->get_process_mode() == Sky::PROCESS_MODE_AUTOMATIC);
  60. test_sky->set_process_mode(Sky::PROCESS_MODE_INCREMENTAL);
  61. CHECK(test_sky->get_process_mode() == Sky::PROCESS_MODE_INCREMENTAL);
  62. }
  63. TEST_CASE("[SceneTree][Sky] Material setter and getter") {
  64. Ref<Sky> test_sky;
  65. test_sky.instantiate();
  66. Ref<Material> material;
  67. material.instantiate();
  68. SUBCASE("Material passed to the class should remain the same") {
  69. test_sky->set_material(material);
  70. CHECK(test_sky->get_material() == material);
  71. }
  72. SUBCASE("Material passed many times to the class should remain the same") {
  73. test_sky->set_material(material);
  74. test_sky->set_material(material);
  75. test_sky->set_material(material);
  76. CHECK(test_sky->get_material() == material);
  77. }
  78. SUBCASE("Material rewrite testing") {
  79. Ref<Material> material1;
  80. Ref<Material> material2;
  81. material1.instantiate();
  82. material2.instantiate();
  83. test_sky->set_material(material1);
  84. test_sky->set_material(material2);
  85. CHECK_MESSAGE(test_sky->get_material() != material1,
  86. "After rewrite, second material should be in class.");
  87. CHECK_MESSAGE(test_sky->get_material() == material2,
  88. "After rewrite, second material should be in class.");
  89. }
  90. SUBCASE("Assign same material to two skys") {
  91. Ref<Sky> sky2;
  92. sky2.instantiate();
  93. test_sky->set_material(material);
  94. sky2->set_material(material);
  95. CHECK_MESSAGE(test_sky->get_material() == sky2->get_material(),
  96. "Both skys should have the same material.");
  97. }
  98. SUBCASE("Swapping materials between two skys") {
  99. Ref<Sky> sky2;
  100. sky2.instantiate();
  101. Ref<Material> material1;
  102. Ref<Material> material2;
  103. material1.instantiate();
  104. material2.instantiate();
  105. test_sky->set_material(material1);
  106. sky2->set_material(material2);
  107. CHECK(test_sky->get_material() == material1);
  108. CHECK(sky2->get_material() == material2);
  109. // Do the swap.
  110. Ref<Material> temp = test_sky->get_material();
  111. test_sky->set_material(sky2->get_material());
  112. sky2->set_material(temp);
  113. CHECK(test_sky->get_material() == material2);
  114. CHECK(sky2->get_material() == material1);
  115. }
  116. }
  117. TEST_CASE("[SceneTree][Sky] Invalid radiance size handling") {
  118. Ref<Sky> test_sky;
  119. test_sky.instantiate();
  120. // Attempt to set an invalid radiance size.
  121. ERR_PRINT_OFF;
  122. test_sky->set_radiance_size(Sky::RADIANCE_SIZE_MAX);
  123. ERR_PRINT_ON;
  124. // Verify that the radiance size remains unchanged.
  125. CHECK(test_sky->get_radiance_size() == Sky::RADIANCE_SIZE_256);
  126. }
  127. TEST_CASE("[SceneTree][Sky] Process mode variations") {
  128. Ref<Sky> test_sky;
  129. test_sky.instantiate();
  130. // Test all process modes.
  131. const Sky::ProcessMode process_modes[] = {
  132. Sky::PROCESS_MODE_AUTOMATIC,
  133. Sky::PROCESS_MODE_QUALITY,
  134. Sky::PROCESS_MODE_INCREMENTAL,
  135. Sky::PROCESS_MODE_REALTIME
  136. };
  137. for (Sky::ProcessMode mode : process_modes) {
  138. test_sky->set_process_mode(mode);
  139. CHECK(test_sky->get_process_mode() == mode);
  140. }
  141. }
  142. TEST_CASE("[SceneTree][Sky] Radiance size variations") {
  143. Ref<Sky> test_sky;
  144. test_sky.instantiate();
  145. // Test all radiance sizes except MAX.
  146. const Sky::RadianceSize radiance_sizes[] = {
  147. Sky::RADIANCE_SIZE_32,
  148. Sky::RADIANCE_SIZE_64,
  149. Sky::RADIANCE_SIZE_128,
  150. Sky::RADIANCE_SIZE_256,
  151. Sky::RADIANCE_SIZE_512,
  152. Sky::RADIANCE_SIZE_1024,
  153. Sky::RADIANCE_SIZE_2048
  154. };
  155. for (Sky::RadianceSize size : radiance_sizes) {
  156. test_sky->set_radiance_size(size);
  157. CHECK(test_sky->get_radiance_size() == size);
  158. }
  159. }
  160. TEST_CASE("[SceneTree][Sky] Null material handling") {
  161. Ref<Sky> test_sky;
  162. test_sky.instantiate();
  163. SUBCASE("Setting null material") {
  164. test_sky->set_material(Ref<Material>());
  165. CHECK(test_sky->get_material().is_null());
  166. }
  167. SUBCASE("Overwriting existing material with null") {
  168. Ref<Material> material;
  169. material.instantiate();
  170. test_sky->set_material(material);
  171. test_sky->set_material(Ref<Material>());
  172. CHECK(test_sky->get_material().is_null());
  173. }
  174. }
  175. TEST_CASE("[SceneTree][Sky] RID generation") {
  176. Ref<Sky> test_sky;
  177. test_sky.instantiate();
  178. // Check validity.
  179. CHECK(!test_sky->get_rid().is_valid());
  180. }
  181. } // namespace TestSky
  182. #endif // TEST_SKY_H