test_sky.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. Sky *test_sky = memnew(Sky);
  37. CHECK(test_sky->get_process_mode() == Sky::PROCESS_MODE_AUTOMATIC);
  38. CHECK(test_sky->get_radiance_size() == Sky::RADIANCE_SIZE_256);
  39. CHECK(test_sky->get_material().is_null());
  40. memdelete(test_sky);
  41. }
  42. TEST_CASE("[SceneTree][Sky] Radiance size setter and getter") {
  43. Sky *test_sky = memnew(Sky);
  44. // Check default.
  45. CHECK(test_sky->get_radiance_size() == Sky::RADIANCE_SIZE_256);
  46. test_sky->set_radiance_size(Sky::RADIANCE_SIZE_1024);
  47. CHECK(test_sky->get_radiance_size() == Sky::RADIANCE_SIZE_1024);
  48. ERR_PRINT_OFF;
  49. // Check setting invalid radiance size.
  50. test_sky->set_radiance_size(Sky::RADIANCE_SIZE_MAX);
  51. ERR_PRINT_ON;
  52. CHECK(test_sky->get_radiance_size() == Sky::RADIANCE_SIZE_1024);
  53. memdelete(test_sky);
  54. }
  55. TEST_CASE("[SceneTree][Sky] Process mode setter and getter") {
  56. Sky *test_sky = memnew(Sky);
  57. // Check default.
  58. CHECK(test_sky->get_process_mode() == Sky::PROCESS_MODE_AUTOMATIC);
  59. test_sky->set_process_mode(Sky::PROCESS_MODE_INCREMENTAL);
  60. CHECK(test_sky->get_process_mode() == Sky::PROCESS_MODE_INCREMENTAL);
  61. memdelete(test_sky);
  62. }
  63. TEST_CASE("[SceneTree][Sky] Material setter and getter") {
  64. Sky *test_sky = memnew(Sky);
  65. Ref<Material> material = memnew(Material);
  66. SUBCASE("Material passed to the class should remain the same") {
  67. test_sky->set_material(material);
  68. CHECK(test_sky->get_material() == material);
  69. }
  70. SUBCASE("Material passed many times to the class should remain the same") {
  71. test_sky->set_material(material);
  72. test_sky->set_material(material);
  73. test_sky->set_material(material);
  74. CHECK(test_sky->get_material() == material);
  75. }
  76. SUBCASE("Material rewrite testing") {
  77. Ref<Material> material1 = memnew(Material);
  78. Ref<Material> material2 = memnew(Material);
  79. test_sky->set_material(material1);
  80. test_sky->set_material(material2);
  81. CHECK_MESSAGE(test_sky->get_material() != material1,
  82. "After rewrite, second material should be in class.");
  83. CHECK_MESSAGE(test_sky->get_material() == material2,
  84. "After rewrite, second material should be in class.");
  85. }
  86. SUBCASE("Assign same material to two skys") {
  87. Sky *sky2 = memnew(Sky);
  88. test_sky->set_material(material);
  89. sky2->set_material(material);
  90. CHECK_MESSAGE(test_sky->get_material() == sky2->get_material(),
  91. "Both skys should have the same material.");
  92. memdelete(sky2);
  93. }
  94. SUBCASE("Swapping materials between two skys") {
  95. Sky *sky2 = memnew(Sky);
  96. Ref<Material> material1 = memnew(Material);
  97. Ref<Material> material2 = memnew(Material);
  98. test_sky->set_material(material1);
  99. sky2->set_material(material2);
  100. CHECK(test_sky->get_material() == material1);
  101. CHECK(sky2->get_material() == material2);
  102. // Do the swap.
  103. Ref<Material> temp = test_sky->get_material();
  104. test_sky->set_material(sky2->get_material());
  105. sky2->set_material(temp);
  106. CHECK(test_sky->get_material() == material2);
  107. CHECK(sky2->get_material() == material1);
  108. memdelete(sky2);
  109. }
  110. memdelete(test_sky);
  111. }
  112. } // namespace TestSky
  113. #endif // TEST_SKY_H