Mercurial > thymian
comparison 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 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:a4671277546c |
|---|---|
| 1 #ifndef TESTS_H | |
| 2 #define TESTS_H | |
| 3 | |
| 4 #define UNUSED(x) (void)x; | |
| 5 | |
| 6 #include "nap_runtime.h" | |
| 7 #include "utils.h" | |
| 8 | |
| 9 /* | |
| 10 * Macros for making the life of the test writer easier | |
| 11 */ | |
| 12 | |
| 13 #define SCRIPT_START \ | |
| 14 nap_runtime* runtime = nap_runtime_create(0); \ | |
| 15 ASSERT_FALSE(runtime == NULL); \ | |
| 16 int found_indicator = 0; \ | |
| 17 nap_bytecode_chunk* bytecode = nap_runtime_compile(runtime, | |
| 18 | |
| 19 #define SCRIPT_END \ | |
| 20 ,0); \ | |
| 21 ASSERT_FALSE(bytecode == NULL); \ | |
| 22 int t = nap_runtime_execute(runtime, bytecode); \ | |
| 23 ASSERT_EQ(1, t); | |
| 24 | |
| 25 #define VAR_INT(a) nap_runtime_get_int(runtime, #a, &found_indicator) | |
| 26 | |
| 27 #define VAR_REAL(a) nap_runtime_get_real(runtime, #a, &found_indicator) | |
| 28 | |
| 29 #define VAR_BYTE(a) nap_runtime_get_byte(runtime, #a, &found_indicator) | |
| 30 | |
| 31 #define VAR_STRING(a) nap_runtime_get_string(runtime, #a, &found_indicator) | |
| 32 | |
| 33 #define SCRIPT_SHUTDOWN \ | |
| 34 nap_runtime_shutdown(&runtime); \ | |
| 35 ASSERT_TRUE(runtime == NULL); | |
| 36 | |
| 37 | |
| 38 #ifdef _WINDOWS | |
| 39 #pragma warning(disable: 4127) | |
| 40 #endif | |
| 41 | |
| 42 #define SCRIPT_ASSERT_STREQ(with,what) \ | |
| 43 do { \ | |
| 44 char* what = VAR_STRING(what); \ | |
| 45 ASSERT_STREQ(with, what); \ | |
| 46 free(what); \ | |
| 47 } while(0); | |
| 48 | |
| 49 #endif // TESTS_H |
