From acf156b965a92faf4bfcf8cded7cf9effd370379 Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Wed, 27 Nov 2024 07:02:44 +0000 Subject: [PATCH 01/20] chore(common/web): add test-unicodeset-parser.ts to test UnicodeSet --- .../test-unicodeset-parser-api.ts | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 common/web/types/test/ldml-keyboard/test-unicodeset-parser-api.ts diff --git a/common/web/types/test/ldml-keyboard/test-unicodeset-parser-api.ts b/common/web/types/test/ldml-keyboard/test-unicodeset-parser-api.ts new file mode 100644 index 0000000000..073e0d61f3 --- /dev/null +++ b/common/web/types/test/ldml-keyboard/test-unicodeset-parser-api.ts @@ -0,0 +1,24 @@ +import 'mocha'; +import { assert } from 'chai'; +import { UnicodeSet } from '../../src/ldml-keyboard/unicodeset-parser-api.js'; + +class MockUnicodeSet extends UnicodeSet { + constructor(public pattern: string, public ranges: number[][]) { + super(pattern, ranges); // does nothing + this.pattern = pattern; + this.ranges = ranges; + } +} + +describe('Test of Unicode-Parser-API', () => { + describe('Test UnicodeSet', () => { + it('can provide a correct ranges length', () => { + const unicodeSet = new MockUnicodeSet("[ħa-z]", [[0x41, 0x7A], [0x0127, 0x0127]]); + assert.equal(unicodeSet.length, 2); + }); + it('can provide a correct string representation', () => { + const unicodeSet = new MockUnicodeSet("[ħa-z]", [[0x41, 0x7A], [0x0127, 0x0127]]); + assert.deepEqual(unicodeSet.toString(), "[ħa-z]"); + }); + }); +}); \ No newline at end of file From d151d0999f1e5308a69fb3eac58a65561d4680ad Mon Sep 17 00:00:00 2001 From: Eberhard Beilharz Date: Wed, 27 Nov 2024 11:15:43 +0100 Subject: [PATCH 02/20] refactor(common): output number of tests when running on TC This change adds the mocha-teamcity-reporter which outputs the running tests in a special format that TeamCity can interpret. This allows TC to show which tests run as well as the number of tests run. --- common/web/types/build.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/common/web/types/build.sh b/common/web/types/build.sh index b2ada0ecbc..75273aaa2c 100755 --- a/common/web/types/build.sh +++ b/common/web/types/build.sh @@ -80,13 +80,20 @@ function do_configure() { } function do_test() { + local MOCHA_FLAGS= + + if [[ "${TEAMCITY_GIT_PATH:-}" != "" ]]; then + # we're running in TeamCity + MOCHA_FLAGS="-reporter mocha-teamcity-reporter" + fi + eslint . tsc --build test readonly C8_THRESHOLD=60 # Excludes are defined in .c8rc.json - c8 -skip-full --reporter=lcov --reporter=text --lines $C8_THRESHOLD --statements $C8_THRESHOLD --branches $C8_THRESHOLD --functions $C8_THRESHOLD mocha "${builder_extra_params[@]}" + c8 -skip-full --reporter=lcov --reporter=text --lines $C8_THRESHOLD --statements $C8_THRESHOLD --branches $C8_THRESHOLD --functions $C8_THRESHOLD mocha ${MOCHA_FLAGS} "${builder_extra_params[@]}" builder_echo warning "Coverage thresholds are currently $C8_THRESHOLD%, which is lower than ideal." builder_echo warning "Please increase threshold in build.sh as test coverage improves." } From 21736d881759c1e880f3e177401dd15c25103beb Mon Sep 17 00:00:00 2001 From: Eberhard Beilharz Date: Tue, 26 Nov 2024 21:57:54 +0100 Subject: [PATCH 03/20] refactor(developer): output number of tests when running on TC This change adds the mocha-teamcity-reporter which outputs the running tests in a special format that TeamCity can interpret. This allows TC to show which tests run as well as the number of tests run. Also refactor some of the build scripts to use functions. Note that we had to explicitly add `--check-coverage=false` (which is the default) to get successful builds when we run on TC. --- developer/src/common/web/utils/build.sh | 22 +++++++---- developer/src/kmc-analyze/build.sh | 9 ++++- developer/src/kmc-copy/build.sh | 9 ++++- developer/src/kmc-generate/build.sh | 9 ++++- developer/src/kmc-keyboard-info/build.sh | 25 +++++++----- developer/src/kmc-kmn/build.sh | 22 ++++++----- developer/src/kmc-ldml/build.sh | 50 +++++++++++------------- developer/src/kmc-model-info/build.sh | 15 +++++-- developer/src/kmc-model/build.sh | 16 +++++++- developer/src/kmc-model/package.json | 2 +- developer/src/kmc-package/build.sh | 25 +++++++----- developer/src/kmc/build.sh | 9 ++++- 12 files changed, 139 insertions(+), 74 deletions(-) diff --git a/developer/src/common/web/utils/build.sh b/developer/src/common/web/utils/build.sh index ddc6654993..b813761987 100755 --- a/developer/src/common/web/utils/build.sh +++ b/developer/src/common/web/utils/build.sh @@ -46,18 +46,24 @@ function do_build() { tsc --build } -builder_run_action clean rm -rf ./build/ -builder_run_action configure verify_npm_setup -builder_run_action build do_build +function do_test() { + local MOCHA_FLAGS= + + if [[ "${TEAMCITY_GIT_PATH:-}" != "" ]]; then + # we're running in TeamCity + MOCHA_FLAGS="-reporter mocha-teamcity-reporter" + fi -if builder_start_action test; then eslint . tsc --build test readonly C8_THRESHOLD=50 - c8 --reporter=lcov --reporter=text --exclude-after-remap --lines $C8_THRESHOLD --statements $C8_THRESHOLD --branches $C8_THRESHOLD --functions $C8_THRESHOLD mocha + c8 --reporter=lcov --reporter=text --exclude-after-remap --check-coverage=false --lines $C8_THRESHOLD --statements $C8_THRESHOLD --branches $C8_THRESHOLD --functions $C8_THRESHOLD mocha ${MOCHA_FLAGS} builder_echo warning "Coverage thresholds are currently $C8_THRESHOLD%, which is lower than ideal." builder_echo warning "Please increase threshold in build.sh as test coverage improves." - builder_finish_action success test -fi +} -builder_run_action publish builder_publish_npm +builder_run_action clean rm -rf ./build/ +builder_run_action configure verify_npm_setup +builder_run_action build do_build +builder_run_action test do_test +builder_run_action publish builder_publish_npm diff --git a/developer/src/kmc-analyze/build.sh b/developer/src/kmc-analyze/build.sh index a4844c6afc..d78bd146cd 100755 --- a/developer/src/kmc-analyze/build.sh +++ b/developer/src/kmc-analyze/build.sh @@ -26,12 +26,19 @@ builder_parse "$@" #------------------------------------------------------------------------------------------------------------------- function do_test() { + local MOCHA_FLAGS= + + if [[ "${TEAMCITY_GIT_PATH:-}" != "" ]]; then + # we're running in TeamCity + MOCHA_FLAGS="-reporter mocha-teamcity-reporter" + fi + eslint . cd test tsc --build cd .. readonly C8_THRESHOLD=70 - c8 --reporter=lcov --reporter=text --lines $C8_THRESHOLD --statements $C8_THRESHOLD --branches $C8_THRESHOLD --functions $C8_THRESHOLD mocha + c8 --reporter=lcov --reporter=text --lines $C8_THRESHOLD --statements $C8_THRESHOLD --branches $C8_THRESHOLD --functions $C8_THRESHOLD mocha ${MOCHA_FLAGS} } builder_run_action clean rm -rf ./build/ diff --git a/developer/src/kmc-copy/build.sh b/developer/src/kmc-copy/build.sh index 023f0c73bf..f916bec556 100755 --- a/developer/src/kmc-copy/build.sh +++ b/developer/src/kmc-copy/build.sh @@ -32,12 +32,19 @@ builder_parse "$@" do_test() { # note: `export TEST_SAVE_ARTIFACTS=1` to save a copy of artifacts to temp path # note: `export TEST_SAVE_FIXTURES=1` to get a copy of cloud-based fixtures saved to online/ + local MOCHA_FLAGS= + + if [[ "${TEAMCITY_GIT_PATH:-}" != "" ]]; then + # we're running in TeamCity + MOCHA_FLAGS="-reporter mocha-teamcity-reporter" + fi + eslint . cd test tsc --build cd .. readonly C8_THRESHOLD=70 - c8 -skip-full --reporter=lcov --reporter=text --lines $C8_THRESHOLD --statements $C8_THRESHOLD --branches $C8_THRESHOLD --functions $C8_THRESHOLD mocha "${builder_extra_params[@]}" + c8 -skip-full --reporter=lcov --reporter=text --lines $C8_THRESHOLD --statements $C8_THRESHOLD --branches $C8_THRESHOLD --functions $C8_THRESHOLD mocha ${MOCHA_FLAGS} "${builder_extra_params[@]}" builder_echo warning "Coverage thresholds are currently $C8_THRESHOLD%, which is lower than ideal." builder_echo warning "Please increase threshold in build.sh as test coverage improves." } diff --git a/developer/src/kmc-generate/build.sh b/developer/src/kmc-generate/build.sh index 6a86a9339f..5380ee3eb2 100755 --- a/developer/src/kmc-generate/build.sh +++ b/developer/src/kmc-generate/build.sh @@ -37,11 +37,18 @@ do_build() { } do_test() { + local MOCHA_FLAGS= + + if [[ "${TEAMCITY_GIT_PATH:-}" != "" ]]; then + # we're running in TeamCity + MOCHA_FLAGS="-reporter mocha-teamcity-reporter" + fi + eslint . cd test tsc --build cd .. - c8 --reporter=lcov --reporter=text mocha "${builder_extra_params[@]}" + c8 --reporter=lcov --reporter=text mocha ${MOCHA_FLAGS} "${builder_extra_params[@]}" } builder_run_action clean rm -rf ./build/ ./tsconfig.tsbuildinfo diff --git a/developer/src/kmc-keyboard-info/build.sh b/developer/src/kmc-keyboard-info/build.sh index c85d76db01..5ccc41a813 100755 --- a/developer/src/kmc-keyboard-info/build.sh +++ b/developer/src/kmc-keyboard-info/build.sh @@ -32,23 +32,28 @@ function do_configure() { mkdir -p src/imports echo 'export default ' > src/imports/langtags.js cat "$KEYMAN_ROOT/resources/standards-data/langtags/langtags.json" >> src/imports/langtags.js - } + +function do_test() { + local MOCHA_FLAGS= + + if [[ "${TEAMCITY_GIT_PATH:-}" != "" ]]; then + # we're running in TeamCity + MOCHA_FLAGS="-reporter mocha-teamcity-reporter" + fi + + eslint . + tsc --build test + c8 --reporter=lcov --reporter=text --exclude-after-remap --check-coverage=false mocha ${MOCHA_FLAGS} +} + #------------------------------------------------------------------------------------------------------------------- builder_run_action clean rm -rf ./build/ ./tsconfig.tsbuildinfo builder_run_action configure do_configure builder_run_action build tsc --build builder_run_action api api-extractor run --local --verbose - -#------------------------------------------------------------------------------------------------------------------- - -if builder_start_action test; then - eslint . - tsc --build test - c8 --reporter=lcov --reporter=text --exclude-after-remap mocha - builder_finish_action success test -fi +builder_run_action test do_test #------------------------------------------------------------------------------------------------------------------- diff --git a/developer/src/kmc-kmn/build.sh b/developer/src/kmc-kmn/build.sh index a073241475..5f81a367a9 100755 --- a/developer/src/kmc-kmn/build.sh +++ b/developer/src/kmc-kmn/build.sh @@ -56,27 +56,31 @@ function copy_deps() { cp ../kmcmplib/build/wasm/$BUILDER_CONFIGURATION/src/wasm-host.wasm ./build/src/import/kmcmplib/wasm-host.wasm } -if builder_start_action build; then +function do_build() { copy_deps tsc --build - builder_finish_action success build -fi +} -builder_run_action api api-extractor run --local --verbose +function do_test() { + local MOCHA_FLAGS= -#------------------------------------------------------------------------------------------------------------------- + if [[ "${TEAMCITY_GIT_PATH:-}" != "" ]]; then + # we're running in TeamCity + MOCHA_FLAGS="-reporter mocha-teamcity-reporter" + fi -if builder_start_action test; then copy_deps tsc --build test/ npm run lint readonly C8_THRESHOLD=80 - c8 --reporter=lcov --reporter=text --lines $C8_THRESHOLD --statements $C8_THRESHOLD --branches $C8_THRESHOLD --functions $C8_THRESHOLD mocha + c8 --reporter=lcov --reporter=text --lines $C8_THRESHOLD --statements $C8_THRESHOLD --branches $C8_THRESHOLD --functions $C8_THRESHOLD mocha ${MOCHA_FLAGS} builder_echo warning "Coverage thresholds are currently $C8_THRESHOLD%, which is lower than ideal." builder_echo warning "Please increase threshold in build.sh as test coverage improves." +} - builder_finish_action success test -fi +builder_run_action build do_build +builder_run_action api api-extractor run --local --verbose +builder_run_action test do_test #------------------------------------------------------------------------------------------------------------------- diff --git a/developer/src/kmc-ldml/build.sh b/developer/src/kmc-ldml/build.sh index 73a40c79d7..61fc2a695c 100755 --- a/developer/src/kmc-ldml/build.sh +++ b/developer/src/kmc-ldml/build.sh @@ -33,30 +33,19 @@ builder_describe_outputs \ builder_parse "$@" -#------------------------------------------------------------------------------------------------------------------- - -if builder_start_action clean; then +function do_clean() { rm -rf ./build/ ./tsconfig.tsbuildinfo - builder_finish_action success clean -fi +} -#------------------------------------------------------------------------------------------------------------------- - -if builder_start_action configure; then +function do_configure() { verify_npm_setup - builder_finish_action success configure -fi +} -#------------------------------------------------------------------------------------------------------------------- - -if builder_start_action build; then +function do_build() { npm run build - builder_finish_action success build -fi +} -#------------------------------------------------------------------------------------------------------------------- - -if builder_start_action build-fixtures; then +function do_build_fixtures() { # Build basic.kmx and emit its checksum mkdir -p ./build/test/fixtures node ../kmc build ./test/fixtures/basic.xml --no-compiler-version --debug --out-file ./build/test/fixtures/basic-xml.kmx @@ -65,22 +54,29 @@ if builder_start_action build-fixtures; then # Generate a binary file from basic.txt for comparison purposes node ../../../common/tools/hextobin/build/hextobin.js ./test/fixtures/basic.txt ./build/test/fixtures/basic-txt.kmx +} - builder_finish_action success build-fixtures -fi +function do_test() { + local MOCHA_FLAGS= -builder_run_action api api-extractor run --local --verbose + if [[ "${TEAMCITY_GIT_PATH:-}" != "" ]]; then + # we're running in TeamCity + MOCHA_FLAGS="-reporter mocha-teamcity-reporter" + fi -#------------------------------------------------------------------------------------------------------------------- - -if builder_start_action test; then eslint . cd test tsc -b cd .. - c8 --reporter=lcov --reporter=text mocha "${builder_extra_params[@]}" - builder_finish_action success test -fi + c8 --reporter=lcov --reporter=text mocha ${MOCHA_FLAGS} "${builder_extra_params[@]}" +} + +builder_run_action clean do_clean +builder_run_action configure do_configure +builder_run_action build do_build +builder_run_action build-fixtures do_build_fixtures +builder_run_action api api-extractor run --local --verbose +builder_run_action test do_test #------------------------------------------------------------------------------------------------------------------- diff --git a/developer/src/kmc-model-info/build.sh b/developer/src/kmc-model-info/build.sh index b1ba95c34b..2563da2224 100755 --- a/developer/src/kmc-model-info/build.sh +++ b/developer/src/kmc-model-info/build.sh @@ -50,13 +50,20 @@ builder_run_action api api-extractor run --local --verbose #------------------------------------------------------------------------------------------------------------------- -if builder_start_action test; then +function do_test() { + local MOCHA_FLAGS= + + if [[ "${TEAMCITY_GIT_PATH:-}" != "" ]]; then + # we're running in TeamCity + MOCHA_FLAGS="-reporter mocha-teamcity-reporter" + fi eslint . tsc --build test - c8 --reporter=lcov --reporter=text --exclude-after-remap --lines 80 mocha + c8 --reporter=lcov --reporter=text --exclude-after-remap --check-coverage=false --lines 80 mocha ${MOCHA_FLAGS} # TODO: remove --lines 80 and improve coverage - builder_finish_action success test -fi +} + +builder_run_action test do_test #------------------------------------------------------------------------------------------------------------------- diff --git a/developer/src/kmc-model/build.sh b/developer/src/kmc-model/build.sh index 372a145312..7186c3ef89 100755 --- a/developer/src/kmc-model/build.sh +++ b/developer/src/kmc-model/build.sh @@ -35,10 +35,24 @@ function do_build() { npm run build } +function do_test() { + local MOCHA_FLAGS= + + if [[ "${TEAMCITY_GIT_PATH:-}" != "" ]]; then + # we're running in TeamCity + MOCHA_FLAGS="-reporter mocha-teamcity-reporter" + fi + npm run lint + cd test + tsc -b + cd .. + c8 --reporter=lcov --reporter=text mocha ${MOCHA_FLAGS} +} + builder_run_action clean rm -rf ./build/ ./tsconfig.tsbuildinfo builder_run_action configure verify_npm_setup builder_run_action build do_build builder_run_action api api-extractor run --local --verbose -builder_run_action test npm test +builder_run_action test do_test builder_run_action publish builder_publish_npm diff --git a/developer/src/kmc-model/package.json b/developer/src/kmc-model/package.json index 9f95de51f8..3f95b5e181 100644 --- a/developer/src/kmc-model/package.json +++ b/developer/src/kmc-model/package.json @@ -18,7 +18,7 @@ "scripts": { "build": "tsc -b", "lint": "eslint .", - "test": "npm run lint && cd test && tsc -b && cd .. && c8 --reporter=lcov --reporter=text mocha" + "test": "./build.sh test" }, "author": "Marc Durdin (https://github.com/mcdurdin)", "contributors": [ diff --git a/developer/src/kmc-package/build.sh b/developer/src/kmc-package/build.sh index 0b2d7bda9b..bad3bb1d18 100755 --- a/developer/src/kmc-package/build.sh +++ b/developer/src/kmc-package/build.sh @@ -30,20 +30,25 @@ builder_describe_outputs \ builder_parse "$@" +function do_test() { + local MOCHA_FLAGS= + + if [[ "${TEAMCITY_GIT_PATH:-}" != "" ]]; then + # we're running in TeamCity + MOCHA_FLAGS="-reporter mocha-teamcity-reporter" + fi + eslint . + cd test + tsc --build + cd .. + c8 --reporter=lcov --reporter=text mocha ${MOCHA_FLAGS} +} + #------------------------------------------------------------------------------------------------------------------- builder_run_action clean rm -rf ./build/ ./tsconfig.tsbuildinfo builder_run_action configure verify_npm_setup builder_run_action build tsc --build builder_run_action api api-extractor run --local --verbose - -if builder_start_action test; then - eslint . - cd test - tsc --build - cd .. - c8 --reporter=lcov --reporter=text mocha - builder_finish_action success test -fi - +builder_run_action test do_test builder_run_action publish builder_publish_npm diff --git a/developer/src/kmc/build.sh b/developer/src/kmc/build.sh index 6c3dfa17bd..6e4ebc0a58 100755 --- a/developer/src/kmc/build.sh +++ b/developer/src/kmc/build.sh @@ -62,10 +62,17 @@ function do_api() { #------------------------------------------------------------------------------------------------------------------- function do_test() { + local MOCHA_FLAGS= + + if [[ "${TEAMCITY_GIT_PATH:-}" != "" ]]; then + # we're running in TeamCity + MOCHA_FLAGS="-reporter mocha-teamcity-reporter" + fi + eslint . tsc --build test/ readonly C8_THRESHOLD=50 - c8 --reporter=lcov --reporter=text --lines $C8_THRESHOLD --statements $C8_THRESHOLD --branches $C8_THRESHOLD --functions $C8_THRESHOLD mocha + c8 --reporter=lcov --reporter=text --lines $C8_THRESHOLD --statements $C8_THRESHOLD --branches $C8_THRESHOLD --functions $C8_THRESHOLD mocha ${MOCHA_FLAGS} builder_echo warning "Coverage thresholds are currently $C8_THRESHOLD%, which is lower than ideal." builder_echo warning "Please increase threshold in build.sh as test coverage improves." } From 6731cc44abae2ae6a61d919ac6dfb270649d0977 Mon Sep 17 00:00:00 2001 From: Eberhard Beilharz Date: Wed, 27 Nov 2024 12:13:57 +0100 Subject: [PATCH 04/20] chore(web): rename file missed in #12704 --- ...geContextAttachment.test.ts => pageContextAttachment.tests.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename web/src/test/auto/dom/cases/attachment/{pageContextAttachment.test.ts => pageContextAttachment.tests.ts} (100%) diff --git a/web/src/test/auto/dom/cases/attachment/pageContextAttachment.test.ts b/web/src/test/auto/dom/cases/attachment/pageContextAttachment.tests.ts similarity index 100% rename from web/src/test/auto/dom/cases/attachment/pageContextAttachment.test.ts rename to web/src/test/auto/dom/cases/attachment/pageContextAttachment.tests.ts From 3dc3f040de0dd50bbf97a5461d5cccffa0f45ca3 Mon Sep 17 00:00:00 2001 From: Eberhard Beilharz Date: Fri, 30 Aug 2024 14:44:40 +0700 Subject: [PATCH 05/20] feat(core): implement loading KMX from blob - split keyboard loading into loading KMX file into blob and then loading the keyboard processor from the blob. - deprecate `km_core_keyboard_load` - move file access next to deprecated method. This is now the only place that loads a file in Core; unit tests have some more places that load files. - introduce GTest and add unit tests for loading from blob Cherry-picked from `epic/web-core` branch. Cherry-Pick-Commit: 1deaa323ada28a6212da06d76ef886abc9c1335c Cherry-Pick-Commit: 59019cc8b79242de3c1e2a1703083f1b89d792d7 Cherry-Pick-Commit: bc4645836838e37e696f49fa6f342e548635a91a Cherry-Pick-Commit: d06aa29956227dd3277dee32fe36a94e0828f102 Cherry-Pick-Commit: 1c88166f6eea3ebb27bb5bdd05c4704ea6afb4b3 Cherry-Pick-Commit: 069cd21ecde94730ba16cfef91a8f37a225bdcd7 Cherry-Pick-Commit: 052ae2ec35e1756eebc15c691c3d690685272638 Cherry-Pick-Commit: 11a2a3ba3a3e1bd58583438ca054f290836fcae2 Part-of: #11293 Part-of: #8093 --- core/include/keyman/keyman_core_api.h | 66 ++++++++- core/include/keyman/keyman_core_api_bits.h | 5 +- core/src/keyboard.cpp | 7 +- core/src/keyboard.hpp | 5 +- core/src/km_core_keyboard_api.cpp | 119 +++++++++++++--- core/src/kmx/kmx_file.cpp | 92 +++++-------- core/src/kmx/kmx_processevent.h | 4 +- core/src/kmx/kmx_processor.cpp | 29 +++- core/src/kmx/kmx_processor.hpp | 4 +- core/src/ldml/ldml_processor.cpp | 52 +++---- core/src/ldml/ldml_processor.hpp | 9 +- core/src/meson.build | 32 +++-- core/src/mock/mock_processor.cpp | 24 +++- core/src/mock/mock_processor.hpp | 10 +- core/src/util_normalize_table_generator.cpp | 1 - core/subprojects/.gitignore | 1 + core/subprojects/gtest.wrap | 16 +++ .../tests/unit/km_core_keyboard_api.tests.cpp | 128 ++++++++++++++++++ .../unit/kmnkbd/action_set_api.tests.cpp | 5 +- .../unit/kmnkbd/actions_get_api.tests.cpp | 4 +- .../unit/kmnkbd/actions_normalize.tests.cpp | 4 +- core/tests/unit/kmnkbd/debug_api.tests.cpp | 5 +- core/tests/unit/kmnkbd/keyboard_api.tests.cpp | 8 +- core/tests/unit/kmnkbd/state_api.tests.cpp | 5 +- .../unit/kmnkbd/state_context_api.tests.cpp | 11 +- core/tests/unit/kmx/kmx.cpp | 4 +- .../unit/kmx/kmx_external_event.tests.cpp | 4 +- core/tests/unit/kmx/kmx_imx.tests.cpp | 7 +- core/tests/unit/kmx/kmx_key_list.tests.cpp | 4 +- .../unit/ldml/context_normalization.tests.cpp | 4 +- core/tests/unit/ldml/core_ldml_min.tests.cpp | 4 +- core/tests/unit/ldml/ldml.cpp | 4 +- core/tests/unit/ldml/ldml_test_source.cpp | 6 +- core/tests/unit/ldml/meson.build | 5 +- core/tests/unit/load_kmx_file.cpp | 34 +++++ core/tests/unit/load_kmx_file.hpp | 14 ++ core/tests/unit/meson.build | 30 +++- linux/debian/libkeymancore2.symbols | 3 +- 38 files changed, 579 insertions(+), 190 deletions(-) create mode 100644 core/subprojects/gtest.wrap create mode 100644 core/tests/unit/km_core_keyboard_api.tests.cpp create mode 100644 core/tests/unit/load_kmx_file.cpp create mode 100644 core/tests/unit/load_kmx_file.hpp diff --git a/core/include/keyman/keyman_core_api.h b/core/include/keyman/keyman_core_api.h index 328965e876..3c41182bab 100644 --- a/core/include/keyman/keyman_core_api.h +++ b/core/include/keyman/keyman_core_api.h @@ -1007,7 +1007,11 @@ Provides read-only information about a keyboard. typedef struct { km_core_cu const * version_string; km_core_cu const * id; + + // TODO-web-core: Deprecate this field (#12497) + // KMN_DEPRECATED km_core_path_name folder_path; + km_core_option_item const * default_options; } km_core_keyboard_attrs; @@ -1022,7 +1026,7 @@ typedef struct { : Keyman keyboard ID string. `folder_path` -: Path to the unpacked folder containing the keyboard and associated resources. +: Path to the unpacked folder containing the keyboard and associated resources (deprecated). `default_options` : Set of default values for any options included in the keyboard. @@ -1096,12 +1100,16 @@ typedef struct { ## Description +DEPRECATED: use [km_core_keyboard_load_from_blob] instead. + Parse and load keyboard from the supplied path and a pointer to the loaded keyboard -into the out paramter. +into the out parameter. ## Specification ```c */ +// TODO-web-core: Deprecate this function (#12497) +// KMN_DEPRECATED_API KMN_API km_core_status km_core_keyboard_load(km_core_path_name kb_path, @@ -1140,6 +1148,60 @@ km_core_keyboard_load(km_core_path_name kb_path, ------------------------------------------------------------------------------- +# km_core_keyboard_load_from_blob() + +## Description + +Parse and load keyboard from the supplied blob and a pointer to the loaded keyboard +into the out paramter. + +## Specification + +```c */ +KMN_API +km_core_status km_core_keyboard_load_from_blob(const km_core_path_name kb_name, + const void* blob, + const size_t blob_size, + km_core_keyboard** keyboard); + +/* +``` + +## Parameters + +`kb_name` +: a string with the name of the keyboard. + +`blob` +: a byte array containing the content of a KMX/KMX+ file. + +`blob_size` +: a size_t variable with the size of the blob in bytes. + +`keyboard` +: A pointer to result variable: A pointer to the opaque keyboard + object returned by the Processor. This memory must be freed with a + call to [km_core_keyboard_dispose]. + +## Returns + +`KM_CORE_STATUS_OK` +: On success. + +`KM_CORE_STATUS_NO_MEM` +: In the event an internal memory allocation fails. + +`KM_CORE_STATUS_IO_ERROR` +: In the event the keyboard file is unparseable for any reason + +`KM_CORE_STATUS_INVALID_ARGUMENT` +: In the event `keyboard` is null. + +`KM_CORE_STATUS_OS_ERROR` +: Bit 31 (high bit) set, bits 0-30 are an OS-specific error code. + +------------------------------------------------------------------------------- + # km_core_keyboard_dispose() ## Description diff --git a/core/include/keyman/keyman_core_api_bits.h b/core/include/keyman/keyman_core_api_bits.h index e00f4698a8..bd1f519bff 100644 --- a/core/include/keyman/keyman_core_api_bits.h +++ b/core/include/keyman/keyman_core_api_bits.h @@ -23,7 +23,6 @@ #define _kmn_unused(x) UNUSED_ ## x __attribute__((__unused__)) #else #define _kmn_unused(x) UNUSED_ ## x - #endif #if defined _WIN32 || defined __CYGWIN__ @@ -36,7 +35,7 @@ #undef _kmn_static_flag #else // How MSVC sepcifies function level attributes adn deprecation #define _kmn_and - #define _kmn_tag_fn(a) __declspec(a) + #define _kmn_tag_fn(a) __declspec(a) #define _kmn_deprecated_flag deprecated #endif #define _kmn_export_flag dllexport @@ -48,6 +47,8 @@ #define _KM_CORE_EXT_SEPARATOR ('.') #endif +#define KMN_DEPRECATED _kmn_tag_fn(_kmn_deprecated_flag) + #if defined KM_CORE_LIBRARY_STATIC #define KMN_API _kmn_tag_fn(_kmn_static_flag) #define KMN_DEPRECATED_API _kmn_tag_fn(_kmn_deprecated_flag _kmn_and _kmn_static_flag) diff --git a/core/src/keyboard.cpp b/core/src/keyboard.cpp index 2c3a0c11b2..0f104f9422 100644 --- a/core/src/keyboard.cpp +++ b/core/src/keyboard.cpp @@ -17,18 +17,16 @@ void keyboard_attributes::render() // Make attributes point to the stored values above. id = _keyboard_id.c_str(); version_string = _version_string.c_str(); - folder_path = _folder_path.c_str(); default_options = _default_opts.data(); } keyboard_attributes::keyboard_attributes(std::u16string const & kbid, std::u16string const & version, - path_type const & path, options_store const &opts) : _keyboard_id(kbid), _version_string(version), - _folder_path(path), + _folder_path(""), _default_opts(opts) { // Ensure that the default_options array will be properly terminated. @@ -40,7 +38,7 @@ keyboard_attributes::keyboard_attributes(std::u16string const & kbid, keyboard_attributes::keyboard_attributes(keyboard_attributes &&rhs) : _keyboard_id(std::move(rhs._keyboard_id)), _version_string(std::move(rhs._version_string)), - _folder_path(std::move(rhs._folder_path)), + _folder_path(""), _default_opts(std::move(rhs._default_opts)) { rhs.id = rhs.version_string = nullptr; @@ -58,7 +56,6 @@ json & km::core::operator << (json & j, km::core::keyboard_attributes const & kb { j << json::object << "id" << kb.id - << "folder" << kb._folder_path << "version" << kb.version_string << "rules" << json::array << json::close; diff --git a/core/src/keyboard.hpp b/core/src/keyboard.hpp index 142bf40e86..2ca7118d87 100644 --- a/core/src/keyboard.hpp +++ b/core/src/keyboard.hpp @@ -26,6 +26,7 @@ namespace core { std::u16string _keyboard_id; std::u16string _version_string; + // unused and deprecated core::path _folder_path; std::vector