diff --git a/common/include/test_assert.h b/common/include/test_assert.h index 75c586bcc67..9669c16a022 100644 --- a/common/include/test_assert.h +++ b/common/include/test_assert.h @@ -12,10 +12,10 @@ #include #include "test_color.h" -#ifdef _assert_failed -#undef _assert_failed +#ifdef _test_assert_failed +#undef _test_assert_failed #endif -#define _assert_failed(result, exprText) { \ +#define _test_assert_failed(result, exprText) { \ std::wcerr << console_color::fg(console_color::BRIGHT_RED) \ << "Test failed with " << (result) \ << " at " << __FILE__ << ":" << __LINE__ << ":" \ @@ -31,23 +31,23 @@ #define try_status(expr) { \ auto __s = (expr); \ if (__s != KM_CORE_STATUS_OK) { \ - _assert_failed(__s, u ## #expr); \ + _test_assert_failed(__s, u ## #expr); \ } \ } -#ifdef assert -#undef assert +#ifdef test_assert +#undef test_assert #endif -#define assert(expr) { \ +#define test_assert(expr) { \ if (!(expr)) { \ - _assert_failed(0, u ## #expr); \ + _test_assert_failed(0, u ## #expr); \ } \ } -#ifdef assert_equal -#undef assert_equal +#ifdef test_assert_equal +#undef test_assert_equal #endif -#define assert_equal(actual, expected) { \ +#define test_assert_equal(actual, expected) { \ if ((actual) != (expected)) { \ std::wcerr << console_color::fg(console_color::BRIGHT_RED) \ << "Test failed at " << __FILE__ << ":" << __LINE__ << ":" \ @@ -59,10 +59,10 @@ } \ } -#ifdef assert_string_equal -#undef assert_string_equal +#ifdef test_assert_string_equal +#undef test_assert_string_equal #endif -#define assert_string_equal(actual, expected) { \ +#define test_assert_string_equal(actual, expected) { \ if (u16cmp((actual), (expected)) != 0) { \ std::wcerr << console_color::fg(console_color::BRIGHT_RED) \ << "Test failed at " << __FILE__ << ":" << __LINE__ << ":" \ diff --git a/common/include/test_color.h b/common/include/test_color.h index f06f94c562f..71267dc3a94 100644 --- a/common/include/test_color.h +++ b/common/include/test_color.h @@ -8,6 +8,12 @@ #include +#ifdef _MSC_VER +#include +#else +#include +#endif + namespace console_color { enum ansi_code { @@ -65,12 +71,10 @@ __define_ansi_code__(reversed, "7"); #undef __define_ansi_code__ #ifdef _MSC_VER -#include inline bool isaterminal() { return _isatty(_fileno(stdout)); } #else -#include inline bool isaterminal() { return isatty(STDOUT_FILENO); } diff --git a/common/windows/delphi/general/KeymanPaths.pas b/common/windows/delphi/general/KeymanPaths.pas index bc534b9f526..fbfa9961d70 100644 --- a/common/windows/delphi/general/KeymanPaths.pas +++ b/common/windows/delphi/general/KeymanPaths.pas @@ -436,12 +436,18 @@ class function TKeymanPaths.RunningFromSource(var keyman_root: string): Boolean; class function TKeymanPaths.KeymanCoreLibraryPath(const Filename: string): string; var keyman_root: string; + configuration: string; begin // Look up KEYMAN_ROOT development variable -- if found and executable // within that path then use that as source path if TKeymanPaths.RunningFromSource(keyman_root) then begin - Exit(keyman_root + 'core\build\x86\debug\src\' + Filename); +{$IFDEF DEBUG} + configuration := 'debug'; +{$ELSE} + configuration := 'release'; +{$ENDIF} + Exit(keyman_root + 'core\build\x86\'+configuration+'\src\' + Filename); end; Result := GetDebugPath('KeymanCoreLibraryPath', ''); diff --git a/core/src/action.cpp b/core/src/action.cpp index 5f591444091..1ff7917575c 100644 --- a/core/src/action.cpp +++ b/core/src/action.cpp @@ -61,7 +61,9 @@ bool km::core::action_item_list_to_actions_object( if(output.empty()) { actions->code_points_to_delete++; } else { +#ifndef NDEBUG auto last_context_item = output.back(); +#endif output.pop_back(); assert(last_context_item.type == KM_CORE_CT_CHAR); assert(last_context_item.character == action_items->backspace.expected_value); @@ -71,7 +73,9 @@ bool km::core::action_item_list_to_actions_object( if(output.empty()) { // deleting a marker has no effect on the application } else { +#ifndef NDEBUG auto last_context_item = output.back(); +#endif output.pop_back(); assert(last_context_item.type == KM_CORE_CT_MARKER); assert(last_context_item.marker == action_items->backspace.expected_value); diff --git a/core/src/ldml/ldml_markers.cpp b/core/src/ldml/ldml_markers.cpp index 5d4fb4ff462..50c2282828d 100644 --- a/core/src/ldml/ldml_markers.cpp +++ b/core/src/ldml/ldml_markers.cpp @@ -56,15 +56,19 @@ void add_back_markers(std::u32string &str, const std::u32string &src, marker_map str.clear(); // iterator over the marker map auto marki = map2.rbegin(); +#ifndef NDEBUG // number of markers left to processnfd size_t max_markers = count_markers(map); size_t processed_markers = 0; +#endif // add any end-of-text markers while(marki != map2.rend() && marki->ch == MARKER_BEFORE_EOT) { if (!marki->end) { prepend_marker(str, marki->marker, encoding); +#ifndef NDEBUG processed_markers++; +#endif } marki->processed = true; // mark as done marki++; @@ -88,7 +92,9 @@ void add_back_markers(std::u32string &str, const std::u32string &src, marker_map break; } else { prepend_marker(str, i->marker, encoding); +#ifndef NDEBUG processed_markers++; +#endif } } } diff --git a/core/src/ldml/ldml_processor.cpp b/core/src/ldml/ldml_processor.cpp index 826c0e7f51c..548c0d76b00 100644 --- a/core/src/ldml/ldml_processor.cpp +++ b/core/src/ldml/ldml_processor.cpp @@ -410,8 +410,10 @@ ldml_event_state::remove_text(std::u32string &str, size_t length) { /** track how many context items have been removed, via push_backspace() */ size_t contextRemoved = 0; for (auto c = state->context().rbegin(); length > 0 && c != state->context().rend(); c++, contextRemoved++) { +#ifndef NDEBUG /** last char of context */ km_core_usv lastCtx = str.back(); +#endif uint8_t type = c->type; assert(type == KM_CORE_BT_CHAR || type == KM_CORE_BT_MARKER); if (type == KM_CORE_BT_CHAR) { diff --git a/core/tests/kmx_test_source/kmx_test_source.cpp b/core/tests/kmx_test_source/kmx_test_source.cpp index 0464bce8832..9ba7ed36e83 100644 --- a/core/tests/kmx_test_source/kmx_test_source.cpp +++ b/core/tests/kmx_test_source/kmx_test_source.cpp @@ -18,6 +18,9 @@ #include "kmx_test_source.hpp" +#include +#include + namespace km { namespace tests { @@ -51,7 +54,7 @@ KmxTestSource::parse_source_string(std::string const &s) { if (*p == '\\') { p++; km_core_usv v; - assert(p != s.end()); + test_assert(p != s.end()); if (*p == 'u' || *p == 'U') { // Unicode value p++; @@ -59,7 +62,7 @@ KmxTestSource::parse_source_string(std::string const &s) { std::string s1 = s.substr(p - s.begin(), 8); v = std::stoul(s1, &n, 16); // Allow deadkey_number (U+0001) characters and onward - assert(v >= 0x0001 && v <= 0x10FFFF); + test_assert(v >= 0x0001 && v <= 0x10FFFF); p += n - 1; if (v < 0x10000) { t += km_core_cu(v); @@ -70,7 +73,7 @@ KmxTestSource::parse_source_string(std::string const &s) { } else if (*p == 'd') { // Deadkey // TODO, not yet supported - assert(false); + test_assert(false); } } else { t += *p; @@ -212,7 +215,7 @@ KmxTestSource::get_keyboard_options(kmx_options options) { key_event KmxTestSource::char_to_event(char ch) { - assert(ch >= 32); + test_assert(ch >= 32); return { km::core::kmx::s_char_to_vkey[(int)ch - 32].vk, (uint16_t)(km::core::kmx::s_char_to_vkey[(int)ch - 32].shifted ? KM_CORE_MODIFIER_SHIFT : 0)}; @@ -258,8 +261,8 @@ KmxTestSource::vkey_to_event(std::string const &vk_event) { } // The string should be empty at this point - assert(!std::getline(f, s, ' ')); - assert(vk != 0); + test_assert(!std::getline(f, s, ' ')); + test_assert(vk != 0); return {vk, modifier_state}; } @@ -276,7 +279,7 @@ KmxTestSource::next_key(std::string &keys) { return char_to_event(ch); } auto n = keys.find(']'); - assert(n != std::string::npos); + test_assert(n != std::string::npos); auto vkey = keys.substr(1, n - 1); keys.erase(0, n + 1); return vkey_to_event(vkey); diff --git a/core/tests/meson.build b/core/tests/meson.build index 90e0ab2a54b..ce0f68a2577 100644 --- a/core/tests/meson.build +++ b/core/tests/meson.build @@ -7,7 +7,7 @@ # # Note: this version of cmpfiles ignores line endings, which is better for platform independence -cmpfiles = ['-c', 'import sys; a = open(sys.argv[1], \'r\').read(); b = open(sys.argv[2], \'r\').read(); exit(not (a==b))'] +cmpfiles = ['-c', 'import sys; a = open(sys.argv[1], \'r\').read(); b = open(sys.argv[2], \'r\').read(); sys.exit(not (a==b))'] stnds = join_paths(meson.current_source_dir(), 'standards') libsrc = include_directories( diff --git a/core/tests/unit/emscripten_filesystem.cpp b/core/tests/unit/emscripten_filesystem.cpp index c5e180f6bea..d51fa98f12d 100644 --- a/core/tests/unit/emscripten_filesystem.cpp +++ b/core/tests/unit/emscripten_filesystem.cpp @@ -4,7 +4,7 @@ #include #include -#include +#include const std::string get_wasm_file_path(const std::string& filename) { // Verify that we are passing a fully-qualified path @@ -13,13 +13,13 @@ const std::string get_wasm_file_path(const std::string& filename) { std::cout << "get_wasm_file_path ENTER (" << filename << ")" << std::endl; #endif - assert( + test_assert( (filename.length() > 0 && filename.at(0) == '/') || (filename.length() > 1 && filename.at(1) == ':') ); #if _DEBUG_FOPEN - std::cout << "get_wasm_file_path assert passed " << std::endl; + std::cout << "get_wasm_file_path test_assert passed " << std::endl; #endif EM_ASM_({ diff --git a/core/tests/unit/kmnkbd/action_api.tests.cpp b/core/tests/unit/kmnkbd/action_api.tests.cpp index 6899539d874..b4bbb1cd844 100644 --- a/core/tests/unit/kmnkbd/action_api.tests.cpp +++ b/core/tests/unit/kmnkbd/action_api.tests.cpp @@ -35,19 +35,19 @@ void test_two_backspaces() { }; km_core_actions actions; - assert(km::core::action_item_list_to_actions_object(action_items, &actions)); + test_assert(km::core::action_item_list_to_actions_object(action_items, &actions)); - assert(actions.code_points_to_delete == 1); - assert(std::u32string(actions.output) == U""); - assert(actions.persist_options != nullptr); - assert(actions.persist_options[0].key == nullptr); - assert(actions.persist_options[0].value == nullptr); - assert(actions.persist_options[0].scope == KM_CORE_OPT_UNKNOWN); + test_assert(actions.code_points_to_delete == 1); + test_assert(std::u32string(actions.output) == U""); + test_assert(actions.persist_options != nullptr); + test_assert(actions.persist_options[0].key == nullptr); + test_assert(actions.persist_options[0].value == nullptr); + test_assert(actions.persist_options[0].scope == KM_CORE_OPT_UNKNOWN); - assert(actions.do_alert == false); - assert(actions.emit_keystroke == false); - assert(actions.new_caps_lock_state == -1); - assert(actions.deleted_context == nullptr); + test_assert(actions.do_alert == false); + test_assert(actions.emit_keystroke == false); + test_assert(actions.new_caps_lock_state == -1); + test_assert(actions.deleted_context == nullptr); km::core::actions_dispose(actions); } @@ -68,18 +68,18 @@ void test_marker_text_interleaved() { }; km_core_actions actions; - assert(km::core::action_item_list_to_actions_object(action_items, &actions)); - - assert(actions.code_points_to_delete == 0); - assert(std::u32string(actions.output) == U"ABD"); - assert(actions.persist_options != nullptr); - assert(actions.persist_options[0].key == nullptr); - assert(actions.persist_options[0].value == nullptr); - assert(actions.persist_options[0].scope == KM_CORE_OPT_UNKNOWN); - assert(actions.do_alert == false); - assert(actions.emit_keystroke == false); - assert(actions.new_caps_lock_state == -1); - assert(actions.deleted_context == nullptr); + test_assert(km::core::action_item_list_to_actions_object(action_items, &actions)); + + test_assert(actions.code_points_to_delete == 0); + test_assert(std::u32string(actions.output) == U"ABD"); + test_assert(actions.persist_options != nullptr); + test_assert(actions.persist_options[0].key == nullptr); + test_assert(actions.persist_options[0].value == nullptr); + test_assert(actions.persist_options[0].scope == KM_CORE_OPT_UNKNOWN); + test_assert(actions.do_alert == false); + test_assert(actions.emit_keystroke == false); + test_assert(actions.new_caps_lock_state == -1); + test_assert(actions.deleted_context == nullptr); km::core::actions_dispose(actions); } @@ -93,18 +93,18 @@ void test_alert() { }; km_core_actions actions; - assert(km::core::action_item_list_to_actions_object(action_items, &actions)); - - assert(actions.code_points_to_delete == 0); - assert(std::u32string(actions.output) == U""); - assert(actions.persist_options != nullptr); - assert(actions.persist_options[0].key == nullptr); - assert(actions.persist_options[0].value == nullptr); - assert(actions.persist_options[0].scope == KM_CORE_OPT_UNKNOWN); - assert(actions.do_alert == KM_CORE_TRUE); - assert(actions.emit_keystroke == KM_CORE_FALSE); - assert(actions.new_caps_lock_state == KM_CORE_CAPS_UNCHANGED); - assert(actions.deleted_context == nullptr); + test_assert(km::core::action_item_list_to_actions_object(action_items, &actions)); + + test_assert(actions.code_points_to_delete == 0); + test_assert(std::u32string(actions.output) == U""); + test_assert(actions.persist_options != nullptr); + test_assert(actions.persist_options[0].key == nullptr); + test_assert(actions.persist_options[0].value == nullptr); + test_assert(actions.persist_options[0].scope == KM_CORE_OPT_UNKNOWN); + test_assert(actions.do_alert == KM_CORE_TRUE); + test_assert(actions.emit_keystroke == KM_CORE_FALSE); + test_assert(actions.new_caps_lock_state == KM_CORE_CAPS_UNCHANGED); + test_assert(actions.deleted_context == nullptr); km::core::actions_dispose(actions); } @@ -118,18 +118,18 @@ void test_emit_keystroke() { }; km_core_actions actions; - assert(km::core::action_item_list_to_actions_object(action_items, &actions)); - - assert(actions.code_points_to_delete == 0); - assert(std::u32string(actions.output) == U""); - assert(actions.persist_options != nullptr); - assert(actions.persist_options[0].key == nullptr); - assert(actions.persist_options[0].value == nullptr); - assert(actions.persist_options[0].scope == KM_CORE_OPT_UNKNOWN); - assert(actions.do_alert == KM_CORE_FALSE); - assert(actions.emit_keystroke == KM_CORE_TRUE); - assert(actions.new_caps_lock_state == KM_CORE_CAPS_UNCHANGED); - assert(actions.deleted_context == nullptr); + test_assert(km::core::action_item_list_to_actions_object(action_items, &actions)); + + test_assert(actions.code_points_to_delete == 0); + test_assert(std::u32string(actions.output) == U""); + test_assert(actions.persist_options != nullptr); + test_assert(actions.persist_options[0].key == nullptr); + test_assert(actions.persist_options[0].value == nullptr); + test_assert(actions.persist_options[0].scope == KM_CORE_OPT_UNKNOWN); + test_assert(actions.do_alert == KM_CORE_FALSE); + test_assert(actions.emit_keystroke == KM_CORE_TRUE); + test_assert(actions.new_caps_lock_state == KM_CORE_CAPS_UNCHANGED); + test_assert(actions.deleted_context == nullptr); km::core::actions_dispose(actions); } @@ -144,18 +144,18 @@ void test_invalidate_context() { }; km_core_actions actions; - assert(km::core::action_item_list_to_actions_object(action_items, &actions)); - - assert(actions.code_points_to_delete == 0); - assert(std::u32string(actions.output) == U""); - assert(actions.persist_options != nullptr); - assert(actions.persist_options[0].key == nullptr); - assert(actions.persist_options[0].value == nullptr); - assert(actions.persist_options[0].scope == KM_CORE_OPT_UNKNOWN); - assert(actions.do_alert == KM_CORE_FALSE); - assert(actions.emit_keystroke == KM_CORE_FALSE); - assert(actions.new_caps_lock_state == KM_CORE_CAPS_UNCHANGED); - assert(actions.deleted_context == nullptr); + test_assert(km::core::action_item_list_to_actions_object(action_items, &actions)); + + test_assert(actions.code_points_to_delete == 0); + test_assert(std::u32string(actions.output) == U""); + test_assert(actions.persist_options != nullptr); + test_assert(actions.persist_options[0].key == nullptr); + test_assert(actions.persist_options[0].value == nullptr); + test_assert(actions.persist_options[0].scope == KM_CORE_OPT_UNKNOWN); + test_assert(actions.do_alert == KM_CORE_FALSE); + test_assert(actions.emit_keystroke == KM_CORE_FALSE); + test_assert(actions.new_caps_lock_state == KM_CORE_CAPS_UNCHANGED); + test_assert(actions.deleted_context == nullptr); km::core::actions_dispose(actions); } @@ -175,28 +175,28 @@ void test_persist_opt() { }; km_core_actions actions; - assert(km::core::action_item_list_to_actions_object(action_items, &actions)); + test_assert(km::core::action_item_list_to_actions_object(action_items, &actions)); - assert(actions.code_points_to_delete == 0); - assert(std::u32string(actions.output) == U""); - assert(actions.persist_options != nullptr); - assert(std::u16string(actions.persist_options[0].key) == u"key"); - assert(std::u16string(actions.persist_options[0].value) == u"value"); - assert(actions.persist_options[0].scope == KM_CORE_OPT_KEYBOARD); + test_assert(actions.code_points_to_delete == 0); + test_assert(std::u32string(actions.output) == U""); + test_assert(actions.persist_options != nullptr); + test_assert(std::u16string(actions.persist_options[0].key) == u"key"); + test_assert(std::u16string(actions.persist_options[0].value) == u"value"); + test_assert(actions.persist_options[0].scope == KM_CORE_OPT_KEYBOARD); // verify that data is copied - assert(actions.persist_options[0].key != option.key); - assert(actions.persist_options[0].value != option.value); + test_assert(actions.persist_options[0].key != option.key); + test_assert(actions.persist_options[0].value != option.value); // verify that we have a KM_CORE_OPTIONS_END term - assert(actions.persist_options[1].key == nullptr); - assert(actions.persist_options[1].value == nullptr); - assert(actions.persist_options[1].scope == KM_CORE_OPT_UNKNOWN); - - assert(actions.do_alert == KM_CORE_FALSE); - assert(actions.emit_keystroke == KM_CORE_FALSE); - assert(actions.new_caps_lock_state == KM_CORE_CAPS_UNCHANGED); - assert(actions.deleted_context == nullptr); + test_assert(actions.persist_options[1].key == nullptr); + test_assert(actions.persist_options[1].value == nullptr); + test_assert(actions.persist_options[1].scope == KM_CORE_OPT_UNKNOWN); + + test_assert(actions.do_alert == KM_CORE_FALSE); + test_assert(actions.emit_keystroke == KM_CORE_FALSE); + test_assert(actions.new_caps_lock_state == KM_CORE_CAPS_UNCHANGED); + test_assert(actions.deleted_context == nullptr); km::core::actions_dispose(actions); } diff --git a/core/tests/unit/kmnkbd/action_set_api.tests.cpp b/core/tests/unit/kmnkbd/action_set_api.tests.cpp index 4806eb4ac94..72a2d9be531 100644 --- a/core/tests/unit/kmnkbd/action_set_api.tests.cpp +++ b/core/tests/unit/kmnkbd/action_set_api.tests.cpp @@ -74,20 +74,20 @@ void run_test(km_core_action_item const * action_items, const km_core_actions &a int n = 0; for(auto act = set_actions.begin(); act != set_actions.end(); act++, n++) { - assert(act->type == action_items[n].type); + test_assert(act->type == action_items[n].type); // TODO: all other fields switch(act->type) { case KM_CORE_IT_ALERT: break; case KM_CORE_IT_BACK: - assert(act->backspace.expected_type == action_items[n].backspace.expected_type); - assert(act->backspace.expected_value == action_items[n].backspace.expected_value); + test_assert(act->backspace.expected_type == action_items[n].backspace.expected_type); + test_assert(act->backspace.expected_value == action_items[n].backspace.expected_value); break; case KM_CORE_IT_CAPSLOCK: - assert(act->capsLock == action_items[n].capsLock); + test_assert(act->capsLock == action_items[n].capsLock); break; case KM_CORE_IT_CHAR: - assert(act->character == action_items[n].character); + test_assert(act->character == action_items[n].character); break; case KM_CORE_IT_EMIT_KEYSTROKE: break; @@ -96,16 +96,16 @@ void run_test(km_core_action_item const * action_items, const km_core_actions &a case KM_CORE_IT_INVALIDATE_CONTEXT: break; case KM_CORE_IT_MARKER: - assert(act->marker == action_items[n].marker); + test_assert(act->marker == action_items[n].marker); break; case KM_CORE_IT_PERSIST_OPT: - assert(act->option->scope == action_items[n].option->scope); - assert(std::u16string(act->option->key) == action_items[n].option->key); - assert(std::u16string(act->option->value) == action_items[n].option->value); + test_assert(act->option->scope == action_items[n].option->scope); + test_assert(std::u16string(act->option->key) == action_items[n].option->key); + test_assert(std::u16string(act->option->value) == action_items[n].option->value); break; default: // Invalid action type - assert(false); + test_assert(false); } } } diff --git a/core/tests/unit/kmnkbd/actions_get_api.tests.cpp b/core/tests/unit/kmnkbd/actions_get_api.tests.cpp index 579f02e5ced..f9b7c75dac5 100644 --- a/core/tests/unit/kmnkbd/actions_get_api.tests.cpp +++ b/core/tests/unit/kmnkbd/actions_get_api.tests.cpp @@ -139,17 +139,17 @@ void test( } std::cout << std::endl; - assert(expected_delete == actual_actions->code_points_to_delete); - assert(expected_output == actual_actions->output); - assert(expected_deleted_context == actual_actions->deleted_context); + test_assert(expected_delete == actual_actions->code_points_to_delete); + test_assert(expected_output == actual_actions->output); + test_assert(expected_deleted_context == actual_actions->deleted_context); - // assert(expected_deleted_context == actual_actions->deleted_context); + // test_assert(expected_deleted_context == actual_actions->deleted_context); auto actual_final_app_context = get_context_as_string(km_core_state_app_context(test_state)); auto actual_final_app_context_string = std::u16string(actual_final_app_context); auto expected_final_app_context_string = std::u16string(expected_final_app_context); std::cout << " final app context: actual: |" << actual_final_app_context_string << "| expected: |" << expected_final_app_context_string << "|" << std::endl; - assert(actual_final_app_context_string == expected_final_app_context_string); + test_assert(actual_final_app_context_string == expected_final_app_context_string); delete [] actual_final_app_context; teardown(); diff --git a/core/tests/unit/kmnkbd/actions_normalize.tests.cpp b/core/tests/unit/kmnkbd/actions_normalize.tests.cpp index aa4150ef9ad..f71ef1cd3f1 100644 --- a/core/tests/unit/kmnkbd/actions_normalize.tests.cpp +++ b/core/tests/unit/kmnkbd/actions_normalize.tests.cpp @@ -121,7 +121,7 @@ void test_actions_normalize( setup(initial_app_context, final_cached_context_string, final_cached_context_items, actions_code_points_to_delete, actions_output); - assert(km::core::actions_normalize(km_core_state_context(test_state), km_core_state_app_context(test_state), test_actions)); + test_assert(km::core::actions_normalize(km_core_state_context(test_state), km_core_state_app_context(test_state), test_actions)); std::cout << "test_actions_normalize: (" << name << "): delete: " << test_actions.code_points_to_delete << " output: |" << std::u32string(test_actions.output) << "|" << std::endl; std::u32string o(test_actions.output); @@ -130,8 +130,8 @@ void test_actions_normalize( } std::cout << std::endl; - assert(expected_delete == test_actions.code_points_to_delete); - assert(expected_output == test_actions.output); + test_assert(expected_delete == test_actions.code_points_to_delete); + test_assert(expected_output == test_actions.output); auto debug = km_core_state_context_debug(test_state, KM_CORE_DEBUG_CONTEXT_APP); std::cout << " final app context: " << debug << std::endl; @@ -195,7 +195,7 @@ void test_actions_update_app_context_nfu( setup(initial_app_context, final_cached_context_string, final_cached_context_items, actions_code_points_to_delete, actions_output); - assert(km::core::actions_update_app_context_nfu(km_core_state_context(test_state), km_core_state_app_context(test_state))); + test_assert(km::core::actions_update_app_context_nfu(km_core_state_context(test_state), km_core_state_app_context(test_state))); std::cout << "test_actions_update_app_context_nfu: (" << name << "): delete: " << expected_delete << " output: |" << std::u32string(test_actions.output) << "|" << std::endl; std::u32string o(test_actions.output); @@ -204,8 +204,8 @@ void test_actions_update_app_context_nfu( } std::cout << std::endl; - assert(expected_delete == test_actions.code_points_to_delete); - assert(expected_output == test_actions.output); + test_assert(expected_delete == test_actions.code_points_to_delete); + test_assert(expected_output == test_actions.output); auto debug = km_core_state_context_debug(test_state, KM_CORE_DEBUG_CONTEXT_APP); std::cout << " final app context: " << debug << std::endl; @@ -627,7 +627,7 @@ void compare_context(km_core_context *app_context, const km_core_cu* expected_fi try_status(context_items_from_utf16(expected_final_app_context, &expected_final_app_context_items)); for(int i = 0; actual_final_app_context_items[i].type != KM_CORE_CT_END || expected_final_app_context_items[i].type != KM_CORE_CT_END; i++) { - assert( + test_assert( actual_final_app_context_items[i].type == expected_final_app_context_items[i].type && // union so testing character is sufficient to do both char + marker types actual_final_app_context_items[i].character == expected_final_app_context_items[i].character diff --git a/core/tests/unit/kmnkbd/debug_api.tests.cpp b/core/tests/unit/kmnkbd/debug_api.tests.cpp index 9a0d771e041..d40664436b0 100644 --- a/core/tests/unit/kmnkbd/debug_api.tests.cpp +++ b/core/tests/unit/kmnkbd/debug_api.tests.cpp @@ -61,10 +61,10 @@ void setup(const char *keyboard) { try_status(context_items_from_utf16(u"Hello 😁", &citems)); // Pre-test sanity: ensure debugging is disabled - assert(km_core_state_debug_get(test_state) == 0); + test_assert(km_core_state_debug_get(test_state) == 0); // Ensure the pre-run debug item state is not empty - assert(debug_items(test_state, { + test_assert(debug_items(test_state, { km_core_state_debug_item{KM_CORE_DEBUG_END, {}, {}, {}} })); @@ -79,11 +79,11 @@ void test_debugging_disabled() { setup("k_000___null_keyboard.kmx"); try_status(km_core_state_debug_set(test_state, 0)); try_status(km_core_process_event(test_state, KM_CORE_VKEY_S, KM_CORE_MODIFIER_SHIFT, 1, KM_CORE_EVENT_FLAG_DEFAULT)); - assert(debug_items(test_state, { + test_assert(debug_items(test_state, { km_core_state_debug_item{KM_CORE_DEBUG_END} })); - assert(action_items(test_state, { + test_assert(action_items(test_state, { {KM_CORE_IT_CHAR, {0,}, {km_core_usv('S')}}, {KM_CORE_IT_END} })); @@ -97,14 +97,14 @@ void test_debugging_no_rule_match() { DEBUG_GROUP gp = {u"Main"}; try_status(km_core_state_debug_set(test_state, 1)); try_status(km_core_process_event(test_state, KM_CORE_VKEY_S, KM_CORE_MODIFIER_SHIFT, 1, KM_CORE_EVENT_FLAG_DEFAULT)); - assert(debug_items(test_state, { + test_assert(debug_items(test_state, { km_core_state_debug_item{KM_CORE_DEBUG_BEGIN, KM_CORE_DEBUG_FLAG_UNICODE, {KM_CORE_VKEY_S, KM_CORE_MODIFIER_SHIFT, 'S'}}, km_core_state_debug_item{KM_CORE_DEBUG_GROUP_ENTER, 0, {}, {u"", &gp}}, km_core_state_debug_item{KM_CORE_DEBUG_GROUP_EXIT, KM_CORE_DEBUG_FLAG_NOMATCH, {}, {u"", &gp, nullptr, {}, 1}}, km_core_state_debug_item{KM_CORE_DEBUG_END, 0, {}, {u"", nullptr, nullptr, {}, 1}} })); - assert(action_items(test_state, { + test_assert(action_items(test_state, { {KM_CORE_IT_CHAR, {0,}, {km_core_usv('S')}}, {KM_CORE_IT_END} })); @@ -118,14 +118,14 @@ void test_debugging_function_key() { DEBUG_GROUP gp = {u"Main"}; try_status(km_core_state_debug_set(test_state, 1)); try_status(km_core_process_event(test_state, KM_CORE_VKEY_F1, 0, 1, KM_CORE_EVENT_FLAG_DEFAULT)); - assert(debug_items(test_state, { + test_assert(debug_items(test_state, { km_core_state_debug_item{KM_CORE_DEBUG_BEGIN, KM_CORE_DEBUG_FLAG_UNICODE, {KM_CORE_VKEY_F1, 0, 0}}, km_core_state_debug_item{KM_CORE_DEBUG_GROUP_ENTER, 0, {}, {u"", &gp}}, km_core_state_debug_item{KM_CORE_DEBUG_GROUP_EXIT, KM_CORE_DEBUG_FLAG_NOMATCH, {}, {u"", &gp, nullptr, {}, 0}}, km_core_state_debug_item{KM_CORE_DEBUG_END, KM_CORE_DEBUG_FLAG_OUTPUTKEYSTROKE, {}, {u"", nullptr, nullptr, {}, 0}} })); - assert(action_items(test_state, { + test_assert(action_items(test_state, { {KM_CORE_IT_INVALIDATE_CONTEXT}, // It's a non character key that is not a modifier, so this is a hint that context may no longer be valid {KM_CORE_IT_EMIT_KEYSTROKE}, {KM_CORE_IT_END} @@ -144,33 +144,33 @@ void test_basic_rule_matches() { // 'DE' + 'F' > U+0E04 U+0E05 U+0E06 try_status(km_core_process_event(test_state, KM_CORE_VKEY_D, KM_CORE_MODIFIER_SHIFT, 1, KM_CORE_EVENT_FLAG_DEFAULT)); - assert(debug_items(test_state, { + test_assert(debug_items(test_state, { km_core_state_debug_item{KM_CORE_DEBUG_BEGIN, KM_CORE_DEBUG_FLAG_UNICODE, {KM_CORE_VKEY_D, KM_CORE_MODIFIER_SHIFT, 'D'}}, km_core_state_debug_item{KM_CORE_DEBUG_GROUP_ENTER, 0, {}, {u"", &gp}}, km_core_state_debug_item{KM_CORE_DEBUG_GROUP_EXIT, KM_CORE_DEBUG_FLAG_NOMATCH, {}, {u"", &gp, nullptr, {}, 1}}, km_core_state_debug_item{KM_CORE_DEBUG_END, 0, {}, {u"", nullptr, nullptr, {}, 1}}, // action item will emit a default 'D' })); - assert(action_items(test_state, { + test_assert(action_items(test_state, { {KM_CORE_IT_CHAR, {0,}, {km_core_usv('D')}}, {KM_CORE_IT_END} })); try_status(km_core_process_event(test_state, KM_CORE_VKEY_E, KM_CORE_MODIFIER_SHIFT, 1, KM_CORE_EVENT_FLAG_DEFAULT)); - assert(debug_items(test_state, { + test_assert(debug_items(test_state, { km_core_state_debug_item{KM_CORE_DEBUG_BEGIN, KM_CORE_DEBUG_FLAG_UNICODE, {KM_CORE_VKEY_E, KM_CORE_MODIFIER_SHIFT, 'E'}}, km_core_state_debug_item{KM_CORE_DEBUG_GROUP_ENTER, 0, {}, {u"", &gp}}, km_core_state_debug_item{KM_CORE_DEBUG_GROUP_EXIT, KM_CORE_DEBUG_FLAG_NOMATCH, {}, {u"", &gp, nullptr, {}, 1}}, km_core_state_debug_item{KM_CORE_DEBUG_END, 0, {}, {u"", nullptr, nullptr, {}, 1}}, // action item will emit a default 'E' })); - assert(action_items(test_state, { + test_assert(action_items(test_state, { {KM_CORE_IT_CHAR, {0,}, {km_core_usv('E')}}, {KM_CORE_IT_END} })); try_status(km_core_process_event(test_state, KM_CORE_VKEY_F, KM_CORE_MODIFIER_SHIFT, 1, KM_CORE_EVENT_FLAG_DEFAULT)); - assert(debug_items(test_state, { + test_assert(debug_items(test_state, { km_core_state_debug_item{KM_CORE_DEBUG_BEGIN, KM_CORE_DEBUG_FLAG_UNICODE, {KM_CORE_VKEY_F, KM_CORE_MODIFIER_SHIFT, 'F'}}, km_core_state_debug_item{KM_CORE_DEBUG_GROUP_ENTER, 0, {}, {u"", &gp}}, km_core_state_debug_item{KM_CORE_DEBUG_RULE_ENTER, 0, {}, {u"DE", &gp, &kp, {0xFFFF}}}, @@ -187,7 +187,7 @@ void test_basic_rule_matches() { bksp_e.backspace.expected_type = KM_CORE_BT_CHAR; bksp_e.backspace.expected_value = 'E'; - assert(action_items(test_state, { + test_assert(action_items(test_state, { bksp_e, bksp_d, {KM_CORE_IT_CHAR, {0,}, {km_core_usv(u'\u0E04')}}, @@ -214,7 +214,7 @@ void test_multiple_groups() { // '12' -> 'abc' try_status(km_core_process_event(test_state, KM_CORE_VKEY_1, 0, 1, KM_CORE_EVENT_FLAG_DEFAULT)); - assert(debug_items(test_state, { + test_assert(debug_items(test_state, { km_core_state_debug_item{KM_CORE_DEBUG_BEGIN, KM_CORE_DEBUG_FLAG_UNICODE, {KM_CORE_VKEY_1, 0, '1'}}, km_core_state_debug_item{KM_CORE_DEBUG_GROUP_ENTER, 0, {}, {u"", &gp}}, @@ -236,7 +236,7 @@ void test_multiple_groups() { bksp_a.backspace.expected_type = KM_CORE_BT_CHAR; bksp_a.backspace.expected_value = 'a'; - assert(action_items(test_state, { + test_assert(action_items(test_state, { {KM_CORE_IT_CHAR, {0,}, {km_core_usv('a')}}, bksp_a, {KM_CORE_IT_CHAR, {0,}, {km_core_usv('b')}}, @@ -244,7 +244,7 @@ void test_multiple_groups() { })); try_status(km_core_process_event(test_state, KM_CORE_VKEY_2, 0, 1, KM_CORE_EVENT_FLAG_DEFAULT)); - assert(debug_items(test_state, { + test_assert(debug_items(test_state, { km_core_state_debug_item{KM_CORE_DEBUG_BEGIN, KM_CORE_DEBUG_FLAG_UNICODE, {KM_CORE_VKEY_2, 0, '2'}}, km_core_state_debug_item{KM_CORE_DEBUG_GROUP_ENTER, 0, {}, {u"", &gp}}, @@ -269,7 +269,7 @@ void test_multiple_groups() { bksp_b.backspace.expected_type = KM_CORE_BT_CHAR; bksp_b.backspace.expected_value = 'b'; - assert(action_items(test_state, { + test_assert(action_items(test_state, { bksp_b, {KM_CORE_IT_CHAR, {0,}, {km_core_usv('a')}}, {KM_CORE_IT_CHAR, {0,}, {km_core_usv('b')}}, @@ -293,7 +293,7 @@ void test_store_offsets() { // 'ab' -> 'ex' try_status(km_core_process_event(test_state, KM_CORE_VKEY_A, 0, 1, KM_CORE_EVENT_FLAG_DEFAULT)); - assert(debug_items(test_state, { + test_assert(debug_items(test_state, { km_core_state_debug_item{KM_CORE_DEBUG_BEGIN, KM_CORE_DEBUG_FLAG_UNICODE, {KM_CORE_VKEY_A, 0, 'a'}}, km_core_state_debug_item{KM_CORE_DEBUG_GROUP_ENTER, 0, {}, {u"", &gp}}, @@ -304,7 +304,7 @@ void test_store_offsets() { km_core_state_debug_item{KM_CORE_DEBUG_END, 0, {}, {u"", nullptr, nullptr, {}, 4}}, // action item will emit a 'exay' })); - assert(action_items(test_state, { + test_assert(action_items(test_state, { {KM_CORE_IT_CHAR, {0,}, {km_core_usv('e')}}, {KM_CORE_IT_CHAR, {0,}, {km_core_usv('x')}}, {KM_CORE_IT_CHAR, {0,}, {km_core_usv('a')}}, @@ -313,7 +313,7 @@ void test_store_offsets() { })); try_status(km_core_process_event(test_state, KM_CORE_VKEY_B, 0, 1, KM_CORE_EVENT_FLAG_DEFAULT)); - assert(debug_items(test_state, { + test_assert(debug_items(test_state, { km_core_state_debug_item{KM_CORE_DEBUG_BEGIN, KM_CORE_DEBUG_FLAG_UNICODE, {KM_CORE_VKEY_B, 0, 'b'}}, km_core_state_debug_item{KM_CORE_DEBUG_GROUP_ENTER, 0, {}, {u"", &gp}}, @@ -342,7 +342,7 @@ void test_store_offsets() { bksp[2].backspace.expected_value = 'x'; bksp[3].backspace.expected_value = 'e'; - assert(action_items(test_state, { + test_assert(action_items(test_state, { bksp[0], bksp[1], bksp[2], @@ -367,7 +367,7 @@ void test_set_option() { // '1' -> set_option try_status(km_core_process_event(test_state, KM_CORE_VKEY_1, 0, 1, KM_CORE_EVENT_FLAG_DEFAULT)); - assert(debug_items(test_state, { + test_assert(debug_items(test_state, { km_core_state_debug_item{KM_CORE_DEBUG_BEGIN, KM_CORE_DEBUG_FLAG_UNICODE, {KM_CORE_VKEY_1, 0, '1'}}, km_core_state_debug_item{KM_CORE_DEBUG_GROUP_ENTER, 0, {}, {u"", &gp}}, @@ -395,7 +395,7 @@ void test_save_option() { // '2' -> save_option try_status(km_core_process_event(test_state, KM_CORE_VKEY_2, 0, 1, KM_CORE_EVENT_FLAG_DEFAULT)); - assert(debug_items(test_state, { + test_assert(debug_items(test_state, { km_core_state_debug_item{KM_CORE_DEBUG_BEGIN, KM_CORE_DEBUG_FLAG_UNICODE, {KM_CORE_VKEY_2, 0, '2'}}, km_core_state_debug_item{KM_CORE_DEBUG_GROUP_ENTER, 0, {}, {u"", &gp}}, @@ -409,7 +409,7 @@ void test_save_option() { km_core_action_item action = {KM_CORE_IT_PERSIST_OPT, {0,}, }; action.option = &opt; - assert(action_items(test_state, { + test_assert(action_items(test_state, { action, {KM_CORE_IT_END} })); @@ -437,7 +437,7 @@ void test_backspace_markers() { try_status(km_core_state_debug_set(test_state, 1)); try_status(km_core_process_event(test_state, KM_CORE_VKEY_BKSP, 0, 1, KM_CORE_EVENT_FLAG_DEFAULT)); - assert(debug_items(test_state, { + test_assert(debug_items(test_state, { km_core_state_debug_item{KM_CORE_DEBUG_BEGIN, KM_CORE_DEBUG_FLAG_UNICODE, {KM_CORE_VKEY_BKSP, 0, 0}}, km_core_state_debug_item{KM_CORE_DEBUG_GROUP_ENTER, 0, {}, {u"", &gp}}, km_core_state_debug_item{KM_CORE_DEBUG_GROUP_EXIT, 2, {}, {u"", &gp, nullptr, {}, 2}}, @@ -448,7 +448,7 @@ void test_backspace_markers() { bksp.backspace.expected_type = KM_CORE_BT_MARKER; bksp.backspace.expected_value = 1; - assert(action_items(test_state, { + test_assert(action_items(test_state, { bksp, bksp, {KM_CORE_IT_INVALIDATE_CONTEXT}, diff --git a/core/tests/unit/kmnkbd/debug_items.hpp b/core/tests/unit/kmnkbd/debug_items.hpp index ae5f0e8cbd5..9e281631f6b 100644 --- a/core/tests/unit/kmnkbd/debug_items.hpp +++ b/core/tests/unit/kmnkbd/debug_items.hpp @@ -121,20 +121,20 @@ bool operator==( case KM_CORE_DEBUG_MATCH_EXIT: case KM_CORE_DEBUG_NOMATCH_ENTER: case KM_CORE_DEBUG_NOMATCH_EXIT: - assert(lgp != nullptr); - assert(rgp != nullptr); - assert(lgp->dpName != nullptr); - assert(rgp->dpName != nullptr); + test_assert(lgp != nullptr); + test_assert(rgp != nullptr); + test_assert(lgp->dpName != nullptr); + test_assert(rgp->dpName != nullptr); result = u16cmp(lgp->dpName, rgp->dpName) == 0; break; case KM_CORE_DEBUG_RULE_ENTER: case KM_CORE_DEBUG_RULE_EXIT: - assert(lgp != nullptr); - assert(rgp != nullptr); - assert(lgp->dpName != nullptr); - assert(rgp->dpName != nullptr); - assert(lrule != nullptr); - assert(rrule != nullptr); + test_assert(lgp != nullptr); + test_assert(rgp != nullptr); + test_assert(lgp->dpName != nullptr); + test_assert(rgp->dpName != nullptr); + test_assert(lrule != nullptr); + test_assert(rrule != nullptr); result = u16cmp(lgp->dpName, rgp->dpName) == 0 && lrule->Line == rrule->Line && lrule->Key == rrule->Key && @@ -143,13 +143,13 @@ bool operator==( are_store_offsets_equal(lhs.kmx_info.store_offsets, rhs.kmx_info.store_offsets); break; case KM_CORE_DEBUG_SET_OPTION: - assert(loption_store != nullptr && roption_store != nullptr); + test_assert(loption_store != nullptr && roption_store != nullptr); result = u16cmp(loption_store->dpName, roption_store->dpName) == 0 && u16cmp(lhs.kmx_info.option.value, rhs.kmx_info.option.value) == 0; break; default: - assert(false); + test_assert(false); result = false; } } diff --git a/core/tests/unit/kmnkbd/kmx_context.tests.cpp b/core/tests/unit/kmnkbd/kmx_context.tests.cpp index e557daeb3cb..0679c34d1a5 100644 --- a/core/tests/unit/kmnkbd/kmx_context.tests.cpp +++ b/core/tests/unit/kmnkbd/kmx_context.tests.cpp @@ -21,89 +21,89 @@ using namespace std; void test_CharIsDeadkey() { KMX_Context context; - assert(context.CharIsDeadkey() == FALSE); + test_assert(context.CharIsDeadkey() == FALSE); context.Reset(); context.Add(u'a'); context.Add(u'a'); context.Add(u'a'); - assert(context.CharIsDeadkey() == FALSE); + test_assert(context.CharIsDeadkey() == FALSE); context.Reset(); context.Add(u'\uffff'); context.Add(u'\u0008'); - assert(context.CharIsDeadkey() == FALSE); + test_assert(context.CharIsDeadkey() == FALSE); context.Reset(); context.Add(u'\uffff'); - assert(context.CharIsDeadkey() == FALSE); + test_assert(context.CharIsDeadkey() == FALSE); context.Reset(); context.Add(u'a'); context.Add(0xD801); context.Add(0xDC12); - assert(context.CharIsDeadkey() == FALSE); + test_assert(context.CharIsDeadkey() == FALSE); context.Reset(); context.Add(u'a'); context.Add(u'\uffff'); context.Add(u'\u0008'); - assert(context.CharIsDeadkey() == FALSE); + test_assert(context.CharIsDeadkey() == FALSE); context.Reset(); context.Add(u'a'); context.Add(u'\uffff'); context.Add(u'\u0014'); context.Add(u'\u0001'); - assert(context.CharIsDeadkey() == FALSE); + test_assert(context.CharIsDeadkey() == FALSE); context.Reset(); context.Add(u'\uffff'); context.Add(u'\u0008'); context.Add(u'\u0001'); - assert(context.CharIsDeadkey() == TRUE); + test_assert(context.CharIsDeadkey() == TRUE); context.Reset(); context.Add(u'a'); context.Add(u'\uffff'); context.Add(u'\u0008'); context.Add(u'\u0001'); - assert(context.CharIsDeadkey() == TRUE); + test_assert(context.CharIsDeadkey() == TRUE); } void test_CharIsSurrogatePair() { KMX_Context context; - assert(context.CharIsSurrogatePair() == FALSE); + test_assert(context.CharIsSurrogatePair() == FALSE); context.Reset(); context.Add(u'a'); - assert(context.CharIsSurrogatePair() == FALSE); + test_assert(context.CharIsSurrogatePair() == FALSE); context.Reset(); context.Add(u'a'); context.Add(u'a'); - assert(context.CharIsSurrogatePair() == FALSE); + test_assert(context.CharIsSurrogatePair() == FALSE); context.Reset(); context.Add(u'\uffff'); context.Add(u'\u0008'); context.Add(u'\u0001'); - assert(context.CharIsSurrogatePair() == FALSE); + test_assert(context.CharIsSurrogatePair() == FALSE); context.Reset(); context.Add(0xD801); - assert(context.CharIsSurrogatePair() == FALSE); + test_assert(context.CharIsSurrogatePair() == FALSE); // We don't support little endian surrogate pairs (cf #5111) context.Reset(); context.Add(0xDC12); context.Add(0xD801); - assert(context.CharIsSurrogatePair() == FALSE); + test_assert(context.CharIsSurrogatePair() == FALSE); context.Reset(); context.Add(0xD801); context.Add(0xDC12); - assert(context.CharIsSurrogatePair() == TRUE); + test_assert(context.CharIsSurrogatePair() == TRUE); } void @@ -114,54 +114,54 @@ test_Set() { context.Set(u"abc"); context.Get((KMX_WCHAR*)&buf, bufsize); - assert_string_equal(buf, u"abc"); + test_assert_string_equal(buf, u"abc"); context.Reset(); context.Set(u"\uFFFF\u0008\u0001abc"); context.Get((KMX_WCHAR *)&buf, bufsize); - assert_string_equal(buf, u"\uFFFF\u0008\u0001abc"); + test_assert_string_equal(buf, u"\uFFFF\u0008\u0001abc"); // test that we can set MAXCONTEXT-1 characters context.Reset(); auto text = u"\uFFFF\u0008\u0001abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefgh"; - assert_equal(u16len(text), MAXCONTEXT - 1); + test_assert_equal(u16len(text), MAXCONTEXT - 1); context.Set(text); context.Get((KMX_WCHAR *)&buf, bufsize); - assert_string_equal(buf, u"\uFFFF\u0008\u0001abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefgh"); + test_assert_string_equal(buf, u"\uFFFF\u0008\u0001abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefgh"); // test that setting > MAXCONTEXT-1 characters will only set the last MAXCONTEXT-1 characters context.Reset(); text = u"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl"; - assert_equal(u16len(text), MAXCONTEXT); + test_assert_equal(u16len(text), MAXCONTEXT); context.Set(text); context.Get((KMX_WCHAR *)&buf, bufsize); - assert_string_equal(buf, u"bcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl"); - assert_equal(u16len(buf), MAXCONTEXT - 1); + test_assert_string_equal(buf, u"bcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl"); + test_assert_equal(u16len(buf), MAXCONTEXT - 1); // test that setting > MAXCONTEXT-1 characters will set last characters and not split the deadkey context.Reset(); text = u"\uFFFF\u0008\u0001abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghi"; - assert_equal(u16len(text), MAXCONTEXT); + test_assert_equal(u16len(text), MAXCONTEXT); context.Set(text); context.Get((KMX_WCHAR *)&buf, bufsize); - assert_string_equal(buf, u"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghi"); - assert_equal(u16len(buf), MAXCONTEXT - 3); + test_assert_string_equal(buf, u"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghi"); + test_assert_equal(u16len(buf), MAXCONTEXT - 3); // test that setting the context replaces the previous context context.Reset(); context.Set(u"\uFFFF\u0008\u0001abc"); context.Set(u"def"); context.Get((KMX_WCHAR *)&buf, bufsize); - assert_string_equal(buf, u"def"); + test_assert_string_equal(buf, u"def"); // test that setting the context completely replaces the existing context context.Reset(); text = u"\uFFFF\u0008\u0001abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefgh"; - assert_equal(u16len(text), MAXCONTEXT-1); + test_assert_equal(u16len(text), MAXCONTEXT-1); context.Set(text); context.Set(u"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefgh1"); context.Get((KMX_WCHAR *)&buf, bufsize); - assert_string_equal(buf, u"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefgh1"); + test_assert_string_equal(buf, u"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefgh1"); } void @@ -172,19 +172,19 @@ test_Add() { context.Add(u'a'); context.Get((KMX_WCHAR *)&buf, bufsize); - assert_string_equal(buf, u"a"); + test_assert_string_equal(buf, u"a"); context.Reset(); context.Add(0xD801); context.Get((KMX_WCHAR *)&buf, bufsize); - assert_equal(u16len(buf), 1); - assert_equal(buf[0], 0xD801); + test_assert_equal(u16len(buf), 1); + test_assert_equal(buf[0], 0xD801); context.Reset(); context.Add(0xD801); context.Add(0xDC12); context.Get((KMX_WCHAR *)&buf, bufsize); - assert_string_equal(buf, u"\U00010412"); + test_assert_string_equal(buf, u"\U00010412"); context.Reset(); context.Add(u'\uFFFF'); @@ -192,25 +192,25 @@ test_Add() { context.Add(u'\u0001'); context.Add(u'a'); context.Get((KMX_WCHAR *)&buf, bufsize); - assert_string_equal(buf, u"\uFFFF\u0008\u0001a"); + test_assert_string_equal(buf, u"\uFFFF\u0008\u0001a"); context.Reset(); auto text = u"\uFFFF\u0008\u0001abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg"; - assert_equal(u16len(text), MAXCONTEXT - 2); + test_assert_equal(u16len(text), MAXCONTEXT - 2); context.Set(text); context.Add(u'1'); context.Get((KMX_WCHAR *)&buf, bufsize); - assert_string_equal(buf, u"\uFFFF\u0008\u0001abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg1"); - assert_equal(u16len(buf), MAXCONTEXT - 1); + test_assert_string_equal(buf, u"\uFFFF\u0008\u0001abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg1"); + test_assert_equal(u16len(buf), MAXCONTEXT - 1); context.Reset(); text = u"\uFFFF\u0008\u0001abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefgh"; - assert_equal(u16len(text), MAXCONTEXT - 1); + test_assert_equal(u16len(text), MAXCONTEXT - 1); context.Set(text); context.Add(u'1'); context.Get((KMX_WCHAR *)&buf, bufsize); - assert_string_equal(buf, u"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefgh1"); - assert_equal(u16len(buf), MAXCONTEXT - 3); + test_assert_string_equal(buf, u"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefgh1"); + test_assert_equal(u16len(buf), MAXCONTEXT - 3); } void @@ -222,25 +222,25 @@ test_Delete() { context.Reset(); context.Delete(); context.Get((KMX_WCHAR *)&buf, bufsize); - assert_string_equal(buf, u""); + test_assert_string_equal(buf, u""); context.Reset(); context.Set(u"abc"); context.Delete(); context.Get((KMX_WCHAR *)&buf, bufsize); - assert_string_equal(buf, u"ab"); + test_assert_string_equal(buf, u"ab"); context.Reset(); context.Set(u"ab\U00010412"); context.Delete(); context.Get((KMX_WCHAR *)&buf, bufsize); - assert_string_equal(buf, u"ab"); + test_assert_string_equal(buf, u"ab"); context.Reset(); context.Set(u"ab\uFFFF\u0008\u0001"); context.Delete(); context.Get((KMX_WCHAR *)&buf, bufsize); - assert_string_equal(buf, u"ab"); + test_assert_string_equal(buf, u"ab"); } void @@ -251,81 +251,81 @@ test_Buf() { context.Set(u"abc"); auto last = context.Buf(0); auto p = context.Buf(1); - assert_equal(p, last - 1); + test_assert_equal(p, last - 1); p = context.Buf(2); - assert_equal(p, last - 2); + test_assert_equal(p, last - 2); p = context.Buf(3); - assert_equal(p, last - 3); + test_assert_equal(p, last - 3); p = context.Buf(4); - assert(p == NULL); + test_assert(p == NULL); p = context.Buf(10); - assert(p == NULL); + test_assert(p == NULL); p = context.Buf(-1); - assert_equal(p, last); + test_assert_equal(p, last); context.Reset(); context.Set(u"ab\U00010412"); last = context.Buf(0); p = context.Buf(1); - assert_equal(p, last - 2); + test_assert_equal(p, last - 2); p = context.Buf(2); - assert_equal(p, last - 3); + test_assert_equal(p, last - 3); p = context.Buf(3); - assert_equal(p, last - 4); + test_assert_equal(p, last - 4); p = context.Buf(4); - assert(p == NULL); + test_assert(p == NULL); p = context.Buf(5); - assert(p == NULL); + test_assert(p == NULL); p = context.Buf(10); - assert(p == NULL); + test_assert(p == NULL); context.Reset(); context.Set(u"ab\uFFFF\u0008\u0001"); last = context.Buf(0); p = context.Buf(1); - assert_equal(p, last - 3); + test_assert_equal(p, last - 3); p = context.Buf(2); - assert_equal(p, last - 4); + test_assert_equal(p, last - 4); p = context.Buf(3); - assert_equal(p, last - 5); + test_assert_equal(p, last - 5); p = context.Buf(4); - assert(p == NULL); + test_assert(p == NULL); p = context.Buf(5); - assert(p == NULL); + test_assert(p == NULL); p = context.Buf(6); - assert(p == NULL); + test_assert(p == NULL); context.Reset(); auto text = u"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk"; - assert_equal(u16len(text), MAXCONTEXT - 1); + test_assert_equal(u16len(text), MAXCONTEXT - 1); context.Set(text); last = context.Buf(0); p = context.Buf(1); - assert_equal(p, last - 1); + test_assert_equal(p, last - 1); p = context.Buf(MAXCONTEXT - 1); - assert_equal(p, last - (MAXCONTEXT - 1)); + test_assert_equal(p, last - (MAXCONTEXT - 1)); p = context.Buf(MAXCONTEXT); - assert(p == NULL); + test_assert(p == NULL); p = context.Buf(MAXCONTEXT + 1); - assert(p == NULL); + test_assert(p == NULL); } void @@ -336,97 +336,97 @@ test_BufMax() { context.Set(u"abc"); auto last = context.Buf(0); auto p = context.BufMax(0); - assert_equal(p, last); + test_assert_equal(p, last); p = context.BufMax(1); - assert_equal(p, last - 1); + test_assert_equal(p, last - 1); p = context.BufMax(2); - assert_equal(p, last - 2); + test_assert_equal(p, last - 2); p = context.BufMax(3); - assert_equal(p, last - 3); + test_assert_equal(p, last - 3); p = context.BufMax(4); - assert_equal(p, last - 3); + test_assert_equal(p, last - 3); p = context.BufMax(5); - assert_equal(p, last - 3); + test_assert_equal(p, last - 3); p = context.BufMax(10); - assert_equal(p, last - 3); + test_assert_equal(p, last - 3); p = context.BufMax(-1); - assert_equal(p, last); + test_assert_equal(p, last); context.Reset(); context.Set(u"ab\U00010412"); last = context.Buf(0); p = context.BufMax(0); - assert_equal(p, last); + test_assert_equal(p, last); p = context.BufMax(1); - assert_equal(p, last); + test_assert_equal(p, last); p = context.BufMax(2); - assert_equal(p, last - 2); + test_assert_equal(p, last - 2); p = context.BufMax(3); - assert_equal(p, last - 3); + test_assert_equal(p, last - 3); p = context.BufMax(4); - assert_equal(p, last - 4); + test_assert_equal(p, last - 4); p = context.BufMax(5); - assert_equal(p, last - 4); + test_assert_equal(p, last - 4); p = context.BufMax(10); - assert_equal(p, last - 4); + test_assert_equal(p, last - 4); context.Reset(); context.Set(u"ab\uFFFF\u0008\u0001"); last = context.Buf(0); p = context.BufMax(0); - assert_equal(p, last); + test_assert_equal(p, last); p = context.BufMax(1); - assert_equal(p, last); + test_assert_equal(p, last); p = context.BufMax(2); - assert_equal(p, last); + test_assert_equal(p, last); p = context.BufMax(3); - assert_equal(p, last - 3); + test_assert_equal(p, last - 3); p = context.BufMax(4); - assert_equal(p, last - 4); + test_assert_equal(p, last - 4); p = context.BufMax(5); - assert_equal(p, last - 5); + test_assert_equal(p, last - 5); p = context.BufMax(6); - assert_equal(p, last - 5); + test_assert_equal(p, last - 5); p = context.BufMax(10); - assert_equal(p, last - 5); + test_assert_equal(p, last - 5); context.Reset(); auto text = u"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk"; - assert_equal(u16len(text), MAXCONTEXT - 1); + test_assert_equal(u16len(text), MAXCONTEXT - 1); context.Set(text); last = context.Buf(0); p = context.BufMax(1); - assert_equal(p, last - 1); + test_assert_equal(p, last - 1); p = context.BufMax(MAXCONTEXT - 1); - assert_equal(p, last - (MAXCONTEXT - 1)); + test_assert_equal(p, last - (MAXCONTEXT - 1)); p = context.BufMax(MAXCONTEXT); - assert_equal(p, last - MAXCONTEXT + 1); + test_assert_equal(p, last - MAXCONTEXT + 1); p = context.BufMax(MAXCONTEXT + 1); - assert_equal(p, last - MAXCONTEXT + 1); + test_assert_equal(p, last - MAXCONTEXT + 1); } constexpr const auto help_str = "\ diff --git a/core/tests/unit/kmnkbd/kmx_xstring.tests.cpp b/core/tests/unit/kmnkbd/kmx_xstring.tests.cpp index 157a744ae72..529e2308103 100644 --- a/core/tests/unit/kmnkbd/kmx_xstring.tests.cpp +++ b/core/tests/unit/kmnkbd/kmx_xstring.tests.cpp @@ -48,32 +48,32 @@ void test_decxstr() { p_start = (PKMX_WCHAR) C_CODE_ANY(u"\u0002"); p = p_start + 2; // \u0002 in the middle of the otherwise valid UC_SENTINEL CODE_ANY sequence q = decxstr(p, p_start); - assert(q == p - 1); + test_assert(q == p - 1); p_start = (PKMX_WCHAR)u"abc" C_CODE_ANY(u"\u0001"); p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p-1)); + test_assert(q == (p-1)); p_start = (PKMX_WCHAR) C_CODE_ANY(u"\u0001"); p = p_start + 3; // nul, i.e. at the end of the valid UC_SENTINEL CODE_ANY sequence q = decxstr(p, p_start); - assert(q == p - 3); + test_assert(q == p - 3); p_start = (PKMX_WCHAR)u"abc" C_CODE_ANY(u"\u0001") u"\u0014"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p-3)); + test_assert(q == (p-3)); p_start = (PKMX_WCHAR)u"abc" C_CODE_ANY(u"\u0001") U_1F609_WINKING_FACE; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p-1)); + test_assert(q == (p-1)); p_start = (PKMX_WCHAR)u"abc" C_CODE_ANY(u"\u0001") U_1F609_WINKING_FACE; p = find_ptr_to_last_character(p_start)-1; q = decxstr(p, p_start); - assert(q == (p-3)); + test_assert(q == (p-3)); // ------------------------------------------------------------------------------------------------------------------------------------------------------- // even more tests: check for use UC_SENTINEL with F000 @@ -82,47 +82,47 @@ void test_decxstr() { p_start = (PKMX_WCHAR)u"abc" U_UC_SENTINEL u"\uF000"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p-1)); + test_assert(q == (p-1)); p_start = (PKMX_WCHAR)u"abc" U_UC_SENTINEL u"\uF000d"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 1)); + test_assert(q == (p - 1)); p_start = (PKMX_WCHAR)u"abc" U_UC_SENTINEL u"\uF000\u0001"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 1)); + test_assert(q == (p - 1)); p_start = (PKMX_WCHAR)u"abc" U_UC_SENTINEL u"\uF000\u0002"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 1)); + test_assert(q == (p - 1)); p_start = (PKMX_WCHAR)u"abc" U_UC_SENTINEL u"\uF000\u0001\u0001"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 1)); + test_assert(q == (p - 1)); p_start = (PKMX_WCHAR)u"abc" U_UC_SENTINEL u"\uF000\u0002\u0001"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 1)); + test_assert(q == (p - 1)); p_start = (PKMX_WCHAR)u"abc" U_UC_SENTINEL u"\uF000\u0001\u0001d"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 1)); + test_assert(q == (p - 1)); p_start = (PKMX_WCHAR)u"abc" U_UC_SENTINEL u"\uF000\u0002\u0001\u0001"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 1)); + test_assert(q == (p - 1)); p_start = (PKMX_WCHAR)u"abc" U_UC_SENTINEL u"\uF000\u0002\u0001\u0001d"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 1)); + test_assert(q == (p - 1)); // ------------------------------------------------------------------------------------------------------------------------------------------------------- // more tests: check if we might end up left of pstart @@ -131,96 +131,96 @@ void test_decxstr() { p_start = (PKMX_WCHAR)u"\u0001"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (NULL )); + test_assert(q == (NULL )); p_start = (PKMX_WCHAR)u"\u0001\u0001"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 1)); + test_assert(q == (p - 1)); p_start = (PKMX_WCHAR)u"\u0001\u0001\u0001"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 1)); + test_assert(q == (p - 1)); p_start = (PKMX_WCHAR) U_UC_SENTINEL U_CODE_ANY; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 1)); + test_assert(q == (p - 1)); // Note: this test puts the pointer into the middle of a valid `UC_SENTINEL CODE_ANY ` // so we should expect it to not be properly understood. p_start = (PKMX_WCHAR) C_CODE_ANY(u"\u0001"); p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 1)); + test_assert(q == (p - 1)); p_start = (PKMX_WCHAR) C_CODE_ANY(u"\u0001") u"\u0001"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 3)); + test_assert(q == (p - 3)); p_start = (PKMX_WCHAR)u"\u0014"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (NULL)); + test_assert(q == (NULL)); p_start = (PKMX_WCHAR)u"\u0014\u0014"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 1)); + test_assert(q == (p - 1)); p_start = (PKMX_WCHAR)u"\u0014\u0014\u0014"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 1)); + test_assert(q == (p - 1)); p_start = (PKMX_WCHAR)u"\u0014\u0014\u0014\u0014"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 1)); + test_assert(q == (p - 1)); p_start = (PKMX_WCHAR)u"\u0014\u0014\u0014\u0014\u0014"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 1)); + test_assert(q == (p - 1)); p_start = (PKMX_WCHAR)u"\u0014\u0014\u0014\u0014\u0014\u0014"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 1)); + test_assert(q == (p - 1)); p_start = (PKMX_WCHAR) U_UC_SENTINEL u"\u0014"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 1)); + test_assert(q == (p - 1)); // 0x14 = CODE_IFOPT which has 3 parameters, so this is an invalid, so // go back only one char p_start = (PKMX_WCHAR) U_UC_SENTINEL u"\u0014\u0014"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 1)); + test_assert(q == (p - 1)); p_start = (PKMX_WCHAR) U_UC_SENTINEL u"\u0014\u0014\u0014"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 1)); + test_assert(q == (p - 1)); p_start = (PKMX_WCHAR) C_CODE_IFOPT(u"\u0014", u"\u0014", u"\u0014"); p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 1)); + test_assert(q == (p - 1)); p_start = (PKMX_WCHAR) C_CODE_IFOPT(u"\u0014", u"\u0014", u"\u0014") u"\u0014"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 5)); + test_assert(q == (p - 5)); p_start = (PKMX_WCHAR) C_CODE_IFOPT(u"\u0014", u"\u0014", u"\u0014") u"\u0014\u0014"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 1)); + test_assert(q == (p - 1)); // ------------------------------------------------------------------------------------------------------------------------------------------------------- // -- differences in pointer movement for new decxstr ---------------------------------------------------------------------------------------------------- @@ -232,25 +232,25 @@ void test_decxstr() { p_start = (PKMX_WCHAR)u"abc" U_UC_SENTINEL U_CODE_EXTENDED u"\u0001" u"\u0001" u"d"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 4) ); + test_assert(q == (p - 4) ); //runs OK with NEW version of decxstr (with CODE_SWITCH pointer moves 2 ( 3 altogether) p_start = (PKMX_WCHAR)u"abc" C_CODE_SWITCH(u"\u0001") u"d"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 3) ); + test_assert(q == (p - 3) ); // runs OK with NEW version of decxstr (with CODE_CLEARCONTEXT pointer moves 0 ( 1 altogether) p_start = (PKMX_WCHAR)u"abc" C_CODE_CLEARCONTEXT() u"\u0001d"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 1) ); + test_assert(q == (p - 1) ); // runs OK with OLD version and NEW version of decxstr p_start = (PKMX_WCHAR)u"abc" C_CODE_CLEARCONTEXT() u"\u0001"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 2) ); + test_assert(q == (p - 2) ); // --------------------------------------------------------------------------------------- // ---- character @@ -260,7 +260,7 @@ void test_decxstr() { p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 1) ); + test_assert(q == (p - 1) ); // --------------------------------------------------------------------------------------- // ---- p <= pstart @@ -269,12 +269,12 @@ void test_decxstr() { p_start = (PKMX_WCHAR)u"abc"; p = find_ptr_to_last_character(p_start)-5; q = decxstr(p, p_start); - assert(q == (NULL) ); + test_assert(q == (NULL) ); p_start = (PKMX_WCHAR)u"a"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (NULL) ); + test_assert(q == (NULL) ); // --------------------------------------------------------------------------------------- // ---- p= UC_SENTINEL_EXTENDED @@ -283,22 +283,22 @@ void test_decxstr() { p_start = (PKMX_WCHAR)u"abc" C_CODE_EXTENDED(u"\u0001" u"\u0002" u"\u0003" u"\u0004" U_CODE_EXTENDEDEND); p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 1) ); + test_assert(q == (p - 1) ); p_start = (PKMX_WCHAR)u"abc" C_CODE_EXTENDED(u"\u0001" u"\u0002" u"\u0003" u"\u0004" u"\u0005" u"\u0006" u"\u0007" u"\u0008" U_CODE_EXTENDEDEND); p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 1) ); + test_assert(q == (p - 1) ); p_start = (PKMX_WCHAR)u"abc" C_CODE_EXTENDED(u"\u0001" u"\u0002" u"\u0003" u"\u0004" u"\u0005" U_CODE_EXTENDEDEND) u"d"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 8) ); + test_assert(q == (p - 8) ); p_start = (PKMX_WCHAR)u"abc" C_CODE_EXTENDED(u"\u0001" u"\u0002" u"\u0003" u"\u0004" u"\u0005" u"\u0006" u"\u0007" u"\u0008" U_CODE_EXTENDEDEND) u"d"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 11) ); + test_assert(q == (p - 11) ); // --------------------------------------------------------------------------------------- // ---- Surrogate Pair @@ -307,32 +307,32 @@ void test_decxstr() { p_start = (PKMX_WCHAR)u"abc" U_1F609_WINKING_FACE; p = find_ptr_to_last_character(p_start)-1; q = decxstr(p, p_start); - assert(q == (p - 1) ); + test_assert(q == (p - 1) ); p_start = (PKMX_WCHAR)u"abc" U_1F609_WINKING_FACE; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 1) ); + test_assert(q == (p - 1) ); p_start = (PKMX_WCHAR)u"abc" U_1F609_WINKING_FACE u"d"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 2) ); + test_assert(q == (p - 2) ); p_start = (PKMX_WCHAR)u"abc" U_UC_SENTINEL U_1F609_WINKING_FACE; p = find_ptr_to_last_character(p_start)-1; q = decxstr(p, p_start); - assert(q == (p-1)); + test_assert(q == (p-1)); p_start = (PKMX_WCHAR)u"abc" U_UC_SENTINEL U_1F609_WINKING_FACE; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p-1)); + test_assert(q == (p-1)); p_start = (PKMX_WCHAR)u"abc" U_UC_SENTINEL U_1F609_WINKING_FACE u"d"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p-2)); + test_assert(q == (p-2)); // --------------------------------------------------------------------------------------- // ---- CODE_ // --------------------------------------------------------------------------------------- @@ -351,16 +351,16 @@ void test_decxstr() { p_start = (PKMX_WCHAR) str.c_str(); p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 1)); // this is in the middle of the sequence so it should always go back a single unit + test_assert(q == (p - 1)); // this is in the middle of the sequence so it should always go back a single unit str.append(u"a"); p_start = (PKMX_WCHAR)str.c_str(); p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); if (size < 0) { - assert(q == (p - 1)); // this is in the middle of the sequence so it should always go back a single unit + test_assert(q == (p - 1)); // this is in the middle of the sequence so it should always go back a single unit } else { - assert(q == (p - size - 2)); /* UC_SENTINEL + code + (CODE__SIZE = number of params) */ + test_assert(q == (p - size - 2)); /* UC_SENTINEL + code + (CODE__SIZE = number of params) */ } } @@ -371,87 +371,87 @@ void test_decxstr() { p_start = (PKMX_WCHAR)u"abc" C_CODE_ANY(u"\u0001") u"d"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 3) ); + test_assert(q == (p - 3) ); p_start = (PKMX_WCHAR)u"abc" C_CODE_INDEX(u"\u0001", u"\u0001d"); p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 4) ); + test_assert(q == (p - 4) ); p_start = (PKMX_WCHAR)u"abc" C_CODE_CONTEXT() u"\u0001d"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 1) ); + test_assert(q == (p - 1) ); p_start = (PKMX_WCHAR)u"abc" C_CODE_NUL() u"\u0001d"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 1) ); + test_assert(q == (p - 1) ); p_start = (PKMX_WCHAR)u"abc" C_CODE_USE(u"\u0001") u"d"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 3) ); + test_assert(q == (p - 3) ); p_start = (PKMX_WCHAR)u"abc" C_CODE_RETURN() u"\u0001d"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 1) ); + test_assert(q == (p - 1) ); p_start = (PKMX_WCHAR)u"abc" C_CODE_BEEP() u"\u0001d"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 1) ); + test_assert(q == (p - 1) ); p_start = (PKMX_WCHAR)u"abc" C_CODE_DEADKEY(u"\u0001") u"d"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 3) ); + test_assert(q == (p - 3) ); p_start = (PKMX_WCHAR)u"abc" C_CODE_CALL(u"\u0001") u"d"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 3) ); + test_assert(q == (p - 3) ); p_start = (PKMX_WCHAR)u"abc" C_CODE_CONTEXTEX(u"\u0001") u"d"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 3) ); + test_assert(q == (p - 3) ); p_start = (PKMX_WCHAR)u"abc" C_CODE_NOTANY(u"\u0001") u"d"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 3) ); + test_assert(q == (p - 3) ); p_start = (PKMX_WCHAR)u"abc" C_CODE_SETOPT(u"\u0001", u"\u0001") u"d"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 4) ); + test_assert(q == (p - 4) ); p_start = (PKMX_WCHAR)u"abc" C_CODE_IFOPT(u"\u0001", u"\u0001", u"\u0001") u"d"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 5) ); + test_assert(q == (p - 5) ); p_start = (PKMX_WCHAR)u"abc" C_CODE_SAVEOPT(u"\u0001") u"d"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 3) ); + test_assert(q == (p - 3) ); p_start = (PKMX_WCHAR)u"abc" C_CODE_RESETOPT(u"\u0001") u"d"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 3) ); + test_assert(q == (p - 3) ); p_start = (PKMX_WCHAR)u"abc" C_CODE_IFSYSTEMSTORE(u"\u0001", u"\u0001", u"\u0001") u"d"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 5) ); + test_assert(q == (p - 5) ); p_start = (PKMX_WCHAR)u"abc" C_CODE_SETSYSTEMSTORE(u"\u0001", u"\u0001") u"d"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 4) ); + test_assert(q == (p - 4) ); // --------------------------------------------------------------------------------------- // ---- other @@ -460,38 +460,38 @@ void test_decxstr() { p_start = (PKMX_WCHAR)u"abc" C_CODE_INDEX(u"d", u"e") u"f\u0001"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 1) ); + test_assert(q == (p - 1) ); p_start = (PKMX_WCHAR)u"abc" U_UC_SENTINEL; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 1) ); + test_assert(q == (p - 1) ); // pointer in the middle of a surrogate pair, so beware! p_start = (PKMX_WCHAR) U_UC_SENTINEL U_1F609_WINKING_FACE; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 1) ); + test_assert(q == (p - 1) ); p_start = (PKMX_WCHAR)u"\u0014d"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 1) ); + test_assert(q == (p - 1) ); p_start = (PKMX_WCHAR) U_UC_SENTINEL; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == NULL ); + test_assert(q == NULL ); p_start = (PKMX_WCHAR) U_UC_SENTINEL u"d"; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == (p - 1) ); + test_assert(q == (p - 1) ); p_start = (PKMX_WCHAR) U_UC_SENTINEL U_UC_SENTINEL; p = find_ptr_to_last_character(p_start); q = decxstr(p, p_start); - assert(q == p - 1 ); + test_assert(q == p - 1 ); } @@ -508,27 +508,27 @@ void test_decxstr() { // --- Test for empty string ------------------------------------------------------------------------------------------------------------------------ p = (PKMX_WCHAR) u"\0"; q = incxstr(p); - assert(q == p); + test_assert(q == p); // --- Test for character --------------------------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) u"\u1234"; q = incxstr(p); - assert(q == p+1); + test_assert(q == p+1); // --- Test for surrogate pair ---------------------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p+2); + test_assert(q == p+2); // --- Test for one ----------------------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR)u"\u0012"; q = incxstr(p); - assert(q == p + 1); + test_assert(q == p + 1); // --- Test for FFFF only ------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) U_UC_SENTINEL; q = incxstr(p); - assert(q == p + 1); + test_assert(q == p + 1); // -------------------------------------------------------------------------------------------------------------------------------------------------- // ---- UC_SENTINEL WITHOUT \0 ---------------------------------------------------------------------------------------------------------------------- @@ -537,102 +537,102 @@ void test_decxstr() { // --- Test for FFFF +CODE_INDEX -------------------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_INDEX(u"\u0002", u"\u0001"); q = incxstr(p); - assert(q == p + 4); + test_assert(q == p + 4); // --- Test for FFFF +CODE_USE ---------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_USE(u"\u0001"); q = incxstr(p); - assert(q == p + 3); + test_assert(q == p + 3); // --- Test for FFFF +CODE_DEADKEY ------------------------------------------------------------------------------------------------------------------ p = (PKMX_WCHAR) C_CODE_DEADKEY(u"\u0001"); q = incxstr(p); - assert(q == p + 3); + test_assert(q == p + 3); // --- Test for FFFF CODE_EXTENDED -------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_EXTENDED(u"\u0001" u"\u0002" u"\u0003" u"\u0004" u"\u0005" u"\u0006" U_CODE_EXTENDEDEND); q = incxstr(p); - assert(q == p + 9); + test_assert(q == p + 9); // --- Test for FFFF +CODE_CLEARCONTEXT ------------------------------------------------------------------------------------------------------------ p = (PKMX_WCHAR) C_CODE_CLEARCONTEXT() u"\u0001"; q = incxstr(p); - assert(q == p + 2); + test_assert(q == p + 2); // --- Test for FFFF +CODE_CALL ---------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_CALL(u"\u0001"); q = incxstr(p); - assert(q == p + 3); + test_assert(q == p + 3); // --- Test for FFFF +CODE_CONTEXTEX --------------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_CONTEXTEX(u"\u0001"); q = incxstr(p); - assert(q == p + 3); + test_assert(q == p + 3); // --- Test for FFFF +CODE_IFOPT ------------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_IFOPT(u"\u0002", u"\u0002", u"\u0001"); q = incxstr(p); - assert(q == p + 5); + test_assert(q == p + 5); // --- Test for FFFF +CODE_IFSYSTEMSTORE ------------------------------------------------------------------------------------------ p = (PKMX_WCHAR) C_CODE_IFSYSTEMSTORE(u"\u0002", u"\u0002", u"\u0001"); q = incxstr(p); - assert(q == p + 5); + test_assert(q == p + 5); // --- Test for FFFF +CODE_SETOPT ---------------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_SETOPT(u"\u0002", u"\u0001"); q = incxstr(p); - assert(q == p + 4); + test_assert(q == p + 4); // --- Test for FFFF +CODE_SETSYSTEMRESTORE --------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_SETSYSTEMSTORE(u"\u0002", u"\u0001"); q = incxstr(p); - assert(q == p + 4); + test_assert(q == p + 4); // --- Test for FFFF +CODE_RESETOPT ----------------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_RESETOPT(u"\u0001"); q = incxstr(p); - assert(q == p + 3); + test_assert(q == p + 3); // --- Test for FFFF +CODE_SAVEOPT ----------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_SAVEOPT(u"\u0001"); q = incxstr(p); - assert(q == p + 3 ); + test_assert(q == p + 3 ); // --- Test for FFFF +default ---------------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_NUL(); q = incxstr(p); - assert(q == p + 2); + test_assert(q == p + 2); // --- Test for FFFF + CODE_ANY ----------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_ANY(u"\u0001"); q = incxstr(p); - assert(q == p + 3 ); + test_assert(q == p + 3 ); // --- Test for FFFF + CODE_CONTEXT ----------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_CONTEXT() u"\u0001"; q = incxstr(p); - assert(q == p + 2 ); + test_assert(q == p + 2 ); // --- Test for FFFF + CODE_RETURN ----------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_RETURN() u"\u0001"; q = incxstr(p); - assert(q == p + 2 ); + test_assert(q == p + 2 ); // --- Test for FFFF + CODE_BEEP ----------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_BEEP() u"\u0001"; q = incxstr(p); - assert(q == p + 2 ); + test_assert(q == p + 2 ); // --- Test for FFFF + CODE_SWITCH ----------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_SWITCH(u"\u0001"); q = incxstr(p); - assert(q == p + 3 ); + test_assert(q == p + 3 ); // --- Test for FFFF + NOTANY ----------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_NOTANY(u"\u0001"); q = incxstr(p); - assert(q == p + 3 ); + test_assert(q == p + 3 ); // -------------------------------------------------------------------------------------------------------------------------------------------------- // ---- UC_SENTINEL WITH \0 AT DIFFERENT POSITIONS -------------------------------------------------------------------------------------------------- @@ -641,52 +641,52 @@ void test_decxstr() { // --- Test for FFFF + control (earlier p+1) with \0 after first position --------------- unit test failed with old version of incxstr() ----- p = (PKMX_WCHAR) U_UC_SENTINEL u"\0\u0008\u0001"; q = incxstr(p); - assert(q == p+1); + test_assert(q == p+1); // --- Test for FFFF +control (earlier p+1) with \0 after second position --------- unit test failed with old version of incxstr() ----- p = (PKMX_WCHAR) C_CODE_DEADKEY(u"\0") u"\u0001"; q = incxstr(p); - assert(q == p+2); + test_assert(q == p+2); // --- Test for FFFF +control (earlier p+1) with \0 after third position ----- unit test failed with old version of incxstr() ----- p = (PKMX_WCHAR) C_CODE_DEADKEY(u"\u0001") u"\0"; q = incxstr(p); - assert(q == p+3) + test_assert(q == p+3) // --- Test for FFFF +control (earlier p+2) with \0 after fourth position ----- unit test failed with old version of incxstr() ---- p = (PKMX_WCHAR) C_CODE_INDEX(u"\u0001", u"\u0001") u"\0"; q = incxstr(p); - assert(q == p+4); + test_assert(q == p+4); // --- Test for FFFF +control (earlier p+3) with \0 after fifth position ----- unit test failed with old version of incxstr() --------- p = (PKMX_WCHAR) C_CODE_IFOPT(u"\u0001", u"\u0001", u"\u0001") u"\0"; q = incxstr(p); - assert(q == p+5); + test_assert(q == p+5); // --- Test for FFFF +control CODE_EXTENDED ----- (earlier p+n) with \0 after 6. position ----- unit test failed with old version of incxstr() ----- p = (PKMX_WCHAR) C_CODE_EXTENDED(u"\u0001" u"\u0002" u"\u0003" u"\u0004" u"\0" u"\u0005" u"\u0006" u"\u0007" U_CODE_EXTENDEDEND); q = incxstr(p); - assert(q == p + 6); + test_assert(q == p + 6); // --- Test for FFFF +control CODE_EXTENDED ----- (earlier p+n) with \0 after 7. position ----- unit test failed with old version of incxstr() p = (PKMX_WCHAR) C_CODE_EXTENDED(u"\u0001" u"\u0002" u"\u0003" u"\u0004" u"\u0005" u"\0" u"\u0006" u"\u0007" U_CODE_EXTENDEDEND); q = incxstr(p); - assert(q == p + 7); + test_assert(q == p + 7); // --- Test for FFFF +control CODE_EXTENDED ----- (earlier p+n) with \0 after 8. position ----- unit test failed with old version of incxstr() ---------- p = (PKMX_WCHAR) C_CODE_EXTENDED(u"\u0001" u"\u0002" u"\u0003" u"\u0004" u"\u0005" u"\u0006" u"\0" u"\u0007" U_CODE_EXTENDEDEND); q = incxstr(p); - assert(q == p + 8); + test_assert(q == p + 8); // --- Test for FFFF +control CODE_EXTENDED ----- (earlier p+n) with \0 after 9. position ----- unit test failed with old version of incxstr() --- p = (PKMX_WCHAR) C_CODE_EXTENDED(u"\u0001" u"\u0002" u"\u0003" u"\u0004" u"\u0005" u"\u0006" u"\u0007" u"\0" U_CODE_EXTENDEDEND); q = incxstr(p); - assert(q == p + 9); + test_assert(q == p + 9); // --- Test for FFFF +control CODE_EXTENDED ----- (earlier p+n) with \0 after 10. position ----- unit test failed with old version of incxstr() ----------- p = (PKMX_WCHAR) C_CODE_EXTENDED(u"\u0001" u"\u0002" u"\u0003" u"\u0004" u"\u0005" u"\u0006" u"\u0007" U_CODE_EXTENDEDEND) u"\0"; q = incxstr(p); - assert(q == p + 10); + test_assert(q == p + 10); // -------------------------------------------------------------------------------------------------------------------------------------------------- // ---- UC_SENTINEL, INCOMPLETE & UNUSUAL SEQUENCES-------------------------------------------------------------------------------------------------- @@ -695,22 +695,22 @@ void test_decxstr() { // --- Test for FFFF + \0 -------------------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) U_UC_SENTINEL u"\0"; q = incxstr(p); - assert(q == p + 1); + test_assert(q == p + 1); // --- Test for FFFF +one character ------------------------------------------------------------------------------------------------------------ p = (PKMX_WCHAR) U_UC_SENTINEL u"\u0062"; q = incxstr(p); - assert(q == p + 1); + test_assert(q == p + 1); // --- Test for FFFF +one ----------------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_NUL(); q = incxstr(p); - assert(q == p + 2); + test_assert(q == p + 2); // --- Test for FFFF + one + character ------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_NUL() u"\u0062"; q = incxstr(p); - assert(q == p + 2); + test_assert(q == p + 2); //------------------------------------------------------------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------------------------------------------------------------- @@ -725,31 +725,31 @@ void test_decxstr() { //--------------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) u"\0\u1234\u2468"; q = incxstr(p); - assert(q == p); + test_assert(q == p); // --- Test for character // --------------------------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR)u"\u1234\u1234\u2468"; q = incxstr(p); - assert(q == p + 1);; + test_assert(q == p + 1);; // --- Test for surrogate pair // ---------------------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) U_1F609_WINKING_FACE u"\u1234\u2468"; q = incxstr(p); - assert(q == p + 2); + test_assert(q == p + 2); // --- Test for one // ----------------------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR)u"\u0012\u1234\u2468"; q = incxstr(p); - assert(q == p + 1); + test_assert(q == p + 1); // --- Test for FFFF only // ------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) U_UC_SENTINEL u"\u1234\u2468"; q = incxstr(p); - assert(q == p + 1); + test_assert(q == p + 1); // -------------------------------------------------------------------------------------------------------------------------------------------------- // ---- UC_SENTINEL WITHOUT \0 @@ -760,115 +760,115 @@ void test_decxstr() { // -------------------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_INDEX(u"\u0002", u"\u0001") u"\u1234\u2468"; q = incxstr(p); - assert(q == p + 4); + test_assert(q == p + 4); // --- Test for FFFF +CODE_USE // ---------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_USE(u"\u0001") u"\u1234\u2468"; q = incxstr(p); - assert(q == p + 3); + test_assert(q == p + 3); // --- Test for FFFF +CODE_DEADKEY // ------------------------------------------------------------------------------------------------------------------ p = (PKMX_WCHAR) C_CODE_DEADKEY(u"\u0001") u"\u1234\u2468"; q = incxstr(p); - assert(q == p + 3); + test_assert(q == p + 3); // --- Test for FFFF CODE_EXTENDED // -------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_EXTENDED(u"\u0001" u"\u0002" u"\u0003" u"\u0004" u"\u0005" u"\u0006" U_CODE_EXTENDEDEND) u"\u1234\u2468"; q = incxstr(p); - assert(q == p + 9); + test_assert(q == p + 9); // --- Test for FFFF +CODE_CLEARCONTEXT // ------------------------------------------------------------------------------------------------------------ p = (PKMX_WCHAR) C_CODE_CLEARCONTEXT() u"\u0001\u1234\u2468"; q = incxstr(p); - assert(q == p + 2); + test_assert(q == p + 2); // --- Test for FFFF +CODE_CALL // ---------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_CALL(u"\u0001") u"\u1234\u2468"; q = incxstr(p); - assert(q == p + 3); + test_assert(q == p + 3); // --- Test for FFFF +CODE_CONTEXTEX // --------------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_CONTEXTEX(u"\u0001") u"\u1234\u2468"; q = incxstr(p); - assert(q == p + 3); + test_assert(q == p + 3); // --- Test for FFFF +CODE_IFOPT // ------------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_IFOPT(u"\u0002", u"\u0002", u"\u0001") u"\u1234\u2468"; q = incxstr(p); - assert(q == p + 5); + test_assert(q == p + 5); // --- Test for FFFF +CODE_IFSYSTEMSTORE // ------------------------------------------------------------------------------------------ p = (PKMX_WCHAR) C_CODE_IFSYSTEMSTORE(u"\u0002", u"\u0002", u"\u0001") u"\u1234\u2468"; q = incxstr(p); - assert(q == p + 5); + test_assert(q == p + 5); // --- Test for FFFF +CODE_SETOPT // ---------------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_SETOPT(u"\u0002", u"\u0001") u"\u1234\u2468"; q = incxstr(p); - assert(q == p + 4); + test_assert(q == p + 4); // --- Test for FFFF +CODE_SETSYSTEMRESTORE // --------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_SETSYSTEMSTORE(u"\u0002", u"\u0001") u"\u1234\u2468"; q = incxstr(p); - assert(q == p + 4); + test_assert(q == p + 4); // --- Test for FFFF +CODE_RESETOPT // ----------------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_RESETOPT(u"\u0001") u"\u1234\u2468"; q = incxstr(p); - assert(q == p + 3); + test_assert(q == p + 3); // --- Test for FFFF +CODE_SAVEOPT // ----------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_SAVEOPT(u"\u0001") u"\u1234\u2468"; q = incxstr(p); - assert(q == p + 3); + test_assert(q == p + 3); // --- Test for FFFF +default // ---------------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_NUL() u"\u1234\u2468"; q = incxstr(p); - assert(q == p + 2); + test_assert(q == p + 2); // --- Test for FFFF + CODE_ANY ----------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_ANY(u"\u0001") u"\u1234\u2468"; q = incxstr(p); - assert(q == p + 3 ); + test_assert(q == p + 3 ); // --- Test for FFFF + CODE_CONTEXT ----------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_CONTEXT() u"\u0001\u1234\u2468"; q = incxstr(p); - assert(q == p + 2 ); + test_assert(q == p + 2 ); // --- Test for FFFF + CODE_RETURN ----------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_RETURN() u"\u0001\u1234\u2468"; q = incxstr(p); - assert(q == p + 2 ); + test_assert(q == p + 2 ); // --- Test for FFFF + CODE_BEEP ----------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_BEEP() u"\u0001\u1234\u2468"; q = incxstr(p); - assert(q == p + 2 ); + test_assert(q == p + 2 ); // --- Test for FFFF + CODE_SWITCH ----------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_SWITCH(u"\u0001") u"\u1234\u2468"; q = incxstr(p); - assert(q == p + 3 ); + test_assert(q == p + 3 ); // --- Test for FFFF + NOTANY ----------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_NOTANY(u"\u0001") u"\u1234\u2468"; q = incxstr(p); - assert(q == p + 3 ); + test_assert(q == p + 3 ); // -------------------------------------------------------------------------------------------------------------------------------------------------- // ---- UC_SENTINEL WITH \0 AT DIFFERENT POSITIONS @@ -879,61 +879,61 @@ void test_decxstr() { // incxstr() ----- p = (PKMX_WCHAR) U_UC_SENTINEL u"\0\u0008\u0001\u1234\u2468"; q = incxstr(p); - assert(q == p + 1); + test_assert(q == p + 1); // --- Test for FFFF +control (earlier p+1) with \0 after second position --------- unit test failed with old version of // incxstr() ----- p = (PKMX_WCHAR) C_CODE_DEADKEY(u"\0") u"\u0001\u1234\u2468"; q = incxstr(p); - assert(q == p + 2); + test_assert(q == p + 2); // --- Test for FFFF +control (earlier p+1) with \0 after third position ----- unit test failed with old version of incxstr() // ----- p = (PKMX_WCHAR) C_CODE_DEADKEY(u"\u0001") u"\0\u1234\u2468"; q = incxstr(p); - assert(q == p + 3) + test_assert(q == p + 3) // --- Test for FFFF +control (earlier p+2) with \0 after fourth position ----- unit test failed with old version of // incxstr() ---- p = (PKMX_WCHAR) C_CODE_INDEX(u"\u0001", u"\u0001") u"\0\u1234\u2468"; q = incxstr(p); - assert(q == p + 4); + test_assert(q == p + 4); // --- Test for FFFF +control (earlier p+3) with \0 after fifth position ----- unit test failed with old version of incxstr() // --------- p = (PKMX_WCHAR) C_CODE_IFOPT(u"\u0001", u"\u0001", u"\u0001") u"\0\u1234\u2468"; q = incxstr(p); - assert(q == p + 5); + test_assert(q == p + 5); // --- Test for FFFF +control CODE_EXTENDED ----- (earlier p+n) with \0 after 6. position ----- unit test failed with old // version of incxstr() ----- p = (PKMX_WCHAR) C_CODE_EXTENDED(u"\u0001" u"\u0002" u"\u0003" u"\u0004" u"\0" u"\u0005" u"\u0006" u"\u0007" U_CODE_EXTENDEDEND) u"\u1234\u2468"; q = incxstr(p); - assert(q == p + 6); + test_assert(q == p + 6); // --- Test for FFFF +control CODE_EXTENDED ----- (earlier p+n) with \0 after 7. position ----- unit test failed with old // version of incxstr() p = (PKMX_WCHAR) C_CODE_EXTENDED(u"\u0001" u"\u0002" u"\u0003" u"\u0004" u"\u0005" u"\0" u"\u0006" u"\u0007" U_CODE_EXTENDEDEND) u"\u1234\u2468"; q = incxstr(p); - assert(q == p + 7); + test_assert(q == p + 7); // --- Test for FFFF +control CODE_EXTENDED ----- (earlier p+n) with \0 after 8. position ----- unit test failed with old // version of incxstr() ---------- p = (PKMX_WCHAR) C_CODE_EXTENDED(u"\u0001" u"\u0002" u"\u0003" u"\u0004" u"\u0005" u"\u0006" u"\0" u"\u0007" U_CODE_EXTENDEDEND) u"\u1234\u2468"; q = incxstr(p); - assert(q == p + 8); + test_assert(q == p + 8); // --- Test for FFFF +control CODE_EXTENDED ----- (earlier p+n) with \0 after 9. position ----- unit test failed with old // version of incxstr() --- p = (PKMX_WCHAR) C_CODE_EXTENDED(u"\u0001" u"\u0002" u"\u0003" u"\u0004" u"\u0005" u"\u0006" u"\u0007" u"\0" U_CODE_EXTENDEDEND) u"\u1234\u2468"; q = incxstr(p); - assert(q == p + 9); + test_assert(q == p + 9); // --- Test for FFFF +control CODE_EXTENDED ----- (earlier p+n) with \0 after 10. position ----- unit test failed with old // version of incxstr() ----------- p = (PKMX_WCHAR) C_CODE_EXTENDED(u"\u0001" u"\u0002" u"\u0003" u"\u0004" u"\u0005" u"\u0006" u"\u0007" U_CODE_EXTENDEDEND) u"\0\u1234\u2468"; q = incxstr(p); - assert(q == p + 10); + test_assert(q == p + 10); // -------------------------------------------------------------------------------------------------------------------------------------------------- // ---- UC_SENTINEL, INCOMPLETE & UNUSUAL SEQUENCES-------------------------------------------------------------------------------------------------- @@ -943,25 +943,25 @@ void test_decxstr() { // -------------------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) U_UC_SENTINEL u"\0\u1234\u2468"; q = incxstr(p); - assert(q == p + 1); + test_assert(q == p + 1); // --- Test for FFFF +one character // ------------------------------------------------------------------------------------------------------------ p = (PKMX_WCHAR) U_UC_SENTINEL u"\u0062\u1234\u2468"; q = incxstr(p); - assert(q == p + 1); + test_assert(q == p + 1); // --- Test for FFFF +one // ----------------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_NUL() u"\u1234\u2468"; q = incxstr(p); - assert(q == p + 2); + test_assert(q == p + 2); // --- Test for FFFF + one + character // ------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_NUL() u"\u0062\u1234\u2468"; q = incxstr(p); - assert(q == p + 2); + test_assert(q == p + 2); //------------------------------------------------------------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------------------------------------------------------------- @@ -976,31 +976,31 @@ void test_decxstr() { //------------------------------------------------------------------------------------------------------------------------ p = (PKMX_WCHAR)u"\0" U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p); + test_assert(q == p); // --- Test for character // --------------------------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR)u"\u1234" U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p + 1); + test_assert(q == p + 1); // --- Test for surrogate pair // ---------------------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) U_1F609_WINKING_FACE U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p + 2); + test_assert(q == p + 2); // --- Test for one // ----------------------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR)u"\u0012" U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p + 1); + test_assert(q == p + 1); // --- Test for FFFF only // ------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) U_UC_SENTINEL U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p + 1); + test_assert(q == p + 1); // -------------------------------------------------------------------------------------------------------------------------------------------------- // ---- UC_SENTINEL WITHOUT \0 @@ -1011,115 +1011,115 @@ void test_decxstr() { // -------------------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_INDEX(u"\u0002", u"\u0001") U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p + 4); + test_assert(q == p + 4); // --- Test for FFFF +CODE_USE // ---------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_USE(u"\u0001") U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p + 3); + test_assert(q == p + 3); // --- Test for FFFF +CODE_DEADKEY // ------------------------------------------------------------------------------------------------------------------ p = (PKMX_WCHAR) C_CODE_DEADKEY(u"\u0001") U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p + 3); + test_assert(q == p + 3); // --- Test for FFFF CODE_EXTENDED // -------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_EXTENDED(u"\u0001" u"\u0002" u"\u0003" u"\u0004" u"\u0005" u"\u0006" U_CODE_EXTENDEDEND) U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p + 9); + test_assert(q == p + 9); // --- Test for FFFF +CODE_CLEARCONTEXT // ------------------------------------------------------------------------------------------------------------ p = (PKMX_WCHAR) C_CODE_CLEARCONTEXT() u"\u0001" U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p + 2); + test_assert(q == p + 2); // --- Test for FFFF +CODE_CALL // ---------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_CALL(u"\u0001") U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p + 3); + test_assert(q == p + 3); // --- Test for FFFF +CODE_CONTEXTEX // --------------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_CONTEXTEX(u"\u0001") U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p + 3); + test_assert(q == p + 3); // --- Test for FFFF +CODE_IFOPT // ------------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_IFOPT(u"\u0002", u"\u0002", u"\u0001") U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p + 5); + test_assert(q == p + 5); // --- Test for FFFF +CODE_IFSYSTEMSTORE // ------------------------------------------------------------------------------------------ p = (PKMX_WCHAR) C_CODE_IFSYSTEMSTORE(u"\u0002", u"\u0002", u"\u0001") U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p + 5); + test_assert(q == p + 5); // --- Test for FFFF +CODE_SETOPT // ---------------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_SETOPT(u"\u0002", u"\u0001") U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p + 4); + test_assert(q == p + 4); // --- Test for FFFF +CODE_SETSYSTEMRESTORE // --------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_SETSYSTEMSTORE(u"\u0002", u"\u0001") U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p + 4); + test_assert(q == p + 4); // --- Test for FFFF +CODE_RESETOPT // ----------------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_RESETOPT(u"\u0001") U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p + 3); + test_assert(q == p + 3); // --- Test for FFFF +CODE_SAVEOPT // ----------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_SAVEOPT(u"\u0001") U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p + 3); + test_assert(q == p + 3); // --- Test for FFFF +default // ---------------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_NUL() U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p + 2); + test_assert(q == p + 2); // --- Test for FFFF + CODE_ANY ----------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_ANY(u"\u0001") U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p + 3 ); + test_assert(q == p + 3 ); // --- Test for FFFF + CODE_CONTEXT ----------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_CONTEXT() u"\u0001" U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p + 2 ); + test_assert(q == p + 2 ); // --- Test for FFFF + CODE_RETURN ----------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_RETURN() u"\u0001" U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p + 2 ); + test_assert(q == p + 2 ); // --- Test for FFFF + CODE_BEEP ----------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_BEEP() u"\u0001" U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p + 2 ); + test_assert(q == p + 2 ); // --- Test for FFFF + CODE_SWITCH ----------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_SWITCH(u"\u0001") U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p + 3 ); + test_assert(q == p + 3 ); // --- Test for FFFF + NOTANY ----------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_NOTANY(u"\u0001") U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p + 3 ); + test_assert(q == p + 3 ); // -------------------------------------------------------------------------------------------------------------------------------------------------- // ---- UC_SENTINEL WITH \0 AT DIFFERENT POSITIONS @@ -1130,61 +1130,61 @@ void test_decxstr() { // with old version of incxstr() ----- p = (PKMX_WCHAR) U_UC_SENTINEL u"\0\u0008\u0001" U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p + 1); + test_assert(q == p + 1); // --- Test for FFFF +control (earlier p+1) with \0 after second position --------- unit test failed with // old version of incxstr() ----- p = (PKMX_WCHAR) C_CODE_DEADKEY(u"\0") u"\u0001" U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p + 2); + test_assert(q == p + 2); // --- Test for FFFF +control (earlier p+1) with \0 after third position ----- unit test failed with old // version of incxstr() ----- p = (PKMX_WCHAR) C_CODE_DEADKEY(u"\u0001") u"\0" U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p + 3) + test_assert(q == p + 3) // --- Test for FFFF +control (earlier p+2) with \0 after fourth position ----- unit test failed with // old version of incxstr() ---- p = (PKMX_WCHAR) C_CODE_INDEX(u"\u0001", u"\u0001") u"\0" U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p + 4); + test_assert(q == p + 4); // --- Test for FFFF +control (earlier p+3) with \0 after fifth position ----- unit test failed with old // version of incxstr() --------- p = (PKMX_WCHAR) C_CODE_IFOPT(u"\u0001", u"\u0001", u"\u0001") u"\0" U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p + 5); + test_assert(q == p + 5); // --- Test for FFFF +control CODE_EXTENDED ----- (earlier p+n) with \0 after 6. position ----- unit test // failed with old version of incxstr() ----- p = (PKMX_WCHAR) C_CODE_EXTENDED(u"\u0001" u"\u0002" u"\u0003" u"\u0004" u"\0" u"\u0005" u"\u0006" u"\u0007" U_CODE_EXTENDEDEND) U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p + 6); + test_assert(q == p + 6); // --- Test for FFFF +control CODE_EXTENDED ----- (earlier p+n) with \0 after 7. position ----- unit test // failed with old version of incxstr() p = (PKMX_WCHAR) C_CODE_EXTENDED(u"\u0001" u"\u0002" u"\u0003" u"\u0004" u"\u0005" u"\0" u"\u0006" u"\u0007" U_CODE_EXTENDEDEND) U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p + 7); + test_assert(q == p + 7); // --- Test for FFFF +control CODE_EXTENDED ----- (earlier p+n) with \0 after 8. position ----- unit test // failed with old version of incxstr() ---------- p = (PKMX_WCHAR) C_CODE_EXTENDED(u"\u0001" u"\u0002" u"\u0003" u"\u0004" u"\u0005" u"\u0006" u"\0" u"\u0007" U_CODE_EXTENDEDEND) U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p + 8); + test_assert(q == p + 8); // --- Test for FFFF +control CODE_EXTENDED ----- (earlier p+n) with \0 after 9. position ----- unit test // failed with old version of incxstr() --- p = (PKMX_WCHAR) C_CODE_EXTENDED(u"\u0001" u"\u0002" u"\u0003" u"\u0004" u"\u0005" u"\u0006" u"\u0007" u"\0" U_CODE_EXTENDEDEND) U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p + 9); + test_assert(q == p + 9); // --- Test for FFFF +control CODE_EXTENDED ----- (earlier p+n) with \0 after 10. position ----- unit test // failed with old version of incxstr() ----------- p = (PKMX_WCHAR) C_CODE_EXTENDED(u"\u0001" u"\u0002" u"\u0003" u"\u0004" u"\u0005" u"\u0006" u"\u0007" U_CODE_EXTENDEDEND) u"\0" U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p + 10); + test_assert(q == p + 10); // -------------------------------------------------------------------------------------------------------------------------------------------------- // ---- UC_SENTINEL, INCOMPLETE & UNUSUAL SEQUENCES-------------------------------------------------------------------------------------------------- @@ -1194,46 +1194,46 @@ void test_decxstr() { // -------------------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) U_UC_SENTINEL u"\0" U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p + 1); + test_assert(q == p + 1); // --- Test for FFFF +one character // ------------------------------------------------------------------------------------------------------------ p = (PKMX_WCHAR) U_UC_SENTINEL u"\u0062" U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p + 1); + test_assert(q == p + 1); // --- Test for FFFF +one // ----------------------------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_NUL() U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p + 2); + test_assert(q == p + 2); // --- Test for FFFF + one + character // ------------------------------------------------------------------------------------------- p = (PKMX_WCHAR) C_CODE_NUL() u"\u0062" U_1F609_WINKING_FACE; q = incxstr(p); - assert(q == p + 2); + test_assert(q == p + 2); } void test_xstrlen() { - assert_equal(xstrlen((PKMX_WCHAR)u""), 0); - assert_equal(xstrlen((PKMX_WCHAR)u"1"), 1); - assert_equal(xstrlen((PKMX_WCHAR)u"1234567890"), 10); - assert_equal(xstrlen((PKMX_WCHAR) C_CODE_DEADKEY(u"\u0001") u"a"), 2); - assert_equal(xstrlen((PKMX_WCHAR) C_CODE_IFOPT(u"\u0001", u"\u0002", u"\u0003") u"a"), 2); - assert_equal(xstrlen((PKMX_WCHAR) C_CODE_IFSYSTEMSTORE(u"\u0001", u"\u0002", u"\u0003") u"a"), 2); - assert_equal(xstrlen((PKMX_WCHAR) U_1F609_WINKING_FACE u"a"), 2); + test_assert_equal(xstrlen((PKMX_WCHAR)u""), 0); + test_assert_equal(xstrlen((PKMX_WCHAR)u"1"), 1); + test_assert_equal(xstrlen((PKMX_WCHAR)u"1234567890"), 10); + test_assert_equal(xstrlen((PKMX_WCHAR) C_CODE_DEADKEY(u"\u0001") u"a"), 2); + test_assert_equal(xstrlen((PKMX_WCHAR) C_CODE_IFOPT(u"\u0001", u"\u0002", u"\u0003") u"a"), 2); + test_assert_equal(xstrlen((PKMX_WCHAR) C_CODE_IFSYSTEMSTORE(u"\u0001", u"\u0002", u"\u0003") u"a"), 2); + test_assert_equal(xstrlen((PKMX_WCHAR) U_1F609_WINKING_FACE u"a"), 2); } void test_xstrlen_ignoreifopt() { - assert_equal(xstrlen_ignoreifopt((PKMX_WCHAR)u""), 0); - assert_equal(xstrlen_ignoreifopt((PKMX_WCHAR)u"1"), 1); - assert_equal(xstrlen_ignoreifopt((PKMX_WCHAR)u"1234567890"), 10); - assert_equal(xstrlen_ignoreifopt((PKMX_WCHAR) C_CODE_DEADKEY(u"\u0001") u"a"), 2); - assert_equal(xstrlen_ignoreifopt((PKMX_WCHAR) C_CODE_IFOPT(u"\u0001", u"\u0002", u"\u0003") u"a"), 1); - assert_equal(xstrlen_ignoreifopt((PKMX_WCHAR) C_CODE_IFSYSTEMSTORE(u"\u0001", u"\u0002", u"\u0003") u"a"), 1); - assert_equal(xstrlen_ignoreifopt((PKMX_WCHAR) U_1F609_WINKING_FACE u"a"), 2); + test_assert_equal(xstrlen_ignoreifopt((PKMX_WCHAR)u""), 0); + test_assert_equal(xstrlen_ignoreifopt((PKMX_WCHAR)u"1"), 1); + test_assert_equal(xstrlen_ignoreifopt((PKMX_WCHAR)u"1234567890"), 10); + test_assert_equal(xstrlen_ignoreifopt((PKMX_WCHAR) C_CODE_DEADKEY(u"\u0001") u"a"), 2); + test_assert_equal(xstrlen_ignoreifopt((PKMX_WCHAR) C_CODE_IFOPT(u"\u0001", u"\u0002", u"\u0003") u"a"), 1); + test_assert_equal(xstrlen_ignoreifopt((PKMX_WCHAR) C_CODE_IFSYSTEMSTORE(u"\u0001", u"\u0002", u"\u0003") u"a"), 1); + test_assert_equal(xstrlen_ignoreifopt((PKMX_WCHAR) U_1F609_WINKING_FACE u"a"), 2); } void @@ -1241,32 +1241,32 @@ test_utf32() { std::cout << "== " << __FUNCTION__ << std::endl; const KMX_DWORD u295 = 0x0127; // ħ - assert(Uni_IsBMP(u295)); + test_assert(Uni_IsBMP(u295)); const char16_t hmaqtugha = Uni_UTF32BMPToUTF16(u295); - assert(hmaqtugha == 0x0127); + test_assert(hmaqtugha == 0x0127); char16_single c0; int l0 = Utf32CharToUtf16(u295, c0); - assert(l0 == 1); - assert(c0.ch[0] == 0x0127); - assert(c0.ch[1] == 0); + test_assert(l0 == 1); + test_assert(c0.ch[0] == 0x0127); + test_assert(c0.ch[1] == 0); std::u16string s0 = std::u16string(c0.ch, l0); - assert(s0 == std::u16string(u"ħ")); - assert_equal(s0.at(0), 0x0127); + test_assert(s0 == std::u16string(u"ħ")); + test_assert_equal(s0.at(0), 0x0127); const KMX_DWORD scat = 0x0001F640; // 🙀 - assert(!Uni_IsBMP(scat)); + test_assert(!Uni_IsBMP(scat)); char16_single c1; int l1 = Utf32CharToUtf16(scat, c1); - assert(l1 == 2); - assert_equal(c1.ch[0], 0xD83D); - assert_equal(c1.ch[1], 0xDE40); - assert_equal(c1.ch[2], 0); + test_assert(l1 == 2); + test_assert_equal(c1.ch[0], 0xD83D); + test_assert_equal(c1.ch[1], 0xDE40); + test_assert_equal(c1.ch[2], 0); std::u16string s1 = std::u16string(c1.ch, l1); - assert_equal(s1.at(0), 0xD83D); - assert_equal(s1.at(1), 0xDE40); - assert(s1 == std::u16string(u"🙀")); + test_assert_equal(s1.at(0), 0xD83D); + test_assert_equal(s1.at(1), 0xDE40); + test_assert(s1 == std::u16string(u"🙀")); } void @@ -1275,23 +1275,23 @@ test_u16string_to_u32string() { // normal cases { const std::u32string str = u16string_to_u32string(u""); - assert_equal(str.length(), 0); + test_assert_equal(str.length(), 0); } { const std::u32string str = u16string_to_u32string(u"e"); - assert_equal(str.length(), 1); - assert_equal(str.at(0), 0x0065); + test_assert_equal(str.length(), 1); + test_assert_equal(str.at(0), 0x0065); } { const std::u32string str = u16string_to_u32string(u"🙀"); - assert_equal(str.length(), 1); - assert_equal(str.at(0), 0x0001F640); + test_assert_equal(str.length(), 1); + test_assert_equal(str.at(0), 0x0001F640); } { const std::u32string str = u16string_to_u32string(u"Ω🙀"); - assert_equal(str.length(), 2); - assert_equal(str.at(0), u'Ω'); - assert_equal(str.at(1), 0x0001F640); + test_assert_equal(str.length(), 2); + test_assert_equal(str.at(0), u'Ω'); + test_assert_equal(str.at(1), 0x0001F640); } // error cases @@ -1299,33 +1299,33 @@ test_u16string_to_u32string() { std::u16string half_cat; half_cat.push_back(0xD83D); // mismatched lead surrogate const std::u32string str = u16string_to_u32string(half_cat); - assert_equal(str.length(), 1); - assert_equal(str.at(0), 0xFFFD); + test_assert_equal(str.length(), 1); + test_assert_equal(str.at(0), 0xFFFD); } { std::u16string half_cat; half_cat.push_back(0xD83D); // mismatched lead surrogate half_cat.push_back(u'Ω'); // with following text const std::u32string str = u16string_to_u32string(half_cat); - assert_equal(str.length(), 2); - assert_equal(str.at(0), 0xFFFD); - assert_equal(str.at(1), u'Ω'); + test_assert_equal(str.length(), 2); + test_assert_equal(str.at(0), 0xFFFD); + test_assert_equal(str.at(1), u'Ω'); } { std::u16string half_cat; half_cat.push_back(0xDE40); // mismatched trail surrogate const std::u32string str = u16string_to_u32string(half_cat); - assert_equal(str.length(), 1); - assert_equal(str.at(0), 0xFFFD); + test_assert_equal(str.length(), 1); + test_assert_equal(str.at(0), 0xFFFD); } { std::u16string no_cat; no_cat.push_back(0xDE40); no_cat.push_back(0xD83D); const std::u32string str = u16string_to_u32string(no_cat); - assert_equal(str.length(), 2); - assert_equal(str.at(0), 0xFFFD); - assert_equal(str.at(1), 0xFFFD); + test_assert_equal(str.length(), 2); + test_assert_equal(str.at(0), 0xFFFD); + test_assert_equal(str.at(1), 0xFFFD); } } @@ -1336,75 +1336,75 @@ test_u32string_to_u16string() { // normal cases { const auto str = u32string_to_u16string(U""); - assert_equal(str.length(), 0); + test_assert_equal(str.length(), 0); } { const auto str = u32string_to_u16string(U"e"); - assert_equal(str.length(), 1); - assert_equal(str.at(0), 0x0065); + test_assert_equal(str.length(), 1); + test_assert_equal(str.at(0), 0x0065); } { const auto str = u32string_to_u16string(U"🙀"); - assert_equal(str.length(), 2); - assert_equal(str.at(0), 0xD83D); - assert_equal(str.at(1), 0xDE40); + test_assert_equal(str.length(), 2); + test_assert_equal(str.at(0), 0xD83D); + test_assert_equal(str.at(1), 0xDE40); } { const auto str = u32string_to_u16string(U"Ω🙀"); - assert_equal(str.length(), 3); - assert_equal(str.at(0), u'Ω'); - assert_equal(str.at(1), 0xD83D); - assert_equal(str.at(2), 0xDE40); + test_assert_equal(str.length(), 3); + test_assert_equal(str.at(0), u'Ω'); + test_assert_equal(str.at(1), 0xD83D); + test_assert_equal(str.at(2), 0xDE40); } } void test_is_valid() { std::cout << "== " << __FUNCTION__ << std::endl; // valid - assert_equal(Uni_IsValid(0x0000), true); - assert_equal(Uni_IsValid(0x0127), true); - assert_equal(Uni_IsValid(U'🙀'), true); + test_assert_equal(Uni_IsValid(0x0000), true); + test_assert_equal(Uni_IsValid(0x0127), true); + test_assert_equal(Uni_IsValid(U'🙀'), true); // invalid - assert_equal(Uni_IsValid(0xDECAFBAD), false); // out of range - assert_equal(Uni_IsValid(0x566D4128), false); - assert_equal(Uni_IsValid(0xFFFF), false); // nonchar - assert_equal(Uni_IsValid(0xFFFE), false); // nonchar - assert_equal(Uni_IsValid(0x10FFFF), false); // nonchar - assert_equal(Uni_IsValid(0x10FFFE), false); // nonchar - assert_equal(Uni_IsValid(0x01FFFF), false); // nonchar - assert_equal(Uni_IsValid(0x01FFFE), false); // nonchar - assert_equal(Uni_IsValid(0x02FFFF), false); // nonchar - assert_equal(Uni_IsValid(0x02FFFE), false); // nonchar - assert_equal(Uni_IsValid(0xFDD1), false); // nonchar - assert_equal(Uni_IsValid(0xFDD0), false); // nonchar + test_assert_equal(Uni_IsValid(0xDECAFBAD), false); // out of range + test_assert_equal(Uni_IsValid(0x566D4128), false); + test_assert_equal(Uni_IsValid(0xFFFF), false); // nonchar + test_assert_equal(Uni_IsValid(0xFFFE), false); // nonchar + test_assert_equal(Uni_IsValid(0x10FFFF), false); // nonchar + test_assert_equal(Uni_IsValid(0x10FFFE), false); // nonchar + test_assert_equal(Uni_IsValid(0x01FFFF), false); // nonchar + test_assert_equal(Uni_IsValid(0x01FFFE), false); // nonchar + test_assert_equal(Uni_IsValid(0x02FFFF), false); // nonchar + test_assert_equal(Uni_IsValid(0x02FFFE), false); // nonchar + test_assert_equal(Uni_IsValid(0xFDD1), false); // nonchar + test_assert_equal(Uni_IsValid(0xFDD0), false); // nonchar // positive range test - assert_equal(Uni_IsValid(0x100000, 0x10FFFD), true); - assert_equal(Uni_IsValid(0x10, 0x20), true); - assert_equal(Uni_IsValid(0x100000, 0x10FFFD), true); + test_assert_equal(Uni_IsValid(0x100000, 0x10FFFD), true); + test_assert_equal(Uni_IsValid(0x10, 0x20), true); + test_assert_equal(Uni_IsValid(0x100000, 0x10FFFD), true); // all valid ranges in BMP - assert_equal(Uni_IsValid(0x0000, 0xD7FF), true); - assert_equal(Uni_IsValid(0xD800, 0xDFFF), false); - assert_equal(Uni_IsValid(0xE000, 0xFDCF), true); - assert_equal(Uni_IsValid(0xFDD0, 0xFDEF), false); - assert_equal(Uni_IsValid(0xFDF0, 0xFDFF), true); - assert_equal(Uni_IsValid(0xFDF0, 0xFFFD), true); + test_assert_equal(Uni_IsValid(0x0000, 0xD7FF), true); + test_assert_equal(Uni_IsValid(0xD800, 0xDFFF), false); + test_assert_equal(Uni_IsValid(0xE000, 0xFDCF), true); + test_assert_equal(Uni_IsValid(0xFDD0, 0xFDEF), false); + test_assert_equal(Uni_IsValid(0xFDF0, 0xFDFF), true); + test_assert_equal(Uni_IsValid(0xFDF0, 0xFFFD), true); // negative range test - assert_equal(Uni_IsValid(0, 0x10FFFF), false); // ends with nonchar - assert_equal(Uni_IsValid(0, 0x10FFFD), false); // contains lots o' nonchars - assert_equal(Uni_IsValid(0x20, 0x10), false); // swapped - assert_equal(Uni_IsValid(0xFDEF, 0xFDF0), false); // just outside range - assert_equal(Uni_IsValid(0x0000, 0x010000), false); // crosses noncharacter plane boundary and other stuff - assert_equal(Uni_IsValid(0x010000, 0x020000), false); // crosses noncharacter plane boundary - assert_equal(Uni_IsValid(0x0000, 0xFFFF), false); // crosses other BMP prohibited and plane boundary - assert_equal(Uni_IsValid(0x0000, 0xFFFD), false); // crosses other BMP prohibited - assert_equal(Uni_IsValid(0x0000, 0xE000), false); // crosses surrogate space - assert_equal(Uni_IsValid(0x0000, 0x20FFFF), false); // out of bounds - assert_equal(Uni_IsValid(0x10FFFD, 0x20FFFF), false); // out of bounds + test_assert_equal(Uni_IsValid(0, 0x10FFFF), false); // ends with nonchar + test_assert_equal(Uni_IsValid(0, 0x10FFFD), false); // contains lots o' nonchars + test_assert_equal(Uni_IsValid(0x20, 0x10), false); // swapped + test_assert_equal(Uni_IsValid(0xFDEF, 0xFDF0), false); // just outside range + test_assert_equal(Uni_IsValid(0x0000, 0x010000), false); // crosses noncharacter plane boundary and other stuff + test_assert_equal(Uni_IsValid(0x010000, 0x020000), false); // crosses noncharacter plane boundary + test_assert_equal(Uni_IsValid(0x0000, 0xFFFF), false); // crosses other BMP prohibited and plane boundary + test_assert_equal(Uni_IsValid(0x0000, 0xFFFD), false); // crosses other BMP prohibited + test_assert_equal(Uni_IsValid(0x0000, 0xE000), false); // crosses surrogate space + test_assert_equal(Uni_IsValid(0x0000, 0x20FFFF), false); // out of bounds + test_assert_equal(Uni_IsValid(0x10FFFD, 0x20FFFF), false); // out of bounds } diff --git a/core/tests/unit/kmnkbd/state_api.tests.cpp b/core/tests/unit/kmnkbd/state_api.tests.cpp index f13f03d536e..70dcce31335 100644 --- a/core/tests/unit/kmnkbd/state_api.tests.cpp +++ b/core/tests/unit/kmnkbd/state_api.tests.cpp @@ -156,23 +156,23 @@ int main(int argc, char * argv[]) try_status(km_core_process_event(test_state, KM_CORE_VKEY_S, KM_CORE_MODIFIER_SHIFT, 1, KM_CORE_EVENT_FLAG_DEFAULT)); - assert(action_items(test_state, {{KM_CORE_IT_CHAR, {0,}, {km_core_usv('S')}}, {KM_CORE_IT_END}})); + test_assert(action_items(test_state, {{KM_CORE_IT_CHAR, {0,}, {km_core_usv('S')}}, {KM_CORE_IT_END}})); try_status(km_core_process_event(test_state, KM_CORE_VKEY_I, KM_CORE_MODIFIER_SHIFT, 1, KM_CORE_EVENT_FLAG_DEFAULT)); - assert(action_items(test_state, {{KM_CORE_IT_CHAR, {0,}, {km_core_usv('I')}}, {KM_CORE_IT_END}})); + test_assert(action_items(test_state, {{KM_CORE_IT_CHAR, {0,}, {km_core_usv('I')}}, {KM_CORE_IT_END}})); try_status(km_core_process_event(test_state, KM_CORE_VKEY_L, 0, 1, KM_CORE_EVENT_FLAG_DEFAULT)); - assert(action_items(test_state, {{KM_CORE_IT_CHAR, {0,}, {km_core_usv('l')}}, {KM_CORE_IT_END}})); + test_assert(action_items(test_state, {{KM_CORE_IT_CHAR, {0,}, {km_core_usv('l')}}, {KM_CORE_IT_END}})); try_status(km_core_process_event(test_state, KM_CORE_VKEY_BKSP, 0, 1, KM_CORE_EVENT_FLAG_DEFAULT)); - assert(action_items(test_state, {{KM_CORE_IT_BACK, {0,}, {0}}, {KM_CORE_IT_END}})); + test_assert(action_items(test_state, {{KM_CORE_IT_BACK, {0,}, {0}}, {KM_CORE_IT_END}})); try_status(km_core_process_event(test_state, KM_CORE_VKEY_L, KM_CORE_MODIFIER_SHIFT, 1, KM_CORE_EVENT_FLAG_DEFAULT)); - assert(action_items(test_state, {{KM_CORE_IT_CHAR, {0,}, {km_core_usv('L')}}, {KM_CORE_IT_END}})); + test_assert(action_items(test_state, {{KM_CORE_IT_CHAR, {0,}, {km_core_usv('L')}}, {KM_CORE_IT_END}})); try_status(km_core_process_event(test_state, KM_CORE_VKEY_F2, 0, 1, KM_CORE_EVENT_FLAG_DEFAULT)); km_core_action_item action = {KM_CORE_IT_PERSIST_OPT, {0,}, }; action.option = &expected_persist_opt; - assert(action_items(test_state, {action, {KM_CORE_IT_END}})); + test_assert(action_items(test_state, {action, {KM_CORE_IT_END}})); // Test debug dump auto doc1 = get_json_doc(*test_state), diff --git a/core/tests/unit/kmnkbd/state_context_api.tests.cpp b/core/tests/unit/kmnkbd/state_context_api.tests.cpp index b7f4efbcc2a..34de27cd944 100644 --- a/core/tests/unit/kmnkbd/state_context_api.tests.cpp +++ b/core/tests/unit/kmnkbd/state_context_api.tests.cpp @@ -135,7 +135,7 @@ test_context_set_if_needed__identical_context() { km_core_cu const *new_app_context = u"This is a test"; setup("k_000___null_keyboard.kmx", cached_context, false); assert_equal_status(km_core_state_context_set_if_needed(test_state, new_app_context), KM_CORE_CONTEXT_STATUS_UNCHANGED); - assert(is_identical_context(cached_context)); + test_assert(is_identical_context(cached_context)); teardown(); } @@ -145,8 +145,8 @@ test_context_set_if_needed__different_context() { km_core_cu const *new_app_context = u"This is a test"; setup("k_000___null_keyboard.kmx", cached_context); assert_equal_status(km_core_state_context_set_if_needed(test_state, new_app_context), KM_CORE_CONTEXT_STATUS_UPDATED); - assert(!is_identical_context(cached_context)); - assert(is_identical_context(new_app_context)); + test_assert(!is_identical_context(cached_context)); + test_assert(is_identical_context(new_app_context)); teardown(); } @@ -157,8 +157,8 @@ test_context_set_if_needed__cached_context_cleared() { setup("k_000___null_keyboard.kmx", cached_context); km_core_state_context_clear(test_state); assert_equal_status(km_core_state_context_set_if_needed(test_state, new_app_context), KM_CORE_CONTEXT_STATUS_UPDATED); - assert(!is_identical_context(cached_context)); - assert(is_identical_context(new_app_context)); + test_assert(!is_identical_context(cached_context)); + test_assert(is_identical_context(new_app_context)); teardown(); } @@ -168,8 +168,8 @@ test_context_set_if_needed__application_context_empty() { km_core_cu const *new_app_context = u""; setup("k_000___null_keyboard.kmx", cached_context); assert_equal_status(km_core_state_context_set_if_needed(test_state, new_app_context), KM_CORE_CONTEXT_STATUS_UPDATED); - assert(!is_identical_context(cached_context)); - assert(is_identical_context(new_app_context)); + test_assert(!is_identical_context(cached_context)); + test_assert(is_identical_context(new_app_context)); teardown(); } @@ -179,8 +179,8 @@ test_context_set_if_needed__app_context_is_longer() { km_core_cu const *new_app_context = u"Longer This is a test"; setup("k_000___null_keyboard.kmx", cached_context); assert_equal_status(km_core_state_context_set_if_needed(test_state, new_app_context), KM_CORE_CONTEXT_STATUS_UPDATED); - assert(!is_identical_context(cached_context)); - assert(is_identical_context(new_app_context)); + test_assert(!is_identical_context(cached_context)); + test_assert(is_identical_context(new_app_context)); teardown(); } @@ -190,8 +190,8 @@ test_context_set_if_needed__app_context_is_shorter() { km_core_cu const *new_app_context = u"is a test"; setup("k_000___null_keyboard.kmx", cached_context); assert_equal_status(km_core_state_context_set_if_needed(test_state, new_app_context), KM_CORE_CONTEXT_STATUS_UPDATED); - assert(!is_identical_context(cached_context)); - assert(is_identical_context(new_app_context)); + test_assert(!is_identical_context(cached_context)); + test_assert(is_identical_context(new_app_context)); teardown(); } @@ -237,7 +237,7 @@ test_context_set_if_needed__cached_context_shorter_and_markers() { {KM_CORE_CT_MARKER, {0}, {3}}, {KM_CORE_CT_MARKER, {0}, {4}}, KM_CORE_CONTEXT_ITEM_END}; assert_identical_context_with_markers(km_core_state_context(test_state), expected_citems); assert_identical_context_without_markers(km_core_state_app_context(test_state), expected_citems); - assert(is_identical_context(new_app_context)); + test_assert(is_identical_context(new_app_context)); teardown(); } @@ -339,7 +339,7 @@ test_context_set_if_needed__surrogate_pairs_unchanged() { km_core_cu const *new_app_context = u"a\U00010100"; setup("k_000___null_keyboard.kmx", cached_context); assert_equal_status(km_core_state_context_set_if_needed(test_state, new_app_context), KM_CORE_CONTEXT_STATUS_UNCHANGED); - assert(is_identical_context(new_app_context)); + test_assert(is_identical_context(new_app_context)); teardown(); } @@ -349,7 +349,7 @@ test_context_set_if_needed__surrogate_pairs_app_context_longer() { km_core_cu const *new_app_context = u"xa\U00010100"; setup("k_000___null_keyboard.kmx", cached_context); assert_equal_status(km_core_state_context_set_if_needed(test_state, new_app_context), KM_CORE_CONTEXT_STATUS_UPDATED); - assert(is_identical_context(new_app_context)); + test_assert(is_identical_context(new_app_context)); teardown(); } @@ -359,7 +359,7 @@ test_context_set_if_needed__surrogate_pairs_cached_context_longer() { km_core_cu const *new_app_context = u"a\U00010100"; setup("k_000___null_keyboard.kmx", cached_context); assert_equal_status(km_core_state_context_set_if_needed(test_state, new_app_context), KM_CORE_CONTEXT_STATUS_UPDATED); - assert(is_identical_context(new_app_context)); + test_assert(is_identical_context(new_app_context)); teardown(); } @@ -476,8 +476,8 @@ test_context_clear() { km_core_cu const *cached_context = u"This is a test"; setup("k_000___null_keyboard.kmx", cached_context); try_status(km_core_state_context_clear(test_state)); - assert(!is_identical_context(cached_context)); - assert(is_identical_context(u"")); + test_assert(!is_identical_context(cached_context)); + test_assert(is_identical_context(u"")); teardown(); } @@ -488,7 +488,7 @@ void test_context_debug_empty() { setup("k_000___null_keyboard.kmx", cached_context); auto str = km_core_state_context_debug(test_state, KM_CORE_DEBUG_CONTEXT_CACHED); // std::cout << str << std::endl; - assert(std::u16string(str) == u"|| (len: 0) [ ]"); + test_assert(std::u16string(str) == u"|| (len: 0) [ ]"); km_core_cu_dispose(str); } @@ -513,7 +513,7 @@ void test_context_debug_various() { auto str = km_core_state_context_debug(test_state, KM_CORE_DEBUG_CONTEXT_CACHED); // std::cout << str << std::endl; - assert(std::u16string(str) == u"|123🤣| (len: 9) [ M(5) U+0031 M(1) U+0032 M(2) U+0033 M(3) M(4) U+1f923 ]"); + test_assert(std::u16string(str) == u"|123🤣| (len: 9) [ M(5) U+0031 M(1) U+0032 M(2) U+0033 M(3) M(4) U+1f923 ]"); km_core_cu_dispose(str); } diff --git a/core/tests/unit/kmx/kmx.cpp b/core/tests/unit/kmx/kmx.cpp index 6dc3d69d68d..9eac21494a1 100644 --- a/core/tests/unit/kmx/kmx.cpp +++ b/core/tests/unit/kmx/kmx.cpp @@ -71,7 +71,7 @@ apply_action( ) { switch (act.type) { case KM_CORE_IT_END: - assert(false); + test_assert(false); break; case KM_CORE_IT_ALERT: g_beep_found = true; @@ -110,11 +110,11 @@ apply_action( // in a table. Or, if Keyman has a cached context, then there may be // additional text in the text store that Keyman can't see. if (act.backspace.expected_type == KM_CORE_BT_MARKER) { - assert(!context.empty()); - assert(context.back().type == KM_CORE_CT_MARKER); + test_assert(!context.empty()); + test_assert(context.back().type == KM_CORE_CT_MARKER); context.pop_back(); } else if (text_store.length() > 0) { - assert(!context.empty() && !text_store.empty()); + test_assert(!context.empty() && !text_store.empty()); km_core_usv ch = text_store.back(); text_store.pop_back(); if (text_store.length() > 0 && Uni_IsSurrogate2(ch)) { @@ -126,10 +126,10 @@ apply_action( text_store.pop_back(); } } - assert(ch == act.backspace.expected_value); + test_assert(ch == act.backspace.expected_value); - assert(context.back().type == KM_CORE_CT_CHAR); - assert(context.back().character == ch); + test_assert(context.back().type == KM_CORE_CT_CHAR); + test_assert(context.back().character == ch); context.pop_back(); } break; @@ -164,7 +164,7 @@ apply_action( test_source.set_caps_lock_on(act.capsLock); break; default: - assert(false); // NOT SUPPORTED + test_assert(false); // NOT SUPPORTED break; } } @@ -255,15 +255,15 @@ run_test(const km::core::path &source, const km::core::path &compiled) { // not diverged auto ci = citems; for(auto test_ci = test_context.begin(); ci->type != KM_CORE_CT_END || test_ci != test_context.end(); ci++, test_ci++) { - assert(ci->type != KM_CORE_CT_END && test_ci != test_context.end()); // Verify that both lists are same length - assert(test_ci->type == ci->type && test_ci->marker == ci->marker); + test_assert(ci->type != KM_CORE_CT_END && test_ci != test_context.end()); // Verify that both lists are same length + test_assert(test_ci->type == ci->type && test_ci->marker == ci->marker); } km_core_context_items_dispose(citems); if ((!context_invalidated) && (text_store != core_context_str)) { std::cerr << "text store has unexpectedly diverged from core_context" << std::endl; std::cerr << "text store : " << string_to_hex(text_store) << " [" << text_store << "]" << std::endl; std::cerr << "core context: " << string_to_hex(core_context_str) << " [" << core_context_str << "]" << std::endl; - assert(false); + test_assert(false); } } @@ -282,8 +282,8 @@ run_test(const km::core::path &source, const km::core::path &compiled) { // not diverged auto ci = citems; for(auto test_ci = test_context.begin(); ci->type != KM_CORE_CT_END || test_ci != test_context.end(); ci++, test_ci++) { - assert(ci->type != KM_CORE_CT_END && test_ci != test_context.end()); // Verify that both lists are same length - assert(test_ci->type == ci->type && test_ci->marker == ci->marker); + test_assert(ci->type != KM_CORE_CT_END && test_ci != test_context.end()); // Verify that both lists are same length + test_assert(test_ci->type == ci->type && test_ci->marker == ci->marker); } km_core_context_items_dispose(citems); diff --git a/core/tests/unit/kmx/kmx_external_event.tests.cpp b/core/tests/unit/kmx/kmx_external_event.tests.cpp index a7ad4d750ab..15f2d284dfb 100644 --- a/core/tests/unit/kmx/kmx_external_event.tests.cpp +++ b/core/tests/unit/kmx/kmx_external_event.tests.cpp @@ -58,7 +58,7 @@ void test_external_event(const km::core::path &source_file){ try_status(km_core_event(test_state, event, nullptr)); // The action to turn capslock off must be in the actions list. - assert(action_items(test_state, {{KM_CORE_IT_CAPSLOCK, {0,}, {0}}, {KM_CORE_IT_END}})); + test_assert(action_items(test_state, {{KM_CORE_IT_CAPSLOCK, {0,}, {0}}, {KM_CORE_IT_END}})); km_core_state_dispose(test_state); km_core_keyboard_dispose(test_kb); diff --git a/core/tests/unit/kmx/kmx_imx.tests.cpp b/core/tests/unit/kmx/kmx_imx.tests.cpp index 698bbb8fe55..ab2bbb372b8 100644 --- a/core/tests/unit/kmx/kmx_imx.tests.cpp +++ b/core/tests/unit/kmx/kmx_imx.tests.cpp @@ -181,14 +181,14 @@ void test_imx_list(const km::core::path &source_file){ str.append(u":"); str.append(imx_rule_it->function_name); auto extracted_library_function = convert(str); - assert(extracted_library_function == expected_imx_map[imx_rule_it->imx_id] ); + test_assert(extracted_library_function == expected_imx_map[imx_rule_it->imx_id] ); g_extract_imx_map[imx_rule_it->imx_id] = extracted_library_function; ++x; } std::cout << " X Value is " << x << std::endl; - assert(x==4); + test_assert(x==4); km_core_keyboard_imx_list_dispose(kb_imx_list); km_core_state_dispose(test_state); @@ -223,13 +223,13 @@ void test_queue_actions (const km::core::path &source_keyboard) { // Key Press that doesn't trigger a call back try_status(km_core_process_event(test_state, KM_CORE_VKEY_S,KM_CORE_MODIFIER_SHIFT, 1, KM_CORE_EVENT_FLAG_DEFAULT)); - assert(action_items(test_state, {{KM_CORE_IT_CHAR, {0,}, {km_core_usv('S')}}, {KM_CORE_IT_END}})); + test_assert(action_items(test_state, {{KM_CORE_IT_CHAR, {0,}, {km_core_usv('S')}}, {KM_CORE_IT_END}})); try_status(km_core_process_event(test_state, KM_CORE_VKEY_BKSP, 0, 1, KM_CORE_EVENT_FLAG_DEFAULT)); - assert(action_items(test_state, {{KM_CORE_IT_CHAR, {0,}, {km_core_usv('X')}}, {KM_CORE_IT_ALERT, {0,}, {0}}, {KM_CORE_IT_END}})); + test_assert(action_items(test_state, {{KM_CORE_IT_CHAR, {0,}, {km_core_usv('X')}}, {KM_CORE_IT_ALERT, {0,}, {0}}, {KM_CORE_IT_END}})); try_status(km_core_process_event(test_state, KM_CORE_VKEY_ESC, 0, 1, KM_CORE_EVENT_FLAG_DEFAULT)); - assert(action_items(test_state, { {KM_CORE_IT_CHAR, {0,}, {km_core_usv('Y')}}, + test_assert(action_items(test_state, { {KM_CORE_IT_CHAR, {0,}, {km_core_usv('Y')}}, {KM_CORE_IT_MARKER, {0,}, {1}}, {KM_CORE_IT_CHAR, {0,}, {km_core_usv('A')}}, {KM_CORE_IT_END}})); @@ -239,10 +239,10 @@ void test_queue_actions (const km::core::path &source_keyboard) { km_core_action_item bksp_a = {KM_CORE_IT_BACK}; bksp_a.backspace.expected_type = KM_CORE_BT_CHAR; bksp_a.backspace.expected_value = 'A'; - assert(action_items(test_state, {bksp_a,{KM_CORE_IT_CHAR, {0,}, {km_core_usv('Z')}}, {KM_CORE_IT_END}})); + test_assert(action_items(test_state, {bksp_a,{KM_CORE_IT_CHAR, {0,}, {km_core_usv('Z')}}, {KM_CORE_IT_END}})); try_status(km_core_process_event(test_state, KM_CORE_VKEY_2, 0, 1, KM_CORE_EVENT_FLAG_DEFAULT)); - assert(action_items(test_state, {{KM_CORE_IT_INVALIDATE_CONTEXT, {0,}, {0}}, {KM_CORE_IT_END}})); + test_assert(action_items(test_state, {{KM_CORE_IT_INVALIDATE_CONTEXT, {0,}, {0}}, {KM_CORE_IT_END}})); km_core_state_imx_deregister_callback(test_state); km_core_keyboard_imx_list_dispose(kb_imx_list); diff --git a/core/tests/unit/kmx/kmx_key_list.tests.cpp b/core/tests/unit/kmx/kmx_key_list.tests.cpp index d4aa9b4e93f..7b811bd0b1a 100644 --- a/core/tests/unit/kmx/kmx_key_list.tests.cpp +++ b/core/tests/unit/kmx/kmx_key_list.tests.cpp @@ -77,14 +77,14 @@ void test_key_list(const km::core::path &source_file){ map_key_list[std::make_pair(key_rule_it->key, key_rule_it->modifier_flag)] = key_rule_it->modifier_flag; ++n; } - assert(n==7); + test_assert(n==7); std::map, uint32_t>::iterator it_expected; std::map, uint32_t>::iterator it_key_list = map_key_list.begin(); while (it_key_list != map_key_list.end()){ it_expected = kb_key_expected_key_list.find(it_key_list->first); - assert (it_expected != kb_key_expected_key_list.end()); + test_assert (it_expected != kb_key_expected_key_list.end()); it_key_list++; } diff --git a/core/tests/unit/ldml/context_normalization.tests.cpp b/core/tests/unit/ldml/context_normalization.tests.cpp index cda91cbf4df..ea9d635ab23 100644 --- a/core/tests/unit/ldml/context_normalization.tests.cpp +++ b/core/tests/unit/ldml/context_normalization.tests.cpp @@ -83,9 +83,9 @@ bool is_identical_context(km_core_cu const *cached_context, km_core_debug_contex void test_context_normalization_already_nfd() { km_core_cu const *app_context_nfd = u"A\u0300"; setup("k_001_tiny.kmx"); - assert(km_core_state_context_set_if_needed(test_state, app_context_nfd) == KM_CORE_CONTEXT_STATUS_UPDATED); - assert(is_identical_context(app_context_nfd, KM_CORE_DEBUG_CONTEXT_APP)); - assert(is_identical_context(app_context_nfd, KM_CORE_DEBUG_CONTEXT_CACHED)); + test_assert(km_core_state_context_set_if_needed(test_state, app_context_nfd) == KM_CORE_CONTEXT_STATUS_UPDATED); + test_assert(is_identical_context(app_context_nfd, KM_CORE_DEBUG_CONTEXT_APP)); + test_assert(is_identical_context(app_context_nfd, KM_CORE_DEBUG_CONTEXT_CACHED)); teardown(); } @@ -93,9 +93,9 @@ void test_context_normalization_basic() { km_core_cu const *application_context = u"This is a test À"; km_core_cu const *cached_context = u"This is a test A\u0300"; setup("k_001_tiny.kmx"); - assert(km_core_state_context_set_if_needed(test_state, application_context) == KM_CORE_CONTEXT_STATUS_UPDATED); - assert(is_identical_context(application_context, KM_CORE_DEBUG_CONTEXT_APP)); - assert(is_identical_context(cached_context, KM_CORE_DEBUG_CONTEXT_CACHED)); + test_assert(km_core_state_context_set_if_needed(test_state, application_context) == KM_CORE_CONTEXT_STATUS_UPDATED); + test_assert(is_identical_context(application_context, KM_CORE_DEBUG_CONTEXT_APP)); + test_assert(is_identical_context(cached_context, KM_CORE_DEBUG_CONTEXT_CACHED)); teardown(); } @@ -104,9 +104,9 @@ void test_context_normalization_hefty() { km_core_cu const *application_context = u"À" u"é̖" u"\u1e69" u"\u212b" u"\U000114BC"; km_core_cu const *cached_context = u"A\u0300" u"e\u0316\u0301" u"\u0073\u0323\u0307" u"\u0041\u030a" u"\U000114B9\U000114B0"; setup("k_001_tiny.kmx"); - assert(km_core_state_context_set_if_needed(test_state, application_context) == KM_CORE_CONTEXT_STATUS_UPDATED); - assert(is_identical_context(application_context, KM_CORE_DEBUG_CONTEXT_APP)); - assert(is_identical_context(cached_context, KM_CORE_DEBUG_CONTEXT_CACHED)); + test_assert(km_core_state_context_set_if_needed(test_state, application_context) == KM_CORE_CONTEXT_STATUS_UPDATED); + test_assert(is_identical_context(application_context, KM_CORE_DEBUG_CONTEXT_APP)); + test_assert(is_identical_context(cached_context, KM_CORE_DEBUG_CONTEXT_CACHED)); teardown(); } @@ -115,9 +115,9 @@ void test_context_normalization_invalid_unicode() { km_core_cu const application_context[] = { 0xDC01, 0x0020, 0x0020, 0xFFFF, 0x0000 }; km_core_cu const cached_context[] = { 0xDC01, 0x0020, 0x0020, 0xFFFF, 0x0000 }; setup("k_001_tiny.kmx"); - assert(km_core_state_context_set_if_needed(test_state, application_context) == KM_CORE_CONTEXT_STATUS_UPDATED); - assert(is_identical_context(application_context, KM_CORE_DEBUG_CONTEXT_APP)); - assert(is_identical_context(cached_context, KM_CORE_DEBUG_CONTEXT_CACHED)); + test_assert(km_core_state_context_set_if_needed(test_state, application_context) == KM_CORE_CONTEXT_STATUS_UPDATED); + test_assert(is_identical_context(application_context, KM_CORE_DEBUG_CONTEXT_APP)); + test_assert(is_identical_context(cached_context, KM_CORE_DEBUG_CONTEXT_CACHED)); teardown(); } @@ -126,9 +126,9 @@ void test_context_normalization_lone_trailing_surrogate() { km_core_cu const application_context[] = { 0xDC01, 0x0020, 0x0020, 0x0000 }; km_core_cu const cached_context[] = /* skipped*/ { 0x0020, 0x0020, 0x0000 }; setup("k_001_tiny.kmx"); - assert(km_core_state_context_set_if_needed(test_state, application_context) == KM_CORE_CONTEXT_STATUS_UPDATED); - assert(is_identical_context(application_context+1, KM_CORE_DEBUG_CONTEXT_APP)); // first code unit is skipped - assert(is_identical_context(cached_context, KM_CORE_DEBUG_CONTEXT_CACHED)); + test_assert(km_core_state_context_set_if_needed(test_state, application_context) == KM_CORE_CONTEXT_STATUS_UPDATED); + test_assert(is_identical_context(application_context+1, KM_CORE_DEBUG_CONTEXT_APP)); // first code unit is skipped + test_assert(is_identical_context(cached_context, KM_CORE_DEBUG_CONTEXT_CACHED)); teardown(); } diff --git a/core/tests/unit/ldml/core_ldml_min.tests.cpp b/core/tests/unit/ldml/core_ldml_min.tests.cpp index 72090263a61..fadd62a2a45 100644 --- a/core/tests/unit/ldml/core_ldml_min.tests.cpp +++ b/core/tests/unit/ldml/core_ldml_min.tests.cpp @@ -11,7 +11,7 @@ */ #include -#include +#include #include "keyman_core.h" #include "../load_kmx_file.hpp" @@ -27,15 +27,17 @@ int main(int argc, const char *argv[]) { status = km_core_keyboard_load_from_blob(nowhere, blob.data(), blob.size(), &test_kb); std::cerr << "null km_core_keyboard_load = " << status << std::endl; - assert(status == KM_CORE_STATUS_INVALID_ARGUMENT); - assert(test_kb == nullptr); + test_assert(status == KM_CORE_STATUS_INVALID_ARGUMENT); + test_assert(test_kb == nullptr); km_core_keyboard_dispose(test_kb); km_core_state_dispose(nullptr); km_core_cu_dispose(nullptr); status = km_core_process_event(nullptr, 0, 0, 0, 0); - /* NOTREACHED - assertion fails above. */ - assert(status == KM_CORE_STATUS_INVALID_ARGUMENT); + /* Note: an assertion fails in km_core_process_event on debug builds, + but we will fail on the line below on release builds (as assertions + are disabled); actual return value is KM_CORE_STATUS_INVALID_ARGUMENT */ + test_assert(status == KM_CORE_STATUS_OK); return 0; } diff --git a/core/tests/unit/ldml/kmx_plus.tests.cpp b/core/tests/unit/ldml/kmx_plus.tests.cpp index 5b14043b742..eed021664c0 100644 --- a/core/tests/unit/ldml/kmx_plus.tests.cpp +++ b/core/tests/unit/ldml/kmx_plus.tests.cpp @@ -34,27 +34,27 @@ int test_COMP_KMXPLUS_KEYS_KEY() { 0x00000000 // flags: CHAR }}; std::u16string s0 = e[0].get_to_string(); - assert_equal(s0.length(), 1); - assert_equal(s0.at(0), 0x0127); - assert(s0 == std::u16string(u"ħ")); + test_assert_equal(s0.length(), 1); + test_assert_equal(s0.at(0), 0x0127); + test_assert(s0 == std::u16string(u"ħ")); std::u16string s1 = e[1].get_to_string(); - assert_equal(s1.length(), 2); - assert_equal(s1.at(0), 0xD83D); - assert_equal(s1.at(1), 0xDE40); - assert(s1 == std::u16string(u"🙀")); + test_assert_equal(s1.length(), 2); + test_assert_equal(s1.at(0), 0xD83D); + test_assert_equal(s1.at(1), 0xDE40); + test_assert(s1 == std::u16string(u"🙀")); // now, elems. Parallel. std::u16string es0 = elems[0].get_element_string(); - assert_equal(es0.length(), 1); - assert_equal(es0.at(0), 0x0127); - assert(es0 == std::u16string(u"ħ")); + test_assert_equal(es0.length(), 1); + test_assert_equal(es0.at(0), 0x0127); + test_assert(es0 == std::u16string(u"ħ")); std::u16string es1 = elems[1].get_element_string(); - assert_equal(es1.length(), 2); - assert_equal(es1.at(0), 0xD83D); - assert_equal(es1.at(1), 0xDE40); - assert(es1 == std::u16string(u"🙀")); + test_assert_equal(es1.length(), 2); + test_assert_equal(es1.at(0), 0xD83D); + test_assert_equal(es1.at(1), 0xDE40); + test_assert(es1 == std::u16string(u"🙀")); return EXIT_SUCCESS; } @@ -89,67 +89,67 @@ int test_ldml_vkeys() { vk.add(km::tests::get_vk("K_F"), 0, u""); // K_F as a 'gap' key bool found = false; - assert_equal(vk.lookup(km::tests::get_vk( + test_assert_equal(vk.lookup(km::tests::get_vk( "K_F"), 0, found), u""); - assert_equal(found, true); // K_F found, but empty string (gap) - assert_equal(vk.lookup(km::tests::get_vk( + test_assert_equal(found, true); // K_F found, but empty string (gap) + test_assert_equal(vk.lookup(km::tests::get_vk( "K_ENTER"), 0, found), u""); - assert_equal(found, false); // K_ENTER not found, empty string - assert_equal(vk.lookup(km::tests::get_vk( + test_assert_equal(found, false); // K_ENTER not found, empty string + test_assert_equal(vk.lookup(km::tests::get_vk( "K_A"), 0, found), u"K_A-0"); - assert_equal(found, true); // expect - assert_equal(vk.lookup(km::tests::get_vk( + test_assert_equal(found, true); // expect + test_assert_equal(vk.lookup(km::tests::get_vk( "K_A"), LCTRLFLAG, found), u"K_A-LCTRLFLAG"); - assert_equal(vk.lookup(km::tests::get_vk( + test_assert_equal(vk.lookup(km::tests::get_vk( "K_A"), RCTRLFLAG, found), u"K_A-RCTRLFLAG"); - assert_equal(vk.lookup(km::tests::get_vk( + test_assert_equal(vk.lookup(km::tests::get_vk( "K_A"), LALTFLAG, found), u"K_A-LALTFLAG"); - assert_equal(vk.lookup(km::tests::get_vk( + test_assert_equal(vk.lookup(km::tests::get_vk( "K_A"), RALTFLAG, found), u"K_A-RALTFLAG"); // now try either-side keys :should get the same result with either or both - assert_equal(vk.lookup(km::tests::get_vk( + test_assert_equal(vk.lookup(km::tests::get_vk( "K_B"), LCTRLFLAG, found), u"K_B-K_CTRLFLAG"); - assert_equal(vk.lookup(km::tests::get_vk( + test_assert_equal(vk.lookup(km::tests::get_vk( "K_B"), RCTRLFLAG, found), u"K_B-K_CTRLFLAG"); - assert_equal(vk.lookup(km::tests::get_vk( + test_assert_equal(vk.lookup(km::tests::get_vk( "K_B"), LCTRLFLAG|RCTRLFLAG, found), u"K_B-K_CTRLFLAG"); - assert_equal(vk.lookup(km::tests::get_vk( + test_assert_equal(vk.lookup(km::tests::get_vk( "K_B"), LALTFLAG, found), u"K_B-K_ALTFLAG"); - assert_equal(vk.lookup(km::tests::get_vk( + test_assert_equal(vk.lookup(km::tests::get_vk( "K_B"), RALTFLAG, found), u"K_B-K_ALTFLAG"); - assert_equal(vk.lookup(km::tests::get_vk( + test_assert_equal(vk.lookup(km::tests::get_vk( "K_B"), LALTFLAG|RALTFLAG, found), u"K_B-K_ALTFLAG"); // OOOkay now try BOTH side - assert_equal(vk.lookup(km::tests::get_vk( + test_assert_equal(vk.lookup(km::tests::get_vk( "K_C"), LCTRLFLAG|LALTFLAG, found), u"K_C-K_ALTFLAG|K_CTRLFLAG"); - assert_equal(vk.lookup(km::tests::get_vk( + test_assert_equal(vk.lookup(km::tests::get_vk( "K_C"), LCTRLFLAG|RALTFLAG, found), u"K_C-K_ALTFLAG|K_CTRLFLAG"); - assert_equal(vk.lookup(km::tests::get_vk( + test_assert_equal(vk.lookup(km::tests::get_vk( "K_C"), RCTRLFLAG|LALTFLAG, found), u"K_C-K_ALTFLAG|K_CTRLFLAG"); - assert_equal(vk.lookup(km::tests::get_vk( + test_assert_equal(vk.lookup(km::tests::get_vk( "K_C"), RCTRLFLAG|RALTFLAG, found), u"K_C-K_ALTFLAG|K_CTRLFLAG"); // OOOkay now try either alt - assert_equal(vk.lookup(km::tests::get_vk( + test_assert_equal(vk.lookup(km::tests::get_vk( "K_D"), LCTRLFLAG|LALTFLAG, found), u"K_D-LALTFLAG|K_CTRLFLAG"); - assert_equal(vk.lookup(km::tests::get_vk( + test_assert_equal(vk.lookup(km::tests::get_vk( "K_D"), LCTRLFLAG|RALTFLAG, found), u"K_D-RALTFLAG|K_CTRLFLAG"); - assert_equal(vk.lookup(km::tests::get_vk( + test_assert_equal(vk.lookup(km::tests::get_vk( "K_D"), RCTRLFLAG|LALTFLAG, found), u"K_D-LALTFLAG|K_CTRLFLAG"); - assert_equal(vk.lookup(km::tests::get_vk( + test_assert_equal(vk.lookup(km::tests::get_vk( "K_D"), RCTRLFLAG|RALTFLAG, found), u"K_D-RALTFLAG|K_CTRLFLAG"); // OOOkay now try either ctrl - assert_equal(vk.lookup(km::tests::get_vk( + test_assert_equal(vk.lookup(km::tests::get_vk( "K_E"), LCTRLFLAG|LALTFLAG, found), u"K_E-K_ALTFLAG|LCTRLFLAG"); - assert_equal(vk.lookup(km::tests::get_vk( + test_assert_equal(vk.lookup(km::tests::get_vk( "K_E"), LCTRLFLAG|RALTFLAG, found), u"K_E-K_ALTFLAG|LCTRLFLAG"); - assert_equal(vk.lookup(km::tests::get_vk( + test_assert_equal(vk.lookup(km::tests::get_vk( "K_E"), RCTRLFLAG|LALTFLAG, found), u"K_E-K_ALTFLAG|RCTRLFLAG"); - assert_equal(vk.lookup(km::tests::get_vk( + test_assert_equal(vk.lookup(km::tests::get_vk( "K_E"), RCTRLFLAG|RALTFLAG, found), u"K_E-K_ALTFLAG|RCTRLFLAG"); return EXIT_SUCCESS; @@ -164,13 +164,13 @@ int test_uset() { }; SimpleUSet u0(&r[0], 2); - assert_equal(u0.contains(0x62), true); // b - assert_equal(u0.contains(0x41), false); // A - assert_equal(u0.contains(0x127), true); // ħ + test_assert_equal(u0.contains(0x62), true); // b + test_assert_equal(u0.contains(0x41), false); // A + test_assert_equal(u0.contains(0x127), true); // ħ SimpleUSet uempty; - assert_equal(uempty.contains(0x62), false); - assert_equal(uempty.contains(0x127), false); + test_assert_equal(uempty.contains(0x62), false); + test_assert_equal(uempty.contains(0x127), false); return EXIT_SUCCESS; } diff --git a/core/tests/unit/ldml/ldml.cpp b/core/tests/unit/ldml/ldml.cpp index 339b1f0dc19..78e0aacebac 100644 --- a/core/tests/unit/ldml/ldml.cpp +++ b/core/tests/unit/ldml/ldml.cpp @@ -83,7 +83,7 @@ apply_action( std::vector &test_context) { switch (act.type) { case KM_CORE_IT_END: - assert(false); + test_assert(false); break; case KM_CORE_IT_ALERT: g_beep_found = true; @@ -120,8 +120,8 @@ apply_action( km_core_usv ch = 0; bool matched_text = false; // assume the backspace came from set_action() and there's no further info. - assert(act.backspace.expected_type == KM_CORE_BT_CHAR); - assert(act.backspace.expected_value == 0); + test_assert(act.backspace.expected_type == KM_CORE_BT_CHAR); + test_assert(act.backspace.expected_value == 0); // It is valid for a backspace to be received with an empty text store // as the user can press backspace with no text in the store and Keyman // will pass that back to the client, as the client may do additional @@ -130,7 +130,7 @@ apply_action( // additional text in the text store that Keyman can't see. // If there's anything in the text store, pop it off. Two if a pair. if (text_store.length() > 0) { - assert(!context.empty() && !text_store.empty()); + test_assert(!context.empty() && !text_store.empty()); const auto ch1 = text_store.back(); text_store.pop_back(); if (text_store.length() > 0 && Uni_IsSurrogate2(ch1)) { @@ -153,16 +153,16 @@ apply_action( auto end = context.rbegin(); while (end != context.rend()) { if (end->type == KM_CORE_CT_CHAR) { - assert(!matched_text); - assert_equal(end->character, ch); // expect popped char to be same as what's in context + test_assert(!matched_text); + test_assert_equal(end->character, ch); // expect popped char to be same as what's in context matched_text = true; context.pop_back(); break; // exit on first real char } - assert(end->type != KM_CORE_CT_END); // inappropriate here. + test_assert(end->type != KM_CORE_CT_END); // inappropriate here. context.pop_back(); } - assert(matched_text); + test_assert(matched_text); } break; case KM_CORE_IT_PERSIST_OPT: @@ -175,7 +175,7 @@ apply_action( km_core_context_item* new_context_items = nullptr; // We replace the cached context with the current application context km_core_status status = context_items_from_utf16(text_store.c_str(), &new_context_items); - assert(status == KM_CORE_STATUS_OK); + test_assert(status == KM_CORE_STATUS_OK); copy_context_items_to_vector(new_context_items, context); // also update the test context copy_context_items_to_vector(new_context_items, test_context); @@ -193,7 +193,7 @@ apply_action( test_source.set_caps_lock_on(act.capsLock); break; default: - assert(false); // NOT SUPPORTED + test_assert(false); // NOT SUPPORTED break; } } @@ -254,16 +254,16 @@ verify_context(std::u16string &text_store, km_core_state *&test_state, std::vect break; // success } // fail if only ONE is at end - assert(ci->type != KM_CORE_CT_END && test_ci != test_context.end()); + test_assert(ci->type != KM_CORE_CT_END && test_ci != test_context.end()); // fail if type and marker don't match. - assert(test_ci->type == ci->type && test_ci->marker == ci->marker); + test_assert(test_ci->type == ci->type && test_ci->marker == ci->marker); } km_core_context_items_dispose(citems); if (text_store != buf) { std::cerr << "text store has diverged from buf" << std::endl; std::cerr << "text store: " << string_to_hex(text_store) << " [" << text_store << "]" << std::endl; - assert(false); + test_assert(false); } delete[] buf; } @@ -275,7 +275,7 @@ run_test(const km::core::path &source, const km::core::path &compiled, km::tests const km_core_status expect_load_status = test_source.get_expected_load_status(); auto blob = km::tests::load_kmx_file(compiled.native().c_str()); - assert_equal(km_core_keyboard_load_from_blob(compiled.stem().c_str(), blob.data(), blob.size(), &test_kb), expect_load_status); + test_assert_equal(km_core_keyboard_load_from_blob(compiled.stem().c_str(), blob.data(), blob.size(), &test_kb), expect_load_status); if (expect_load_status != KM_CORE_STATUS_OK) { std::cout << "Keyboard was expected to be invalid, so exiting " << std::endl; @@ -364,7 +364,7 @@ run_test(const km::core::path &source, const km::core::path &compiled, km::tests } break; case km::tests::LDML_ACTION_CHECK_EXPECTED: { if (!normalization_disabled) { - assert(km::core::util::normalize_nfd(action.string)); // TODO-LDML: should be NFC + test_assert(km::core::util::normalize_nfd(action.string)); // TODO-LDML: should be NFC } std::cout << "- check expected" << std::endl; std::cout << "expected : " << string_to_hex(action.string) << " [" << action.string << "]" << std::endl; @@ -453,7 +453,7 @@ int run_all_tests(const km::core::path &source, const km::core::path &compiled, const km::tests::JsonTestMap& json_tests = json_factory.get_tests(); size_t skip_count = 0; - assert(json_tests.size() > 0); + test_assert(json_tests.size() > 0); // Loop over all tests for (const auto& n : json_tests) { const auto test_name = n.first; diff --git a/core/tests/unit/ldml/ldml_test_source.cpp b/core/tests/unit/ldml/ldml_test_source.cpp index beabee6a6f2..94e10e7ac43 100644 --- a/core/tests/unit/ldml/ldml_test_source.cpp +++ b/core/tests/unit/ldml/ldml_test_source.cpp @@ -41,6 +41,8 @@ #include "unicode/usetiter.h" #include "../load_kmx_file.hpp" + +#include #include #define assert_or_return(expr) if(!(expr)) { \ @@ -161,20 +163,20 @@ LdmlTestSource::parse_source_string(std::string const &s) { p++; km_core_usv v; bool had_open_curly = false; - assert(p != s.end()); + test_assert(p != s.end()); if (*p == 'u' || *p == 'U') { // Unicode value p++; if (*p == '{') { p++; - assert(p != s.end()); + test_assert(p != s.end()); had_open_curly = true; } size_t n; std::string s1 = s.substr(p - s.begin(), 8); v = std::stoul(s1, &n, 16); // Allow deadkey_number (U+0001) characters and onward - assert(v >= 0x0001 && v <= 0x10FFFF); + test_assert(v >= 0x0001 && v <= 0x10FFFF); p += n - 1; if (v < 0x10000) { t += km_core_cu(v); @@ -185,13 +187,13 @@ LdmlTestSource::parse_source_string(std::string const &s) { if (had_open_curly) { p++; // close what you opened - assert(*p == '}'); // close curly - assert(p != s.end()); + test_assert(*p == '}'); // close curly + test_assert(p != s.end()); } } else if (*p == 'd') { // Deadkey // TODO, not yet supported - assert(false); + test_assert(false); } } else { t += *p; @@ -210,13 +212,13 @@ LdmlTestSource::parse_u8_source_string(std::string const &u8s) { p++; km_core_usv v; bool had_open_curly = false; - assert(p != s.end()); + test_assert(p != s.end()); if (*p == 'u' || *p == 'U') { // Unicode value p++; if (*p == '{') { p++; - assert(p != s.end()); + test_assert(p != s.end()); had_open_curly = true; } size_t n; @@ -225,7 +227,7 @@ LdmlTestSource::parse_u8_source_string(std::string const &u8s) { std::string s1b = convert(s1); v = std::stoul(s1b, &n, 16); // Allow deadkey_number (U+0001) characters and onward - assert(v >= 0x0001 && v <= 0x10FFFF); + test_assert(v >= 0x0001 && v <= 0x10FFFF); p += n - 1; if (v < 0x10000) { t += km_core_cu(v); @@ -236,13 +238,13 @@ LdmlTestSource::parse_u8_source_string(std::string const &u8s) { if (had_open_curly) { p++; // close what you opened - assert(*p == '}'); // close curly - assert(p != s.end()); + test_assert(*p == '}'); // close curly + test_assert(p != s.end()); } } else if (*p == 'd') { // Deadkey // TODO, not yet supported - assert(false); + test_assert(false); } } else { t += *p; @@ -348,7 +350,7 @@ LdmlTestSource::set_caps_lock_on(bool caps_lock_on) { key_event LdmlTestSource::char_to_event(char ch) { - assert(ch >= 32); + test_assert(ch >= 32); return { km::core::kmx::s_char_to_vkey[(int)ch - 32].vk, (uint16_t)(km::core::kmx::s_char_to_vkey[(int)ch - 32].shifted ? KM_CORE_MODIFIER_SHIFT : 0)}; @@ -382,7 +384,7 @@ LdmlEmbeddedTestSource::vkey_to_event(std::string const &vk_event) { if (vk == 0) { std::cerr << "Error parsing [" << vk_event << "] - could not find vkey or modifier: " << s << std::endl; } - assert(vk != 0); + test_assert(vk != 0); break; // only one vkey allowed } } @@ -390,9 +392,9 @@ LdmlEmbeddedTestSource::vkey_to_event(std::string const &vk_event) { // The string should be empty at this point if (std::getline(f, s, ' ')) { std::cerr << "Error parsing vkey ["<key2 != nullptr); + test_assert(kmxplus->key2 != nullptr); - assert(kmxplus->key2Helper.valid()); + test_assert(kmxplus->key2Helper.valid()); // First, find the string KMX_DWORD strId = kmxplus->strs->find(id); if (strId == 0) { @@ -503,7 +505,7 @@ bool LdmlJsonTestSource::set_key_from_id(key_event& k, const std::u16string& id) // Now, look for the _first_ candidate vkey match in the kmap. for (KMX_DWORD kmapIndex = 0; kmapIndex < kmxplus->key2->kmapCount; kmapIndex++) { auto *kmap = kmxplus->key2Helper.getKmap(kmapIndex); - assert(kmap != nullptr); + test_assert(kmap != nullptr); if (kmap->key == keyIndex) { k = {(km_core_virtual_key)kmap->vkey, (uint16_t)kmap->mod}; return true; @@ -535,7 +537,7 @@ LdmlJsonTestSource::next_action(ldml_action &fillin) { fillin.type = LDML_ACTION_CHECK_EXPECTED; fillin.string = LdmlTestSource::parse_u8_source_string(result.get()); if (!get_normalization_disabled()) { - assert(km::core::util::normalize_nfd(fillin.string)); // TODO-LDML: will be NFC when core is normalizing to NFC + test_assert(km::core::util::normalize_nfd(fillin.string)); // TODO-LDML: will be NFC when core is normalizing to NFC } return; } else if (type == "keystroke") { @@ -550,7 +552,7 @@ LdmlJsonTestSource::next_action(ldml_action &fillin) { fillin.type = LDML_ACTION_EMIT_STRING; fillin.string = LdmlTestSource::parse_u8_source_string(to.get()); if (!get_normalization_disabled()) { - assert(km::core::util::normalize_nfd(fillin.string)); // TODO-LDML: will be NFC when core is normalizing to NFC + test_assert(km::core::util::normalize_nfd(fillin.string)); // TODO-LDML: will be NFC when core is normalizing to NFC } return; } else if (type == "backspace") { @@ -577,7 +579,7 @@ LdmlJsonTestSource::get_context() { auto startContext = data["/startContext/to"_json_pointer]; context = LdmlTestSource::parse_u8_source_string(startContext); if (!get_normalization_disabled()) { - assert(km::core::util::normalize_nfd(context)); // TODO-LDML: should be NFC + test_assert(km::core::util::normalize_nfd(context)); // TODO-LDML: should be NFC } } loaded_context = true; @@ -648,7 +650,7 @@ LdmlJsonRepertoireTestSource::next_action(ldml_action &fillin) { std::size_t len = km::core::kmx::Utf32CharToUtf16(ch, ch16); std::u16string chstr = std::u16string(ch16.ch, len); if (!get_normalization_disabled()) { - assert(km::core::util::normalize_nfd(chstr)); // TODO-LDML: will be NFC when core is normalizing to NFC + test_assert(km::core::util::normalize_nfd(chstr)); // TODO-LDML: will be NFC when core is normalizing to NFC } // append to expected expected.append(chstr); @@ -659,14 +661,14 @@ LdmlJsonRepertoireTestSource::next_action(ldml_action &fillin) { // TODO-LDML: no transforms yet. // TODO-LDML: looking for an exact single key for now - assert(kmxplus != nullptr); + test_assert(kmxplus != nullptr); // lookup the id - assert(kmxplus->strs != nullptr); - assert(kmxplus->key2 != nullptr); - assert(kmxplus->layr != nullptr); + test_assert(kmxplus->strs != nullptr); + test_assert(kmxplus->key2 != nullptr); + test_assert(kmxplus->layr != nullptr); - assert(kmxplus->key2Helper.valid()); - assert(kmxplus->layrHelper.valid()); + test_assert(kmxplus->key2Helper.valid()); + test_assert(kmxplus->layrHelper.valid()); // First, find the string as an id // TODO-LDML: will not work for multi string cases @@ -683,7 +685,7 @@ LdmlJsonRepertoireTestSource::next_action(ldml_action &fillin) { // Now, look for the _first_ candidate vkey match in the kmap. for (KMX_DWORD kmapIndex = 0; kmapIndex < kmxplus->key2->kmapCount; kmapIndex++) { auto *kmap = kmxplus->key2Helper.getKmap(kmapIndex); - assert(kmap != nullptr); + test_assert(kmap != nullptr); if (kmap->key == keyIndex) { fillin.k = {(km_core_virtual_key)kmap->vkey, (uint16_t)kmap->mod}; std::cout << "found vkey " << fillin.k.vk << ":" << fillin.k.modifier_state << std::endl; diff --git a/core/tests/unit/ldml/ldml_test_source.hpp b/core/tests/unit/ldml/ldml_test_source.hpp index 4637af9bd44..8d2b05159a9 100644 --- a/core/tests/unit/ldml/ldml_test_source.hpp +++ b/core/tests/unit/ldml/ldml_test_source.hpp @@ -8,6 +8,9 @@ #include "kmx/kmx_plus.h" +#include +#include + namespace km { namespace tests { @@ -92,7 +95,7 @@ class LdmlTestSource { } bool get_normalization_disabled() const { - assert(setup); // make sure set_ was called first + test_assert(setup); // make sure set_ was called first return normalization_disabled; } diff --git a/core/tests/unit/ldml/meson.build b/core/tests/unit/ldml/meson.build index 151fb61ace6..08512bd5500 100644 --- a/core/tests/unit/ldml/meson.build +++ b/core/tests/unit/ldml/meson.build @@ -4,16 +4,6 @@ # Authors: Marc Durdin # -# TODO -- why are these differing from the standard.meson.build flags? -if cpp_compiler.get_id() == 'gcc' or cpp_compiler.get_id() == 'clang' or cpp_compiler.get_id() == 'emscripten' - warns = [ - '-Wno-missing-field-initializers', - '-Wno-unused-parameter' - ] -else - warns = [] -endif - # Build all keyboards in output folder; these are defined here and used in the # keyboards subdir @@ -85,7 +75,7 @@ ldml = executable('ldml', core_ldml_min = executable('core_ldml_min_tests', [ 'core_ldml_min.tests.cpp', - meson.current_source_dir() / '../load_kmx_file.cpp', + common_test_files, ], cpp_args: defns + warns, include_directories: [inc, libsrc], diff --git a/core/tests/unit/ldml/transforms.tests.cpp b/core/tests/unit/ldml/transforms.tests.cpp index fa909516bc9..411d9410476 100644 --- a/core/tests/unit/ldml/transforms.tests.cpp +++ b/core/tests/unit/ldml/transforms.tests.cpp @@ -227,14 +227,14 @@ test_reorder_standalone() { element es(U'a', 0xF4500000 | LDML_ELEM_FLAGS_PREBASE | LDML_ELEM_FLAGS_TERTIARY_BASE); // tertiary -12, primary 80 std::cout << "es flags" << std::hex << es.get_flags() << std::dec << std::endl; // verify element metadata - assert_equal(es.is_uset(), false); - assert_equal(es.get_order(), 0x50); - assert_equal(es.get_tertiary(), -12); - assert_equal(es.is_prebase(), true); - assert_equal(es.is_tertiary_base(), true); + test_assert_equal(es.is_uset(), false); + test_assert_equal(es.get_order(), 0x50); + test_assert_equal(es.get_tertiary(), -12); + test_assert_equal(es.is_prebase(), true); + test_assert_equal(es.is_tertiary_base(), true); // verify element matching - assert_equal(es.matches(U'a'), true); - assert_equal(es.matches(U'b'), false); + test_assert_equal(es.matches(U'a'), true); + test_assert_equal(es.matches(U'b'), false); } std::cout << __FILE__ << ":" << __LINE__ << " - nod-Lana " << std::endl; @@ -255,8 +255,8 @@ test_reorder_standalone() { const COMP_KMXPLUS_USET_USET &toneMarksUset = usets[0]; const SimpleUSet toneMarks(&ranges[toneMarksUset.range], toneMarksUset.count); // validate that the range [1A75, 1A79] matches - assert_equal(toneMarks.contains(0x1A76), true); - assert_equal(toneMarks.contains(0x1A60), false); + test_assert_equal(toneMarks.contains(0x1A76), true); + test_assert_equal(toneMarks.contains(0x1A60), false); std::cout << __FILE__ << ":" << __LINE__ << " - element API test " << std::endl; // element test @@ -264,40 +264,40 @@ test_reorder_standalone() { element es(U'a', (80 << LDML_ELEM_FLAGS_ORDER_BITSHIFT) | LDML_ELEM_FLAGS_PREBASE); // tertiary -12, primary 80 std::cout << "es flags" << std::hex << es.get_flags() << std::dec << std::endl; // verify element metadata - assert_equal(es.is_uset(), false); - assert_equal(es.get_order(), 0x50); - assert_equal(es.get_tertiary(), 0); - assert_equal(es.is_prebase(), true); - assert_equal(es.is_tertiary_base(), false); + test_assert_equal(es.is_uset(), false); + test_assert_equal(es.get_order(), 0x50); + test_assert_equal(es.get_tertiary(), 0); + test_assert_equal(es.is_prebase(), true); + test_assert_equal(es.is_tertiary_base(), false); // verify element matching - assert_equal(es.matches(U'a'), true); - assert_equal(es.matches(U'b'), false); + test_assert_equal(es.matches(U'a'), true); + test_assert_equal(es.matches(U'b'), false); element eu(toneMarks, 0x37F40000); // element metadata std::cout << "eu flags" << std::hex << eu.get_flags() << std::dec << std::endl; - assert_equal(eu.is_uset(), true); + test_assert_equal(eu.is_uset(), true); std::cout << "order" << (int)eu.get_order() << std::endl; - assert_equal(eu.get_order(), -12); - assert_equal(eu.get_tertiary(), 55); - assert_equal(eu.is_prebase(), false); - assert_equal(eu.is_tertiary_base(), false); + test_assert_equal(eu.get_order(), -12); + test_assert_equal(eu.get_tertiary(), 55); + test_assert_equal(eu.is_prebase(), false); + test_assert_equal(eu.is_tertiary_base(), false); // element matching - assert_equal(eu.matches(U'a'), false); - assert_equal(eu.matches(U'\u1A76'), true); - assert_equal(eu.matches(U'\u1A75'), true); + test_assert_equal(eu.matches(U'a'), false); + test_assert_equal(eu.matches(U'\u1A76'), true); + test_assert_equal(eu.matches(U'\u1A75'), true); element_list l; // '[tones]a' l.emplace_back(es); l.emplace_back(eu); std::cout << __FILE__ << ":" << __LINE__ << " - list test " << std::endl; - assert_equal(l.match_end(U"asdfasdf"), 0); // no match - assert_equal(l.match_end(U"a"), 0); // partial substring, fastpath because it's short - assert_equal(l.match_end(U"\u1A76"), 0); // partial substring, fastpath because it's short - assert_equal(l.match_end(U"a\u1A76"), 2); // Match - assert_equal(l.match_end(U"a\u1A75"), 2); // Match - assert_equal(l.match_end(U"SomethingSomethingSomethinga\u1A76"), 2); // Sub-Match + test_assert_equal(l.match_end(U"asdfasdf"), 0); // no match + test_assert_equal(l.match_end(U"a"), 0); // partial substring, fastpath because it's short + test_assert_equal(l.match_end(U"\u1A76"), 0); // partial substring, fastpath because it's short + test_assert_equal(l.match_end(U"a\u1A76"), 2); // Match + test_assert_equal(l.match_end(U"a\u1A75"), 2); // Match + test_assert_equal(l.match_end(U"SomethingSomethingSomethinga\u1A76"), 2); // Sub-Match // generate sort keys std::cout << __FILE__ << ":" << __LINE__ << " - get_sort_key test " << std::endl; @@ -309,24 +309,24 @@ test_reorder_standalone() { i->dump(); } // make sure it matches - assert_equal(l.match_end(str), 2); + test_assert_equal(l.match_end(str), 2); // update the keylist with these elements. l.update_sort_key(0, keylist); std::cout << __FILE__ << ":" << __LINE__ << " updated sortkey" << std::endl; - assert_equal(keylist.size(), 2); + test_assert_equal(keylist.size(), 2); reorder_weight secondary = 0; for (auto i = keylist.begin(); i < keylist.end(); i++) { i->dump(); - assert_equal(i->secondary, secondary); - assert_equal(i->quaternary, secondary); + test_assert_equal(i->secondary, secondary); + test_assert_equal(i->quaternary, secondary); secondary++; } std::cout << std::endl; // spot check first sortkey - assert_equal(keylist.begin()->primary, 80); - assert_equal(keylist.begin()->tertiary, 0); - assert_equal(keylist.begin()->ch, 0x61); + test_assert_equal(keylist.begin()->primary, 80); + test_assert_equal(keylist.begin()->tertiary, 0); + test_assert_equal(keylist.begin()->ch, 0x61); std::cout << __FILE__ << ":" << __LINE__ << " sorted sortkey" << std::endl; // now sort them @@ -336,9 +336,9 @@ test_reorder_standalone() { } std::cout << std::endl; // spot check first sort key - assert_equal(keylist.begin()->primary, -12); - assert_equal(keylist.begin()->tertiary, 55); - assert_equal(keylist.begin()->ch, 0x1A78); + test_assert_equal(keylist.begin()->primary, -12); + test_assert_equal(keylist.begin()->tertiary, 55); + test_assert_equal(keylist.begin()->ch, 0x1A78); } std::cout << __FILE__ << ":" << __LINE__ << " - key test " << std::endl; @@ -486,7 +486,7 @@ test_reorder_standalone() { std::u32string output; size_t len = tr.apply(text, output); zassert_string_equal(output, U""); - assert_equal(len, 0); + test_assert_equal(len, 0); } } } @@ -626,16 +626,16 @@ test_map() { std::cout << __FILE__ << ":" << __LINE__ << " transform_entry::findIndex" << std::endl; { std::deque list; - assert_equal(km::core::util::km_regex::findIndex(U"Does Not Exist", list), -1); + test_assert_equal(km::core::util::km_regex::findIndex(U"Does Not Exist", list), -1); list.emplace_back(U"0th"); list.emplace_back(U"First"); list.emplace_back(U"Second"); - assert_equal(km::core::util::km_regex::findIndex(U"First", list), 1); - assert_equal(km::core::util::km_regex::findIndex(U"0th", list), 0); - assert_equal(km::core::util::km_regex::findIndex(U"Second", list), 2); - assert_equal(km::core::util::km_regex::findIndex(U"Nowhere", list), -1); + test_assert_equal(km::core::util::km_regex::findIndex(U"First", list), 1); + test_assert_equal(km::core::util::km_regex::findIndex(U"0th", list), 0); + test_assert_equal(km::core::util::km_regex::findIndex(U"Second", list), 2); + test_assert_equal(km::core::util::km_regex::findIndex(U"Nowhere", list), -1); } return EXIT_SUCCESS; @@ -659,7 +659,7 @@ test_strutils() { const std::u32string src = U"abc"; const std::u32string dst = remove_markers(src, map); zassert_string_equal(dst, src); // unchanged - assert_equal(count_markers(map), 0); + test_assert_equal(count_markers(map), 0); } { marker_map map; @@ -670,7 +670,7 @@ test_strutils() { zassert_string_equal(dst, expect); marker_map expm = {{U'e', 0x1L}}; assert_marker_map_equal(map, expm); // marker 1 @ e - assert_equal(count_markers(map), 1); + test_assert_equal(count_markers(map), 1); } { marker_map map; @@ -679,7 +679,7 @@ test_strutils() { const std::u32string dst = remove_markers(src, map); const std::u32string expect = src; zassert_string_equal(dst, expect); - assert_equal(count_markers(map), 0); + test_assert_equal(count_markers(map), 0); } { marker_map map; @@ -688,7 +688,7 @@ test_strutils() { const std::u32string dst = remove_markers(src, map); const std::u32string expect = src; // 'q' removed zassert_string_equal(dst, expect); - assert_equal(count_markers(map), 0); + test_assert_equal(count_markers(map), 0); } { marker_map map; @@ -697,7 +697,7 @@ test_strutils() { const std::u32string dst = remove_markers(src, map); const std::u32string expect = src; zassert_string_equal(dst, expect); - assert_equal(count_markers(map), 0); + test_assert_equal(count_markers(map), 0); } { marker_map map; @@ -706,7 +706,7 @@ test_strutils() { const std::u32string dst = remove_markers(src, map); const std::u32string expect = src; zassert_string_equal(dst, expect); - assert_equal(count_markers(map), 0); + test_assert_equal(count_markers(map), 0); } { marker_map map; @@ -717,7 +717,7 @@ test_strutils() { zassert_string_equal(dst, expect); marker_map expm({{MARKER_BEFORE_EOT, 0x1L}}); assert_marker_map_equal(map, expm); - assert_equal(count_markers(map), 1); + test_assert_equal(count_markers(map), 1); } { marker_map map; @@ -730,7 +730,7 @@ test_strutils() { zassert_string_equal(dst, expect); marker_map expm({{U'e', 0x1L}, {0x0320, 0x2L}, {0x0300, 0x3L}, {MARKER_BEFORE_EOT, 0x4L}}); assert_marker_map_equal(map, expm); - assert_equal(count_markers(map), 4); + test_assert_equal(count_markers(map), 4); } { std::cout << __FILE__ << ":" << __LINE__ << " - prepend hex quad" << std::endl; @@ -752,11 +752,11 @@ test_strutils() { } { std::cout << __FILE__ << ":" << __LINE__ << " - parse hex quad" << std::endl; - assert_equal(parse_hex_quad(U"0001"), 0x0001); - assert_equal(parse_hex_quad(U"CAFE"), 0xCAFE); - assert_equal(parse_hex_quad(U"D00d"), 0xD00D); - assert_equal(parse_hex_quad(U"FFFF"), 0xFFFF); - assert_equal(parse_hex_quad(U"zzzz"), 0); // err + test_assert_equal(parse_hex_quad(U"0001"), 0x0001); + test_assert_equal(parse_hex_quad(U"CAFE"), 0xCAFE); + test_assert_equal(parse_hex_quad(U"D00d"), 0xD00D); + test_assert_equal(parse_hex_quad(U"FFFF"), 0xFFFF); + test_assert_equal(parse_hex_quad(U"zzzz"), 0); // err } return EXIT_SUCCESS; } @@ -773,9 +773,9 @@ test_normalize() { const std::u32string src = U"6e\U00000320\U00000300"; // already NFD const std::u32string expect = src; std::u32string dst = src; - assert(normalize_nfd_markers_segment(dst, map)); + test_assert(normalize_nfd_markers_segment(dst, map)); zassert_string_equal(dst, expect); - assert_equal(count_markers(map), 0); + test_assert_equal(count_markers(map), 0); } { marker_map map; @@ -783,9 +783,9 @@ test_normalize() { const std::u32string src = U"6e\U00000300\U00000320"; // swapped const std::u32string expect = U"6e\U00000320\U00000300"; // correct NFD std::u32string dst = src; - assert(normalize_nfd_markers_segment(dst, map)); + test_assert(normalize_nfd_markers_segment(dst, map)); zassert_string_equal(dst, expect); - assert_equal(count_markers(map), 0); + test_assert_equal(count_markers(map), 0); } { @@ -796,11 +796,11 @@ test_normalize() { U"\U0000ffff\U00000008\U00000004"; const std::u32string expect = src; std::u32string dst = src; - assert(normalize_nfd_markers_segment(dst, map)); + test_assert(normalize_nfd_markers_segment(dst, map)); zassert_string_equal(dst, expect); marker_map expm({{U'e', 0x1L}, {0x320, 0x2L}, {0x300, 0x3L}, {MARKER_BEFORE_EOT, 0x4L}}); assert_marker_map_equal(map, expm); - assert_equal(count_markers(map), 4); + test_assert_equal(count_markers(map), 4); } { @@ -811,11 +811,11 @@ test_normalize() { U"\U0000ffff\U00000008\U00000004"; const std::u32string expect = src; std::u32string dst = src; - assert(normalize_nfd_markers_segment(dst, map)); + test_assert(normalize_nfd_markers_segment(dst, map)); zassert_string_equal(dst, expect); marker_map expm({{U'e', 0x1L}, {0x320, 0x2L}, {0x300, 0x3L}, {MARKER_BEFORE_EOT, 0x4L}}); assert_marker_map_equal(map, expm); - assert_equal(count_markers(map), 4); + test_assert_equal(count_markers(map), 4); } { marker_map map; @@ -827,7 +827,7 @@ test_normalize() { U"6\U0000ffff\U00000008\U00000001e\U0000ffff\U00000008\U00000003\U00000320\U0000ffff\U00000008\U00000002\U00000300" U"\U0000ffff\U00000008\U00000004"; std::u32string dst = src; - assert(normalize_nfd_markers_segment(dst, map)); + test_assert(normalize_nfd_markers_segment(dst, map)); if (dst != expect) { std::cout << "dst: " << Debug_UnicodeString(dst) << std::endl; std::cout << "exp: " << Debug_UnicodeString(expect) << std::endl; @@ -835,7 +835,7 @@ test_normalize() { zassert_string_equal(dst, expect); marker_map expm({{U'e', 0x1L}, {0x300, 0x2L}, {0x320, 0x3L}, {MARKER_BEFORE_EOT, 0x4L}}); assert_marker_map_equal(map, expm); - assert_equal(count_markers(map), 4); + test_assert_equal(count_markers(map), 4); } { @@ -845,7 +845,7 @@ test_normalize() { const std::u32string src = U"4e\u0300\uFFFF\u0008\u0001\u0320"; const std::u32string expect = U"4e\uFFFF\u0008\u0001\u0320\u0300"; std::u32string dst = src; - assert(normalize_nfd_markers_segment(dst, map)); + test_assert(normalize_nfd_markers_segment(dst, map)); if (dst != expect) { std::cout << "dst: " << Debug_UnicodeString(dst) << std::endl; std::cout << "exp: " << Debug_UnicodeString(expect) << std::endl; @@ -853,7 +853,7 @@ test_normalize() { zassert_string_equal(dst, expect); marker_map expm({{0x320, 0x1L}}); assert_marker_map_equal(map, expm); - assert_equal(count_markers(map), 1); + test_assert_equal(count_markers(map), 1); } { @@ -863,7 +863,7 @@ test_normalize() { const std::u32string src = U"9ce\u0300\uFFFF\u0008\u0002\u0320\uFFFF\u0008\u0001"; const std::u32string expect = U"9ce\uFFFF\u0008\u0002\u0320\u0300\uFFFF\u0008\u0001"; std::u32string dst = src; - assert(normalize_nfd_markers_segment(dst, map)); + test_assert(normalize_nfd_markers_segment(dst, map)); if (dst != expect) { std::cout << "dst: " << Debug_UnicodeString(dst) << std::endl; std::cout << "exp: " << Debug_UnicodeString(expect) << std::endl; @@ -871,7 +871,7 @@ test_normalize() { zassert_string_equal(dst, expect); marker_map expm({{0x320, 0x2L}, {MARKER_BEFORE_EOT, 0x1L}}); assert_marker_map_equal(map, expm); - assert_equal(count_markers(map), 2); + test_assert_equal(count_markers(map), 2); } { @@ -881,7 +881,7 @@ test_normalize() { const std::u32string src = U"9ce\u0300\\uffff\\u0008\\u0002\u0320\\uffff\\u0008\\u0001"; const std::u32string expect = U"9ce\\uffff\\u0008\\u0002\u0320\u0300\\uffff\\u0008\\u0001"; std::u32string dst = src; - assert(normalize_nfd_markers_segment(dst, map, regex_sentinel)); + test_assert(normalize_nfd_markers_segment(dst, map, regex_sentinel)); if (dst != expect) { std::cout << "dst: " << Debug_UnicodeString(dst) << std::endl; std::cout << " " << dst << std::endl; @@ -891,7 +891,7 @@ test_normalize() { zassert_string_equal(dst, expect); marker_map expm({{0x320, 0x2L}, {MARKER_BEFORE_EOT, 0x1L}}); assert_marker_map_equal(map, expm); - assert_equal(count_markers(map), 2); + test_assert_equal(count_markers(map), 2); } { // from tests - regex edition @@ -900,7 +900,7 @@ test_normalize() { const std::u32string src = U"9ce\u0300\\uffff\\u0008[\\u0001-\\ud7fe]\u0320\\uffff\\u0008\\u0001"; const std::u32string expect = U"9ce\\uffff\\u0008[\\u0001-\\ud7fe]\u0320\u0300\\uffff\\u0008\\u0001"; std::u32string dst = src; - assert(normalize_nfd_markers_segment(dst, map, regex_sentinel)); + test_assert(normalize_nfd_markers_segment(dst, map, regex_sentinel)); if (dst != expect) { std::cout << "dst: " << Debug_UnicodeString(dst) << std::endl; std::cout << "exp: " << Debug_UnicodeString(expect) << std::endl; @@ -908,7 +908,7 @@ test_normalize() { zassert_string_equal(dst, expect); marker_map expm({{0x320, LDML_MARKER_ANY_INDEX}, {MARKER_BEFORE_EOT, 0x1L}}); assert_marker_map_equal(map, expm); - assert_equal(count_markers(map), 2); + test_assert_equal(count_markers(map), 2); } { @@ -918,7 +918,7 @@ test_normalize() { const std::u32string src = U"9ce\u0300\uFFFF\u0008\u0002\uFFFF\u0008\u0002\u0320"; const std::u32string expect = U"9ce\uFFFF\u0008\u0002\uFFFF\u0008\u0002\u0320\u0300"; std::u32string dst = src; - assert(normalize_nfd_markers_segment(dst, map)); + test_assert(normalize_nfd_markers_segment(dst, map)); if (dst != expect) { std::cout << "dst: " << Debug_UnicodeString(dst) << std::endl; std::cout << "exp: " << Debug_UnicodeString(expect) << std::endl; @@ -926,7 +926,7 @@ test_normalize() { zassert_string_equal(dst, expect); marker_map expm({{0x320, 0x2L}, {0x320, 0x2L}}); assert_marker_map_equal(map, expm); - assert_equal(count_markers(map), 2); + test_assert_equal(count_markers(map), 2); } { @@ -936,7 +936,7 @@ test_normalize() { const std::u32string src = U"9ce\u0300\uFFFF\u0008\u0002\uFFFF\u0008\u0001\uFFFF\u0008\u0003\u0320"; const std::u32string expect = U"9ce\uFFFF\u0008\u0002\uFFFF\u0008\u0001\uFFFF\u0008\u0003\u0320\u0300"; std::u32string dst = src; - assert(normalize_nfd_markers_segment(dst, map)); + test_assert(normalize_nfd_markers_segment(dst, map)); if (dst != expect) { std::cout << "dst: " << Debug_UnicodeString(dst) << std::endl; std::cout << "exp: " << Debug_UnicodeString(expect) << std::endl; @@ -972,7 +972,7 @@ test_normalize() { assert_marker_map_equal(map, expm); zassert_string_equal(dst_rem, expect_rem); std::u32string dst_nfd = src; - assert(normalize_nfd_markers(dst_nfd)); + test_assert(normalize_nfd_markers(dst_nfd)); if (dst_nfd != expect_nfd) { std::cout << "dst: " << Debug_UnicodeString(dst_nfd) << std::endl; std::cout << "exp: " << Debug_UnicodeString(expect_nfd) << std::endl; @@ -990,7 +990,7 @@ test_normalize() { marker_map expm({{0x09C7, 0x1L}}); zassert_string_equal(dst_rem, expect_rem); std::u32string dst_nfd = src; - assert(normalize_nfd_markers(dst_nfd)); + test_assert(normalize_nfd_markers(dst_nfd)); if (dst_nfd != expect_nfd) { std::cout << "dst: " << Debug_UnicodeString(dst_nfd) << std::endl; std::cout << "exp: " << Debug_UnicodeString(expect_nfd) << std::endl; @@ -1008,7 +1008,7 @@ test_normalize() { marker_map expm({{0x09C7, 0x1L}}); zassert_string_equal(dst_rem, expect_rem); std::u32string dst_nfd = src; - assert(normalize_nfd_markers(dst_nfd)); + test_assert(normalize_nfd_markers(dst_nfd)); if (dst_nfd != expect_nfd) { std::cout << "dst: " << Debug_UnicodeString(dst_nfd) << std::endl; std::cout << "exp: " << Debug_UnicodeString(expect_nfd) << std::endl; @@ -1026,7 +1026,7 @@ test_normalize() { marker_map expm({{0x09C7, 0x1L}}); zassert_string_equal(dst_rem, expect_rem); std::u32string dst_nfd = src; - assert(normalize_nfd_markers(dst_nfd)); + test_assert(normalize_nfd_markers(dst_nfd)); if (dst_nfd != expect_nfd) { std::cout << "dst: " << Debug_UnicodeString(dst_nfd) << std::endl; std::cout << "exp: " << Debug_UnicodeString(expect_nfd) << std::endl; @@ -1044,7 +1044,7 @@ test_normalize() { marker_map expm({{0x0308, 0x1L}}); zassert_string_equal(dst_rem, expect_rem); std::u32string dst_nfd = src; - assert(normalize_nfd_markers(dst_nfd)); + test_assert(normalize_nfd_markers(dst_nfd)); if (dst_nfd != expect_nfd) { std::cout << "dst: " << Debug_UnicodeString(dst_nfd) << std::endl; std::cout << "exp: " << Debug_UnicodeString(expect_nfd) << std::endl; @@ -1064,7 +1064,7 @@ test_normalize() { marker_map expm({{0x0300, 0x1L}}); zassert_string_equal(dst_rem, expect_rem); std::u32string dst_nfd = src; - assert(normalize_nfd_markers(dst_nfd)); + test_assert(normalize_nfd_markers(dst_nfd)); if (dst_nfd != expect_nfd) { std::cout << "dst: " << Debug_UnicodeString(dst_nfd) << std::endl; std::cout << "exp: " << Debug_UnicodeString(expect_nfd) << std::endl; @@ -1082,7 +1082,7 @@ test_normalize() { marker_map expm({{0x300, 0x1L}}); zassert_string_equal(dst_rem, expect_rem); std::u32string dst_nfd = src; - assert(normalize_nfd_markers(dst_nfd)); + test_assert(normalize_nfd_markers(dst_nfd)); if (dst_nfd != expect_nfd) { std::cout << "dst: " << Debug_UnicodeString(dst_nfd) << std::endl; std::cout << "exp: " << Debug_UnicodeString(expect_nfd) << std::endl; @@ -1100,7 +1100,7 @@ test_normalize() { marker_map expm({{0x0308, 0x1L},{0x0308, 0x2L},{MARKER_BEFORE_EOT, 0x3L}}); zassert_string_equal(dst_rem, expect_rem); std::u32string dst_nfd = src; - assert(normalize_nfd_markers(dst_nfd)); + test_assert(normalize_nfd_markers(dst_nfd)); if (dst_nfd != expect_nfd) { std::cout << "dst: " << Debug_UnicodeString(dst_nfd) << std::endl; std::cout << "exp: " << Debug_UnicodeString(expect_nfd) << std::endl; @@ -1117,7 +1117,7 @@ test_normalize() { const std::u32string src = x; \ const std::u32string expect_nfd = y; \ std::u32string dst_nfd = src; \ - assert(normalize_nfd_markers(dst_nfd)); \ + test_assert(normalize_nfd_markers(dst_nfd)); \ if (dst_nfd != expect_nfd) { \ std::cout << "dst: " << Debug_UnicodeString(dst_nfd) << std::endl; \ std::cout << "exp: " << Debug_UnicodeString(expect_nfd) << std::endl; \ @@ -1145,43 +1145,43 @@ test_util_regex() { { std::cout << __FILE__ << ":" << __LINE__ << " * util_regex.hpp null tests" << std::endl; km::core::util::km_regex r; - assert(!r.valid()); // not valid because of an empty string + test_assert(!r.valid()); // not valid because of an empty string } { std::cout << __FILE__ << ":" << __LINE__ << " * util_regex.hpp simple tests" << std::endl; km::core::util::km_regex r(U"ion"); - assert(r.valid()); + test_assert(r.valid()); const std::u32string to(U"ivity"); const std::deque fromList; const std::deque toList; std::u32string output; auto apply0 = r.apply(U"not present", output, to, fromList, toList); - assert_equal(apply0, 0); // not found + test_assert_equal(apply0, 0); // not found const std::u32string input(U"action"); auto apply1 = r.apply(input, output, to, fromList, toList); - assert_equal(apply1, 3); // matched last 3 codepoints + test_assert_equal(apply1, 3); // matched last 3 codepoints std::u32string expect(U"ivity"); zassert_string_equal(output, expect) } { std::cout << __FILE__ << ":" << __LINE__ << " * util_regex.hpp wide tests" << std::endl; km::core::util::km_regex r(U"e𐒻"); - assert(r.valid()); + test_assert(r.valid()); const std::u32string to(U"𐓏"); const std::deque fromList; const std::deque toList; std::u32string output; const std::u32string input(U":e𐒻"); auto apply1 = r.apply(input, output, to, fromList, toList); - assert_equal(apply1, 2); // matched last 2 codepoints + test_assert_equal(apply1, 2); // matched last 2 codepoints std::u32string expect(U"𐓏"); zassert_string_equal(output, expect) } { std::cout << __FILE__ << ":" << __LINE__ << " * util_regex.hpp simple map tests" << std::endl; km::core::util::km_regex r(U"(A|B|C)"); - assert(r.valid()); + test_assert(r.valid()); const std::u32string to(U"$[1:alpha2]"); // ignored std::deque fromList; fromList.emplace_back(U"A"); @@ -1193,18 +1193,18 @@ test_util_regex() { toList.emplace_back(U"P"); std::u32string output; auto apply0 = r.apply(U"not present", output, to, fromList, toList); - assert_equal(apply0, 0); // not found + test_assert_equal(apply0, 0); // not found const std::u32string input(U"WHOA"); auto apply1 = r.apply(input, output, to, fromList, toList); - assert_equal(apply1, 1); // matched last 1 codepoint + test_assert_equal(apply1, 1); // matched last 1 codepoint std::u32string expect(U"N"); zassert_string_equal(output, expect) } { std::cout << __FILE__ << ":" << __LINE__ << " * util_regex.hpp wide map tests" << std::endl; km::core::util::km_regex r(U"(𐒷|𐒻|𐓏𐓏|x)"); - assert(r.valid()); + test_assert(r.valid()); const std::u32string to(U"$[1:alpha2]"); // ignored std::deque fromList; fromList.emplace_back(U"𐒷"); @@ -1218,15 +1218,15 @@ test_util_regex() { toList.emplace_back(U"𐓏"); std::u32string output; auto apply0 = r.apply(U"not present", output, to, fromList, toList); - assert_equal(apply0, 0); // not found + test_assert_equal(apply0, 0); // not found - assert_equal(r.apply(U"WHO𐓏𐒷", output, to, fromList, toList), 1); + test_assert_equal(r.apply(U"WHO𐓏𐒷", output, to, fromList, toList), 1); zassert_string_equal(output, U"x"); - assert_equal(r.apply(U"WHO𐓏x", output, to, fromList, toList), 1); + test_assert_equal(r.apply(U"WHO𐓏x", output, to, fromList, toList), 1); zassert_string_equal(output, U"𐓏"); - assert_equal(r.apply(U"WHO𐓏𐓏", output, to, fromList, toList), 2); // 2 codepoints + test_assert_equal(r.apply(U"WHO𐓏𐓏", output, to, fromList, toList), 2); // 2 codepoints zassert_string_equal(output, U"𐒻"); } diff --git a/core/tests/unit/ldml/unicode.tests.cpp b/core/tests/unit/ldml/unicode.tests.cpp index 937125d1727..f9d95893dca 100644 --- a/core/tests/unit/ldml/unicode.tests.cpp +++ b/core/tests/unit/ldml/unicode.tests.cpp @@ -66,7 +66,7 @@ nlohmann::json load_json(const km::core::path &jsonpath) { std::ifstream json_file(jsonpath.native()); if (!json_file) { std::cerr << "ERROR Could not load: " << jsonpath << std::endl; - assert (json_file); + test_assert (json_file); } nlohmann::json data = nlohmann::json::parse(json_file); return data; @@ -74,7 +74,7 @@ nlohmann::json load_json(const km::core::path &jsonpath) { /** @returns the major version of 'ver', skipping initial '^'. empty on err */ std::string get_major(const std::string& ver) { - assert(!ver.empty()); + test_assert(!ver.empty()); auto start = 0; // skip leading '^' if (ver[start] == '^') { @@ -82,7 +82,7 @@ std::string get_major(const std::string& ver) { } // find first '.' auto end = ver.find('.', start); - assert(end != std::string::npos); + test_assert(end != std::string::npos); return ver.substr(start, end - start); } @@ -94,9 +94,9 @@ std::string get_block_unicode_ver(const char *blocks_path) { // open Blocks.txt std::ifstream blocks_file( km::core::path(blocks_path).native()); - assert(blocks_file.good()); + test_assert(blocks_file.good()); std::string block_line; - assert(std::getline(blocks_file, block_line)); // first line + test_assert(std::getline(blocks_file, block_line)); // first line // The first line is something such as '# Blocks-15.1.0.txt' // We skip the prefix, and then stop before the suffix @@ -105,12 +105,12 @@ std::string get_block_unicode_ver(const char *blocks_path) { const std::string txt_suffix = ".txt"; // find and skip the prefix - "15.1.0.txt" - assert(block_line.length() > prefix.length()); + test_assert(block_line.length() > prefix.length()); std::string result = block_line.substr(prefix.length()); // "15.1.0" // find and trim before the suffix auto txt_pos = result.find(txt_suffix, 0); - assert(txt_pos != std::string::npos); + test_assert(txt_pos != std::string::npos); result.resize(txt_pos); return result; @@ -167,7 +167,7 @@ const std::string &block_unicode_ver) { // allow the Node.js version to be >= required auto node_engine_num = std::atoi(node_engine_major.c_str()); auto node_num = std::atoi(node_major.c_str()); - assert(node_num >= node_engine_num); + test_assert(node_num >= node_engine_num); // the cxx_icu can come from the Ubuntu environment, so do not depend on it // for now. @@ -213,7 +213,7 @@ void test_has_boundary_before() { std::cerr << "Error: util_normalize_table.h said " << boolstr(km_hbb) << " but ICU said " << boolstr(icu_hbb) << " for " << "has_nfd_boundary_before(0x" << std::hex << cp << std::dec << ")" << std::endl; } - assert(km_hbb == icu_hbb); + test_assert(km_hbb == icu_hbb); } std::cout << "All OK!" << std::endl; } @@ -224,11 +224,11 @@ int test_all(const char *jsonpath, const char *packagepath, const char *blockspa // load the dump of node's process.versions which the meson.build file generated auto versions = load_json(km::core::path(jsonpath)); - assert(!versions.empty()); + test_assert(!versions.empty()); // load our top level package.json auto package = load_json(km::core::path(packagepath)); - assert(!package.empty()); + test_assert(!package.empty()); const auto block_unicode_ver = get_block_unicode_ver(blockspath); diff --git a/core/tests/unit/meson.build b/core/tests/unit/meson.build index ea8b74ea97a..0637ace96e5 100644 --- a/core/tests/unit/meson.build +++ b/core/tests/unit/meson.build @@ -4,6 +4,17 @@ gtest = subproject('gtest') gtest_dep = gtest.get_variable('gtest_dep') gmock_dep = gtest.get_variable('gmock_dep') +# TODO -- why are these differing from the standard.meson.build flags? +# -Wno-unused-parameter --> test_color.h +if cpp_compiler.get_id() == 'gcc' or cpp_compiler.get_id() == 'clang' or cpp_compiler.get_id() == 'emscripten' + warns = [ + '-Wno-missing-field-initializers', + '-Wno-unused-parameter' + ] +else + warns = [] +endif + test_util_files = [ meson.current_source_dir() / 'emscripten_filesystem.cpp', meson.current_source_dir() / 'load_kmx_file.cpp', @@ -26,9 +37,10 @@ endif kmcorekeyboardapitests = executable('km_core_keyboard_api.tests', [ 'km_core_keyboard_api.tests.cpp', - test_util_files, + common_test_files, ], include_directories: [inc, libsrc], + cpp_args: defns + warns, link_args: [ links, extra_link_args ], dependencies: [icu_uc, icu_i18n, gtest_dep, gmock_dep], objects: lib.extract_all_objects(recursive: false), diff --git a/developer/src/kmcmplib/tests/api.tests.cpp b/developer/src/kmcmplib/tests/api.tests.cpp index 52769f2b042..ea44e3fade0 100644 --- a/developer/src/kmcmplib/tests/api.tests.cpp +++ b/developer/src/kmcmplib/tests/api.tests.cpp @@ -64,9 +64,9 @@ void test_kmcmp_CompileKeyboard(char *kmn_file) { options.warnDeprecatedCode = true; options.shouldAddCompilerVersion = false; options.target = CKF_KEYMAN; - assert(!kmcmp_CompileKeyboard(kmn_file, options, msgproc, loadfileProc, nullptr, result)); - assert(error_vec.size() == 1); - assert(error_vec[0] == KmnCompilerMessages::ERROR_InfileNotExist); // zero byte no longer gives us KmnCompilerMessages::ERROR_CannotReadInfile + test_assert(!kmcmp_CompileKeyboard(kmn_file, options, msgproc, loadfileProc, nullptr, result)); + test_assert(error_vec.size() == 1); + test_assert(error_vec[0] == KmnCompilerMessages::ERROR_InfileNotExist); // zero byte no longer gives us KmnCompilerMessages::ERROR_CannotReadInfile unlink(kmn_file); } @@ -77,61 +77,61 @@ void test_GetCompileTargetsFromTargetsStore() { int targets = 0; setup(); - assert(GetCompileTargetsFromTargetsStore(u"any", targets)); - assert(error_vec.size() == 0); - assert(targets == (COMPILETARGETS_KMX | COMPILETARGETS_JS)); + test_assert(GetCompileTargetsFromTargetsStore(u"any", targets)); + test_assert(error_vec.size() == 0); + test_assert(targets == (COMPILETARGETS_KMX | COMPILETARGETS_JS)); setup(); - assert(GetCompileTargetsFromTargetsStore(u"windows", targets)); - assert(error_vec.size() == 0); - assert(targets == COMPILETARGETS_KMX); + test_assert(GetCompileTargetsFromTargetsStore(u"windows", targets)); + test_assert(error_vec.size() == 0); + test_assert(targets == COMPILETARGETS_KMX); setup(); - assert(GetCompileTargetsFromTargetsStore(u"desktop", targets)); - assert(error_vec.size() == 0); - assert(targets == COMPILETARGETS_KMX); + test_assert(GetCompileTargetsFromTargetsStore(u"desktop", targets)); + test_assert(error_vec.size() == 0); + test_assert(targets == COMPILETARGETS_KMX); setup(); - assert(GetCompileTargetsFromTargetsStore(u"mobile", targets)); - assert(error_vec.size() == 0); - assert(targets == COMPILETARGETS_JS); + test_assert(GetCompileTargetsFromTargetsStore(u"mobile", targets)); + test_assert(error_vec.size() == 0); + test_assert(targets == COMPILETARGETS_JS); setup(); - assert(GetCompileTargetsFromTargetsStore(u"web", targets)); - assert(error_vec.size() == 0); - assert(targets == COMPILETARGETS_JS); + test_assert(GetCompileTargetsFromTargetsStore(u"web", targets)); + test_assert(error_vec.size() == 0); + test_assert(targets == COMPILETARGETS_JS); setup(); - assert(GetCompileTargetsFromTargetsStore(u"desktop mobile", targets)); - assert(error_vec.size() == 0); - assert(targets == (COMPILETARGETS_KMX | COMPILETARGETS_JS)); + test_assert(GetCompileTargetsFromTargetsStore(u"desktop mobile", targets)); + test_assert(error_vec.size() == 0); + test_assert(targets == (COMPILETARGETS_KMX | COMPILETARGETS_JS)); setup(); - assert(GetCompileTargetsFromTargetsStore(u"desktop tablet", targets)); - assert(error_vec.size() == 0); - assert(targets == (COMPILETARGETS_KMX | COMPILETARGETS_JS)); + test_assert(GetCompileTargetsFromTargetsStore(u"desktop tablet", targets)); + test_assert(error_vec.size() == 0); + test_assert(targets == (COMPILETARGETS_KMX | COMPILETARGETS_JS)); setup(); - assert(!GetCompileTargetsFromTargetsStore(u"foo bar baz", targets)); - assert(error_vec.size() == 1); - assert(error_vec[0] == KmnCompilerMessages::ERROR_InvalidTarget); - assert(targets == 0); + test_assert(!GetCompileTargetsFromTargetsStore(u"foo bar baz", targets)); + test_assert(error_vec.size() == 1); + test_assert(error_vec[0] == KmnCompilerMessages::ERROR_InvalidTarget); + test_assert(targets == 0); setup(); - assert(!GetCompileTargetsFromTargetsStore(u"windows chromeos", targets)); - assert(error_vec.size() == 1); - assert(error_vec[0] == KmnCompilerMessages::ERROR_InvalidTarget); - assert(targets == 0); + test_assert(!GetCompileTargetsFromTargetsStore(u"windows chromeos", targets)); + test_assert(error_vec.size() == 1); + test_assert(error_vec[0] == KmnCompilerMessages::ERROR_InvalidTarget); + test_assert(targets == 0); setup(); - assert(!GetCompileTargetsFromTargetsStore(u" ", targets)); - assert(error_vec.size() == 1); - assert(error_vec[0] == KmnCompilerMessages::ERROR_NoTargetsSpecified); - assert(targets == 0); + test_assert(!GetCompileTargetsFromTargetsStore(u" ", targets)); + test_assert(error_vec.size() == 1); + test_assert(error_vec[0] == KmnCompilerMessages::ERROR_NoTargetsSpecified); + test_assert(targets == 0); setup(); - assert(!GetCompileTargetsFromTargetsStore(u"", targets)); - assert(error_vec.size() == 1); - assert(error_vec[0] == KmnCompilerMessages::ERROR_NoTargetsSpecified); - assert(targets == 0); + test_assert(!GetCompileTargetsFromTargetsStore(u"", targets)); + test_assert(error_vec.size() == 1); + test_assert(error_vec[0] == KmnCompilerMessages::ERROR_NoTargetsSpecified); + test_assert(targets == 0); } diff --git a/developer/src/kmcmplib/tests/meson.build b/developer/src/kmcmplib/tests/meson.build index fafed5f1f6f..da2ac61a37d 100644 --- a/developer/src/kmcmplib/tests/meson.build +++ b/developer/src/kmcmplib/tests/meson.build @@ -6,6 +6,8 @@ fs = import('fs') +common_test_files = [ meson.global_source_root() / '../../../common/include/test_color.cpp' ] + tests_links = [] if cpp_compiler.get_id() == 'emscripten' @@ -15,7 +17,7 @@ endif input_path = meson.current_source_dir() / '../../../../common/test/keyboards/baseline' output_path = meson.current_build_dir() -kmcompxtest = executable('kmcompxtests', ['kmcompx.tests.cpp','util_filesystem.cpp','util_callbacks.cpp'], +kmcompxtest = executable('kmcompxtests', ['kmcompx.tests.cpp','util_filesystem.cpp','util_callbacks.cpp',common_test_files], cpp_args: defns + flags, include_directories: inc, name_suffix: name_suffix, @@ -129,8 +131,6 @@ if get_option('full_test') endif -common_test_files = [ meson.global_source_root() / '../../../common/include/test_color.cpp' ] - # Test the API endpoints apitest = executable('api-tests', ['api.tests.cpp','util_filesystem.cpp','util_callbacks.cpp', common_test_files], diff --git a/developer/src/kmcmplib/tests/uset-api.tests.cpp b/developer/src/kmcmplib/tests/uset-api.tests.cpp index 7a24f5cd4a5..ce83e012eb9 100644 --- a/developer/src/kmcmplib/tests/uset-api.tests.cpp +++ b/developer/src/kmcmplib/tests/uset-api.tests.cpp @@ -37,14 +37,14 @@ void test_kmcmp_parseUnicodeSet() { uint32_t buf[bufsiz]; uintptr_t buf_ = reinterpret_cast(buf); int rc = kmcmp_parseUnicodeSet(u8"[]", buf_, bufsiz); - assert(rc == KMCMP_USET_OK); + test_assert(rc == KMCMP_USET_OK); } { // preflight null test const auto bufsiz = 0; uintptr_t buf_ = 0L; int rc = kmcmp_parseUnicodeSet(u8"[]", buf_, bufsiz); - assert(rc == KMCMP_USET_OK); // == 0 + test_assert(rc == KMCMP_USET_OK); // == 0 } { // basic test @@ -52,17 +52,17 @@ void test_kmcmp_parseUnicodeSet() { uint32_t buf[bufsiz]; uintptr_t buf_ = reinterpret_cast(buf); int rc = kmcmp_parseUnicodeSet(u8"[x A-C]", buf_, bufsiz); - assert(rc == 2); - assert(buf[0] == 0x41); - assert(buf[1] == 0x43); - assert(buf[2] == 0x78); - assert(buf[3] == 0x78); + test_assert(rc == 2); + test_assert(buf[0] == 0x41); + test_assert(buf[1] == 0x43); + test_assert(buf[2] == 0x78); + test_assert(buf[3] == 0x78); } { uintptr_t buf_ = 0L; const auto bufsiz = 0; int rc = kmcmp_parseUnicodeSet(u8"[x A-C]", buf_, bufsiz); // preflight - assert(rc == 2); // 2 ranges + test_assert(rc == 2); // 2 ranges } { // bigger test @@ -70,11 +70,11 @@ void test_kmcmp_parseUnicodeSet() { uint32_t buf[bufsiz]; uintptr_t buf_ = reinterpret_cast(buf); int rc = kmcmp_parseUnicodeSet(u8"[[🙀A-C]-[CB]]", buf_, bufsiz); - assert(rc == 2); - assert(buf[0] == 0x41); - assert(buf[1] == 0x41); - assert(buf[2] == 0x1F640); - assert(buf[3] == 0x1F640); + test_assert(rc == 2); + test_assert(buf[0] == 0x41); + test_assert(buf[1] == 0x41); + test_assert(buf[2] == 0x1F640); + test_assert(buf[3] == 0x1F640); } { // overflow test @@ -82,7 +82,7 @@ void test_kmcmp_parseUnicodeSet() { uint32_t buf[bufsiz]; uintptr_t buf_ = reinterpret_cast(buf); int rc = kmcmp_parseUnicodeSet(u8"[x A-C]", buf_, bufsiz); - assert(rc == KMCMP_FATAL_OUT_OF_RANGE); + test_assert(rc == KMCMP_FATAL_OUT_OF_RANGE); } { // err test @@ -90,7 +90,7 @@ void test_kmcmp_parseUnicodeSet() { uint32_t buf[bufsiz]; uintptr_t buf_ = reinterpret_cast(buf); int rc = kmcmp_parseUnicodeSet(u8"[:Adlm:]", buf_, bufsiz); - assert(rc == KMCMP_ERROR_UNSUPPORTED_PROPERTY); + test_assert(rc == KMCMP_ERROR_UNSUPPORTED_PROPERTY); } { // err test @@ -98,7 +98,7 @@ void test_kmcmp_parseUnicodeSet() { uint32_t buf[bufsiz]; uintptr_t buf_ = reinterpret_cast(buf); int rc = kmcmp_parseUnicodeSet(u8"[[\\p{Mn}]&[A-Z]]", buf_, bufsiz); - assert(rc == KMCMP_ERROR_UNSUPPORTED_PROPERTY); + test_assert(rc == KMCMP_ERROR_UNSUPPORTED_PROPERTY); } { // err test @@ -106,7 +106,7 @@ void test_kmcmp_parseUnicodeSet() { uint32_t buf[bufsiz]; uintptr_t buf_ = reinterpret_cast(buf); int rc = kmcmp_parseUnicodeSet(u8"[abc{def}]", buf_, bufsiz); - assert(rc == KMCMP_ERROR_HAS_STRINGS); + test_assert(rc == KMCMP_ERROR_HAS_STRINGS); } { // err test @@ -114,34 +114,34 @@ void test_kmcmp_parseUnicodeSet() { uint32_t buf[bufsiz]; uintptr_t buf_ = reinterpret_cast(buf); int rc = kmcmp_parseUnicodeSet(u8"[[]", buf_, bufsiz); - assert(rc == KMCMP_ERROR_SYNTAX_ERR); + test_assert(rc == KMCMP_ERROR_SYNTAX_ERR); } { // preflight err test const auto bufsiz = 0; // preflight uintptr_t buf_ = 0L; int rc = kmcmp_parseUnicodeSet(u8"[:Adlm:]", buf_, bufsiz); - assert(rc == KMCMP_ERROR_UNSUPPORTED_PROPERTY); + test_assert(rc == KMCMP_ERROR_UNSUPPORTED_PROPERTY); } { // preflight err test const auto bufsiz = 0; // preflight uintptr_t buf_ = 0L; int rc = kmcmp_parseUnicodeSet(u8"[[\\p{Mn}]&[A-Z]]", buf_, bufsiz); - assert(rc == KMCMP_ERROR_UNSUPPORTED_PROPERTY); + test_assert(rc == KMCMP_ERROR_UNSUPPORTED_PROPERTY); } { // preflight err test const auto bufsiz = 0; // preflight uintptr_t buf_ = 0L; int rc = kmcmp_parseUnicodeSet(u8"[abc{def}]", buf_, bufsiz); - assert(rc == KMCMP_ERROR_HAS_STRINGS); + test_assert(rc == KMCMP_ERROR_HAS_STRINGS); } { // preflight err test const auto bufsiz = 0; // preflight uintptr_t buf_ = 0L; int rc = kmcmp_parseUnicodeSet(u8"[[]", buf_, bufsiz); - assert(rc == KMCMP_ERROR_SYNTAX_ERR); + test_assert(rc == KMCMP_ERROR_SYNTAX_ERR); } } diff --git a/developer/src/kmcmplib/tests/util_filesystem.cpp b/developer/src/kmcmplib/tests/util_filesystem.cpp index 0873ff13288..0a45e29876a 100644 --- a/developer/src/kmcmplib/tests/util_filesystem.cpp +++ b/developer/src/kmcmplib/tests/util_filesystem.cpp @@ -1,10 +1,8 @@ - #ifdef __EMSCRIPTEN__ #include #include #endif -#include #include #include #include "util_filesystem.h" @@ -15,6 +13,8 @@ #include #endif +#include + //#define _DEBUG_FOPEN 1 #ifdef __EMSCRIPTEN__ @@ -26,13 +26,13 @@ const std::string get_wasm_file_path(const std::string& filename) { std::cout << "get_wasm_file_path ENTER (" << filename << ")" << std::endl; #endif - assert( + test_assert( (filename.length() > 0 && filename.at(0) == '/') || (filename.length() > 1 && filename.at(1) == ':') ); #if _DEBUG_FOPEN - std::cout << "get_wasm_file_path assert passed " << std::endl; + std::cout << "get_wasm_file_path test_assert passed " << std::endl; #endif EM_ASM_({ diff --git a/linux/ibus-keyman/tests/meson.build b/linux/ibus-keyman/tests/meson.build index 40d8b9713af..a1c51a35aee 100644 --- a/linux/ibus-keyman/tests/meson.build +++ b/linux/ibus-keyman/tests/meson.build @@ -5,6 +5,8 @@ test_files = [ '../src/KeymanSystemServiceClient.cpp', ] +common_test_files = [ meson.global_source_root() / '../../common/include/test_color.cpp' ] + keymancore_tests_lib = c_compiler.find_library( 'keymancore-tests', # meson will prefix 'lib' dirs: [ core_dir / 'build/arch' / get_option('buildtype') / 'tests/kmx_test_source' ] @@ -27,7 +29,7 @@ test_include_dirs = [ test_exe = executable( 'ibus-keyman-tests', - test_files, util_files, + test_files, util_files, common_test_files, dependencies: test_deps, include_directories: test_include_dirs, ) diff --git a/resources/build/meson/standard.meson.build b/resources/build/meson/standard.meson.build index 87efed5ab55..d039080172c 100644 --- a/resources/build/meson/standard.meson.build +++ b/resources/build/meson/standard.meson.build @@ -84,3 +84,10 @@ if cpp_compiler.get_id() == 'emscripten' links += ['-O2'] endif endif + +# Disable assertions on release builds +if get_option('buildtype') != 'debug' + defns += [ + '-DNDEBUG' + ] +endif