Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(windows): update windows engine unit tests to match removal of engine cached context #10184

Merged
merged 5 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions windows/src/engine/keyman32/keyman-engine.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LibraryPath>$(ProjectDir)..\..\..\..\core\build\x86\$(Configuration)\src;$(ProjectDir)..\..\..\..\core\build\rust\x86\$(Configuration);$(LibraryPath)</LibraryPath>
<LibraryPath>$(ProjectDir)..\..\..\..\core\build\x86\$(Configuration)\src;$(ProjectDir)..\..\..\..\core\build\x86\$(Configuration)\subprojects\icu\source\common;$(ProjectDir)..\..\..\..\core\build\x86\$(Configuration)\subprojects\icu\source\i18n;$(ProjectDir)..\..\..\..\core\build\rust\x86\$(Configuration);$(LibraryPath)</LibraryPath>
<IncludePath>$(ProjectDir)..\..\..\..\common\include;$(ProjectDir)..\..\..\..\core\build\x86\$(Configuration)\include;$(ProjectDir)..\..\..\..\core\include;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
Expand Down Expand Up @@ -98,7 +98,7 @@
</ResourceCompile>
<Link>
<AdditionalOptions>/verbose:lib /section:.SHARDATA,rws %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>keymancore.lib;psapi.lib;rpcrt4.lib;version.lib;setupapi.lib;iphlpapi.lib;imm32.lib;crypt32.lib;wintrust.lib;imagehlp.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>keymancore.lib;libicuuc.a;libicuin.a;psapi.lib;rpcrt4.lib;version.lib;setupapi.lib;iphlpapi.lib;imm32.lib;crypt32.lib;wintrust.lib;imagehlp.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>./Keyman32.dll</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
<ModuleDefinitionFile>keyman32.def</ModuleDefinitionFile>
Expand Down Expand Up @@ -186,6 +186,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="$(KEYMAN_ROOT)\common\windows\cpp\src\xstring.cpp" />
<ClCompile Include="appcontext.cpp" />
<ClCompile Include="appint\aiTIP.cpp">
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
Expand Down Expand Up @@ -364,6 +365,7 @@
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="appcontext.h" />
<ClInclude Include="keymanengine.h" />
<ClInclude Include="addins.h" />
<ClInclude Include="appint\aiTIP.h" />
Expand Down Expand Up @@ -397,4 +399,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
6 changes: 6 additions & 0 deletions windows/src/engine/keyman32/keyman-engine.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@
<ClCompile Include="CoreEnvironment.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="appcontext.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="KEYMAN32.DEF">
Expand Down Expand Up @@ -243,6 +246,9 @@
<ClInclude Include="kmprocessactions.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="appcontext.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="keyman-debug-etw.man" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@ TEST(AppContext, Get_split_surrogate) {

// Test Calling BufMax
TEST(AppContext, BufMax_LastChar) {
WCHAR callbuff[MAXCONTEXT];
const uint32_t ExpectedMarker = 0x0002;
AppContext testContext;
WCHAR testString[] = {0x0042, 0xD800, 0xDC00, UC_SENTINEL, CODE_DEADKEY, ExpectedMarker, 0x0000};
WCHAR expectedString[] = {UC_SENTINEL, CODE_DEADKEY, 0x0002, 0x0000};

testContext.Set(testString);
WCHAR *contextBuf = testContext.BufMax(3);
EXPECT_STREQ((expectedString), contextBuf);
Expand All @@ -60,7 +58,6 @@ TEST(AppContext, BufMax_LastChar) {

// Test AppContext::Delete()
TEST(AppContext, AppContext_Delete) {
WCHAR callbuff[MAXCONTEXT];
const uint32_t ExpectedMarker = 0x0002;
AppContext testContext;
WCHAR testString[] = {0x0042, 0xD800, 0xDC00, UC_SENTINEL, CODE_DEADKEY, ExpectedMarker, 0x0000};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,24 @@
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<IncludePath>$(ProjectDir)..\..\..\..\..\..\common\include;$(ProjectDir)..\..\..\..\..\..\core\include;$(ProjectDir)..\..\..\..\..\..\core\build\x86\$(Configuration)\include;$(ProjectDir)..\..\..\..\global\inc;$(ProjectDir)..\..;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir)..\..\..\..\..\..\common\include;$(ProjectDir)..\..\..\..\..\..\core\include;$(ProjectDir)..\..\..\..\..\..\core\build\x86\$(Configuration)\include;$(ProjectDir)..\..\..\..\..\..\core\build\x86\$(Configuration)\subprojects\icu\source\common;$(ProjectDir)..\..\..\..\..\..\core\build\x86\$(Configuration)\subprojects\icu\source\i18n;$(ProjectDir)..\..\..\..\global\inc;$(ProjectDir)..\..;$(IncludePath)</IncludePath>
<OutDir>$(ProjectDir)bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)obj\$(Platform)\$(Configuration)\</IntDir>
<LibraryPath>$(ProjectDir)..\..\..\..\..\..\core\build\x86\$(Configuration)\src;$(ProjectDir)..\..\..\..\..\..\core\build\rust\x86\$(Configuration);$(ProjectDir)..\..\..\kmtip\bin\Win32\$(Configuration);$(LibraryPath)</LibraryPath>
<LibraryPath>$(ProjectDir)..\..\..\..\..\..\core\build\x86\$(Configuration)\src;$(ProjectDir)..\..\..\..\kmtip\bin\Win32\$(Configuration);$(ProjectDir)..\..\..\..\..\..\core\build\x86\$(Configuration)\subprojects\icu\source\common;$(ProjectDir)..\..\..\..\..\..\core\build\x86\$(Configuration)\subprojects\icu\source\i18n;$(LibraryPath)</LibraryPath>
<Microsoft-googletest-v140-windesktop-msvcstl-static-rt-static-Disable-gtest_main>true</Microsoft-googletest-v140-windesktop-msvcstl-static-rt-static-Disable-gtest_main>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<IncludePath>$(ProjectDir)..\..\..\..\global\inc;$(ProjectDir)..\..;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir)..\..\..\..\..\..\common\include;$(ProjectDir)..\..\..\..\..\..\core\include;$(ProjectDir)..\..\..\..\..\..\core\build\x86\$(Configuration)\include;$(ProjectDir)..\..\..\..\core\build\x86\$(Configuration)\subprojects\icu\source\common;$(ProjectDir)..\..\..\..\core\build\x86\$(Configuration)\subprojects\icu\source\i18n;$(ProjectDir)..\..\..\..\global\inc;$(ProjectDir)..\..;$(IncludePath)</IncludePath>
<OutDir>$(ProjectDir)bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)obj\$(Platform)\$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<IncludePath>$(ProjectDir)..\..\..\..\..\..\common\include;$(ProjectDir)..\..\..\..\..\..\core\build\x86\$(Configuration)\include;$(ProjectDir)..\..\..\..\..\..\core\include;$(ProjectDir)..\..\..\..\global\inc;$(ProjectDir)..\..;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir)..\..\..\..\..\..\common\include;$(ProjectDir)..\..\..\..\..\..\core\build\x64\$(Configuration)\include;$(ProjectDir)..\..\..\..\..\..\core\include;$(ProjectDir)..\..\..\..\..\..\core\build\x64\$(Configuration)\subprojects\icu\source\common;$(ProjectDir)..\..\..\..\..\..\core\build\x64\$(Configuration)\subprojects\icu\source\i18n;$(ProjectDir)..\..\..\..\global\inc;$(ProjectDir)..\..;$(IncludePath)</IncludePath>
<OutDir>$(ProjectDir)bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)obj\$(Platform)\$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<IncludePath>$(ProjectDir)..\..\..\..\global\inc;$(ProjectDir)..\..;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir)..\..\..\..\..\..\common\include;$(ProjectDir)..\..\..\..\..\..\core\build\x64\$(Configuration)\include;$(ProjectDir)..\..\..\..\..\..\core\include;$(ProjectDir)..\..\..\..\..\..\core\build\x64\$(Configuration)\subprojects\icu\source\common;$(ProjectDir)..\..\..\..\..\..\core\build\x64\$(Configuration)\subprojects\icu\source\i18n;$(ProjectDir)..\..\..\..\global\inc;$(ProjectDir)..\..;$(IncludePath)</IncludePath>
<OutDir>$(ProjectDir)bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)obj\$(Platform)\$(Configuration)\</IntDir>
</PropertyGroup>
Expand Down Expand Up @@ -98,7 +98,7 @@
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<AdditionalDependencies>version.lib;psapi.lib;imm32.lib;libkeymancore.a;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>version.lib;psapi.lib;imm32.lib;libkeymancore.a;libicuuc.a;libicuin.a;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<ProjectReference>
<UseLibraryDependencyInputs>false</UseLibraryDependencyInputs>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,163 +24,17 @@ class KMPROCESSACTIONS : public ::testing::Test {
};

// KM_CORE_IT_CHAR - processUnicodeChar
// Now that the AITIP no longer contains a context
// this test is just reduced to checking the size of the
// action queue
TEST_F(KMPROCESSACTIONS, processUnicodeChartest) {

WCHAR callbuf[MAXCONTEXT];
AITIP testApp;
WCHAR *expectedContext = L"A";
km_core_action_item itemAddChar = { KM_CORE_IT_CHAR, {0,}, {'A'}};

processUnicodeChar(&testApp, &itemAddChar);
WCHAR *contextBuf = testApp.ContextBufMax(MAXCONTEXT);
EXPECT_STREQ(contextBuf, expectedContext);

km_core_usv testSurrogateChar = Uni_SurrogateToUTF32(0xD801, 0xDC37); //𐐷';
km_core_action_item itemAddChar2 = {KM_CORE_IT_CHAR, {0,}, {testSurrogateChar}};
WCHAR expectedStringSurrogate[] = {'A', 0xD801, 0xDC37, 0};
processUnicodeChar(&testApp, &itemAddChar2);
contextBuf = testApp.ContextBufMax(MAXCONTEXT);
EXPECT_STREQ(contextBuf, &expectedStringSurrogate[0]);
}

// KM_CORE_IT_MARKER - processMarker Deadkey
TEST_F(KMPROCESSACTIONS, processMarkertest) {

WCHAR callbuf[MAXCONTEXT];
AITIP testApp;
WCHAR expectedContext[] = {UC_SENTINEL, CODE_DEADKEY, 2, 0};
uint32_t marker = 2;
km_core_action_item itemAddMarker = {KM_CORE_IT_MARKER, {0,}, {marker}};

processMarker(&testApp, &itemAddMarker);
WCHAR *contextBuf = testApp.ContextBufMax(MAXCONTEXT);
EXPECT_STREQ(contextBuf, expectedContext);
}

// KM_CORE_IT_BACK - processBack
// First test processing a backspace for a deadkey
TEST_F(KMPROCESSACTIONS, processBackDeadkeytest) {

WCHAR callbuf[MAXCONTEXT];
AITIP testApp;
WCHAR expectedContext[] = {'A', 0};
km_core_action_item itemAddChar = {KM_CORE_IT_CHAR, {0,}, {'A'}};

processUnicodeChar(&testApp, &itemAddChar);
uint32_t marker = 2;
km_core_action_item itemAddMarker = {KM_CORE_IT_MARKER, {0,}, {marker}};
processMarker(&testApp, &itemAddMarker);
km_core_action_item itemBackSpace = {KM_CORE_IT_BACK};
itemBackSpace.backspace.expected_type = KM_CORE_IT_MARKER;
itemBackSpace.backspace.expected_value = marker;
processBack(&testApp, &itemBackSpace);
WCHAR *contextBuf = testApp.ContextBufMax(MAXCONTEXT);
EXPECT_STREQ(contextBuf, expectedContext);
}

// KM_CORE_IT_BACK - processBack
// Press Backspace for a normal character
// Also test for Unknown Character
TEST_F(KMPROCESSACTIONS, processBackCharactertest) {

WCHAR callbuf[MAXCONTEXT];
AITIP testApp;
WCHAR expectedContext[] = {'A', 0};
WCHAR expectedContextFinal[] = {0};
km_core_action_item itemAddChar = {KM_CORE_IT_CHAR, {0,}, {'A'}};

processUnicodeChar(&testApp, &itemAddChar);
itemAddChar.character = 'B';
processUnicodeChar(&testApp, &itemAddChar);
km_core_action_item itemBackSpace = {KM_CORE_IT_BACK};
itemBackSpace.backspace.expected_type = KM_CORE_IT_CHAR;
itemBackSpace.backspace.expected_value = 'B';
// backspace
processBack(&testApp, &itemBackSpace);
WCHAR *contextBuf = testApp.ContextBufMax(MAXCONTEXT);
EXPECT_STREQ(contextBuf, expectedContext);
// backspace for unknown it should backspace a character
itemBackSpace.type = KM_CORE_BT_UNKNOWN;
processBack(&testApp, &itemBackSpace);
contextBuf = testApp.ContextBufMax(MAXCONTEXT);
EXPECT_STREQ(contextBuf, expectedContextFinal);
}


// KM_CORE_IT_BACK - processBack
// Press Backspace for a surrogate character.
// TODO: This test doesn't test for the PostKey handling
// of TSF and two backspaces being sent to the App.
TEST_F(KMPROCESSACTIONS, processBackSurrogateTSFtest) {
WCHAR callbuf[MAXCONTEXT];
AITIP testApp;
WCHAR expectedContext[] = { 0 };
WCHAR expectedStringSurrogate[] = {0xD801, 0xDC37, 0};

km_core_usv testSurrogateChar = Uni_SurrogateToUTF32(0xD801, 0xDC37); //𐐷';
km_core_action_item itemAddChar = {KM_CORE_IT_CHAR, {0,}, {testSurrogateChar}};
processUnicodeChar(&testApp, &itemAddChar);

km_core_action_item itemBackSpace = {KM_CORE_IT_BACK};
itemBackSpace.backspace.expected_type = KM_CORE_IT_CHAR;
itemBackSpace.backspace.expected_value = testSurrogateChar;
WCHAR *contextBuf = testApp.ContextBufMax(MAXCONTEXT);
EXPECT_STREQ(contextBuf, expectedStringSurrogate);
// backspace
processBack(&testApp, &itemBackSpace);
contextBuf = testApp.ContextBufMax(MAXCONTEXT);
EXPECT_STREQ(contextBuf, expectedContext);
}

// KM_CORE_IT_BACK - processBack
// Press Backspace for a character doesn't match expected character
// Note currently we don't check for a character match this should be updated

TEST_F(KMPROCESSACTIONS, processBackUnexpectedChartest) {

// just check something has been added to the que
WCHAR callbuf[MAXCONTEXT];
AITIP testApp;
WCHAR expectedContext[] = {'A', 0};
km_core_action_item itemAddChar = {KM_CORE_IT_CHAR, {0,}, {'A'}};

processUnicodeChar(&testApp, &itemAddChar);
itemAddChar.character = 'C';
processUnicodeChar(&testApp, &itemAddChar);
km_core_action_item itemBackSpace = {KM_CORE_IT_BACK};
itemBackSpace.backspace.expected_type = KM_CORE_IT_CHAR;
itemBackSpace.backspace.expected_value = 'B';
// backspace
processBack(&testApp, &itemBackSpace);
WCHAR *contextBuf = testApp.ContextBufMax(MAXCONTEXT);
EXPECT_STREQ(contextBuf, expectedContext);
int expectedQueueSize = 3; // 1 + surrogate pair
km_core_usv output_string[] = {0x0041, 0x010000, 0};
processUnicodeChar(&testApp, &output_string[0]);
int queueSize = testApp.GetQueueSize();
EXPECT_EQ(queueSize, expectedQueueSize);
}

// KM_CORE_IT_INVALIDATE_CONTEXT - processInvalidateContext
TEST_F(KMPROCESSACTIONS, processInvalidateContextTest) {

WCHAR callbuf[MAXCONTEXT];
AITIP testApp;
WCHAR expectedContext[] = {0};
km_core_action_item itemAddChar = {KM_CORE_IT_CHAR, {0,}, {'A'}};

processUnicodeChar(&testApp, &itemAddChar);
itemAddChar.character = 'B';
processUnicodeChar(&testApp, &itemAddChar);

// A keyboard a state is need to test processInvalidateContext
km_core_option_item test_env_opts[] = {{u"hello", u"world", KM_CORE_OPT_KEYBOARD}, KM_CORE_OPTIONS_END};
km_core_keyboard *testKB = nullptr;
km_core_state *testState = nullptr;
km_core_path_name dummyPath = L"dummyActions.mock";
EXPECT_EQ(km_core_keyboard_load(dummyPath, &testKB), KM_CORE_STATUS_OK);
EXPECT_EQ(km_core_state_create(testKB, test_env_opts, &testState), KM_CORE_STATUS_OK);

processInvalidateContext(&testApp,testState);
WCHAR *contextBuf = testApp.ContextBufMax(MAXCONTEXT);
EXPECT_STREQ(contextBuf, expectedContext);

// dispose keyboard
km_core_state_dispose(testState);
km_core_keyboard_dispose(testKB);

}
Loading