Browse Source

Remove const, rise coverage

Kajetan Johannes Hammerle 11 months ago
parent
commit
f540b31c6d
7 changed files with 37 additions and 8 deletions
  1. 2 1
      CMakeLists.txt
  2. 1 1
      include/core/HashMap.h
  3. 3 6
      src/Test.c
  4. 2 0
      tasks
  5. 3 0
      test/Main.c
  6. 1 0
      test/Tests.h
  7. 25 0
      test/modules/TestTests.c

+ 2 - 1
CMakeLists.txt

@@ -43,6 +43,7 @@ set(SRC_TESTS
     "test/modules/ReadLineTests.c"
     "test/modules/RingBufferTests.c"
     "test/modules/SpinLockTests.c"
+    "test/modules/TestTests.c"
     "test/modules/UtilityTests.c"
     "test/modules/VectorTests.c"
     "test/modules/ViewTests.c"
@@ -56,7 +57,7 @@ if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
     set(COMPILE_OPTIONS "")
     set(LINK_OPTIONS "")
     set(LOG_LEVEL 2)
-    set(DEFINITIONS "")
+    set(DEFINITIONS CORE_CHECK_MEMORY)
 else()
     set(DEFINITIONS ERROR_SIMULATOR CORE_CHECK_MEMORY)
     if(CMAKE_C_COMPILER_ID STREQUAL "GNU")

+ 1 - 1
include/core/HashMap.h

@@ -70,7 +70,7 @@ bool coreHashMapHasNext(CoreHashMapIterator* mi);
 CoreHashMapNode* coreHashMapNext(CoreHashMapIterator* mi);
 #define coreHashMapKeyPointer(node, type) ((const type*)node->key)
 #define coreHashMapKey(node, type) (*coreHashMapKeyPointer(node, type))
-#define coreHashMapValuePointer(node, type) ((const type*)node->value)
+#define coreHashMapValuePointer(node, type) ((type*)node->value)
 #define coreHashMapValue(node, type) (*coreHashMapValuePointer(node, type))
 
 #endif

+ 3 - 6
src/Test.c

@@ -5,6 +5,7 @@
 #include <string.h>
 
 #include "core/Logger.h"
+#include "core/Utility.h"
 
 typedef struct {
     char* file;
@@ -25,11 +26,7 @@ static Result* getResult(const char* file) {
     }
     while(resultsIndex >= resultsCapacity) {
         size_t newCapacity = resultsCapacity == 0 ? 8 : resultsCapacity * 2;
-        results = realloc(results, newCapacity * sizeof(Result));
-        if(results == nullptr) {
-            printf("realloc failure in '%s' at '%d'\n", __FILE__, __LINE__);
-            exit(1);
-        }
+        results = coreReallocate(results, newCapacity * sizeof(Result));
         resultsCapacity = newCapacity;
     }
     Result* r = results + (resultsIndex++);
@@ -49,7 +46,7 @@ void coreFinalizeTests(void) {
         puts(CORE_TERMINAL_RESET);
         free(r->file);
     }
-    free(results);
+    coreFree(results);
     results = nullptr;
     resultsIndex = 0;
     resultsCapacity = 0;

+ 2 - 0
tasks

@@ -153,6 +153,8 @@ function runTests() {
     LLVM_PROFILE_FILE="pre_canary.profraw" $valgrind ./test pre_canary $valgrind || true
     echo "--------------Post canary detection-------------"
     LLVM_PROFILE_FILE="post_canary.profraw" $valgrind ./test post_canary $valgrind || true
+    echo "--------------Test Fails------------------------"
+    LLVM_PROFILE_FILE="test.profraw" $valgrind ./test test $valgrind || true
     echo "--------------Default run-----------------------"
     LLVM_PROFILE_FILE="default.profraw" $valgrind ./test light $valgrind < ../readLineTest || true
 }

+ 3 - 0
test/Main.c

@@ -28,6 +28,9 @@ int main(int argAmount, const char** args) {
             coreTestPreCanary();
         } else if(strcmp(args[i], "post_canary") == 0) {
             coreTestPostCanary();
+        } else if(strcmp(args[i], "test") == 0) {
+            coreTestTest();
+            return 0;
         }
     }
 

+ 1 - 0
test/Tests.h

@@ -22,6 +22,7 @@ void coreTestRandom(bool light);
 void coreTestReadLine(void);
 void coreTestRingBuffer(void);
 void coreTestSpinLock(void);
+void coreTestTest(void);
 void coreTestUtility(bool light);
 void coreTestVector(void);
 void coreTestView(void);

+ 25 - 0
test/modules/TestTests.c

@@ -0,0 +1,25 @@
+#include "../Tests.h"
+#include "core/Vector.h"
+
+void coreTestTest() {
+    CORE_TEST_BOOL(false, true);
+    CORE_TEST_INT(0, 1);
+    CORE_TEST_I64(0, 1);
+    CORE_TEST_U64(0, 1);
+    CORE_TEST_SIZE(0, 1);
+    CORE_TEST_STRING("a", "b");
+    CORE_TEST_FALSE(true);
+    CORE_TEST_TRUE(false);
+    CORE_TEST_NULL(&(int){0});
+    CORE_TEST_NOT_NULL(nullptr);
+    CORE_TEST_FLOAT(0.0f, 1.0f, 0.1f);
+
+    CoreVector2 a = {0, 1};
+    CoreVector2 b = {2, 3};
+    CORE_TEST_V2(&a, &b);
+
+    CoreIntVector2 ia = {0, 1};
+    CoreIntVector2 ib = {2, 3};
+    CORE_TEST_IV2(&ia, &ib);
+    coreFinalizeTests();
+}