#include "naut/event.h" #include "naut/plugin.h" #include "naut/rpc.h" #include "test.h" #include #ifndef NAUT_EXAMPLE_PLUGIN #define NAUT_EXAMPLE_PLUGIN "naut_example.so" #endif int main(void) { naut_event_bus *events = naut_event_bus_create(); naut_rpc_registry *rpc = naut_rpc_registry_create(); naut_plugin_manager *plugins = naut_plugin_manager_create(rpc, events); CHECK(events && rpc && plugins); CHECK(naut_plugin_load(plugins, NAUT_EXAMPLE_PLUGIN) == NAUT_OK); CHECK_EQ(naut_plugin_count(plugins), 1); CHECK(strcmp(naut_plugin_name(plugins, 0), "example") == 0); CHECK_EQ(naut_plugin_storage_count(plugins), 1); const naut_storage_backend_v1 *backend = naut_plugin_storage_backend(plugins, "memory"); CHECK(backend != NULL); naut_err error; void *storage = backend->open("", &error); CHECK(storage && error == NAUT_OK); const char value[] = "plugin-storage"; char result[sizeof value]; CHECK(backend->write(storage, 17, value, sizeof value) == NAUT_OK); CHECK(backend->read(storage, 17, result, sizeof result) == NAUT_OK); CHECK(memcmp(value, result, sizeof value) == 0); backend->close(storage); naut_event event = { .type = NAUT_EVENT_TORRENT_FINISHED, .torrent_id = 9, }; naut_event_emit(events, &event); json_t *reply = naut_rpc_dispatch( rpc, "example.events", json_null(), &error); CHECK(error == NAUT_OK && reply); CHECK(json_integer_value(json_object_get(reply, "finished")) == 1); json_decref(reply); naut_plugin_manager_destroy(plugins); reply = naut_rpc_dispatch(rpc, "example.events", json_null(), &error); CHECK(reply == NULL && error == NAUT_ERR_INVAL); naut_rpc_registry_destroy(rpc); naut_event_bus_destroy(events); TEST_MAIN_END(); }