mirror of
https://github.com/godotengine/godot.git
synced 2024-12-21 10:25:24 +08:00
Add unit tests to Sky
This commit is contained in:
parent
893bbdfde8
commit
1e62c7f53e
@ -38,16 +38,17 @@
|
||||
namespace TestSky {
|
||||
|
||||
TEST_CASE("[SceneTree][Sky] Constructor") {
|
||||
Sky *test_sky = memnew(Sky);
|
||||
Ref<Sky> test_sky;
|
||||
test_sky.instantiate();
|
||||
|
||||
CHECK(test_sky->get_process_mode() == Sky::PROCESS_MODE_AUTOMATIC);
|
||||
CHECK(test_sky->get_radiance_size() == Sky::RADIANCE_SIZE_256);
|
||||
CHECK(test_sky->get_material().is_null());
|
||||
memdelete(test_sky);
|
||||
}
|
||||
|
||||
TEST_CASE("[SceneTree][Sky] Radiance size setter and getter") {
|
||||
Sky *test_sky = memnew(Sky);
|
||||
Ref<Sky> test_sky;
|
||||
test_sky.instantiate();
|
||||
|
||||
// Check default.
|
||||
CHECK(test_sky->get_radiance_size() == Sky::RADIANCE_SIZE_256);
|
||||
@ -61,25 +62,25 @@ TEST_CASE("[SceneTree][Sky] Radiance size setter and getter") {
|
||||
ERR_PRINT_ON;
|
||||
|
||||
CHECK(test_sky->get_radiance_size() == Sky::RADIANCE_SIZE_1024);
|
||||
|
||||
memdelete(test_sky);
|
||||
}
|
||||
|
||||
TEST_CASE("[SceneTree][Sky] Process mode setter and getter") {
|
||||
Sky *test_sky = memnew(Sky);
|
||||
Ref<Sky> test_sky;
|
||||
test_sky.instantiate();
|
||||
|
||||
// Check default.
|
||||
CHECK(test_sky->get_process_mode() == Sky::PROCESS_MODE_AUTOMATIC);
|
||||
|
||||
test_sky->set_process_mode(Sky::PROCESS_MODE_INCREMENTAL);
|
||||
CHECK(test_sky->get_process_mode() == Sky::PROCESS_MODE_INCREMENTAL);
|
||||
|
||||
memdelete(test_sky);
|
||||
}
|
||||
|
||||
TEST_CASE("[SceneTree][Sky] Material setter and getter") {
|
||||
Sky *test_sky = memnew(Sky);
|
||||
Ref<Material> material = memnew(Material);
|
||||
Ref<Sky> test_sky;
|
||||
test_sky.instantiate();
|
||||
|
||||
Ref<Material> material;
|
||||
material.instantiate();
|
||||
|
||||
SUBCASE("Material passed to the class should remain the same") {
|
||||
test_sky->set_material(material);
|
||||
@ -92,8 +93,10 @@ TEST_CASE("[SceneTree][Sky] Material setter and getter") {
|
||||
CHECK(test_sky->get_material() == material);
|
||||
}
|
||||
SUBCASE("Material rewrite testing") {
|
||||
Ref<Material> material1 = memnew(Material);
|
||||
Ref<Material> material2 = memnew(Material);
|
||||
Ref<Material> material1;
|
||||
Ref<Material> material2;
|
||||
material1.instantiate();
|
||||
material2.instantiate();
|
||||
|
||||
test_sky->set_material(material1);
|
||||
test_sky->set_material(material2);
|
||||
@ -104,19 +107,22 @@ TEST_CASE("[SceneTree][Sky] Material setter and getter") {
|
||||
}
|
||||
|
||||
SUBCASE("Assign same material to two skys") {
|
||||
Sky *sky2 = memnew(Sky);
|
||||
Ref<Sky> sky2;
|
||||
sky2.instantiate();
|
||||
|
||||
test_sky->set_material(material);
|
||||
sky2->set_material(material);
|
||||
CHECK_MESSAGE(test_sky->get_material() == sky2->get_material(),
|
||||
"Both skys should have the same material.");
|
||||
memdelete(sky2);
|
||||
}
|
||||
|
||||
SUBCASE("Swapping materials between two skys") {
|
||||
Sky *sky2 = memnew(Sky);
|
||||
Ref<Material> material1 = memnew(Material);
|
||||
Ref<Material> material2 = memnew(Material);
|
||||
Ref<Sky> sky2;
|
||||
sky2.instantiate();
|
||||
Ref<Material> material1;
|
||||
Ref<Material> material2;
|
||||
material1.instantiate();
|
||||
material2.instantiate();
|
||||
|
||||
test_sky->set_material(material1);
|
||||
sky2->set_material(material2);
|
||||
@ -130,10 +136,85 @@ TEST_CASE("[SceneTree][Sky] Material setter and getter") {
|
||||
|
||||
CHECK(test_sky->get_material() == material2);
|
||||
CHECK(sky2->get_material() == material1);
|
||||
memdelete(sky2);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("[SceneTree][Sky] Invalid radiance size handling") {
|
||||
Ref<Sky> test_sky;
|
||||
test_sky.instantiate();
|
||||
|
||||
// Attempt to set an invalid radiance size.
|
||||
ERR_PRINT_OFF;
|
||||
test_sky->set_radiance_size(Sky::RADIANCE_SIZE_MAX);
|
||||
ERR_PRINT_ON;
|
||||
|
||||
// Verify that the radiance size remains unchanged.
|
||||
CHECK(test_sky->get_radiance_size() == Sky::RADIANCE_SIZE_256);
|
||||
}
|
||||
|
||||
TEST_CASE("[SceneTree][Sky] Process mode variations") {
|
||||
Ref<Sky> test_sky;
|
||||
test_sky.instantiate();
|
||||
|
||||
// Test all process modes.
|
||||
const Sky::ProcessMode process_modes[] = {
|
||||
Sky::PROCESS_MODE_AUTOMATIC,
|
||||
Sky::PROCESS_MODE_QUALITY,
|
||||
Sky::PROCESS_MODE_INCREMENTAL,
|
||||
Sky::PROCESS_MODE_REALTIME
|
||||
};
|
||||
|
||||
for (Sky::ProcessMode mode : process_modes) {
|
||||
test_sky->set_process_mode(mode);
|
||||
CHECK(test_sky->get_process_mode() == mode);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("[SceneTree][Sky] Radiance size variations") {
|
||||
Ref<Sky> test_sky;
|
||||
test_sky.instantiate();
|
||||
|
||||
// Test all radiance sizes except MAX.
|
||||
const Sky::RadianceSize radiance_sizes[] = {
|
||||
Sky::RADIANCE_SIZE_32,
|
||||
Sky::RADIANCE_SIZE_64,
|
||||
Sky::RADIANCE_SIZE_128,
|
||||
Sky::RADIANCE_SIZE_256,
|
||||
Sky::RADIANCE_SIZE_512,
|
||||
Sky::RADIANCE_SIZE_1024,
|
||||
Sky::RADIANCE_SIZE_2048
|
||||
};
|
||||
|
||||
for (Sky::RadianceSize size : radiance_sizes) {
|
||||
test_sky->set_radiance_size(size);
|
||||
CHECK(test_sky->get_radiance_size() == size);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("[SceneTree][Sky] Null material handling") {
|
||||
Ref<Sky> test_sky;
|
||||
test_sky.instantiate();
|
||||
|
||||
SUBCASE("Setting null material") {
|
||||
test_sky->set_material(Ref<Material>());
|
||||
CHECK(test_sky->get_material().is_null());
|
||||
}
|
||||
|
||||
memdelete(test_sky);
|
||||
SUBCASE("Overwriting existing material with null") {
|
||||
Ref<Material> material;
|
||||
material.instantiate();
|
||||
test_sky->set_material(material);
|
||||
test_sky->set_material(Ref<Material>());
|
||||
|
||||
CHECK(test_sky->get_material().is_null());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("[SceneTree][Sky] RID generation") {
|
||||
Ref<Sky> test_sky;
|
||||
test_sky.instantiate();
|
||||
// Check validity.
|
||||
CHECK(!test_sky->get_rid().is_valid());
|
||||
}
|
||||
|
||||
} // namespace TestSky
|
||||
|
Loading…
Reference in New Issue
Block a user