Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Implemented ToastNotification + unit tests #1996

Merged
merged 3 commits into from
Jan 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions dev/ToastNotifications/ToastNotification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,76 +4,76 @@

namespace winrt::Microsoft::Windows::ToastNotifications::implementation
{
ToastNotification::ToastNotification(winrt::Windows::Data::Xml::Dom::XmlDocument const& /* payload */)
ToastNotification::ToastNotification(winrt::Windows::Data::Xml::Dom::XmlDocument const& payload)
{
throw hresult_not_implemented();
m_payload = payload;
}
hstring ToastNotification::Tag()
{
throw hresult_not_implemented();
return m_tag;
}
void ToastNotification::Tag(hstring const& /* value */)
void ToastNotification::Tag(hstring const& tag)
{
throw hresult_not_implemented();
m_tag = tag;
}
hstring ToastNotification::Group()
{
throw hresult_not_implemented();
return m_group;
}
void ToastNotification::Group(hstring const& /* value */)
void ToastNotification::Group(hstring const& group)
{
throw hresult_not_implemented();
m_group = group;
}
uint32_t ToastNotification::ToastId()
{
throw hresult_not_implemented();
return m_toastId;
}
void ToastNotification::ToastId(uint32_t /* value */)
void ToastNotification::ToastId(uint32_t toastId)
{
throw hresult_not_implemented();
m_toastId = toastId;
}
winrt::Windows::Data::Xml::Dom::XmlDocument ToastNotification::Payload()
{
throw hresult_not_implemented();
return m_payload;
}
winrt::Microsoft::Windows::ToastNotifications::ToastProgressData ToastNotification::ProgressData()
{
throw hresult_not_implemented();
return m_progressData;
}
void ToastNotification::ProgressData(winrt::Microsoft::Windows::ToastNotifications::ToastProgressData const& /* value */)
void ToastNotification::ProgressData(winrt::Microsoft::Windows::ToastNotifications::ToastProgressData const& progressData)
{
throw hresult_not_implemented();
m_progressData = progressData;
}
winrt::Windows::Foundation::DateTime ToastNotification::ExpirationTime()
{
throw hresult_not_implemented();
return m_expirationTime;
}
void ToastNotification::ExpirationTime(winrt::Windows::Foundation::DateTime const& /* value */)
void ToastNotification::ExpirationTime(winrt::Windows::Foundation::DateTime const& expirationTime)
{
throw hresult_not_implemented();
m_expirationTime = expirationTime;
}
bool ToastNotification::ExpiresOnReboot()
{
throw hresult_not_implemented();
return m_expiresOnReboot;
}
void ToastNotification::ExpiresOnReboot(bool /* value */)
void ToastNotification::ExpiresOnReboot(bool expiresOnReboot)
{
throw hresult_not_implemented();
m_expiresOnReboot = expiresOnReboot;
}
winrt::Microsoft::Windows::ToastNotifications::ToastPriority ToastNotification::Priority()
{
throw hresult_not_implemented();
return m_priority;
}
void ToastNotification::Priority(winrt::Microsoft::Windows::ToastNotifications::ToastPriority const& /* value */)
void ToastNotification::Priority(winrt::Microsoft::Windows::ToastNotifications::ToastPriority const& priority)
{
throw hresult_not_implemented();
m_priority = priority;
}
bool ToastNotification::SuppressDisplay()
{
throw hresult_not_implemented();
return m_suppressDisplay;
}
void ToastNotification::SuppressDisplay(bool /* value */)
void ToastNotification::SuppressDisplay(bool suppressDisplay)
{
throw hresult_not_implemented();
m_suppressDisplay = suppressDisplay;
}
}
20 changes: 20 additions & 0 deletions dev/ToastNotifications/ToastNotification.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,26 @@ namespace winrt::Microsoft::Windows::ToastNotifications::implementation
void Priority(winrt::Microsoft::Windows::ToastNotifications::ToastPriority const& value);
bool SuppressDisplay();
void SuppressDisplay(bool value);

private:
winrt::hstring m_tag{};

winrt::hstring m_group{};

uint32_t m_toastId{ 0 };

winrt::Windows::Data::Xml::Dom::XmlDocument m_payload{};

winrt::Microsoft::Windows::ToastNotifications::ToastProgressData m_progressData{};

winrt::Windows::Foundation::DateTime m_expirationTime{};

bool m_expiresOnReboot{ false };

winrt::Microsoft::Windows::ToastNotifications::ToastPriority m_priority
{ winrt::Microsoft::Windows::ToastNotifications::ToastPriority::Default };

bool m_suppressDisplay{ false };
};
}
namespace winrt::Microsoft::Windows::ToastNotifications::factory_implementation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<ActivatableClass ActivatableClassId="Microsoft.Windows.ToastNotifications.ToastActivationInfo" ThreadingModel="both" />
<ActivatableClass ActivatableClassId="Microsoft.Windows.ToastNotifications.ToastAssets" ThreadingModel="both" />
<ActivatableClass ActivatableClassId="Microsoft.Windows.ToastNotifications.ToastNotificationManager" ThreadingModel="both" />
<ActivatableClass ActivatableClassId="Microsoft.Windows.ToastNotifications.ToastNotification" ThreadingModel="both" />
</InProcessServer>
</Extension>
<Extension Category="windows.activatableClass.inProcessServer">
Expand Down
177 changes: 177 additions & 0 deletions test/TestApps/ToastNotificationsTestApp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
#include <iostream>
#include <wil/win32_helpers.h>
#include "WindowsAppRuntime.Test.AppModel.h"
#include <chrono>

namespace winrt
{
using namespace winrt::Microsoft::Windows::AppLifecycle;
using namespace winrt::Windows::ApplicationModel::Activation;
using namespace winrt::Windows::Foundation;
using namespace winrt::Microsoft::Windows::ToastNotifications;
using namespace winrt::Windows::Data::Xml::Dom;
}

bool BackgroundActivationTest() // Activating application for background test.
Expand All @@ -23,6 +25,16 @@ bool UnregisterBackgroundActivationTest()
return true;
}

winrt::ToastNotification GetToastNotification()
{
winrt::hstring xmlPayload{ L"<toast>intrepidToast</toast>" };

winrt::XmlDocument xmlDocument{};
xmlDocument.LoadXml(xmlPayload);

return winrt::ToastNotification(xmlDocument);
}

bool VerifyFailedRegisterActivatorUsingNullClsid()
{
try
Expand Down Expand Up @@ -209,6 +221,163 @@ bool VerifyToastSettingEnabled()
return winrt::ToastNotificationManager::Default().Setting() == winrt::ToastNotificationSetting::Enabled;
}

bool VerifyToastPayload()
{
winrt::hstring xmlPayload{ L"<toast>intrepidToast</toast>" };

winrt::XmlDocument xmlDocument{};
xmlDocument.LoadXml(xmlPayload);

winrt::ToastNotification toast{ xmlDocument };;

if (toast.Payload() != xmlDocument)
{
return false;
}

return true;
}

bool VerifyToastTag()
{
winrt::ToastNotification toast{ GetToastNotification() };

if (toast.Tag() != winrt::hstring{ L"" })
{
return false;
}

winrt::hstring tag{ L"tag" };
toast.Tag(tag);

if (toast.Tag() != tag)
{
return false;
}

return true;
}

bool VerifyToastGroup()
{
winrt::ToastNotification toast{ GetToastNotification() };

if (toast.Group() != winrt::hstring{ L"" })
{
return false;
}

winrt::hstring group{ L"group" };
toast.Group(group);

if (toast.Group() != group)
{
return false;
}

return true;
}

bool VerifyToastProgressDataFromToast()
{
/*
* TODO: Uncomment once ToastProgressData has been implemented

winrt::ToastNotification toast{ GetToastNotification() };

winrt::ToastProgressData progressData{};
progressData.Status(L"SomeStatus");
progressData.Title(L"SomeTitle");
progressData.Value(0.14);
progressData.ValueStringOverride(L"14%");

toast.ProgressData(progressData);

auto progressDataFromToast = toast.ProgressData();
if (progressDataFromToast != progressData)
{
return false;
}
*/

return true;
}

bool VerifyToastExpirationTime()
{
winrt::ToastNotification toast{ GetToastNotification() };

if (toast.ExpirationTime() != winrt::DateTime{})
{
return false;
}

winrt::DateTime expirationTime{ winrt::clock::now() };
expirationTime += winrt::TimeSpan{ std::chrono::seconds(10) };

toast.ExpirationTime(expirationTime);
if (toast.ExpirationTime() != expirationTime)
{
return false;
}

return true;
}

bool VerifyToastPriority()
{
winrt::ToastNotification toast{ GetToastNotification() };

if (toast.Priority() != winrt::ToastPriority::Default)
{
return false;
}

toast.Priority(winrt::ToastPriority::High);
if (toast.Priority() != winrt::ToastPriority::High)
{
return false;
}

return true;
}

bool VerifyToastSuppressDisplay()
{
winrt::ToastNotification toast{ GetToastNotification() };

if (toast.SuppressDisplay())
{
return false;
}

toast.SuppressDisplay(true);
if (!toast.SuppressDisplay())
{
return false;
}

return true;
}

bool VerifyToastExpiresOnReboot()
{
winrt::ToastNotification toast{ GetToastNotification() };

if (toast.ExpiresOnReboot())
{
return false;
}

toast.ExpiresOnReboot(true);
if (!toast.ExpiresOnReboot())
{
return false;
}

return true;
}

std::string unitTestNameFromLaunchArguments(const winrt::ILaunchActivatedEventArgs& launchArgs)
{
std::string unitTestName = to_string(launchArgs.Arguments());
Expand Down Expand Up @@ -238,6 +407,14 @@ std::map<std::string, bool(*)()> const& GetSwitchMapping()
{ "VerifyFailedToastAssetsWithEmptyIconPath_Unpackaged", &VerifyFailedToastAssetsWithEmptyIconPath_Unpackaged },
{ "VerifyFailedToastAssetsWithNullIconPath_Unpackaged", &VerifyFailedToastAssetsWithNullIconPath_Unpackaged },
{ "VerifyToastSettingEnabled", &VerifyToastSettingEnabled },
{ "VerifyToastPayload", &VerifyToastPayload },
{ "VerifyToastTag", &VerifyToastTag },
{ "VerifyToastGroup", &VerifyToastGroup },
{ "VerifyToastProgressDataFromToast", &VerifyToastProgressDataFromToast },
{ "VerifyToastExpirationTime", &VerifyToastExpirationTime },
{ "VerifyToastPriority", &VerifyToastPriority },
{ "VerifyToastSuppressDisplay", &VerifyToastSuppressDisplay },
{ "VerifyToastExpiresOnReboot", &VerifyToastExpiresOnReboot },
};
return switchMapping;
}
Expand Down
1 change: 1 addition & 0 deletions test/TestApps/ToastNotificationsTestApp/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
#include <winrt/Windows.Storage.Streams.h>
#include <winrt/Microsoft.Windows.AppLifecycle.h>
#include <winrt/Microsoft.Windows.ToastNotifications.h>
#include <winrt/Windows.Data.Xml.Dom.h>

#include <WindowsAppRuntime.Test.Bootstrap.h>
Loading