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