#ifdef LRTS_IMPL
#include "tests/t_args.c"
+#include "tests/t_arena.c"
#endif
int main(int argc, char **argv) {
lrts_getopt(argc, argv, lrts_cfg());
T_TESTCASE("test-argv", t_test_argv);
+ T_TESTCASE("test-arena", t_test_arena);
T_TESTEND("lrts test");
--- /dev/null
+#include "../u_arena.h"
+#include "t_defs.h"
+
+int t_test_arena(void) {
+ struct u_arena a = u_arena_init(1, 2);
+ T_ASSERT(a.err == 0, "Areana failed to allocate");
+ T_ASSERT(a.data, "Areana failed to allocate");
+ T_ASSERT(a.o_max == 2, "Invalid max");
+ T_ASSERT(a.o_size == 1, "Invalid size");
+
+
+ return 0;
+}
#define T_TESTEND(name) { u_fprintf(u_stderr, "=== %s ===\n", name); }
+/* asserta a test if expr is false prints message and returns 1 */
+#define T_ASSERT(expr, message) {\
+ if (!(expr)) { \
+ u_log(U_LOG_CRIT, "\n%s:%d: %s\n", __FILE__, __LINE__, message); \
+ return 1; \
+ } \
+}
+
/**
* Runs a test case
* Test functions should return 0 when they succeed otherwise 1
#include "u_arena.h"
+#include "u_mem.h"
+#include "u_log.h"
+struct u_arena u_arena_init(u32 o_size, u32 o_max) {
+ struct u_arena a;
+ memset(&a, 0, sizeof(a));
+ a.o_size = o_size;
+ a.o_max = o_max;
+
+ a.data = u_malloc(o_size * o_max);
+ if (a.data == LRTS_NULL) {
+ u_log(U_LOG_ERR, "Unable to malloc arena of size %d\n", o_size * o_max);
+ a.err = U_ERRNO_MALLOC_FAIL;
+ }
+
+ return a;
+}
*/
enum u_errno_code {
U_ERRNO_OK = 0,
- U_ERRNO_FAIL
+ U_ERRNO_FAIL,
+ U_ERRNO_MALLOC_FAIL
};
#endif
return 0;
}
va_start(args, fmt);
- res = u_fprintf(u_stderr, fmt, args);
+ res = u_vfprintf(u_stderr, fmt, args);
va_end(args);
return res;
}