summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/logging/logging_tests.c215
-rw-r--r--src/test/minunit.h2
-rw-r--r--src/test/mock/mock_GLFW.c39
-rw-r--r--src/test/mock/mock_GLFW.h9
-rw-r--r--src/test/mock_queue.test.c (renamed from src/test/mock_queue_tests.c)0
-rw-r--r--src/test/suites.h4
6 files changed, 53 insertions, 216 deletions
diff --git a/src/test/logging/logging_tests.c b/src/test/logging/logging_tests.c
deleted file mode 100644
index e267b5d..0000000
--- a/src/test/logging/logging_tests.c
+++ /dev/null
@@ -1,215 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "test/minunit.h"
-#include "test/suites.h"
-
-#include "logging/logging.h"
-
-
-/* test declarations */
-
-mu_test test_log_get_level();
-mu_test test_log_set_defaults();
-mu_test test_log_debug();
-mu_test test_log_info();
-mu_test test_log_warn();
-mu_test test_log_error();
-mu_test test_log_fatal();
-
-
-/* main suite */
-
-void honey_logging_tests()
-{
- mu_run_test("get log level strings", test_log_get_level);
- mu_run_test("print debug message", test_log_debug);
- mu_run_test("print info message", test_log_info);
- mu_run_test("print warning message", test_log_warn);
- mu_run_test("print error message", test_log_error);
- mu_run_test("print fatal error message", test_log_fatal);
-}
-
-
-/* ~~~~~~~~ test definitions ~~~~~~~~ */
-
-mu_test test_log_get_level()
-{
- honey_log_set_level(DEBUG);
- mu_assert_equal(DEBUG, honey_log_get_level());
- mu_assert_streq("DEBUG", honey_log_level_str());
-
- honey_log_set_level(INFO);
- mu_assert_equal(INFO, honey_log_get_level());
- mu_assert_streq("INFO", honey_log_level_str());
-
- honey_log_set_level(WARN);
- mu_assert_equal(WARN, honey_log_get_level());
- mu_assert_streq("WARN", honey_log_level_str());
-
- honey_log_set_level(ERROR);
- mu_assert_equal(ERROR, honey_log_get_level());
- mu_assert_streq("ERROR", honey_log_level_str());
-
- honey_log_set_level(FATAL);
- mu_assert_equal(FATAL, honey_log_get_level());
- mu_assert_streq("FATAL", honey_log_level_str());
-
- return 0;
-}
-
-
-mu_test test_log_debug()
-{
- FILE *stream;
- char *buffer;
- size_t len;
-
- stream = open_memstream(&buffer, &len);
- mu_assert_unequal(stream, NULL);
-
- honey_log_set_file(stream);
- mu_assert_equal(honey_log_get_file(), stream);
-
- honey_log_set_level(FATAL);
- mu_assert_equal(honey_log_get_level(), FATAL);
-
- honey_debug("hello, %s!", "world");
- fflush(stream);
- mu_assert_streq(buffer, "");
-
- honey_log_set_level(DEBUG);
- mu_assert_equal(honey_log_get_level(), DEBUG);
-
- honey_debug("hello, %s!", "world");
- fclose(stream);
- mu_assert_streq(buffer, "[DEBUG] hello, world!");
- free(buffer);
-
- return 0;
-}
-
-
-mu_test test_log_info()
-{
- FILE *stream;
- char *buffer;
- size_t len;
-
- stream = open_memstream(&buffer, &len);
- mu_assert_unequal(stream, NULL);
-
- honey_log_set_file(stream);
- mu_assert_equal(honey_log_get_file(), stream);
-
- honey_log_set_level(FATAL);
- mu_assert_equal(honey_log_get_level(), FATAL);
-
- honey_info("hello, %s!", "world");
- fflush(stream);
- mu_assert_streq(buffer, "");
-
- honey_log_set_level(INFO);
- mu_assert_equal(honey_log_get_level(), INFO);
-
- honey_info("hello, %s!", "world");
- fclose(stream);
- mu_assert_streq(buffer, "[INFO] hello, world!");
- free(buffer);
-
- return 0;
-}
-
-
-mu_test test_log_warn()
-{
- FILE *stream;
- char *buffer;
- size_t len;
-
- stream = open_memstream(&buffer, &len);
- mu_assert_unequal(stream, NULL);
-
- honey_log_set_file(stream);
- mu_assert_equal(honey_log_get_file(), stream);
-
- honey_log_set_level(FATAL);
- mu_assert_equal(honey_log_get_level(), FATAL);
-
- honey_warn("hello, %s!", "world");
- fflush(stream);
- mu_assert_streq(buffer, "");
-
- honey_log_set_level(WARN);
- mu_assert_equal(honey_log_get_level(), WARN);
-
- honey_warn("hello, %s!", "world");
- fclose(stream);
- mu_assert_streq(buffer, "[WARN] hello, world!");
- free(buffer);
-
- return 0;
-}
-
-
-mu_test test_log_error()
-{
- FILE *stream;
- char *buffer;
- size_t len;
-
- stream = open_memstream(&buffer, &len);
- mu_assert_unequal(stream, NULL);
-
- honey_log_set_file(stream);
- mu_assert_equal(honey_log_get_file(), stream);
-
- honey_log_set_level(FATAL);
- mu_assert_equal(honey_log_get_level(), FATAL);
-
- honey_error("hello, %s!", "world");
- fflush(stream);
- mu_assert_streq(buffer, "");
-
- honey_log_set_level(ERROR);
- mu_assert_equal(honey_log_get_level(), ERROR);
-
- honey_error("hello, %s!", "world");
- fclose(stream);
- mu_assert_streq(buffer, "[ERROR] hello, world!");
- free(buffer);
-
- return 0;
-}
-
-
-mu_test test_log_fatal()
-{
- FILE *stream;
- char *buffer;
- size_t len;
-
- stream = open_memstream(&buffer, &len);
- mu_assert_unequal(stream, NULL);
-
- honey_log_set_file(stream);
- mu_assert_equal(honey_log_get_file(), stream);
-
- honey_log_set_level(-1);
- mu_assert_equal(honey_log_get_level(), -1);
-
- honey_fatal("hello, %s!", "world");
- fflush(stream);
- // all error levels will print fatal messagesf
- mu_assert_streq(buffer, "[FATAL] hello, world!");
-
- honey_log_set_level(FATAL);
- mu_assert_equal(honey_log_get_level(), FATAL);
-
- honey_fatal("hello, %s!", "world");
- fclose(stream);
- mu_assert_streq(buffer, "[FATAL] hello, world![FATAL] hello, world!");
- free(buffer);
-
- return 0;
-}
diff --git a/src/test/minunit.h b/src/test/minunit.h
index ed5e57d..1a418c0 100644
--- a/src/test/minunit.h
+++ b/src/test/minunit.h
@@ -4,6 +4,8 @@
#include <stdio.h>
#include <string.h>
+#define UNIT_TEST
+
#define STR_IMPL(x) #x
#define STR(x) STR_IMPL(x)
diff --git a/src/test/mock/mock_GLFW.c b/src/test/mock/mock_GLFW.c
new file mode 100644
index 0000000..f1942fd
--- /dev/null
+++ b/src/test/mock/mock_GLFW.c
@@ -0,0 +1,39 @@
+#include "minunit.h"
+#include "test/mock_queue.h"
+#include "mock_GLFW.h"
+
+void glfwGetVersion(int *major, int *minor, int *rev)
+{
+ *major = mock_front(int);
+ mock_pop();
+ *minor = mock_front(int);
+ mock_pop();
+ *rev = mock_front(int);
+ mock_pop();
+}
+
+
+int glfwInit()
+{
+ int result = mock_front(int);
+ mock_pop();
+ return result;
+}
+
+
+void glfwTerminate()
+{
+ mock_queue(bool, true);
+}
+
+
+int glfwGetError(const char **description)
+{
+ int error_code = mock_front(int);
+ mock_pop();
+ if (description != NULL) {
+ *description = mock_front(const char *);
+ mock_pop();
+ }
+ return error_code;
+}
diff --git a/src/test/mock/mock_GLFW.h b/src/test/mock/mock_GLFW.h
new file mode 100644
index 0000000..d8689ab
--- /dev/null
+++ b/src/test/mock/mock_GLFW.h
@@ -0,0 +1,9 @@
+#ifndef MOCK_GLFW_H
+#define MOCK_GLFW_H
+
+void glfwGetVersion(int *major, int *minor, int *rev);
+int glfwInit();
+void glfwTerminate();
+int glfwGetError(const char **description);
+
+#endif
diff --git a/src/test/mock_queue_tests.c b/src/test/mock_queue.test.c
index 92d7cdf..92d7cdf 100644
--- a/src/test/mock_queue_tests.c
+++ b/src/test/mock_queue.test.c
diff --git a/src/test/suites.h b/src/test/suites.h
index 893f2b1..85b04d5 100644
--- a/src/test/suites.h
+++ b/src/test/suites.h
@@ -5,9 +5,11 @@
void mock_queue_tests();
void honey_logging_tests();
+void honey_gl_tests();
#define RUN_TESTS \
mu_run_suite(honey_logging_tests); \
- mu_run_suite(mock_queue_tests);
+ mu_run_suite(mock_queue_tests); \
+ mu_run_suite(honey_gl_tests);
#endif