From 4a511bde1ebe852e15cdfb00323837e8a28f9b8a Mon Sep 17 00:00:00 2001
From: rc-swag <58423624+rc-swag@users.noreply.github.com>
Date: Tue, 12 Dec 2023 23:49:04 +1000
Subject: [PATCH 1/7] fix(core): clear core context on invalidate cache
---
common/test/keyboards/baseline/baseline.kpj | 7 +++++++
.../baseline/k_049___context_and_invalidate.kmn | 16 ++++++++++++++++
.../baseline/k_049___context_and_invalidate.kmx | Bin 0 -> 368 bytes
core/src/kmx/kmx_processor.cpp | 1 +
core/tests/unit/kmx/kmx.cpp | 2 ++
core/tests/unit/kmx/meson.build | 3 ++-
6 files changed, 28 insertions(+), 1 deletion(-)
create mode 100644 common/test/keyboards/baseline/k_049___context_and_invalidate.kmn
create mode 100644 common/test/keyboards/baseline/k_049___context_and_invalidate.kmx
diff --git a/common/test/keyboards/baseline/baseline.kpj b/common/test/keyboards/baseline/baseline.kpj
index b98e7519fda..3371c33490d 100644
--- a/common/test/keyboards/baseline/baseline.kpj
+++ b/common/test/keyboards/baseline/baseline.kpj
@@ -323,5 +323,12 @@
1.0
.kmn
+
+ id_k_049___context_and_invalidate
+ k_049___context_and_invalidate.kmn
+ k_049___context_and_invalidate.kmn
+ 1.0
+ .kmn
+
diff --git a/common/test/keyboards/baseline/k_049___context_and_invalidate.kmn b/common/test/keyboards/baseline/k_049___context_and_invalidate.kmn
new file mode 100644
index 00000000000..bb305145942
--- /dev/null
+++ b/common/test/keyboards/baseline/k_049___context_and_invalidate.kmn
@@ -0,0 +1,16 @@
+store(&NAME) '049 - context and invalidate'
+c Description: Tests that core context is cleared when invalidated See #10182.
+c keys: [K_A][K_B][K_ENTER][K_C]
+c expected: c
+c context:
+
+store(&version) '10.0'
+
+begin Unicode > use(Main)
+
+group(Main) using keys
+
+c Test if context was not invalidated by [K_ENTER] context will be 'abd'
+
+'a' 'b' + [K_C] > 'abd'
+
diff --git a/common/test/keyboards/baseline/k_049___context_and_invalidate.kmx b/common/test/keyboards/baseline/k_049___context_and_invalidate.kmx
new file mode 100644
index 0000000000000000000000000000000000000000..64efeb72f23159cfdccf69dce247461b6f9d04c3
GIT binary patch
literal 368
zcmYL@y-q?w5JnFT5F2fT#OhX5Y9OJp1C>}1X^@2W;-!F~5;aEOz{2_)Zhw3-WDVY5HeWGHk&Lp0?#Q;{%TWHs^2b=S^C0(9mnV6YioD6Q
zROM4XWJAhvS3+-DYtmFhpDA~ok#nBTP1@{{u_LEk*uBcv`3mYdE06
zfG)@M)GfE~rWYDIr(ANSH@3yBWj=D6>CV$Od=vH=>6oQ=i?s8w1Oxevkiq}G15fKQ
P?!d&+TyiG<>$}1VMpY|6
literal 0
HcmV?d00001
diff --git a/core/src/kmx/kmx_processor.cpp b/core/src/kmx/kmx_processor.cpp
index 6790d5b46df..1fa0734e074 100644
--- a/core/src/kmx/kmx_processor.cpp
+++ b/core/src/kmx/kmx_processor.cpp
@@ -247,6 +247,7 @@ kmx_processor::internal_process_queued_actions(km_core_state *state) {
}
break;
case QIT_INVALIDATECONTEXT:
+ state->context().clear();
state->actions().push_invalidate_context();
break;
default:
diff --git a/core/tests/unit/kmx/kmx.cpp b/core/tests/unit/kmx/kmx.cpp
index cf1105d3f3b..e1c1845739f 100644
--- a/core/tests/unit/kmx/kmx.cpp
+++ b/core/tests/unit/kmx/kmx.cpp
@@ -147,6 +147,8 @@ apply_action(
}
} break;
case KM_CORE_IT_INVALIDATE_CONTEXT:
+ context.clear();
+ text_store.clear();
std::cout << "action: context invalidated (markers cleared)" << std::endl;
break;
case KM_CORE_IT_EMIT_KEYSTROKE:
diff --git a/core/tests/unit/kmx/meson.build b/core/tests/unit/kmx/meson.build
index a2e43ff1d49..289b59b7b64 100644
--- a/core/tests/unit/kmx/meson.build
+++ b/core/tests/unit/kmx/meson.build
@@ -79,7 +79,8 @@ tests = [
'k_045___deadkey_and_context',
'k_046___deadkey_and_contextex',
'k_047___caps_always_off_initially_on',
- 'k_048___modifier_keys_keep_context'
+ 'k_048___modifier_keys_keep_context',
+ 'k_049___context_and_invalidate'
]
node = find_program('node', required: true)
From 437f938368377b0768186e1d50f0921c038a6b10 Mon Sep 17 00:00:00 2001
From: rc-swag <58423624+rc-swag@users.noreply.github.com>
Date: Thu, 14 Dec 2023 12:25:32 +1000
Subject: [PATCH 2/7] fix(core): fix baseline test cases k_000 and k_0008
Test k_000___null_keyboard has been updated as the [RALT K_B] should
cause the context to be reset.
Test k_008___vkey_input__ctrl_alt_2_ has been updated as the [LCTRL LALT
K_B] does not match a keyboard rule the context is deemed invalid and should be
reset.
It could be a consideration to modify the text_store object to better
reflect the state of a applications context however this would mean
we would need two expected results one for the application and one
for the context
---
.../keyboards/baseline/k_000___null_keyboard.kmn | 6 +++---
.../baseline/k_008___vkey_input__ctrl_alt_2_.kmn | 6 +++---
.../baseline/k_049___context_and_invalidate.kmx | Bin 368 -> 0 bytes
....kmn => k_049___enter_invalidates_context.kmn} | 5 +++--
.../k_049___enter_invalidates_context.kmx | Bin 0 -> 376 bytes
core/tests/unit/kmx/meson.build | 2 +-
6 files changed, 10 insertions(+), 9 deletions(-)
delete mode 100644 common/test/keyboards/baseline/k_049___context_and_invalidate.kmx
rename common/test/keyboards/baseline/{k_049___context_and_invalidate.kmn => k_049___enter_invalidates_context.kmn} (56%)
create mode 100644 common/test/keyboards/baseline/k_049___enter_invalidates_context.kmx
diff --git a/common/test/keyboards/baseline/k_000___null_keyboard.kmn b/common/test/keyboards/baseline/k_000___null_keyboard.kmn
index b1304c20c8c..30985b275b1 100644
--- a/common/test/keyboards/baseline/k_000___null_keyboard.kmn
+++ b/common/test/keyboards/baseline/k_000___null_keyboard.kmn
@@ -1,8 +1,8 @@
store(&NAME) '000 - null keyboard'
-c Description: Tests null keyboard
+c Description: Tests null keyboard
c keys: [K_A][RALT K_B][SHIFT K_C]
-c expected: aC
-c context:
+c expected: C
+c context:
store(&version) '6.0'
diff --git a/common/test/keyboards/baseline/k_008___vkey_input__ctrl_alt_2_.kmn b/common/test/keyboards/baseline/k_008___vkey_input__ctrl_alt_2_.kmn
index ac267fa15b5..895f8da8c35 100644
--- a/common/test/keyboards/baseline/k_008___vkey_input__ctrl_alt_2_.kmn
+++ b/common/test/keyboards/baseline/k_008___vkey_input__ctrl_alt_2_.kmn
@@ -1,13 +1,13 @@
store(&NAME) '008 - vkey input (ctrl alt 2)'
c Description: Tests basic vkey input with control and alt (Unicode)
c keys: [LCTRL LALT K_A][LCTRL LALT K_B][LCTRL LALT K_C]
-c expected: \u0E01\u0E03
-c context:
+c expected: \u0E03
+c context:
store(&version) '6.0'
begin Unicode > use(Main)
-
+
group(Main) using keys
+ [CTRL ALT K_A] > U+0E01
diff --git a/common/test/keyboards/baseline/k_049___context_and_invalidate.kmx b/common/test/keyboards/baseline/k_049___context_and_invalidate.kmx
deleted file mode 100644
index 64efeb72f23159cfdccf69dce247461b6f9d04c3..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001
literal 368
zcmYL@y-q?w5JnFT5F2fT#OhX5Y9OJp1C>}1X^@2W;-!F~5;aEOz{2_)Zhw3-WDVY5HeWGHk&Lp0?#Q;{%TWHs^2b=S^C0(9mnV6YioD6Q
zROM4XWJAhvS3+-DYtmFhpDA~ok#nBTP1@{{u_LEk*uBcv`3mYdE06
zfG)@M)GfE~rWYDIr(ANSH@3yBWj=D6>CV$Od=vH=>6oQ=i?s8w1Oxevkiq}G15fKQ
P?!d&+TyiG<>$}1VMpY|6
diff --git a/common/test/keyboards/baseline/k_049___context_and_invalidate.kmn b/common/test/keyboards/baseline/k_049___enter_invalidates_context.kmn
similarity index 56%
rename from common/test/keyboards/baseline/k_049___context_and_invalidate.kmn
rename to common/test/keyboards/baseline/k_049___enter_invalidates_context.kmn
index bb305145942..8476fc663e6 100644
--- a/common/test/keyboards/baseline/k_049___context_and_invalidate.kmn
+++ b/common/test/keyboards/baseline/k_049___enter_invalidates_context.kmn
@@ -1,5 +1,6 @@
-store(&NAME) '049 - context and invalidate'
-c Description: Tests that core context is cleared when invalidated See #10182.
+store(&NAME) '049 - enter_invalidates_context'
+c Description: Tests that core context is cleared when kb processor
+c determines its invalid. eg Enter key See #10182.
c keys: [K_A][K_B][K_ENTER][K_C]
c expected: c
c context:
diff --git a/common/test/keyboards/baseline/k_049___enter_invalidates_context.kmx b/common/test/keyboards/baseline/k_049___enter_invalidates_context.kmx
new file mode 100644
index 0000000000000000000000000000000000000000..f67141b3bc8ed9745a0668519a5928c03c77f34b
GIT binary patch
literal 376
zcmYL_J8r^I5JfKy1Vlka8VZYo4g?WRIzB=a1{yv}7nzs>6hML~B0Hc!SwX}uSOdFY
z0jbkbgfq5*kxd_w|G
zu!jfugI~x%n%Ov*&J%M`MoX?H`qEsU7Qwl!s-ESj2orK2_?2EYMSs%uj`E3?Uz2~+
zGV0oplM3pouC7|>3U`!(dkW0jo;B0fZ?z|Uo2o;%7wiuwq=ts{OoQD%b5e)*j^Ju0
Wjr(MilYO22z8R$zcpCH8FiIEfBQ3-L
literal 0
HcmV?d00001
diff --git a/core/tests/unit/kmx/meson.build b/core/tests/unit/kmx/meson.build
index 289b59b7b64..abeb12ace18 100644
--- a/core/tests/unit/kmx/meson.build
+++ b/core/tests/unit/kmx/meson.build
@@ -80,7 +80,7 @@ tests = [
'k_046___deadkey_and_contextex',
'k_047___caps_always_off_initially_on',
'k_048___modifier_keys_keep_context',
- 'k_049___context_and_invalidate'
+ 'k_049___enter_invalidates_context'
]
node = find_program('node', required: true)
From 8e20fcf6b24dfe4240ba7db3bec61675f3f60420 Mon Sep 17 00:00:00 2001
From: rc-swag <58423624+rc-swag@users.noreply.github.com>
Date: Thu, 14 Dec 2023 14:20:05 +1000
Subject: [PATCH 3/7] fix(core): missed checking in baseline.kpj
---
common/test/keyboards/baseline/baseline.kpj | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/common/test/keyboards/baseline/baseline.kpj b/common/test/keyboards/baseline/baseline.kpj
index 3371c33490d..3ce7e9b83c1 100644
--- a/common/test/keyboards/baseline/baseline.kpj
+++ b/common/test/keyboards/baseline/baseline.kpj
@@ -324,9 +324,9 @@
.kmn
- id_k_049___context_and_invalidate
- k_049___context_and_invalidate.kmn
- k_049___context_and_invalidate.kmn
+ id_k_049___enter_invalidates_context
+ k_049___enter_invalidates_context.kmn
+ k_049___enter_invalidates_context.kmn
1.0
.kmn
From 2f737981f7c9bc3e5a10d62b4e757888c25799cf Mon Sep 17 00:00:00 2001
From: rc-swag <58423624+rc-swag@users.noreply.github.com>
Date: Fri, 15 Dec 2023 11:20:08 +1000
Subject: [PATCH 4/7] fix(core): add expected_context to keyboard unit tests
The unit tests needed to be updated to handle the cases
where the context is invalidated by a keystroke. However, they
still need to be able to verify the final string the application
should recieve. To do this a expected context token has been added
to the unit test format.
---
.../baseline/k_000___null_keyboard.kmn | 3 +-
.../baseline/k_000___null_keyboard.kmx | Bin 314 -> 316 bytes
.../k_008___vkey_input__ctrl_alt_2_.kmn | 3 +-
.../k_008___vkey_input__ctrl_alt_2_.kmx | Bin 386 -> 388 bytes
.../k_049___enter_invalidates_context.kmn | 3 +-
.../k_049___enter_invalidates_context.kmx | Bin 376 -> 376 bytes
.../tests/kmx_test_source/kmx_test_source.cpp | 4 ++
.../tests/kmx_test_source/kmx_test_source.hpp | 1 +
core/tests/unit/kmx/kmx.cpp | 47 +++++++++++-------
9 files changed, 40 insertions(+), 21 deletions(-)
diff --git a/common/test/keyboards/baseline/k_000___null_keyboard.kmn b/common/test/keyboards/baseline/k_000___null_keyboard.kmn
index 30985b275b1..ecae49acde0 100644
--- a/common/test/keyboards/baseline/k_000___null_keyboard.kmn
+++ b/common/test/keyboards/baseline/k_000___null_keyboard.kmn
@@ -1,7 +1,8 @@
store(&NAME) '000 - null keyboard'
c Description: Tests null keyboard
c keys: [K_A][RALT K_B][SHIFT K_C]
-c expected: C
+c expected: aC
+c expected context: C
c context:
store(&version) '6.0'
diff --git a/common/test/keyboards/baseline/k_000___null_keyboard.kmx b/common/test/keyboards/baseline/k_000___null_keyboard.kmx
index 2a49864d0044876a4e4de92c762e54c6791ce423..2ac1a0f65f7eacb2c86137b5e428632f5695f5e7 100644
GIT binary patch
delta 104
zcmdnRw1CVV8u`$=s2q@~#V8Ecj
q;LDK6kjan-Tp+H_HLo!1?LkdGGP{asmlFejUMp*#mSQJA5
delta 102
zcmdnPw2O(yJ0c{QfsKK|h35?0L>>uI2}TBn|3JWi1gs`nx-+s(Y|Pa+1d6&d7%(U>
o_%b9iWHRId`IbQJ#1IN(XEG!+a&06_T?q5uE@
diff --git a/common/test/keyboards/baseline/k_008___vkey_input__ctrl_alt_2_.kmn b/common/test/keyboards/baseline/k_008___vkey_input__ctrl_alt_2_.kmn
index 895f8da8c35..d1660c40f26 100644
--- a/common/test/keyboards/baseline/k_008___vkey_input__ctrl_alt_2_.kmn
+++ b/common/test/keyboards/baseline/k_008___vkey_input__ctrl_alt_2_.kmn
@@ -1,7 +1,8 @@
store(&NAME) '008 - vkey input (ctrl alt 2)'
c Description: Tests basic vkey input with control and alt (Unicode)
c keys: [LCTRL LALT K_A][LCTRL LALT K_B][LCTRL LALT K_C]
-c expected: \u0E03
+c expected: \u0E01\u0E03
+c expected context: \u0E03
c context:
store(&version) '6.0'
diff --git a/common/test/keyboards/baseline/k_008___vkey_input__ctrl_alt_2_.kmx b/common/test/keyboards/baseline/k_008___vkey_input__ctrl_alt_2_.kmx
index 0f7e29779eda3a9ac306e7fb2e3a750482163bbe..b12a0f15c85c201507c654b35744a967bf70d2f9 100644
GIT binary patch
delta 153
zcmZo-Zeix}jtB{6U}In~_?r8BB9DZq9wP(8e;{B$0xc6Q-5F&jHZ~d>0Y%*z3>Xv`
zd>IlMG8yuKd_y3gfx(F(6v)eDNM^`qNMT3?inswy3YcujsA#|kXv`
zd>IlMG8yuKd`lp9Vh9DYGZ~T@@)=SXQh_2aKy&;i8#5{z@B(=W4h#%sK#?jSb_VkK
Spkg&ZeghCQf&>_t!6X3fnHT{8
diff --git a/common/test/keyboards/baseline/k_049___enter_invalidates_context.kmn b/common/test/keyboards/baseline/k_049___enter_invalidates_context.kmn
index 8476fc663e6..78363865ef3 100644
--- a/common/test/keyboards/baseline/k_049___enter_invalidates_context.kmn
+++ b/common/test/keyboards/baseline/k_049___enter_invalidates_context.kmn
@@ -2,7 +2,8 @@ store(&NAME) '049 - enter_invalidates_context'
c Description: Tests that core context is cleared when kb processor
c determines its invalid. eg Enter key See #10182.
c keys: [K_A][K_B][K_ENTER][K_C]
-c expected: c
+c expected: abc
+c expected context: c
c context:
store(&version) '10.0'
diff --git a/common/test/keyboards/baseline/k_049___enter_invalidates_context.kmx b/common/test/keyboards/baseline/k_049___enter_invalidates_context.kmx
index f67141b3bc8ed9745a0668519a5928c03c77f34b..916a4a46625113bebba4aba17872cab7223f6235 100644
GIT binary patch
delta 54
zcmeyt^n;1VJ0c{Qfs27*v+}g)i9CPAjTsmi+!+iQ6c~IN5*acX@_>9p2E)nnjMj{T
IlcO1B0dZUli2wiq
delta 54
zcmeyt^n;1VJ0c{Qfs29R_i@gx6M6oK8!<32xHA|qC@}akBr;?&M0sxLQ3_kz>
diff --git a/core/tests/kmx_test_source/kmx_test_source.cpp b/core/tests/kmx_test_source/kmx_test_source.cpp
index f506fde062d..1dcbdf3091d 100644
--- a/core/tests/kmx_test_source/kmx_test_source.cpp
+++ b/core/tests/kmx_test_source/kmx_test_source.cpp
@@ -110,11 +110,13 @@ KmxTestSource::load_source(
const km::core::path &path,
std::string &keys,
std::u16string &expected,
+ std::u16string &expected_context,
std::u16string &context,
kmx_options &options,
bool &expected_beep) {
const std::string s_keys = "c keys: ";
const std::string s_expected = "c expected: ";
+ const std::string s_expected_context = "c expected context: ";
const std::string s_context = "c context: ";
const std::string s_option = "c option: ";
const std::string s_option_expected = "c expected option: ";
@@ -143,6 +145,8 @@ KmxTestSource::load_source(
} else {
expected = parse_source_string(line);
}
+ } else if (is_token(s_expected_context, line)) {
+ expected_context = parse_source_string(line);
} else if (is_token(s_context, line)) {
context = parse_source_string(line);
} else if (is_token(s_option, line)) {
diff --git a/core/tests/kmx_test_source/kmx_test_source.hpp b/core/tests/kmx_test_source/kmx_test_source.hpp
index bd7f19b5866..0a8e125c03e 100644
--- a/core/tests/kmx_test_source/kmx_test_source.hpp
+++ b/core/tests/kmx_test_source/kmx_test_source.hpp
@@ -28,6 +28,7 @@ class KmxTestSource {
const km::core::path &path,
std::string &keys,
std::u16string &expected,
+ std::u16string &expected_context,
std::u16string &context,
kmx_options &options,
bool &expected_beep);
diff --git a/core/tests/unit/kmx/kmx.cpp b/core/tests/unit/kmx/kmx.cpp
index e1c1845739f..d508655c38b 100644
--- a/core/tests/unit/kmx/kmx.cpp
+++ b/core/tests/unit/kmx/kmx.cpp
@@ -63,7 +63,9 @@ apply_action(
std::u16string &text_store,
std::vector &context,
km::tests::kmx_options &options,
- km::tests::KmxTestSource &test_source) {
+ km::tests::KmxTestSource &test_source,
+ bool &context_invalidated
+ ) {
switch (act.type) {
case KM_CORE_IT_END:
assert(false);
@@ -148,7 +150,7 @@ apply_action(
} break;
case KM_CORE_IT_INVALIDATE_CONTEXT:
context.clear();
- text_store.clear();
+ context_invalidated = true;
std::cout << "action: context invalidated (markers cleared)" << std::endl;
break;
case KM_CORE_IT_EMIT_KEYSTROKE:
@@ -167,14 +169,20 @@ apply_action(
int
run_test(const km::core::path &source, const km::core::path &compiled) {
std::string keys = "";
- std::u16string expected = u"", context = u"";
+ std::u16string expected = u"", expected_context = u"NOT SUPPLIED", context = u"";
km::tests::kmx_options options;
bool expected_beep = false;
km::tests::KmxTestSource test_source;
- int result = test_source.load_source(source, keys, expected, context, options, expected_beep);
+ int result = test_source.load_source(source, keys, expected, expected_context, context, options, expected_beep);
if (result != 0) return result;
+ // If an expect_context is not provided, default to expected == expect_context
+ std::cout << "expected_context = " << string_to_hex(expected_context) << " [" << expected_context << "]" << std::endl;
+ if (expected_context == u"NOT SUPPLIED") {
+ expected_context = expected;
+ }
+
std::cout << "source file = " << source << std::endl
<< "compiled file = " << compiled << std::endl;
@@ -210,6 +218,8 @@ run_test(const km::core::path &source, const km::core::path &compiled) {
// Setup baseline text store
std::u16string text_store = context;
+ // used to stop comparing text_store to context if this flag is set
+ bool context_invalidated = false;
// Run through key events, applying output for each event
for (auto p = test_source.next_key(keys); p.vk != 0; p = test_source.next_key(keys)) {
@@ -225,16 +235,17 @@ run_test(const km::core::path &source, const km::core::path &compiled) {
try_status(km_core_process_event(test_state, p.vk, p.modifier_state | test_source.caps_lock_state(), key_down, KM_CORE_EVENT_FLAG_DEFAULT));
for (auto act = km_core_state_action_items(test_state, nullptr); act->type != KM_CORE_IT_END; act++) {
- apply_action(test_state, *act, text_store, test_context, options, test_source);
+ apply_action(test_state, *act, text_store, test_context, options, test_source, context_invalidated);
}
}
- // Compare context and text store at each step - should be identical
+ // Compare context and text store at each step
+ // should be identical unless an action has caused the context to be invalidated
size_t n = 0;
try_status(km_core_context_get(km_core_state_context(test_state), &citems));
try_status(km_core_context_items_to_utf16(citems, nullptr, &n));
- km_core_cp *buf = new km_core_cp[n];
- try_status(km_core_context_items_to_utf16(citems, buf, &n));
+ km_core_cp *core_context_str = new km_core_cp[n];
+ try_status(km_core_context_items_to_utf16(citems, core_context_str, &n));
// Verify that both our local test_context and the core's test_state.context have
// not diverged
@@ -243,13 +254,12 @@ run_test(const km::core::path &source, const km::core::path &compiled) {
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);
}
-
km_core_context_items_dispose(citems);
- if (text_store != buf) {
- std::cerr << "text store has diverged from buf" << std::endl;
+ 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 << "context : " << string_to_hex(buf) << " [" << buf << "]" << std::endl;
- assert(false);
+ std::cerr << "core context : " << string_to_hex(core_context_str) << " [" << core_context_str << "]" << std::endl;
+ assert(false);
}
}
@@ -261,8 +271,8 @@ run_test(const km::core::path &source, const km::core::path &compiled) {
size_t n = 0;
try_status(km_core_context_get(km_core_state_context(test_state), &citems));
try_status(km_core_context_items_to_utf16(citems, nullptr, &n));
- km_core_cp *buf = new km_core_cp[n];
- try_status(km_core_context_items_to_utf16(citems, buf, &n));
+ km_core_cp *core_context_str = new km_core_cp[n];
+ try_status(km_core_context_items_to_utf16(citems, core_context_str, &n));
// Verify that both our local test_context and the core's test_state.context have
// not diverged
@@ -276,10 +286,11 @@ run_test(const km::core::path &source, const km::core::path &compiled) {
std::cout << "expected : " << string_to_hex(expected) << " [" << expected << "]" << std::endl;
std::cout << "text store: " << string_to_hex(text_store) << " [" << text_store << "]" << std::endl;
- std::cout << "context : " << string_to_hex(buf) << " [" << buf << "]" << std::endl;
+ std::cout << "expected context : " << string_to_hex(expected_context) << " [" << expected_context << "]" << std::endl;
+ std::cout << "context : " << string_to_hex(core_context_str) << " [" << core_context_str << "]" << std::endl;
- // Compare internal context with expected result
- if (buf != expected) return __LINE__;
+ // Compare internal context with expected context result
+ if (core_context_str != expected_context) return __LINE__;
// Compare text store with expected result
if (text_store != expected) return __LINE__;
From aef718c56b4658ed20984ada55f44c78f4e2c1b3 Mon Sep 17 00:00:00 2001
From: rc-swag <58423624+rc-swag@users.noreply.github.com>
Date: Fri, 15 Dec 2023 14:05:37 +1000
Subject: [PATCH 5/7] fix(core): update linux test load_source call
---
linux/ibus-keyman/tests/testfixture.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/linux/ibus-keyman/tests/testfixture.cpp b/linux/ibus-keyman/tests/testfixture.cpp
index 8ea476d9168..ecf5241e794 100644
--- a/linux/ibus-keyman/tests/testfixture.cpp
+++ b/linux/ibus-keyman/tests/testfixture.cpp
@@ -309,12 +309,12 @@ static void test_source(IBusKeymanTestsFixture *fixture, gconstpointer user_data
km::tests::KmxTestSource test_source;
std::string keys = "";
- std::u16string expected = u"", context = u"";
+ std::u16string expected = u"", expected_context = u"", context = u"";
km::tests::kmx_options options;
bool expected_beep = false;
// NOTE: we don't verify expected beeps since engine.c directly calls a gdk method so we
// don't know when it gets called.
- g_assert_cmpint(test_source.load_source(sourcefile.c_str(), keys, expected, context, options, expected_beep), ==, 0);
+ g_assert_cmpint(test_source.load_source(sourcefile.c_str(), keys, expected, expected_context, context, options, expected_beep), ==, 0);
for (auto & option : options) {
if (option.type == km::tests::KOT_INPUT) {
From af850007ccaeb4107a0beb4d354070c4052393d6 Mon Sep 17 00:00:00 2001
From: sgschantz
Date: Mon, 18 Dec 2023 09:09:07 +0700
Subject: [PATCH 6/7] fix unit tests for core update
---
.../KeymanEngine4MacTests/KMEngineTests.m | 83 +------------------
1 file changed, 4 insertions(+), 79 deletions(-)
diff --git a/mac/KeymanEngine4Mac/KeymanEngine4MacTests/KMEngineTests.m b/mac/KeymanEngine4Mac/KeymanEngine4MacTests/KMEngineTests.m
index d2075c0542b..40a357480bf 100644
--- a/mac/KeymanEngine4Mac/KeymanEngine4MacTests/KMEngineTests.m
+++ b/mac/KeymanEngine4Mac/KeymanEngine4MacTests/KMEngineTests.m
@@ -518,9 +518,6 @@ - (void)testContextMatch_InvertedPlatformLogic_NotTouch {
- (void)testEngine_ipaKeyboardAction_DoesNotCrash_Issue1892 {
-// KMXFile *kmxFile = [KeymanEngineTestsStaticHelperMethods getKmxFileForSilIpaTests];
-// KMEngine *engine = [[KMEngine alloc] initWithKMX:kmxFile contextBuffer:@"a" verboseLogging:YES];
-// NSEvent *event = [NSEvent keyEventWithType:NSEventTypeKeyDown location:NSMakePoint(0, 0) modifierFlags:0 timestamp:0 windowNumber:0 context:nil characters:@"=" charactersIgnoringModifiers:@"=" isARepeat:NO keyCode:kVK_ANSI_Equal];
KMXFile *kmxFile = [KeymanEngineTestsStaticHelperMethods getKmxFileForIndexOffsetTests];
KMEngine *engine = [[KMEngine alloc] initWithKMX:kmxFile context:@"z" verboseLogging:YES];
NSEvent *event = [NSEvent keyEventWithType:NSEventTypeKeyDown location:NSMakePoint(0, 0) modifierFlags:0 timestamp:0 windowNumber:0 context:nil characters:@"a" charactersIgnoringModifiers:@"a" isARepeat:NO keyCode:kVK_ANSI_A];
@@ -534,21 +531,6 @@ - (void)testEngine_ipaKeyboardAction_DoesNotCrash_Issue1892 {
XCTAssert([action.content isEqualToString:@"Z"], @"Expected output to be 'Z'.");
}
-/*
-- (void)testLegacyProcessEvent_eventForFWithElNuerKmx_ReturnsCorrectCharacter {
- KMXFile *kmxFile = [KeymanEngineTestsStaticHelperMethods getKmxFileForElNuerTests];
- KMEngine *engine = [[KMEngine alloc] initWithKMX:kmxFile contextBuffer:@"" verboseLogging:YES];
- NSEvent *event = [NSEvent keyEventWithType:NSEventTypeKeyDown location:NSMakePoint(0, 0) modifierFlags:0 timestamp:0 windowNumber:0 context:nil characters:@"f" charactersIgnoringModifiers:@"f" isARepeat:NO keyCode:kVK_ANSI_F];
- NSArray *actions = [engine experimentallyProcessEventForUnitTestingOnly:event usingCore:NO];
- XCTAssert(actions.count == 1, @"Expected one action");
- NSDictionary *action = actions[0];
- NSString *actionType = [[action allKeys] objectAtIndex:0];
- XCTAssert([actionType isEqualToString:Q_STR], @"Expected Q_STR action");
- NSString *output = [action objectForKey:actionType];
- XCTAssert([output isEqualToString:@"ɣ"], @"Expected output to be 'ɣ'.");
-}
-*/
-
- (void)testCoreProcessEvent_eventForFWithElNuerKmx_ReturnsCorrectCharacter {
KMXFile *kmxFile = [KeymanEngineTestsStaticHelperMethods getKmxFileForElNuerTests];
KMEngine *engine = [[KMEngine alloc] initWithKMX:kmxFile context:@"" verboseLogging:YES];
@@ -572,20 +554,7 @@ - (void)testCoreProcessEvent_eventDeleteWithElNuerKmx_EmptiesContextReturnsDelet
XCTAssert([context isEqualToString:@""], @"Context should be empty.");
}
-/*
-- (void)testLegacyProcessEvent_eventDeleteWithElNuerKmx_ReturnsEmptyActionListContextUnchanged {
- KMXFile *kmxFile = [KeymanEngineTestsStaticHelperMethods getKmxFileForElNuerTests];
- KMEngine *engine = [[KMEngine alloc] initWithKMX:kmxFile contextBuffer:@"ɣ" verboseLogging:YES];
- NSEvent *event = [NSEvent keyEventWithType:NSEventTypeKeyDown location:NSMakePoint(0, 0) modifierFlags:0 timestamp:0 windowNumber:0 context:nil characters:@"\b" charactersIgnoringModifiers:@"\b" isARepeat:NO keyCode:kVK_Delete];
- NSArray *actions = [engine experimentallyProcessEventForUnitTestingOnly:event usingCore:NO];
- XCTAssert(actions.count == 0, @"Expected no actions");
- NSString *context = engine.contextBuffer;
- XCTAssert([context isEqualToString:@"ɣ"], @"Context should be unchanged.");
-}
-*/
-
-
-- (void)testCoreProcessEvent_eventReturnWithElNuerKmx_ContextUnchangedReturnsReturn {
+- (void)testCoreProcessEvent_eventReturnWithElNuerKmx_EmitWithContextEmpty {
KMXFile *kmxFile = [KeymanEngineTestsStaticHelperMethods getKmxFileForElNuerTests];
KMEngine *engine = [[KMEngine alloc] initWithKMX:kmxFile context:@"ɣ" verboseLogging:YES];
NSEvent *event = [NSEvent keyEventWithType:NSEventTypeKeyDown location:NSMakePoint(0, 0) modifierFlags:0 timestamp:0 windowNumber:0 context:nil characters:@"\n" charactersIgnoringModifiers:@"\n" isARepeat:NO keyCode:kVK_Return];
@@ -594,22 +563,10 @@ - (void)testCoreProcessEvent_eventReturnWithElNuerKmx_ContextUnchangedReturnsRet
CoreAction *action = actions[1];
XCTAssert(action.actionType == EmitKeystrokeAction, @"Expected EmitKeystrokeAction");
NSString *context = engine.getCoreContext;
- XCTAssert([context isEqualToString:@"ɣ"], @"Context should be unchanged.");
+ XCTAssert([context isEqualToString:@""], @"Context should be cleared.");
}
-/*
-- (void)testLegacyProcessEvent_eventReturnWithElNuerKmx_ReturnsEmptyActionListContextUnchanged {
- KMXFile *kmxFile = [KeymanEngineTestsStaticHelperMethods getKmxFileForElNuerTests];
- KMEngine *engine = [[KMEngine alloc] initWithKMX:kmxFile contextBuffer:@"ɣ" verboseLogging:YES];
- NSEvent *event = [NSEvent keyEventWithType:NSEventTypeKeyDown location:NSMakePoint(0, 0) modifierFlags:0 timestamp:0 windowNumber:0 context:nil characters:@"\n" charactersIgnoringModifiers:@"\n" isARepeat:NO keyCode:kVK_Return];
- NSArray *actions = [engine experimentallyProcessEventForUnitTestingOnly:event usingCore:NO];
- XCTAssert(actions.count == 0, @"Expected no actions");
- NSString *context = engine.contextBuffer;
- XCTAssert([context isEqualToString:@"ɣ"], @"Context should be unchanged.");
-}
-*/
-
-- (void)testCoreProcessEvent_eventTabWithElNuerKmx_ContextUnchangedReturnsTab {
+- (void)testCoreProcessEvent_eventTabWithElNuerKmx_EmitWithContextEmpty {
KMXFile *kmxFile = [KeymanEngineTestsStaticHelperMethods getKmxFileForElNuerTests];
KMEngine *engine = [[KMEngine alloc] initWithKMX:kmxFile context:@"ɣ" verboseLogging:YES];
NSEvent *event = [NSEvent keyEventWithType:NSEventTypeKeyDown location:NSMakePoint(0, 0) modifierFlags:0 timestamp:0 windowNumber:0 context:nil characters:@"\t" charactersIgnoringModifiers:@"\t" isARepeat:NO keyCode:kVK_Tab];
@@ -618,20 +575,8 @@ - (void)testCoreProcessEvent_eventTabWithElNuerKmx_ContextUnchangedReturnsTab {
CoreAction *action = actions[1];
XCTAssert(action.actionType == EmitKeystrokeAction, @"Expected EmitKeystrokeAction");
NSString *context = engine.getCoreContext;
- XCTAssert([context isEqualToString:@"ɣ"], @"Context should be unchanged.");
-}
-
-/*
-- (void)testLegacyProcessEvent_eventTabWithElNuerKmx_ReturnsEmptyActionListContextUnchanged {
- KMXFile *kmxFile = [KeymanEngineTestsStaticHelperMethods getKmxFileForElNuerTests];
- KMEngine *engine = [[KMEngine alloc] initWithKMX:kmxFile contextBuffer:@"ɣ" verboseLogging:YES];
- NSEvent *event = [NSEvent keyEventWithType:NSEventTypeKeyDown location:NSMakePoint(0, 0) modifierFlags:0 timestamp:0 windowNumber:0 context:nil characters:@"\t" charactersIgnoringModifiers:@"\n" isARepeat:NO keyCode:kVK_Tab];
- NSArray *actions = [engine experimentallyProcessEventForUnitTestingOnly:event usingCore:NO];
- XCTAssert(actions.count == 0, @"Expected no actions");
- NSString *context = engine.contextBuffer;
- XCTAssert([context isEqualToString:@"ɣ"], @"Context should be unchanged.");
+ XCTAssert([context isEqualToString:@""], @"Context should be cleared.");
}
-*/
- (void)testCoreProcessEvent_eventSingleQuoteWithElNuerKmx_ReturnsDiacritic {
KMXFile *kmxFile = [KeymanEngineTestsStaticHelperMethods getKmxFileForElNuerTests];
@@ -646,24 +591,4 @@ - (void)testCoreProcessEvent_eventSingleQuoteWithElNuerKmx_ReturnsDiacritic {
XCTAssert([context isEqualToString:@"\u025B\u0308"], @"Context updated with diacritic.");
}
-/*
-- (void)testLegacyProcessEvent_eventSingleQuoteWithElNuerKmx_ReturnsTwoActions {
- KMXFile *kmxFile = [KeymanEngineTestsStaticHelperMethods getKmxFileForElNuerTests];
- NSString *context = @"ɛ";
- KMEngine *engine = [[KMEngine alloc] initWithKMX:kmxFile contextBuffer:context verboseLogging:YES];
- NSEvent *event = [NSEvent keyEventWithType:NSEventTypeKeyDown location:NSMakePoint(0, 0) modifierFlags:0 timestamp:0 windowNumber:0 context:nil characters:@"'" charactersIgnoringModifiers:@"'" isARepeat:NO keyCode:kVK_ANSI_Quote];
- NSArray *actions = [engine experimentallyProcessEventForUnitTestingOnly:event usingCore:NO];
- XCTAssert(actions.count == 2, @"Expected two actions");
- NSDictionary *action = actions[0];
- NSString *actionType = [[action allKeys] objectAtIndex:0];
- XCTAssert([actionType isEqualToString:Q_BACK], @"Expected Q_BACK action");
- action = actions[1];
- actionType = [[action allKeys] objectAtIndex:0];
- NSString *characters = [action objectForKey:actionType];
- XCTAssert([characters isEqualToString:@"\u025B\u0308"], @"Expected \u025B\u0308");
- context = engine.contextBuffer;
- XCTAssert([context isEqualToString:@"\u025B\u0308"], @"Context updated with diacritic.");
-}
-*/
-
@end
From deceabd5c303145eda90320a09ca99966e0f26f6 Mon Sep 17 00:00:00 2001
From: rc-swag <58423624+rc-swag@users.noreply.github.com>
Date: Mon, 18 Dec 2023 20:39:16 +1000
Subject: [PATCH 7/7] fix(windows): review comments and suggestions
Co-authored-by: Eberhard Beilharz
---
core/tests/unit/kmx/kmx.cpp | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/core/tests/unit/kmx/kmx.cpp b/core/tests/unit/kmx/kmx.cpp
index d508655c38b..794c744a7c4 100644
--- a/core/tests/unit/kmx/kmx.cpp
+++ b/core/tests/unit/kmx/kmx.cpp
@@ -257,8 +257,8 @@ run_test(const km::core::path &source, const km::core::path &compiled) {
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;
+ 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);
}
}
@@ -284,10 +284,10 @@ run_test(const km::core::path &source, const km::core::path &compiled) {
km_core_context_items_dispose(citems);
- std::cout << "expected : " << string_to_hex(expected) << " [" << expected << "]" << std::endl;
- std::cout << "text store: " << string_to_hex(text_store) << " [" << text_store << "]" << std::endl;
- std::cout << "expected context : " << string_to_hex(expected_context) << " [" << expected_context << "]" << std::endl;
- std::cout << "context : " << string_to_hex(core_context_str) << " [" << core_context_str << "]" << std::endl;
+ std::cout << "expected : " << string_to_hex(expected) << " [" << expected << "]" << std::endl;
+ std::cout << "text store : " << string_to_hex(text_store) << " [" << text_store << "]" << std::endl;
+ std::cout << "expected context: " << string_to_hex(expected_context) << " [" << expected_context << "]" << std::endl;
+ std::cout << "context : " << string_to_hex(core_context_str) << " [" << core_context_str << "]" << std::endl;
// Compare internal context with expected context result
if (core_context_str != expected_context) return __LINE__;