Skip to content

Commit

Permalink
New test case for async channel
Browse files Browse the repository at this point in the history
  • Loading branch information
vczh committed Feb 16, 2025
1 parent 44f8727 commit 9fa7a5b
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 7 deletions.
9 changes: 8 additions & 1 deletion Source/UnitTestUtilities/GuiUnitTestProtocol_Shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
};
Expand Down
21 changes: 17 additions & 4 deletions Source/UnitTestUtilities/GuiUnitTestUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,9 @@ void GacUIUnitTest_Start(const WString& appName, Nullable<UnitTestScreenConfig>

// Core
repeatfiltering::GuiRemoteProtocolFilterVerifier verifierProtocol(
globalConfig.useSyncChannel
? &channelSender
: unitTestProtocol.GetProtocol()
globalConfig.useChannel == UnitTestRemoteChannel::None
? unitTestProtocol.GetProtocol()
: &channelSender
);
repeatfiltering::GuiRemoteProtocolFilter filteredProtocol(&verifierProtocol);
GuiRemoteProtocolDomDiffConverter diffConverterProtocol(&filteredProtocol);
Expand All @@ -328,6 +328,11 @@ void GacUIUnitTest_Start(const WString& appName, Nullable<UnitTestScreenConfig>
GacUIUnitTest_LogDiffs(appName, unitTestProtocol);
}

void GacUIUnitTest_StartAsync(const WString& appName, Nullable<UnitTestScreenConfig> config)
{
CHECK_FAIL(L"Not Implemented!");
}

void GacUIUnitTest_Start_WithResourceAsText(const WString& appName, Nullable<UnitTestScreenConfig> config, const WString& resourceText)
{
#define ERROR_MESSAGE_PREFIX L"GacUIUnitTest_Start_WithResourceAsText(const WString&, Nullable<UnitTestScreenConfig>, const WString&)#"
Expand Down Expand Up @@ -363,7 +368,15 @@ void GacUIUnitTest_Start_WithResourceAsText(const WString& appName, Nullable<Uni
}
previousMainProxy(protocol, context);
});
GacUIUnitTest_Start(appName, config);

if (config && config.Value().useChannel == UnitTestRemoteChannel::Async)
{
GacUIUnitTest_StartAsync(appName, config);
}
else
{
GacUIUnitTest_Start(appName, config);
}
#undef ERROR_MESSAGE_PREFIX
}

Expand Down
1 change: 1 addition & 0 deletions Source/UnitTestUtilities/GuiUnitTestUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ extern void GacUIUnitTest_Finalize();
extern void GacUIUnitTest_SetGuiMainProxy(const vl::presentation::unittest::UnitTestMainFunc& proxy);
extern void GacUIUnitTest_LinkGuiMainProxy(const vl::presentation::unittest::UnitTestLinkFunc& proxy);
extern void GacUIUnitTest_Start(const vl::WString& appName, vl::Nullable<vl::presentation::unittest::UnitTestScreenConfig> config = {});
extern void GacUIUnitTest_StartAsync(const vl::WString& appName, vl::Nullable<vl::presentation::unittest::UnitTestScreenConfig> config = {});
extern void GacUIUnitTest_Start_WithResourceAsText(const vl::WString& appName, vl::Nullable<vl::presentation::unittest::UnitTestScreenConfig> config, const vl::WString& resourceText);
extern vl::Ptr<vl::presentation::GuiResource> GacUIUnitTest_CompileAndLoad(const vl::WString& xmlResource);

Expand Down
4 changes: 2 additions & 2 deletions Test/GacUISrc/UnitTest/TestRemote_UnitTestFramework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ TEST_FILE

UnitTestScreenConfig globalConfig;
globalConfig.FastInitialize(1024, 768);
globalConfig.useSyncChannel = true;
globalConfig.useChannel = UnitTestRemoteChannel::Sync;

GacUIUnitTest_StartFast_WithResourceAsText<darkskin::Theme>(
WString::Unmanaged(L"UnitTestFramework/Channel/Sync"),
Expand Down Expand Up @@ -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<darkskin::Theme>(
WString::Unmanaged(L"UnitTestFramework/Channel/Everything"),
Expand Down
72 changes: 72 additions & 0 deletions Test/GacUISrc/UnitTest/TestRemote_UnitTestFramework_Async.cpp
Original file line number Diff line number Diff line change
@@ -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(
<Resource>
<Instance name="MainWindowResource">
<Instance ref.Class="gacuisrc_unittest::MainWindow">
<Window ref.Name="self" Text="Hello, world!" ClientSize="x:320 y:240">
<Button ref.Name="buttonOK" Text="OK">
<att.BoundsComposition-set AlignmentToParent="left:5 top:5 right:-1 bottom:-1"/>
<ev.Clicked-eval><![CDATA[ {
Application::GetApplication().InvokeInMainThread(self, func():void{self.Hide();});
} ]]></ev.Clicked-eval>
</Button>
</Window>
</Instance>
</Instance>
</Resource>
)GacUISrc";

auto sharedProxy = [](UnitTestRemoteProtocol* protocol, IUnitTestContext*)
{
protocol->OnNextIdleFrame(L"Ready", [=]()
{
auto window = GetApplication()->GetMainWindow();
auto buttonOK = TryFindObjectByName<GuiButton>(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<darkskin::Theme>(
WString::Unmanaged(L"UnitTestFramework/Channel/Async"),
WString::Unmanaged(L"gacuisrc_unittest::MainWindow"),
resource,
globalConfig
);
});
});
}
1 change: 1 addition & 0 deletions Test/GacUISrc/UnitTest/UnitTest.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@
<ClCompile Include="TestRemote_RenderingDom.cpp" />
<ClCompile Include="TestRemote_Startup.cpp" />
<ClCompile Include="TestRemote_UnitTestFramework.cpp" />
<ClCompile Include="TestRemote_UnitTestFramework_Async.cpp" />
<ClCompile Include="TestResource.cpp" />
</ItemGroup>
<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions Test/GacUISrc/UnitTest/UnitTest.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@
<ClCompile Include="TestRemote_RenderingDom.cpp">
<Filter>Source Files\Remote</Filter>
</ClCompile>
<ClCompile Include="TestRemote_UnitTestFramework_Async.cpp">
<Filter>Source Files\Remote</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="TestCompositions.h">
Expand Down

0 comments on commit 9fa7a5b

Please sign in to comment.