Skip to content

Commit 136e4d5

Browse files
matthewestopinalakien-mga
authored andcommitted
Add Unit Test cases for Sky
1 parent e3213aa commit 136e4d5

File tree

2 files changed

+142
-0
lines changed

2 files changed

+142
-0
lines changed

tests/scene/test_sky.h

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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+
#ifndef TEST_SKY_H
32+
#define TEST_SKY_H
33+
34+
#include "scene/resources/sky.h"
35+
36+
#include "tests/test_macros.h"
37+
38+
namespace TestSky {
39+
40+
TEST_CASE("[SceneTree][Sky] Constructor") {
41+
Sky *test_sky = memnew(Sky);
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+
memdelete(test_sky);
47+
}
48+
49+
TEST_CASE("[SceneTree][Sky] Radiance size setter and getter") {
50+
Sky *test_sky = memnew(Sky);
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+
memdelete(test_sky);
66+
}
67+
68+
TEST_CASE("[SceneTree][Sky] Process mode setter and getter") {
69+
Sky *test_sky = memnew(Sky);
70+
71+
// Check default.
72+
CHECK(test_sky->get_process_mode() == Sky::PROCESS_MODE_AUTOMATIC);
73+
74+
test_sky->set_process_mode(Sky::PROCESS_MODE_INCREMENTAL);
75+
CHECK(test_sky->get_process_mode() == Sky::PROCESS_MODE_INCREMENTAL);
76+
77+
memdelete(test_sky);
78+
}
79+
80+
TEST_CASE("[SceneTree][Sky] Material setter and getter") {
81+
Sky *test_sky = memnew(Sky);
82+
Ref<Material> material = memnew(Material);
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 = memnew(Material);
96+
Ref<Material> material2 = memnew(Material);
97+
98+
test_sky->set_material(material1);
99+
test_sky->set_material(material2);
100+
CHECK_MESSAGE(test_sky->get_material() != material1,
101+
"After rewrite, second material should be in class.");
102+
CHECK_MESSAGE(test_sky->get_material() == material2,
103+
"After rewrite, second material should be in class.");
104+
}
105+
106+
SUBCASE("Assign same material to two skys") {
107+
Sky *sky2 = memnew(Sky);
108+
109+
test_sky->set_material(material);
110+
sky2->set_material(material);
111+
CHECK_MESSAGE(test_sky->get_material() == sky2->get_material(),
112+
"Both skys should have the same material.");
113+
memdelete(sky2);
114+
}
115+
116+
SUBCASE("Swapping materials between two skys") {
117+
Sky *sky2 = memnew(Sky);
118+
Ref<Material> material1 = memnew(Material);
119+
Ref<Material> material2 = memnew(Material);
120+
121+
test_sky->set_material(material1);
122+
sky2->set_material(material2);
123+
CHECK(test_sky->get_material() == material1);
124+
CHECK(sky2->get_material() == material2);
125+
126+
// Do the swap.
127+
Ref<Material> temp = test_sky->get_material();
128+
test_sky->set_material(sky2->get_material());
129+
sky2->set_material(temp);
130+
131+
CHECK(test_sky->get_material() == material2);
132+
CHECK(sky2->get_material() == material1);
133+
memdelete(sky2);
134+
}
135+
136+
memdelete(test_sky);
137+
}
138+
139+
} // namespace TestSky
140+
141+
#endif // TEST_SKY_H

tests/test_main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@
161161
#include "tests/scene/test_path_follow_3d.h"
162162
#include "tests/scene/test_primitives.h"
163163
#include "tests/scene/test_skeleton_3d.h"
164+
#include "tests/scene/test_sky.h"
164165
#endif // _3D_DISABLED
165166

166167
#include "modules/modules_tests.gen.h"

0 commit comments

Comments
 (0)