- Separated Platform and Compiler Dependent Behaviour into CMake scripts

- Implemented Basic Platform Interfaces
 - Implemented partial Linux platform and Wayland Display.
 - Implemented Dependencies for the above
   - map
     - set
       - optional
     - pair

TODO: threading
This commit is contained in:
2025-07-22 00:59:41 -04:00
parent ab1c7d94be
commit 73333b4c67
86 changed files with 3257 additions and 203 deletions

View File

@@ -27,6 +27,12 @@ add_executable(fennec-test main.cpp
printing.h
tests/math/test_ext.h
tests/math/ext/test_quaternion.h
tests/platform/linux/test_wayland.h
tests/platform/test_linux.h
tests/test_platform.h
tests/lang/test_hashing.h
tests/containers/test_array.h
tests/containers/test_set.h
)
target_compile_definitions(fennec-test PUBLIC FENNEC_TEST_CWD="${CMAKE_SOURCE_DIR}/bin/${FENNEC_BUILD_NAME}"

View File

@@ -23,7 +23,9 @@
#include "tests/test_memory.h"
#include "test.h"
#include "tests/test_containers.h"
#include "tests/test_fproc.h"
#include "tests/test_platform.h"
int main(int, char **)
@@ -37,6 +39,11 @@ int main(int, char **)
fennec::test::fennec_test_lang();
fennec_test_spacer(3);
fennec_test_header("containers library");
fennec_test_spacer(2);
fennec::test::fennec_test_containers();
fennec_test_spacer(3);
fennec_test_header("math library");
fennec_test_spacer(2);
fennec::test::fennec_test_math();
@@ -47,5 +54,10 @@ int main(int, char **)
fennec::test::fennec_test_fproc();
fennec_test_spacer(3);
fennec_test_header("platform library");
fennec_test_spacer(2);
fennec::test::fennec_test_platform();
fennec_test_spacer(3);
return 0;
}

View File

@@ -73,7 +73,7 @@ inline void __fennec_test_run(const std::string& expression, const ResultT& resu
std::cout << std::endl;
// Assert to halt and get some debug info
assert(passed, "Test Failed");
assertf(passed, "Test Failed");
}
}

View File

@@ -0,0 +1,49 @@
// =====================================================================================================================
// fennec, a free and open source game engine
// Copyright © 2025 Medusa Slockbower
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// =====================================================================================================================
#ifndef FENNEC_TEST_CONTAINERS_ARRAY_H
#define FENNEC_TEST_CONTAINERS_ARRAY_H
#include "../../test.h"
#include <fennec/containers/array.h>
namespace fennec
{
namespace test
{
inline void fennec_test_containers_array() {
const char string[] = "Hello World!";
array<char, sizeof(string)> arr1;
array<char, sizeof(string)> arr2;
strcpy(&arr1[0], string);
strcpy(&arr2[0], string);
fennec_test_run(strcmp(&arr1[0], string), 0);
fennec_test_run(strcmp(&arr2[0], string), 0);
fennec_test_run(arr1 == arr2, true);
}
}
}
#endif // FENNEC_TEST_CONTAINERS_ARRAY_H

View File

@@ -0,0 +1,55 @@
// =====================================================================================================================
// fennec, a free and open source game engine
// Copyright © 2025 Medusa Slockbower
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// =====================================================================================================================
#ifndef FENNEC_TEST_CONTAINERS_DYNARRAY_H
#define FENNEC_TEST_CONTAINERS_DYNARRAY_H
#include "../../test.h"
#include <fennec/containers/dynarray.h>
namespace fennec
{
namespace test
{
inline void fennec_test_containers_dynarray() {
dynarray<int> test1;
dynarray<int> test2;
int n = 10000;
test1.resize(n); test2.resize(n);
for (int i = 0; i < n; ++i) {
test1.push_back(i);
test2.push_back(n - i - 1);
}
for (int i = 0; i < n; ++i) {
assertf(test1[i] == test2[n - i - 1], "Failed dynarray::push_back");
}
std::cout << "passed" << std::endl;
}
}
}
#endif // FENNEC_TEST_CONTAINERS_DYNARRAY_H

View File

@@ -0,0 +1,124 @@
// =====================================================================================================================
// fennec, a free and open source game engine
// Copyright © 2025 Medusa Slockbower
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// =====================================================================================================================
#ifndef FENNEC_TEST_CONTAINERS_OPTIONAL_H
#define FENNEC_TEST_CONTAINERS_OPTIONAL_H
#include "../../test.h"
#include <fennec/containers/optional.h>
namespace fennec
{
namespace test
{
enum opt_test_ : uint8_t {
opt_test_none = 0x1 << 0,
opt_test_default_constructor = 0x1 << 1,
opt_test_destructor = 0x1 << 2,
opt_test_copy_constructor = 0x1 << 3,
opt_test_move_constructor = 0x1 << 4,
opt_test_copy_assignment = 0x1 << 5,
opt_test_move_assignment = 0x1 << 6,
};
struct optional_helper {
inline static uint8_t test = opt_test_none;
optional_helper() : i(0) {
fennec_test_run(bool(test & opt_test_default_constructor), true);
}
~optional_helper() {
fennec_test_run(bool(test & opt_test_destructor), true);
}
optional_helper(const optional_helper&) : i(0) {
fennec_test_run(bool(test & opt_test_copy_constructor), true);
}
optional_helper(optional_helper&&) noexcept : i(0) {
fennec_test_run(bool(test & opt_test_move_constructor), true);
}
optional_helper& operator=(const optional_helper&) {
fennec_test_run(bool(test & opt_test_copy_assignment), true);
return *this;
}
optional_helper& operator=(optional_helper&&) noexcept {
fennec_test_run(bool(test & opt_test_move_assignment), true);
return *this;
}
int i;
};
inline void fennec_test_containers_optional() {
static_assert(
is_default_constructible_v<optional_helper>
and is_copy_constructible_v<optional_helper>
and is_move_constructible_v<optional_helper>
and is_copy_assignable_v<optional_helper>
and is_move_assignable_v<optional_helper>
);
optional<optional_helper> opt = optional<optional_helper>();
optional_helper::test = opt_test_default_constructor;
opt.emplace();
optional_helper::test = opt_test_destructor;
opt.reset();
optional_helper::test = opt_test_default_constructor | opt_test_copy_constructor | opt_test_destructor;
opt = copy(optional_helper());
optional_helper::test = opt_test_destructor;
opt.reset();
optional_helper::test = opt_test_default_constructor | opt_test_move_constructor | opt_test_destructor;
opt = optional_helper();
optional_helper::test = opt_test_destructor;
opt.reset();
optional_helper::test = opt_test_default_constructor;
opt.emplace();
optional_helper::test = opt_test_default_constructor | opt_test_copy_assignment | opt_test_destructor;
opt = copy(optional_helper());
optional_helper::test = opt_test_default_constructor | opt_test_move_assignment | opt_test_destructor;
opt = optional_helper();
optional_helper::test = opt_test_destructor;
opt.reset();
std::cout << opt << std::endl;
std::cout << "passed" << std::endl;
}
}
}
#endif // FENNEC_TEST_CONTAINERS_OPTIONAL_H

View File

@@ -0,0 +1,58 @@
// =====================================================================================================================
// fennec, a free and open source game engine
// Copyright © 2025 Medusa Slockbower
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// =====================================================================================================================
#ifndef FENNEC_TEST_CONTAINERS_SET_H
#define FENNEC_TEST_CONTAINERS_SET_H
#include "../../test.h"
#include <cstdlib>
#include <unordered_set>
#include <fennec/containers/set.h>
namespace fennec
{
namespace test
{
inline void fennec_test_containers_set() {
using type_t = decltype(rand());
std::unordered_set<type_t> ref;
set<type_t> test;
srand(0);
for (int i = 0; i < 10000; ++i) {
type_t v = rand();
ref.insert(v);
test.insert(v);
}
for (int i = 0; i < 10000; ++i) {
assertf(ref.contains(i) == test.contains(i), "set test failed");
}
std::cout << "passed" << std::endl;
}
}
}
#endif // FENNEC_TEST_CONTAINERS_SET_H

View File

@@ -47,8 +47,6 @@ inline void fennec_test_fproc_strings_cstring()
fennec_test_run(str.rfind('o'), static_cast<size_t>(7));
fennec_test_run(str.rfind("World"), static_cast<size_t>(6));
fennec_test_spacer(2);
}
}

View File

@@ -88,8 +88,6 @@ inline void fennec_test_fproc_io() {
fennec_test_run(file::cout().write("Hello World!"), sizeof("Hello World!"));
fennec_test_run(file::cerr().write("Hello World!"), sizeof("Hello World!"));
fennec_test_spacer(2);
}
}

View File

@@ -35,6 +35,7 @@ inline void fennec_test_fproc_strings()
fennec_test_fproc_strings_cstring();
fennec_test_spacer(3);
// TODO
}
}

View File

@@ -30,7 +30,7 @@ namespace fennec
namespace test
{
void fennec_test_lang_bits()
inline void fennec_test_lang_bits()
{
int a = 0x48ef13ad;
int b = 0x23e5ab9c;

View File

@@ -0,0 +1,57 @@
// =====================================================================================================================
// fennec, a free and open source game engine
// Copyright © 2025 Medusa Slockbower
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// =====================================================================================================================
#ifndef FENNEC_TEST_LANG_HASHING_H
#define FENNEC_TEST_LANG_HASHING_H
#include <fennec/lang/hashing.h>
#include "../../test.h"
namespace fennec
{
namespace test
{
inline void fennec_test_lang_hashing() {
size_t num = 61;
float_t numf = bit_cast<float>((uint32_t)num);
double_t numd = bit_cast<double>(num);
size_t exp = hash<size_t>()(num);
fennec_test_run(hash<int8_t>()(num), exp);
fennec_test_run(hash<uint8_t>()(num), exp);
fennec_test_run(hash<int16_t>()(num), exp);
fennec_test_run(hash<uint16_t>()(num), exp);
fennec_test_run(hash<int32_t>()(num), exp);
fennec_test_run(hash<uint32_t>()(num), exp);
fennec_test_run(hash<int64_t>()(num), exp);
fennec_test_run(hash<uint64_t>()(num), exp);
fennec_test_spacer(1);
fennec_test_run(hash<float_t>()(numf), exp);
fennec_test_run(hash<double_t>()(numd), exp);
}
}
}
#endif // FENNEC_TEST_LANG_HASHING_H

View File

@@ -32,6 +32,8 @@ inline void test_sequences()
static_assert(fennec::is_same_v<make_index_sequence_t<2>, index_sequence<0, 1>>);
static_assert(fennec::is_same_v<make_index_sequence_t<3>, index_sequence<0, 1, 2>>);
static_assert(fennec::is_same_v<make_index_sequence_t<4>, index_sequence<0, 1, 2, 3>>);
// TODO
}
}

View File

@@ -38,6 +38,8 @@ inline void fennec_test_math_quaternion() {
fennec_test_run(quat(), quat(1, 0, 0, 0));
fennec_test_spacer(2);
// TODO
}
}

View File

@@ -208,9 +208,6 @@ inline void fennec_test_math_common()
fennec_test_run(mix(0.0f, 1.0f, false), 0.0f);
fennec_test_run(mix(0.0f, 1.0f, true), 1.0f);
fennec_test_spacer(2);
}
}

View File

@@ -75,9 +75,6 @@ inline void fennec_test_math_exponential()
fennec_test_run(fennec::inversesqrt(1.0f), 1.0f / 1.0f);
fennec_test_run(fennec::inversesqrt(4.0f), 1.0f / 2.0f);
fennec_test_run(fennec::inversesqrt(9.0f), 1.0f / 3.0f);
fennec_test_spacer(2);
}
}

View File

@@ -36,6 +36,7 @@ inline void fennec_test_math_ext() {
fennec_test_math_quaternion();
fennec_test_spacer(3);
// TODO
}
}

View File

@@ -77,9 +77,6 @@ inline void fennec_test_math_geometric()
fennec_test_run(fennec::reflect(vec2(1, -1), vec2(0, 1)), vec2(1, 1));
fennec_test_run(fennec::refract(vec2(1, -1), vec2(0, 1), 1/1.33f), vec2(0.7518797, -1));
fennec_test_spacer(2);
}
}

View File

@@ -320,8 +320,6 @@ inline void fennec_test_math_matrix()
fennec_test_run(fennec::inverse(mat2(1, 2, 3, 4)), mat2(-2, 1, 1.5, -0.5));
fennec_test_run(fennec::inverse(mat3(1, 2, 3, 0, 1, 4, 5, 6, 0)), mat3(-24, 18, 5, 20, -15, -4, -5, 4, 1));
fennec_test_run(fennec::inverse(mat4(2, 1, -3, 4, -1, 0, 2, 5, 3, 2, 1, 0, 4, -2, 3, 1)), (1.0f / 414.0f) * mat4(36, -39, 33, 51, -18, 31, 133, -83, -72, 55, 49, 13, 36, 53, -13, 5));
fennec_test_spacer(2);
}
}

View File

@@ -45,8 +45,6 @@ inline void fennec_test_math_relational()
fennec_test_run(not(bvec3(true, false, true)), bvec3(false, true, false));
fennec_test_run(fennec::all(bvec3(true, true, true)), true);
fennec_test_spacer(2);
}
}

View File

@@ -112,11 +112,6 @@ inline void fennec_test_math_trigonometric()
fennec_test_run(fennec::asinh((fennec::e<float>() - fennec::one_over_e<float>()) / 2.0f), 1.0f);
fennec_test_run(fennec::acosh((fennec::e<float>() + fennec::one_over_e<float>()) / 2.0f), 1.0f);
fennec_test_run(fennec::atanh(((fennec::e_raised_two<float>() - 1) / (fennec::e_raised_two<float>() + 1))), 1.0f);
fennec_test_spacer(2);
}
}

View File

@@ -594,8 +594,6 @@ inline void fennec_test_math_vector()
fennec_test_run(([]() -> ivec2 { ivec2 v(0x2A1E, 0x7BF3); return v >>= ivec2(4, 8); }()), ivec2(0x2A1, 0x7B));
fennec_test_run(([]() -> ivec3 { ivec3 v(0x2A1E, 0x7BF3, 0x3927); return v >>= ivec3(4, 8, 12); }()), ivec3(0x2A1, 0x7B, 0x3));
fennec_test_run(([]() -> ivec4 { ivec4 v(0x2A1E, 0x7BF3, 0x3927, 0x237C); return v >>= ivec4(4, 8, 12, 16); }()), ivec4(0x2A1, 0x7B, 0x3, 0x0));
}
}

View File

@@ -0,0 +1,43 @@
// =====================================================================================================================
// fennec, a free and open source game engine
// Copyright © 2025 Medusa Slockbower
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// =====================================================================================================================
#ifndef FENNEC_TEST_PLATFORM_LINUX_WAYLAND_H
#define FENNEC_TEST_PLATFORM_LINUX_WAYLAND_H
#include "../../../test.h"
#include <fennec/platform/linux/wayland/display.h>
namespace fennec
{
namespace test
{
using namespace wayland;
inline void fennec_test_platform_linux_wayland(linux_platform& platform) {
wayland_display* display = static_cast<wayland_display*>(platform.get_display());
fennec_test_run(display != nullptr, true);
}
}
}
#endif // FENNEC_TEST_PLATFORM_LINUX_WAYLAND_H

View File

@@ -0,0 +1,51 @@
// =====================================================================================================================
// fennec, a free and open source game engine
// Copyright © 2025 Medusa Slockbower
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// =====================================================================================================================
#ifndef FENNEC_TEST_PLATFORM_LINUX_H
#define FENNEC_TEST_PLATFORM_LINUX_H
#include "../../test.h"
#ifdef FENNEC_LIB_WAYLAND
#include "linux/test_wayland.h"
#endif
namespace fennec
{
namespace test
{
inline void fennec_test_platform_linux() {
linux_platform platform(platform::user::client);
#ifdef FENNEC_LIB_WAYLAND
fennec_test_section("wayland tests");
fennec_test_spacer(2);
fennec_test_platform_linux_wayland(platform);
fennec_test_spacer(3);
#endif
// TODO
}
}
}
#endif // FENNEC_TEST_PLATFORM_LINUX_H

View File

@@ -0,0 +1,61 @@
// =====================================================================================================================
// fennec-test, a program to execute unit tests for fennec
// Copyright © 2025 Medusa Slockbower
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// =====================================================================================================================
#ifndef FENNEC_TEST_CONTAINERS_H
#define FENNEC_TEST_CONTAINERS_H
#include "containers/test_array.h"
#include "containers/test_dynarray.h"
#include "containers/test_optional.h"
#include "containers/test_set.h"
namespace fennec
{
namespace test
{
inline void fennec_test_containers()
{
fennec_test_subheader("optional tests");
fennec_test_spacer(2);
fennec_test_containers_optional();
fennec_test_spacer(3);
fennec_test_subheader("array tests");
fennec_test_spacer(2);
fennec_test_containers_array();
fennec_test_spacer(3);
fennec_test_subheader("dynarray tests");
fennec_test_spacer(2);
fennec_test_containers_dynarray();
fennec_test_spacer(3);
fennec_test_subheader("set tests");
fennec_test_spacer(2);
fennec_test_containers_set();
// TODO
}
}
}
#endif // FENNEC_TEST_CONTAINERS_H

View File

@@ -40,6 +40,8 @@ inline void fennec_test_fproc() {
fennec_test_spacer(2);
fennec_test_fproc_io();
fennec_test_spacer(3);
// TODO
}
}

View File

@@ -21,6 +21,7 @@
#include "lang/test_bits.h"
#include "lang/test_conditional_types.h"
#include "lang/test_hashing.h"
namespace fennec
{
@@ -34,6 +35,12 @@ inline void fennec_test_lang()
fennec_test_spacer(2);
fennec_test_lang_bits();
fennec_test_spacer(3);
fennec_test_subheader("hashing tests");
fennec_test_spacer(2);
fennec_test_lang_hashing();
// TODO
}
}

View File

@@ -83,6 +83,8 @@ inline void fennec_test_math()
fennec_test_spacer(2);
fennec_test_math_ext();
fennec_test_spacer(3);
// TODO
}
}

View File

@@ -19,4 +19,6 @@
#ifndef FENNEC_TEST_MEMORY_H
#define FENNEC_TEST_MEMORY_H
// TODO
#endif // FENNEC_TEST_MEMORY_H

View File

@@ -0,0 +1,46 @@
// =====================================================================================================================
// fennec, a free and open source game engine
// Copyright © 2025 Medusa Slockbower
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// =====================================================================================================================
#ifndef FENNEC_TEST_PLATFORM_H
#define FENNEC_TEST_PLATFORM_H
#include "../test.h"
#if FENNEC_PLATFORM_LINUX
#include "./platform/test_linux.h"
#endif
namespace fennec
{
namespace test
{
inline void fennec_test_platform() {
#if FENNEC_PLATFORM_LINUX
fennec_test_subheader("linux");
fennec_test_spacer(2);
fennec_test_platform_linux();
fennec_test_spacer(3);
#endif
}
}
}
#endif // FENNEC_TEST_PLATFORM_H