浏览代码

Rename everything with new style

Kajetan Johannes Hammerle 3 周之前
父节点
当前提交
31bacbc52f
共有 6 个文件被更改,包括 88 次插入92 次删除
  1. 18 20
      include/core/utils/Logger.h
  2. 7 6
      src/Logger.c
  3. 3 3
      test/Main.c
  4. 9 11
      test/Test.c
  5. 20 21
      test/Test.h
  6. 31 31
      test/Tests.h

+ 18 - 20
include/core/utils/Logger.h

@@ -1,8 +1,6 @@
 #ifndef CORE_LOGGER_HPP
 #define CORE_LOGGER_HPP
 
-#include <stdio.h>
-
 #include "core/utils/Check.h"
 
 #define CORE_TERMINAL_RED "\33[1;31m"
@@ -12,48 +10,48 @@
 #define CORE_TERMINAL_RESET "\33[0m"
 
 typedef enum {
-    LOG_LEVEL_ERROR,
-    LOG_LEVEL_WARNING,
-    LOG_LEVEL_INFO,
-    LOG_LEVEL_DEBUG
-} Logger_Level;
+    CORE_LOG_ERROR,
+    CORE_LOG_WARNING,
+    CORE_LOG_INFO,
+    CORE_LOG_DEBUG
+} CoreLogLevel;
 
-extern Logger_Level logLevel;
+extern CoreLogLevel coreLogLevel;
 
-const char* Logger_getShortFileName(const char* s);
+const char* coreGetShortFileName(const char* s);
 
-check_format(6, 7) void Logger_log(Logger_Level l, const char* file, int line,
-                                   const char* prefix, const char* tag,
-                                   const char* format, ...);
+check_format(6, 7) void coreLog(CoreLogLevel l, const char* file, int line,
+                                const char* prefix, const char* tag,
+                                const char* format, ...);
 
 #if defined(CORE_LOG_LEVEL) && CORE_LOG_LEVEL >= 1
 #define CORE_LOG_ERROR(...)                                                    \
-    Logger_log(LOG_LEVEL_ERROR, __FILE__, __LINE__, CORE_TERMINAL_RED,         \
-               "[ERROR] ", __VA_ARGS__);
+    coreLog(CORE_LOG_ERROR, __FILE__, __LINE__, CORE_TERMINAL_RED, "[ERROR] ", \
+            __VA_ARGS__);
 #else
 #define CORE_LOG_ERROR(...)
 #endif
 
 #if defined(CORE_LOG_LEVEL) && CORE_LOG_LEVEL >= 2
 #define CORE_LOG_WARNING(...)                                                  \
-    Logger_log(LOG_LEVEL_WARNING, __FILE__, __LINE__, CORE_TERMINAL_YELLOW,    \
-               "[WARNING] ", __VA_ARGS__);
+    coreLog(CORE_LOG_WARNING, __FILE__, __LINE__, CORE_TERMINAL_YELLOW,        \
+            "[WARNING] ", __VA_ARGS__);
 #else
 #define CORE_LOG_WARNING(...)
 #endif
 
 #if defined(CORE_LOG_LEVEL) && CORE_LOG_LEVEL >= 3
 #define CORE_LOG_INFO(...)                                                     \
-    Logger_log(LOG_LEVEL_INFO, __FILE__, __LINE__, CORE_TERMINAL_GRAY,         \
-               "[INFO] ", __VA_ARGS__);
+    coreLog(CORE_LOG_INFO, __FILE__, __LINE__, CORE_TERMINAL_GRAY, "[INFO] ",  \
+            __VA_ARGS__);
 #else
 #define CORE_LOG_INFO(...)
 #endif
 
 #if defined(CORE_LOG_LEVEL) && CORE_LOG_LEVEL >= 4
 #define CORE_LOG_DEBUG(...)                                                    \
-    Logger_log(LOG_LEVEL_DEBUG, __FILE__, __LINE__, CORE_TERMINAL_GREEN,       \
-               "[DEBUG] ", __VA_ARGS__);
+    coreLog(CORE_LOG_DEBUG, __FILE__, __LINE__, CORE_TERMINAL_GREEN,           \
+            "[DEBUG] ", __VA_ARGS__);
 #else
 #define CORE_LOG_DEBUG(...)
 #endif

+ 7 - 6
src/Logger.c

@@ -1,10 +1,11 @@
 #include "core/utils/Logger.h"
 
 #include <stdarg.h>
+#include <stdio.h>
 
-Logger_Level logLevel = LOG_LEVEL_DEBUG;
+CoreLogLevel coreLogLevel = CORE_LOG_DEBUG;
 
-const char* Logger_getShortFileName(const char* s) {
+const char* coreGetShortFileName(const char* s) {
     const char* r = s;
     while(*s != '\0') {
         if(*(s++) == '/') {
@@ -14,12 +15,12 @@ const char* Logger_getShortFileName(const char* s) {
     return r;
 }
 
-void Logger_log(Logger_Level l, const char* file, int line, const char* prefix,
-                const char* tag, const char* format, ...) {
-    if(logLevel < l) {
+void coreLog(CoreLogLevel l, const char* file, int line, const char* prefix,
+             const char* tag, const char* format, ...) {
+    if(coreLogLevel < l) {
         return;
     }
-    file = Logger_getShortFileName(file);
+    file = coreGetShortFileName(file);
     fputs(prefix, stdout);
     fputs(tag, stdout);
     printf("%s:%d | ", file, line);

+ 3 - 3
test/Main.c

@@ -40,7 +40,7 @@ int main(int argAmount, const char** args) {
     CORE_TEST_FLOAT(0, 3, 1);
     CORE_TEST_STRING("wusi", "GUSI");
     CORE_TEST_STRING("wusi", "wusi");
-    Test_finalize();
+    coreFinalizeTests();
 
     CORE_LOG_DEBUG("This is a test %d", 6);
     CORE_LOG_INFO("This is a test");
@@ -80,9 +80,9 @@ int main(int argAmount, const char** args) {
     Core::testVector();
     Core::testView();*/
 
-    logLevel = LOG_LEVEL_WARNING;
+    coreLogLevel = CORE_LOG_WARNING;
     CORE_LOG_DEBUG("You won't see this!");
-    logLevel = LOG_LEVEL_DEBUG;
+    coreLogLevel = CORE_LOG_DEBUG;
 
     // unsigned int data = 123456789;
     // Core::setExitHandler(onExit, &data);

+ 9 - 11
test/Test.c

@@ -39,7 +39,7 @@ static Result* getResult(const char* file) {
     return r;
 }
 
-void Test_finalize(void) {
+void coreFinalizeTests(void) {
     for(size_t i = 0; i < resultsIndex; i++) {
         Result* r = results + i;
         bool c = r->successTests == r->tests;
@@ -66,13 +66,13 @@ static bool addToResult(const char* file, bool comparison) {
 }
 
 #define CORE_TEST_SUCCESS(result)                                              \
-    file = Logger_getShortFileName(file);                                      \
+    file = coreGetShortFileName(file);                                         \
     if(addToResult(file, result)) {                                            \
         return true;                                                           \
     }
 
 #define CORE_TEST_NAMED_COMPARE(name, type, format)                            \
-    bool Test_compare_##name(CORE_TEST_ARGS, type wanted, type actual) {       \
+    bool coreTest##name(CORE_TEST_ARGS, type wanted, type actual) {            \
         CORE_TEST_SUCCESS(wanted == actual)                                    \
         fputs(CORE_TERMINAL_RED, stdout);                                      \
         printf("%s:%d - expected '" format "' got '" format "'", file, line,   \
@@ -81,11 +81,10 @@ static bool addToResult(const char* file, bool comparison) {
         return false;                                                          \
     }
 
-CORE_TEST_NAMED_COMPARE(int, int, "%d")
-CORE_TEST_NAMED_COMPARE(bool, bool, "%d")
+CORE_TEST_NAMED_COMPARE(Int, int, "%d")
+CORE_TEST_NAMED_COMPARE(Bool, bool, "%d")
 
-bool Test_compare_string(CORE_TEST_ARGS, const char* wanted,
-                         const char* actual) {
+bool coreTestString(CORE_TEST_ARGS, const char* wanted, const char* actual) {
     CORE_TEST_SUCCESS(strcmp(wanted, actual) == 0);
     fputs(CORE_TERMINAL_RED, stdout);
     printf("%s:%d - expected '%s' got '%s'", file, line, wanted, actual);
@@ -93,8 +92,7 @@ bool Test_compare_string(CORE_TEST_ARGS, const char* wanted,
     return false;
 }
 
-bool Test_compare_float(CORE_TEST_ARGS, float wanted, float actual,
-                        float error) {
+bool coreTestFloat(CORE_TEST_ARGS, float wanted, float actual, float error) {
     float diff = wanted - actual;
     diff = diff < 0.0f ? -diff : diff;
     CORE_TEST_SUCCESS(diff <= error);
@@ -105,7 +103,7 @@ bool Test_compare_float(CORE_TEST_ARGS, float wanted, float actual,
     return false;
 }
 
-bool Test_isNull(CORE_TEST_ARGS, const void* actual) {
+bool coreTestNull(CORE_TEST_ARGS, const void* actual) {
     CORE_TEST_SUCCESS(actual == nullptr);
     fputs(CORE_TERMINAL_RED, stdout);
     printf("%s:%d - expected null", file, line);
@@ -113,7 +111,7 @@ bool Test_isNull(CORE_TEST_ARGS, const void* actual) {
     return false;
 }
 
-bool Test_isNotNull(CORE_TEST_ARGS, const void* actual) {
+bool coreTestNotNull(CORE_TEST_ARGS, const void* actual) {
     CORE_TEST_SUCCESS(actual != nullptr);
     fputs(CORE_TERMINAL_RED, stdout);
     printf("%s:%d - expected valid pointer", file, line);

+ 20 - 21
test/Test.h

@@ -1,36 +1,35 @@
 #ifndef CORE_TEST_HPP
 #define CORE_TEST_HPP
 
-void Test_finalize(void);
+void coreFinalizeTests(void);
 
 #define CORE_TEST_ARGS const char *file, int line
-#define CORE_TEST_NAMED_FUNCTION(name, type)                                   \
-    bool Test_compare_##name(CORE_TEST_ARGS, type wanted, type actual)
-#define CORE_TEST_FUNCTION(type) CORE_TEST_NAMED_FUNCTION(type, type)
+#define CORE_TEST_FUNCTION(name, type)                                         \
+    bool coreTest##name(CORE_TEST_ARGS, type wanted, type actual)
 
-CORE_TEST_FUNCTION(int);
-CORE_TEST_NAMED_FUNCTION(bool, bool);
-CORE_TEST_NAMED_FUNCTION(string, const char*);
+CORE_TEST_FUNCTION(Int, int);
+CORE_TEST_FUNCTION(Bool, bool);
+CORE_TEST_FUNCTION(String, const char*);
 
-bool Test_compare_float(CORE_TEST_ARGS, float wanted, float actual,
-                        float error);
+bool coreTestFloat(CORE_TEST_ARGS, float wanted, float actual, float error);
 
-bool Test_isNull(CORE_TEST_ARGS, const void* p);
-bool Test_isNotNull(CORE_TEST_ARGS, const void* p);
+bool coreTestNull(CORE_TEST_ARGS, const void* p);
+bool coreTestNotNull(CORE_TEST_ARGS, const void* p);
 
-#define CORE_TEST(wanted, actual, type)                                        \
-    Test_compare_##type(__FILE__, __LINE__, wanted, actual)
+#define CORE_TEST(wanted, actual, name, type)                                  \
+    coreTest##name(__FILE__, __LINE__, wanted, actual)
 
 #define CORE_TEST_FLOAT(wanted, actual, error)                                 \
-    Test_compare_float(__FILE__, __LINE__, wanted, actual, error)
+    coreTestFloat(__FILE__, __LINE__, wanted, actual, error)
 
-#define CORE_TEST_BOOL(wanted, actual) CORE_TEST(wanted, actual, bool)
-#define CORE_TEST_INT(wanted, actual) CORE_TEST(wanted, actual, int)
-#define CORE_TEST_STRING(wanted, actual) CORE_TEST(wanted, actual, string)
+#define CORE_TEST_BOOL(wanted, actual) CORE_TEST(wanted, actual, Bool, bool)
+#define CORE_TEST_INT(wanted, actual) CORE_TEST(wanted, actual, Int, int)
+#define CORE_TEST_STRING(wanted, actual)                                       \
+    CORE_TEST(wanted, actual, String, string)
 
-#define CORE_TEST_FALSE(actual) CORE_TEST(false, actual, bool)
-#define CORE_TEST_TRUE(actual) CORE_TEST(true, actual, bool)
-#define CORE_TEST_NULL(actual) Test_isNull(__FILE__, __LINE__, actual)
-#define CORE_TEST_NOT_NULL(actual) Test_isNotNull(__FILE__, __LINE__, actual)
+#define CORE_TEST_FALSE(actual) CORE_TEST(false, actual, Bool, bool)
+#define CORE_TEST_TRUE(actual) CORE_TEST(true, actual, Bool, bool)
+#define CORE_TEST_NULL(actual) coreTestNull(__FILE__, __LINE__, actual)
+#define CORE_TEST_NOT_NULL(actual) coreTestNotNull(__FILE__, __LINE__, actual)
 
 #endif

+ 31 - 31
test/Tests.h

@@ -1,36 +1,36 @@
 #ifndef CORE_TESTS_HPP
 #define CORE_TESTS_HPP
 
-void testArrayList(bool light);
-void testArrayString(void);
-void testArray(void);
-void testBitArray(void);
-void testBox(void);
-void testBuffer(bool light);
-void testBufferedValue(void);
-void testClock(bool light);
-void testColor(void);
-void testComponents(void);
-void testError(void);
-void testFileReader(void);
-void testFrustum(void);
-void testHashedString(void);
-void testHashMap(bool light);
-void testLinkedList(bool light);
-void testList(bool light);
-void testMath(void);
-void testMatrixStack(bool light);
-void testMatrix(void);
-void testNew(void);
-void testPlane(void);
-void testQuaternion(void);
-void testRandom(bool light);
-void testRingBuffer(void);
-void testStack(bool light);
-void testThread(void);
-void testUniquePointer(void);
-void testUtility(void);
-void testVector(void);
-void testView(void);
+void coreTestArrayList(bool light);
+void coreTestArrayString(void);
+void coreTestArray(void);
+void coreTestBitArray(void);
+void coreTestBox(void);
+void coreTestBuffer(bool light);
+void coreTestBufferedValue(void);
+void coreTestClock(bool light);
+void coreTestColor(void);
+void coreTestComponents(void);
+void coreTestError(void);
+void coreTestFileReader(void);
+void coreTestFrustum(void);
+void coreTestHashedString(void);
+void coreTestHashMap(bool light);
+void coreTestLinkedList(bool light);
+void coreTestList(bool light);
+void coreTestMath(void);
+void coreTestMatrixStack(bool light);
+void coreTestMatrix(void);
+void coreTestNew(void);
+void coreTestPlane(void);
+void coreTestQuaternion(void);
+void coreTestRandom(bool light);
+void coreTestRingBuffer(void);
+void coreTestStack(bool light);
+void coreTestThread(void);
+void coreTestUniquePointer(void);
+void coreTestUtility(void);
+void coreTestVector(void);
+void coreTestView(void);
 
 #endif