-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide winrt_activation_handler to hook/mock activation (#477)
- Loading branch information
Showing
4 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include "winrt/Windows.Foundation.Numerics.h" | ||
#include "catch.hpp" | ||
|
||
using namespace winrt; | ||
using namespace Windows::Foundation; | ||
|
||
namespace | ||
{ | ||
struct custom_factory : implements<custom_factory, IUriRuntimeClassFactory> | ||
{ | ||
inline static Uri mock_uri{ nullptr }; | ||
|
||
Uri CreateUri(hstring const& value) const | ||
{ | ||
REQUIRE(value == L"http://ignored.com"); | ||
return mock_uri; | ||
} | ||
|
||
Uri CreateWithRelativeUri(hstring const&, hstring const&) const | ||
{ | ||
throw hresult_not_implemented(); | ||
} | ||
}; | ||
|
||
int32_t __stdcall handler(void* classId, winrt::guid const& iid, void** factory) noexcept | ||
{ | ||
bool expected = reinterpret_cast<hstring const&>(classId) == L"Windows.Foundation.Uri"; | ||
REQUIRE(expected); | ||
REQUIRE(iid == guid_of<IUriRuntimeClassFactory>()); | ||
|
||
*factory = detach_abi(make<custom_factory>()); | ||
return 0; | ||
} | ||
} | ||
|
||
TEST_CASE("custom_activation") | ||
{ | ||
custom_factory::mock_uri = Uri(L"http://actual.com"); | ||
clear_factory_cache(); | ||
|
||
// Set up global handler | ||
REQUIRE(!winrt_activation_handler); | ||
winrt_activation_handler = handler; | ||
|
||
// Windows.Foundation.Uri activation factory now returns mock object | ||
auto uri = Uri(L"http://ignored.com"); | ||
REQUIRE(uri.Domain() == L"actual.com"); | ||
|
||
// Remove global handler | ||
winrt_activation_handler = nullptr; | ||
clear_factory_cache(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters