From 45d6a349c57b35906f195095e127666b197b5599 Mon Sep 17 00:00:00 2001 From: Paul Purifoy Date: Thu, 7 Apr 2022 13:13:17 -0700 Subject: [PATCH 01/16] Work in progress --- test/PowerNotifications/APITests.cpp | 8 +- .../PowerNotifications.vcxproj | 6 +- test/PushNotificationTests/APITests.cpp | 328 ------------------ test/PushNotificationTests/LRPTests.cpp | 5 + test/PushNotificationTests/PackagedTests.cpp | 143 ++++++++ .../PushNotificationTests.vcxproj | 180 +++------- .../PushNotificationTests.vcxproj.filters | 18 +- .../PushNotifications-AppxManifest.xml | 53 +++ test/PushNotificationTests/TestFunctions.cpp | 153 ++++++++ test/PushNotificationTests/TestFunctions.h | 18 + .../PushNotificationTests/UnpackagedTests.cpp | 220 ++++++++++++ test/PushNotificationTests/pch.h | 6 + test/inc/TestDef.h | 3 + 13 files changed, 670 insertions(+), 471 deletions(-) delete mode 100644 test/PushNotificationTests/APITests.cpp create mode 100644 test/PushNotificationTests/PackagedTests.cpp create mode 100644 test/PushNotificationTests/PushNotifications-AppxManifest.xml create mode 100644 test/PushNotificationTests/TestFunctions.cpp create mode 100644 test/PushNotificationTests/TestFunctions.h create mode 100644 test/PushNotificationTests/UnpackagedTests.cpp diff --git a/test/PowerNotifications/APITests.cpp b/test/PowerNotifications/APITests.cpp index 3af302b558..0418f62882 100644 --- a/test/PowerNotifications/APITests.cpp +++ b/test/PowerNotifications/APITests.cpp @@ -3,9 +3,11 @@ #include "pch.h" #include "winrt/Microsoft.Windows.System.Power.h" +#include "winrt/Microsoft.Windows.PushNotifications.h" using namespace std::chrono_literals; using namespace winrt::Microsoft::Windows::System::Power; +using namespace winrt::Microsoft::Windows::PushNotifications; namespace Test::PowerNotifications { @@ -51,8 +53,10 @@ namespace Test::PowerNotifications TEST_METHOD(GetBatteryStatus) { - auto value = PowerManager::BatteryStatus(); - VERIFY_ARE_EQUAL(value, BatteryStatus::NotPresent); + /*auto value = PowerManager::BatteryStatus(); + VERIFY_ARE_EQUAL(value, BatteryStatus::NotPresent);*/ + + PushNotificationManager::Default().Register(); } TEST_METHOD(GetPowerSupplyStatus) diff --git a/test/PowerNotifications/PowerNotifications.vcxproj b/test/PowerNotifications/PowerNotifications.vcxproj index f4a2456b12..2a691b85da 100644 --- a/test/PowerNotifications/PowerNotifications.vcxproj +++ b/test/PowerNotifications/PowerNotifications.vcxproj @@ -173,6 +173,10 @@ + + ..\..\BuildOutput\Debug\x64\WindowsAppRuntime_DLL\Microsoft.Windows.PushNotifications.winmd + true + $(OutDir)\..\WindowsAppRuntime_DLL\Microsoft.Windows.System.Power.winmd true @@ -210,4 +214,4 @@ - + \ No newline at end of file diff --git a/test/PushNotificationTests/APITests.cpp b/test/PushNotificationTests/APITests.cpp deleted file mode 100644 index 1215b71713..0000000000 --- a/test/PushNotificationTests/APITests.cpp +++ /dev/null @@ -1,328 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See LICENSE in the project root for license information. - -#include "pch.h" -#include -#include "MockBackgroundTaskInstance.h" - -using namespace WEX::Common; -using namespace WEX::Logging; -using namespace WEX::TestExecution; - -using namespace winrt::Windows::ApplicationModel::Activation; -using namespace winrt::Windows::ApplicationModel::Background; -using namespace winrt::Windows::Foundation; -using namespace winrt::Windows::Foundation::Collections; -using namespace winrt::Windows::Management::Deployment; -using namespace winrt::Windows::Storage; -using namespace winrt::Windows::System; - -namespace Test::PushNotifications -{ - class APITests - { - private: - wil::unique_event m_failed; - wil::unique_process_handle m_processHandle; - winrt::com_ptr m_testAppLauncher; - - public: - BEGIN_TEST_CLASS(APITests) - TEST_CLASS_PROPERTY(L"Description", L"Windows App SDK Push Notifications test") - TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") - TEST_CLASS_PROPERTY(L"RunAs:Class", L"RestrictedUser") - END_TEST_CLASS() - - static const int testWaitTime() - { - return 3000; - } - - static const int channelTestWaitTime() - { - return 303000; // Need to wait 300000ms for channel request + 3000ms for application overhead - } - - static PCWSTR GetTestPackageFile() - { - return L"PushNotificationsTestAppPackage"; - } - - static PCWSTR GetTestPackageFullName() - { - return L"PushNotificationsTestAppPackage_1.0.0.0_" WINDOWSAPPRUNTIME_TEST_PACKAGE_DDLM_ARCHITECTURE L"__8wekyb3d8bbwe"; - } - - TEST_CLASS_SETUP(ClassInit) - { - try - { - // Cleanup previous installations. Need this to remove any manual installations outside of running this tests. - TP::RemovePackage(GetTestPackageFullName()); - TP::RemovePackage_PushNotificationsLongRunningTask(); - TP::RemovePackage_DynamicDependencyLifetimeManager(); - TP::RemovePackage_DynamicDependencyDataStore(); - TP::RemovePackage_WindowsAppRuntimeFramework(); - - TP::AddPackage_WindowsAppRuntimeFramework(); // Installs WARfwk - TP::AddPackage_DynamicDependencyDataStore(); // Installs WARmain - TP::AddPackage_DynamicDependencyLifetimeManager(); // Installs WARddlm - TP::AddPackage_PushNotificationsLongRunningTask(); // Installs the PushNotifications long running task. - TP::WapProj::AddPackage(TAEF::GetDeploymentDir(), GetTestPackageFile(), L".msix"); // Installs PushNotificationsTestApp.msix - } - catch (...) - { - return false; - } - - m_testAppLauncher = winrt::create_instance(CLSID_ApplicationActivationManager, CLSCTX_ALL); - return true; - } - - TEST_CLASS_CLEANUP(ClassUninit) - { - try - { - // Remove in reverse order to avoid conflicts between inter-dependent packages. - TP::RemovePackage(GetTestPackageFullName()); - TP::RemovePackage_PushNotificationsLongRunningTask(); - TP::RemovePackage_DynamicDependencyLifetimeManager(); - TP::RemovePackage_DynamicDependencyDataStore(); - TP::RemovePackage_WindowsAppRuntimeFramework(); - } - catch (...) - { - return false; - } - return true; - } - - TEST_METHOD_SETUP(MethodInit) - { - VERIFY_IS_TRUE(TP::IsPackageRegistered_WindowsAppRuntimeFramework()); - VERIFY_IS_TRUE(TP::IsPackageRegistered_DynamicDependencyDataStore()); - VERIFY_IS_TRUE(TP::IsPackageRegistered_DynamicDependencyLifetimeManager()); - VERIFY_IS_TRUE(TP::IsPackageRegistered_PushNotificationsLongRunningTask()); - return true; - } - - TEST_METHOD_CLEANUP(MethodUninit) - { - VERIFY_IS_TRUE(TP::IsPackageRegistered_WindowsAppRuntimeFramework()); - VERIFY_IS_TRUE(TP::IsPackageRegistered_DynamicDependencyDataStore()); - VERIFY_IS_TRUE(TP::IsPackageRegistered_DynamicDependencyLifetimeManager()); - VERIFY_IS_TRUE(TP::IsPackageRegistered_PushNotificationsLongRunningTask()); - - m_processHandle.reset(); - return true; - } - - wil::unique_handle RunUnpackaged(const std::wstring& command, const std::wstring& args, const std::wstring& directory) - { - SHELLEXECUTEINFO ei{}; - ei.cbSize = sizeof(SHELLEXECUTEINFO); - ei.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_DOENVSUBST; - ei.lpFile = command.c_str(); - ei.lpParameters = args.c_str(); - ei.lpDirectory = directory.c_str(); - ei.nShow = SW_NORMAL; - - if (!ShellExecuteEx(&ei)) - { - auto lastError = GetLastError(); - VERIFY_WIN32_SUCCEEDED(lastError); - } - - wil::unique_handle process{ ei.hProcess }; - return process; - } - - void RunTest(const PCWSTR& testName, const int& waitTime) - { - DWORD processId {}; - VERIFY_SUCCEEDED(m_testAppLauncher->ActivateApplication(L"PushNotificationsTestAppPackage_8wekyb3d8bbwe!App", testName, AO_NONE, &processId)); - - m_processHandle.reset(OpenProcess(SYNCHRONIZE | PROCESS_QUERY_LIMITED_INFORMATION, FALSE, processId)); - VERIFY_IS_TRUE(m_processHandle.is_valid()); - - VERIFY_IS_TRUE(wil::handle_wait(m_processHandle.get(), waitTime)); - - DWORD exitCode {}; - VERIFY_WIN32_BOOL_SUCCEEDED(GetExitCodeProcess(m_processHandle.get(), &exitCode)); - VERIFY_ARE_EQUAL(exitCode, 0); - } - - const std::wstring GetDeploymentDir() - { - WEX::Common::String deploymentDir; - WEX::TestExecution::RuntimeParameters::TryGetValue(L"TestDeploymentDir", deploymentDir); - return reinterpret_cast(deploymentDir.GetBuffer()); - } - - void RunTestUnpackaged(const PCWSTR& testName, const int& waitTime) - { - auto processHandle = RunUnpackaged(L"PushNotificationsTestApp.exe", testName, GetDeploymentDir()); - VERIFY_IS_TRUE(processHandle.is_valid()); - - VERIFY_IS_TRUE(wil::handle_wait(processHandle.get(), channelTestWaitTime())); - - DWORD exitCode{}; - VERIFY_WIN32_BOOL_SUCCEEDED(GetExitCodeProcess(processHandle.get(), &exitCode)); - VERIFY_ARE_EQUAL(exitCode, 0); - } - - TEST_METHOD(BackgroundActivation) - { - RunTest(L"BackgroundActivationTest", testWaitTime()); // Need to launch one time to enable background activation. - - auto LocalBackgroundTask = winrt::create_instance(c_comServerId, CLSCTX_ALL); - auto mockBackgroundTaskInstance = winrt::make(); - VERIFY_NO_THROW(LocalBackgroundTask.Run(mockBackgroundTaskInstance)); - } - - TEST_METHOD(MultipleBackgroundActivation) - { - RunTest(L"BackgroundActivationTest", testWaitTime()); // Need to launch one time to enable background activation. - - auto LocalBackgroundTask1 = winrt::create_instance(c_comServerId, CLSCTX_ALL); - auto mockBackgroundTaskInstance1 = winrt::make(); - - auto LocalBackgroundTask2 = winrt::create_instance(c_comServerId, CLSCTX_ALL); - auto mockBackgroundTaskInstance2 = winrt::make(); - - VERIFY_NO_THROW(LocalBackgroundTask1.Run(mockBackgroundTaskInstance1)); - VERIFY_NO_THROW(LocalBackgroundTask2.Run(mockBackgroundTaskInstance2)); - - } - - TEST_METHOD(ChannelRequestUsingNullRemoteId) - { - RunTest(L"ChannelRequestUsingNullRemoteId", testWaitTime()); - } - - TEST_METHOD(ChannelRequestUsingNullRemoteId_Unpackaged) - { - RunTestUnpackaged(L"ChannelRequestUsingNullRemoteId", testWaitTime()); - } - - TEST_METHOD(ChannelRequestUsingRemoteId) - { - RunTest(L"ChannelRequestUsingRemoteId", channelTestWaitTime()); - } - - TEST_METHOD(ChannelRequestUsingRemoteId_Unpackaged) - { - RunTestUnpackaged(L"ChannelRequestUsingRemoteId", channelTestWaitTime()); - } - - TEST_METHOD(MultipleChannelClose_Unpackaged) - { - RunTestUnpackaged(L"MultipleChannelClose", 3000000); - } - - TEST_METHOD(VerifyRegisterandUnregister) - { - RunTest(L"VerifyRegisterandUnregister", testWaitTime()); - } - - TEST_METHOD(VerifyRegisterandUnregister_Unpackaged) - { - RunTestUnpackaged(L"VerifyRegisterandUnregister", testWaitTime()); - } - - TEST_METHOD(VerifyRegisterandUnregisterAll) - { - RunTest(L"VerifyRegisterandUnregisterAll", testWaitTime()); - } - - TEST_METHOD(VerifyRegisterandUnregisterAll_Unpackaged) - { - RunTestUnpackaged(L"VerifyRegisterandUnregisterAll", testWaitTime()); - } - - TEST_METHOD(MultipleRegister) - { - RunTest(L"MultipleRegister", testWaitTime()); - } - - TEST_METHOD(MultipleRegister_Unpackaged) - { - RunTestUnpackaged(L"MultipleRegister", testWaitTime()); - } - - TEST_METHOD(VerifyMultipleRegisterAndUnregister) - { - RunTest(L"VerifyMultipleRegisterAndUnregister", testWaitTime()); - } - - TEST_METHOD(VerifyMultipleRegisterAndUnregister_Unpackaged) - { - RunTestUnpackaged(L"VerifyMultipleRegisterAndUnregister", testWaitTime()); - } - - TEST_METHOD(VerifyMultipleRegisterAndUnregisterAll) - { - RunTest(L"VerifyMultipleRegisterAndUnregisterAll", testWaitTime()); - } - - TEST_METHOD(VerifyMultipleRegisterAndUnregisterAll_Unpackaged) - { - RunTestUnpackaged(L"VerifyMultipleRegisterAndUnregisterAll", testWaitTime()); - } - - TEST_METHOD(VerifyUnregisterTwice) - { - RunTest(L"VerifyUnregisterTwice", testWaitTime()); - } - - TEST_METHOD(VerifyUnregisterTwice_Unpackaged) - { - RunTestUnpackaged(L"VerifyUnregisterTwice", testWaitTime()); - } - - TEST_METHOD(VerifyUnregisterAll) - { - RunTest(L"VerifyUnregisterAll", testWaitTime()); - } - - TEST_METHOD(VerifyUnregisterAll_Unpackaged) - { - RunTestUnpackaged(L"VerifyUnregisterAll", testWaitTime()); - } - - TEST_METHOD(VerifyUnregisterAllTwice) - { - RunTest(L"VerifyUnregisterAllTwice", testWaitTime()); - } - - TEST_METHOD(VerifyUnregisterAllTwice_Unpackaged) - { - RunTestUnpackaged(L"VerifyUnregisterAllTwice", testWaitTime()); - } - - TEST_METHOD(VerifyUnregisterAndUnregisterAll) - { - RunTest(L"VerifyUnregisterAndUnregisterAll", testWaitTime()); - } - - TEST_METHOD(VerifyUnregisterAndUnregisterAll_Unpackaged) - { - RunTestUnpackaged(L"VerifyUnregisterAndUnregisterAll", testWaitTime()); - } - - TEST_METHOD(VerifyForegroundHandlerSucceeds) - { - RunTest(L"VerifyForegroundHandlerSucceeds", testWaitTime()); - } - - TEST_METHOD(VerifyForegroundHandlerFails) - { - RunTest(L"VerifyForegroundHandlerFails", testWaitTime()); - } - - TEST_METHOD(VerifyProtocolActivation_Unpackaged) - { - RunTestUnpackaged(L"----WindowsAppRuntimePushServer:-Payload:\"\"", testWaitTime()); - } - }; -} diff --git a/test/PushNotificationTests/LRPTests.cpp b/test/PushNotificationTests/LRPTests.cpp index d5f294e964..0de336bc58 100644 --- a/test/PushNotificationTests/LRPTests.cpp +++ b/test/PushNotificationTests/LRPTests.cpp @@ -34,6 +34,11 @@ namespace Test::PushNotifications try { VERIFY_SUCCEEDED(::CoInitializeEx(nullptr, COINITBASE_MULTITHREADED)); + TP::RemovePackage_PushNotificationsLongRunningTask(); + TP::RemovePackage_DynamicDependencyLifetimeManager(); + TP::RemovePackage_DynamicDependencyDataStore(); + TP::RemovePackage_WindowsAppRuntimeFramework(); + TP::AddPackage_WindowsAppRuntimeFramework(); // Installs WASfwk TP::AddPackage_DynamicDependencyDataStore(); // Installs WASmain TP::AddPackage_DynamicDependencyLifetimeManager(); // Installs WASddlm diff --git a/test/PushNotificationTests/PackagedTests.cpp b/test/PushNotificationTests/PackagedTests.cpp new file mode 100644 index 0000000000..4a622022e8 --- /dev/null +++ b/test/PushNotificationTests/PackagedTests.cpp @@ -0,0 +1,143 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +#include "pch.h" +#include +#include "MockBackgroundTaskInstance.h" +#include +#include "TestFunctions.h" + +using namespace WEX::Common; +using namespace WEX::Logging; +using namespace WEX::TestExecution; + +using namespace winrt::Windows::ApplicationModel::Activation; +using namespace winrt::Windows::ApplicationModel::Background; +using namespace winrt::Windows::Foundation; +using namespace winrt::Windows::Foundation::Collections; +using namespace winrt::Windows::Management::Deployment; +using namespace winrt::Windows::Storage; +using namespace winrt::Windows::System; +using namespace winrt::Microsoft::Windows::PushNotifications; + +namespace Test::PushNotifications +{ +#define VERIFY_THROWS_HR(expression, hr) \ + VERIFY_THROWS_SPECIFIC(expression, \ + winrt::hresult_error, \ + [&](winrt::hresult_error e) -> bool \ + { \ + return (e.code() == hr); \ + }) + + class PackagedTests + { + public: + BEGIN_TEST_CLASS(PackagedTests) + TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") + TEST_CLASS_PROPERTY(L"RunFixtureAs:Class", L"RestrictedUser") + TEST_CLASS_PROPERTY(L"RunAs", L"UAP") + TEST_CLASS_PROPERTY(L"UAP:AppxManifest", L"PushNotifications-AppxManifest.xml") + END_TEST_CLASS() + + TEST_CLASS_SETUP(ClassInit) + { + ::Test::Bootstrap::SetupPackages(); + return true; + } + + TEST_CLASS_CLEANUP(ClassUninit) + { + ::Test::Bootstrap::CleanupPackages(); + return true; + } + + TEST_METHOD_SETUP(MethodInit) + { + VERIFY_IS_TRUE(TP::IsPackageRegistered_DynamicDependencyDataStore()); + VERIFY_IS_TRUE(TP::IsPackageRegistered_DynamicDependencyLifetimeManager()); + return true; + } + + TEST_METHOD_CLEANUP(MethodUninit) + { + VERIFY_IS_TRUE(TP::IsPackageRegistered_DynamicDependencyDataStore()); + VERIFY_IS_TRUE(TP::IsPackageRegistered_DynamicDependencyLifetimeManager()); + return true; + } + + TEST_METHOD(ChannelRequestUsingNullRemoteId) + { + // Need to use SelfContained test hook to setup tests. + ::WindowsAppRuntime::SelfContained::TestInitialize(::Test::Bootstrap::TP::WindowsAppRuntimeFramework::c_PackageFamilyName); + + TestFunctions::ChannelRequestUsingNullRemoteId(); + } + + TEST_METHOD(ChannelRequestUsingRemoteId) + { + TestFunctions::ChannelRequestUsingRemoteId(); + } + + // Currently failing. + TEST_METHOD(MultipleChannelClose) + { + TestFunctions::MultipleChannelClose(); + } + + TEST_METHOD(VerifyRegisterAndUnregister) + { + TestFunctions::VerifyRegisterAndUnregister(); + } + + TEST_METHOD(VerifyRegisterAndUnregisterAll) + { + TestFunctions::VerifyRegisterAndUnregisterAll(); + } + + TEST_METHOD(MultipleRegister) + { + TestFunctions::MultipleRegister(); + } + + TEST_METHOD(VerifyMultipleRegisterAndUnregister) + { + TestFunctions::VerifyMultipleRegisterAndUnregister(); + } + + TEST_METHOD(VerifyMultipleRegisterAndUnregisterAll) + { + TestFunctions::VerifyMultipleRegisterAndUnregisterAll(); + } + + TEST_METHOD(VerifyUnregisterTwice) + { + TestFunctions::VerifyUnregisterTwice(); + } + + TEST_METHOD(VerifyUnregisterAll) + { + TestFunctions::VerifyUnregisterAll(); + } + + TEST_METHOD(VerifyUnregisterAllTwice) + { + TestFunctions::VerifyUnregisterAllTwice(); + } + + TEST_METHOD(VerifyUnregisterAndUnregisterAll) + { + TestFunctions::VerifyUnregisterAndUnregisterAll(); + } + + TEST_METHOD(VerifyForegroundHandlerSucceeds) + { + TestFunctions::VerifyForegroundHandlerSucceeds(); + } + + TEST_METHOD(VerifyForegroundHandlerFails) + { + TestFunctions::VerifyForegroundHandlerFails(); + } + }; +} diff --git a/test/PushNotificationTests/PushNotificationTests.vcxproj b/test/PushNotificationTests/PushNotificationTests.vcxproj index f25487a212..65cbb413cd 100644 --- a/test/PushNotificationTests/PushNotificationTests.vcxproj +++ b/test/PushNotificationTests/PushNotificationTests.vcxproj @@ -35,53 +35,25 @@ 10.0 - - DynamicLibrary - true - v142 - Unicode - - - DynamicLibrary - false - v142 - true - Unicode - - + DynamicLibrary - true + false v142 Unicode - - DynamicLibrary + + false false - v142 true - Unicode - - DynamicLibrary + + true true - v142 - Unicode - false - - - DynamicLibrary - false - v142 - true - Unicode - false - - - + @@ -94,146 +66,64 @@ - + - + - - true - - - false - - - true - - - false - - - true - - - false - - + Use - Level3 - true - true + Level4 true - %(AdditionalIncludeDirectories);$(OutDir)\..\WindowsAppRuntime_DLL;..\inc;$(OutDir)\..\WindowsAppRuntime_BootstrapDLL;$(OutDir)..\PushNotificationsLongRunningTask.ProxyStub - WIN32;NDEBUG;%(PreprocessorDefinitions);;INLINE_TEST_METHOD_MARKUP true pch.h + $(OutDir)..\PushNotificationsLongRunningTask.ProxyStub;$(RepoRoot)\test\inc;$(RepoRoot)\Dev\Common;$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories);$(OutDir)\..\WindowsAppRuntime_DLL;$(OutDir)\..\WindowsAppRuntime_BootstrapDLL + $(RepoRoot);%(AdditionalIncludeDirectories) Windows - true - true - $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories);$(OutDir)\..\WindowsAppRuntime_DLL onecore.lib;onecoreuap.lib;Microsoft.WindowsAppRuntime.lib;wex.common.lib;wex.logger.lib;te.common.lib;%(AdditionalDependencies) - - - - - Use - Level3 - true - %(AdditionalIncludeDirectories);$(OutDir)\..\WindowsAppRuntime_DLL;..\inc;$(OutDir)\..\WindowsAppRuntime_BootstrapDLL;$(OutDir)..\PushNotificationsLongRunningTask.ProxyStub - WIN32;_DEBUG;%(PreprocessorDefinitions);;INLINE_TEST_METHOD_MARKUP - true - pch.h - - - Windows - $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories);$(OutDir)\..\WindowsAppRuntime_DLL - onecore.lib;onecoreuap.lib;Microsoft.WindowsAppRuntime.lib;wex.common.lib;wex.logger.lib;te.common.lib;%(AdditionalDependencies) - - - - - Use - Level3 - true - %(AdditionalIncludeDirectories);$(OutDir)\..\WindowsAppRuntime_DLL;..\inc;$(OutDir)\..\WindowsAppRuntime_BootstrapDLL;$(OutDir)..\PushNotificationsLongRunningTask.ProxyStub - _DEBUG;%(PreprocessorDefinitions);;INLINE_TEST_METHOD_MARKUP - true - pch.h - - - Windows - $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories);$(OutDir)\..\WindowsAppRuntime_DLL - onecore.lib;onecoreuap.lib;Microsoft.WindowsAppRuntime.lib;wex.common.lib;wex.logger.lib;te.common.lib;%(AdditionalDependencies) - - - - - Use - Level3 - true - %(AdditionalIncludeDirectories);$(OutDir)\..\WindowsAppRuntime_DLL;..\inc;$(OutDir)\..\WindowsAppRuntime_BootstrapDLL;$(OutDir)..\PushNotificationsLongRunningTask.ProxyStub - _DEBUG;%(PreprocessorDefinitions);;INLINE_TEST_METHOD_MARKUP - true - pch.h - - - Windows $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories);$(OutDir)\..\WindowsAppRuntime_DLL - onecore.lib;onecoreuap.lib;Microsoft.WindowsAppRuntime.lib;wex.common.lib;wex.logger.lib;te.common.lib;%(AdditionalDependencies) + Microsoft.WindowsAppRuntime.Bootstrap.dll;%(DelayLoadDLLs) + Microsoft.WindowsAppRuntime.dll;%(DelayLoadDLLs) - + - Use - Level3 true true - true - %(AdditionalIncludeDirectories);$(OutDir)\..\WindowsAppRuntime_DLL;..\inc;$(OutDir)\..\WindowsAppRuntime_BootstrapDLL;$(OutDir)..\PushNotificationsLongRunningTask.ProxyStub - NDEBUG;%(PreprocessorDefinitions);;INLINE_TEST_METHOD_MARKUP - true - pch.h + NDEBUG;%(PreprocessorDefinitions) - Windows true true - $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories);$(OutDir)\..\WindowsAppRuntime_DLL - onecore.lib;onecoreuap.lib;Microsoft.WindowsAppRuntime.lib;wex.common.lib;wex.logger.lib;te.common.lib;%(AdditionalDependencies) - + - Use - Level3 - true - true - true - %(AdditionalIncludeDirectories);$(OutDir)\..\WindowsAppRuntime_DLL;..\inc;$(OutDir)\..\WindowsAppRuntime_BootstrapDLL;$(OutDir)..\PushNotificationsLongRunningTask.ProxyStub - NDEBUG;%(PreprocessorDefinitions);;INLINE_TEST_METHOD_MARKUP - true - pch.h + _DEBUG;%(PreprocessorDefinitions) - Windows - true - true - $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories);$(OutDir)\..\WindowsAppRuntime_DLL - onecore.lib;onecoreuap.lib;Microsoft.WindowsAppRuntime.lib;wex.common.lib;wex.logger.lib;te.common.lib;%(AdditionalDependencies) + + + WIN32;%(PreprocessorDefinitions) + + + - + + + @@ -251,6 +141,14 @@ + + + true + true + true + true + + .Debug _Debug @@ -284,6 +182,10 @@ + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. @@ -296,4 +198,4 @@ - + \ No newline at end of file diff --git a/test/PushNotificationTests/PushNotificationTests.vcxproj.filters b/test/PushNotificationTests/PushNotificationTests.vcxproj.filters index fd40c7c2bd..0e1e9a8951 100644 --- a/test/PushNotificationTests/PushNotificationTests.vcxproj.filters +++ b/test/PushNotificationTests/PushNotificationTests.vcxproj.filters @@ -27,12 +27,15 @@ Source Files + + Header Files + Source Files - + Source Files @@ -44,6 +47,12 @@ Source Files + + Source Files + + + Source Files + @@ -54,5 +63,12 @@ CopyFiles + + + + + + Source Files + \ No newline at end of file diff --git a/test/PushNotificationTests/PushNotifications-AppxManifest.xml b/test/PushNotificationTests/PushNotifications-AppxManifest.xml new file mode 100644 index 0000000000..e41c9bf07c --- /dev/null +++ b/test/PushNotificationTests/PushNotifications-AppxManifest.xml @@ -0,0 +1,53 @@ + + + + + + + + WindowsAppRuntime.Test.PushNotifications for tests + Windows APP SDK + taef.png + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/PushNotificationTests/TestFunctions.cpp b/test/PushNotificationTests/TestFunctions.cpp new file mode 100644 index 0000000000..a3892908fd --- /dev/null +++ b/test/PushNotificationTests/TestFunctions.cpp @@ -0,0 +1,153 @@ +#include "pch.h" + +#include "TestFunctions.h" +#include "pch.h" +#include +#include "MockBackgroundTaskInstance.h" +#include + +using namespace WEX::Common; +using namespace WEX::Logging; +using namespace WEX::TestExecution; + +using namespace winrt::Windows::ApplicationModel::Activation; +using namespace winrt::Windows::ApplicationModel::Background; +using namespace winrt::Windows::Foundation; +using namespace winrt::Windows::Foundation::Collections; +using namespace winrt::Windows::Management::Deployment; +using namespace winrt::Windows::Storage; +using namespace winrt::Windows::System; +using namespace winrt::Microsoft::Windows::PushNotifications; + +#define VERIFY_THROWS_HR(expression, hr) \ + VERIFY_THROWS_SPECIFIC(expression, \ + winrt::hresult_error, \ + [&](winrt::hresult_error e) -> bool \ + { \ + return (e.code() == hr); \ + }) + +HRESULT ChannelRequestHelper(IAsyncOperationWithProgress const& channelOperation) +{ + if (channelOperation.wait_for(c_timeout) != winrt::Windows::Foundation::AsyncStatus::Completed) + { + channelOperation.Cancel(); + return HRESULT_FROM_WIN32(ERROR_TIMEOUT); // timed out or failed + } + + auto result{ channelOperation.GetResults() }; + auto status{ result.Status() }; + if (status != PushNotificationChannelStatus::CompletedSuccess) + { + return result.ExtendedError(); // did not produce a channel + } + + result.Channel().Close(); + return S_OK; +} + +void TestFunctions::ChannelRequestUsingNullRemoteId() +{ + VERIFY_THROWS_HR(PushNotificationManager::Default().CreateChannelAsync(winrt::guid()).get(), E_INVALIDARG); +} + +void TestFunctions::ChannelRequestUsingRemoteId() +{ + auto channelOperation{ PushNotificationManager::Default().CreateChannelAsync(c_azureRemoteId) }; + VERIFY_SUCCEEDED(ChannelRequestHelper(channelOperation)); +} + +// Currently failing. +void TestFunctions::MultipleChannelClose() +{ + auto channelOperation{ PushNotificationManager::Default().CreateChannelAsync(c_azureRemoteId) }; + if (channelOperation.wait_for(c_timeout) != winrt::Windows::Foundation::AsyncStatus::Completed) + { + channelOperation.Cancel(); + VERIFY_FAIL(L"Channel request hit timeout."); + } + + auto result{ channelOperation.GetResults() }; + VERIFY_ARE_EQUAL(result.Status(), PushNotificationChannelStatus::CompletedSuccess); + + result.Channel().Close(); + VERIFY_THROWS_HR(result.Channel().Close(), WPN_E_CHANNEL_CLOSED); +} + +void TestFunctions::VerifyRegisterAndUnregister() +{ + auto pushNotificationManager{ PushNotificationManager::Default() }; + pushNotificationManager.Register(); + pushNotificationManager.Unregister(); +} + +void TestFunctions::VerifyRegisterAndUnregisterAll() +{ + auto pushNotificationManager{ PushNotificationManager::Default() }; + pushNotificationManager.Register(); + pushNotificationManager.UnregisterAll(); +} + +void TestFunctions::MultipleRegister() +{ + auto pushNotificationManager{ PushNotificationManager::Default() }; + pushNotificationManager.Register(); + VERIFY_THROWS_HR(pushNotificationManager.Register(), HRESULT_FROM_WIN32(ERROR_ALREADY_REGISTERED)); +} + +void TestFunctions::VerifyMultipleRegisterAndUnregister() +{ + PushNotificationManager::Default().Register(); + PushNotificationManager::Default().Unregister(); + VERIFY_THROWS_HR(PushNotificationManager::Default().Register(), HRESULT_FROM_WIN32(ERROR_ALREADY_REGISTERED)); +} + +void TestFunctions::VerifyMultipleRegisterAndUnregisterAll() +{ + PushNotificationManager::Default().Register(); + PushNotificationManager::Default().UnregisterAll(); + + PushNotificationManager::Default().Register(); + PushNotificationManager::Default().UnregisterAll(); +} + +void TestFunctions::VerifyUnregisterTwice() +{ + PushNotificationManager::Default().Register(); + PushNotificationManager::Default().Unregister(); + VERIFY_THROWS_HR(PushNotificationManager::Default().Unregister(), E_UNEXPECTED); + +} + +void TestFunctions::VerifyUnregisterAll() +{ + PushNotificationManager::Default().Register(); + PushNotificationManager::Default().UnregisterAll(); +} + +void TestFunctions::VerifyUnregisterAllTwice() +{ + PushNotificationManager::Default().Register(); + PushNotificationManager::Default().UnregisterAll(); + VERIFY_THROWS_HR(PushNotificationManager::Default().UnregisterAll(), E_UNEXPECTED); +} + +void TestFunctions::VerifyUnregisterAndUnregisterAll() +{ + PushNotificationManager::Default().Register(); + PushNotificationManager::Default().Unregister(); + PushNotificationManager::Default().UnregisterAll(); +} + +void TestFunctions::VerifyForegroundHandlerSucceeds() +{ + PushNotificationManager::Default().PushReceived([](const auto&, PushNotificationReceivedEventArgs const& /* args */) {}); + PushNotificationManager::Default().Register(); +} + +void TestFunctions::VerifyForegroundHandlerFails() +{ + PushNotificationManager::Default().Register(); + VERIFY_THROWS_HR(PushNotificationManager::Default().PushReceived([](const auto&, PushNotificationReceivedEventArgs const& /* args */) {}), HRESULT_FROM_WIN32(ERROR_NOT_FOUND)); +} + diff --git a/test/PushNotificationTests/TestFunctions.h b/test/PushNotificationTests/TestFunctions.h new file mode 100644 index 0000000000..c3b8aa05e4 --- /dev/null +++ b/test/PushNotificationTests/TestFunctions.h @@ -0,0 +1,18 @@ +class TestFunctions +{ +public: + static void VerifyRegisterAndUnregister(); + static void ChannelRequestUsingNullRemoteId(); + static void ChannelRequestUsingRemoteId(); + static void MultipleChannelClose(); + static void VerifyRegisterAndUnregisterAll(); + static void MultipleRegister(); + static void VerifyMultipleRegisterAndUnregister(); + static void VerifyMultipleRegisterAndUnregisterAll(); + static void VerifyUnregisterTwice(); + static void VerifyUnregisterAll(); + static void VerifyUnregisterAllTwice(); + static void VerifyUnregisterAndUnregisterAll(); + static void VerifyForegroundHandlerSucceeds(); + static void VerifyForegroundHandlerFails(); +}; diff --git a/test/PushNotificationTests/UnpackagedTests.cpp b/test/PushNotificationTests/UnpackagedTests.cpp new file mode 100644 index 0000000000..ac11f18b30 --- /dev/null +++ b/test/PushNotificationTests/UnpackagedTests.cpp @@ -0,0 +1,220 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +#include "pch.h" +#include +#include "MockBackgroundTaskInstance.h" +#include +#include "TestFunctions.h" + +using namespace WEX::Common; +using namespace WEX::Logging; +using namespace WEX::TestExecution; + +using namespace winrt::Windows::ApplicationModel::Activation; +using namespace winrt::Windows::ApplicationModel::Background; +using namespace winrt::Windows::Foundation; +using namespace winrt::Windows::Foundation::Collections; +using namespace winrt::Windows::Management::Deployment; +using namespace winrt::Windows::Storage; +using namespace winrt::Windows::System; +using namespace winrt::Microsoft::Windows::PushNotifications; + +namespace Test::PushNotifications +{ + #define VERIFY_THROWS_HR(expression, hr) \ + VERIFY_THROWS_SPECIFIC(expression, \ + winrt::hresult_error, \ + [&](winrt::hresult_error e) -> bool \ + { \ + return (e.code() == hr); \ + }) + + class UnpackagedTests + { + public: + BEGIN_TEST_CLASS(UnpackagedTests) + TEST_CLASS_PROPERTY(L"Description", L"Windows App SDK Push Notifications test") + TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") + TEST_CLASS_PROPERTY(L"RunAs:Class", L"RestrictedUser") + END_TEST_CLASS() + + TEST_CLASS_SETUP(ClassInit) + { + try + { + // Cleanup previous installations. Need this to remove any manual installations outside of running this tests. + TP::RemovePackage_PushNotificationsLongRunningTask(); + TP::RemovePackage_DynamicDependencyLifetimeManager(); + TP::RemovePackage_DynamicDependencyDataStore(); + TP::RemovePackage_WindowsAppRuntimeFramework(); + + TP::AddPackage_WindowsAppRuntimeFramework(); // Installs WARfwk + TP::AddPackage_DynamicDependencyDataStore(); // Installs WARmain + TP::AddPackage_DynamicDependencyLifetimeManager(); // Installs WARddlm + TP::AddPackage_PushNotificationsLongRunningTask(); // Installs the PushNotifications long running task. + } + catch (...) + { + return false; + } + return true; + } + + void TerminateLRP() + { + wil::unique_handle processesSnapshot(CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)); + VERIFY_IS_NOT_NULL(processesSnapshot.get()); + + PROCESSENTRY32 processEntry = { 0 }; + processEntry.dwSize = sizeof(processEntry); + + BOOL result = Process32First(processesSnapshot.get(), &processEntry); + while (result != FALSE) + { + if (wcscmp(L"PushNotificationsLongRunningTask.exe", processEntry.szExeFile) == 0) + { + DWORD processId = processEntry.th32ProcessID; + + wil::unique_handle longRunningProcessHandle(OpenProcess(PROCESS_TERMINATE, FALSE, processId)); + VERIFY_IS_TRUE(TerminateProcess(longRunningProcessHandle.get(), 0)); + ::WaitForSingleObject(longRunningProcessHandle.get(), 10000); + return; + } + + result = Process32Next(processesSnapshot.get(), &processEntry); + } + } + + TEST_CLASS_CLEANUP(ClassUninit) + { + try + { + // Remove in reverse order to avoid conflicts between inter-dependent packages. + TerminateLRP(); + TP::RemovePackage_PushNotificationsLongRunningTask(); + TP::RemovePackage_DynamicDependencyLifetimeManager(); + TP::RemovePackage_DynamicDependencyDataStore(); + TP::RemovePackage_WindowsAppRuntimeFramework(); + } + catch (...) + { + return false; + } + return true; + } + + TEST_METHOD_SETUP(MethodInit) + { + VERIFY_IS_TRUE(TP::IsPackageRegistered_WindowsAppRuntimeFramework()); + VERIFY_IS_TRUE(TP::IsPackageRegistered_DynamicDependencyDataStore()); + VERIFY_IS_TRUE(TP::IsPackageRegistered_DynamicDependencyLifetimeManager()); + VERIFY_IS_TRUE(TP::IsPackageRegistered_PushNotificationsLongRunningTask()); + + VERIFY_ARE_EQUAL(S_OK, MddBootstrapTestInitialize(Test::Packages::DynamicDependencyLifetimeManager::c_PackageNamePrefix, Test::Packages::DynamicDependencyLifetimeManager::c_PackagePublisherId)); + + // Major.Minor version, MinVersion=0 to find any framework package for this major.minor version + const UINT32 c_Version_MajorMinor{ Test::Packages::DynamicDependencyLifetimeManager::c_Version_MajorMinor }; + const PACKAGE_VERSION c_minVersion{}; + VERIFY_ARE_EQUAL(S_OK, MddBootstrapInitialize(c_Version_MajorMinor, nullptr, c_minVersion)); + + // Need to use SelfContained test hook to setup tests. + ::WindowsAppRuntime::SelfContained::TestInitialize(::Test::Bootstrap::TP::WindowsAppRuntimeFramework::c_PackageFamilyName); + + // Need to keep each TEST_METHOD in a clean state in the LRP. + try + { + PushNotificationManager::Default().UnregisterAll(); + } + catch (...) + { + // We want to unregister regardless of pass/fail to clean the state. + } + return true; + } + + TEST_METHOD_CLEANUP(MethodUninit) + { + MddBootstrapShutdown(); + + VERIFY_IS_TRUE(TP::IsPackageRegistered_WindowsAppRuntimeFramework()); + VERIFY_IS_TRUE(TP::IsPackageRegistered_DynamicDependencyDataStore()); + VERIFY_IS_TRUE(TP::IsPackageRegistered_DynamicDependencyLifetimeManager()); + VERIFY_IS_TRUE(TP::IsPackageRegistered_PushNotificationsLongRunningTask()); + TerminateLRP(); + + return true; + } + + TEST_METHOD(ChannelRequestUsingNullRemoteId) + { + TestFunctions::ChannelRequestUsingNullRemoteId(); + } + + TEST_METHOD(ChannelRequestUsingRemoteId) + { + TestFunctions::ChannelRequestUsingRemoteId(); + } + + // Currently failing. + TEST_METHOD(MultipleChannelClose) + { + TestFunctions::MultipleChannelClose(); + } + + TEST_METHOD(VerifyRegisterAndUnregister) + { + TestFunctions::VerifyRegisterAndUnregister(); + } + + TEST_METHOD(VerifyRegisterAndUnregisterAll) + { + TestFunctions::VerifyRegisterAndUnregisterAll(); + } + + TEST_METHOD(MultipleRegister) + { + TestFunctions::MultipleRegister(); + } + + TEST_METHOD(VerifyMultipleRegisterAndUnregister) + { + TestFunctions::VerifyMultipleRegisterAndUnregister(); + } + + TEST_METHOD(VerifyMultipleRegisterAndUnregisterAll) + { + TestFunctions::VerifyMultipleRegisterAndUnregisterAll(); + } + + TEST_METHOD(VerifyUnregisterTwice) + { + TestFunctions::VerifyUnregisterTwice(); + } + + TEST_METHOD(VerifyUnregisterAll) + { + TestFunctions::VerifyUnregisterAll(); + } + + TEST_METHOD(VerifyUnregisterAllTwice) + { + TestFunctions::VerifyUnregisterAllTwice(); + } + + TEST_METHOD(VerifyUnregisterAndUnregisterAll) + { + TestFunctions::VerifyUnregisterAndUnregisterAll(); + } + + TEST_METHOD(VerifyForegroundHandlerSucceeds) + { + TestFunctions::VerifyForegroundHandlerSucceeds(); + } + + TEST_METHOD(VerifyForegroundHandlerFails) + { + TestFunctions::VerifyForegroundHandlerFails(); + } + }; +} diff --git a/test/PushNotificationTests/pch.h b/test/PushNotificationTests/pch.h index dea78ec628..fee347ce38 100644 --- a/test/PushNotificationTests/pch.h +++ b/test/PushNotificationTests/pch.h @@ -6,6 +6,11 @@ #include +#ifndef INLINE_TEST_METHOD_MARKUP +#define INLINE_TEST_METHOD_MARKUP +#endif + +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers #include #include #include @@ -39,6 +44,7 @@ #include #include +#include namespace TP = ::Test::Packages; namespace TAEF = ::Test::TAEF; diff --git a/test/inc/TestDef.h b/test/inc/TestDef.h index 8adf3f430f..f7cc632b74 100644 --- a/test/inc/TestDef.h +++ b/test/inc/TestDef.h @@ -23,6 +23,9 @@ static const std::wstring c_testRequestRestartNowRestartedPhasePackagedEventName static const std::wstring c_testPushPhaseEventName = L"WindowsAppRuntimeTestPushPhaseEventName"; inline const winrt::hstring c_rawNotificationPayload = L""; +static const std::chrono::seconds c_timeout = std::chrono::seconds(300); +inline IID c_azureRemoteId = winrt::guid(L"a2e4a323-b518-4799-9e80-0b37aeb0d225"); // Generated from ms.portal.azure.com +inline IID c_dummyRemoteId = winrt::guid(L"CA1A4AB2-AC1D-4EFC-A132-E5A191CA285A"); // Dummy guid from visual studio guid tool generator inline IID c_remoteId = winrt::guid("A7652901-313C-4EFA-A303-95C371A00DAB"); inline IID c_comServerId = winrt::guid("ccd2ae3f-764f-4ae3-be45-9804761b28b2"); // Value from PushNotificationsTestAppPackage ComActivator in appxmanifest. inline IID c_toastComServerId = winrt::guid("1940dba9-0f64-4f0d-8a4b-5d207b812e61"); // Value from ToastNotificationsTestAppPackage ComActivator in appxmanifest. From 310f7dc09572b3f476edb37793399f117a06c3f8 Mon Sep 17 00:00:00 2001 From: Paul Purifoy Date: Mon, 11 Apr 2022 14:16:41 -0700 Subject: [PATCH 02/16] Push tests working individually --- .../PackagedSelfContainedTests.cpp | 144 ++++++++++++ test/PushNotificationTests/PackagedTests.cpp | 55 +++-- .../PushNotificationTests.vcxproj | 179 +++++++++------ .../PushNotificationTests.vcxproj.filters | 21 +- .../PushNotifications-AppxManifest.xml | 65 +++--- test/PushNotificationTests/TestFunctions.cpp | 30 ++- test/PushNotificationTests/TestFunctions.h | 32 +-- .../UnpackagedSelfContained.cpp | 214 ++++++++++++++++++ .../PushNotificationTests/UnpackagedTests.cpp | 103 ++------- 9 files changed, 577 insertions(+), 266 deletions(-) create mode 100644 test/PushNotificationTests/PackagedSelfContainedTests.cpp create mode 100644 test/PushNotificationTests/UnpackagedSelfContained.cpp diff --git a/test/PushNotificationTests/PackagedSelfContainedTests.cpp b/test/PushNotificationTests/PackagedSelfContainedTests.cpp new file mode 100644 index 0000000000..bd6eeb9059 --- /dev/null +++ b/test/PushNotificationTests/PackagedSelfContainedTests.cpp @@ -0,0 +1,144 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +#include "pch.h" +#include +#include "MockBackgroundTaskInstance.h" +#include +#include "TestFunctions.h" + +using namespace WEX::Common; +using namespace WEX::Logging; +using namespace WEX::TestExecution; + +using namespace winrt::Windows::ApplicationModel::Activation; +using namespace winrt::Windows::ApplicationModel::Background; +using namespace winrt::Windows::Foundation; +using namespace winrt::Windows::Foundation::Collections; +using namespace winrt::Windows::Management::Deployment; +using namespace winrt::Windows::Storage; +using namespace winrt::Windows::System; +using namespace winrt::Microsoft::Windows::PushNotifications; + +namespace Test::PushNotifications +{ + class PackagedSelfContainedTests + { + + public: + BEGIN_TEST_CLASS(PackagedSelfContainedTests) + TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") + TEST_CLASS_PROPERTY(L"RunFixtureAs:Class", L"RestrictedUser") + TEST_CLASS_PROPERTY(L"RunAs", L"UAP") + TEST_CLASS_PROPERTY(L"UAP:AppxManifest", L"PushNotifications-AppxManifest.xml") + TEST_CLASS_PROPERTY(L"UAP:Host", L"PackagedCWA") + END_TEST_CLASS() + + TEST_CLASS_SETUP(ClassInit) + { + ::Test::Bootstrap::SetupPackages(); + return true; + } + + TEST_CLASS_CLEANUP(ClassUninit) + { + ::Test::Bootstrap::CleanupPackages(); + return true; + } + + TEST_METHOD_SETUP(MethodInit) + { + VERIFY_IS_TRUE(TP::IsPackageRegistered_DynamicDependencyDataStore()); + VERIFY_IS_TRUE(TP::IsPackageRegistered_DynamicDependencyLifetimeManager()); + return true; + } + + TEST_METHOD_CLEANUP(MethodUninit) + { + VERIFY_IS_TRUE(TP::IsPackageRegistered_DynamicDependencyDataStore()); + VERIFY_IS_TRUE(TP::IsPackageRegistered_DynamicDependencyLifetimeManager()); + + // Need to keep each TEST_METHOD in clean state. + try + { + PushNotificationManager::Default().UnregisterAll(); + } + catch (...) + { + // We want to unregister regardless of pass/fail to clean the state. + } + return true; + } + + TEST_METHOD(ChannelRequestUsingNullRemoteId) + { + PushNotificationTestFunctions::ChannelRequestUsingNullRemoteId(); + } + + TEST_METHOD(ChannelRequestUsingRemoteId) + { + PushNotificationTestFunctions::ChannelRequestUsingRemoteId(); + } + + // Currently failing. + TEST_METHOD(MultipleChannelClose) + { + PushNotificationTestFunctions::MultipleChannelClose(); + } + + TEST_METHOD(VerifyRegisterAndUnregister) + { + PushNotificationTestFunctions::VerifyRegisterAndUnregister(); + } + + TEST_METHOD(VerifyRegisterAndUnregisterAll) + { + PushNotificationTestFunctions::VerifyRegisterAndUnregisterAll(); + } + + TEST_METHOD(MultipleRegister) + { + PushNotificationTestFunctions::MultipleRegister(); + } + + TEST_METHOD(VerifyMultipleRegisterAndUnregister) + { + PushNotificationTestFunctions::VerifyMultipleRegisterAndUnregister(); + } + + TEST_METHOD(VerifyMultipleRegisterAndUnregisterAll) + { + PushNotificationTestFunctions::VerifyMultipleRegisterAndUnregisterAll(); + } + + TEST_METHOD(VerifyUnregisterTwice) + { + PushNotificationTestFunctions::VerifyUnregisterTwice(); + } + + TEST_METHOD(VerifyUnregisterAll) + { + PushNotificationTestFunctions::VerifyUnregisterAll(); + } + + TEST_METHOD(VerifyUnregisterAllTwice) + { + PushNotificationTestFunctions::VerifyUnregisterAllTwice(); + } + + TEST_METHOD(VerifyUnregisterAndUnregisterAll) + { + PushNotificationTestFunctions::VerifyUnregisterAndUnregisterAll(); + } + + TEST_METHOD(VerifyForegroundHandlerSucceeds) + { + PushNotificationTestFunctions::VerifyForegroundHandlerSucceeds(); + } + + TEST_METHOD(VerifyForegroundHandlerFails) + { + PushNotificationTestFunctions::VerifyForegroundHandlerFails(); + } + }; +} diff --git a/test/PushNotificationTests/PackagedTests.cpp b/test/PushNotificationTests/PackagedTests.cpp index 4a622022e8..5c93c252b1 100644 --- a/test/PushNotificationTests/PackagedTests.cpp +++ b/test/PushNotificationTests/PackagedTests.cpp @@ -22,22 +22,16 @@ using namespace winrt::Microsoft::Windows::PushNotifications; namespace Test::PushNotifications { -#define VERIFY_THROWS_HR(expression, hr) \ - VERIFY_THROWS_SPECIFIC(expression, \ - winrt::hresult_error, \ - [&](winrt::hresult_error e) -> bool \ - { \ - return (e.code() == hr); \ - }) - class PackagedTests { + public: BEGIN_TEST_CLASS(PackagedTests) TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") TEST_CLASS_PROPERTY(L"RunFixtureAs:Class", L"RestrictedUser") TEST_CLASS_PROPERTY(L"RunAs", L"UAP") TEST_CLASS_PROPERTY(L"UAP:AppxManifest", L"PushNotifications-AppxManifest.xml") + TEST_CLASS_PROPERTY(L"UAP:Host", L"PackagedCWA") END_TEST_CLASS() TEST_CLASS_SETUP(ClassInit) @@ -54,90 +48,93 @@ namespace Test::PushNotifications TEST_METHOD_SETUP(MethodInit) { - VERIFY_IS_TRUE(TP::IsPackageRegistered_DynamicDependencyDataStore()); - VERIFY_IS_TRUE(TP::IsPackageRegistered_DynamicDependencyLifetimeManager()); + ::WindowsAppRuntime::SelfContained::TestInitialize(::Test::Bootstrap::TP::WindowsAppRuntimeFramework::c_PackageFamilyName); return true; } TEST_METHOD_CLEANUP(MethodUninit) { - VERIFY_IS_TRUE(TP::IsPackageRegistered_DynamicDependencyDataStore()); - VERIFY_IS_TRUE(TP::IsPackageRegistered_DynamicDependencyLifetimeManager()); + // Need to keep each TEST_METHOD in clean state. + try + { + PushNotificationManager::Default().UnregisterAll(); + } + catch (...) + { + // We want to unregister regardless of pass/fail to clean the state. + } return true; } TEST_METHOD(ChannelRequestUsingNullRemoteId) { - // Need to use SelfContained test hook to setup tests. - ::WindowsAppRuntime::SelfContained::TestInitialize(::Test::Bootstrap::TP::WindowsAppRuntimeFramework::c_PackageFamilyName); - - TestFunctions::ChannelRequestUsingNullRemoteId(); + PushNotificationTestFunctions::ChannelRequestUsingNullRemoteId(); } TEST_METHOD(ChannelRequestUsingRemoteId) { - TestFunctions::ChannelRequestUsingRemoteId(); + PushNotificationTestFunctions::ChannelRequestUsingRemoteId(); } // Currently failing. TEST_METHOD(MultipleChannelClose) { - TestFunctions::MultipleChannelClose(); + PushNotificationTestFunctions::MultipleChannelClose(); } TEST_METHOD(VerifyRegisterAndUnregister) { - TestFunctions::VerifyRegisterAndUnregister(); + PushNotificationTestFunctions::VerifyRegisterAndUnregister(); } TEST_METHOD(VerifyRegisterAndUnregisterAll) { - TestFunctions::VerifyRegisterAndUnregisterAll(); + PushNotificationTestFunctions::VerifyRegisterAndUnregisterAll(); } TEST_METHOD(MultipleRegister) { - TestFunctions::MultipleRegister(); + PushNotificationTestFunctions::MultipleRegister(); } TEST_METHOD(VerifyMultipleRegisterAndUnregister) { - TestFunctions::VerifyMultipleRegisterAndUnregister(); + PushNotificationTestFunctions::VerifyMultipleRegisterAndUnregister(); } TEST_METHOD(VerifyMultipleRegisterAndUnregisterAll) { - TestFunctions::VerifyMultipleRegisterAndUnregisterAll(); + PushNotificationTestFunctions::VerifyMultipleRegisterAndUnregisterAll(); } TEST_METHOD(VerifyUnregisterTwice) { - TestFunctions::VerifyUnregisterTwice(); + PushNotificationTestFunctions::VerifyUnregisterTwice(); } TEST_METHOD(VerifyUnregisterAll) { - TestFunctions::VerifyUnregisterAll(); + PushNotificationTestFunctions::VerifyUnregisterAll(); } TEST_METHOD(VerifyUnregisterAllTwice) { - TestFunctions::VerifyUnregisterAllTwice(); + PushNotificationTestFunctions::VerifyUnregisterAllTwice(); } TEST_METHOD(VerifyUnregisterAndUnregisterAll) { - TestFunctions::VerifyUnregisterAndUnregisterAll(); + PushNotificationTestFunctions::VerifyUnregisterAndUnregisterAll(); } TEST_METHOD(VerifyForegroundHandlerSucceeds) { - TestFunctions::VerifyForegroundHandlerSucceeds(); + PushNotificationTestFunctions::VerifyForegroundHandlerSucceeds(); } TEST_METHOD(VerifyForegroundHandlerFails) { - TestFunctions::VerifyForegroundHandlerFails(); + PushNotificationTestFunctions::VerifyForegroundHandlerFails(); } }; } diff --git a/test/PushNotificationTests/PushNotificationTests.vcxproj b/test/PushNotificationTests/PushNotificationTests.vcxproj index 65cbb413cd..297aa5a979 100644 --- a/test/PushNotificationTests/PushNotificationTests.vcxproj +++ b/test/PushNotificationTests/PushNotificationTests.vcxproj @@ -18,14 +18,6 @@ Release x64 - - Debug - ARM64 - - - Release - ARM64 - 16.0 @@ -35,25 +27,37 @@ 10.0 - + DynamicLibrary - false + true v142 Unicode - - false + + DynamicLibrary false + v142 true + Unicode - - true + + DynamicLibrary true + v142 + Unicode + + + DynamicLibrary + false + v142 + true + Unicode - + + @@ -66,104 +70,132 @@ - - - - - - - + + true + + + false + + + true + + + false + + - Use Level4 true - true + WIN32;_DEBUG;PUSHNOTIFICATIONTESTS_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use pch.h - $(OutDir)..\PushNotificationsLongRunningTask.ProxyStub;$(RepoRoot)\test\inc;$(RepoRoot)\Dev\Common;$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories);$(OutDir)\..\WindowsAppRuntime_DLL;$(OutDir)\..\WindowsAppRuntime_BootstrapDLL - $(RepoRoot);%(AdditionalIncludeDirectories) + $(OutDir)..\PushNotificationsLongRunningTask.ProxyStub;$(RepoRoot)\test\inc;$(RepoRoot)\Dev\Common;$(ProjectDir)..\inc;$(ProjectDir)..\..\dev\WindowsAppRuntime_BootstrapDLL\ - Windows onecore.lib;onecoreuap.lib;Microsoft.WindowsAppRuntime.lib;wex.common.lib;wex.logger.lib;te.common.lib;%(AdditionalDependencies) $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories);$(OutDir)\..\WindowsAppRuntime_DLL Microsoft.WindowsAppRuntime.Bootstrap.dll;%(DelayLoadDLLs) Microsoft.WindowsAppRuntime.dll;%(DelayLoadDLLs) + Windows + true + false - + + Level4 true true - NDEBUG;%(PreprocessorDefinitions) + true + WIN32;NDEBUG;PUSHNOTIFICATIONTESTS_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + $(OutDir)..\PushNotificationsLongRunningTask.ProxyStub;$(RepoRoot)\test\inc;$(RepoRoot)\Dev\Common;$(ProjectDir)..\inc;$(ProjectDir)..\..\dev\WindowsAppRuntime_BootstrapDLL\ + onecore.lib;onecoreuap.lib;Microsoft.WindowsAppRuntime.lib;wex.common.lib;wex.logger.lib;te.common.lib;%(AdditionalDependencies) + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories);$(OutDir)\..\WindowsAppRuntime_DLL + Microsoft.WindowsAppRuntime.Bootstrap.dll;%(DelayLoadDLLs) + Microsoft.WindowsAppRuntime.dll;%(DelayLoadDLLs) + Windows true true + true + false - + - _DEBUG;%(PreprocessorDefinitions) + Level4 + true + _DEBUG;PUSHNOTIFICATIONTESTS_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + $(OutDir)..\PushNotificationsLongRunningTask.ProxyStub;$(RepoRoot)\test\inc;$(RepoRoot)\Dev\Common;$(ProjectDir)..\inc;$(ProjectDir)..\..\dev\WindowsAppRuntime_BootstrapDLL\ + onecore.lib;onecoreuap.lib;Microsoft.WindowsAppRuntime.lib;wex.common.lib;wex.logger.lib;te.common.lib;%(AdditionalDependencies) + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories);$(OutDir)\..\WindowsAppRuntime_DLL + Microsoft.WindowsAppRuntime.Bootstrap.dll;%(DelayLoadDLLs) + Microsoft.WindowsAppRuntime.dll;%(DelayLoadDLLs) + Windows + true + false - + - WIN32;%(PreprocessorDefinitions) + Level4 + true + true + true + NDEBUG;PUSHNOTIFICATIONTESTS_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + $(OutDir)..\PushNotificationsLongRunningTask.ProxyStub;$(RepoRoot)\test\inc;$(RepoRoot)\Dev\Common;$(ProjectDir)..\inc;$(ProjectDir)..\..\dev\WindowsAppRuntime_BootstrapDLL\ + + onecore.lib;onecoreuap.lib;Microsoft.WindowsAppRuntime.lib;wex.common.lib;wex.logger.lib;te.common.lib;%(AdditionalDependencies) + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories);$(OutDir)\..\WindowsAppRuntime_DLL + Microsoft.WindowsAppRuntime.Bootstrap.dll;%(DelayLoadDLLs) + Microsoft.WindowsAppRuntime.dll;%(DelayLoadDLLs) + Windows + true + true + true + false + - - + - + - - + - Create - Create Create + Create Create - Create - Create - Create - Create + Create - - - true - true - true - true - - - - .Debug - _Debug - $(AppxPackageDir)\PushNotificationsTestAppPackage_1.0.0.0_$(PlatformTarget)$(TestPkgDebugConfigName)_Test - $(TestPkgOutputPath)\PushNotificationsTestAppPackage_1.0.0.0_$(PlatformTarget)$(TestPkgDebugConfigName).msix - - - - - - - - - {bf3fced0-cadb-490a-93a7-4d90e1f45ab0} - + + $(OutDir)\..\WindowsAppRuntime_DLL\Microsoft.Windows.PushNotifications.winmd + true + @@ -171,10 +203,12 @@ - - $(OutDir)\..\WindowsAppRuntime_DLL\Microsoft.Windows.PushNotifications.winmd - true - + + true + true + true + true + @@ -195,7 +229,4 @@ - - - \ No newline at end of file diff --git a/test/PushNotificationTests/PushNotificationTests.vcxproj.filters b/test/PushNotificationTests/PushNotificationTests.vcxproj.filters index 0e1e9a8951..ec6c1a0a44 100644 --- a/test/PushNotificationTests/PushNotificationTests.vcxproj.filters +++ b/test/PushNotificationTests/PushNotificationTests.vcxproj.filters @@ -21,12 +21,6 @@ Header Files - - Source Files - - - Source Files - Header Files @@ -38,19 +32,16 @@ Source Files - - Source Files - - + Source Files - + Source Files - + Source Files - + Source Files @@ -59,10 +50,6 @@ - - - CopyFiles - diff --git a/test/PushNotificationTests/PushNotifications-AppxManifest.xml b/test/PushNotificationTests/PushNotifications-AppxManifest.xml index e41c9bf07c..0560f08fb1 100644 --- a/test/PushNotificationTests/PushNotifications-AppxManifest.xml +++ b/test/PushNotificationTests/PushNotifications-AppxManifest.xml @@ -1,5 +1,4 @@  - - + - + WindowsAppRuntime.Test.PushNotifications for tests Windows APP SDK taef.png - + - + - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/PushNotificationTests/TestFunctions.cpp b/test/PushNotificationTests/TestFunctions.cpp index a3892908fd..09ed8a5c4d 100644 --- a/test/PushNotificationTests/TestFunctions.cpp +++ b/test/PushNotificationTests/TestFunctions.cpp @@ -46,19 +46,19 @@ HRESULT ChannelRequestHelper(IAsyncOperationWithProgress +#include "MockBackgroundTaskInstance.h" +#include +#include "TestFunctions.h" + +using namespace WEX::Common; +using namespace WEX::Logging; +using namespace WEX::TestExecution; + +using namespace winrt::Windows::ApplicationModel::Activation; +using namespace winrt::Windows::ApplicationModel::Background; +using namespace winrt::Windows::Foundation; +using namespace winrt::Windows::Foundation::Collections; +using namespace winrt::Windows::Management::Deployment; +using namespace winrt::Windows::Storage; +using namespace winrt::Windows::System; +using namespace winrt::Microsoft::Windows::PushNotifications; + +namespace Test::PushNotifications +{ + class UnpackagedSelfContainedTests + { + + public: + BEGIN_TEST_CLASS(UnpackagedSelfContainedTests) + TEST_CLASS_PROPERTY(L"Description", L"Windows App SDK Push Notifications test") + TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") + TEST_CLASS_PROPERTY(L"RunAs:Class", L"RestrictedUser") + END_TEST_CLASS() + + TEST_CLASS_SETUP(ClassInit) + { + try + { + // Cleanup previous installations. Need this to remove any manual installations outside of running this tests. + TP::RemovePackage_PushNotificationsLongRunningTask(); + TP::RemovePackage_DynamicDependencyLifetimeManager(); + TP::RemovePackage_DynamicDependencyDataStore(); + TP::RemovePackage_WindowsAppRuntimeFramework(); + + TP::AddPackage_WindowsAppRuntimeFramework(); // Installs WARfwk + TP::AddPackage_DynamicDependencyDataStore(); // Installs WARmain + TP::AddPackage_DynamicDependencyLifetimeManager(); // Installs WARddlm + TP::AddPackage_PushNotificationsLongRunningTask(); // Installs the PushNotifications long running task. + } + catch (...) + { + return false; + } + return true; + } + + TEST_CLASS_CLEANUP(ClassUninit) + { + try + { + + // Remove in reverse order to avoid conflicts between inter-dependent packages. + TP::RemovePackage_PushNotificationsLongRunningTask(); + TP::RemovePackage_DynamicDependencyLifetimeManager(); + TP::RemovePackage_DynamicDependencyDataStore(); + TP::RemovePackage_WindowsAppRuntimeFramework(); + } + catch (...) + { + return false; + } + return true; + } + + TEST_METHOD_SETUP(MethodInit) + { + VERIFY_IS_TRUE(TP::IsPackageRegistered_WindowsAppRuntimeFramework()); + VERIFY_IS_TRUE(TP::IsPackageRegistered_DynamicDependencyDataStore()); + VERIFY_IS_TRUE(TP::IsPackageRegistered_DynamicDependencyLifetimeManager()); + VERIFY_IS_TRUE(TP::IsPackageRegistered_PushNotificationsLongRunningTask()); + + VERIFY_ARE_EQUAL(S_OK, MddBootstrapTestInitialize(Test::Packages::DynamicDependencyLifetimeManager::c_PackageNamePrefix, Test::Packages::DynamicDependencyLifetimeManager::c_PackagePublisherId)); + + // Major.Minor version, MinVersion=0 to find any framework package for this major.minor version + const UINT32 c_Version_MajorMinor{ Test::Packages::DynamicDependencyLifetimeManager::c_Version_MajorMinor }; + const PACKAGE_VERSION c_minVersion{}; + VERIFY_ARE_EQUAL(S_OK, MddBootstrapInitialize(c_Version_MajorMinor, nullptr, c_minVersion)); + + return true; + } + + TEST_METHOD_CLEANUP(MethodUninit) + { + // Need to keep each TEST_METHOD in a clean state in the LRP. + try + { + PushNotificationManager::Default().UnregisterAll(); + } + catch (...) + { + // We want to unregister regardless of pass/fail to clean the state. + } + MddBootstrapShutdown(); + + VERIFY_IS_TRUE(TP::IsPackageRegistered_WindowsAppRuntimeFramework()); + VERIFY_IS_TRUE(TP::IsPackageRegistered_DynamicDependencyDataStore()); + VERIFY_IS_TRUE(TP::IsPackageRegistered_DynamicDependencyLifetimeManager()); + VERIFY_IS_TRUE(TP::IsPackageRegistered_PushNotificationsLongRunningTask()); + + return true; + } + + HRESULT ChannelRequestHelper(IAsyncOperationWithProgress const& channelOperation) + { + if (channelOperation.wait_for(c_timeout) != winrt::Windows::Foundation::AsyncStatus::Completed) + { + channelOperation.Cancel(); + return HRESULT_FROM_WIN32(ERROR_TIMEOUT); // timed out or failed + } + + auto result{ channelOperation.GetResults() }; + auto status{ result.Status() }; + if (status != PushNotificationChannelStatus::CompletedSuccess) + { + return result.ExtendedError(); // did not produce a channel + } + + result.Channel().Close(); + return S_OK; + } + + TEST_METHOD(ChannelRequestUsingNullRemoteId) + { + auto channelOperation{ PushNotificationManager::Default().CreateChannelAsync(winrt::guid()) }; + VERIFY_ARE_EQUAL(ChannelRequestHelper(channelOperation), E_FAIL); + } + + TEST_METHOD(ChannelRequestUsingRemoteId) + { + auto channelOperation{ PushNotificationManager::Default().CreateChannelAsync(c_azureRemoteId) }; + VERIFY_ARE_EQUAL(ChannelRequestHelper(channelOperation), E_FAIL); + } + + // Currently failing. + TEST_METHOD(MultipleChannelClose) + { + PushNotificationTestFunctions::MultipleChannelClose(); + } + + TEST_METHOD(VerifyRegisterAndUnregister) + { + PushNotificationTestFunctions::VerifyRegisterAndUnregister(); + } + + TEST_METHOD(VerifyRegisterAndUnregisterAll) + { + PushNotificationTestFunctions::VerifyRegisterAndUnregisterAll(); + } + + TEST_METHOD(MultipleRegister) + { + auto pushNotificationManager{ PushNotificationManager::Default() }; + pushNotificationManager.Register(); + pushNotificationManager.Register(); + } + + TEST_METHOD(VerifyMultipleRegisterAndUnregister) + { + PushNotificationManager::Default().Register(); + PushNotificationManager::Default().Unregister(); + PushNotificationManager::Default().Register(); + } + + TEST_METHOD(VerifyMultipleRegisterAndUnregisterAll) + { + PushNotificationTestFunctions::VerifyMultipleRegisterAndUnregisterAll(); + } + + TEST_METHOD(VerifyUnregisterTwice) + { + PushNotificationManager::Default().Register(); + PushNotificationManager::Default().Unregister(); + PushNotificationManager::Default().Unregister(); + } + + TEST_METHOD(VerifyUnregisterAll) + { + PushNotificationTestFunctions::VerifyUnregisterAll(); + } + + TEST_METHOD(VerifyUnregisterAllTwice) + { + PushNotificationManager::Default().Register(); + PushNotificationManager::Default().UnregisterAll(); + PushNotificationManager::Default().UnregisterAll(); + } + + TEST_METHOD(VerifyUnregisterAndUnregisterAll) + { + PushNotificationTestFunctions::VerifyUnregisterAndUnregisterAll(); + } + + TEST_METHOD(VerifyForegroundHandlerSucceeds) + { + PushNotificationTestFunctions::VerifyForegroundHandlerSucceeds(); + } + + TEST_METHOD(VerifyForegroundHandlerFails) + { + PushNotificationManager::Default().Register(); + PushNotificationManager::Default().PushReceived([](const auto&, PushNotificationReceivedEventArgs const& /* args */) {}); + } + }; +} diff --git a/test/PushNotificationTests/UnpackagedTests.cpp b/test/PushNotificationTests/UnpackagedTests.cpp index ac11f18b30..5b490a647c 100644 --- a/test/PushNotificationTests/UnpackagedTests.cpp +++ b/test/PushNotificationTests/UnpackagedTests.cpp @@ -22,16 +22,9 @@ using namespace winrt::Microsoft::Windows::PushNotifications; namespace Test::PushNotifications { - #define VERIFY_THROWS_HR(expression, hr) \ - VERIFY_THROWS_SPECIFIC(expression, \ - winrt::hresult_error, \ - [&](winrt::hresult_error e) -> bool \ - { \ - return (e.code() == hr); \ - }) - class UnpackagedTests { + public: BEGIN_TEST_CLASS(UnpackagedTests) TEST_CLASS_PROPERTY(L"Description", L"Windows App SDK Push Notifications test") @@ -45,13 +38,8 @@ namespace Test::PushNotifications { // Cleanup previous installations. Need this to remove any manual installations outside of running this tests. TP::RemovePackage_PushNotificationsLongRunningTask(); - TP::RemovePackage_DynamicDependencyLifetimeManager(); - TP::RemovePackage_DynamicDependencyDataStore(); - TP::RemovePackage_WindowsAppRuntimeFramework(); - TP::AddPackage_WindowsAppRuntimeFramework(); // Installs WARfwk - TP::AddPackage_DynamicDependencyDataStore(); // Installs WARmain - TP::AddPackage_DynamicDependencyLifetimeManager(); // Installs WARddlm + ::Test::Bootstrap::Setup(); TP::AddPackage_PushNotificationsLongRunningTask(); // Installs the PushNotifications long running task. } catch (...) @@ -60,42 +48,14 @@ namespace Test::PushNotifications } return true; } - - void TerminateLRP() - { - wil::unique_handle processesSnapshot(CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)); - VERIFY_IS_NOT_NULL(processesSnapshot.get()); - - PROCESSENTRY32 processEntry = { 0 }; - processEntry.dwSize = sizeof(processEntry); - - BOOL result = Process32First(processesSnapshot.get(), &processEntry); - while (result != FALSE) - { - if (wcscmp(L"PushNotificationsLongRunningTask.exe", processEntry.szExeFile) == 0) - { - DWORD processId = processEntry.th32ProcessID; - - wil::unique_handle longRunningProcessHandle(OpenProcess(PROCESS_TERMINATE, FALSE, processId)); - VERIFY_IS_TRUE(TerminateProcess(longRunningProcessHandle.get(), 0)); - ::WaitForSingleObject(longRunningProcessHandle.get(), 10000); - return; - } - - result = Process32Next(processesSnapshot.get(), &processEntry); - } - } TEST_CLASS_CLEANUP(ClassUninit) { try { // Remove in reverse order to avoid conflicts between inter-dependent packages. - TerminateLRP(); + ::Test::Bootstrap::Cleanup(); TP::RemovePackage_PushNotificationsLongRunningTask(); - TP::RemovePackage_DynamicDependencyLifetimeManager(); - TP::RemovePackage_DynamicDependencyDataStore(); - TP::RemovePackage_WindowsAppRuntimeFramework(); } catch (...) { @@ -106,21 +66,13 @@ namespace Test::PushNotifications TEST_METHOD_SETUP(MethodInit) { - VERIFY_IS_TRUE(TP::IsPackageRegistered_WindowsAppRuntimeFramework()); - VERIFY_IS_TRUE(TP::IsPackageRegistered_DynamicDependencyDataStore()); - VERIFY_IS_TRUE(TP::IsPackageRegistered_DynamicDependencyLifetimeManager()); - VERIFY_IS_TRUE(TP::IsPackageRegistered_PushNotificationsLongRunningTask()); - - VERIFY_ARE_EQUAL(S_OK, MddBootstrapTestInitialize(Test::Packages::DynamicDependencyLifetimeManager::c_PackageNamePrefix, Test::Packages::DynamicDependencyLifetimeManager::c_PackagePublisherId)); - - // Major.Minor version, MinVersion=0 to find any framework package for this major.minor version - const UINT32 c_Version_MajorMinor{ Test::Packages::DynamicDependencyLifetimeManager::c_Version_MajorMinor }; - const PACKAGE_VERSION c_minVersion{}; - VERIFY_ARE_EQUAL(S_OK, MddBootstrapInitialize(c_Version_MajorMinor, nullptr, c_minVersion)); - // Need to use SelfContained test hook to setup tests. ::WindowsAppRuntime::SelfContained::TestInitialize(::Test::Bootstrap::TP::WindowsAppRuntimeFramework::c_PackageFamilyName); + return true; + } + TEST_METHOD_CLEANUP(MethodUninit) + { // Need to keep each TEST_METHOD in a clean state in the LRP. try { @@ -133,88 +85,75 @@ namespace Test::PushNotifications return true; } - TEST_METHOD_CLEANUP(MethodUninit) - { - MddBootstrapShutdown(); - - VERIFY_IS_TRUE(TP::IsPackageRegistered_WindowsAppRuntimeFramework()); - VERIFY_IS_TRUE(TP::IsPackageRegistered_DynamicDependencyDataStore()); - VERIFY_IS_TRUE(TP::IsPackageRegistered_DynamicDependencyLifetimeManager()); - VERIFY_IS_TRUE(TP::IsPackageRegistered_PushNotificationsLongRunningTask()); - TerminateLRP(); - - return true; - } - TEST_METHOD(ChannelRequestUsingNullRemoteId) { - TestFunctions::ChannelRequestUsingNullRemoteId(); + PushNotificationTestFunctions::ChannelRequestUsingNullRemoteId(); } TEST_METHOD(ChannelRequestUsingRemoteId) { - TestFunctions::ChannelRequestUsingRemoteId(); + PushNotificationTestFunctions::ChannelRequestUsingRemoteId(); } // Currently failing. TEST_METHOD(MultipleChannelClose) { - TestFunctions::MultipleChannelClose(); + PushNotificationTestFunctions::MultipleChannelClose(); } TEST_METHOD(VerifyRegisterAndUnregister) { - TestFunctions::VerifyRegisterAndUnregister(); + PushNotificationTestFunctions::VerifyRegisterAndUnregister(); } TEST_METHOD(VerifyRegisterAndUnregisterAll) { - TestFunctions::VerifyRegisterAndUnregisterAll(); + PushNotificationTestFunctions::VerifyRegisterAndUnregisterAll(); } TEST_METHOD(MultipleRegister) { - TestFunctions::MultipleRegister(); + PushNotificationTestFunctions::MultipleRegister(); } TEST_METHOD(VerifyMultipleRegisterAndUnregister) { - TestFunctions::VerifyMultipleRegisterAndUnregister(); + PushNotificationTestFunctions::VerifyMultipleRegisterAndUnregister(); } TEST_METHOD(VerifyMultipleRegisterAndUnregisterAll) { - TestFunctions::VerifyMultipleRegisterAndUnregisterAll(); + PushNotificationTestFunctions::VerifyMultipleRegisterAndUnregisterAll(); } TEST_METHOD(VerifyUnregisterTwice) { - TestFunctions::VerifyUnregisterTwice(); + PushNotificationTestFunctions::VerifyUnregisterTwice(); } TEST_METHOD(VerifyUnregisterAll) { - TestFunctions::VerifyUnregisterAll(); + PushNotificationTestFunctions::VerifyUnregisterAll(); } TEST_METHOD(VerifyUnregisterAllTwice) { - TestFunctions::VerifyUnregisterAllTwice(); + PushNotificationTestFunctions::VerifyUnregisterAllTwice(); } TEST_METHOD(VerifyUnregisterAndUnregisterAll) { - TestFunctions::VerifyUnregisterAndUnregisterAll(); + PushNotificationTestFunctions::VerifyUnregisterAndUnregisterAll(); } TEST_METHOD(VerifyForegroundHandlerSucceeds) { - TestFunctions::VerifyForegroundHandlerSucceeds(); + PushNotificationTestFunctions::VerifyForegroundHandlerSucceeds(); } TEST_METHOD(VerifyForegroundHandlerFails) { - TestFunctions::VerifyForegroundHandlerFails(); + PushNotificationTestFunctions::VerifyForegroundHandlerFails(); } }; } From ccaaf7bbc0add716125f0a11a8c1103522ab3528 Mon Sep 17 00:00:00 2001 From: Paul Purifoy Date: Tue, 12 Apr 2022 17:27:55 -0700 Subject: [PATCH 03/16] Adding LRP to singleton, nits --- ...dowsAppRuntime.Test.Singleton.Msix.vcxproj | 30 +- .../appxmanifest.xml | 46 +++ test/PowerNotifications/APITests.cpp | 8 +- .../PowerNotifications.vcxproj | 4 - .../PackagedSelfContainedTests.cpp | 231 ++++++++------- .../PackagedSelfContainedTests.h | 81 ++++++ test/PushNotificationTests/PackagedTests.cpp | 228 +++++++++------ test/PushNotificationTests/PackagedTests.h | 82 ++++++ .../PushNotificationTests.vcxproj | 6 +- .../PushNotificationTests.vcxproj.filters | 14 +- test/PushNotificationTests/TestFunctions.cpp | 151 ---------- test/PushNotificationTests/TestFunctions.h | 18 -- .../UnpackagedSelfContained.cpp | 270 +++++++----------- .../UnpackagedSelfContainedTests.h | 62 ++++ .../PushNotificationTests/UnpackagedTests.cpp | 249 ++++++++-------- test/PushNotificationTests/UnpackagedTests.h | 80 ++++++ test/PushNotificationTests/pch.h | 12 +- test/inc/WindowsAppRuntime.Test.Bootstrap.h | 4 +- 18 files changed, 913 insertions(+), 663 deletions(-) create mode 100644 test/PushNotificationTests/PackagedSelfContainedTests.h create mode 100644 test/PushNotificationTests/PackagedTests.h delete mode 100644 test/PushNotificationTests/TestFunctions.cpp delete mode 100644 test/PushNotificationTests/TestFunctions.h create mode 100644 test/PushNotificationTests/UnpackagedSelfContainedTests.h create mode 100644 test/PushNotificationTests/UnpackagedTests.h diff --git a/test/DynamicDependency/data/WindowsAppRuntime.Test.Singleton.Msix/WindowsAppRuntime.Test.Singleton.Msix.vcxproj b/test/DynamicDependency/data/WindowsAppRuntime.Test.Singleton.Msix/WindowsAppRuntime.Test.Singleton.Msix.vcxproj index bc3464e38e..169fa3581f 100644 --- a/test/DynamicDependency/data/WindowsAppRuntime.Test.Singleton.Msix/WindowsAppRuntime.Test.Singleton.Msix.vcxproj +++ b/test/DynamicDependency/data/WindowsAppRuntime.Test.Singleton.Msix/WindowsAppRuntime.Test.Singleton.Msix.vcxproj @@ -94,10 +94,27 @@ REM TODO Clean WindowsAppRuntime.Test.Singleton.msix + PushNotificationsLongRunningTask + + $(TargetBasename).StartupTask + $(OutDir)$(StartupExe) + $(StartupExeDir)\$(StartupExe).exe + + $(TargetBasename) + $(OutDir)$(TargetExe) + $(TargetExeDir)\$(TargetExe).exe + + $(TargetBasename).ProxyStub + $(OutDir)$(TargetExeProxyStub) + $(TargetExeProxyStubDir)\$(TargetExeProxyStub).dll - + + + + + $(RepoTestCertificatePFX) @@ -107,6 +124,17 @@ + + + {bf3fced0-cadb-490a-93a7-4d90e1f45ab0} + + + {1debbff6-ee6e-4944-9de2-35b7a686af42} + + + {1307dd1b-bbe8-4cd0-b1a0-0db6d61eeaa0} + + diff --git a/test/DynamicDependency/data/WindowsAppRuntime.Test.Singleton.Msix/appxmanifest.xml b/test/DynamicDependency/data/WindowsAppRuntime.Test.Singleton.Msix/appxmanifest.xml index 48c68538f0..846fb81440 100644 --- a/test/DynamicDependency/data/WindowsAppRuntime.Test.Singleton.Msix/appxmanifest.xml +++ b/test/DynamicDependency/data/WindowsAppRuntime.Test.Singleton.Msix/appxmanifest.xml @@ -29,6 +29,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/PowerNotifications/APITests.cpp b/test/PowerNotifications/APITests.cpp index 0418f62882..3af302b558 100644 --- a/test/PowerNotifications/APITests.cpp +++ b/test/PowerNotifications/APITests.cpp @@ -3,11 +3,9 @@ #include "pch.h" #include "winrt/Microsoft.Windows.System.Power.h" -#include "winrt/Microsoft.Windows.PushNotifications.h" using namespace std::chrono_literals; using namespace winrt::Microsoft::Windows::System::Power; -using namespace winrt::Microsoft::Windows::PushNotifications; namespace Test::PowerNotifications { @@ -53,10 +51,8 @@ namespace Test::PowerNotifications TEST_METHOD(GetBatteryStatus) { - /*auto value = PowerManager::BatteryStatus(); - VERIFY_ARE_EQUAL(value, BatteryStatus::NotPresent);*/ - - PushNotificationManager::Default().Register(); + auto value = PowerManager::BatteryStatus(); + VERIFY_ARE_EQUAL(value, BatteryStatus::NotPresent); } TEST_METHOD(GetPowerSupplyStatus) diff --git a/test/PowerNotifications/PowerNotifications.vcxproj b/test/PowerNotifications/PowerNotifications.vcxproj index 2a691b85da..351c1c64ed 100644 --- a/test/PowerNotifications/PowerNotifications.vcxproj +++ b/test/PowerNotifications/PowerNotifications.vcxproj @@ -173,10 +173,6 @@ - - ..\..\BuildOutput\Debug\x64\WindowsAppRuntime_DLL\Microsoft.Windows.PushNotifications.winmd - true - $(OutDir)\..\WindowsAppRuntime_DLL\Microsoft.Windows.System.Power.winmd true diff --git a/test/PushNotificationTests/PackagedSelfContainedTests.cpp b/test/PushNotificationTests/PackagedSelfContainedTests.cpp index bd6eeb9059..5f8926da62 100644 --- a/test/PushNotificationTests/PackagedSelfContainedTests.cpp +++ b/test/PushNotificationTests/PackagedSelfContainedTests.cpp @@ -2,10 +2,9 @@ // Licensed under the MIT License. See LICENSE in the project root for license information. #include "pch.h" + #include -#include "MockBackgroundTaskInstance.h" -#include -#include "TestFunctions.h" +#include "PackagedSelfContainedTests.h" using namespace WEX::Common; using namespace WEX::Logging; @@ -20,125 +19,161 @@ using namespace winrt::Windows::Storage; using namespace winrt::Windows::System; using namespace winrt::Microsoft::Windows::PushNotifications; + namespace Test::PushNotifications { - class PackagedSelfContainedTests + HRESULT PackagedSelfContainedTests::ChannelRequestHelper(IAsyncOperationWithProgress const& channelOperation) { - - public: - BEGIN_TEST_CLASS(PackagedSelfContainedTests) - TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") - TEST_CLASS_PROPERTY(L"RunFixtureAs:Class", L"RestrictedUser") - TEST_CLASS_PROPERTY(L"RunAs", L"UAP") - TEST_CLASS_PROPERTY(L"UAP:AppxManifest", L"PushNotifications-AppxManifest.xml") - TEST_CLASS_PROPERTY(L"UAP:Host", L"PackagedCWA") - END_TEST_CLASS() - - TEST_CLASS_SETUP(ClassInit) + if (channelOperation.wait_for(c_timeout) != winrt::Windows::Foundation::AsyncStatus::Completed) { - ::Test::Bootstrap::SetupPackages(); - return true; + channelOperation.Cancel(); + return HRESULT_FROM_WIN32(ERROR_TIMEOUT); // timed out or failed } - TEST_CLASS_CLEANUP(ClassUninit) + auto result{ channelOperation.GetResults() }; + auto status{ result.Status() }; + if (status != PushNotificationChannelStatus::CompletedSuccess) { - ::Test::Bootstrap::CleanupPackages(); - return true; + return result.ExtendedError(); // did not produce a channel } - TEST_METHOD_SETUP(MethodInit) - { - VERIFY_IS_TRUE(TP::IsPackageRegistered_DynamicDependencyDataStore()); - VERIFY_IS_TRUE(TP::IsPackageRegistered_DynamicDependencyLifetimeManager()); - return true; - } + result.Channel().Close(); + return S_OK; + } - TEST_METHOD_CLEANUP(MethodUninit) - { - VERIFY_IS_TRUE(TP::IsPackageRegistered_DynamicDependencyDataStore()); - VERIFY_IS_TRUE(TP::IsPackageRegistered_DynamicDependencyLifetimeManager()); - - // Need to keep each TEST_METHOD in clean state. - try - { - PushNotificationManager::Default().UnregisterAll(); - } - catch (...) - { - // We want to unregister regardless of pass/fail to clean the state. - } - return true; - } + void PackagedSelfContainedTests::ChannelRequestUsingNullRemoteId() + { + VERIFY_THROWS_HR(PushNotificationManager::Default().CreateChannelAsync(winrt::guid()).get(), E_INVALIDARG); + } - TEST_METHOD(ChannelRequestUsingNullRemoteId) - { - PushNotificationTestFunctions::ChannelRequestUsingNullRemoteId(); - } + void PackagedSelfContainedTests::ChannelRequestUsingRemoteId() + { + auto channelOperation{ PushNotificationManager::Default().CreateChannelAsync(c_azureRemoteId) }; + VERIFY_SUCCEEDED(ChannelRequestHelper(channelOperation)); + } - TEST_METHOD(ChannelRequestUsingRemoteId) + // Currently failing - https://github.com/microsoft/WindowsAppSDK/issues/2392 + void PackagedSelfContainedTests::MultipleChannelClose() + { + auto channelOperation{ PushNotificationManager::Default().CreateChannelAsync(c_azureRemoteId) }; + if (channelOperation.wait_for(c_timeout) != winrt::Windows::Foundation::AsyncStatus::Completed) { - PushNotificationTestFunctions::ChannelRequestUsingRemoteId(); + channelOperation.Cancel(); + VERIFY_FAIL(L"Channel request hit timeout."); } - // Currently failing. - TEST_METHOD(MultipleChannelClose) - { - PushNotificationTestFunctions::MultipleChannelClose(); - } + auto result{ channelOperation.GetResults() }; + VERIFY_ARE_EQUAL(result.Status(), PushNotificationChannelStatus::CompletedSuccess); - TEST_METHOD(VerifyRegisterAndUnregister) - { - PushNotificationTestFunctions::VerifyRegisterAndUnregister(); - } + result.Channel().Close(); + VERIFY_THROWS_HR(result.Channel().Close(), WPN_E_CHANNEL_CLOSED); + } - TEST_METHOD(VerifyRegisterAndUnregisterAll) - { - PushNotificationTestFunctions::VerifyRegisterAndUnregisterAll(); - } + void PackagedSelfContainedTests::VerifyRegisterAndUnregister() + { + auto pushNotificationManager{ PushNotificationManager::Default() }; + pushNotificationManager.Register(); + m_registered = true; + pushNotificationManager.Unregister(); + } - TEST_METHOD(MultipleRegister) - { - PushNotificationTestFunctions::MultipleRegister(); - } + void PackagedSelfContainedTests::VerifyUnregisterFails() + { + auto pushNotificationManager{ PushNotificationManager::Default() }; + VERIFY_THROWS_HR(pushNotificationManager.Unregister(), E_UNEXPECTED); + } - TEST_METHOD(VerifyMultipleRegisterAndUnregister) - { - PushNotificationTestFunctions::VerifyMultipleRegisterAndUnregister(); - } + void PackagedSelfContainedTests::VerifyUnregisterAllFails() + { + auto pushNotificationManager{ PushNotificationManager::Default() }; + VERIFY_THROWS_HR(pushNotificationManager.UnregisterAll(), E_UNEXPECTED); + } - TEST_METHOD(VerifyMultipleRegisterAndUnregisterAll) - { - PushNotificationTestFunctions::VerifyMultipleRegisterAndUnregisterAll(); - } + void PackagedSelfContainedTests::VerifyRegisterAndUnregisterAll() + { + auto pushNotificationManager{ PushNotificationManager::Default() }; + pushNotificationManager.Register(); + m_registered = true; - TEST_METHOD(VerifyUnregisterTwice) - { - PushNotificationTestFunctions::VerifyUnregisterTwice(); - } + pushNotificationManager.UnregisterAll(); + m_registered = false; + } - TEST_METHOD(VerifyUnregisterAll) - { - PushNotificationTestFunctions::VerifyUnregisterAll(); - } + void PackagedSelfContainedTests::MultipleRegister() + { + auto pushNotificationManager{ PushNotificationManager::Default() }; + pushNotificationManager.Register(); + m_registered = true; - TEST_METHOD(VerifyUnregisterAllTwice) - { - PushNotificationTestFunctions::VerifyUnregisterAllTwice(); - } + VERIFY_THROWS_HR(pushNotificationManager.Register(), HRESULT_FROM_WIN32(ERROR_ALREADY_REGISTERED)); + } - TEST_METHOD(VerifyUnregisterAndUnregisterAll) - { - PushNotificationTestFunctions::VerifyUnregisterAndUnregisterAll(); - } + void PackagedSelfContainedTests::VerifyMultipleRegisterAndUnregister() + { + PushNotificationManager::Default().Register(); + m_registered = true; - TEST_METHOD(VerifyForegroundHandlerSucceeds) - { - PushNotificationTestFunctions::VerifyForegroundHandlerSucceeds(); - } + PushNotificationManager::Default().Unregister(); + VERIFY_THROWS_HR(PushNotificationManager::Default().Register(), HRESULT_FROM_WIN32(ERROR_ALREADY_REGISTERED)); + } - TEST_METHOD(VerifyForegroundHandlerFails) - { - PushNotificationTestFunctions::VerifyForegroundHandlerFails(); - } - }; + void PackagedSelfContainedTests::VerifyMultipleRegisterAndUnregisterAll() + { + PushNotificationManager::Default().Register(); + m_registered = true; + + PushNotificationManager::Default().UnregisterAll(); + m_registered = false; + + PushNotificationManager::Default().Register(); + m_registered = true; + + PushNotificationManager::Default().UnregisterAll(); + m_registered = false; + } + + void PackagedSelfContainedTests::VerifyUnregisterTwice() + { + PushNotificationManager::Default().Register(); + m_registered = true; + + PushNotificationManager::Default().Unregister(); + VERIFY_THROWS_HR(PushNotificationManager::Default().Unregister(), E_UNEXPECTED); + } + + void PackagedSelfContainedTests::VerifyUnregisterAllTwice() + { + PushNotificationManager::Default().Register(); + m_registered = true; + + PushNotificationManager::Default().UnregisterAll(); + m_registered = false; + + VERIFY_THROWS_HR(PushNotificationManager::Default().UnregisterAll(), E_UNEXPECTED); + } + + void PackagedSelfContainedTests::VerifyUnregisterAndUnregisterAll() + { + PushNotificationManager::Default().Register(); + m_registered = true; + + PushNotificationManager::Default().Unregister(); + PushNotificationManager::Default().UnregisterAll(); + m_registered = false; + } + + void PackagedSelfContainedTests::VerifyForegroundHandlerSucceeds() + { + PushNotificationManager::Default().PushReceived([](const auto&, PushNotificationReceivedEventArgs const& /* args */) {}); + PushNotificationManager::Default().Register(); + m_registered = true; + } + + void PackagedSelfContainedTests::VerifyForegroundHandlerFails() + { + PushNotificationManager::Default().Register(); + m_registered = true; + + VERIFY_THROWS_HR(PushNotificationManager::Default().PushReceived([](const auto&, PushNotificationReceivedEventArgs const& /* args */) {}), HRESULT_FROM_WIN32(ERROR_NOT_FOUND)); + } } diff --git a/test/PushNotificationTests/PackagedSelfContainedTests.h b/test/PushNotificationTests/PackagedSelfContainedTests.h new file mode 100644 index 0000000000..4986618230 --- /dev/null +++ b/test/PushNotificationTests/PackagedSelfContainedTests.h @@ -0,0 +1,81 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +#include "pch.h" +#include + +using namespace WEX::Common; +using namespace WEX::Logging; +using namespace WEX::TestExecution; + +using namespace winrt::Windows::ApplicationModel::Activation; +using namespace winrt::Windows::ApplicationModel::Background; +using namespace winrt::Windows::Foundation; +using namespace winrt::Windows::Foundation::Collections; +using namespace winrt::Windows::Management::Deployment; +using namespace winrt::Windows::Storage; +using namespace winrt::Windows::System; +using namespace winrt::Microsoft::Windows::PushNotifications; + +namespace Test::PushNotifications +{ + class PackagedSelfContainedTests + { + private: + HRESULT ChannelRequestHelper(IAsyncOperationWithProgress const& channelOperation); + + bool m_registered{ false }; + public: + BEGIN_TEST_CLASS(PackagedSelfContainedTests) + TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") + TEST_CLASS_PROPERTY(L"RunFixtureAs:Class", L"RestrictedUser") + TEST_CLASS_PROPERTY(L"RunAs", L"UAP") + TEST_CLASS_PROPERTY(L"UAP:AppxManifest", L"PushNotifications-AppxManifest.xml") + TEST_CLASS_PROPERTY(L"UAP:Host", L"PackagedCWA") + END_TEST_CLASS() + + TEST_CLASS_SETUP(ClassInit) + { + ::Test::Bootstrap::Setup(); + return true; + } + + TEST_CLASS_CLEANUP(ClassUninit) + { + ::Test::Bootstrap::Cleanup(); + return true; + } + + TEST_METHOD_SETUP(MethodInit) + { + return true; + } + + TEST_METHOD_CLEANUP(MethodUninit) + { + if (m_registered) + { + PushNotificationManager::Default().UnregisterAll(); + m_registered = false; + } + + return true; + } + + TEST_METHOD(ChannelRequestUsingNullRemoteId); + TEST_METHOD(ChannelRequestUsingRemoteId); + TEST_METHOD(MultipleChannelClose); // Currently failing + TEST_METHOD(VerifyRegisterAndUnregister); + TEST_METHOD(VerifyRegisterAndUnregisterAll); + TEST_METHOD(VerifyUnregisterFails); + TEST_METHOD(VerifyUnregisterAllFails); + TEST_METHOD(MultipleRegister); + TEST_METHOD(VerifyMultipleRegisterAndUnregister); + TEST_METHOD(VerifyMultipleRegisterAndUnregisterAll); + TEST_METHOD(VerifyUnregisterTwice); + TEST_METHOD(VerifyUnregisterAllTwice); + TEST_METHOD(VerifyUnregisterAndUnregisterAll); + TEST_METHOD(VerifyForegroundHandlerSucceeds); + TEST_METHOD(VerifyForegroundHandlerFails); + }; +} diff --git a/test/PushNotificationTests/PackagedTests.cpp b/test/PushNotificationTests/PackagedTests.cpp index 5c93c252b1..92dd30565d 100644 --- a/test/PushNotificationTests/PackagedTests.cpp +++ b/test/PushNotificationTests/PackagedTests.cpp @@ -2,10 +2,9 @@ // Licensed under the MIT License. See LICENSE in the project root for license information. #include "pch.h" + #include -#include "MockBackgroundTaskInstance.h" -#include -#include "TestFunctions.h" +#include "PackagedTests.h" using namespace WEX::Common; using namespace WEX::Logging; @@ -20,121 +19,162 @@ using namespace winrt::Windows::Storage; using namespace winrt::Windows::System; using namespace winrt::Microsoft::Windows::PushNotifications; + namespace Test::PushNotifications { - class PackagedTests + HRESULT PackagedTests::ChannelRequestHelper(IAsyncOperationWithProgress const& channelOperation) { - - public: - BEGIN_TEST_CLASS(PackagedTests) - TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") - TEST_CLASS_PROPERTY(L"RunFixtureAs:Class", L"RestrictedUser") - TEST_CLASS_PROPERTY(L"RunAs", L"UAP") - TEST_CLASS_PROPERTY(L"UAP:AppxManifest", L"PushNotifications-AppxManifest.xml") - TEST_CLASS_PROPERTY(L"UAP:Host", L"PackagedCWA") - END_TEST_CLASS() - - TEST_CLASS_SETUP(ClassInit) + if (channelOperation.wait_for(c_timeout) != winrt::Windows::Foundation::AsyncStatus::Completed) { - ::Test::Bootstrap::SetupPackages(); - return true; + channelOperation.Cancel(); + return HRESULT_FROM_WIN32(ERROR_TIMEOUT); // timed out or failed } - TEST_CLASS_CLEANUP(ClassUninit) + auto result{ channelOperation.GetResults() }; + auto status{ result.Status() }; + if (status != PushNotificationChannelStatus::CompletedSuccess) { - ::Test::Bootstrap::CleanupPackages(); - return true; + return result.ExtendedError(); // did not produce a channel } - TEST_METHOD_SETUP(MethodInit) - { - ::WindowsAppRuntime::SelfContained::TestInitialize(::Test::Bootstrap::TP::WindowsAppRuntimeFramework::c_PackageFamilyName); - return true; - } + result.Channel().Close(); + return S_OK; + } - TEST_METHOD_CLEANUP(MethodUninit) - { - // Need to keep each TEST_METHOD in clean state. - try - { - PushNotificationManager::Default().UnregisterAll(); - } - catch (...) - { - // We want to unregister regardless of pass/fail to clean the state. - } - return true; - } + void PackagedTests::ChannelRequestUsingNullRemoteId() + { + VERIFY_THROWS_HR(PushNotificationManager::Default().CreateChannelAsync(winrt::guid()).get(), E_INVALIDARG); + } - TEST_METHOD(ChannelRequestUsingNullRemoteId) - { - PushNotificationTestFunctions::ChannelRequestUsingNullRemoteId(); - } + void PackagedTests::ChannelRequestUsingRemoteId() + { + auto channelOperation{ PushNotificationManager::Default().CreateChannelAsync(c_azureRemoteId) }; + VERIFY_SUCCEEDED(ChannelRequestHelper(channelOperation)); + } - TEST_METHOD(ChannelRequestUsingRemoteId) + // Currently failing - https://github.com/microsoft/WindowsAppSDK/issues/2392 + void PackagedTests::MultipleChannelClose() + { + auto channelOperation{ PushNotificationManager::Default().CreateChannelAsync(c_azureRemoteId) }; + if (channelOperation.wait_for(c_timeout) != winrt::Windows::Foundation::AsyncStatus::Completed) { - PushNotificationTestFunctions::ChannelRequestUsingRemoteId(); + channelOperation.Cancel(); + VERIFY_FAIL(L"Channel request hit timeout."); } - // Currently failing. - TEST_METHOD(MultipleChannelClose) - { - PushNotificationTestFunctions::MultipleChannelClose(); - } + auto result{ channelOperation.GetResults() }; + VERIFY_ARE_EQUAL(result.Status(), PushNotificationChannelStatus::CompletedSuccess); - TEST_METHOD(VerifyRegisterAndUnregister) - { - PushNotificationTestFunctions::VerifyRegisterAndUnregister(); - } + result.Channel().Close(); + VERIFY_THROWS_HR(result.Channel().Close(), WPN_E_CHANNEL_CLOSED); + } - TEST_METHOD(VerifyRegisterAndUnregisterAll) - { - PushNotificationTestFunctions::VerifyRegisterAndUnregisterAll(); - } + void PackagedTests::VerifyRegisterAndUnregister() + { + auto pushNotificationManager{ PushNotificationManager::Default() }; + pushNotificationManager.Register(); + m_registered = true; - TEST_METHOD(MultipleRegister) - { - PushNotificationTestFunctions::MultipleRegister(); - } + pushNotificationManager.Unregister(); + } - TEST_METHOD(VerifyMultipleRegisterAndUnregister) - { - PushNotificationTestFunctions::VerifyMultipleRegisterAndUnregister(); - } + void PackagedTests::VerifyUnregisterFails() + { + auto pushNotificationManager{ PushNotificationManager::Default() }; + VERIFY_THROWS_HR(pushNotificationManager.Unregister(), E_UNEXPECTED); + } - TEST_METHOD(VerifyMultipleRegisterAndUnregisterAll) - { - PushNotificationTestFunctions::VerifyMultipleRegisterAndUnregisterAll(); - } + void PackagedTests::VerifyUnregisterAllFails() + { + auto pushNotificationManager{ PushNotificationManager::Default() }; + VERIFY_THROWS_HR(pushNotificationManager.UnregisterAll(), E_UNEXPECTED); + } - TEST_METHOD(VerifyUnregisterTwice) - { - PushNotificationTestFunctions::VerifyUnregisterTwice(); - } + void PackagedTests::VerifyRegisterAndUnregisterAll() + { + auto pushNotificationManager{ PushNotificationManager::Default() }; + pushNotificationManager.Register(); + m_registered = true; - TEST_METHOD(VerifyUnregisterAll) - { - PushNotificationTestFunctions::VerifyUnregisterAll(); - } + pushNotificationManager.UnregisterAll(); + m_registered = false; + } - TEST_METHOD(VerifyUnregisterAllTwice) - { - PushNotificationTestFunctions::VerifyUnregisterAllTwice(); - } + void PackagedTests::MultipleRegister() + { + auto pushNotificationManager{ PushNotificationManager::Default() }; + pushNotificationManager.Register(); + m_registered = true; - TEST_METHOD(VerifyUnregisterAndUnregisterAll) - { - PushNotificationTestFunctions::VerifyUnregisterAndUnregisterAll(); - } + VERIFY_THROWS_HR(pushNotificationManager.Register(), HRESULT_FROM_WIN32(ERROR_ALREADY_REGISTERED)); + } - TEST_METHOD(VerifyForegroundHandlerSucceeds) - { - PushNotificationTestFunctions::VerifyForegroundHandlerSucceeds(); - } + void PackagedTests::VerifyMultipleRegisterAndUnregister() + { + PushNotificationManager::Default().Register(); + m_registered = true; - TEST_METHOD(VerifyForegroundHandlerFails) - { - PushNotificationTestFunctions::VerifyForegroundHandlerFails(); - } - }; + PushNotificationManager::Default().Unregister(); + VERIFY_THROWS_HR(PushNotificationManager::Default().Register(), HRESULT_FROM_WIN32(ERROR_ALREADY_REGISTERED)); + } + + void PackagedTests::VerifyMultipleRegisterAndUnregisterAll() + { + PushNotificationManager::Default().Register(); + m_registered = true; + + PushNotificationManager::Default().UnregisterAll(); + m_registered = false; + + PushNotificationManager::Default().Register(); + m_registered = true; + + PushNotificationManager::Default().UnregisterAll(); + m_registered = false; + } + + void PackagedTests::VerifyUnregisterTwice() + { + PushNotificationManager::Default().Register(); + m_registered = true; + + PushNotificationManager::Default().Unregister(); + VERIFY_THROWS_HR(PushNotificationManager::Default().Unregister(), E_UNEXPECTED); + } + + void PackagedTests::VerifyUnregisterAllTwice() + { + PushNotificationManager::Default().Register(); + m_registered = true; + + PushNotificationManager::Default().UnregisterAll(); + m_registered = false; + + VERIFY_THROWS_HR(PushNotificationManager::Default().UnregisterAll(), E_UNEXPECTED); + } + + void PackagedTests::VerifyUnregisterAndUnregisterAll() + { + PushNotificationManager::Default().Register(); + m_registered = true; + + PushNotificationManager::Default().Unregister(); + PushNotificationManager::Default().UnregisterAll(); + m_registered = false; + } + + void PackagedTests::VerifyForegroundHandlerSucceeds() + { + PushNotificationManager::Default().PushReceived([](const auto&, PushNotificationReceivedEventArgs const& /* args */) {}); + PushNotificationManager::Default().Register(); + m_registered = true; + } + + void PackagedTests::VerifyForegroundHandlerFails() + { + PushNotificationManager::Default().Register(); + m_registered = true; + + VERIFY_THROWS_HR(PushNotificationManager::Default().PushReceived([](const auto&, PushNotificationReceivedEventArgs const& /* args */) {}), HRESULT_FROM_WIN32(ERROR_NOT_FOUND)); + } } diff --git a/test/PushNotificationTests/PackagedTests.h b/test/PushNotificationTests/PackagedTests.h new file mode 100644 index 0000000000..7fdee27ec7 --- /dev/null +++ b/test/PushNotificationTests/PackagedTests.h @@ -0,0 +1,82 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +#include "pch.h" +#include + +using namespace WEX::Common; +using namespace WEX::Logging; +using namespace WEX::TestExecution; + +using namespace winrt::Windows::ApplicationModel::Activation; +using namespace winrt::Windows::ApplicationModel::Background; +using namespace winrt::Windows::Foundation; +using namespace winrt::Windows::Foundation::Collections; +using namespace winrt::Windows::Management::Deployment; +using namespace winrt::Windows::Storage; +using namespace winrt::Windows::System; +using namespace winrt::Microsoft::Windows::PushNotifications; + +namespace Test::PushNotifications +{ + class PackagedTests + { + private: + HRESULT ChannelRequestHelper(IAsyncOperationWithProgress const& channelOperation); + + bool m_registered{ false }; + public: + BEGIN_TEST_CLASS(PackagedTests) + TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") + TEST_CLASS_PROPERTY(L"RunFixtureAs:Class", L"RestrictedUser") + TEST_CLASS_PROPERTY(L"RunAs", L"UAP") + TEST_CLASS_PROPERTY(L"UAP:AppxManifest", L"PushNotifications-AppxManifest.xml") + TEST_CLASS_PROPERTY(L"UAP:Host", L"PackagedCWA") + END_TEST_CLASS() + + TEST_CLASS_SETUP(ClassInit) + { + ::Test::Bootstrap::Setup(); + ::WindowsAppRuntime::SelfContained::TestInitialize(::Test::Bootstrap::TP::WindowsAppRuntimeFramework::c_PackageFamilyName); + return true; + } + + TEST_CLASS_CLEANUP(ClassUninit) + { + ::Test::Bootstrap::Cleanup(); + return true; + } + + TEST_METHOD_SETUP(MethodInit) + { + return true; + } + + TEST_METHOD_CLEANUP(MethodUninit) + { + if (m_registered) + { + PushNotificationManager::Default().UnregisterAll(); + m_registered = false; + } + + return true; + } + + TEST_METHOD(ChannelRequestUsingNullRemoteId); + TEST_METHOD(ChannelRequestUsingRemoteId); + TEST_METHOD(MultipleChannelClose); // Currently failing + TEST_METHOD(VerifyRegisterAndUnregister); + TEST_METHOD(VerifyRegisterAndUnregisterAll); + TEST_METHOD(VerifyUnregisterFails); + TEST_METHOD(VerifyUnregisterAllFails); + TEST_METHOD(MultipleRegister); + TEST_METHOD(VerifyMultipleRegisterAndUnregister); + TEST_METHOD(VerifyMultipleRegisterAndUnregisterAll); + TEST_METHOD(VerifyUnregisterTwice); + TEST_METHOD(VerifyUnregisterAllTwice); + TEST_METHOD(VerifyUnregisterAndUnregisterAll); + TEST_METHOD(VerifyForegroundHandlerSucceeds); + TEST_METHOD(VerifyForegroundHandlerFails); + }; +} diff --git a/test/PushNotificationTests/PushNotificationTests.vcxproj b/test/PushNotificationTests/PushNotificationTests.vcxproj index 297aa5a979..153d684bd2 100644 --- a/test/PushNotificationTests/PushNotificationTests.vcxproj +++ b/test/PushNotificationTests/PushNotificationTests.vcxproj @@ -172,15 +172,17 @@ + + - + + - Create Create diff --git a/test/PushNotificationTests/PushNotificationTests.vcxproj.filters b/test/PushNotificationTests/PushNotificationTests.vcxproj.filters index ec6c1a0a44..038182c56d 100644 --- a/test/PushNotificationTests/PushNotificationTests.vcxproj.filters +++ b/test/PushNotificationTests/PushNotificationTests.vcxproj.filters @@ -21,7 +21,16 @@ Header Files - + + Header Files + + + Header Files + + + Header Files + + Header Files @@ -32,9 +41,6 @@ Source Files - - Source Files - Source Files diff --git a/test/PushNotificationTests/TestFunctions.cpp b/test/PushNotificationTests/TestFunctions.cpp deleted file mode 100644 index 09ed8a5c4d..0000000000 --- a/test/PushNotificationTests/TestFunctions.cpp +++ /dev/null @@ -1,151 +0,0 @@ -#include "pch.h" - -#include "TestFunctions.h" -#include "pch.h" -#include -#include "MockBackgroundTaskInstance.h" -#include - -using namespace WEX::Common; -using namespace WEX::Logging; -using namespace WEX::TestExecution; - -using namespace winrt::Windows::ApplicationModel::Activation; -using namespace winrt::Windows::ApplicationModel::Background; -using namespace winrt::Windows::Foundation; -using namespace winrt::Windows::Foundation::Collections; -using namespace winrt::Windows::Management::Deployment; -using namespace winrt::Windows::Storage; -using namespace winrt::Windows::System; -using namespace winrt::Microsoft::Windows::PushNotifications; - -#define VERIFY_THROWS_HR(expression, hr) \ - VERIFY_THROWS_SPECIFIC(expression, \ - winrt::hresult_error, \ - [&](winrt::hresult_error e) -> bool \ - { \ - return (e.code() == hr); \ - }) - -HRESULT ChannelRequestHelper(IAsyncOperationWithProgress const& channelOperation) -{ - if (channelOperation.wait_for(c_timeout) != winrt::Windows::Foundation::AsyncStatus::Completed) - { - channelOperation.Cancel(); - return HRESULT_FROM_WIN32(ERROR_TIMEOUT); // timed out or failed - } - - auto result{ channelOperation.GetResults() }; - auto status{ result.Status() }; - if (status != PushNotificationChannelStatus::CompletedSuccess) - { - return result.ExtendedError(); // did not produce a channel - } - - result.Channel().Close(); - return S_OK; -} - -void PushNotificationTestFunctions::ChannelRequestUsingNullRemoteId() -{ - VERIFY_THROWS_HR(PushNotificationManager::Default().CreateChannelAsync(winrt::guid()).get(), E_INVALIDARG); -} - -void PushNotificationTestFunctions::ChannelRequestUsingRemoteId() -{ - auto channelOperation{ PushNotificationManager::Default().CreateChannelAsync(c_azureRemoteId) }; - VERIFY_SUCCEEDED(ChannelRequestHelper(channelOperation)); -} - -// Currently failing. -void PushNotificationTestFunctions::MultipleChannelClose() -{ - auto channelOperation{ PushNotificationManager::Default().CreateChannelAsync(c_azureRemoteId) }; - if (channelOperation.wait_for(c_timeout) != winrt::Windows::Foundation::AsyncStatus::Completed) - { - channelOperation.Cancel(); - VERIFY_FAIL(L"Channel request hit timeout."); - } - - auto result{ channelOperation.GetResults() }; - VERIFY_ARE_EQUAL(result.Status(), PushNotificationChannelStatus::CompletedSuccess); - - result.Channel().Close(); - VERIFY_THROWS_HR(result.Channel().Close(), WPN_E_CHANNEL_CLOSED); -} - -void PushNotificationTestFunctions::VerifyRegisterAndUnregister() -{ - auto pushNotificationManager{ PushNotificationManager::Default() }; - pushNotificationManager.Register(); - pushNotificationManager.Unregister(); -} - -void PushNotificationTestFunctions::VerifyRegisterAndUnregisterAll() -{ - auto pushNotificationManager{ PushNotificationManager::Default() }; - pushNotificationManager.Register(); - pushNotificationManager.UnregisterAll(); -} - -void PushNotificationTestFunctions::MultipleRegister() -{ - auto pushNotificationManager{ PushNotificationManager::Default() }; - pushNotificationManager.Register(); - VERIFY_THROWS_HR(pushNotificationManager.Register(), HRESULT_FROM_WIN32(ERROR_ALREADY_REGISTERED)); -} - -void PushNotificationTestFunctions::VerifyMultipleRegisterAndUnregister() -{ - PushNotificationManager::Default().Register(); - PushNotificationManager::Default().Unregister(); - VERIFY_THROWS_HR(PushNotificationManager::Default().Register(), HRESULT_FROM_WIN32(ERROR_ALREADY_REGISTERED)); -} - -void PushNotificationTestFunctions::VerifyMultipleRegisterAndUnregisterAll() -{ - PushNotificationManager::Default().Register(); - PushNotificationManager::Default().UnregisterAll(); - - PushNotificationManager::Default().Register(); - PushNotificationManager::Default().UnregisterAll(); -} - -void PushNotificationTestFunctions::VerifyUnregisterTwice() -{ - PushNotificationManager::Default().Register(); - PushNotificationManager::Default().Unregister(); - VERIFY_THROWS_HR(PushNotificationManager::Default().Unregister(), E_UNEXPECTED); -} - -void PushNotificationTestFunctions::VerifyUnregisterAll() -{ - PushNotificationManager::Default().Register(); - PushNotificationManager::Default().UnregisterAll(); -} - -void PushNotificationTestFunctions::VerifyUnregisterAllTwice() -{ - PushNotificationManager::Default().Register(); - PushNotificationManager::Default().UnregisterAll(); - VERIFY_THROWS_HR(PushNotificationManager::Default().UnregisterAll(), E_UNEXPECTED); -} - -void PushNotificationTestFunctions::VerifyUnregisterAndUnregisterAll() -{ - PushNotificationManager::Default().Register(); - PushNotificationManager::Default().Unregister(); - PushNotificationManager::Default().UnregisterAll(); -} - -void PushNotificationTestFunctions::VerifyForegroundHandlerSucceeds() -{ - PushNotificationManager::Default().PushReceived([](const auto&, PushNotificationReceivedEventArgs const& /* args */) {}); - PushNotificationManager::Default().Register(); -} - -void PushNotificationTestFunctions::VerifyForegroundHandlerFails() -{ - PushNotificationManager::Default().Register(); - VERIFY_THROWS_HR(PushNotificationManager::Default().PushReceived([](const auto&, PushNotificationReceivedEventArgs const& /* args */) {}), HRESULT_FROM_WIN32(ERROR_NOT_FOUND)); -} diff --git a/test/PushNotificationTests/TestFunctions.h b/test/PushNotificationTests/TestFunctions.h deleted file mode 100644 index c6d7c7c6c8..0000000000 --- a/test/PushNotificationTests/TestFunctions.h +++ /dev/null @@ -1,18 +0,0 @@ -class PushNotificationTestFunctions -{ - public: - static void VerifyRegisterAndUnregister(); - static void ChannelRequestUsingNullRemoteId(); - static void ChannelRequestUsingRemoteId(); - static void MultipleChannelClose(); - static void VerifyRegisterAndUnregisterAll(); - static void MultipleRegister(); - static void VerifyMultipleRegisterAndUnregister(); - static void VerifyMultipleRegisterAndUnregisterAll(); - static void VerifyUnregisterTwice(); - static void VerifyUnregisterAll(); - static void VerifyUnregisterAllTwice(); - static void VerifyUnregisterAndUnregisterAll(); - static void VerifyForegroundHandlerSucceeds(); - static void VerifyForegroundHandlerFails(); -}; diff --git a/test/PushNotificationTests/UnpackagedSelfContained.cpp b/test/PushNotificationTests/UnpackagedSelfContained.cpp index b3674b41df..5a57eee1fc 100644 --- a/test/PushNotificationTests/UnpackagedSelfContained.cpp +++ b/test/PushNotificationTests/UnpackagedSelfContained.cpp @@ -2,10 +2,9 @@ // Licensed under the MIT License. See LICENSE in the project root for license information. #include "pch.h" + #include -#include "MockBackgroundTaskInstance.h" -#include -#include "TestFunctions.h" +#include "UnpackagedSelfContainedTests.h" using namespace WEX::Common; using namespace WEX::Logging; @@ -20,195 +19,136 @@ using namespace winrt::Windows::Storage; using namespace winrt::Windows::System; using namespace winrt::Microsoft::Windows::PushNotifications; + namespace Test::PushNotifications { - class UnpackagedSelfContainedTests + HRESULT UnpackagedSelfContainedTests::ChannelRequestHelper(IAsyncOperationWithProgress const& channelOperation) { - - public: - BEGIN_TEST_CLASS(UnpackagedSelfContainedTests) - TEST_CLASS_PROPERTY(L"Description", L"Windows App SDK Push Notifications test") - TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") - TEST_CLASS_PROPERTY(L"RunAs:Class", L"RestrictedUser") - END_TEST_CLASS() - - TEST_CLASS_SETUP(ClassInit) + if (channelOperation.wait_for(c_timeout) != winrt::Windows::Foundation::AsyncStatus::Completed) { - try - { - // Cleanup previous installations. Need this to remove any manual installations outside of running this tests. - TP::RemovePackage_PushNotificationsLongRunningTask(); - TP::RemovePackage_DynamicDependencyLifetimeManager(); - TP::RemovePackage_DynamicDependencyDataStore(); - TP::RemovePackage_WindowsAppRuntimeFramework(); - - TP::AddPackage_WindowsAppRuntimeFramework(); // Installs WARfwk - TP::AddPackage_DynamicDependencyDataStore(); // Installs WARmain - TP::AddPackage_DynamicDependencyLifetimeManager(); // Installs WARddlm - TP::AddPackage_PushNotificationsLongRunningTask(); // Installs the PushNotifications long running task. - } - catch (...) - { - return false; - } - return true; + channelOperation.Cancel(); + return HRESULT_FROM_WIN32(ERROR_TIMEOUT); // timed out or failed } - TEST_CLASS_CLEANUP(ClassUninit) + auto result{ channelOperation.GetResults() }; + auto status{ result.Status() }; + if (status != PushNotificationChannelStatus::CompletedSuccess) { - try - { - - // Remove in reverse order to avoid conflicts between inter-dependent packages. - TP::RemovePackage_PushNotificationsLongRunningTask(); - TP::RemovePackage_DynamicDependencyLifetimeManager(); - TP::RemovePackage_DynamicDependencyDataStore(); - TP::RemovePackage_WindowsAppRuntimeFramework(); - } - catch (...) - { - return false; - } - return true; + return result.ExtendedError(); // did not produce a channel } - TEST_METHOD_SETUP(MethodInit) - { - VERIFY_IS_TRUE(TP::IsPackageRegistered_WindowsAppRuntimeFramework()); - VERIFY_IS_TRUE(TP::IsPackageRegistered_DynamicDependencyDataStore()); - VERIFY_IS_TRUE(TP::IsPackageRegistered_DynamicDependencyLifetimeManager()); - VERIFY_IS_TRUE(TP::IsPackageRegistered_PushNotificationsLongRunningTask()); - - VERIFY_ARE_EQUAL(S_OK, MddBootstrapTestInitialize(Test::Packages::DynamicDependencyLifetimeManager::c_PackageNamePrefix, Test::Packages::DynamicDependencyLifetimeManager::c_PackagePublisherId)); + result.Channel().Close(); + return S_OK; + } - // Major.Minor version, MinVersion=0 to find any framework package for this major.minor version - const UINT32 c_Version_MajorMinor{ Test::Packages::DynamicDependencyLifetimeManager::c_Version_MajorMinor }; - const PACKAGE_VERSION c_minVersion{}; - VERIFY_ARE_EQUAL(S_OK, MddBootstrapInitialize(c_Version_MajorMinor, nullptr, c_minVersion)); + void UnpackagedSelfContainedTests::ChannelRequestUsingNullRemoteId() + { + auto channelOperation{ PushNotificationManager::Default().CreateChannelAsync(winrt::guid()) }; + VERIFY_ARE_EQUAL(ChannelRequestHelper(channelOperation), E_FAIL); + } - return true; - } + void UnpackagedSelfContainedTests::ChannelRequestUsingRemoteId() + { + auto channelOperation{ PushNotificationManager::Default().CreateChannelAsync(c_azureRemoteId) }; + VERIFY_ARE_EQUAL(ChannelRequestHelper(channelOperation), E_FAIL); + } - TEST_METHOD_CLEANUP(MethodUninit) + // Currently failing - https://github.com/microsoft/WindowsAppSDK/issues/2392 + void UnpackagedSelfContainedTests::MultipleChannelClose() + { + auto channelOperation{ PushNotificationManager::Default().CreateChannelAsync(c_azureRemoteId) }; + if (channelOperation.wait_for(c_timeout) != winrt::Windows::Foundation::AsyncStatus::Completed) { - // Need to keep each TEST_METHOD in a clean state in the LRP. - try - { - PushNotificationManager::Default().UnregisterAll(); - } - catch (...) - { - // We want to unregister regardless of pass/fail to clean the state. - } - MddBootstrapShutdown(); - - VERIFY_IS_TRUE(TP::IsPackageRegistered_WindowsAppRuntimeFramework()); - VERIFY_IS_TRUE(TP::IsPackageRegistered_DynamicDependencyDataStore()); - VERIFY_IS_TRUE(TP::IsPackageRegistered_DynamicDependencyLifetimeManager()); - VERIFY_IS_TRUE(TP::IsPackageRegistered_PushNotificationsLongRunningTask()); - - return true; + channelOperation.Cancel(); + VERIFY_FAIL(L"Channel request hit timeout."); } - HRESULT ChannelRequestHelper(IAsyncOperationWithProgress const& channelOperation) - { - if (channelOperation.wait_for(c_timeout) != winrt::Windows::Foundation::AsyncStatus::Completed) - { - channelOperation.Cancel(); - return HRESULT_FROM_WIN32(ERROR_TIMEOUT); // timed out or failed - } - - auto result{ channelOperation.GetResults() }; - auto status{ result.Status() }; - if (status != PushNotificationChannelStatus::CompletedSuccess) - { - return result.ExtendedError(); // did not produce a channel - } - - result.Channel().Close(); - return S_OK; - } + auto result{ channelOperation.GetResults() }; + VERIFY_ARE_EQUAL(result.Status(), PushNotificationChannelStatus::CompletedSuccess); - TEST_METHOD(ChannelRequestUsingNullRemoteId) - { - auto channelOperation{ PushNotificationManager::Default().CreateChannelAsync(winrt::guid()) }; - VERIFY_ARE_EQUAL(ChannelRequestHelper(channelOperation), E_FAIL); - } + result.Channel().Close(); + VERIFY_THROWS_HR(result.Channel().Close(), WPN_E_CHANNEL_CLOSED); + } - TEST_METHOD(ChannelRequestUsingRemoteId) - { - auto channelOperation{ PushNotificationManager::Default().CreateChannelAsync(c_azureRemoteId) }; - VERIFY_ARE_EQUAL(ChannelRequestHelper(channelOperation), E_FAIL); - } + void UnpackagedSelfContainedTests::VerifyRegisterAndUnregister() + { + auto pushNotificationManager{ PushNotificationManager::Default() }; + pushNotificationManager.Register(); + pushNotificationManager.Unregister(); + } - // Currently failing. - TEST_METHOD(MultipleChannelClose) - { - PushNotificationTestFunctions::MultipleChannelClose(); - } + void UnpackagedSelfContainedTests::VerifyUnregisterFails() + { + auto pushNotificationManager{ PushNotificationManager::Default() }; + pushNotificationManager.Unregister(); + } - TEST_METHOD(VerifyRegisterAndUnregister) - { - PushNotificationTestFunctions::VerifyRegisterAndUnregister(); - } + void UnpackagedSelfContainedTests::VerifyUnregisterAllFails() + { + auto pushNotificationManager{ PushNotificationManager::Default() }; + pushNotificationManager.UnregisterAll(); + } - TEST_METHOD(VerifyRegisterAndUnregisterAll) - { - PushNotificationTestFunctions::VerifyRegisterAndUnregisterAll(); - } + void UnpackagedSelfContainedTests::VerifyRegisterAndUnregisterAll() + { + auto pushNotificationManager{ PushNotificationManager::Default() }; + pushNotificationManager.Register(); + pushNotificationManager.UnregisterAll(); + } - TEST_METHOD(MultipleRegister) - { - auto pushNotificationManager{ PushNotificationManager::Default() }; - pushNotificationManager.Register(); - pushNotificationManager.Register(); - } + void UnpackagedSelfContainedTests::MultipleRegister() + { + auto pushNotificationManager{ PushNotificationManager::Default() }; + pushNotificationManager.Register(); + pushNotificationManager.Register(); + } - TEST_METHOD(VerifyMultipleRegisterAndUnregister) - { - PushNotificationManager::Default().Register(); - PushNotificationManager::Default().Unregister(); - PushNotificationManager::Default().Register(); - } + void UnpackagedSelfContainedTests::VerifyMultipleRegisterAndUnregister() + { + PushNotificationManager::Default().Register(); + PushNotificationManager::Default().Unregister(); + PushNotificationManager::Default().Register(); + } - TEST_METHOD(VerifyMultipleRegisterAndUnregisterAll) - { - PushNotificationTestFunctions::VerifyMultipleRegisterAndUnregisterAll(); - } + void UnpackagedSelfContainedTests::VerifyMultipleRegisterAndUnregisterAll() + { + PushNotificationManager::Default().Register(); + PushNotificationManager::Default().UnregisterAll(); - TEST_METHOD(VerifyUnregisterTwice) - { - PushNotificationManager::Default().Register(); - PushNotificationManager::Default().Unregister(); - PushNotificationManager::Default().Unregister(); - } + PushNotificationManager::Default().Register(); + PushNotificationManager::Default().UnregisterAll(); + } - TEST_METHOD(VerifyUnregisterAll) - { - PushNotificationTestFunctions::VerifyUnregisterAll(); - } + void UnpackagedSelfContainedTests::VerifyUnregisterTwice() + { + PushNotificationManager::Default().Register(); + PushNotificationManager::Default().Unregister(); + PushNotificationManager::Default().Unregister(); + } - TEST_METHOD(VerifyUnregisterAllTwice) - { - PushNotificationManager::Default().Register(); - PushNotificationManager::Default().UnregisterAll(); - PushNotificationManager::Default().UnregisterAll(); - } + void UnpackagedSelfContainedTests::VerifyUnregisterAllTwice() + { + PushNotificationManager::Default().Register(); + PushNotificationManager::Default().UnregisterAll(); + PushNotificationManager::Default().UnregisterAll(); + } - TEST_METHOD(VerifyUnregisterAndUnregisterAll) - { - PushNotificationTestFunctions::VerifyUnregisterAndUnregisterAll(); - } + void UnpackagedSelfContainedTests::VerifyUnregisterAndUnregisterAll() + { + PushNotificationManager::Default().Register(); + PushNotificationManager::Default().Unregister(); + PushNotificationManager::Default().UnregisterAll(); + } - TEST_METHOD(VerifyForegroundHandlerSucceeds) - { - PushNotificationTestFunctions::VerifyForegroundHandlerSucceeds(); - } + void UnpackagedSelfContainedTests::VerifyForegroundHandlerSucceeds() + { + PushNotificationManager::Default().PushReceived([](const auto&, PushNotificationReceivedEventArgs const& /* args */) {}); + PushNotificationManager::Default().Register(); + } - TEST_METHOD(VerifyForegroundHandlerFails) - { - PushNotificationManager::Default().Register(); - PushNotificationManager::Default().PushReceived([](const auto&, PushNotificationReceivedEventArgs const& /* args */) {}); - } - }; + void UnpackagedSelfContainedTests::VerifyForegroundHandlerFails() + { + PushNotificationManager::Default().Register(); + PushNotificationManager::Default().PushReceived([](const auto&, PushNotificationReceivedEventArgs const& /* args */) {}); + } } diff --git a/test/PushNotificationTests/UnpackagedSelfContainedTests.h b/test/PushNotificationTests/UnpackagedSelfContainedTests.h new file mode 100644 index 0000000000..c158eba24d --- /dev/null +++ b/test/PushNotificationTests/UnpackagedSelfContainedTests.h @@ -0,0 +1,62 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +#include "pch.h" +#include + +using namespace WEX::Common; +using namespace WEX::Logging; +using namespace WEX::TestExecution; + +using namespace winrt::Windows::ApplicationModel::Activation; +using namespace winrt::Windows::ApplicationModel::Background; +using namespace winrt::Windows::Foundation; +using namespace winrt::Windows::Foundation::Collections; +using namespace winrt::Windows::Management::Deployment; +using namespace winrt::Windows::Storage; +using namespace winrt::Windows::System; +using namespace winrt::Microsoft::Windows::PushNotifications; + +namespace Test::PushNotifications +{ + class UnpackagedSelfContainedTests + { + private: + HRESULT ChannelRequestHelper(IAsyncOperationWithProgress const& channelOperation); + + public: + BEGIN_TEST_CLASS(UnpackagedSelfContainedTests) + TEST_CLASS_PROPERTY(L"Description", L"Windows App SDK Push Notifications test") + TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") + TEST_CLASS_PROPERTY(L"RunAs:Class", L"RestrictedUser") + END_TEST_CLASS() + + TEST_CLASS_SETUP(ClassInit) + { + ::Test::Bootstrap::Setup(); + return true; + } + + TEST_CLASS_CLEANUP(ClassUninit) + { + ::Test::Bootstrap::Cleanup(); + return true; + } + + TEST_METHOD(ChannelRequestUsingNullRemoteId); + TEST_METHOD(ChannelRequestUsingRemoteId); + TEST_METHOD(MultipleChannelClose); // Currently failing + TEST_METHOD(VerifyRegisterAndUnregister); + TEST_METHOD(VerifyRegisterAndUnregisterAll); + TEST_METHOD(VerifyUnregisterFails); + TEST_METHOD(VerifyUnregisterAllFails); + TEST_METHOD(MultipleRegister); + TEST_METHOD(VerifyMultipleRegisterAndUnregister); + TEST_METHOD(VerifyMultipleRegisterAndUnregisterAll); + TEST_METHOD(VerifyUnregisterTwice); + TEST_METHOD(VerifyUnregisterAllTwice); + TEST_METHOD(VerifyUnregisterAndUnregisterAll); + TEST_METHOD(VerifyForegroundHandlerSucceeds); + TEST_METHOD(VerifyForegroundHandlerFails); + }; +} diff --git a/test/PushNotificationTests/UnpackagedTests.cpp b/test/PushNotificationTests/UnpackagedTests.cpp index 5b490a647c..485806b848 100644 --- a/test/PushNotificationTests/UnpackagedTests.cpp +++ b/test/PushNotificationTests/UnpackagedTests.cpp @@ -2,10 +2,9 @@ // Licensed under the MIT License. See LICENSE in the project root for license information. #include "pch.h" + #include -#include "MockBackgroundTaskInstance.h" -#include -#include "TestFunctions.h" +#include "UnpackagedTests.h" using namespace WEX::Common; using namespace WEX::Logging; @@ -20,140 +19,162 @@ using namespace winrt::Windows::Storage; using namespace winrt::Windows::System; using namespace winrt::Microsoft::Windows::PushNotifications; + namespace Test::PushNotifications { - class UnpackagedTests + HRESULT UnpackagedTests::ChannelRequestHelper(IAsyncOperationWithProgress const& channelOperation) { - - public: - BEGIN_TEST_CLASS(UnpackagedTests) - TEST_CLASS_PROPERTY(L"Description", L"Windows App SDK Push Notifications test") - TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") - TEST_CLASS_PROPERTY(L"RunAs:Class", L"RestrictedUser") - END_TEST_CLASS() - - TEST_CLASS_SETUP(ClassInit) + if (channelOperation.wait_for(c_timeout) != winrt::Windows::Foundation::AsyncStatus::Completed) { - try - { - // Cleanup previous installations. Need this to remove any manual installations outside of running this tests. - TP::RemovePackage_PushNotificationsLongRunningTask(); - - ::Test::Bootstrap::Setup(); - TP::AddPackage_PushNotificationsLongRunningTask(); // Installs the PushNotifications long running task. - } - catch (...) - { - return false; - } - return true; - } - - TEST_CLASS_CLEANUP(ClassUninit) - { - try - { - // Remove in reverse order to avoid conflicts between inter-dependent packages. - ::Test::Bootstrap::Cleanup(); - TP::RemovePackage_PushNotificationsLongRunningTask(); - } - catch (...) - { - return false; - } - return true; + channelOperation.Cancel(); + return HRESULT_FROM_WIN32(ERROR_TIMEOUT); // timed out or failed } - TEST_METHOD_SETUP(MethodInit) + auto result{ channelOperation.GetResults() }; + auto status{ result.Status() }; + if (status != PushNotificationChannelStatus::CompletedSuccess) { - // Need to use SelfContained test hook to setup tests. - ::WindowsAppRuntime::SelfContained::TestInitialize(::Test::Bootstrap::TP::WindowsAppRuntimeFramework::c_PackageFamilyName); - return true; + return result.ExtendedError(); // did not produce a channel } - TEST_METHOD_CLEANUP(MethodUninit) - { - // Need to keep each TEST_METHOD in a clean state in the LRP. - try - { - PushNotificationManager::Default().UnregisterAll(); - } - catch (...) - { - // We want to unregister regardless of pass/fail to clean the state. - } - return true; - } + result.Channel().Close(); + return S_OK; + } - TEST_METHOD(ChannelRequestUsingNullRemoteId) - { - PushNotificationTestFunctions::ChannelRequestUsingNullRemoteId(); - } + void UnpackagedTests::ChannelRequestUsingNullRemoteId() + { + VERIFY_THROWS_HR(PushNotificationManager::Default().CreateChannelAsync(winrt::guid()).get(), E_INVALIDARG); + } - TEST_METHOD(ChannelRequestUsingRemoteId) - { - PushNotificationTestFunctions::ChannelRequestUsingRemoteId(); - } + void UnpackagedTests::ChannelRequestUsingRemoteId() + { + auto channelOperation{ PushNotificationManager::Default().CreateChannelAsync(c_azureRemoteId) }; + VERIFY_SUCCEEDED(ChannelRequestHelper(channelOperation)); + } - // Currently failing. - TEST_METHOD(MultipleChannelClose) + // Currently failing - https://github.com/microsoft/WindowsAppSDK/issues/2392 + void UnpackagedTests::MultipleChannelClose() + { + auto channelOperation{ PushNotificationManager::Default().CreateChannelAsync(c_azureRemoteId) }; + if (channelOperation.wait_for(c_timeout) != winrt::Windows::Foundation::AsyncStatus::Completed) { - PushNotificationTestFunctions::MultipleChannelClose(); + channelOperation.Cancel(); + VERIFY_FAIL(L"Channel request hit timeout."); } - TEST_METHOD(VerifyRegisterAndUnregister) - { - PushNotificationTestFunctions::VerifyRegisterAndUnregister(); - } + auto result{ channelOperation.GetResults() }; + VERIFY_ARE_EQUAL(result.Status(), PushNotificationChannelStatus::CompletedSuccess); - TEST_METHOD(VerifyRegisterAndUnregisterAll) - { - PushNotificationTestFunctions::VerifyRegisterAndUnregisterAll(); - } + result.Channel().Close(); + VERIFY_THROWS_HR(result.Channel().Close(), WPN_E_CHANNEL_CLOSED); + } - TEST_METHOD(MultipleRegister) - { - PushNotificationTestFunctions::MultipleRegister(); - } + void UnpackagedTests::VerifyRegisterAndUnregister() + { + auto pushNotificationManager{ PushNotificationManager::Default() }; + pushNotificationManager.Register(); + m_registered = true; - TEST_METHOD(VerifyMultipleRegisterAndUnregister) - { - PushNotificationTestFunctions::VerifyMultipleRegisterAndUnregister(); - } + pushNotificationManager.Unregister(); + } - TEST_METHOD(VerifyMultipleRegisterAndUnregisterAll) - { - PushNotificationTestFunctions::VerifyMultipleRegisterAndUnregisterAll(); - } + void UnpackagedTests::VerifyUnregisterFails() + { + auto pushNotificationManager{ PushNotificationManager::Default() }; + VERIFY_THROWS_HR(pushNotificationManager.Unregister(), E_UNEXPECTED); + } - TEST_METHOD(VerifyUnregisterTwice) - { - PushNotificationTestFunctions::VerifyUnregisterTwice(); - } + void UnpackagedTests::VerifyUnregisterAllFails() + { + auto pushNotificationManager{ PushNotificationManager::Default() }; + VERIFY_THROWS_HR(pushNotificationManager.UnregisterAll(), E_UNEXPECTED); + } - TEST_METHOD(VerifyUnregisterAll) - { - PushNotificationTestFunctions::VerifyUnregisterAll(); - } + void UnpackagedTests::VerifyRegisterAndUnregisterAll() + { + auto pushNotificationManager{ PushNotificationManager::Default() }; + pushNotificationManager.Register(); + m_registered = true; - TEST_METHOD(VerifyUnregisterAllTwice) - { - PushNotificationTestFunctions::VerifyUnregisterAllTwice(); - } + pushNotificationManager.UnregisterAll(); + m_registered = false; + } - TEST_METHOD(VerifyUnregisterAndUnregisterAll) - { - PushNotificationTestFunctions::VerifyUnregisterAndUnregisterAll(); - } + void UnpackagedTests::MultipleRegister() + { + auto pushNotificationManager{ PushNotificationManager::Default() }; + pushNotificationManager.Register(); + m_registered = true; - TEST_METHOD(VerifyForegroundHandlerSucceeds) - { - PushNotificationTestFunctions::VerifyForegroundHandlerSucceeds(); - } + VERIFY_THROWS_HR(pushNotificationManager.Register(), HRESULT_FROM_WIN32(ERROR_ALREADY_REGISTERED)); + } - TEST_METHOD(VerifyForegroundHandlerFails) - { - PushNotificationTestFunctions::VerifyForegroundHandlerFails(); - } - }; + void UnpackagedTests::VerifyMultipleRegisterAndUnregister() + { + PushNotificationManager::Default().Register(); + m_registered = true; + + PushNotificationManager::Default().Unregister(); + VERIFY_THROWS_HR(PushNotificationManager::Default().Register(), HRESULT_FROM_WIN32(ERROR_ALREADY_REGISTERED)); + } + + void UnpackagedTests::VerifyMultipleRegisterAndUnregisterAll() + { + PushNotificationManager::Default().Register(); + m_registered = true; + + PushNotificationManager::Default().UnregisterAll(); + m_registered = false; + + PushNotificationManager::Default().Register(); + m_registered = true; + + PushNotificationManager::Default().UnregisterAll(); + m_registered = false; + } + + void UnpackagedTests::VerifyUnregisterTwice() + { + PushNotificationManager::Default().Register(); + m_registered = true; + + PushNotificationManager::Default().Unregister(); + VERIFY_THROWS_HR(PushNotificationManager::Default().Unregister(), E_UNEXPECTED); + } + + void UnpackagedTests::VerifyUnregisterAllTwice() + { + PushNotificationManager::Default().Register(); + m_registered = true; + + PushNotificationManager::Default().UnregisterAll(); + m_registered = false; + + VERIFY_THROWS_HR(PushNotificationManager::Default().UnregisterAll(), E_UNEXPECTED); + } + + void UnpackagedTests::VerifyUnregisterAndUnregisterAll() + { + PushNotificationManager::Default().Register(); + m_registered = true; + + PushNotificationManager::Default().Unregister(); + PushNotificationManager::Default().UnregisterAll(); + m_registered = false; + } + + void UnpackagedTests::VerifyForegroundHandlerSucceeds() + { + PushNotificationManager::Default().PushReceived([](const auto&, PushNotificationReceivedEventArgs const& /* args */) {}); + PushNotificationManager::Default().Register(); + m_registered = true; + } + + void UnpackagedTests::VerifyForegroundHandlerFails() + { + PushNotificationManager::Default().Register(); + m_registered = true; + + VERIFY_THROWS_HR(PushNotificationManager::Default().PushReceived([](const auto&, PushNotificationReceivedEventArgs const& /* args */) {}), HRESULT_FROM_WIN32(ERROR_NOT_FOUND)); + } } diff --git a/test/PushNotificationTests/UnpackagedTests.h b/test/PushNotificationTests/UnpackagedTests.h new file mode 100644 index 0000000000..ee45e39a9b --- /dev/null +++ b/test/PushNotificationTests/UnpackagedTests.h @@ -0,0 +1,80 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +#include "pch.h" +#include + +using namespace WEX::Common; +using namespace WEX::Logging; +using namespace WEX::TestExecution; + +using namespace winrt::Windows::ApplicationModel::Activation; +using namespace winrt::Windows::ApplicationModel::Background; +using namespace winrt::Windows::Foundation; +using namespace winrt::Windows::Foundation::Collections; +using namespace winrt::Windows::Management::Deployment; +using namespace winrt::Windows::Storage; +using namespace winrt::Windows::System; +using namespace winrt::Microsoft::Windows::PushNotifications; + +namespace Test::PushNotifications +{ + class UnpackagedTests + { + private: + HRESULT ChannelRequestHelper(IAsyncOperationWithProgress const& channelOperation); + + bool m_registered{ false }; + public: + BEGIN_TEST_CLASS(UnpackagedTests) + TEST_CLASS_PROPERTY(L"Description", L"Windows App SDK Push Notifications test") + TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") + TEST_CLASS_PROPERTY(L"RunAs:Class", L"RestrictedUser") + END_TEST_CLASS() + + TEST_CLASS_SETUP(ClassInit) + { + ::Test::Bootstrap::Setup(); + ::WindowsAppRuntime::SelfContained::TestInitialize(::Test::Bootstrap::TP::WindowsAppRuntimeFramework::c_PackageFamilyName); + return true; + } + + TEST_CLASS_CLEANUP(ClassUninit) + { + ::Test::Bootstrap::Cleanup(); + return true; + } + + TEST_METHOD_SETUP(MethodInit) + { + return true; + } + + TEST_METHOD_CLEANUP(MethodUninit) + { + if (m_registered) + { + PushNotificationManager::Default().UnregisterAll(); + m_registered = false; + } + + return true; + } + + TEST_METHOD(ChannelRequestUsingNullRemoteId); + TEST_METHOD(ChannelRequestUsingRemoteId); + TEST_METHOD(MultipleChannelClose); // Currently failing + TEST_METHOD(VerifyRegisterAndUnregister); + TEST_METHOD(VerifyRegisterAndUnregisterAll); + TEST_METHOD(VerifyUnregisterFails); + TEST_METHOD(VerifyUnregisterAllFails); + TEST_METHOD(MultipleRegister); + TEST_METHOD(VerifyMultipleRegisterAndUnregister); + TEST_METHOD(VerifyMultipleRegisterAndUnregisterAll); + TEST_METHOD(VerifyUnregisterTwice); + TEST_METHOD(VerifyUnregisterAllTwice); + TEST_METHOD(VerifyUnregisterAndUnregisterAll); + TEST_METHOD(VerifyForegroundHandlerSucceeds); + TEST_METHOD(VerifyForegroundHandlerFails); + }; +} diff --git a/test/PushNotificationTests/pch.h b/test/PushNotificationTests/pch.h index fee347ce38..e9dc540edd 100644 --- a/test/PushNotificationTests/pch.h +++ b/test/PushNotificationTests/pch.h @@ -6,10 +6,6 @@ #include -#ifndef INLINE_TEST_METHOD_MARKUP -#define INLINE_TEST_METHOD_MARKUP -#endif - #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers #include #include @@ -46,6 +42,14 @@ #include #include +#define VERIFY_THROWS_HR(expression, hr) \ + VERIFY_THROWS_SPECIFIC(expression, \ + winrt::hresult_error, \ + [&](winrt::hresult_error e) -> bool \ + { \ + return (e.code() == hr); \ + }) + namespace TP = ::Test::Packages; namespace TAEF = ::Test::TAEF; #endif //PCH_H diff --git a/test/inc/WindowsAppRuntime.Test.Bootstrap.h b/test/inc/WindowsAppRuntime.Test.Bootstrap.h index 35466b4988..aa4a051221 100644 --- a/test/inc/WindowsAppRuntime.Test.Bootstrap.h +++ b/test/inc/WindowsAppRuntime.Test.Bootstrap.h @@ -22,7 +22,7 @@ namespace Test::Bootstrap DDLM = 0x0004, Singleton = 0x0008, - Default = Framework | Main | DDLM, + Default = Framework | Main | DDLM | Singleton, }; } DEFINE_ENUM_FLAG_OPERATORS(Test::Bootstrap::Packages) @@ -154,8 +154,8 @@ namespace Test::Bootstrap inline void Cleanup() { - CleanupPackages(); CleanupBootstrap(); + CleanupPackages(); } } From ec7a981613a58e3b50e7a404a677932e1e9a6ade Mon Sep 17 00:00:00 2001 From: Paul Purifoy <33183370+pmpurifoy@users.noreply.github.com> Date: Tue, 12 Apr 2022 17:36:47 -0700 Subject: [PATCH 04/16] Update PowerNotifications.vcxproj --- test/PowerNotifications/PowerNotifications.vcxproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/PowerNotifications/PowerNotifications.vcxproj b/test/PowerNotifications/PowerNotifications.vcxproj index 351c1c64ed..f4a2456b12 100644 --- a/test/PowerNotifications/PowerNotifications.vcxproj +++ b/test/PowerNotifications/PowerNotifications.vcxproj @@ -210,4 +210,4 @@ - \ No newline at end of file + From 99fa965c5d506ea2cbbe4bf10b5edacfdbc96911 Mon Sep 17 00:00:00 2001 From: Paul Purifoy Date: Wed, 13 Apr 2022 15:53:58 -0700 Subject: [PATCH 05/16] Condensed packaged/unpackaged self contained tests --- .../PackagedSelfContainedTests.cpp | 179 ------------------ .../PackagedSelfContainedTests.h | 81 -------- test/PushNotificationTests/PackagedTests.cpp | 1 - test/PushNotificationTests/PackagedTests.h | 15 +- .../PushNotificationTests.vcxproj | 4 - .../PushNotificationTests.vcxproj.filters | 12 -- .../UnpackagedSelfContained.cpp | 154 --------------- .../UnpackagedSelfContainedTests.h | 62 ------ .../PushNotificationTests/UnpackagedTests.cpp | 101 ++++++++-- test/PushNotificationTests/UnpackagedTests.h | 13 +- 10 files changed, 104 insertions(+), 518 deletions(-) delete mode 100644 test/PushNotificationTests/PackagedSelfContainedTests.cpp delete mode 100644 test/PushNotificationTests/PackagedSelfContainedTests.h delete mode 100644 test/PushNotificationTests/UnpackagedSelfContained.cpp delete mode 100644 test/PushNotificationTests/UnpackagedSelfContainedTests.h diff --git a/test/PushNotificationTests/PackagedSelfContainedTests.cpp b/test/PushNotificationTests/PackagedSelfContainedTests.cpp deleted file mode 100644 index 5f8926da62..0000000000 --- a/test/PushNotificationTests/PackagedSelfContainedTests.cpp +++ /dev/null @@ -1,179 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See LICENSE in the project root for license information. - -#include "pch.h" - -#include -#include "PackagedSelfContainedTests.h" - -using namespace WEX::Common; -using namespace WEX::Logging; -using namespace WEX::TestExecution; - -using namespace winrt::Windows::ApplicationModel::Activation; -using namespace winrt::Windows::ApplicationModel::Background; -using namespace winrt::Windows::Foundation; -using namespace winrt::Windows::Foundation::Collections; -using namespace winrt::Windows::Management::Deployment; -using namespace winrt::Windows::Storage; -using namespace winrt::Windows::System; -using namespace winrt::Microsoft::Windows::PushNotifications; - - -namespace Test::PushNotifications -{ - HRESULT PackagedSelfContainedTests::ChannelRequestHelper(IAsyncOperationWithProgress const& channelOperation) - { - if (channelOperation.wait_for(c_timeout) != winrt::Windows::Foundation::AsyncStatus::Completed) - { - channelOperation.Cancel(); - return HRESULT_FROM_WIN32(ERROR_TIMEOUT); // timed out or failed - } - - auto result{ channelOperation.GetResults() }; - auto status{ result.Status() }; - if (status != PushNotificationChannelStatus::CompletedSuccess) - { - return result.ExtendedError(); // did not produce a channel - } - - result.Channel().Close(); - return S_OK; - } - - void PackagedSelfContainedTests::ChannelRequestUsingNullRemoteId() - { - VERIFY_THROWS_HR(PushNotificationManager::Default().CreateChannelAsync(winrt::guid()).get(), E_INVALIDARG); - } - - void PackagedSelfContainedTests::ChannelRequestUsingRemoteId() - { - auto channelOperation{ PushNotificationManager::Default().CreateChannelAsync(c_azureRemoteId) }; - VERIFY_SUCCEEDED(ChannelRequestHelper(channelOperation)); - } - - // Currently failing - https://github.com/microsoft/WindowsAppSDK/issues/2392 - void PackagedSelfContainedTests::MultipleChannelClose() - { - auto channelOperation{ PushNotificationManager::Default().CreateChannelAsync(c_azureRemoteId) }; - if (channelOperation.wait_for(c_timeout) != winrt::Windows::Foundation::AsyncStatus::Completed) - { - channelOperation.Cancel(); - VERIFY_FAIL(L"Channel request hit timeout."); - } - - auto result{ channelOperation.GetResults() }; - VERIFY_ARE_EQUAL(result.Status(), PushNotificationChannelStatus::CompletedSuccess); - - result.Channel().Close(); - VERIFY_THROWS_HR(result.Channel().Close(), WPN_E_CHANNEL_CLOSED); - } - - void PackagedSelfContainedTests::VerifyRegisterAndUnregister() - { - auto pushNotificationManager{ PushNotificationManager::Default() }; - pushNotificationManager.Register(); - m_registered = true; - pushNotificationManager.Unregister(); - } - - void PackagedSelfContainedTests::VerifyUnregisterFails() - { - auto pushNotificationManager{ PushNotificationManager::Default() }; - VERIFY_THROWS_HR(pushNotificationManager.Unregister(), E_UNEXPECTED); - } - - void PackagedSelfContainedTests::VerifyUnregisterAllFails() - { - auto pushNotificationManager{ PushNotificationManager::Default() }; - VERIFY_THROWS_HR(pushNotificationManager.UnregisterAll(), E_UNEXPECTED); - } - - void PackagedSelfContainedTests::VerifyRegisterAndUnregisterAll() - { - auto pushNotificationManager{ PushNotificationManager::Default() }; - pushNotificationManager.Register(); - m_registered = true; - - pushNotificationManager.UnregisterAll(); - m_registered = false; - } - - void PackagedSelfContainedTests::MultipleRegister() - { - auto pushNotificationManager{ PushNotificationManager::Default() }; - pushNotificationManager.Register(); - m_registered = true; - - VERIFY_THROWS_HR(pushNotificationManager.Register(), HRESULT_FROM_WIN32(ERROR_ALREADY_REGISTERED)); - } - - void PackagedSelfContainedTests::VerifyMultipleRegisterAndUnregister() - { - PushNotificationManager::Default().Register(); - m_registered = true; - - PushNotificationManager::Default().Unregister(); - VERIFY_THROWS_HR(PushNotificationManager::Default().Register(), HRESULT_FROM_WIN32(ERROR_ALREADY_REGISTERED)); - } - - void PackagedSelfContainedTests::VerifyMultipleRegisterAndUnregisterAll() - { - PushNotificationManager::Default().Register(); - m_registered = true; - - PushNotificationManager::Default().UnregisterAll(); - m_registered = false; - - PushNotificationManager::Default().Register(); - m_registered = true; - - PushNotificationManager::Default().UnregisterAll(); - m_registered = false; - } - - void PackagedSelfContainedTests::VerifyUnregisterTwice() - { - PushNotificationManager::Default().Register(); - m_registered = true; - - PushNotificationManager::Default().Unregister(); - VERIFY_THROWS_HR(PushNotificationManager::Default().Unregister(), E_UNEXPECTED); - } - - void PackagedSelfContainedTests::VerifyUnregisterAllTwice() - { - PushNotificationManager::Default().Register(); - m_registered = true; - - PushNotificationManager::Default().UnregisterAll(); - m_registered = false; - - VERIFY_THROWS_HR(PushNotificationManager::Default().UnregisterAll(), E_UNEXPECTED); - } - - void PackagedSelfContainedTests::VerifyUnregisterAndUnregisterAll() - { - PushNotificationManager::Default().Register(); - m_registered = true; - - PushNotificationManager::Default().Unregister(); - PushNotificationManager::Default().UnregisterAll(); - m_registered = false; - } - - void PackagedSelfContainedTests::VerifyForegroundHandlerSucceeds() - { - PushNotificationManager::Default().PushReceived([](const auto&, PushNotificationReceivedEventArgs const& /* args */) {}); - PushNotificationManager::Default().Register(); - m_registered = true; - } - - void PackagedSelfContainedTests::VerifyForegroundHandlerFails() - { - PushNotificationManager::Default().Register(); - m_registered = true; - - VERIFY_THROWS_HR(PushNotificationManager::Default().PushReceived([](const auto&, PushNotificationReceivedEventArgs const& /* args */) {}), HRESULT_FROM_WIN32(ERROR_NOT_FOUND)); - } -} diff --git a/test/PushNotificationTests/PackagedSelfContainedTests.h b/test/PushNotificationTests/PackagedSelfContainedTests.h deleted file mode 100644 index 4986618230..0000000000 --- a/test/PushNotificationTests/PackagedSelfContainedTests.h +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See LICENSE in the project root for license information. - -#include "pch.h" -#include - -using namespace WEX::Common; -using namespace WEX::Logging; -using namespace WEX::TestExecution; - -using namespace winrt::Windows::ApplicationModel::Activation; -using namespace winrt::Windows::ApplicationModel::Background; -using namespace winrt::Windows::Foundation; -using namespace winrt::Windows::Foundation::Collections; -using namespace winrt::Windows::Management::Deployment; -using namespace winrt::Windows::Storage; -using namespace winrt::Windows::System; -using namespace winrt::Microsoft::Windows::PushNotifications; - -namespace Test::PushNotifications -{ - class PackagedSelfContainedTests - { - private: - HRESULT ChannelRequestHelper(IAsyncOperationWithProgress const& channelOperation); - - bool m_registered{ false }; - public: - BEGIN_TEST_CLASS(PackagedSelfContainedTests) - TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") - TEST_CLASS_PROPERTY(L"RunFixtureAs:Class", L"RestrictedUser") - TEST_CLASS_PROPERTY(L"RunAs", L"UAP") - TEST_CLASS_PROPERTY(L"UAP:AppxManifest", L"PushNotifications-AppxManifest.xml") - TEST_CLASS_PROPERTY(L"UAP:Host", L"PackagedCWA") - END_TEST_CLASS() - - TEST_CLASS_SETUP(ClassInit) - { - ::Test::Bootstrap::Setup(); - return true; - } - - TEST_CLASS_CLEANUP(ClassUninit) - { - ::Test::Bootstrap::Cleanup(); - return true; - } - - TEST_METHOD_SETUP(MethodInit) - { - return true; - } - - TEST_METHOD_CLEANUP(MethodUninit) - { - if (m_registered) - { - PushNotificationManager::Default().UnregisterAll(); - m_registered = false; - } - - return true; - } - - TEST_METHOD(ChannelRequestUsingNullRemoteId); - TEST_METHOD(ChannelRequestUsingRemoteId); - TEST_METHOD(MultipleChannelClose); // Currently failing - TEST_METHOD(VerifyRegisterAndUnregister); - TEST_METHOD(VerifyRegisterAndUnregisterAll); - TEST_METHOD(VerifyUnregisterFails); - TEST_METHOD(VerifyUnregisterAllFails); - TEST_METHOD(MultipleRegister); - TEST_METHOD(VerifyMultipleRegisterAndUnregister); - TEST_METHOD(VerifyMultipleRegisterAndUnregisterAll); - TEST_METHOD(VerifyUnregisterTwice); - TEST_METHOD(VerifyUnregisterAllTwice); - TEST_METHOD(VerifyUnregisterAndUnregisterAll); - TEST_METHOD(VerifyForegroundHandlerSucceeds); - TEST_METHOD(VerifyForegroundHandlerFails); - }; -} diff --git a/test/PushNotificationTests/PackagedTests.cpp b/test/PushNotificationTests/PackagedTests.cpp index 92dd30565d..9e3dcefa26 100644 --- a/test/PushNotificationTests/PackagedTests.cpp +++ b/test/PushNotificationTests/PackagedTests.cpp @@ -74,7 +74,6 @@ namespace Test::PushNotifications auto pushNotificationManager{ PushNotificationManager::Default() }; pushNotificationManager.Register(); m_registered = true; - pushNotificationManager.Unregister(); } diff --git a/test/PushNotificationTests/PackagedTests.h b/test/PushNotificationTests/PackagedTests.h index 7fdee27ec7..3f27e13134 100644 --- a/test/PushNotificationTests/PackagedTests.h +++ b/test/PushNotificationTests/PackagedTests.h @@ -29,15 +29,24 @@ namespace Test::PushNotifications BEGIN_TEST_CLASS(PackagedTests) TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") TEST_CLASS_PROPERTY(L"RunFixtureAs:Class", L"RestrictedUser") + TEST_CLASS_PROPERTY(L"IsolationLevel", L"Class") TEST_CLASS_PROPERTY(L"RunAs", L"UAP") - TEST_CLASS_PROPERTY(L"UAP:AppxManifest", L"PushNotifications-AppxManifest.xml") TEST_CLASS_PROPERTY(L"UAP:Host", L"PackagedCWA") - END_TEST_CLASS() + TEST_CLASS_PROPERTY(L"UAP:AppxManifest", L"PushNotifications-AppxManifest.xml") + TEST_CLASS_PROPERTY(L"Data:SelfContained", L"{true, false}") + END_TEST_CLASS() TEST_CLASS_SETUP(ClassInit) { ::Test::Bootstrap::Setup(); - ::WindowsAppRuntime::SelfContained::TestInitialize(::Test::Bootstrap::TP::WindowsAppRuntimeFramework::c_PackageFamilyName); + bool isSelfContained{ false }; + if (SUCCEEDED(TestData::TryGetValue(L"SelfContained", isSelfContained))) + { + if (!isSelfContained) + { + ::WindowsAppRuntime::SelfContained::TestInitialize(::Test::Bootstrap::TP::WindowsAppRuntimeFramework::c_PackageFamilyName); + } + } return true; } diff --git a/test/PushNotificationTests/PushNotificationTests.vcxproj b/test/PushNotificationTests/PushNotificationTests.vcxproj index 153d684bd2..ae5a91cea9 100644 --- a/test/PushNotificationTests/PushNotificationTests.vcxproj +++ b/test/PushNotificationTests/PushNotificationTests.vcxproj @@ -172,16 +172,12 @@ - - - - Create diff --git a/test/PushNotificationTests/PushNotificationTests.vcxproj.filters b/test/PushNotificationTests/PushNotificationTests.vcxproj.filters index 038182c56d..388552939c 100644 --- a/test/PushNotificationTests/PushNotificationTests.vcxproj.filters +++ b/test/PushNotificationTests/PushNotificationTests.vcxproj.filters @@ -21,15 +21,9 @@ Header Files - - Header Files - Header Files - - Header Files - Header Files @@ -44,12 +38,6 @@ Source Files - - Source Files - - - Source Files - diff --git a/test/PushNotificationTests/UnpackagedSelfContained.cpp b/test/PushNotificationTests/UnpackagedSelfContained.cpp deleted file mode 100644 index 5a57eee1fc..0000000000 --- a/test/PushNotificationTests/UnpackagedSelfContained.cpp +++ /dev/null @@ -1,154 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See LICENSE in the project root for license information. - -#include "pch.h" - -#include -#include "UnpackagedSelfContainedTests.h" - -using namespace WEX::Common; -using namespace WEX::Logging; -using namespace WEX::TestExecution; - -using namespace winrt::Windows::ApplicationModel::Activation; -using namespace winrt::Windows::ApplicationModel::Background; -using namespace winrt::Windows::Foundation; -using namespace winrt::Windows::Foundation::Collections; -using namespace winrt::Windows::Management::Deployment; -using namespace winrt::Windows::Storage; -using namespace winrt::Windows::System; -using namespace winrt::Microsoft::Windows::PushNotifications; - - -namespace Test::PushNotifications -{ - HRESULT UnpackagedSelfContainedTests::ChannelRequestHelper(IAsyncOperationWithProgress const& channelOperation) - { - if (channelOperation.wait_for(c_timeout) != winrt::Windows::Foundation::AsyncStatus::Completed) - { - channelOperation.Cancel(); - return HRESULT_FROM_WIN32(ERROR_TIMEOUT); // timed out or failed - } - - auto result{ channelOperation.GetResults() }; - auto status{ result.Status() }; - if (status != PushNotificationChannelStatus::CompletedSuccess) - { - return result.ExtendedError(); // did not produce a channel - } - - result.Channel().Close(); - return S_OK; - } - - void UnpackagedSelfContainedTests::ChannelRequestUsingNullRemoteId() - { - auto channelOperation{ PushNotificationManager::Default().CreateChannelAsync(winrt::guid()) }; - VERIFY_ARE_EQUAL(ChannelRequestHelper(channelOperation), E_FAIL); - } - - void UnpackagedSelfContainedTests::ChannelRequestUsingRemoteId() - { - auto channelOperation{ PushNotificationManager::Default().CreateChannelAsync(c_azureRemoteId) }; - VERIFY_ARE_EQUAL(ChannelRequestHelper(channelOperation), E_FAIL); - } - - // Currently failing - https://github.com/microsoft/WindowsAppSDK/issues/2392 - void UnpackagedSelfContainedTests::MultipleChannelClose() - { - auto channelOperation{ PushNotificationManager::Default().CreateChannelAsync(c_azureRemoteId) }; - if (channelOperation.wait_for(c_timeout) != winrt::Windows::Foundation::AsyncStatus::Completed) - { - channelOperation.Cancel(); - VERIFY_FAIL(L"Channel request hit timeout."); - } - - auto result{ channelOperation.GetResults() }; - VERIFY_ARE_EQUAL(result.Status(), PushNotificationChannelStatus::CompletedSuccess); - - result.Channel().Close(); - VERIFY_THROWS_HR(result.Channel().Close(), WPN_E_CHANNEL_CLOSED); - } - - void UnpackagedSelfContainedTests::VerifyRegisterAndUnregister() - { - auto pushNotificationManager{ PushNotificationManager::Default() }; - pushNotificationManager.Register(); - pushNotificationManager.Unregister(); - } - - void UnpackagedSelfContainedTests::VerifyUnregisterFails() - { - auto pushNotificationManager{ PushNotificationManager::Default() }; - pushNotificationManager.Unregister(); - } - - void UnpackagedSelfContainedTests::VerifyUnregisterAllFails() - { - auto pushNotificationManager{ PushNotificationManager::Default() }; - pushNotificationManager.UnregisterAll(); - } - - void UnpackagedSelfContainedTests::VerifyRegisterAndUnregisterAll() - { - auto pushNotificationManager{ PushNotificationManager::Default() }; - pushNotificationManager.Register(); - pushNotificationManager.UnregisterAll(); - } - - void UnpackagedSelfContainedTests::MultipleRegister() - { - auto pushNotificationManager{ PushNotificationManager::Default() }; - pushNotificationManager.Register(); - pushNotificationManager.Register(); - } - - void UnpackagedSelfContainedTests::VerifyMultipleRegisterAndUnregister() - { - PushNotificationManager::Default().Register(); - PushNotificationManager::Default().Unregister(); - PushNotificationManager::Default().Register(); - } - - void UnpackagedSelfContainedTests::VerifyMultipleRegisterAndUnregisterAll() - { - PushNotificationManager::Default().Register(); - PushNotificationManager::Default().UnregisterAll(); - - PushNotificationManager::Default().Register(); - PushNotificationManager::Default().UnregisterAll(); - } - - void UnpackagedSelfContainedTests::VerifyUnregisterTwice() - { - PushNotificationManager::Default().Register(); - PushNotificationManager::Default().Unregister(); - PushNotificationManager::Default().Unregister(); - } - - void UnpackagedSelfContainedTests::VerifyUnregisterAllTwice() - { - PushNotificationManager::Default().Register(); - PushNotificationManager::Default().UnregisterAll(); - PushNotificationManager::Default().UnregisterAll(); - } - - void UnpackagedSelfContainedTests::VerifyUnregisterAndUnregisterAll() - { - PushNotificationManager::Default().Register(); - PushNotificationManager::Default().Unregister(); - PushNotificationManager::Default().UnregisterAll(); - } - - void UnpackagedSelfContainedTests::VerifyForegroundHandlerSucceeds() - { - PushNotificationManager::Default().PushReceived([](const auto&, PushNotificationReceivedEventArgs const& /* args */) {}); - PushNotificationManager::Default().Register(); - } - - void UnpackagedSelfContainedTests::VerifyForegroundHandlerFails() - { - PushNotificationManager::Default().Register(); - PushNotificationManager::Default().PushReceived([](const auto&, PushNotificationReceivedEventArgs const& /* args */) {}); - } -} diff --git a/test/PushNotificationTests/UnpackagedSelfContainedTests.h b/test/PushNotificationTests/UnpackagedSelfContainedTests.h deleted file mode 100644 index c158eba24d..0000000000 --- a/test/PushNotificationTests/UnpackagedSelfContainedTests.h +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See LICENSE in the project root for license information. - -#include "pch.h" -#include - -using namespace WEX::Common; -using namespace WEX::Logging; -using namespace WEX::TestExecution; - -using namespace winrt::Windows::ApplicationModel::Activation; -using namespace winrt::Windows::ApplicationModel::Background; -using namespace winrt::Windows::Foundation; -using namespace winrt::Windows::Foundation::Collections; -using namespace winrt::Windows::Management::Deployment; -using namespace winrt::Windows::Storage; -using namespace winrt::Windows::System; -using namespace winrt::Microsoft::Windows::PushNotifications; - -namespace Test::PushNotifications -{ - class UnpackagedSelfContainedTests - { - private: - HRESULT ChannelRequestHelper(IAsyncOperationWithProgress const& channelOperation); - - public: - BEGIN_TEST_CLASS(UnpackagedSelfContainedTests) - TEST_CLASS_PROPERTY(L"Description", L"Windows App SDK Push Notifications test") - TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") - TEST_CLASS_PROPERTY(L"RunAs:Class", L"RestrictedUser") - END_TEST_CLASS() - - TEST_CLASS_SETUP(ClassInit) - { - ::Test::Bootstrap::Setup(); - return true; - } - - TEST_CLASS_CLEANUP(ClassUninit) - { - ::Test::Bootstrap::Cleanup(); - return true; - } - - TEST_METHOD(ChannelRequestUsingNullRemoteId); - TEST_METHOD(ChannelRequestUsingRemoteId); - TEST_METHOD(MultipleChannelClose); // Currently failing - TEST_METHOD(VerifyRegisterAndUnregister); - TEST_METHOD(VerifyRegisterAndUnregisterAll); - TEST_METHOD(VerifyUnregisterFails); - TEST_METHOD(VerifyUnregisterAllFails); - TEST_METHOD(MultipleRegister); - TEST_METHOD(VerifyMultipleRegisterAndUnregister); - TEST_METHOD(VerifyMultipleRegisterAndUnregisterAll); - TEST_METHOD(VerifyUnregisterTwice); - TEST_METHOD(VerifyUnregisterAllTwice); - TEST_METHOD(VerifyUnregisterAndUnregisterAll); - TEST_METHOD(VerifyForegroundHandlerSucceeds); - TEST_METHOD(VerifyForegroundHandlerFails); - }; -} diff --git a/test/PushNotificationTests/UnpackagedTests.cpp b/test/PushNotificationTests/UnpackagedTests.cpp index 485806b848..e3d50b1538 100644 --- a/test/PushNotificationTests/UnpackagedTests.cpp +++ b/test/PushNotificationTests/UnpackagedTests.cpp @@ -43,13 +43,29 @@ namespace Test::PushNotifications void UnpackagedTests::ChannelRequestUsingNullRemoteId() { - VERIFY_THROWS_HR(PushNotificationManager::Default().CreateChannelAsync(winrt::guid()).get(), E_INVALIDARG); + if (!m_isSelfContained) + { + VERIFY_THROWS_HR(PushNotificationManager::Default().CreateChannelAsync(winrt::guid()).get(), E_INVALIDARG); + } + else + { + auto channelOperation{ PushNotificationManager::Default().CreateChannelAsync(winrt::guid()) }; + VERIFY_ARE_EQUAL(ChannelRequestHelper(channelOperation), E_FAIL); + } } void UnpackagedTests::ChannelRequestUsingRemoteId() { - auto channelOperation{ PushNotificationManager::Default().CreateChannelAsync(c_azureRemoteId) }; - VERIFY_SUCCEEDED(ChannelRequestHelper(channelOperation)); + if (!m_isSelfContained) + { + auto channelOperation{ PushNotificationManager::Default().CreateChannelAsync(c_azureRemoteId) }; + VERIFY_SUCCEEDED(ChannelRequestHelper(channelOperation)); + } + else + { + auto channelOperation{ PushNotificationManager::Default().CreateChannelAsync(c_azureRemoteId) }; + VERIFY_ARE_EQUAL(ChannelRequestHelper(channelOperation), E_FAIL); + } } // Currently failing - https://github.com/microsoft/WindowsAppSDK/issues/2392 @@ -71,42 +87,58 @@ namespace Test::PushNotifications void UnpackagedTests::VerifyRegisterAndUnregister() { - auto pushNotificationManager{ PushNotificationManager::Default() }; - pushNotificationManager.Register(); + PushNotificationManager::Default().Register(); m_registered = true; - pushNotificationManager.Unregister(); + PushNotificationManager::Default().Unregister(); } void UnpackagedTests::VerifyUnregisterFails() { - auto pushNotificationManager{ PushNotificationManager::Default() }; - VERIFY_THROWS_HR(pushNotificationManager.Unregister(), E_UNEXPECTED); + if (!m_isSelfContained) + { + VERIFY_THROWS_HR(PushNotificationManager::Default().Unregister(), E_UNEXPECTED); + } + else + { + PushNotificationManager::Default().Unregister(); + } } void UnpackagedTests::VerifyUnregisterAllFails() { - auto pushNotificationManager{ PushNotificationManager::Default() }; - VERIFY_THROWS_HR(pushNotificationManager.UnregisterAll(), E_UNEXPECTED); + if (!m_isSelfContained) + { + VERIFY_THROWS_HR(PushNotificationManager::Default().UnregisterAll(), E_UNEXPECTED); + } + else + { + PushNotificationManager::Default().UnregisterAll(); + } } void UnpackagedTests::VerifyRegisterAndUnregisterAll() { - auto pushNotificationManager{ PushNotificationManager::Default() }; - pushNotificationManager.Register(); + PushNotificationManager::Default().Register(); m_registered = true; - pushNotificationManager.UnregisterAll(); + PushNotificationManager::Default().UnregisterAll(); m_registered = false; } void UnpackagedTests::MultipleRegister() { - auto pushNotificationManager{ PushNotificationManager::Default() }; - pushNotificationManager.Register(); + PushNotificationManager::Default().Register(); m_registered = true; - VERIFY_THROWS_HR(pushNotificationManager.Register(), HRESULT_FROM_WIN32(ERROR_ALREADY_REGISTERED)); + if (!m_isSelfContained) + { + VERIFY_THROWS_HR(PushNotificationManager::Default().Register(), HRESULT_FROM_WIN32(ERROR_ALREADY_REGISTERED)); + } + else + { + PushNotificationManager::Default().Register(); + } } void UnpackagedTests::VerifyMultipleRegisterAndUnregister() @@ -115,7 +147,15 @@ namespace Test::PushNotifications m_registered = true; PushNotificationManager::Default().Unregister(); - VERIFY_THROWS_HR(PushNotificationManager::Default().Register(), HRESULT_FROM_WIN32(ERROR_ALREADY_REGISTERED)); + + if (!m_isSelfContained) + { + VERIFY_THROWS_HR(PushNotificationManager::Default().Register(), HRESULT_FROM_WIN32(ERROR_ALREADY_REGISTERED)); + } + else + { + PushNotificationManager::Default().Register(); + } } void UnpackagedTests::VerifyMultipleRegisterAndUnregisterAll() @@ -139,7 +179,14 @@ namespace Test::PushNotifications m_registered = true; PushNotificationManager::Default().Unregister(); - VERIFY_THROWS_HR(PushNotificationManager::Default().Unregister(), E_UNEXPECTED); + if (!m_isSelfContained) + { + VERIFY_THROWS_HR(PushNotificationManager::Default().Unregister(), E_UNEXPECTED); + } + else + { + PushNotificationManager::Default().Unregister(); + } } void UnpackagedTests::VerifyUnregisterAllTwice() @@ -150,7 +197,14 @@ namespace Test::PushNotifications PushNotificationManager::Default().UnregisterAll(); m_registered = false; - VERIFY_THROWS_HR(PushNotificationManager::Default().UnregisterAll(), E_UNEXPECTED); + if (!m_isSelfContained) + { + VERIFY_THROWS_HR(PushNotificationManager::Default().UnregisterAll(), E_UNEXPECTED); + } + else + { + PushNotificationManager::Default().UnregisterAll(); + } } void UnpackagedTests::VerifyUnregisterAndUnregisterAll() @@ -175,6 +229,13 @@ namespace Test::PushNotifications PushNotificationManager::Default().Register(); m_registered = true; - VERIFY_THROWS_HR(PushNotificationManager::Default().PushReceived([](const auto&, PushNotificationReceivedEventArgs const& /* args */) {}), HRESULT_FROM_WIN32(ERROR_NOT_FOUND)); + if (!m_isSelfContained) + { + VERIFY_THROWS_HR(PushNotificationManager::Default().PushReceived([](const auto&, PushNotificationReceivedEventArgs const& /* args */) {}), HRESULT_FROM_WIN32(ERROR_NOT_FOUND)); + } + else + { + PushNotificationManager::Default().PushReceived([](const auto&, PushNotificationReceivedEventArgs const& /* args */) {}); + } } } diff --git a/test/PushNotificationTests/UnpackagedTests.h b/test/PushNotificationTests/UnpackagedTests.h index ee45e39a9b..46bd58db17 100644 --- a/test/PushNotificationTests/UnpackagedTests.h +++ b/test/PushNotificationTests/UnpackagedTests.h @@ -25,17 +25,26 @@ namespace Test::PushNotifications HRESULT ChannelRequestHelper(IAsyncOperationWithProgress const& channelOperation); bool m_registered{ false }; + bool m_isSelfContained{ false }; public: BEGIN_TEST_CLASS(UnpackagedTests) TEST_CLASS_PROPERTY(L"Description", L"Windows App SDK Push Notifications test") TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") TEST_CLASS_PROPERTY(L"RunAs:Class", L"RestrictedUser") - END_TEST_CLASS() + TEST_CLASS_PROPERTY(L"IsolationLevel", L"Class") + TEST_CLASS_PROPERTY(L"Data:SelfContained", L"{true, false}") + END_TEST_CLASS() TEST_CLASS_SETUP(ClassInit) { ::Test::Bootstrap::Setup(); - ::WindowsAppRuntime::SelfContained::TestInitialize(::Test::Bootstrap::TP::WindowsAppRuntimeFramework::c_PackageFamilyName); + if (SUCCEEDED(TestData::TryGetValue(L"SelfContained", m_isSelfContained))) + { + if (!m_isSelfContained) + { + ::WindowsAppRuntime::SelfContained::TestInitialize(::Test::Bootstrap::TP::WindowsAppRuntimeFramework::c_PackageFamilyName); + } + } return true; } From c382214b7aebd876f8bc13521e627cf808063431 Mon Sep 17 00:00:00 2001 From: Paul Purifoy Date: Thu, 14 Apr 2022 09:56:46 -0700 Subject: [PATCH 06/16] Used IsSupported flag instead --- test/PushNotificationTests/UnpackagedTests.cpp | 18 +++++++++--------- test/PushNotificationTests/UnpackagedTests.h | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/test/PushNotificationTests/UnpackagedTests.cpp b/test/PushNotificationTests/UnpackagedTests.cpp index e3d50b1538..ac7273c6a9 100644 --- a/test/PushNotificationTests/UnpackagedTests.cpp +++ b/test/PushNotificationTests/UnpackagedTests.cpp @@ -43,7 +43,7 @@ namespace Test::PushNotifications void UnpackagedTests::ChannelRequestUsingNullRemoteId() { - if (!m_isSelfContained) + if (PushNotificationManager::Default().IsSupported()) { VERIFY_THROWS_HR(PushNotificationManager::Default().CreateChannelAsync(winrt::guid()).get(), E_INVALIDARG); } @@ -56,7 +56,7 @@ namespace Test::PushNotifications void UnpackagedTests::ChannelRequestUsingRemoteId() { - if (!m_isSelfContained) + if (PushNotificationManager::Default().IsSupported()) { auto channelOperation{ PushNotificationManager::Default().CreateChannelAsync(c_azureRemoteId) }; VERIFY_SUCCEEDED(ChannelRequestHelper(channelOperation)); @@ -95,7 +95,7 @@ namespace Test::PushNotifications void UnpackagedTests::VerifyUnregisterFails() { - if (!m_isSelfContained) + if (PushNotificationManager::Default().IsSupported()) { VERIFY_THROWS_HR(PushNotificationManager::Default().Unregister(), E_UNEXPECTED); } @@ -107,7 +107,7 @@ namespace Test::PushNotifications void UnpackagedTests::VerifyUnregisterAllFails() { - if (!m_isSelfContained) + if (PushNotificationManager::Default().IsSupported()) { VERIFY_THROWS_HR(PushNotificationManager::Default().UnregisterAll(), E_UNEXPECTED); } @@ -131,7 +131,7 @@ namespace Test::PushNotifications PushNotificationManager::Default().Register(); m_registered = true; - if (!m_isSelfContained) + if (PushNotificationManager::Default().IsSupported()) { VERIFY_THROWS_HR(PushNotificationManager::Default().Register(), HRESULT_FROM_WIN32(ERROR_ALREADY_REGISTERED)); } @@ -148,7 +148,7 @@ namespace Test::PushNotifications PushNotificationManager::Default().Unregister(); - if (!m_isSelfContained) + if (PushNotificationManager::Default().IsSupported()) { VERIFY_THROWS_HR(PushNotificationManager::Default().Register(), HRESULT_FROM_WIN32(ERROR_ALREADY_REGISTERED)); } @@ -179,7 +179,7 @@ namespace Test::PushNotifications m_registered = true; PushNotificationManager::Default().Unregister(); - if (!m_isSelfContained) + if (PushNotificationManager::Default().IsSupported()) { VERIFY_THROWS_HR(PushNotificationManager::Default().Unregister(), E_UNEXPECTED); } @@ -197,7 +197,7 @@ namespace Test::PushNotifications PushNotificationManager::Default().UnregisterAll(); m_registered = false; - if (!m_isSelfContained) + if (PushNotificationManager::Default().IsSupported()) { VERIFY_THROWS_HR(PushNotificationManager::Default().UnregisterAll(), E_UNEXPECTED); } @@ -229,7 +229,7 @@ namespace Test::PushNotifications PushNotificationManager::Default().Register(); m_registered = true; - if (!m_isSelfContained) + if (PushNotificationManager::Default().IsSupported()) { VERIFY_THROWS_HR(PushNotificationManager::Default().PushReceived([](const auto&, PushNotificationReceivedEventArgs const& /* args */) {}), HRESULT_FROM_WIN32(ERROR_NOT_FOUND)); } diff --git a/test/PushNotificationTests/UnpackagedTests.h b/test/PushNotificationTests/UnpackagedTests.h index 46bd58db17..85a62ef37b 100644 --- a/test/PushNotificationTests/UnpackagedTests.h +++ b/test/PushNotificationTests/UnpackagedTests.h @@ -25,7 +25,6 @@ namespace Test::PushNotifications HRESULT ChannelRequestHelper(IAsyncOperationWithProgress const& channelOperation); bool m_registered{ false }; - bool m_isSelfContained{ false }; public: BEGIN_TEST_CLASS(UnpackagedTests) TEST_CLASS_PROPERTY(L"Description", L"Windows App SDK Push Notifications test") @@ -38,9 +37,10 @@ namespace Test::PushNotifications TEST_CLASS_SETUP(ClassInit) { ::Test::Bootstrap::Setup(); - if (SUCCEEDED(TestData::TryGetValue(L"SelfContained", m_isSelfContained))) + bool isSelfContained{ false }; + if (SUCCEEDED(TestData::TryGetValue(L"SelfContained", isSelfContained))) { - if (!m_isSelfContained) + if (!isSelfContained) { ::WindowsAppRuntime::SelfContained::TestInitialize(::Test::Bootstrap::TP::WindowsAppRuntimeFramework::c_PackageFamilyName); } From b833a499e2eec83fbc80fa9ecbed03625099c703 Mon Sep 17 00:00:00 2001 From: Paul Purifoy Date: Thu, 14 Apr 2022 14:19:46 -0700 Subject: [PATCH 07/16] Working on it --- test/PushNotificationTests/Base.cpp | 264 ++++++++++++++++++ test/PushNotificationTests/Base.h | 51 ++++ test/PushNotificationTests/PackagedTests.cpp | 179 ------------ test/PushNotificationTests/PackagedTests.h | 57 ++-- .../PushNotificationTests.vcxproj | 12 +- .../PushNotificationTests.vcxproj.filters | 8 +- .../PushNotificationTests/UnpackagedTests.cpp | 241 ---------------- test/PushNotificationTests/packages.config | 4 +- 8 files changed, 345 insertions(+), 471 deletions(-) create mode 100644 test/PushNotificationTests/Base.cpp create mode 100644 test/PushNotificationTests/Base.h delete mode 100644 test/PushNotificationTests/PackagedTests.cpp delete mode 100644 test/PushNotificationTests/UnpackagedTests.cpp diff --git a/test/PushNotificationTests/Base.cpp b/test/PushNotificationTests/Base.cpp new file mode 100644 index 0000000000..5b38b04243 --- /dev/null +++ b/test/PushNotificationTests/Base.cpp @@ -0,0 +1,264 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +#include "pch.h" + +#include +#include "Base.h" + +using namespace WEX::Common; +using namespace WEX::Logging; +using namespace WEX::TestExecution; + +using namespace winrt::Windows::ApplicationModel::Activation; +using namespace winrt::Windows::ApplicationModel::Background; +using namespace winrt::Windows::Foundation; +using namespace winrt::Windows::Foundation::Collections; +using namespace winrt::Windows::Management::Deployment; +using namespace winrt::Windows::Storage; +using namespace winrt::Windows::System; +using namespace winrt::Microsoft::Windows::PushNotifications; + +void Base::ClassSetup() +{ + ::Test::Bootstrap::Setup(); + bool isSelfContained{ false }; + if (SUCCEEDED(TestData::TryGetValue(L"SelfContained", isSelfContained))) + { + if (!isSelfContained) + { + ::WindowsAppRuntime::SelfContained::TestInitialize(::Test::Bootstrap::TP::WindowsAppRuntimeFramework::c_PackageFamilyName); + } + } +} + +void Base::ClassCleanup() +{ + ::Test::Bootstrap::Cleanup(); +} + +void Base::MethodCleanup() +{ + if (m_registered) + { + PushNotificationManager::Default().UnregisterAll(); + m_registered = false; + } +} + +HRESULT Base::ChannelRequestHelper(IAsyncOperationWithProgress const& channelOperation) +{ + if (channelOperation.wait_for(c_timeout) != winrt::Windows::Foundation::AsyncStatus::Completed) + { + channelOperation.Cancel(); + return HRESULT_FROM_WIN32(ERROR_TIMEOUT); // timed out or failed + } + + auto result{ channelOperation.GetResults() }; + auto status{ result.Status() }; + if (status != PushNotificationChannelStatus::CompletedSuccess) + { + return result.ExtendedError(); // did not produce a channel + } + + result.Channel().Close(); + return S_OK; +} + +void Base::ChannelRequestUsingNullRemoteId() +{ + if (PushNotificationManager::Default().IsSupported()) + { + VERIFY_THROWS_HR(PushNotificationManager::Default().CreateChannelAsync(winrt::guid()).get(), E_INVALIDARG); + } + else + { + auto channelOperation{ PushNotificationManager::Default().CreateChannelAsync(winrt::guid()) }; + VERIFY_ARE_EQUAL(ChannelRequestHelper(channelOperation), E_FAIL); + } +} + +void Base::ChannelRequestUsingRemoteId() +{ + if (PushNotificationManager::Default().IsSupported()) + { + auto channelOperation{ PushNotificationManager::Default().CreateChannelAsync(c_azureRemoteId) }; + VERIFY_SUCCEEDED(ChannelRequestHelper(channelOperation)); + } + else + { + auto channelOperation{ PushNotificationManager::Default().CreateChannelAsync(c_azureRemoteId) }; + VERIFY_ARE_EQUAL(ChannelRequestHelper(channelOperation), E_FAIL); + } +} + +// Currently failing - https://github.com/microsoft/WindowsAppSDK/issues/2392 +void Base::MultipleChannelClose() +{ + auto channelOperation{ PushNotificationManager::Default().CreateChannelAsync(c_azureRemoteId) }; + if (channelOperation.wait_for(c_timeout) != winrt::Windows::Foundation::AsyncStatus::Completed) + { + channelOperation.Cancel(); + VERIFY_FAIL(L"Channel request hit timeout."); + } + + auto result{ channelOperation.GetResults() }; + VERIFY_ARE_EQUAL(result.Status(), PushNotificationChannelStatus::CompletedSuccess); + + result.Channel().Close(); + VERIFY_THROWS_HR(result.Channel().Close(), WPN_E_CHANNEL_CLOSED); +} + +void Base::VerifyRegisterAndUnregister() +{ + PushNotificationManager::Default().Register(); + m_registered = true; + + PushNotificationManager::Default().Unregister(); +} + +void Base::VerifyUnregisterFails() +{ + if (PushNotificationManager::Default().IsSupported()) + { + VERIFY_THROWS_HR(PushNotificationManager::Default().Unregister(), E_UNEXPECTED); + } + else + { + PushNotificationManager::Default().Unregister(); + } +} + +void Base::VerifyUnregisterAllFails() +{ + if (PushNotificationManager::Default().IsSupported()) + { + VERIFY_THROWS_HR(PushNotificationManager::Default().UnregisterAll(), E_UNEXPECTED); + } + else + { + PushNotificationManager::Default().UnregisterAll(); + } +} + +void Base::VerifyRegisterAndUnregisterAll() +{ + PushNotificationManager::Default().Register(); + m_registered = true; + + PushNotificationManager::Default().UnregisterAll(); + m_registered = false; +} + +void Base::MultipleRegister() +{ + PushNotificationManager::Default().Register(); + m_registered = true; + + if (PushNotificationManager::Default().IsSupported()) + { + VERIFY_THROWS_HR(PushNotificationManager::Default().Register(), HRESULT_FROM_WIN32(ERROR_ALREADY_REGISTERED)); + } + else + { + PushNotificationManager::Default().Register(); + } +} + +void Base::VerifyMultipleRegisterAndUnregister() +{ + PushNotificationManager::Default().Register(); + m_registered = true; + + PushNotificationManager::Default().Unregister(); + + if (PushNotificationManager::Default().IsSupported()) + { + VERIFY_THROWS_HR(PushNotificationManager::Default().Register(), HRESULT_FROM_WIN32(ERROR_ALREADY_REGISTERED)); + } + else + { + PushNotificationManager::Default().Register(); + } +} + +void Base::VerifyMultipleRegisterAndUnregisterAll() +{ + PushNotificationManager::Default().Register(); + m_registered = true; + + PushNotificationManager::Default().UnregisterAll(); + m_registered = false; + + PushNotificationManager::Default().Register(); + m_registered = true; + + PushNotificationManager::Default().UnregisterAll(); + m_registered = false; +} + +void Base::VerifyUnregisterTwice() +{ + PushNotificationManager::Default().Register(); + m_registered = true; + + PushNotificationManager::Default().Unregister(); + if (PushNotificationManager::Default().IsSupported()) + { + VERIFY_THROWS_HR(PushNotificationManager::Default().Unregister(), E_UNEXPECTED); + } + else + { + PushNotificationManager::Default().Unregister(); + } +} + +void Base::VerifyUnregisterAllTwice() +{ + PushNotificationManager::Default().Register(); + m_registered = true; + + PushNotificationManager::Default().UnregisterAll(); + m_registered = false; + + if (PushNotificationManager::Default().IsSupported()) + { + VERIFY_THROWS_HR(PushNotificationManager::Default().UnregisterAll(), E_UNEXPECTED); + } + else + { + PushNotificationManager::Default().UnregisterAll(); + } +} + +void Base::VerifyUnregisterAndUnregisterAll() +{ + PushNotificationManager::Default().Register(); + m_registered = true; + + PushNotificationManager::Default().Unregister(); + PushNotificationManager::Default().UnregisterAll(); + m_registered = false; +} + +void Base::VerifyForegroundHandlerSucceeds() +{ + PushNotificationManager::Default().PushReceived([](const auto&, PushNotificationReceivedEventArgs const& /* args */) {}); + PushNotificationManager::Default().Register(); + m_registered = true; +} + +void Base::VerifyForegroundHandlerFails() +{ + PushNotificationManager::Default().Register(); + m_registered = true; + + if (PushNotificationManager::Default().IsSupported()) + { + VERIFY_THROWS_HR(PushNotificationManager::Default().PushReceived([](const auto&, PushNotificationReceivedEventArgs const& /* args */) {}), HRESULT_FROM_WIN32(ERROR_NOT_FOUND)); + } + else + { + PushNotificationManager::Default().PushReceived([](const auto&, PushNotificationReceivedEventArgs const& /* args */) {}); + } +} diff --git a/test/PushNotificationTests/Base.h b/test/PushNotificationTests/Base.h new file mode 100644 index 0000000000..c0941fc499 --- /dev/null +++ b/test/PushNotificationTests/Base.h @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +#include "pch.h" +#include + +using namespace WEX::Common; +using namespace WEX::Logging; +using namespace WEX::TestExecution; + +using namespace winrt::Windows::ApplicationModel::Activation; +using namespace winrt::Windows::ApplicationModel::Background; +using namespace winrt::Windows::Foundation; +using namespace winrt::Windows::Foundation::Collections; +using namespace winrt::Windows::Management::Deployment; +using namespace winrt::Windows::Storage; +using namespace winrt::Windows::System; +using namespace winrt::Microsoft::Windows::PushNotifications; + +class Base +{ + public: + Base() = default; + + // Unit test environment functions + void ClassSetup(); + void ClassCleanup(); + void MethodCleanup(); + + // Base unit tests + void ChannelRequestUsingNullRemoteId(); + void ChannelRequestUsingRemoteId(); + void MultipleChannelClose(); // Currently failing + void VerifyRegisterAndUnregister(); + void VerifyRegisterAndUnregisterAll(); + void VerifyUnregisterFails(); + void VerifyUnregisterAllFails(); + void MultipleRegister(); + void VerifyMultipleRegisterAndUnregister(); + void VerifyMultipleRegisterAndUnregisterAll(); + void VerifyUnregisterTwice(); + void VerifyUnregisterAllTwice(); + void VerifyUnregisterAndUnregisterAll(); + void VerifyForegroundHandlerSucceeds(); + void VerifyForegroundHandlerFails(); + + private: + HRESULT ChannelRequestHelper(IAsyncOperationWithProgress const& channelOperation); + + bool m_registered{ false }; +}; diff --git a/test/PushNotificationTests/PackagedTests.cpp b/test/PushNotificationTests/PackagedTests.cpp deleted file mode 100644 index 9e3dcefa26..0000000000 --- a/test/PushNotificationTests/PackagedTests.cpp +++ /dev/null @@ -1,179 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See LICENSE in the project root for license information. - -#include "pch.h" - -#include -#include "PackagedTests.h" - -using namespace WEX::Common; -using namespace WEX::Logging; -using namespace WEX::TestExecution; - -using namespace winrt::Windows::ApplicationModel::Activation; -using namespace winrt::Windows::ApplicationModel::Background; -using namespace winrt::Windows::Foundation; -using namespace winrt::Windows::Foundation::Collections; -using namespace winrt::Windows::Management::Deployment; -using namespace winrt::Windows::Storage; -using namespace winrt::Windows::System; -using namespace winrt::Microsoft::Windows::PushNotifications; - - -namespace Test::PushNotifications -{ - HRESULT PackagedTests::ChannelRequestHelper(IAsyncOperationWithProgress const& channelOperation) - { - if (channelOperation.wait_for(c_timeout) != winrt::Windows::Foundation::AsyncStatus::Completed) - { - channelOperation.Cancel(); - return HRESULT_FROM_WIN32(ERROR_TIMEOUT); // timed out or failed - } - - auto result{ channelOperation.GetResults() }; - auto status{ result.Status() }; - if (status != PushNotificationChannelStatus::CompletedSuccess) - { - return result.ExtendedError(); // did not produce a channel - } - - result.Channel().Close(); - return S_OK; - } - - void PackagedTests::ChannelRequestUsingNullRemoteId() - { - VERIFY_THROWS_HR(PushNotificationManager::Default().CreateChannelAsync(winrt::guid()).get(), E_INVALIDARG); - } - - void PackagedTests::ChannelRequestUsingRemoteId() - { - auto channelOperation{ PushNotificationManager::Default().CreateChannelAsync(c_azureRemoteId) }; - VERIFY_SUCCEEDED(ChannelRequestHelper(channelOperation)); - } - - // Currently failing - https://github.com/microsoft/WindowsAppSDK/issues/2392 - void PackagedTests::MultipleChannelClose() - { - auto channelOperation{ PushNotificationManager::Default().CreateChannelAsync(c_azureRemoteId) }; - if (channelOperation.wait_for(c_timeout) != winrt::Windows::Foundation::AsyncStatus::Completed) - { - channelOperation.Cancel(); - VERIFY_FAIL(L"Channel request hit timeout."); - } - - auto result{ channelOperation.GetResults() }; - VERIFY_ARE_EQUAL(result.Status(), PushNotificationChannelStatus::CompletedSuccess); - - result.Channel().Close(); - VERIFY_THROWS_HR(result.Channel().Close(), WPN_E_CHANNEL_CLOSED); - } - - void PackagedTests::VerifyRegisterAndUnregister() - { - auto pushNotificationManager{ PushNotificationManager::Default() }; - pushNotificationManager.Register(); - m_registered = true; - pushNotificationManager.Unregister(); - } - - void PackagedTests::VerifyUnregisterFails() - { - auto pushNotificationManager{ PushNotificationManager::Default() }; - VERIFY_THROWS_HR(pushNotificationManager.Unregister(), E_UNEXPECTED); - } - - void PackagedTests::VerifyUnregisterAllFails() - { - auto pushNotificationManager{ PushNotificationManager::Default() }; - VERIFY_THROWS_HR(pushNotificationManager.UnregisterAll(), E_UNEXPECTED); - } - - void PackagedTests::VerifyRegisterAndUnregisterAll() - { - auto pushNotificationManager{ PushNotificationManager::Default() }; - pushNotificationManager.Register(); - m_registered = true; - - pushNotificationManager.UnregisterAll(); - m_registered = false; - } - - void PackagedTests::MultipleRegister() - { - auto pushNotificationManager{ PushNotificationManager::Default() }; - pushNotificationManager.Register(); - m_registered = true; - - VERIFY_THROWS_HR(pushNotificationManager.Register(), HRESULT_FROM_WIN32(ERROR_ALREADY_REGISTERED)); - } - - void PackagedTests::VerifyMultipleRegisterAndUnregister() - { - PushNotificationManager::Default().Register(); - m_registered = true; - - PushNotificationManager::Default().Unregister(); - VERIFY_THROWS_HR(PushNotificationManager::Default().Register(), HRESULT_FROM_WIN32(ERROR_ALREADY_REGISTERED)); - } - - void PackagedTests::VerifyMultipleRegisterAndUnregisterAll() - { - PushNotificationManager::Default().Register(); - m_registered = true; - - PushNotificationManager::Default().UnregisterAll(); - m_registered = false; - - PushNotificationManager::Default().Register(); - m_registered = true; - - PushNotificationManager::Default().UnregisterAll(); - m_registered = false; - } - - void PackagedTests::VerifyUnregisterTwice() - { - PushNotificationManager::Default().Register(); - m_registered = true; - - PushNotificationManager::Default().Unregister(); - VERIFY_THROWS_HR(PushNotificationManager::Default().Unregister(), E_UNEXPECTED); - } - - void PackagedTests::VerifyUnregisterAllTwice() - { - PushNotificationManager::Default().Register(); - m_registered = true; - - PushNotificationManager::Default().UnregisterAll(); - m_registered = false; - - VERIFY_THROWS_HR(PushNotificationManager::Default().UnregisterAll(), E_UNEXPECTED); - } - - void PackagedTests::VerifyUnregisterAndUnregisterAll() - { - PushNotificationManager::Default().Register(); - m_registered = true; - - PushNotificationManager::Default().Unregister(); - PushNotificationManager::Default().UnregisterAll(); - m_registered = false; - } - - void PackagedTests::VerifyForegroundHandlerSucceeds() - { - PushNotificationManager::Default().PushReceived([](const auto&, PushNotificationReceivedEventArgs const& /* args */) {}); - PushNotificationManager::Default().Register(); - m_registered = true; - } - - void PackagedTests::VerifyForegroundHandlerFails() - { - PushNotificationManager::Default().Register(); - m_registered = true; - - VERIFY_THROWS_HR(PushNotificationManager::Default().PushReceived([](const auto&, PushNotificationReceivedEventArgs const& /* args */) {}), HRESULT_FROM_WIN32(ERROR_NOT_FOUND)); - } -} diff --git a/test/PushNotificationTests/PackagedTests.h b/test/PushNotificationTests/PackagedTests.h index 3f27e13134..b11ed555cc 100644 --- a/test/PushNotificationTests/PackagedTests.h +++ b/test/PushNotificationTests/PackagedTests.h @@ -3,6 +3,7 @@ #include "pch.h" #include +#include "Base.h" using namespace WEX::Common; using namespace WEX::Logging; @@ -17,42 +18,31 @@ using namespace winrt::Windows::Storage; using namespace winrt::Windows::System; using namespace winrt::Microsoft::Windows::PushNotifications; -namespace Test::PushNotifications +class PackagedTests : public WEX::TestClass { - class PackagedTests - { private: - HRESULT ChannelRequestHelper(IAsyncOperationWithProgress const& channelOperation); + Base m_base{}; - bool m_registered{ false }; public: BEGIN_TEST_CLASS(PackagedTests) TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") TEST_CLASS_PROPERTY(L"RunFixtureAs:Class", L"RestrictedUser") TEST_CLASS_PROPERTY(L"IsolationLevel", L"Class") + TEST_CLASS_PROPERTY(L"Data:SelfContained", L"{true, false}") TEST_CLASS_PROPERTY(L"RunAs", L"UAP") TEST_CLASS_PROPERTY(L"UAP:Host", L"PackagedCWA") TEST_CLASS_PROPERTY(L"UAP:AppxManifest", L"PushNotifications-AppxManifest.xml") - TEST_CLASS_PROPERTY(L"Data:SelfContained", L"{true, false}") END_TEST_CLASS() TEST_CLASS_SETUP(ClassInit) { - ::Test::Bootstrap::Setup(); - bool isSelfContained{ false }; - if (SUCCEEDED(TestData::TryGetValue(L"SelfContained", isSelfContained))) - { - if (!isSelfContained) - { - ::WindowsAppRuntime::SelfContained::TestInitialize(::Test::Bootstrap::TP::WindowsAppRuntimeFramework::c_PackageFamilyName); - } - } + m_base.ClassSetup(); return true; } TEST_CLASS_CLEANUP(ClassUninit) { - ::Test::Bootstrap::Cleanup(); + m_base.ClassCleanup(); return true; } @@ -63,29 +53,18 @@ namespace Test::PushNotifications TEST_METHOD_CLEANUP(MethodUninit) { - if (m_registered) - { - PushNotificationManager::Default().UnregisterAll(); - m_registered = false; - } - + m_base.MethodCleanup(); return true; } - TEST_METHOD(ChannelRequestUsingNullRemoteId); - TEST_METHOD(ChannelRequestUsingRemoteId); - TEST_METHOD(MultipleChannelClose); // Currently failing - TEST_METHOD(VerifyRegisterAndUnregister); - TEST_METHOD(VerifyRegisterAndUnregisterAll); - TEST_METHOD(VerifyUnregisterFails); - TEST_METHOD(VerifyUnregisterAllFails); - TEST_METHOD(MultipleRegister); - TEST_METHOD(VerifyMultipleRegisterAndUnregister); - TEST_METHOD(VerifyMultipleRegisterAndUnregisterAll); - TEST_METHOD(VerifyUnregisterTwice); - TEST_METHOD(VerifyUnregisterAllTwice); - TEST_METHOD(VerifyUnregisterAndUnregisterAll); - TEST_METHOD(VerifyForegroundHandlerSucceeds); - TEST_METHOD(VerifyForegroundHandlerFails); - }; -} + TEST_METHOD(ChannelRequestUsingNullRemoteId) + { + m_base.ChannelRequestUsingNullRemoteId(); + } + + TEST_METHOD(ChannelRequestUsingNullRemoteId2) + { + VERIFY_IS_TRUE(true); + } +}; + diff --git a/test/PushNotificationTests/PushNotificationTests.vcxproj b/test/PushNotificationTests/PushNotificationTests.vcxproj index ae5a91cea9..59193db74c 100644 --- a/test/PushNotificationTests/PushNotificationTests.vcxproj +++ b/test/PushNotificationTests/PushNotificationTests.vcxproj @@ -1,6 +1,6 @@ - + Debug @@ -172,13 +172,13 @@ + - - + Create Create @@ -212,7 +212,7 @@ - + @@ -224,7 +224,7 @@ - - + + \ No newline at end of file diff --git a/test/PushNotificationTests/PushNotificationTests.vcxproj.filters b/test/PushNotificationTests/PushNotificationTests.vcxproj.filters index 388552939c..27e29292b7 100644 --- a/test/PushNotificationTests/PushNotificationTests.vcxproj.filters +++ b/test/PushNotificationTests/PushNotificationTests.vcxproj.filters @@ -27,15 +27,15 @@ Header Files + + Header Files + Source Files - - Source Files - - + Source Files diff --git a/test/PushNotificationTests/UnpackagedTests.cpp b/test/PushNotificationTests/UnpackagedTests.cpp deleted file mode 100644 index ac7273c6a9..0000000000 --- a/test/PushNotificationTests/UnpackagedTests.cpp +++ /dev/null @@ -1,241 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See LICENSE in the project root for license information. - -#include "pch.h" - -#include -#include "UnpackagedTests.h" - -using namespace WEX::Common; -using namespace WEX::Logging; -using namespace WEX::TestExecution; - -using namespace winrt::Windows::ApplicationModel::Activation; -using namespace winrt::Windows::ApplicationModel::Background; -using namespace winrt::Windows::Foundation; -using namespace winrt::Windows::Foundation::Collections; -using namespace winrt::Windows::Management::Deployment; -using namespace winrt::Windows::Storage; -using namespace winrt::Windows::System; -using namespace winrt::Microsoft::Windows::PushNotifications; - - -namespace Test::PushNotifications -{ - HRESULT UnpackagedTests::ChannelRequestHelper(IAsyncOperationWithProgress const& channelOperation) - { - if (channelOperation.wait_for(c_timeout) != winrt::Windows::Foundation::AsyncStatus::Completed) - { - channelOperation.Cancel(); - return HRESULT_FROM_WIN32(ERROR_TIMEOUT); // timed out or failed - } - - auto result{ channelOperation.GetResults() }; - auto status{ result.Status() }; - if (status != PushNotificationChannelStatus::CompletedSuccess) - { - return result.ExtendedError(); // did not produce a channel - } - - result.Channel().Close(); - return S_OK; - } - - void UnpackagedTests::ChannelRequestUsingNullRemoteId() - { - if (PushNotificationManager::Default().IsSupported()) - { - VERIFY_THROWS_HR(PushNotificationManager::Default().CreateChannelAsync(winrt::guid()).get(), E_INVALIDARG); - } - else - { - auto channelOperation{ PushNotificationManager::Default().CreateChannelAsync(winrt::guid()) }; - VERIFY_ARE_EQUAL(ChannelRequestHelper(channelOperation), E_FAIL); - } - } - - void UnpackagedTests::ChannelRequestUsingRemoteId() - { - if (PushNotificationManager::Default().IsSupported()) - { - auto channelOperation{ PushNotificationManager::Default().CreateChannelAsync(c_azureRemoteId) }; - VERIFY_SUCCEEDED(ChannelRequestHelper(channelOperation)); - } - else - { - auto channelOperation{ PushNotificationManager::Default().CreateChannelAsync(c_azureRemoteId) }; - VERIFY_ARE_EQUAL(ChannelRequestHelper(channelOperation), E_FAIL); - } - } - - // Currently failing - https://github.com/microsoft/WindowsAppSDK/issues/2392 - void UnpackagedTests::MultipleChannelClose() - { - auto channelOperation{ PushNotificationManager::Default().CreateChannelAsync(c_azureRemoteId) }; - if (channelOperation.wait_for(c_timeout) != winrt::Windows::Foundation::AsyncStatus::Completed) - { - channelOperation.Cancel(); - VERIFY_FAIL(L"Channel request hit timeout."); - } - - auto result{ channelOperation.GetResults() }; - VERIFY_ARE_EQUAL(result.Status(), PushNotificationChannelStatus::CompletedSuccess); - - result.Channel().Close(); - VERIFY_THROWS_HR(result.Channel().Close(), WPN_E_CHANNEL_CLOSED); - } - - void UnpackagedTests::VerifyRegisterAndUnregister() - { - PushNotificationManager::Default().Register(); - m_registered = true; - - PushNotificationManager::Default().Unregister(); - } - - void UnpackagedTests::VerifyUnregisterFails() - { - if (PushNotificationManager::Default().IsSupported()) - { - VERIFY_THROWS_HR(PushNotificationManager::Default().Unregister(), E_UNEXPECTED); - } - else - { - PushNotificationManager::Default().Unregister(); - } - } - - void UnpackagedTests::VerifyUnregisterAllFails() - { - if (PushNotificationManager::Default().IsSupported()) - { - VERIFY_THROWS_HR(PushNotificationManager::Default().UnregisterAll(), E_UNEXPECTED); - } - else - { - PushNotificationManager::Default().UnregisterAll(); - } - } - - void UnpackagedTests::VerifyRegisterAndUnregisterAll() - { - PushNotificationManager::Default().Register(); - m_registered = true; - - PushNotificationManager::Default().UnregisterAll(); - m_registered = false; - } - - void UnpackagedTests::MultipleRegister() - { - PushNotificationManager::Default().Register(); - m_registered = true; - - if (PushNotificationManager::Default().IsSupported()) - { - VERIFY_THROWS_HR(PushNotificationManager::Default().Register(), HRESULT_FROM_WIN32(ERROR_ALREADY_REGISTERED)); - } - else - { - PushNotificationManager::Default().Register(); - } - } - - void UnpackagedTests::VerifyMultipleRegisterAndUnregister() - { - PushNotificationManager::Default().Register(); - m_registered = true; - - PushNotificationManager::Default().Unregister(); - - if (PushNotificationManager::Default().IsSupported()) - { - VERIFY_THROWS_HR(PushNotificationManager::Default().Register(), HRESULT_FROM_WIN32(ERROR_ALREADY_REGISTERED)); - } - else - { - PushNotificationManager::Default().Register(); - } - } - - void UnpackagedTests::VerifyMultipleRegisterAndUnregisterAll() - { - PushNotificationManager::Default().Register(); - m_registered = true; - - PushNotificationManager::Default().UnregisterAll(); - m_registered = false; - - PushNotificationManager::Default().Register(); - m_registered = true; - - PushNotificationManager::Default().UnregisterAll(); - m_registered = false; - } - - void UnpackagedTests::VerifyUnregisterTwice() - { - PushNotificationManager::Default().Register(); - m_registered = true; - - PushNotificationManager::Default().Unregister(); - if (PushNotificationManager::Default().IsSupported()) - { - VERIFY_THROWS_HR(PushNotificationManager::Default().Unregister(), E_UNEXPECTED); - } - else - { - PushNotificationManager::Default().Unregister(); - } - } - - void UnpackagedTests::VerifyUnregisterAllTwice() - { - PushNotificationManager::Default().Register(); - m_registered = true; - - PushNotificationManager::Default().UnregisterAll(); - m_registered = false; - - if (PushNotificationManager::Default().IsSupported()) - { - VERIFY_THROWS_HR(PushNotificationManager::Default().UnregisterAll(), E_UNEXPECTED); - } - else - { - PushNotificationManager::Default().UnregisterAll(); - } - } - - void UnpackagedTests::VerifyUnregisterAndUnregisterAll() - { - PushNotificationManager::Default().Register(); - m_registered = true; - - PushNotificationManager::Default().Unregister(); - PushNotificationManager::Default().UnregisterAll(); - m_registered = false; - } - - void UnpackagedTests::VerifyForegroundHandlerSucceeds() - { - PushNotificationManager::Default().PushReceived([](const auto&, PushNotificationReceivedEventArgs const& /* args */) {}); - PushNotificationManager::Default().Register(); - m_registered = true; - } - - void UnpackagedTests::VerifyForegroundHandlerFails() - { - PushNotificationManager::Default().Register(); - m_registered = true; - - if (PushNotificationManager::Default().IsSupported()) - { - VERIFY_THROWS_HR(PushNotificationManager::Default().PushReceived([](const auto&, PushNotificationReceivedEventArgs const& /* args */) {}), HRESULT_FROM_WIN32(ERROR_NOT_FOUND)); - } - else - { - PushNotificationManager::Default().PushReceived([](const auto&, PushNotificationReceivedEventArgs const& /* args */) {}); - } - } -} diff --git a/test/PushNotificationTests/packages.config b/test/PushNotificationTests/packages.config index 71b99361d6..6b0a29d23a 100644 --- a/test/PushNotificationTests/packages.config +++ b/test/PushNotificationTests/packages.config @@ -1,6 +1,6 @@  - + - + \ No newline at end of file From e82b459b00107e194da5e33ce4b001fd3be5862a Mon Sep 17 00:00:00 2001 From: Paul Purifoy Date: Fri, 15 Apr 2022 13:10:22 -0700 Subject: [PATCH 08/16] BaseTestSuite working --- .../{Base.cpp => BaseTestSuite.cpp} | 40 +++--- .../{Base.h => BaseTestSuite.h} | 4 +- test/PushNotificationTests/PackagedTests.cpp | 80 ++++++++++++ test/PushNotificationTests/PackagedTests.h | 108 ++++++++-------- .../PushNotificationTests.vcxproj | 6 +- .../PushNotificationTests.vcxproj.filters | 10 +- .../PushNotificationTests/UnpackagedTests.cpp | 80 ++++++++++++ test/PushNotificationTests/UnpackagedTests.h | 119 +++++++----------- 8 files changed, 288 insertions(+), 159 deletions(-) rename test/PushNotificationTests/{Base.cpp => BaseTestSuite.cpp} (86%) rename test/PushNotificationTests/{Base.h => BaseTestSuite.h} (97%) create mode 100644 test/PushNotificationTests/PackagedTests.cpp create mode 100644 test/PushNotificationTests/UnpackagedTests.cpp diff --git a/test/PushNotificationTests/Base.cpp b/test/PushNotificationTests/BaseTestSuite.cpp similarity index 86% rename from test/PushNotificationTests/Base.cpp rename to test/PushNotificationTests/BaseTestSuite.cpp index 5b38b04243..eae225aee7 100644 --- a/test/PushNotificationTests/Base.cpp +++ b/test/PushNotificationTests/BaseTestSuite.cpp @@ -4,7 +4,7 @@ #include "pch.h" #include -#include "Base.h" +#include "BaseTestSuite.h" using namespace WEX::Common; using namespace WEX::Logging; @@ -19,7 +19,7 @@ using namespace winrt::Windows::Storage; using namespace winrt::Windows::System; using namespace winrt::Microsoft::Windows::PushNotifications; -void Base::ClassSetup() +void BaseTestSuite::ClassSetup() { ::Test::Bootstrap::Setup(); bool isSelfContained{ false }; @@ -32,12 +32,12 @@ void Base::ClassSetup() } } -void Base::ClassCleanup() +void BaseTestSuite::ClassCleanup() { ::Test::Bootstrap::Cleanup(); } -void Base::MethodCleanup() +void BaseTestSuite::MethodCleanup() { if (m_registered) { @@ -46,7 +46,7 @@ void Base::MethodCleanup() } } -HRESULT Base::ChannelRequestHelper(IAsyncOperationWithProgress const& channelOperation) +HRESULT BaseTestSuite::ChannelRequestHelper(IAsyncOperationWithProgress const& channelOperation) { if (channelOperation.wait_for(c_timeout) != winrt::Windows::Foundation::AsyncStatus::Completed) { @@ -65,7 +65,7 @@ HRESULT Base::ChannelRequestHelper(IAsyncOperationWithProgress -#include "Base.h" +#include "BaseTestSuite.h" using namespace WEX::Common; using namespace WEX::Logging; using namespace WEX::TestExecution; -using namespace winrt::Windows::ApplicationModel::Activation; -using namespace winrt::Windows::ApplicationModel::Background; -using namespace winrt::Windows::Foundation; -using namespace winrt::Windows::Foundation::Collections; -using namespace winrt::Windows::Management::Deployment; -using namespace winrt::Windows::Storage; -using namespace winrt::Windows::System; -using namespace winrt::Microsoft::Windows::PushNotifications; - -class PackagedTests : public WEX::TestClass +class PackagedTests : BaseTestSuite { - private: - Base m_base{}; - - public: - BEGIN_TEST_CLASS(PackagedTests) - TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") - TEST_CLASS_PROPERTY(L"RunFixtureAs:Class", L"RestrictedUser") - TEST_CLASS_PROPERTY(L"IsolationLevel", L"Class") - TEST_CLASS_PROPERTY(L"Data:SelfContained", L"{true, false}") - TEST_CLASS_PROPERTY(L"RunAs", L"UAP") - TEST_CLASS_PROPERTY(L"UAP:Host", L"PackagedCWA") - TEST_CLASS_PROPERTY(L"UAP:AppxManifest", L"PushNotifications-AppxManifest.xml") - END_TEST_CLASS() - - TEST_CLASS_SETUP(ClassInit) - { - m_base.ClassSetup(); - return true; - } - - TEST_CLASS_CLEANUP(ClassUninit) - { - m_base.ClassCleanup(); - return true; - } - - TEST_METHOD_SETUP(MethodInit) - { - return true; - } - - TEST_METHOD_CLEANUP(MethodUninit) - { - m_base.MethodCleanup(); - return true; - } - - TEST_METHOD(ChannelRequestUsingNullRemoteId) - { - m_base.ChannelRequestUsingNullRemoteId(); - } - - TEST_METHOD(ChannelRequestUsingNullRemoteId2) - { - VERIFY_IS_TRUE(true); - } + BEGIN_TEST_CLASS(PackagedTests) + TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") + TEST_CLASS_PROPERTY(L"RunFixtureAs:Class", L"RestrictedUser") + TEST_CLASS_PROPERTY(L"IsolationLevel", L"Class") + TEST_CLASS_PROPERTY(L"Data:SelfContained", L"{true, false}") + TEST_CLASS_PROPERTY(L"RunAs", L"UAP") + TEST_CLASS_PROPERTY(L"UAP:Host", L"PackagedCWA") + TEST_CLASS_PROPERTY(L"UAP:AppxManifest", L"PushNotifications-AppxManifest.xml") + END_TEST_CLASS() + + TEST_CLASS_SETUP(ClassInit) + { + BaseTestSuite::ClassSetup(); + return true; + } + + TEST_CLASS_CLEANUP(ClassUninit) + { + BaseTestSuite::ClassCleanup(); + return true; + } + + TEST_METHOD_SETUP(MethodInit) + { + return true; + } + + TEST_METHOD_CLEANUP(MethodUninit) + { + BaseTestSuite::MethodCleanup(); + return true; + } + + TEST_METHOD(ChannelRequestUsingNullRemoteId); + TEST_METHOD(ChannelRequestUsingRemoteId); + TEST_METHOD(MultipleChannelClose); // Currently failing + TEST_METHOD(VerifyRegisterAndUnregister); + TEST_METHOD(VerifyRegisterAndUnregisterAll); + TEST_METHOD(VerifyUnregisterFails); + TEST_METHOD(VerifyUnregisterAllFails); + TEST_METHOD(MultipleRegister); + TEST_METHOD(VerifyMultipleRegisterAndUnregister); + TEST_METHOD(VerifyMultipleRegisterAndUnregisterAll); + TEST_METHOD(VerifyUnregisterTwice); + TEST_METHOD(VerifyUnregisterAllTwice); + TEST_METHOD(VerifyUnregisterAndUnregisterAll); + TEST_METHOD(VerifyForegroundHandlerSucceeds); + TEST_METHOD(VerifyForegroundHandlerFails); }; diff --git a/test/PushNotificationTests/PushNotificationTests.vcxproj b/test/PushNotificationTests/PushNotificationTests.vcxproj index 59193db74c..21d7a0701c 100644 --- a/test/PushNotificationTests/PushNotificationTests.vcxproj +++ b/test/PushNotificationTests/PushNotificationTests.vcxproj @@ -172,19 +172,21 @@ - + - + + Create Create Create Create + diff --git a/test/PushNotificationTests/PushNotificationTests.vcxproj.filters b/test/PushNotificationTests/PushNotificationTests.vcxproj.filters index 27e29292b7..89be57a422 100644 --- a/test/PushNotificationTests/PushNotificationTests.vcxproj.filters +++ b/test/PushNotificationTests/PushNotificationTests.vcxproj.filters @@ -27,7 +27,7 @@ Header Files - + Header Files @@ -35,7 +35,13 @@ Source Files - + + Source Files + + + Source Files + + Source Files diff --git a/test/PushNotificationTests/UnpackagedTests.cpp b/test/PushNotificationTests/UnpackagedTests.cpp new file mode 100644 index 0000000000..dd8bfcbac0 --- /dev/null +++ b/test/PushNotificationTests/UnpackagedTests.cpp @@ -0,0 +1,80 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. +#include "pch.h" +#include "UnpackagedTests.h" + +void UnpackagedTests::ChannelRequestUsingNullRemoteId() +{ + BaseTestSuite::ChannelRequestUsingNullRemoteId(); +} + +void UnpackagedTests::ChannelRequestUsingRemoteId() +{ + BaseTestSuite::ChannelRequestUsingRemoteId(); +} + +// Currently failing - https://github.com/microsoft/WindowsAppSDK/issues/2392 +void UnpackagedTests::MultipleChannelClose() +{ + BaseTestSuite::MultipleChannelClose(); +} + +void UnpackagedTests::VerifyRegisterAndUnregister() +{ + BaseTestSuite::VerifyRegisterAndUnregister(); +} + +void UnpackagedTests::VerifyUnregisterFails() +{ + BaseTestSuite::VerifyUnregisterFails(); +} + +void UnpackagedTests::VerifyUnregisterAllFails() +{ + BaseTestSuite::VerifyUnregisterAllFails(); +} + +void UnpackagedTests::VerifyRegisterAndUnregisterAll() +{ + BaseTestSuite::VerifyRegisterAndUnregisterAll(); +} + +void UnpackagedTests::MultipleRegister() +{ + BaseTestSuite::MultipleRegister(); +} + +void UnpackagedTests::VerifyMultipleRegisterAndUnregister() +{ + BaseTestSuite::VerifyMultipleRegisterAndUnregister(); +} + +void UnpackagedTests::VerifyMultipleRegisterAndUnregisterAll() +{ + BaseTestSuite::VerifyMultipleRegisterAndUnregisterAll(); +} + +void UnpackagedTests::VerifyUnregisterTwice() +{ + BaseTestSuite::VerifyUnregisterTwice(); +} + +void UnpackagedTests::VerifyUnregisterAllTwice() +{ + BaseTestSuite::VerifyUnregisterAllTwice(); +} + +void UnpackagedTests::VerifyUnregisterAndUnregisterAll() +{ + BaseTestSuite::VerifyUnregisterAndUnregisterAll(); +} + +void UnpackagedTests::VerifyForegroundHandlerSucceeds() +{ + BaseTestSuite::VerifyForegroundHandlerSucceeds(); +} + +void UnpackagedTests::VerifyForegroundHandlerFails() +{ + BaseTestSuite::VerifyForegroundHandlerFails(); +} diff --git a/test/PushNotificationTests/UnpackagedTests.h b/test/PushNotificationTests/UnpackagedTests.h index 85a62ef37b..a6288a5207 100644 --- a/test/PushNotificationTests/UnpackagedTests.h +++ b/test/PushNotificationTests/UnpackagedTests.h @@ -2,88 +2,59 @@ // Licensed under the MIT License. See LICENSE in the project root for license information. #include "pch.h" -#include +#include "BaseTestSuite.h" using namespace WEX::Common; using namespace WEX::Logging; using namespace WEX::TestExecution; -using namespace winrt::Windows::ApplicationModel::Activation; -using namespace winrt::Windows::ApplicationModel::Background; -using namespace winrt::Windows::Foundation; -using namespace winrt::Windows::Foundation::Collections; -using namespace winrt::Windows::Management::Deployment; -using namespace winrt::Windows::Storage; -using namespace winrt::Windows::System; -using namespace winrt::Microsoft::Windows::PushNotifications; - -namespace Test::PushNotifications +class UnpackagedTests : BaseTestSuite { - class UnpackagedTests + BEGIN_TEST_CLASS(UnpackagedTests) + TEST_CLASS_PROPERTY(L"Description", L"Windows App SDK Push Notifications test") + TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") + TEST_CLASS_PROPERTY(L"RunAs:Class", L"RestrictedUser") + TEST_CLASS_PROPERTY(L"IsolationLevel", L"Class") + TEST_CLASS_PROPERTY(L"Data:SelfContained", L"{true, false}") + END_TEST_CLASS() + + TEST_CLASS_SETUP(ClassInit) { - private: - HRESULT ChannelRequestHelper(IAsyncOperationWithProgress const& channelOperation); - - bool m_registered{ false }; - public: - BEGIN_TEST_CLASS(UnpackagedTests) - TEST_CLASS_PROPERTY(L"Description", L"Windows App SDK Push Notifications test") - TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA") - TEST_CLASS_PROPERTY(L"RunAs:Class", L"RestrictedUser") - TEST_CLASS_PROPERTY(L"IsolationLevel", L"Class") - TEST_CLASS_PROPERTY(L"Data:SelfContained", L"{true, false}") - END_TEST_CLASS() - - TEST_CLASS_SETUP(ClassInit) - { - ::Test::Bootstrap::Setup(); - bool isSelfContained{ false }; - if (SUCCEEDED(TestData::TryGetValue(L"SelfContained", isSelfContained))) - { - if (!isSelfContained) - { - ::WindowsAppRuntime::SelfContained::TestInitialize(::Test::Bootstrap::TP::WindowsAppRuntimeFramework::c_PackageFamilyName); - } - } - return true; - } - - TEST_CLASS_CLEANUP(ClassUninit) - { - ::Test::Bootstrap::Cleanup(); - return true; - } + BaseTestSuite::ClassSetup(); + return true; + } - TEST_METHOD_SETUP(MethodInit) - { - return true; - } + TEST_CLASS_CLEANUP(ClassUninit) + { + BaseTestSuite::ClassCleanup(); + return true; + } - TEST_METHOD_CLEANUP(MethodUninit) - { - if (m_registered) - { - PushNotificationManager::Default().UnregisterAll(); - m_registered = false; - } + TEST_METHOD_SETUP(MethodInit) + { + return true; + } - return true; - } + TEST_METHOD_CLEANUP(MethodUninit) + { + BaseTestSuite::MethodCleanup(); + return true; + } + + TEST_METHOD(ChannelRequestUsingNullRemoteId); + TEST_METHOD(ChannelRequestUsingRemoteId); + TEST_METHOD(MultipleChannelClose); // Currently failing + TEST_METHOD(VerifyRegisterAndUnregister); + TEST_METHOD(VerifyRegisterAndUnregisterAll); + TEST_METHOD(VerifyUnregisterFails); + TEST_METHOD(VerifyUnregisterAllFails); + TEST_METHOD(MultipleRegister); + TEST_METHOD(VerifyMultipleRegisterAndUnregister); + TEST_METHOD(VerifyMultipleRegisterAndUnregisterAll); + TEST_METHOD(VerifyUnregisterTwice); + TEST_METHOD(VerifyUnregisterAllTwice); + TEST_METHOD(VerifyUnregisterAndUnregisterAll); + TEST_METHOD(VerifyForegroundHandlerSucceeds); + TEST_METHOD(VerifyForegroundHandlerFails); +}; - TEST_METHOD(ChannelRequestUsingNullRemoteId); - TEST_METHOD(ChannelRequestUsingRemoteId); - TEST_METHOD(MultipleChannelClose); // Currently failing - TEST_METHOD(VerifyRegisterAndUnregister); - TEST_METHOD(VerifyRegisterAndUnregisterAll); - TEST_METHOD(VerifyUnregisterFails); - TEST_METHOD(VerifyUnregisterAllFails); - TEST_METHOD(MultipleRegister); - TEST_METHOD(VerifyMultipleRegisterAndUnregister); - TEST_METHOD(VerifyMultipleRegisterAndUnregisterAll); - TEST_METHOD(VerifyUnregisterTwice); - TEST_METHOD(VerifyUnregisterAllTwice); - TEST_METHOD(VerifyUnregisterAndUnregisterAll); - TEST_METHOD(VerifyForegroundHandlerSucceeds); - TEST_METHOD(VerifyForegroundHandlerFails); - }; -} From ce4c63aa2718aac747443e91afb1083dc0a3ab2a Mon Sep 17 00:00:00 2001 From: Paul Purifoy Date: Fri, 15 Apr 2022 13:17:29 -0700 Subject: [PATCH 09/16] Removed unused namespaces --- test/PushNotificationTests/BaseTestSuite.h | 7 ------- 1 file changed, 7 deletions(-) diff --git a/test/PushNotificationTests/BaseTestSuite.h b/test/PushNotificationTests/BaseTestSuite.h index 9424e2f512..fac0b5afd5 100644 --- a/test/PushNotificationTests/BaseTestSuite.h +++ b/test/PushNotificationTests/BaseTestSuite.h @@ -7,14 +7,7 @@ using namespace WEX::Common; using namespace WEX::Logging; using namespace WEX::TestExecution; - -using namespace winrt::Windows::ApplicationModel::Activation; -using namespace winrt::Windows::ApplicationModel::Background; using namespace winrt::Windows::Foundation; -using namespace winrt::Windows::Foundation::Collections; -using namespace winrt::Windows::Management::Deployment; -using namespace winrt::Windows::Storage; -using namespace winrt::Windows::System; using namespace winrt::Microsoft::Windows::PushNotifications; class BaseTestSuite From e6fe544e28b33435ab64c6c88a45130b194657eb Mon Sep 17 00:00:00 2001 From: Paul Purifoy Date: Mon, 18 Apr 2022 12:09:12 -0700 Subject: [PATCH 10/16] Addressing nits --- ...dowsAppRuntime.Test.Singleton.Msix.vcxproj | 6 +++--- test/PushNotificationTests/BaseTestSuite.cpp | 20 ++++++++----------- test/PushNotificationTests/BaseTestSuite.h | 2 +- .../PushNotification-Test-Constants.h | 12 +++++++++++ .../PushNotificationTests.vcxproj | 1 + .../PushNotificationTests.vcxproj.filters | 3 +++ .../PushNotificationsTestApp/main.cpp | 4 ++-- .../ToastNotificationsTestApp/main.cpp | 1 - test/inc/TestDef.h | 8 -------- 9 files changed, 30 insertions(+), 27 deletions(-) create mode 100644 test/PushNotificationTests/PushNotification-Test-Constants.h diff --git a/test/DynamicDependency/data/WindowsAppRuntime.Test.Singleton.Msix/WindowsAppRuntime.Test.Singleton.Msix.vcxproj b/test/DynamicDependency/data/WindowsAppRuntime.Test.Singleton.Msix/WindowsAppRuntime.Test.Singleton.Msix.vcxproj index 169fa3581f..13cca41c69 100644 --- a/test/DynamicDependency/data/WindowsAppRuntime.Test.Singleton.Msix/WindowsAppRuntime.Test.Singleton.Msix.vcxproj +++ b/test/DynamicDependency/data/WindowsAppRuntime.Test.Singleton.Msix/WindowsAppRuntime.Test.Singleton.Msix.vcxproj @@ -125,13 +125,13 @@ - + {bf3fced0-cadb-490a-93a7-4d90e1f45ab0} - + {1debbff6-ee6e-4944-9de2-35b7a686af42} - + {1307dd1b-bbe8-4cd0-b1a0-0db6d61eeaa0} diff --git a/test/PushNotificationTests/BaseTestSuite.cpp b/test/PushNotificationTests/BaseTestSuite.cpp index eae225aee7..ab5d202193 100644 --- a/test/PushNotificationTests/BaseTestSuite.cpp +++ b/test/PushNotificationTests/BaseTestSuite.cpp @@ -3,7 +3,7 @@ #include "pch.h" -#include +#include "PushNotification-Test-Constants.h" #include "BaseTestSuite.h" using namespace WEX::Common; @@ -22,13 +22,12 @@ using namespace winrt::Microsoft::Windows::PushNotifications; void BaseTestSuite::ClassSetup() { ::Test::Bootstrap::Setup(); - bool isSelfContained{ false }; - if (SUCCEEDED(TestData::TryGetValue(L"SelfContained", isSelfContained))) + bool isSelfContained{}; + THROW_IF_FAILED(TestData::TryGetValue(L"SelfContained", isSelfContained)); + + if (!isSelfContained) { - if (!isSelfContained) - { - ::WindowsAppRuntime::SelfContained::TestInitialize(::Test::Bootstrap::TP::WindowsAppRuntimeFramework::c_PackageFamilyName); - } + ::WindowsAppRuntime::SelfContained::TestInitialize(::Test::Bootstrap::TP::WindowsAppRuntimeFramework::c_PackageFamilyName); } } @@ -51,15 +50,12 @@ HRESULT BaseTestSuite::ChannelRequestHelper(IAsyncOperationWithProgress const& channelOperation); - bool m_registered{ false }; + bool m_registered{}; }; diff --git a/test/PushNotificationTests/PushNotification-Test-Constants.h b/test/PushNotificationTests/PushNotification-Test-Constants.h new file mode 100644 index 0000000000..80b942404f --- /dev/null +++ b/test/PushNotificationTests/PushNotification-Test-Constants.h @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. +#pragma once + +inline const winrt::hstring c_rawNotificationPayload = L""; +static const std::chrono::seconds c_timeout = std::chrono::seconds(300); +inline IID c_azureRemoteId = winrt::guid(L"a2e4a323-b518-4799-9e80-0b37aeb0d225"); // Generated from ms.portal.azure.com +inline IID c_dummyRemoteId = winrt::guid(L"CA1A4AB2-AC1D-4EFC-A132-E5A191CA285A"); // Dummy guid from visual studio guid tool generator +inline IID c_remoteId = winrt::guid("A7652901-313C-4EFA-A303-95C371A00DAB"); +inline IID c_comServerId = winrt::guid("ccd2ae3f-764f-4ae3-be45-9804761b28b2"); // Value from PushNotificationsTestAppPackage ComActivator in appxmanifest. +inline IID c_toastComServerId = winrt::guid("1940dba9-0f64-4f0d-8a4b-5d207b812e61"); // Value from ToastNotificationsTestAppPackage ComActivator in appxmanifest. +inline IID c_fakeComServerId = winrt::guid("00000000-0000-0000-0000-000000000001"); diff --git a/test/PushNotificationTests/PushNotificationTests.vcxproj b/test/PushNotificationTests/PushNotificationTests.vcxproj index 21d7a0701c..641d33864a 100644 --- a/test/PushNotificationTests/PushNotificationTests.vcxproj +++ b/test/PushNotificationTests/PushNotificationTests.vcxproj @@ -175,6 +175,7 @@ + diff --git a/test/PushNotificationTests/PushNotificationTests.vcxproj.filters b/test/PushNotificationTests/PushNotificationTests.vcxproj.filters index 89be57a422..8059c2a4c0 100644 --- a/test/PushNotificationTests/PushNotificationTests.vcxproj.filters +++ b/test/PushNotificationTests/PushNotificationTests.vcxproj.filters @@ -30,6 +30,9 @@ Header Files + + Header Files + diff --git a/test/TestApps/PushNotificationsTestApp/main.cpp b/test/TestApps/PushNotificationsTestApp/main.cpp index 4ef8e9b10d..4f990e5cf6 100644 --- a/test/TestApps/PushNotificationsTestApp/main.cpp +++ b/test/TestApps/PushNotificationsTestApp/main.cpp @@ -1,5 +1,4 @@ #include "pch.h" -#include #include #include #include @@ -17,8 +16,9 @@ using namespace winrt::Windows::Storage::Streams; winrt::guid remoteId1(L"a2e4a323-b518-4799-9e80-0b37aeb0d225"); // Generated from ms.portal.azure.com winrt::guid remoteId2(L"CA1A4AB2-AC1D-4EFC-A132-E5A191CA285A"); // Dummy guid from visual studio guid tool generator - constexpr auto timeout{ std::chrono::seconds(300) }; +inline const winrt::hstring c_rawNotificationPayload = L""; + bool ChannelRequestUsingNullRemoteId() { diff --git a/test/TestApps/ToastNotificationsTestApp/main.cpp b/test/TestApps/ToastNotificationsTestApp/main.cpp index 22b26e42d8..bbea87d430 100644 --- a/test/TestApps/ToastNotificationsTestApp/main.cpp +++ b/test/TestApps/ToastNotificationsTestApp/main.cpp @@ -1,5 +1,4 @@ #include "pch.h" -#include #include #include #include "WindowsAppRuntime.Test.AppModel.h" diff --git a/test/inc/TestDef.h b/test/inc/TestDef.h index f7cc632b74..ddb4a2014e 100644 --- a/test/inc/TestDef.h +++ b/test/inc/TestDef.h @@ -22,14 +22,6 @@ static const std::wstring c_testRequestRestartNowRestartedPhaseEventName = L"Win static const std::wstring c_testRequestRestartNowRestartedPhasePackagedEventName = L"WindowsAppRuntimeTestRequestRestartNowRestartedPhasePackagedEventName"; static const std::wstring c_testPushPhaseEventName = L"WindowsAppRuntimeTestPushPhaseEventName"; -inline const winrt::hstring c_rawNotificationPayload = L""; -static const std::chrono::seconds c_timeout = std::chrono::seconds(300); -inline IID c_azureRemoteId = winrt::guid(L"a2e4a323-b518-4799-9e80-0b37aeb0d225"); // Generated from ms.portal.azure.com -inline IID c_dummyRemoteId = winrt::guid(L"CA1A4AB2-AC1D-4EFC-A132-E5A191CA285A"); // Dummy guid from visual studio guid tool generator -inline IID c_remoteId = winrt::guid("A7652901-313C-4EFA-A303-95C371A00DAB"); -inline IID c_comServerId = winrt::guid("ccd2ae3f-764f-4ae3-be45-9804761b28b2"); // Value from PushNotificationsTestAppPackage ComActivator in appxmanifest. -inline IID c_toastComServerId = winrt::guid("1940dba9-0f64-4f0d-8a4b-5d207b812e61"); // Value from ToastNotificationsTestAppPackage ComActivator in appxmanifest. -inline IID c_fakeComServerId = winrt::guid("00000000-0000-0000-0000-000000000001"); #ifndef WIDEN2 #define WIDEN2(x) L ## x From 5a6f6a4b03bbf5edeb1f1d0044066078f65edc8e Mon Sep 17 00:00:00 2001 From: Paul Purifoy Date: Mon, 18 Apr 2022 12:09:58 -0700 Subject: [PATCH 11/16] Use verify instead of throw --- test/PushNotificationTests/BaseTestSuite.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/PushNotificationTests/BaseTestSuite.cpp b/test/PushNotificationTests/BaseTestSuite.cpp index ab5d202193..593411531e 100644 --- a/test/PushNotificationTests/BaseTestSuite.cpp +++ b/test/PushNotificationTests/BaseTestSuite.cpp @@ -23,7 +23,7 @@ void BaseTestSuite::ClassSetup() { ::Test::Bootstrap::Setup(); bool isSelfContained{}; - THROW_IF_FAILED(TestData::TryGetValue(L"SelfContained", isSelfContained)); + VERIFY_SUCCEEDED(TestData::TryGetValue(L"SelfContained", isSelfContained)); if (!isSelfContained) { From 3329becb4e9ecac2bac32e91affe6fea24f85ac3 Mon Sep 17 00:00:00 2001 From: Paul Purifoy Date: Mon, 18 Apr 2022 14:55:58 -0700 Subject: [PATCH 12/16] rename m_registered -> m_unregisteredFully --- test/PushNotificationTests/BaseTestSuite.cpp | 71 +++++++++----------- test/PushNotificationTests/BaseTestSuite.h | 4 +- 2 files changed, 33 insertions(+), 42 deletions(-) diff --git a/test/PushNotificationTests/BaseTestSuite.cpp b/test/PushNotificationTests/BaseTestSuite.cpp index 593411531e..e7f0203520 100644 --- a/test/PushNotificationTests/BaseTestSuite.cpp +++ b/test/PushNotificationTests/BaseTestSuite.cpp @@ -38,10 +38,10 @@ void BaseTestSuite::ClassCleanup() void BaseTestSuite::MethodCleanup() { - if (m_registered) + if (!m_unregisteredFully) { PushNotificationManager::Default().UnregisterAll(); - m_registered = false; + m_unregisteredFully = true; } } @@ -61,6 +61,18 @@ HRESULT BaseTestSuite::ChannelRequestHelper(IAsyncOperationWithProgress const& channelOperation); + void RegisterWithPushNotificationManager(); + void UnregisterAllWithPushNotificationManager(); - bool m_registered{}; + bool m_unregisteredFully{ true }; }; From cade72f2d8f6e5ad08598c9545b398454434fef3 Mon Sep 17 00:00:00 2001 From: Paul Purifoy Date: Mon, 18 Apr 2022 16:11:21 -0700 Subject: [PATCH 13/16] Ignored failing tests --- test/PushNotificationTests/PackagedTests.h | 4 +++- test/PushNotificationTests/UnpackagedTests.h | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/test/PushNotificationTests/PackagedTests.h b/test/PushNotificationTests/PackagedTests.h index cb61249c78..2a56324efd 100644 --- a/test/PushNotificationTests/PackagedTests.h +++ b/test/PushNotificationTests/PackagedTests.h @@ -45,7 +45,9 @@ class PackagedTests : BaseTestSuite TEST_METHOD(ChannelRequestUsingNullRemoteId); TEST_METHOD(ChannelRequestUsingRemoteId); - TEST_METHOD(MultipleChannelClose); // Currently failing + BEGIN_TEST_METHOD(MultipleChannelClose) // Currently failing + TEST_METHOD_PROPERTY(L"Ignore", L"true") + END_TEST_METHOD() TEST_METHOD(VerifyRegisterAndUnregister); TEST_METHOD(VerifyRegisterAndUnregisterAll); TEST_METHOD(VerifyUnregisterFails); diff --git a/test/PushNotificationTests/UnpackagedTests.h b/test/PushNotificationTests/UnpackagedTests.h index a6288a5207..8c2c0d92c2 100644 --- a/test/PushNotificationTests/UnpackagedTests.h +++ b/test/PushNotificationTests/UnpackagedTests.h @@ -43,7 +43,9 @@ class UnpackagedTests : BaseTestSuite TEST_METHOD(ChannelRequestUsingNullRemoteId); TEST_METHOD(ChannelRequestUsingRemoteId); - TEST_METHOD(MultipleChannelClose); // Currently failing + BEGIN_TEST_METHOD(MultipleChannelClose) // Currently failing + TEST_METHOD_PROPERTY(L"Ignore", L"true") + END_TEST_METHOD() TEST_METHOD(VerifyRegisterAndUnregister); TEST_METHOD(VerifyRegisterAndUnregisterAll); TEST_METHOD(VerifyUnregisterFails); From a8749c46f0e9aa2fb77d1455b6592aac065655fb Mon Sep 17 00:00:00 2001 From: Paul Purifoy Date: Mon, 18 Apr 2022 17:07:10 -0700 Subject: [PATCH 14/16] Fix build issues --- .../PushNotification-Test-Constants.h | 1 - test/ToastNotificationTests/APITests.cpp | 2 +- .../AppNotification-Test-Constants.h | 7 +++++++ test/ToastNotificationTests/ToastNotificationTests.vcxproj | 7 ++++--- .../ToastNotificationTests.vcxproj.filters | 4 ++++ 5 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 test/ToastNotificationTests/AppNotification-Test-Constants.h diff --git a/test/PushNotificationTests/PushNotification-Test-Constants.h b/test/PushNotificationTests/PushNotification-Test-Constants.h index 80b942404f..21ad68fcc0 100644 --- a/test/PushNotificationTests/PushNotification-Test-Constants.h +++ b/test/PushNotificationTests/PushNotification-Test-Constants.h @@ -8,5 +8,4 @@ inline IID c_azureRemoteId = winrt::guid(L"a2e4a323-b518-4799-9e80-0b37aeb0d225" inline IID c_dummyRemoteId = winrt::guid(L"CA1A4AB2-AC1D-4EFC-A132-E5A191CA285A"); // Dummy guid from visual studio guid tool generator inline IID c_remoteId = winrt::guid("A7652901-313C-4EFA-A303-95C371A00DAB"); inline IID c_comServerId = winrt::guid("ccd2ae3f-764f-4ae3-be45-9804761b28b2"); // Value from PushNotificationsTestAppPackage ComActivator in appxmanifest. -inline IID c_toastComServerId = winrt::guid("1940dba9-0f64-4f0d-8a4b-5d207b812e61"); // Value from ToastNotificationsTestAppPackage ComActivator in appxmanifest. inline IID c_fakeComServerId = winrt::guid("00000000-0000-0000-0000-000000000001"); diff --git a/test/ToastNotificationTests/APITests.cpp b/test/ToastNotificationTests/APITests.cpp index fade62a6ad..ecf3e047ab 100644 --- a/test/ToastNotificationTests/APITests.cpp +++ b/test/ToastNotificationTests/APITests.cpp @@ -1,6 +1,6 @@ #include "pch.h" #include "NotificationActivationCallback.h" -#include +#include "AppNotification-Test-Constants.h" using namespace WEX::Common; using namespace WEX::Logging; diff --git a/test/ToastNotificationTests/AppNotification-Test-Constants.h b/test/ToastNotificationTests/AppNotification-Test-Constants.h new file mode 100644 index 0000000000..bd2730e75d --- /dev/null +++ b/test/ToastNotificationTests/AppNotification-Test-Constants.h @@ -0,0 +1,7 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. +#pragma once + +inline const winrt::hstring c_rawNotificationPayload = L""; +static const std::chrono::seconds c_timeout = std::chrono::seconds(300); +inline IID c_toastComServerId = winrt::guid("1940dba9-0f64-4f0d-8a4b-5d207b812e61"); // Value from ToastNotificationsTestAppPackage ComActivator in appxmanifest. diff --git a/test/ToastNotificationTests/ToastNotificationTests.vcxproj b/test/ToastNotificationTests/ToastNotificationTests.vcxproj index a425d6bd47..c32741f04f 100644 --- a/test/ToastNotificationTests/ToastNotificationTests.vcxproj +++ b/test/ToastNotificationTests/ToastNotificationTests.vcxproj @@ -235,6 +235,7 @@ + @@ -266,9 +267,9 @@ - $(OutDir)\..\WindowsAppRuntime_DLL\Microsoft.Windows.AppLifecycle.winmd - true - + $(OutDir)\..\WindowsAppRuntime_DLL\Microsoft.Windows.AppLifecycle.winmd + true + $(OutDir)\..\WindowsAppRuntime_DLL\Microsoft.Windows.AppNotifications.winmd true diff --git a/test/ToastNotificationTests/ToastNotificationTests.vcxproj.filters b/test/ToastNotificationTests/ToastNotificationTests.vcxproj.filters index f4cfc65598..ef950bacf1 100644 --- a/test/ToastNotificationTests/ToastNotificationTests.vcxproj.filters +++ b/test/ToastNotificationTests/ToastNotificationTests.vcxproj.filters @@ -18,6 +18,9 @@ Header Files + + Header Files + @@ -34,5 +37,6 @@ + \ No newline at end of file From 0a23873cea07f278ce6e22433fb44cdaf5b3a139 Mon Sep 17 00:00:00 2001 From: Paul Purifoy Date: Tue, 19 Apr 2022 12:58:26 -0700 Subject: [PATCH 15/16] Update PushNotificationTests.vcxproj --- .../PushNotificationTests.vcxproj | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/test/PushNotificationTests/PushNotificationTests.vcxproj b/test/PushNotificationTests/PushNotificationTests.vcxproj index 641d33864a..cbfcddc9cd 100644 --- a/test/PushNotificationTests/PushNotificationTests.vcxproj +++ b/test/PushNotificationTests/PushNotificationTests.vcxproj @@ -18,6 +18,14 @@ Release x64 + + Debug + ARM64 + + + Release + ARM64 + 16.0 @@ -52,6 +60,21 @@ v142 true Unicode + + + DynamicLibrary + true + v142 + Unicode + false + + + DynamicLibrary + false + v142 + true + Unicode + false @@ -70,6 +93,12 @@ + + + + + + true @@ -83,6 +112,9 @@ false + + true + Level4 @@ -171,6 +203,50 @@ false + + + Level4 + true + _DEBUG;PUSHNOTIFICATIONTESTS_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + $(OutDir)..\PushNotificationsLongRunningTask.ProxyStub;$(RepoRoot)\test\inc;$(RepoRoot)\Dev\Common;$(ProjectDir)..\inc;$(ProjectDir)..\..\dev\WindowsAppRuntime_BootstrapDLL\ + + + onecore.lib;onecoreuap.lib;Microsoft.WindowsAppRuntime.lib;wex.common.lib;wex.logger.lib;te.common.lib;%(AdditionalDependencies) + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories);$(OutDir)\..\WindowsAppRuntime_DLL + Microsoft.WindowsAppRuntime.Bootstrap.dll;%(DelayLoadDLLs) + Microsoft.WindowsAppRuntime.dll;%(DelayLoadDLLs) + Windows + true + false + + + + + Level4 + true + true + true + WIN32;NDEBUG;PUSHNOTIFICATIONTESTS_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + $(OutDir)..\PushNotificationsLongRunningTask.ProxyStub;$(RepoRoot)\test\inc;$(RepoRoot)\Dev\Common;$(ProjectDir)..\inc;$(ProjectDir)..\..\dev\WindowsAppRuntime_BootstrapDLL\ + + + onecore.lib;onecoreuap.lib;Microsoft.WindowsAppRuntime.lib;wex.common.lib;wex.logger.lib;te.common.lib;%(AdditionalDependencies) + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories);$(OutDir)\..\WindowsAppRuntime_DLL + Microsoft.WindowsAppRuntime.Bootstrap.dll;%(DelayLoadDLLs) + Microsoft.WindowsAppRuntime.dll;%(DelayLoadDLLs) + Windows + true + true + true + false + + @@ -186,6 +262,8 @@ Create Create Create + Create + Create From 6d29c56e4c210f08be2f410e1c7eb4cd810bfed2 Mon Sep 17 00:00:00 2001 From: Paul Purifoy Date: Tue, 19 Apr 2022 16:17:16 -0700 Subject: [PATCH 16/16] Update AppNotification-Test-Constants.h --- test/ToastNotificationTests/AppNotification-Test-Constants.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/ToastNotificationTests/AppNotification-Test-Constants.h b/test/ToastNotificationTests/AppNotification-Test-Constants.h index bd2730e75d..b657742c11 100644 --- a/test/ToastNotificationTests/AppNotification-Test-Constants.h +++ b/test/ToastNotificationTests/AppNotification-Test-Constants.h @@ -3,5 +3,5 @@ #pragma once inline const winrt::hstring c_rawNotificationPayload = L""; -static const std::chrono::seconds c_timeout = std::chrono::seconds(300); +inline const std::chrono::seconds c_timeout = std::chrono::seconds(300); inline IID c_toastComServerId = winrt::guid("1940dba9-0f64-4f0d-8a4b-5d207b812e61"); // Value from ToastNotificationsTestAppPackage ComActivator in appxmanifest.