annotate tests/tests.h @ 0:a4671277546c tip

created the repository for the thymian project
author ferencd
date Tue, 17 Aug 2021 11:19:54 +0200
parents
children
rev   line source
ferencd@0 1 #ifndef TESTS_H
ferencd@0 2 #define TESTS_H
ferencd@0 3
ferencd@0 4 #define UNUSED(x) (void)x;
ferencd@0 5
ferencd@0 6 #include "nap_runtime.h"
ferencd@0 7 #include "utils.h"
ferencd@0 8
ferencd@0 9 /*
ferencd@0 10 * Macros for making the life of the test writer easier
ferencd@0 11 */
ferencd@0 12
ferencd@0 13 #define SCRIPT_START \
ferencd@0 14 nap_runtime* runtime = nap_runtime_create(0); \
ferencd@0 15 ASSERT_FALSE(runtime == NULL); \
ferencd@0 16 int found_indicator = 0; \
ferencd@0 17 nap_bytecode_chunk* bytecode = nap_runtime_compile(runtime,
ferencd@0 18
ferencd@0 19 #define SCRIPT_END \
ferencd@0 20 ,0); \
ferencd@0 21 ASSERT_FALSE(bytecode == NULL); \
ferencd@0 22 int t = nap_runtime_execute(runtime, bytecode); \
ferencd@0 23 ASSERT_EQ(1, t);
ferencd@0 24
ferencd@0 25 #define VAR_INT(a) nap_runtime_get_int(runtime, #a, &found_indicator)
ferencd@0 26
ferencd@0 27 #define VAR_REAL(a) nap_runtime_get_real(runtime, #a, &found_indicator)
ferencd@0 28
ferencd@0 29 #define VAR_BYTE(a) nap_runtime_get_byte(runtime, #a, &found_indicator)
ferencd@0 30
ferencd@0 31 #define VAR_STRING(a) nap_runtime_get_string(runtime, #a, &found_indicator)
ferencd@0 32
ferencd@0 33 #define SCRIPT_SHUTDOWN \
ferencd@0 34 nap_runtime_shutdown(&runtime); \
ferencd@0 35 ASSERT_TRUE(runtime == NULL);
ferencd@0 36
ferencd@0 37
ferencd@0 38 #ifdef _WINDOWS
ferencd@0 39 #pragma warning(disable: 4127)
ferencd@0 40 #endif
ferencd@0 41
ferencd@0 42 #define SCRIPT_ASSERT_STREQ(with,what) \
ferencd@0 43 do { \
ferencd@0 44 char* what = VAR_STRING(what); \
ferencd@0 45 ASSERT_STREQ(with, what); \
ferencd@0 46 free(what); \
ferencd@0 47 } while(0);
ferencd@0 48
ferencd@0 49 #endif // TESTS_H