/** * Copyright (c) 2026 Dominic Masters * * This software is released under the MIT License. * https://opensource.org/licenses/MIT */ #include "dusktest.h" #include "script/scriptmanager.h" #include "locale/localemanager.h" static int locale_setup(void **state) { errorret_t ret = scriptManagerInit(); if(errorIsNotOk(ret)) { errorCatch(ret); return -1; } return 0; } static int locale_teardown(void **state) { errorret_t ret = scriptManagerDispose(); if(errorIsNotOk(ret)) errorCatch(ret); return 0; } // Only the binding shape is covered here -- localeManagerInit() was never // called (LOCALE.locale stays NULL, as a fresh process leaves it), and an // actual successful Locale.set() requires the real asset pipeline (a // mounted locale/*.po file) which the main Dusk binary's headless run // exercises instead; a plain module test isn't the place to stand up the // full asset system just for this. static void test_locale_current_defaults_to_empty_string(void **state) { jerry_value_t result; errorret_t ret = scriptManagerExec("Locale.current;", &result); assert_true(errorIsOk(ret)); char_t buf[8]; jerry_string_to_buffer( result, JERRY_ENCODING_UTF8, (jerry_char_t *)buf, sizeof(buf) - 1 ); jerry_value_free(result); } static void test_locale_set_unknown_name_throws(void **state) { errorret_t ret = scriptManagerExec("Locale.set('xx-XX');", NULL); assert_true(errorIsNotOk(ret)); errorCatch(ret); } static void test_locale_set_requires_a_string(void **state) { errorret_t ret = scriptManagerExec("Locale.set(42);", NULL); assert_true(errorIsNotOk(ret)); errorCatch(ret); } int main(void) { assertInit(); const struct CMUnitTest tests[] = { cmocka_unit_test_setup_teardown( test_locale_current_defaults_to_empty_string, locale_setup, locale_teardown ), cmocka_unit_test_setup_teardown( test_locale_set_unknown_name_throws, locale_setup, locale_teardown ), cmocka_unit_test_setup_teardown( test_locale_set_requires_a_string, locale_setup, locale_teardown ), }; return cmocka_run_group_tests(tests, NULL, NULL); }