Debian Codegraph @

tests/scene/test_sky.h

raw symbols SCIP
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
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 // Check default.
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 // Check setting invalid radiance size.
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 // Check default.
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 // Do the swap.
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 // Attempt to set an invalid radiance size.
146 ERR_PRINT_OFF;
147 test_sky->set_radiance_size(Sky::RADIANCE_SIZE_MAX);
148 ERR_PRINT_ON;
149
150 // Verify that the radiance size remains unchanged.
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 // Test all process modes.
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 // Test all radiance sizes except MAX.
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 // Check validity.
216 CHECK(!test_sky->get_rid().is_valid());
217 }
218
219 } // namespace TestSky