engine: Added setup for tests
authorLukas Krickl <lukas@krickl.dev>
Sun, 22 Feb 2026 19:21:06 +0000 (20:21 +0100)
committerLukas Krickl <lukas@krickl.dev>
Sun, 22 Feb 2026 19:21:06 +0000 (20:21 +0100)
Added basic tile def

STYLE.md
src/lrts.c
src/lrts.h
src/p_posix/p_getopt.c [new file with mode: 0644]
src/t_tile.c [new file with mode: 0644]
src/t_tile.h [new file with mode: 0644]
src/test.c
src/tests/t_args.c [new file with mode: 0644]
src/tests/t_defs.h [new file with mode: 0644]
src/u_defs.h

index f2ad25c662ebd24eeff96d8a4196a03e5de9e89f..f9520553366a4d184b5f5f17956bf3ad5f57eeff 100644 (file)
--- a/STYLE.md
+++ b/STYLE.md
@@ -14,6 +14,7 @@ Files and all functions therein are prefixed with one of the following:
 - `s_`: server side code
 - `u_`: system utility code
 - `p_`: platform module directory
+- `t_`: test case
 
 
 ## Library functions
@@ -34,6 +35,12 @@ Currently supported platforms are:
 - p_win: win32 specific code
 - p_r_cli: cli-based renderer
 - p_r_sdl: sdl-based renderer
+- p_tests: platform for running tests
 
 It is possible to enable more than one platform at a time e.g. usually p_pc, p_posix and one renderer are 
 enabled to allow the program to compile.
+
+## Tests
+
+All test cases are included in the tests directory.
+When test are run p_tests is used as a platform.
index 9c49163c799940fe7a66c831ce70e18d2e23c011..eada0d514712eed2f28d56d6d3b23bce861e716e 100644 (file)
@@ -24,34 +24,6 @@ void lrts_version(void) {
        u_fprintf(u_stderr, "%s\n", LRTS_VER);
 }
 
-void lrts_getopt(int argc, char **argv, struct lrts_config *cfg) {
-  int c = 0;
-  while ((c = getopt(argc, argv, LRTS_OPTS LRTS_OPTS_ARG)) != -1) {
-    switch (c) {
-    case 'h':
-      lrts_help(argc, argv);
-      exit(0);
-      break;
-    case 'V':
-      lrts_version();
-      exit(0);
-      break;
-    case 'v':
-      cfg->verbose = 1;
-      break;
-    case '?':
-      break;
-    default:
-      u_fprintf(u_stderr, "%s: invalid option '%c'\nTry '%s -h' for more information.\n",
-             argv[0], c, argv[0]);
-      exit(-1);
-      break;
-    }
-  }
-
-  cfg->argc = argc - optind;
-  cfg->argv = argv + optind;
-}
 
 int lrts_main(int argc, char **argv) {
        p_io_init();
index 704d0a16cedf1c565e8a3cf5f030d0494151cfcf..7fecfc9ac44390b96c6499ce84981250af347e40 100644 (file)
 #include "p_pc/u_mem.c"
 #include "p_pc/u_assert.c"
 #include "p_posix/p_init.c"
+#include "p_posix/p_getopt.c"
 #else
 #error "No platform is provided"
 #endif
 
+#ifdef LRTS_RENDERER_TEST
+#endif
+
+
 #ifdef LRTS_RENDERER_CLI
 #include "p_r_cli/p_init.c"
-#else 
-#error "No renderer is provided"
 #endif
 
 
@@ -40,6 +43,7 @@
 #include "u_rand.c"
 #include "n_conn.c"
 #include "u_math.c"
+#include "t_tile.c"
 
 #endif
 
diff --git a/src/p_posix/p_getopt.c b/src/p_posix/p_getopt.c
new file mode 100644 (file)
index 0000000..b9af175
--- /dev/null
@@ -0,0 +1,29 @@
+
+void lrts_getopt(int argc, char **argv, struct lrts_config *cfg) {
+  int c = 0;
+  while ((c = getopt(argc, argv, LRTS_OPTS LRTS_OPTS_ARG)) != -1) {
+    switch (c) {
+    case 'h':
+      lrts_help(argc, argv);
+      exit(0);
+      break;
+    case 'V':
+      lrts_version();
+      exit(0);
+      break;
+    case 'v':
+      cfg->verbose = 1;
+      break;
+    case '?':
+      break;
+    default:
+      u_fprintf(u_stderr, "%s: invalid option '%c'\nTry '%s -h' for more information.\n",
+             argv[0], c, argv[0]);
+      exit(-1);
+      break;
+    }
+  }
+
+  cfg->argc = argc - optind;
+  cfg->argv = argv + optind;
+}
diff --git a/src/t_tile.c b/src/t_tile.c
new file mode 100644 (file)
index 0000000..acf22e3
--- /dev/null
@@ -0,0 +1 @@
+#include "t_tile.h"
diff --git a/src/t_tile.h b/src/t_tile.h
new file mode 100644 (file)
index 0000000..d5424a6
--- /dev/null
@@ -0,0 +1,23 @@
+#ifndef T_TILE_H__
+#define T_TILE_H__
+
+#include "u_defs.h"
+
+enum t_tile_types {
+       T_TILE_TYPE_NONE = 0
+};
+
+enum t_tile_flags {
+       T_TILE_F_NONE = 0
+};
+
+/* 
+ * A tile is the smallest unit of the map.
+ */
+struct t_tile {
+       u8 type;
+       u8 flags;
+       u8 elevation;
+};
+
+#endif
index 46ee85a73b8c9717841ec966cfa8dfc5786b727c..bc6906de622e47d9b17deaf2d4b700f3d1c1da01 100644 (file)
@@ -1,21 +1,26 @@
 #define LRTS_IMPL
+#define LRTS_RENDERER_TESTS
+
 
 #include <stdio.h>
 #include <assert.h>
 #include "lrts.h"
 #include "p_platform.h"
+#include "tests/t_defs.h"
 
-#define TESTBEGIN(name) { u_fprintf(u_stderr, "%s\n", name); }
-
-#define TESTEND(name) { u_fprintf(u_stderr, "%s\n", name); }
+#ifdef LRTS_IMPL 
+#include "tests/t_args.c"
+#endif
 
 int main(int argc, char **argv) {
        p_io_init();
 
-  TESTBEGIN("lrts test");
+  T_TESTBEGIN("lrts test");
   lrts_getopt(argc, argv, lrts_cfg());
+       
+       T_TESTCASE("test-argv", t_test_argv);
 
-  TESTEND("lrts test");
+  T_TESTEND("lrts test");
 
        p_io_finish();
   return 0;
diff --git a/src/tests/t_args.c b/src/tests/t_args.c
new file mode 100644 (file)
index 0000000..f3df856
--- /dev/null
@@ -0,0 +1,5 @@
+#include "t_defs.h"
+
+int t_test_argv() {
+       return lrts_cfg()->argv == LRTS_NULL;
+}
diff --git a/src/tests/t_defs.h b/src/tests/t_defs.h
new file mode 100644 (file)
index 0000000..7290a49
--- /dev/null
@@ -0,0 +1,23 @@
+#ifndef T_DEFS_H__
+#define T_DEFS_H__
+
+
+#define T_TESTBEGIN(name) { u_fprintf(u_stderr, "=== %s ===\n", name); }
+
+#define T_TESTEND(name) { u_fprintf(u_stderr, "=== %s ===\n", name); }
+
+/**
+ * Runs a test case
+ * Test functions should return 0 when they succeed otherwise 1
+ */
+#define T_TESTCASE(name, fn) { \
+       T_TESTBEGIN(name); \
+       if (fn() == 0) {\
+               u_fprintf(u_stderr, "%s OK\n", name); \
+       } else {\
+               u_fprintf(u_stderr, "%s FAIL\n", name); \
+       }\
+       T_TESTEND(name); \
+}
+
+#endif
index ee3ae8acef826fe9a0b80296cd4b0a22568eb890..b93981fc97cf78bf71234890eb99f2eb51eb8991 100644 (file)
@@ -10,6 +10,8 @@
 /* args without value */
 #define LRTS_OPTS "hvV"
 
+#define LRTS_NULL 0
+
 /* args with value */
 #define LRTS_OPTS_ARG "c:"
 #define LRTS_HELP(a, desc) u_fprintf(u_stderr, "\t-%s\t%s\n", (a), desc);