diff options
Diffstat (limited to 'tests/test_core.c')
| -rw-r--r-- | tests/test_core.c | 88 |
1 files changed, 0 insertions, 88 deletions
diff --git a/tests/test_core.c b/tests/test_core.c deleted file mode 100644 index 42dfd99..0000000 --- a/tests/test_core.c +++ /dev/null @@ -1,88 +0,0 @@ -#include "ecex.h" - -#include <assert.h> -#include <stddef.h> -#include <string.h> - -static void test_plugin_identity(void) { - ecex_t ed; - memset(&ed, 0, sizeof(ed)); - ed.plugins = ecex_plugin_runtime_new(); - assert(ed.plugins); - - ecex_plugin_t *a = ecex_plugin_register(&ed, "alpha", ECEX_PLUGIN_API_VERSION); - assert(a); - assert(ecex_plugin_find(&ed, "alpha") == a); - assert(ecex_plugin_register(&ed, "alpha", ECEX_PLUGIN_API_VERSION) == 0); - assert(ecex_plugin_require(&ed, "alpha", ECEX_PLUGIN_API_VERSION) == a); - assert(ecex_plugin_register(&ed, "Bad ID", ECEX_PLUGIN_API_VERSION) == 0); - assert(ecex_plugin_register(&ed, "beta", ECEX_PLUGIN_API_VERSION + 1) == 0); - - ecex_plugin_runtime_free(ed.plugins); -} - -static void test_plugin_slots_and_exports(void) { - ecex_t ed; - memset(&ed, 0, sizeof(ed)); - ed.plugins = ecex_plugin_runtime_new(); - assert(ed.plugins); - - ecex_plugin_t *owner = ecex_plugin_register(&ed, "owner", ECEX_PLUGIN_API_VERSION); - ecex_plugin_t *reader = ecex_plugin_register(&ed, "reader", ECEX_PLUGIN_API_VERSION); - assert(owner); - assert(reader); - - assert(ecex_plugin_slot_i32_set(owner, "score", 0, 42) == 0); - assert(ecex_plugin_slot_i32_get_scalar(owner, "score", -1) == 42); - assert(ecex_plugin_slot_i32_set_2d(owner, "board", 10, 3, 4, 99) == 0); - assert(ecex_plugin_slot_i32_get_2d(owner, "board", 10, 3, 4, -1) == 99); - assert(ecex_plugin_slot_i32_get_2d(owner, "board", 0, 3, 4, -7) == -7); - - int copied = 0; - size_t copied_len = 0; - assert(ecex_plugin_slot_read_exported(&ed, "owner", "score", &copied, sizeof(copied), &copied_len) != 0); - assert(ecex_plugin_slot_set_export_flags(owner, "score", ECEX_PLUGIN_I32, ECEX_PLUGIN_EXPORT_READ) == 0); - assert(ecex_plugin_slot_read_exported(&ed, "owner", "score", &copied, sizeof(copied), &copied_len) == 0); - assert(copied == 42); - assert(copied_len == sizeof(copied)); - - copied = 7; - assert(ecex_plugin_slot_read_exported(&ed, "owner", "score", &copied, 0, &copied_len) != 0); - assert(copied == 7); - assert(copied_len == sizeof(copied)); - - ecex_plugin_runtime_free(ed.plugins); -} - -static void test_plugin_objects_and_text(void) { - ecex_t ed; - memset(&ed, 0, sizeof(ed)); - ed.plugins = ecex_plugin_runtime_new(); - assert(ed.plugins); - - ecex_plugin_t *plugin = ecex_plugin_register(&ed, "objects", ECEX_PLUGIN_API_VERSION); - assert(plugin); - - unsigned char *object = ecex_plugin_object_calloc(plugin, "state", 1, 16); - assert(object); - assert(ecex_plugin_object_i32_set(plugin, object, 4, 1234) == 0); - assert(ecex_plugin_object_i32_get(plugin, object, 4, -1) == 1234); - assert(ecex_plugin_object_i32_set(plugin, object, 14, 1) != 0); - assert(ecex_plugin_object_valid(plugin, object) == 1); - assert(ecex_plugin_object_free(plugin, object) == 0); - assert(ecex_plugin_object_valid(plugin, object) == 0); - - assert(ecex_plugin_text_set(plugin, 1, "hello", -1) == 0); - assert(strcmp(ecex_plugin_text_get_drawable(&ed, plugin, 1), "hello") == 0); - assert(ecex_plugin_text_free_all(plugin) == 0); - assert(strcmp(ecex_plugin_text_get_drawable(&ed, plugin, 1), "") == 0); - - ecex_plugin_runtime_free(ed.plugins); -} - -int main(void) { - test_plugin_identity(); - test_plugin_slots_and_exports(); - test_plugin_objects_and_text(); - return 0; -} |
