summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt33
-rw-r--r--src/logging/logging.c33
-rw-r--r--src/logging/logging.h10
-rw-r--r--src/test/logging/logging_tests.c40
-rw-r--r--src/test/minunit.h17
5 files changed, 109 insertions, 24 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2934ec2..10f0b84 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,28 +6,29 @@ set(CMAKE_C_FLAGS "-Wall -Wextra -Werror -Wfatal-errors -Wpedantic")
find_package(OpenGL REQUIRED)
find_package(Lua51 REQUIRED)
-include_directories(${LUA_INCLUDE_DIR})
+include_directories(${LUA_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/src)
set(CMAKE_C_FLAGS "-g")
add_library(glad src/glad/glad.c)
add_library(stb_image src/stb_image/stb_image.c)
+set(SRC_ROOT ${CMAKE_SOURCE_DIR}/src)
set(SOURCE_FILES
- src/main.c
- src/cairo_bindings.c
- src/glm_bindings.c
- src/glm_vec3_bindings.c
- src/glm_vec4_bindings.c
- src/glm_mat3_bindings.c
- src/glm_mat4_bindings.c
- src/honey.c
- src/input.c
- src/honey_lua.c
- src/mesh.c
- src/shader.c
- src/texture.c
- src/window.c)
+ ${SRC_ROOT}/main.c
+ ${SRC_ROOT}/cairo_bindings.c
+ ${SRC_ROOT}/glm_bindings.c
+ ${SRC_ROOT}/glm_vec3_bindings.c
+ ${SRC_ROOT}/glm_vec4_bindings.c
+ ${SRC_ROOT}/glm_mat3_bindings.c
+ ${SRC_ROOT}/glm_mat4_bindings.c
+ ${SRC_ROOT}/honey.c
+ ${SRC_ROOT}/input.c
+ ${SRC_ROOT}/honey_lua.c
+ ${SRC_ROOT}/mesh.c
+ ${SRC_ROOT}/shader.c
+ ${SRC_ROOT}/texture.c
+ ${SRC_ROOT}/window.c)
add_executable(honey ${SOURCE_FILES})
@@ -46,6 +47,8 @@ set(TEST_ROOT ${CMAKE_SOURCE_DIR}/src/test)
set(TEST_SOURCES
${TEST_ROOT}/test_main.c
${TEST_ROOT}/logging/logging_tests.c
+
+ ${SRC_ROOT}/logging/logging.c
)
add_executable(test EXCLUDE_FROM_ALL ${TEST_SOURCES})
set_target_properties(test PROPERTIES
diff --git a/src/logging/logging.c b/src/logging/logging.c
new file mode 100644
index 0000000..429f222
--- /dev/null
+++ b/src/logging/logging.c
@@ -0,0 +1,33 @@
+#include <stdio.h>
+
+#include "logging/logging.h"
+
+
+const char * honey_log_level_str_(struct honey_log_info *info)
+{
+ switch(info->log_level) {
+ case DEBUG:
+ return "DEBUG";
+ break;
+
+ case INFO:
+ return "INFO";
+ break;
+
+ case WARN:
+ return "WARN";
+ break;
+
+ case ERROR:
+ return "ERROR";
+ break;
+
+ case FATAL:
+ return "FATAL";
+ break;
+
+ default:
+ return NULL;
+ break;
+ }
+}
diff --git a/src/logging/logging.h b/src/logging/logging.h
new file mode 100644
index 0000000..87436e5
--- /dev/null
+++ b/src/logging/logging.h
@@ -0,0 +1,10 @@
+#ifndef HONEY_LOGGING_H
+#define HONEY_LOGGING_H
+
+struct honey_log_info {
+ enum { DEBUG, INFO, WARN, ERROR, FATAL } log_level;
+};
+
+const char * honey_log_level_str_(struct honey_log_info *info);
+
+#endif
diff --git a/src/test/logging/logging_tests.c b/src/test/logging/logging_tests.c
index 2e92d68..2a07d30 100644
--- a/src/test/logging/logging_tests.c
+++ b/src/test/logging/logging_tests.c
@@ -1,6 +1,42 @@
-#include "../minunit.h"
-#include "../suites.h"
+#include "test/minunit.h"
+#include "test/suites.h"
+
+#include "logging/logging.h"
+
+
+/* test declarations */
+
+mu_test test_log_get_level();
+
+
+/* main suite */
void honey_logging_tests()
{
+ mu_run_test("get log level strings", test_log_get_level);
+}
+
+
+/* test definitions */
+
+mu_test test_log_get_level()
+{
+ struct honey_log_info info;
+
+ info.log_level = DEBUG;
+ mu_assert_streq("DEBUG", honey_log_level_str_(&info));
+
+ info.log_level = INFO;
+ mu_assert_streq("INFO", honey_log_level_str_(&info));
+
+ info.log_level = WARN;
+ mu_assert_streq("WARN", honey_log_level_str_(&info));
+
+ info.log_level = ERROR;
+ mu_assert_streq("ERROR", honey_log_level_str_(&info));
+
+ info.log_level = FATAL;
+ mu_assert_streq("FATAL", honey_log_level_str_(&info));
+
+ return 0;
}
diff --git a/src/test/minunit.h b/src/test/minunit.h
index b1bfda7..ed5e57d 100644
--- a/src/test/minunit.h
+++ b/src/test/minunit.h
@@ -2,6 +2,7 @@
#define MINUNIT_H
#include <stdio.h>
+#include <string.h>
#define STR_IMPL(x) #x
#define STR(x) STR_IMPL(x)
@@ -9,7 +10,7 @@
#define MU_INDENT " "
/* minunit testing macros from /www.jera.com/techinfo/jtns/jtn002.html */
-#define mu_assert(test, message) do { if (!(test)) return message "\n" MU_INDENT "[" __FILE__ ":" STR(__LINE__) "]"; } while (0)
+#define mu_assert(test, message) do { if (!(test)) return message "\n" MU_INDENT " [" __FILE__ ":" STR(__LINE__) "]"; } while (0)
#define mu_assert_equal(a, b) mu_assert(a == b, "'" #a "' is not equal to '" #b "'")
#define mu_assert_unequal(a, b) mu_assert(a != b, "'" #a "' is equal to '" #b "'")
#define mu_assert_streq(a, b) mu_assert(strcmp(a, b) == 0, "'" #a "' is not equal to '" #b "'")
@@ -22,12 +23,14 @@
tests_failed++; \
} \
} while (0)
-#define mu_run_suite(suite) do { \
- int tests_run_old = tests_run; \
- printf("suite: " #suite "\n"); \
- suite(); \
- printf(MU_INDENT "ran %d tests\n\n", \
- tests_run - tests_run_old); \
+#define mu_run_suite(suite) do { \
+ int run_old = tests_run; \
+ int failed_old = tests_failed; \
+ printf("suite: " #suite "\n"); \
+ suite(); \
+ printf(MU_INDENT "ran %d tests, %d failed\n\n", \
+ tests_run - run_old, \
+ tests_failed - failed_old); \
} while(0)
#define mu_tests_finished() do { \
printf("ran %d tests, %d failed\n", tests_run, tests_failed); \