From 9c238237597de90c73cc65c3fccf2f49bfaa46b4 Mon Sep 17 00:00:00 2001 From: sanine Date: Thu, 21 Oct 2021 21:33:06 -0500 Subject: move test files to the same directories as the files they test --- src/test/logging/logging_tests.c | 215 --------------------------------------- src/test/minunit.h | 2 + src/test/mock/mock_GLFW.c | 39 +++++++ src/test/mock/mock_GLFW.h | 9 ++ src/test/mock_queue.test.c | 127 +++++++++++++++++++++++ src/test/mock_queue_tests.c | 127 ----------------------- src/test/suites.h | 4 +- 7 files changed, 180 insertions(+), 343 deletions(-) delete mode 100644 src/test/logging/logging_tests.c create mode 100644 src/test/mock/mock_GLFW.c create mode 100644 src/test/mock/mock_GLFW.h create mode 100644 src/test/mock_queue.test.c delete mode 100644 src/test/mock_queue_tests.c (limited to 'src/test') 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 -#include - -#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 #include +#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.test.c b/src/test/mock_queue.test.c new file mode 100644 index 0000000..92d7cdf --- /dev/null +++ b/src/test/mock_queue.test.c @@ -0,0 +1,127 @@ +#include "test/minunit.h" +#include "test/mock_queue.h" + +#include + +mu_test mock_queue_int(); +mu_test mock_queue_int_seq(); +mu_test mock_queue_pop_multi(); +mu_test mock_queue_clean_finish(); +mu_test mock_queue_push_multidata(); + + +void mock_queue_tests() +{ + mu_run_test("push and pop integer to mock queue", mock_queue_int); + mu_run_test("push and pop integer sequence", mock_queue_int_seq); + mu_run_test("pop multiple times with empty queue", mock_queue_pop_multi); + mu_run_test("clean up mock queue", mock_queue_clean_finish); + mu_run_test("push and pop multiple data types", mock_queue_push_multidata); +} + + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +mu_test mock_queue_int() +{ + mock_queue(int, 5); + mu_assert_unequal(mock_queue_len(), 0); + mu_assert_equal(mock_front(int), 5); + + mock_pop(); + + mu_assert_equal(mock_queue_len(), 0); + + return 0; +} + + +mu_test mock_queue_int_seq() +{ + mock_queue(int, 2); + mock_queue(int, 1); + mock_queue(int, 3); + mock_queue(int, 4); + + mu_assert_unequal(mock_queue_len(), 0); + mu_assert_equal(mock_queue_len(), 4); + mu_assert_equal(mock_front(int), 2); + + mock_pop(); + + mu_assert_unequal(mock_queue_len(), 0); + mu_assert_equal(mock_queue_len(), 3); + mu_assert_equal(mock_front(int), 1); + + mock_pop(); + + mu_assert_unequal(mock_queue_len(), 0); + mu_assert_equal(mock_queue_len(), 2); + mu_assert_equal(mock_front(int), 3); + + mock_pop(); + + mu_assert_unequal(mock_queue_len(), 0); + mu_assert_equal(mock_queue_len(), 1); + mu_assert_equal(mock_front(int), 4); + + mock_pop(); + + mu_assert_equal(mock_queue_len(), 0); + + return 0; +} + + +mu_test mock_queue_pop_multi() +{ + mu_assert_equal(mock_queue_len(), 0); + + mock_pop(); + mock_pop(); + mock_pop(); + + mu_assert_equal(mock_queue_len(), 0); + return 0; +} + + +mu_test mock_queue_clean_finish() +{ + mu_assert_equal(mock_queue_len(), 0); + + mock_queue(int, 5); + mock_queue(int, 5); + mock_queue(int, 5); + + mu_assert_equal(mock_queue_len(), 3); + + mock_queue_cleanup(); + + mu_assert_equal(mock_queue_len(), 0); + + return 0; +} + + +mu_test mock_queue_push_multidata() +{ + mock_queue_cleanup(); + mu_assert_equal(mock_queue_len(), 0); + + mock_queue(const char *, "hello, world!"); + mock_queue(bool, true); + mock_queue(float, 4.20f); + + mu_assert_equal(mock_queue_len(), 3); + + mu_assert_streq(mock_front(const char *), "hello, world!"); + mock_pop(); + mu_assert_equal(mock_front(bool), true); + mock_pop(); + mu_assert_equal(mock_front(float), 4.20f); + mock_pop(); + + mu_assert_equal(mock_queue_len(), 0); + return 0; +} diff --git a/src/test/mock_queue_tests.c b/src/test/mock_queue_tests.c deleted file mode 100644 index 92d7cdf..0000000 --- a/src/test/mock_queue_tests.c +++ /dev/null @@ -1,127 +0,0 @@ -#include "test/minunit.h" -#include "test/mock_queue.h" - -#include - -mu_test mock_queue_int(); -mu_test mock_queue_int_seq(); -mu_test mock_queue_pop_multi(); -mu_test mock_queue_clean_finish(); -mu_test mock_queue_push_multidata(); - - -void mock_queue_tests() -{ - mu_run_test("push and pop integer to mock queue", mock_queue_int); - mu_run_test("push and pop integer sequence", mock_queue_int_seq); - mu_run_test("pop multiple times with empty queue", mock_queue_pop_multi); - mu_run_test("clean up mock queue", mock_queue_clean_finish); - mu_run_test("push and pop multiple data types", mock_queue_push_multidata); -} - - -/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ - -mu_test mock_queue_int() -{ - mock_queue(int, 5); - mu_assert_unequal(mock_queue_len(), 0); - mu_assert_equal(mock_front(int), 5); - - mock_pop(); - - mu_assert_equal(mock_queue_len(), 0); - - return 0; -} - - -mu_test mock_queue_int_seq() -{ - mock_queue(int, 2); - mock_queue(int, 1); - mock_queue(int, 3); - mock_queue(int, 4); - - mu_assert_unequal(mock_queue_len(), 0); - mu_assert_equal(mock_queue_len(), 4); - mu_assert_equal(mock_front(int), 2); - - mock_pop(); - - mu_assert_unequal(mock_queue_len(), 0); - mu_assert_equal(mock_queue_len(), 3); - mu_assert_equal(mock_front(int), 1); - - mock_pop(); - - mu_assert_unequal(mock_queue_len(), 0); - mu_assert_equal(mock_queue_len(), 2); - mu_assert_equal(mock_front(int), 3); - - mock_pop(); - - mu_assert_unequal(mock_queue_len(), 0); - mu_assert_equal(mock_queue_len(), 1); - mu_assert_equal(mock_front(int), 4); - - mock_pop(); - - mu_assert_equal(mock_queue_len(), 0); - - return 0; -} - - -mu_test mock_queue_pop_multi() -{ - mu_assert_equal(mock_queue_len(), 0); - - mock_pop(); - mock_pop(); - mock_pop(); - - mu_assert_equal(mock_queue_len(), 0); - return 0; -} - - -mu_test mock_queue_clean_finish() -{ - mu_assert_equal(mock_queue_len(), 0); - - mock_queue(int, 5); - mock_queue(int, 5); - mock_queue(int, 5); - - mu_assert_equal(mock_queue_len(), 3); - - mock_queue_cleanup(); - - mu_assert_equal(mock_queue_len(), 0); - - return 0; -} - - -mu_test mock_queue_push_multidata() -{ - mock_queue_cleanup(); - mu_assert_equal(mock_queue_len(), 0); - - mock_queue(const char *, "hello, world!"); - mock_queue(bool, true); - mock_queue(float, 4.20f); - - mu_assert_equal(mock_queue_len(), 3); - - mu_assert_streq(mock_front(const char *), "hello, world!"); - mock_pop(); - mu_assert_equal(mock_front(bool), true); - mock_pop(); - mu_assert_equal(mock_front(float), 4.20f); - mock_pop(); - - mu_assert_equal(mock_queue_len(), 0); - return 0; -} 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 -- cgit v1.2.1