84 lines
2.1 KiB
C
84 lines
2.1 KiB
C
/**
|
|
* Copyright (c) 2026 Dominic Masters
|
|
*
|
|
* This software is released under the MIT License.
|
|
* https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
#include "dusktest.h"
|
|
#include "console/console.h"
|
|
#include "script/scriptmanager.h"
|
|
#include "util/memory.h"
|
|
|
|
static int ui_setup(void **state) {
|
|
consoleInit();
|
|
|
|
errorret_t ret = scriptManagerInit();
|
|
if(errorIsNotOk(ret)) { errorCatch(ret); return -1; }
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int ui_teardown(void **state) {
|
|
errorret_t ret = scriptManagerDispose();
|
|
if(errorIsNotOk(ret)) errorCatch(ret);
|
|
|
|
consoleDispose();
|
|
return 0;
|
|
}
|
|
|
|
static void test_ui_add_logs_prefixed_args(void **state) {
|
|
jerry_value_t result;
|
|
errorret_t ret = scriptManagerExec(
|
|
"UI.add('button', 1, true);", &result
|
|
);
|
|
assert_true(errorIsOk(ret));
|
|
jerry_value_free(result);
|
|
|
|
assert_string_equal(
|
|
CONSOLE.line[CONSOLE_HISTORY_MAX - 1], "UI.add button 1 true"
|
|
);
|
|
|
|
assert_int_equal(memoryGetAllocatedCount(), 0);
|
|
}
|
|
|
|
static void test_ui_remove_logs_prefixed_args(void **state) {
|
|
jerry_value_t result;
|
|
errorret_t ret = scriptManagerExec("UI.remove('button');", &result);
|
|
assert_true(errorIsOk(ret));
|
|
jerry_value_free(result);
|
|
|
|
assert_string_equal(
|
|
CONSOLE.line[CONSOLE_HISTORY_MAX - 1], "UI.remove button"
|
|
);
|
|
|
|
assert_int_equal(memoryGetAllocatedCount(), 0);
|
|
}
|
|
|
|
static void test_ui_add_no_args_logs_just_the_name(void **state) {
|
|
jerry_value_t result;
|
|
errorret_t ret = scriptManagerExec("UI.add();", &result);
|
|
assert_true(errorIsOk(ret));
|
|
jerry_value_free(result);
|
|
|
|
assert_string_equal(CONSOLE.line[CONSOLE_HISTORY_MAX - 1], "UI.add");
|
|
|
|
assert_int_equal(memoryGetAllocatedCount(), 0);
|
|
}
|
|
|
|
int main(void) {
|
|
assertInit();
|
|
const struct CMUnitTest tests[] = {
|
|
cmocka_unit_test_setup_teardown(
|
|
test_ui_add_logs_prefixed_args, ui_setup, ui_teardown
|
|
),
|
|
cmocka_unit_test_setup_teardown(
|
|
test_ui_remove_logs_prefixed_args, ui_setup, ui_teardown
|
|
),
|
|
cmocka_unit_test_setup_teardown(
|
|
test_ui_add_no_args_logs_just_the_name, ui_setup, ui_teardown
|
|
),
|
|
};
|
|
return cmocka_run_group_tests(tests, NULL, NULL);
|
|
}
|