Files
oak-editor/engine/tests/oakengine_config_test.cpp
T
Mike-Solar e9f173916f engine: complete C ABI facade (liboakengine oakengine_* surface)
The full pure-C facade used by the app: node/project/timeline/viewer/
undo/task/events/serializer/playback/preview/renderer/gizmo/color/
audio/footage/proxy/encoding/exporter/config/disk/ipc/plugin/worker
families, plus undo-group semantics, display renderer handles,
NodeFactory accessors, and per-family pure-C engine tests.
2026-07-26 22:43:00 +08:00

119 lines
3.6 KiB
C++

/***
Oak - Non-Linear Video Editor
Copyright (C) 2026 Oak Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
// Pure C ABI tests for the liboakengine configuration facade
// (oakengine/config.h). Runs headless; no GPU required.
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include "oakengine/config.h"
#include "oakengine/init.h"
static int g_error_calls = 0;
static char g_last_title[256];
static char g_last_message[256];
static void error_cb(const char *title, const char *message, void *userdata)
{
(void) userdata;
g_error_calls++;
strncpy(g_last_title, title, sizeof(g_last_title) - 1);
g_last_title[sizeof(g_last_title) - 1] = '\0';
strncpy(g_last_message, message, sizeof(g_last_message) - 1);
g_last_message[sizeof(g_last_message) - 1] = '\0';
}
static void test_string_round_trip(void)
{
char buf[256];
// Missing key returns 0 (empty string).
assert(oakengine_config_get_string("oak_test_string_key", buf,
sizeof(buf)) == 0);
assert(oakengine_config_set_string("oak_test_string_key",
"hello world") == OAKENGINE_OK);
int len = oakengine_config_get_string("oak_test_string_key", buf,
sizeof(buf));
assert(len == int(strlen("hello world")));
assert(strcmp(buf, "hello world") == 0);
// Query length with NULL buffer.
assert(oakengine_config_get_string("oak_test_string_key", NULL, 0) == len);
// NULL key is rejected.
assert(oakengine_config_get_string(NULL, buf, sizeof(buf)) ==
OAKENGINE_E_INVALID);
assert(oakengine_config_set_string(NULL, "x") == OAKENGINE_E_INVALID);
}
static void test_int_round_trip(void)
{
assert(oakengine_config_get_int("oak_test_int_key", 42) == 42);
assert(oakengine_config_set_int("oak_test_int_key", 12345) ==
OAKENGINE_OK);
assert(oakengine_config_get_int("oak_test_int_key", 0) == 12345);
assert(oakengine_config_set_int("oak_test_int_key", -7) ==
OAKENGINE_OK);
assert(oakengine_config_get_int("oak_test_int_key", 0) == -7);
// NULL key returns default.
assert(oakengine_config_get_int(NULL, 99) == 99);
assert(oakengine_config_set_int(NULL, 1) == OAKENGINE_E_INVALID);
}
static void test_error_handler(void)
{
g_error_calls = 0;
assert(oakengine_config_set_error_handler(error_cb, NULL) ==
OAKENGINE_OK);
assert(oakengine_config_report_error("Test Title",
"Test Message") == OAKENGINE_OK);
assert(g_error_calls == 1);
assert(strcmp(g_last_title, "Test Title") == 0);
assert(strcmp(g_last_message, "Test Message") == 0);
// Clearing the handler does not crash.
assert(oakengine_config_set_error_handler(NULL, NULL) == OAKENGINE_OK);
assert(oakengine_config_report_error("Ignored", "Ignored") ==
OAKENGINE_OK);
assert(g_error_calls == 1);
}
int main(void)
{
assert(oakengine_init(OAKENGINE_INIT_HEADLESS) == OAKENGINE_OK);
test_string_round_trip();
test_int_round_trip();
test_error_handler();
assert(oakengine_config_save() == OAKENGINE_OK);
assert(oakengine_config_load() == OAKENGINE_OK);
assert(oakengine_shutdown() == OAKENGINE_OK);
return 0;
}