diff --git a/common/engine/keyboardprocessor/include/keyboardprocessor.h.in b/common/engine/keyboardprocessor/include/keyboardprocessor.h.in index 6e0a38b527..52037f86eb 100644 --- a/common/engine/keyboardprocessor/include/keyboardprocessor.h.in +++ b/common/engine/keyboardprocessor/include/keyboardprocessor.h.in @@ -90,7 +90,7 @@ typedef uint32_t km_kbp_status; // Status return code. typedef struct km_kbp_context km_kbp_context; typedef struct km_kbp_keyboard km_kbp_keyboard; typedef struct km_kbp_state km_kbp_state; -typedef struct km_kbp_options_set km_kbp_options_set; +typedef struct km_kbp_options_set km_kbp_options_set; // Forward declarations // @@ -148,7 +148,7 @@ enum km_kbp_context_type { typedef struct { uint8_t type; - uint8_t reserved[3]; + uint8_t _reserved[3]; union { km_kbp_usv character; uint32_t marker; @@ -332,7 +332,7 @@ services framework to acheive the expected effect. */ typedef struct { uint8_t type; - uint8_t __reserved[3]; + uint8_t _reserved[3]; union { uintptr_t marker; // MARKER type km_kbp_option const * option; // OPT types diff --git a/common/engine/keyboardprocessor/meson.build b/common/engine/keyboardprocessor/meson.build index 0cccf42be6..0b816683e7 100644 --- a/common/engine/keyboardprocessor/meson.build +++ b/common/engine/keyboardprocessor/meson.build @@ -13,6 +13,10 @@ project('keyboardprocessor', 'cpp', 'c', compiler = meson.get_compiler('cpp') +if compiler.get_id() == 'msvc' + add_global_arguments('/source-charset:utf-8', language: ['c', 'cpp']) +endif + py = import('python3') python = py.find_python() diff --git a/common/engine/keyboardprocessor/src/keyboard.hpp b/common/engine/keyboardprocessor/src/keyboard.hpp index c936d0ec2a..844108504e 100644 --- a/common/engine/keyboardprocessor/src/keyboard.hpp +++ b/common/engine/keyboardprocessor/src/keyboard.hpp @@ -14,7 +14,7 @@ #include namespace std { - using namespace std::experimental; + namespace filesystem = std::experimental::filesystem; } // Forward declartions @@ -28,7 +28,7 @@ namespace kbp { std::string const _keyboard_id; std::string const _version_string; - std::filesystem::path const _folder_path; + std::string const _folder_path; public: keyboard(std::filesystem::path const &); @@ -36,13 +36,14 @@ namespace kbp inline keyboard::keyboard(std::filesystem::path const & path) - : _keyboard_id(path.stem()), + : _keyboard_id(path.stem().string()), _version_string("3.145"), - _folder_path(path.parent_path()) + _folder_path(path.parent_path().string()) { version_string = _version_string.c_str(); id = _keyboard_id.c_str(); folder_path = _folder_path.c_str(); + default_options = nullptr; } } diff --git a/common/engine/keyboardprocessor/src/keyboardprocessor.cpp b/common/engine/keyboardprocessor/src/keyboardprocessor.cpp index 6bb167f2a0..07dd21ec75 100644 --- a/common/engine/keyboardprocessor/src/keyboardprocessor.cpp +++ b/common/engine/keyboardprocessor/src/keyboardprocessor.cpp @@ -86,6 +86,7 @@ km_kbp_status km_kbp_process_event(km_kbp_state *state, break; default: + { auto shift_state = modifier_state & KM_KBP_MODIFIER_SHIFT; // Only process further one of the shift states has something to output. if (table[0][vk][0] || table[1][vk][0]) @@ -96,7 +97,7 @@ km_kbp_status km_kbp_process_event(km_kbp_state *state, { km_kbp_usv usv = *c; state->context().emplace_back(km_kbp_context_item {KM_KBP_CT_CHAR,{0,},{usv}}); - state->actions.emplace_back(km_kbp_action_item {KM_KBP_IT_CHAR, {0,}, {.character = usv}}); + state->actions.emplace_back(km_kbp_action_item {KM_KBP_IT_CHAR, {0,}, {usv}}); } state->actions.emplace_back(km_kbp_action_item {KM_KBP_IT_END, {0,}, {0}}); @@ -107,6 +108,7 @@ km_kbp_status km_kbp_process_event(km_kbp_state *state, state->actions.emplace_back(km_kbp_action_item {KM_KBP_IT_ALERT, {0,}, {0}}); state->actions.emplace_back(km_kbp_action_item {KM_KBP_IT_END, {0,}, {0}}); break; + } } } catch (std::bad_alloc) diff --git a/common/engine/keyboardprocessor/src/km_kbp_keyboard_api.cpp b/common/engine/keyboardprocessor/src/km_kbp_keyboard_api.cpp index c98093a6ae..bda8464e16 100644 --- a/common/engine/keyboardprocessor/src/km_kbp_keyboard_api.cpp +++ b/common/engine/keyboardprocessor/src/km_kbp_keyboard_api.cpp @@ -36,7 +36,7 @@ km_kbp_status km_kbp_keyboard_load(char const *kb_path, // if (stat.type() != std::filesystem::file_type::regular) // return KM_KBP_STATUS_INVALID_ARGUMENT; - *keyboard = static_cast(new km::kbp::keyboard("/dev/null/unk_dummy.kmx")); + *keyboard = static_cast(new km::kbp::keyboard(kb_path)); return KM_KBP_STATUS_OK; } diff --git a/common/engine/keyboardprocessor/src/km_kbp_state_api.cpp b/common/engine/keyboardprocessor/src/km_kbp_state_api.cpp index d8ea53e94f..ea7cb3268a 100644 --- a/common/engine/keyboardprocessor/src/km_kbp_state_api.cpp +++ b/common/engine/keyboardprocessor/src/km_kbp_state_api.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include diff --git a/common/engine/keyboardprocessor/src/meson.build b/common/engine/keyboardprocessor/src/meson.build index 27e8f9caf4..471ce5a298 100644 --- a/common/engine/keyboardprocessor/src/meson.build +++ b/common/engine/keyboardprocessor/src/meson.build @@ -21,6 +21,7 @@ if compiler.get_id() == 'gcc' or compiler.get_id() == 'clang' '-fvisibility=hidden', '-fvisibility-inlines-hidden' ] + links = ['-lstdc++fs'] if compiler.get_id() == 'clang' warns += [ @@ -38,11 +39,12 @@ endif if compiler.get_id() == 'msvc' warns = [] flags = [] - defns = [ + defns += [ '-D_SCL_SECURE_NO_WARNINGS', '-D_CRT_SECURE_NO_WARNINGS', '-DUNICODE' ] + links = [] endif pkg = import('pkgconfig') @@ -59,7 +61,7 @@ lib = library('kmnkbp0', 'km_kbp_state_api.cpp', 'json.cpp', cpp_args: defns + warns + flags, - link_args: ['-lstdc++fs'], + link_args: links, version: meson.project_version(), include_directories: inc, install: true) diff --git a/common/engine/keyboardprocessor/tests/unit/json/meson.build b/common/engine/keyboardprocessor/tests/unit/json/meson.build index 24adc83903..6b1f31633c 100644 --- a/common/engine/keyboardprocessor/tests/unit/json/meson.build +++ b/common/engine/keyboardprocessor/tests/unit/json/meson.build @@ -5,7 +5,7 @@ # e = executable('jsontest', 'jsontest.cpp', - include_directories: [inc, libsrc], + include_directories: [libsrc], objects: lib.extract_objects('json.cpp')) test('jsontest', e, args: 'jsontest.json') test('jsontestOutput', python, is_parallel: false, args: diff --git a/common/engine/keyboardprocessor/tests/unit/kmnkbd/context_api.cpp b/common/engine/keyboardprocessor/tests/unit/kmnkbd/context_api.cpp index ec747a5808..cb12c568cf 100644 --- a/common/engine/keyboardprocessor/tests/unit/kmnkbd/context_api.cpp +++ b/common/engine/keyboardprocessor/tests/unit/kmnkbd/context_api.cpp @@ -30,8 +30,8 @@ namespace auto const bmp_ctxt_size = count_codepoints(initial_bmp_context), smp_ctxt_size = count_codepoints(initial_smp_context); km_kbp_context_item test_marker_ctxt[2] = { - {KM_KBP_CT_MARKER, {0,}, 0xDEADBEEF}, - {KM_KBP_CT_END, {0,}, 0} + {KM_KBP_CT_MARKER, {0,}, {0xDEADBEEF}}, + {KM_KBP_CT_END, {0,}, {0}} }; @@ -40,7 +40,7 @@ namespace #define try_status(expr) \ {auto __s = (expr); if (__s != KM_KBP_STATUS_OK) return 100*__LINE__+__s;} -int main(int argc, char * argv[]) +int main(int, char * []) { km_kbp_context_item *ctxt1, *ctxt2; // Test UTF16 to context_item conversion. diff --git a/common/engine/keyboardprocessor/tests/unit/kmnkbd/keyboard_api.cpp b/common/engine/keyboardprocessor/tests/unit/kmnkbd/keyboard_api.cpp new file mode 100644 index 0000000000..2ab38c8759 --- /dev/null +++ b/common/engine/keyboardprocessor/tests/unit/kmnkbd/keyboard_api.cpp @@ -0,0 +1,39 @@ +/* + Copyright: © 2018 SIL International. + Description: Tests for the Keyboard API family of functions. + Create Date: 30 Oct 2018 + Authors: Tim Eves (TSE) +*/ +#include + +#include +#include + +namespace std { + namespace filesystem = std::experimental::filesystem; +} + + +//#include "keyboard.hpp" + +namespace +{ + std::filesystem::path const test_kb_path = "/a/dummy/keyboard.mock"; +} + +#define try_status(expr) \ +{auto __s = (expr); if (__s != KM_KBP_STATUS_OK) return 100*__LINE__+__s;} + +int main(int, char *[]) +{ + km_kbp_keyboard * test_kb = nullptr; + + try_status(km_kbp_keyboard_load(test_kb_path.string().c_str(), &test_kb)); + auto kb_attrs = km_kbp_keyboard_get_attrs(test_kb); + if (kb_attrs->folder_path != test_kb_path.parent_path().string()) + return __LINE__; + + km_kbp_keyboard_dispose(test_kb); + + return 0; +} diff --git a/common/engine/keyboardprocessor/tests/unit/kmnkbd/meson.build b/common/engine/keyboardprocessor/tests/unit/kmnkbd/meson.build index f69b6bb335..f3329ebe35 100644 --- a/common/engine/keyboardprocessor/tests/unit/kmnkbd/meson.build +++ b/common/engine/keyboardprocessor/tests/unit/kmnkbd/meson.build @@ -7,5 +7,10 @@ ctxt = executable('context-api', 'context_api.cpp', include_directories: [inc, libsrc], - dependencies: [kmnkbp]) + objects: lib.extract_objects('km_kbp_context_api.cpp', 'json.cpp')) +keyb = executable('keyboard-api', 'keyboard_api.cpp', + include_directories: [inc, libsrc], + link_args: links, + objects: lib.extract_objects('km_kbp_keyboard_api.cpp', 'json.cpp', 'km_kbp_options_api.cpp')) test('context-api', ctxt) +test('keyboard-api', keyb) diff --git a/common/engine/keyboardprocessor/tests/unit/utftest/meson.build b/common/engine/keyboardprocessor/tests/unit/utftest/meson.build index 8374075478..456b7a5391 100644 --- a/common/engine/keyboardprocessor/tests/unit/utftest/meson.build +++ b/common/engine/keyboardprocessor/tests/unit/utftest/meson.build @@ -4,5 +4,5 @@ # Authors: Tim Eves (TSE) # -e = executable('utftest', 'utftest.cpp', include_directories: [inc, libsrc]) +e = executable('utftest', 'utftest.cpp', include_directories: [libsrc]) test('utftest', e)