Added first C++ test
parent
758e3bd227
commit
9bcc3580d6
7
SCsub
7
SCsub
|
@ -6,6 +6,7 @@ Import('env_modules')
|
|||
# SIMD noise support would have to wait for Godot 4...
|
||||
FAST_NOISE_2_SRC = False
|
||||
FAST_NOISE_2_STATIC = False
|
||||
RUN_TESTS = True
|
||||
|
||||
env_voxel = env_modules.Clone()
|
||||
|
||||
|
@ -57,6 +58,12 @@ if env["tools"]:
|
|||
]
|
||||
voxel_files += voxel_editor_files
|
||||
|
||||
if RUN_TESTS:
|
||||
voxel_files += [
|
||||
"tests/tests.cpp"
|
||||
]
|
||||
env_voxel.Append(CPPDEFINES={"VOXEL_RUN_TESTS": 0})
|
||||
|
||||
if env["platform"] == "windows":
|
||||
# When compiling SQLite with Godot on Windows with MSVC, it produces the following warning:
|
||||
# `sqlite3.c(42754): warning C4996: 'GetVersionExA': was declared deprecated `
|
||||
|
|
|
@ -49,6 +49,10 @@
|
|||
#include "editor/voxel_debug.h"
|
||||
#endif
|
||||
|
||||
#ifdef VOXEL_RUN_TESTS
|
||||
#include "tests/tests.h"
|
||||
#endif
|
||||
|
||||
void register_voxel_types() {
|
||||
VoxelMemoryPool::create_singleton();
|
||||
VoxelStringNames::create_singleton();
|
||||
|
@ -136,6 +140,10 @@ void register_voxel_types() {
|
|||
EditorPlugins::add_by_type<VoxelInstanceLibraryEditorPlugin>();
|
||||
EditorPlugins::add_by_type<FastNoiseLiteEditorPlugin>();
|
||||
#endif
|
||||
|
||||
#ifdef VOXEL_RUN_TESTS
|
||||
run_voxel_tests();
|
||||
#endif
|
||||
}
|
||||
|
||||
void unregister_voxel_types() {
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
#include "tests.h"
|
||||
#include "../util/math/rect3i.h"
|
||||
|
||||
#include <core/hash_map.h>
|
||||
#include <core/print_string.h>
|
||||
|
||||
void test_rect3i_for_inner_outline() {
|
||||
const Rect3i box(-1, 2, 3, 4, 3, 2);
|
||||
|
||||
HashMap<Vector3i, bool, Vector3iHasher> expected_coords;
|
||||
const Rect3i inner_box = box.padded(-1);
|
||||
box.for_each_cell([&expected_coords, inner_box](Vector3i pos) {
|
||||
expected_coords.set(pos, false);
|
||||
});
|
||||
|
||||
box.for_inner_outline([&expected_coords](Vector3i pos) {
|
||||
bool *b = expected_coords.getptr(pos);
|
||||
if (b == nullptr) {
|
||||
ERR_FAIL_MSG("Unexpected position");
|
||||
}
|
||||
if (*b) {
|
||||
ERR_FAIL_MSG("Duplicate position");
|
||||
}
|
||||
*b = true;
|
||||
});
|
||||
|
||||
const Vector3i *key = nullptr;
|
||||
while ((key = expected_coords.next(key))) {
|
||||
bool v = expected_coords[*key];
|
||||
if (!v) {
|
||||
ERR_FAIL_MSG("Missing position");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void run_voxel_tests() {
|
||||
print_line("------------ Voxel tests begin -------------");
|
||||
|
||||
test_rect3i_for_inner_outline();
|
||||
|
||||
print_line("------------ Voxel tests end -------------");
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef VOXEL_TESTS_H
|
||||
#define VOXEL_TESTS_H
|
||||
|
||||
void run_voxel_tests();
|
||||
|
||||
#endif // VOXEL_TESTS_H
|
Loading…
Reference in New Issue