- `s_`: server side code
- `u_`: system utility code
- `p_`: platform module directory
+- `t_`: test case
## Library functions
- 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.
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();
#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
#include "u_rand.c"
#include "n_conn.c"
#include "u_math.c"
+#include "t_tile.c"
#endif
--- /dev/null
+
+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;
+}
--- /dev/null
+#include "t_tile.h"
--- /dev/null
+#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
#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;
--- /dev/null
+#include "t_defs.h"
+
+int t_test_argv() {
+ return lrts_cfg()->argv == LRTS_NULL;
+}
--- /dev/null
+#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
/* 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);