瀏覽代碼

Rename test classes to prevent clashes, use cmake

Kajetan Johannes Hammerle 3 月之前
父節點
當前提交
c8910020f1
共有 4 個文件被更改,包括 200 次插入150 次删除
  1. 167 0
      CMakeLists.txt
  2. 0 119
      meson.build
  3. 15 15
      tests/HashMapTests.cpp
  4. 18 16
      tests/ProbingHashMapTests.cpp

+ 167 - 0
CMakeLists.txt

@@ -0,0 +1,167 @@
+cmake_minimum_required(VERSION 3.25)
+project(core)
+
+set(CMAKE_CXX_STANDARD 20)
+
+set(SRC
+    "utils/Logger.cpp"
+    "utils/Utility.cpp"
+    "utils/Error.cpp"
+    "utils/New.cpp"
+    "utils/Buffer.cpp"
+    "utils/Clock.cpp"
+    "utils/Random.cpp"
+    "data/BitArray.cpp"
+    "math/Math.cpp"
+    "math/Vector.cpp"
+    "math/Quaternion.cpp"
+    "math/Matrix.cpp"
+    "math/Box.cpp"
+    "math/Plane.cpp"
+    "math/Frustum.cpp"
+    "math/View.cpp"
+    "thread/Thread.cpp"
+    "io/FileReader.cpp"
+)
+
+set(SRC_TESTS
+    "test/Main.cpp"
+    "test/Test.cpp"
+    "tests/ArrayTests.cpp"
+    "tests/ArrayStringTests.cpp"
+    "tests/UtilityTests.cpp"
+    "tests/ArrayListTests.cpp"
+    "tests/BitArrayTests.cpp"
+    "tests/MathTests.cpp"
+    "tests/ListTests.cpp"
+    "tests/LinkedListTests.cpp"
+    "tests/UniquePointerTests.cpp"
+    "tests/HashMapTests.cpp"
+    "tests/ProbingHashMapTests.cpp"
+    "tests/StackTests.cpp"
+    "tests/RingBufferTests.cpp"
+    "tests/ComponentsTests.cpp"
+    "tests/VectorTests.cpp"
+    "tests/QuaternionTests.cpp"
+    "tests/MatrixTests.cpp"
+    "tests/BoxTests.cpp"
+    "tests/BufferedValueTests.cpp"
+    "tests/PlaneTests.cpp"
+    "tests/FrustumTests.cpp"
+    "tests/ViewTests.cpp"
+    "tests/MatrixStackTests.cpp"
+    "tests/ColorTests.cpp"
+    "tests/BufferTests.cpp"
+    "tests/ClockTests.cpp"
+    "tests/RandomTests.cpp"
+    "tests/ThreadTests.cpp"
+    "tests/FileReaderTests.cpp"
+)
+
+set(SRC_PERFORMANCE
+    "performance/Main.cpp"
+    "test/Test.cpp"
+)
+
+add_library(core STATIC ${SRC})
+target_include_directories(core PUBLIC ".")
+target_compile_options(core PUBLIC
+    -Wdeprecated-enum-float-conversion
+    -Wctad-maybe-unsupported
+    -Werror
+    -Wdeprecated-enum-enum-conversion
+    -Winvalid-imported-macros
+    -Wextra
+    -Wzero-as-null-pointer-constant
+    -Wframe-larger-than=8388608
+    -Wundef
+    -Wunused-const-variable=2
+    -Wconditionally-supported
+    -Wwrite-strings
+    -Wlarger-than=1073741824
+    -Wimplicit-fallthrough=5
+    -Wduplicated-cond
+    -Wdisabled-optimization
+    -Wsuggest-final-methods
+    -Wformat-signedness
+    -Wtrivial-auto-var-init
+    -Wmissing-include-dirs
+    -Winfinite-recursion
+    -Wdeprecated-copy-dtor
+    -Wanalyzer-too-complex
+    -Wduplicated-branches
+    -Wstrict-null-sentinel
+    -Wmissing-declarations
+    -Wformat-truncation=2
+    -Wmultiple-inheritance
+    -Wstack-usage=8388608
+    -Winit-self
+    -Wsynth
+    -Wvirtual-inheritance
+    -Wstringop-overflow=4
+    -Wcast-qual
+    -Wshadow
+    -Wsuggest-final-types
+    -Woverloaded-virtual
+    -Wconversion
+    -Walloca
+    -Woverlength-strings
+    -Wctor-dtor-privacy
+    -Wswitch-enum
+    -pedantic
+    -Wstrict-overflow=2
+    -Wcast-align=strict
+    -Wfloat-equal
+    -Wformat=2
+    -Wattribute-alias=2
+    -Wformat-overflow=2
+    -Winvalid-pch
+    -Wvolatile
+    -Wshift-overflow=2
+    -Warith-conversion
+    -Wcatch-value=3
+    -Wnoexcept
+    -Wuse-after-free=3
+    -Wdouble-promotion
+    -Wunused-macros
+    -Wregister
+    -Wsuggest-override
+    -Wnull-dereference
+    -Wtrampolines
+    -Wlogical-op
+    -Wnon-virtual-dtor
+    -pedantic-errors
+    -Wbidi-chars=any
+    -Wdate-time
+    -Warray-parameter
+    -Waligned-new=all
+    -Wold-style-cast
+    -Wmultichar
+    -Wstack-protector
+    -Wmissing-braces
+    -Warray-bounds=2
+    -Walloc-zero
+    -Wplacement-new=2
+    -Wmismatched-tags
+    -Wcomma-subscript
+    -Wall
+    -Wbidi-chars
+    -Wredundant-tags
+    -Wenum-conversion
+    -Wall
+    -Wredundant-decls
+    -Wsign-conversion
+    -fdiagnostics-color=always
+    -nostdinc++
+    -fno-exceptions
+    -fno-rtti
+    -fno-threadsafe-statics
+)
+target_compile_definitions(core PUBLIC CORE_LOG_LEVEL=4)
+target_link_libraries(core PUBLIC -nodefaultlibs c m)
+
+add_executable(test ${SRC_TESTS})
+target_link_libraries(test PRIVATE core)
+
+add_executable(performance ${SRC_PERFORMANCE})
+target_link_libraries(performance PRIVATE core)

+ 0 - 119
meson.build

@@ -1,119 +0,0 @@
-project('core', 'cpp', default_options : ['cpp_std=c++2a'])
-
-src = [
-    'utils/Logger.cpp',
-    'utils/Utility.cpp',
-    'utils/Error.cpp',
-    'utils/New.cpp',
-    'utils/Buffer.cpp',
-    'utils/Clock.cpp',
-    'utils/Random.cpp',
-    'data/BitArray.cpp',
-    'math/Math.cpp',
-    'math/Vector.cpp',
-    'math/Quaternion.cpp',
-    'math/Matrix.cpp',
-    'math/Box.cpp',
-    'math/Plane.cpp',
-    'math/Frustum.cpp',
-    'math/View.cpp',
-    'thread/Thread.cpp',
-    'io/FileReader.cpp',
-]
-
-src_tests = [
-    'test/Main.cpp',
-    'test/Test.cpp',
-    'tests/ArrayTests.cpp',
-    'tests/ArrayStringTests.cpp',
-    'tests/UtilityTests.cpp',
-    'tests/ArrayListTests.cpp',
-    'tests/BitArrayTests.cpp',
-    'tests/MathTests.cpp',
-    'tests/ListTests.cpp',
-    'tests/LinkedListTests.cpp',
-    'tests/UniquePointerTests.cpp',
-    'tests/HashMapTests.cpp',
-    'tests/ProbingHashMapTests.cpp',
-    'tests/StackTests.cpp',
-    'tests/RingBufferTests.cpp',
-    'tests/ComponentsTests.cpp',
-    'tests/VectorTests.cpp',
-    'tests/QuaternionTests.cpp',
-    'tests/MatrixTests.cpp',
-    'tests/BoxTests.cpp',
-    'tests/BufferedValueTests.cpp',
-    'tests/PlaneTests.cpp',
-    'tests/FrustumTests.cpp',
-    'tests/ViewTests.cpp',
-    'tests/MatrixStackTests.cpp',
-    'tests/ColorTests.cpp',
-    'tests/BufferTests.cpp',
-    'tests/ClockTests.cpp',
-    'tests/RandomTests.cpp',
-    'tests/ThreadTests.cpp',
-    'tests/FileReaderTests.cpp',
-]
-
-src_performance = [
-    'performance/Main.cpp',
-    'test/Test.cpp',
-]
-
-compiler = meson.get_compiler('cpp')
-error_args = compiler.get_supported_arguments([
-    '-Wdeprecated-enum-float-conversion', '-Wctad-maybe-unsupported', '-Werror',
-    '-Wdeprecated-enum-enum-conversion', '-Winvalid-imported-macros', '-Wextra',
-    '-Wzero-as-null-pointer-constant', '-Wframe-larger-than=8388608', '-Wundef',
-    '-Wunused-const-variable=2', '-Wconditionally-supported', '-Wwrite-strings',
-    '-Wlarger-than=1073741824', '-Wimplicit-fallthrough=5', '-Wduplicated-cond',
-    '-Wdisabled-optimization', '-Wsuggest-final-methods', '-Wformat-signedness',
-    '-Wtrivial-auto-var-init', '-Wmissing-include-dirs', '-Winfinite-recursion',
-    '-Wdeprecated-copy-dtor', '-Wanalyzer-too-complex', '-Wduplicated-branches',
-    '-Wstrict-null-sentinel', '-Wmissing-declarations', '-Wformat-truncation=2',
-    '-Wmultiple-inheritance', '-Wstack-usage=8388608', '-Winit-self', '-Wsynth',
-    '-Wvirtual-inheritance', '-Wstringop-overflow=4', '-Wcast-qual', '-Wshadow',
-    '-Wsuggest-final-types', '-Woverloaded-virtual', '-Wconversion', '-Walloca',
-    '-Woverlength-strings', '-Wctor-dtor-privacy', '-Wswitch-enum', '-pedantic',
-    '-Wstrict-overflow=2', '-Wcast-align=strict', '-Wfloat-equal', '-Wformat=2',
-    '-Wattribute-alias=2', '-Wformat-overflow=2', '-Winvalid-pch', '-Wvolatile',
-    '-Wshift-overflow=2', '-Warith-conversion', '-Wcatch-value=3', '-Wnoexcept',
-    '-Wuse-after-free=3', '-Wdouble-promotion', '-Wunused-macros', '-Wregister',
-    '-Wsuggest-override', '-Wnull-dereference', '-Wtrampolines', '-Wlogical-op',
-    '-Wnon-virtual-dtor', '-pedantic-errors', '-Wbidi-chars=any', '-Wdate-time',
-    '-Warray-parameter', '-Waligned-new=all', '-Wold-style-cast', '-Wmultichar',
-    '-Wstack-protector', '-Wmissing-braces', '-Warray-bounds=2', '-Walloc-zero',
-    '-Wplacement-new=2', '-Wmismatched-tags', '-Wcomma-subscript', '-Wall',
-    '-Wbidi-chars', '-Wredundant-tags', '-Wenum-conversion', '-Wall',
-    '-Wredundant-decls', '-Wsign-conversion'
-])
-compile_args = compiler.get_supported_arguments([
-    '-nostdinc++', '-fno-exceptions', '-fno-rtti', '-fno-threadsafe-statics'
-])
-link_args = compiler.get_supported_arguments([
-    '-nodefaultlibs', '-lc', '-lm', '-lpthread'
-])
-
-
-core_include = [include_directories('.')]
-core = static_library('core', 
-    sources: src,
-    include_directories: core_include,
-    cpp_args: error_args + compile_args + ['-DCORE_LOG_LEVEL=4'],
-    link_args: link_args)
-
-core_dep = declare_dependency(
-    include_directories: core_include,
-    link_with: core)
-
-executable('tests', 
-    sources: src_tests,
-    dependencies: core_dep,
-    cpp_args: error_args + compile_args + ['-DCORE_LOG_LEVEL=4'],
-    link_args: link_args)
-
-executable('performance', 
-    sources: src_performance,
-    dependencies: core_dep,
-    cpp_args: error_args + compile_args + ['-DCORE_LOG_LEVEL=4'],
-    link_args: link_args)

+ 15 - 15
tests/HashMapTests.cpp

@@ -72,20 +72,20 @@ static void testOverflow() {
     }
 }
 
-struct A final {
+struct HashMapTestStruct final {
     int a;
     int b;
 
-    A(int a_, int b_) : a(a_), b(b_) {
+    HashMapTestStruct(int a_, int b_) : a(a_), b(b_) {
     }
 
     // none of these should be needed for the hashmap
-    A(const A&) = delete;
-    A(A&&) = delete;
-    A& operator=(const A&) = delete;
-    A& operator=(A&&) = delete;
+    HashMapTestStruct(const HashMapTestStruct&) = delete;
+    HashMapTestStruct(HashMapTestStruct&&) = delete;
+    HashMapTestStruct& operator=(const HashMapTestStruct&) = delete;
+    HashMapTestStruct& operator=(HashMapTestStruct&&) = delete;
 
-    bool operator==(const A& other) const {
+    bool operator==(const HashMapTestStruct& other) const {
         return a == other.a && b == other.b;
     }
 
@@ -101,27 +101,27 @@ struct A final {
 };
 
 static void testEmplace() {
-    Core::HashMap<int, A> map;
+    Core::HashMap<int, HashMapTestStruct> map;
 
-    A* ar = nullptr;
+    HashMapTestStruct* ar = nullptr;
     CORE_TEST_ERROR(map.tryEmplace(ar, 0, 3, 4));
     CORE_TEST_ERROR(map.tryEmplace(ar, 3, 4, 5));
     CORE_TEST_ERROR(map.tryEmplace(ar, 20, 5, 6));
     CORE_TEST_EQUAL(Core::Error::EXISTING_KEY, map.tryEmplace(ar, 3, 6, 7));
     CORE_TEST_EQUAL(Core::Error::EXISTING_KEY, map.tryEmplace(ar, 20, 7, 8));
 
-    A* a = map.search(0);
-    A* b = map.search(3);
-    A* c = map.search(20);
+    HashMapTestStruct* a = map.search(0);
+    HashMapTestStruct* b = map.search(3);
+    HashMapTestStruct* c = map.search(20);
 
     CORE_TEST_NOT_NULL(a);
     CORE_TEST_NOT_NULL(b);
     CORE_TEST_NOT_NULL(c);
 
     if(a != nullptr && b != nullptr && c != nullptr) {
-        CORE_TEST_EQUAL(A(3, 4), *a);
-        CORE_TEST_EQUAL(A(4, 5), *b);
-        CORE_TEST_EQUAL(A(5, 6), *c);
+        CORE_TEST_EQUAL(HashMapTestStruct(3, 4), *a);
+        CORE_TEST_EQUAL(HashMapTestStruct(4, 5), *b);
+        CORE_TEST_EQUAL(HashMapTestStruct(5, 6), *c);
     }
 }
 

+ 18 - 16
tests/ProbingHashMapTests.cpp

@@ -76,30 +76,32 @@ static void testOverflow() {
 
 static int aInstances = 0;
 
-struct A final {
+struct ProbingHashMapTestStruct final {
     int a;
     int b;
 
-    A(int a_, int b_) : a(a_), b(b_) {
+    ProbingHashMapTestStruct(int a_, int b_) : a(a_), b(b_) {
         aInstances++;
     }
 
-    A(const A& o) : a(o.a), b(o.b) {
+    ProbingHashMapTestStruct(const ProbingHashMapTestStruct& o)
+        : a(o.a), b(o.b) {
         aInstances++;
     }
 
-    A(A&& o) : a(o.a), b(o.b) {
+    ProbingHashMapTestStruct(ProbingHashMapTestStruct&& o) : a(o.a), b(o.b) {
         aInstances++;
     }
 
-    ~A() {
+    ~ProbingHashMapTestStruct() {
         aInstances--;
     }
 
-    A& operator=(const A& o) = default;
-    A& operator=(A&& o) = default;
+    ProbingHashMapTestStruct&
+    operator=(const ProbingHashMapTestStruct& o) = default;
+    ProbingHashMapTestStruct& operator=(ProbingHashMapTestStruct&& o) = default;
 
-    bool operator==(const A& other) const {
+    bool operator==(const ProbingHashMapTestStruct& other) const {
         return a == other.a && b == other.b;
     }
 
@@ -116,9 +118,9 @@ struct A final {
 
 static void testEmplace() {
     {
-        Core::ProbingHashMap<int, A> map;
+        Core::ProbingHashMap<int, ProbingHashMapTestStruct> map;
 
-        A* ar = nullptr;
+        ProbingHashMapTestStruct* ar = nullptr;
         CORE_TEST_ERROR(map.tryEmplace(ar, 0, 3, 4));
         CORE_TEST_ERROR(map.tryEmplace(ar, 3, 4, 5));
         CORE_TEST_ERROR(map.tryEmplace(ar, 20, 5, 6));
@@ -126,18 +128,18 @@ static void testEmplace() {
         CORE_TEST_EQUAL(Core::Error::EXISTING_KEY,
                         map.tryEmplace(ar, 20, 7, 8));
 
-        A* a = map.search(0);
-        A* b = map.search(3);
-        A* c = map.search(20);
+        ProbingHashMapTestStruct* a = map.search(0);
+        ProbingHashMapTestStruct* b = map.search(3);
+        ProbingHashMapTestStruct* c = map.search(20);
 
         CORE_TEST_NOT_NULL(a);
         CORE_TEST_NOT_NULL(b);
         CORE_TEST_NOT_NULL(c);
 
         if(a != nullptr && b != nullptr && c != nullptr) {
-            CORE_TEST_EQUAL(A(3, 4), *a);
-            CORE_TEST_EQUAL(A(4, 5), *b);
-            CORE_TEST_EQUAL(A(5, 6), *c);
+            CORE_TEST_EQUAL(ProbingHashMapTestStruct(3, 4), *a);
+            CORE_TEST_EQUAL(ProbingHashMapTestStruct(4, 5), *b);
+            CORE_TEST_EQUAL(ProbingHashMapTestStruct(5, 6), *c);
         }
     }
     CORE_TEST_EQUAL(0, aInstances);