summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2022-06-14 00:05:58 -0500
committersanine <sanine.not@pm.me>2022-06-14 00:05:58 -0500
commit034d5c965ff34cfdf4b153af9f32360a02e35684 (patch)
treefcbe5ca527d76a303c197ea8308c6e488ef7c0b4 /src/test
parent8fb7916a0d0cb007a4c3a4e6a31af58765268ca3 (diff)
scorched earth, start over
Diffstat (limited to 'src/test')
-rw-r--r--src/test/minunit.h46
-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.c83
-rw-r--r--src/test/mock_queue.h23
-rw-r--r--src/test/mock_queue.test.c127
-rw-r--r--src/test/suites.h15
-rw-r--r--src/test/test_main.c18
8 files changed, 0 insertions, 360 deletions
diff --git a/src/test/minunit.h b/src/test/minunit.h
deleted file mode 100644
index 1a418c0..0000000
--- a/src/test/minunit.h
+++ /dev/null
@@ -1,46 +0,0 @@
-#ifndef MINUNIT_H
-#define MINUNIT_H
-
-#include <stdio.h>
-#include <string.h>
-
-#define UNIT_TEST
-
-#define STR_IMPL(x) #x
-#define STR(x) STR_IMPL(x)
-
-#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_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 "'")
-
-#define mu_run_test(name, test) do { \
- const char *message = test(); \
- tests_run++; \
- if (message) { \
- printf(MU_INDENT "test '%s' failed: %s\n", name, message); \
- tests_failed++; \
- } \
- } while (0)
-#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); \
- return tests_failed; \
- } while(0)
-
-#define mu_test const char *
-
-extern int tests_run, tests_failed;
-
-#endif
diff --git a/src/test/mock/mock_GLFW.c b/src/test/mock/mock_GLFW.c
deleted file mode 100644
index f1942fd..0000000
--- a/src/test/mock/mock_GLFW.c
+++ /dev/null
@@ -1,39 +0,0 @@
-#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
deleted file mode 100644
index d8689ab..0000000
--- a/src/test/mock/mock_GLFW.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#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.c b/src/test/mock_queue.c
deleted file mode 100644
index 7a36b65..0000000
--- a/src/test/mock_queue.c
+++ /dev/null
@@ -1,83 +0,0 @@
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "mock_queue.h"
-
-struct mock_queue_node_t;
-
-struct mock_queue_node_t {
- struct mock_queue_node_t *next;
- void *data;
-};
-
-static struct mock_queue_node_t mock_queue_head;
-static struct mock_queue_node_t *mock_queue_tail;
-size_t mock_queue_length;
-
-void mock_queue_init()
-{
- mock_queue_length = 0;
- mock_queue_head.next = NULL;
- mock_queue_tail = &mock_queue_head;
-}
-
-
-size_t mock_queue_len() {
- return mock_queue_length;
-}
-
-
-void mock_queue_data(size_t size, void *data)
-{
- struct mock_queue_node_t *node = malloc(sizeof(struct mock_queue_node_t));
- if (node == NULL) {
- fprintf(stderr, "WARNING: memory allocation for mock queue node failed!\n");
- return;
- }
-
- node->data = malloc(size);
- if (node->data == NULL) {
- fprintf(stderr, "WARNING: memory allocation of %zu bytes for mock queue data failed!\n", size);
- return;
- }
-
- memcpy(node->data, data, size);
- node->next = NULL;
- mock_queue_tail->next = node;
- mock_queue_tail = node;
-
- mock_queue_length += 1;
-}
-
-
-void * mock_front_data()
-{
- if (mock_queue_head.next == NULL)
- return NULL;
- return mock_queue_head.next->data;
-}
-
-
-void mock_pop()
-{
- if (mock_queue_head.next == NULL)
- return;
-
- if (mock_queue_head.next->data != NULL)
- free(mock_queue_head.next->data);
- struct mock_queue_node_t *headnext = mock_queue_head.next->next;
- free(mock_queue_head.next);
- mock_queue_head.next = headnext;
- if (headnext == NULL)
- // no more nodes, bring tail back to head
- mock_queue_tail = &mock_queue_head;
- mock_queue_length -= 1;
-}
-
-
-void mock_queue_cleanup()
-{
- while(mock_queue_length != 0)
- mock_pop();
-}
diff --git a/src/test/mock_queue.h b/src/test/mock_queue.h
deleted file mode 100644
index 1c2bbf7..0000000
--- a/src/test/mock_queue.h
+++ /dev/null
@@ -1,23 +0,0 @@
-#ifndef MOCK_QUEUE_H
-#define MOCK_QUEUE_H
-
-#include <stdlib.h>
-
-void mock_queue_init();
-void mock_queue_cleanup();
-
-size_t mock_queue_len();
-
-void mock_queue_data(size_t size, void *data);
-void * mock_front_data();
-
-#define mock_queue(type, raw) do { \
- type data = raw; \
- mock_queue_data(sizeof(type), &data); \
- } while(0)
-
-#define mock_front(type) * (type *) mock_front_data()
-
-void mock_pop();
-
-#endif
diff --git a/src/test/mock_queue.test.c b/src/test/mock_queue.test.c
deleted file mode 100644
index 92d7cdf..0000000
--- a/src/test/mock_queue.test.c
+++ /dev/null
@@ -1,127 +0,0 @@
-#include "test/minunit.h"
-#include "test/mock_queue.h"
-
-#include <stdbool.h>
-
-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
deleted file mode 100644
index 85b04d5..0000000
--- a/src/test/suites.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#ifndef HONEY_TESTS_SUITES
-#define HONEY_TESTS_SUITES
-
-#include "minunit.h"
-
-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(honey_gl_tests);
-
-#endif
diff --git a/src/test/test_main.c b/src/test/test_main.c
deleted file mode 100644
index a3763be..0000000
--- a/src/test/test_main.c
+++ /dev/null
@@ -1,18 +0,0 @@
-#include "minunit.h"
-#include "suites.h"
-#include "mock_queue.h"
-
-int tests_run = 0;
-int tests_failed = 0;
-
-int main()
-{
- mock_queue_init();
- printf("~~~~~~~~ running tests ~~~~~~~~\n\n");
- RUN_TESTS;
- printf("~~~~~~~~~ tests done ~~~~~~~~~~\n\n");
-
- mu_tests_finished();
-
- mock_queue_cleanup();
-}