mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-19 06:47:41 +00:00
feat(core): ldml: implementation for testing get_key_list()
- ldml::vkeys class updated to keep a set<> of keys - fix the test case to not leak! Fixes: #12298
This commit is contained in:
parent
dd11a25b27
commit
382b511dce
4 changed files with 28 additions and 4 deletions
|
|
@ -348,8 +348,7 @@ km_core_attr const & ldml_processor::attributes() const {
|
|||
}
|
||||
|
||||
km_core_keyboard_key * ldml_processor::get_key_list() const {
|
||||
km_core_keyboard_key* key_list = new km_core_keyboard_key(KM_CORE_KEYBOARD_KEY_LIST_END);
|
||||
return key_list;
|
||||
return keys.get_key_list();
|
||||
}
|
||||
|
||||
km_core_keyboard_imx * ldml_processor::get_imx_list() const {
|
||||
|
|
|
|||
|
|
@ -22,6 +22,22 @@ vkeys::add(km_core_virtual_key vk, km_core_ldml_modifier_state modifier_state, s
|
|||
const vkey_id id(vk, modifier_state);
|
||||
// assign the string
|
||||
vkey_to_string[id] = output;
|
||||
if (!output.empty()) {
|
||||
// empty string = gap key, etc.
|
||||
all_vkeys.insert(id);
|
||||
}
|
||||
}
|
||||
|
||||
km_core_keyboard_key *
|
||||
vkeys::get_key_list() const {
|
||||
km_core_keyboard_key *list = new km_core_keyboard_key[all_vkeys.size() + 1];
|
||||
std::size_t n = 0;
|
||||
for (const auto &k : all_vkeys) {
|
||||
list[n ].key = k.first;
|
||||
list[n++].modifier_flag = k.second;
|
||||
}
|
||||
list[n++] = KM_CORE_KEYBOARD_KEY_LIST_END;
|
||||
return list;
|
||||
}
|
||||
|
||||
static const uint16_t BOTH_ALT = LALTFLAG | RALTFLAG;
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
#include <unordered_map>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
|
||||
#include "keyman_core.h"
|
||||
|
||||
|
|
@ -37,6 +38,7 @@ typedef std::pair<km_core_virtual_key, km_core_ldml_modifier_state> vkey_id;
|
|||
class vkeys {
|
||||
private:
|
||||
std::map<vkey_id, std::u16string> vkey_to_string;
|
||||
std::set<vkey_id> all_vkeys;
|
||||
|
||||
public:
|
||||
vkeys();
|
||||
|
|
@ -53,6 +55,11 @@ public:
|
|||
std::u16string
|
||||
lookup(km_core_virtual_key vk, uint16_t modifier_state, bool &found) const;
|
||||
|
||||
/**
|
||||
* For implementing ldml_processor::get_key_list()
|
||||
*/
|
||||
km_core_keyboard_key* get_key_list() const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* Non-recursive internal lookup of a specific ID
|
||||
|
|
|
|||
|
|
@ -294,8 +294,9 @@ verify_key_list(const km_core_keyboard_key *actual_list, const std::u16string &e
|
|||
std::set<km::tests::key_event> actual, expected;
|
||||
std::string expected_str = convert<char16_t, char>(expected_list);
|
||||
// convert actual list
|
||||
while (actual_list != nullptr && actual_list->key != 0 && actual_list->modifier_flag != 0) {
|
||||
actual.emplace(actual_list->key, (uint16_t)actual_list->modifier_flag);
|
||||
while (actual_list != nullptr && !(actual_list->key == 0 && actual_list->modifier_flag == 0)) {
|
||||
km::tests::key_event k(actual_list->key, (uint16_t)actual_list->modifier_flag);
|
||||
actual.insert(k);
|
||||
actual_list++; // advance pointer
|
||||
}
|
||||
// parse expected_str
|
||||
|
|
@ -420,6 +421,7 @@ run_test(const km::core::path &source, const km::core::path &compiled, km::tests
|
|||
} else {
|
||||
std::cout << " .. matches." << std::endl;
|
||||
}
|
||||
delete [] actual_list;
|
||||
} break;
|
||||
case km::tests::LDML_ACTION_FAIL: {
|
||||
// test requested failure
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue