| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "scene/resources/sky.h" |
| 34 |
|
| 35 |
#include "tests/test_macros.h" |
| 36 |
|
| 37 |
namespace TestSky { |
| 38 |
|
| 39 |
TEST_CASE("[SceneTree][Sky] Constructor") { |
| 40 |
Ref<Sky> test_sky; |
| 41 |
test_sky.instantiate(); |
| 42 |
|
| 43 |
CHECK(test_sky->get_process_mode() == Sky::PROCESS_MODE_AUTOMATIC); |
| 44 |
CHECK(test_sky->get_radiance_size() == Sky::RADIANCE_SIZE_256); |
| 45 |
CHECK(test_sky->get_material().is_null()); |
| 46 |
} |
| 47 |
|
| 48 |
TEST_CASE("[SceneTree][Sky] Radiance size setter and getter") { |
| 49 |
Ref<Sky> test_sky; |
| 50 |
test_sky.instantiate(); |
| 51 |
|
| 52 |
|
| 53 |
CHECK(test_sky->get_radiance_size() == Sky::RADIANCE_SIZE_256); |
| 54 |
|
| 55 |
test_sky->set_radiance_size(Sky::RADIANCE_SIZE_1024); |
| 56 |
CHECK(test_sky->get_radiance_size() == Sky::RADIANCE_SIZE_1024); |
| 57 |
|
| 58 |
ERR_PRINT_OFF; |
| 59 |
|
| 60 |
test_sky->set_radiance_size(Sky::RADIANCE_SIZE_MAX); |
| 61 |
ERR_PRINT_ON; |
| 62 |
|
| 63 |
CHECK(test_sky->get_radiance_size() == Sky::RADIANCE_SIZE_1024); |
| 64 |
} |
| 65 |
|
| 66 |
TEST_CASE("[SceneTree][Sky] Process mode setter and getter") { |
| 67 |
Ref<Sky> test_sky; |
| 68 |
test_sky.instantiate(); |
| 69 |
|
| 70 |
|
| 71 |
CHECK(test_sky->get_process_mode() == Sky::PROCESS_MODE_AUTOMATIC); |
| 72 |
|
| 73 |
test_sky->set_process_mode(Sky::PROCESS_MODE_INCREMENTAL); |
| 74 |
CHECK(test_sky->get_process_mode() == Sky::PROCESS_MODE_INCREMENTAL); |
| 75 |
} |
| 76 |
|
| 77 |
TEST_CASE("[SceneTree][Sky] Material setter and getter") { |
| 78 |
Ref<Sky> test_sky; |
| 79 |
test_sky.instantiate(); |
| 80 |
|
| 81 |
Ref<Material> material; |
| 82 |
material.instantiate(); |
| 83 |
|
| 84 |
SUBCASE("Material passed to the class should remain the same") { |
| 85 |
test_sky->set_material(material); |
| 86 |
CHECK(test_sky->get_material() == material); |
| 87 |
} |
| 88 |
SUBCASE("Material passed many times to the class should remain the same") { |
| 89 |
test_sky->set_material(material); |
| 90 |
test_sky->set_material(material); |
| 91 |
test_sky->set_material(material); |
| 92 |
CHECK(test_sky->get_material() == material); |
| 93 |
} |
| 94 |
SUBCASE("Material rewrite testing") { |
| 95 |
Ref<Material> material1; |
| 96 |
Ref<Material> material2; |
| 97 |
material1.instantiate(); |
| 98 |
material2.instantiate(); |
| 99 |
|
| 100 |
test_sky->set_material(material1); |
| 101 |
test_sky->set_material(material2); |
| 102 |
CHECK_MESSAGE(test_sky->get_material() != material1, |
| 103 |
"After rewrite, second material should be in class."); |
| 104 |
CHECK_MESSAGE(test_sky->get_material() == material2, |
| 105 |
"After rewrite, second material should be in class."); |
| 106 |
} |
| 107 |
|
| 108 |
SUBCASE("Assign same material to two skys") { |
| 109 |
Ref<Sky> sky2; |
| 110 |
sky2.instantiate(); |
| 111 |
|
| 112 |
test_sky->set_material(material); |
| 113 |
sky2->set_material(material); |
| 114 |
CHECK_MESSAGE(test_sky->get_material() == sky2->get_material(), |
| 115 |
"Both skys should have the same material."); |
| 116 |
} |
| 117 |
|
| 118 |
SUBCASE("Swapping materials between two skys") { |
| 119 |
Ref<Sky> sky2; |
| 120 |
sky2.instantiate(); |
| 121 |
Ref<Material> material1; |
| 122 |
Ref<Material> material2; |
| 123 |
material1.instantiate(); |
| 124 |
material2.instantiate(); |
| 125 |
|
| 126 |
test_sky->set_material(material1); |
| 127 |
sky2->set_material(material2); |
| 128 |
CHECK(test_sky->get_material() == material1); |
| 129 |
CHECK(sky2->get_material() == material2); |
| 130 |
|
| 131 |
|
| 132 |
Ref<Material> temp = test_sky->get_material(); |
| 133 |
test_sky->set_material(sky2->get_material()); |
| 134 |
sky2->set_material(temp); |
| 135 |
|
| 136 |
CHECK(test_sky->get_material() == material2); |
| 137 |
CHECK(sky2->get_material() == material1); |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
TEST_CASE("[SceneTree][Sky] Invalid radiance size handling") { |
| 142 |
Ref<Sky> test_sky; |
| 143 |
test_sky.instantiate(); |
| 144 |
|
| 145 |
|
| 146 |
ERR_PRINT_OFF; |
| 147 |
test_sky->set_radiance_size(Sky::RADIANCE_SIZE_MAX); |
| 148 |
ERR_PRINT_ON; |
| 149 |
|
| 150 |
|
| 151 |
CHECK(test_sky->get_radiance_size() == Sky::RADIANCE_SIZE_256); |
| 152 |
} |
| 153 |
|
| 154 |
TEST_CASE("[SceneTree][Sky] Process mode variations") { |
| 155 |
Ref<Sky> test_sky; |
| 156 |
test_sky.instantiate(); |
| 157 |
|
| 158 |
|
| 159 |
const Sky::ProcessMode process_modes[] = { |
| 160 |
Sky::PROCESS_MODE_AUTOMATIC, |
| 161 |
Sky::PROCESS_MODE_QUALITY, |
| 162 |
Sky::PROCESS_MODE_INCREMENTAL, |
| 163 |
Sky::PROCESS_MODE_REALTIME |
| 164 |
}; |
| 165 |
|
| 166 |
for (Sky::ProcessMode mode : process_modes) { |
| 167 |
test_sky->set_process_mode(mode); |
| 168 |
CHECK(test_sky->get_process_mode() == mode); |
| 169 |
} |
| 170 |
} |
| 171 |
|
| 172 |
TEST_CASE("[SceneTree][Sky] Radiance size variations") { |
| 173 |
Ref<Sky> test_sky; |
| 174 |
test_sky.instantiate(); |
| 175 |
|
| 176 |
|
| 177 |
const Sky::RadianceSize radiance_sizes[] = { |
| 178 |
Sky::RADIANCE_SIZE_32, |
| 179 |
Sky::RADIANCE_SIZE_64, |
| 180 |
Sky::RADIANCE_SIZE_128, |
| 181 |
Sky::RADIANCE_SIZE_256, |
| 182 |
Sky::RADIANCE_SIZE_512, |
| 183 |
Sky::RADIANCE_SIZE_1024, |
| 184 |
Sky::RADIANCE_SIZE_2048 |
| 185 |
}; |
| 186 |
|
| 187 |
for (Sky::RadianceSize size : radiance_sizes) { |
| 188 |
test_sky->set_radiance_size(size); |
| 189 |
CHECK(test_sky->get_radiance_size() == size); |
| 190 |
} |
| 191 |
} |
| 192 |
|
| 193 |
TEST_CASE("[SceneTree][Sky] Null material handling") { |
| 194 |
Ref<Sky> test_sky; |
| 195 |
test_sky.instantiate(); |
| 196 |
|
| 197 |
SUBCASE("Setting null material") { |
| 198 |
test_sky->set_material(Ref<Material>()); |
| 199 |
CHECK(test_sky->get_material().is_null()); |
| 200 |
} |
| 201 |
|
| 202 |
SUBCASE("Overwriting existing material with null") { |
| 203 |
Ref<Material> material; |
| 204 |
material.instantiate(); |
| 205 |
test_sky->set_material(material); |
| 206 |
test_sky->set_material(Ref<Material>()); |
| 207 |
|
| 208 |
CHECK(test_sky->get_material().is_null()); |
| 209 |
} |
| 210 |
} |
| 211 |
|
| 212 |
TEST_CASE("[SceneTree][Sky] RID generation") { |
| 213 |
Ref<Sky> test_sky; |
| 214 |
test_sky.instantiate(); |
| 215 |
|
| 216 |
CHECK(!test_sky->get_rid().is_valid()); |
| 217 |
} |
| 218 |
|
| 219 |
} |