From 9fa7a5b55a7e6317f4b20ffb3e4c2d9189da7dfe Mon Sep 17 00:00:00 2001 From: vczh Date: Sun, 16 Feb 2025 15:55:41 -0800 Subject: [PATCH] New test case for async channel --- .../GuiUnitTestProtocol_Shared.h | 9 ++- .../GuiUnitTestUtilities.cpp | 21 ++++-- .../UnitTestUtilities/GuiUnitTestUtilities.h | 1 + .../UnitTest/TestRemote_UnitTestFramework.cpp | 4 +- .../TestRemote_UnitTestFramework_Async.cpp | 72 +++++++++++++++++++ Test/GacUISrc/UnitTest/UnitTest.vcxproj | 1 + .../UnitTest/UnitTest.vcxproj.filters | 3 + 7 files changed, 104 insertions(+), 7 deletions(-) create mode 100644 Test/GacUISrc/UnitTest/TestRemote_UnitTestFramework_Async.cpp diff --git a/Source/UnitTestUtilities/GuiUnitTestProtocol_Shared.h b/Source/UnitTestUtilities/GuiUnitTestProtocol_Shared.h index a3e3febd0..b368268e6 100644 --- a/Source/UnitTestUtilities/GuiUnitTestProtocol_Shared.h +++ b/Source/UnitTestUtilities/GuiUnitTestProtocol_Shared.h @@ -31,6 +31,13 @@ namespace vl::presentation::unittest auto operator<=>(const WindowStyleConfig&) const = default; }; + enum class UnitTestRemoteChannel + { + None, + Sync, + Async, + }; + struct UnitTestScreenConfig { using FontConfig = vl::presentation::remoteprotocol::FontConfig; @@ -41,7 +48,7 @@ namespace vl::presentation::unittest FontConfig fontConfig; ScreenConfig screenConfig; bool useDomDiff = false; - bool useSyncChannel = false; + UnitTestRemoteChannel useChannel = UnitTestRemoteChannel::None; void FastInitialize(vint width, vint height, vint taskBarHeight = 0); }; diff --git a/Source/UnitTestUtilities/GuiUnitTestUtilities.cpp b/Source/UnitTestUtilities/GuiUnitTestUtilities.cpp index b1509c8d4..c2d6862f6 100644 --- a/Source/UnitTestUtilities/GuiUnitTestUtilities.cpp +++ b/Source/UnitTestUtilities/GuiUnitTestUtilities.cpp @@ -304,9 +304,9 @@ void GacUIUnitTest_Start(const WString& appName, Nullable // Core repeatfiltering::GuiRemoteProtocolFilterVerifier verifierProtocol( - globalConfig.useSyncChannel - ? &channelSender - : unitTestProtocol.GetProtocol() + globalConfig.useChannel == UnitTestRemoteChannel::None + ? unitTestProtocol.GetProtocol() + : &channelSender ); repeatfiltering::GuiRemoteProtocolFilter filteredProtocol(&verifierProtocol); GuiRemoteProtocolDomDiffConverter diffConverterProtocol(&filteredProtocol); @@ -328,6 +328,11 @@ void GacUIUnitTest_Start(const WString& appName, Nullable GacUIUnitTest_LogDiffs(appName, unitTestProtocol); } +void GacUIUnitTest_StartAsync(const WString& appName, Nullable config) +{ + CHECK_FAIL(L"Not Implemented!"); +} + void GacUIUnitTest_Start_WithResourceAsText(const WString& appName, Nullable config, const WString& resourceText) { #define ERROR_MESSAGE_PREFIX L"GacUIUnitTest_Start_WithResourceAsText(const WString&, Nullable, const WString&)#" @@ -363,7 +368,15 @@ void GacUIUnitTest_Start_WithResourceAsText(const WString& appName, Nullable config = {}); +extern void GacUIUnitTest_StartAsync(const vl::WString& appName, vl::Nullable config = {}); extern void GacUIUnitTest_Start_WithResourceAsText(const vl::WString& appName, vl::Nullable config, const vl::WString& resourceText); extern vl::Ptr GacUIUnitTest_CompileAndLoad(const vl::WString& xmlResource); diff --git a/Test/GacUISrc/UnitTest/TestRemote_UnitTestFramework.cpp b/Test/GacUISrc/UnitTest/TestRemote_UnitTestFramework.cpp index e92e04f62..9aa9c805a 100644 --- a/Test/GacUISrc/UnitTest/TestRemote_UnitTestFramework.cpp +++ b/Test/GacUISrc/UnitTest/TestRemote_UnitTestFramework.cpp @@ -381,7 +381,7 @@ TEST_FILE UnitTestScreenConfig globalConfig; globalConfig.FastInitialize(1024, 768); - globalConfig.useSyncChannel = true; + globalConfig.useChannel = UnitTestRemoteChannel::Sync; GacUIUnitTest_StartFast_WithResourceAsText( WString::Unmanaged(L"UnitTestFramework/Channel/Sync"), @@ -414,7 +414,7 @@ TEST_FILE UnitTestScreenConfig globalConfig; globalConfig.FastInitialize(1024, 768); globalConfig.useDomDiff = true; - globalConfig.useSyncChannel = true; + globalConfig.useChannel = UnitTestRemoteChannel::Sync; GacUIUnitTest_StartFast_WithResourceAsText( WString::Unmanaged(L"UnitTestFramework/Channel/Everything"), diff --git a/Test/GacUISrc/UnitTest/TestRemote_UnitTestFramework_Async.cpp b/Test/GacUISrc/UnitTest/TestRemote_UnitTestFramework_Async.cpp new file mode 100644 index 000000000..e70435f4b --- /dev/null +++ b/Test/GacUISrc/UnitTest/TestRemote_UnitTestFramework_Async.cpp @@ -0,0 +1,72 @@ +#include "../../../Source/UnitTestUtilities/GuiUnitTestUtilities.h" +#ifdef VCZH_64 +#include "../Generated_DarkSkin/Source_x64/DarkSkin.h" +#else +#include "../Generated_DarkSkin/Source_x86/DarkSkin.h" +#endif + +using namespace vl; +using namespace vl::stream; +using namespace vl::reflection::description; +using namespace vl::presentation; +using namespace vl::presentation::elements; +using namespace vl::presentation::compositions; +using namespace vl::presentation::controls; +using namespace vl::presentation::unittest; + +TEST_FILE +{ + TEST_CATEGORY(L"Channels and Diffs") + { + const auto resource = LR"GacUISrc( + + + + + + + + + +)GacUISrc"; + + auto sharedProxy = [](UnitTestRemoteProtocol* protocol, IUnitTestContext*) + { + protocol->OnNextIdleFrame(L"Ready", [=]() + { + auto window = GetApplication()->GetMainWindow(); + auto buttonOK = TryFindObjectByName(window, L"buttonOK"); + protocol->MouseMove(protocol->LocationOf(buttonOK)); + }); + protocol->OnNextIdleFrame(L"Hover", [=]() + { + protocol->_LDown(); + }); + protocol->OnNextIdleFrame(L"Press", [=]() + { + protocol->_LUp(); + }); + }; + + TEST_CASE(L"Async Channel") + { + GacUIUnitTest_SetGuiMainProxy(sharedProxy); + + UnitTestScreenConfig globalConfig; + globalConfig.FastInitialize(1024, 768); + globalConfig.useChannel = UnitTestRemoteChannel::Async; + + GacUIUnitTest_StartFast_WithResourceAsText( + WString::Unmanaged(L"UnitTestFramework/Channel/Async"), + WString::Unmanaged(L"gacuisrc_unittest::MainWindow"), + resource, + globalConfig + ); + }); + }); +} \ No newline at end of file diff --git a/Test/GacUISrc/UnitTest/UnitTest.vcxproj b/Test/GacUISrc/UnitTest/UnitTest.vcxproj index 19fedc3fa..e3c0d67ab 100644 --- a/Test/GacUISrc/UnitTest/UnitTest.vcxproj +++ b/Test/GacUISrc/UnitTest/UnitTest.vcxproj @@ -245,6 +245,7 @@ + diff --git a/Test/GacUISrc/UnitTest/UnitTest.vcxproj.filters b/Test/GacUISrc/UnitTest/UnitTest.vcxproj.filters index 21a36f924..4e1b0aef3 100644 --- a/Test/GacUISrc/UnitTest/UnitTest.vcxproj.filters +++ b/Test/GacUISrc/UnitTest/UnitTest.vcxproj.filters @@ -258,6 +258,9 @@ Source Files\Remote + + Source Files\Remote +