diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..566eace --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +.PHONY: all +all: + ./rscons + +.PHONY: test +test: all + ./build/e.1/tests diff --git a/Rsconscript b/Rsconscript new file mode 100644 index 0000000..196401e --- /dev/null +++ b/Rsconscript @@ -0,0 +1,7 @@ +build do + Environment.new do |env| + sources = glob("src/**/*.c") + env["CPPPATH"] += glob("src/**") + env.Program("^/tests", sources + glob("test/**/*.c")) + end +end diff --git a/test/test_jairee.c b/test/test_jairee.c new file mode 100644 index 0000000..9c4e0aa --- /dev/null +++ b/test/test_jairee.c @@ -0,0 +1,42 @@ +#include "jairee.h" +#include + +#define TEST(x) Test(#x, x, __FILE__, __LINE__) + +static int n_tests_passed; +static int n_tests_failed; + +static void Test(const char * message, int result, const char * file, int line) +{ + if (result) + { + n_tests_passed++; + } + else + { + fprintf(stderr, "Test failure at %s:%d: \"%s\"\n", file, line, message); + n_tests_failed++; + } +} + +static void test_asciiz_string() +{ + jairee_string_t * s = jairee_string_from_asciiz("Test String"); + size_t offset = 0; + TEST(s->len == 11u); + TEST(s->decode(s->str, &offset) == 'T'); + TEST(offset == 1u); + offset = 10u; + TEST(s->decode(s->str, &offset) == 'g'); + TEST(offset == 11u); + jairee_string_free(s); +} + +int main(int argc, char * argv[]) +{ + test_asciiz_string(); + + printf("%d/%d tests passed\n", n_tests_passed, n_tests_passed + n_tests_failed); + + return n_tests_failed == 0 ? 0 : 1; +}