rtengine/tests/rttest.c
Kevin Trogant 027ef8a46f Restructure the project
Move asset_compiler into its own (static) library.
This removes the dependency on it from the runtime and makes it possible
to have a standalone asset_compiler tool (useful for modding support).

Split meson.build into sub-files to improve readability.

Give each target its own pch directory.
This is more inline with what the meson manual recommends.

Export dependencies to make it possible to use the engine as a meson
subproject.
This is currently untested.
2024-02-07 13:56:06 +01:00

74 lines
1.7 KiB
C

#include <stdio.h>
#include "runtime/runtime.h"
/* Check basic relative pointer behaviour */
static rt_result RelPtrTest(void) {
char buf[sizeof(rt_relptr) + sizeof(unsigned int)];
rt_relptr *ptr = (rt_relptr *)buf;
unsigned int *target = (unsigned int *)&buf[sizeof(rt_relptr)];
*target = 42;
rtSetRelptr(ptr, target);
void *resolved = rtResolveRelptr(ptr);
if ((uintptr_t)resolved != (uintptr_t)target)
return 1;
if (*(unsigned int *)resolved != *target)
return 2;
return RT_SUCCESS;
}
static rt_result NegRelPtrTest(void) {
char buf[sizeof(unsigned int) + sizeof(rt_relptr)];
unsigned int *target = (unsigned int *)buf;
rt_relptr *ptr = (rt_relptr *)&buf[sizeof(unsigned int)];
*target = 42;
rtSetRelptr(ptr, target);
void *resolved = rtResolveRelptr(ptr);
if ((uintptr_t)resolved != (uintptr_t)target)
return 1;
if (*(unsigned int *)resolved != *target)
return 2;
return RT_SUCCESS;
}
/* Scaffolding
*
* Run all the test cases, output if they passed or failed.
*/
typedef rt_result rt_test_fnc(void);
typedef struct {
const char *name;
rt_test_fnc *fnc;
} rt_test_case;
#define TEST_CASE(fn) { .name = #fn, .fnc = fn, }
static rt_test_case _test_cases[] = {TEST_CASE(RelPtrTest), TEST_CASE(NegRelPtrTest)};
int main() {
int out = 0;
for (size_t i = 0; i < RT_ARRAY_COUNT(_test_cases); ++i) {
printf("[%s] ... ", _test_cases[i].name);
rt_result res = _test_cases[i].fnc();
if (res == RT_SUCCESS) {
printf("OK\n");
}
else {
printf("FAILED (%u)\n", res);
++out;
}
}
return out;
}