ReactOS 0.4.16-dev-136-g52192f1
CUserNotification.cpp File Reference
#include "shelltest.h"
#include <debug.h>
Include dependency graph for CUserNotification.cpp:

Go to the source code of this file.

Classes

class  CQueryContinue
 

Macros

#define NDEBUG
 
#define ok_hr(status, expected)   ok_hex(status, expected)
 
#define HRESULT_CANCELLED   HRESULT_FROM_WIN32(ERROR_CANCELLED)
 

Functions

static void TestNotification (void)
 
DWORD CALLBACK TestThread (LPVOID lpParam)
 
 START_TEST (CUserNotification)
 

Macro Definition Documentation

◆ HRESULT_CANCELLED

#define HRESULT_CANCELLED   HRESULT_FROM_WIN32(ERROR_CANCELLED)

Definition at line 15 of file CUserNotification.cpp.

◆ NDEBUG

#define NDEBUG

Definition at line 10 of file CUserNotification.cpp.

◆ ok_hr

#define ok_hr (   status,
  expected 
)    ok_hex(status, expected)

Definition at line 13 of file CUserNotification.cpp.

Function Documentation

◆ START_TEST()

START_TEST ( CUserNotification  )

Definition at line 189 of file CUserNotification.cpp.

190{
192 DWORD dwWait;
193
194 /* We create a test thread, because the notification tests can hang */
196 ok(hThread != NULL, "CreateThread failed with error 0x%lu\n", GetLastError());
197 if (!hThread)
198 {
199 skip("Could not create the CUserNotification test thread!\n");
200 return;
201 }
202
203 /* Wait a maximum of 60 seconds for the thread to finish (the timeout tests take some time) */
204 dwWait = WaitForSingleObject(hThread, 60 * 1000);
205 ok(dwWait == WAIT_OBJECT_0, "WaitForSingleObject returned %lu, expected WAIT_OBJECT_0\n", dwWait);
206
207 /* Cleanup and return */
209}
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define NULL
Definition: types.h:112
#define CloseHandle
Definition: compat.h:739
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:137
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD CALLBACK TestThread(LPVOID lpParam)
HANDLE hThread
Definition: wizard.c:28
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define WAIT_OBJECT_0
Definition: winbase.h:406

◆ TestNotification()

static void TestNotification ( void  )
static

Definition at line 73 of file CUserNotification.cpp.

74{
75 HRESULT hr;
76 CComPtr<IUserNotification> pUserNotif;
77 CQueryContinue queryContinue(S_OK);
78
79 // hr = pUserNotif.CoCreateInstance(CLSID_UserNotification);
80 hr = ::CoCreateInstance(CLSID_UserNotification, NULL, CLSCTX_ALL,
81 /*IID_PPV_ARG(IUserNotification, &pUserNotif)*/
82 IID_IUserNotification, (void**)&pUserNotif);
83 ok(hr == S_OK, "CoCreateInstance, hr = 0x%lx\n", hr);
84 if (FAILED(hr))
85 {
86 skip("Could not instantiate IUserNotification\n");
87 return;
88 }
89
90 /* Set an invalid icon for the notification icon */
91 hr = pUserNotif->SetIconInfo((HICON)UlongToHandle(0xdeadbeef), L"Tooltip text");
92 ok_hr(hr, S_OK);
93
94#if 0
95 /* Seting an invalid string would crash the application */
96 hr = pUserNotif->SetIconInfo(NULL, (LPCWSTR)0xdeadbeef);
97 ok_hr(hr, S_OK);
98#endif
99
100 /* Set a default icon for the notification icon */
101 hr = pUserNotif->SetIconInfo(NULL, L"Tooltip text");
102 ok_hr(hr, S_OK);
103
104 /*
105 * Since just displaying a notification icon without balloon hangs (expected),
106 * for making this test automatable we instead just test balloon functionality
107 * where timeouts can be programmed.
108 */
109
110 /* Set up a balloon associated to the notification icon */
111 hr = pUserNotif->SetBalloonInfo(L"Balloon title", L"Balloon text", NIIF_ERROR);
112 ok_hr(hr, S_OK);
113
114 /*
115 * Try to display twice the balloon if the user cancels it.
116 * Without setting balloon retry, we would wait for a very long time...
117 */
118 hr = pUserNotif->SetBalloonRetry(2000, 1000, 2);
119 ok_hr(hr, S_OK);
120
121 /* Display the balloon and also the tooltip if one points on the icon */
122 hr = pUserNotif->Show(NULL, 0);
124
125 /*
126 * Setting icon information *after* having enabled balloon info,
127 * allows to automatically set the notification icon according
128 * to the dwInfoFlags passed to SetBalloonInfo() and by giving
129 * NULL to the hIcon parameter of SetIconInfo().
130 */
131 hr = pUserNotif->SetIconInfo(NULL, NULL);
132 ok_hr(hr, S_OK);
133
134 /* Display the balloon and also the tooltip if one points on the icon */
135 hr = pUserNotif->Show(NULL, 0);
137
138 /*
139 * This line shows the balloon, but without title nor icon in it.
140 * Note that the balloon icon is not displayed when not setting any title.
141 */
142 hr = pUserNotif->SetBalloonInfo(NULL, L"Balloon text", NIIF_WARNING);
143 ok_hr(hr, S_OK);
144
145 hr = pUserNotif->Show(NULL, 0);
147
148
149 /* Test support of the IQueryContinue interface */
150
151 hr = pUserNotif->SetBalloonInfo(L"Balloon title", L"Balloon text", NIIF_WARNING);
152 ok_hr(hr, S_OK);
153
154 hr = pUserNotif->Show(&queryContinue, 2000); /* Timeout of 2 seconds */
156
157#if 0 // Commented because this test (the Show() call) is unreliable.
158 /* Try to hide the balloon by setting an empty string (can use either NULL or L"") */
159 hr = pUserNotif->SetBalloonInfo(L"Balloon title", NULL, NIIF_WARNING);
160 ok_hr(hr, S_OK);
161
162 hr = pUserNotif->Show(&queryContinue, 2000); /* Timeout of 2 seconds */
164#endif
165
166 hr = pUserNotif->SetBalloonInfo(L"Balloon title", L"Balloon text", NIIF_WARNING);
167 ok_hr(hr, S_OK);
168
169 queryContinue = S_FALSE;
170 hr = pUserNotif->Show(&queryContinue, 2000); /* Timeout of 2 seconds */
171 ok_hr(hr, S_FALSE);
172}
#define UlongToHandle(ul)
Definition: basetsd.h:97
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
#define HRESULT_CANCELLED
#define ok_hr(status, expected)
static HICON
Definition: imagelist.c:80
#define L(x)
Definition: ntvdm.h:50
HRESULT hr
Definition: shlfolder.c:183
#define S_FALSE
Definition: winerror.h:2357
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by TestThread().

◆ TestThread()

DWORD CALLBACK TestThread ( LPVOID  lpParam)

Definition at line 176 of file CUserNotification.cpp.

177{
178 /* Initialize COM */
180
181 /* Start the test */
183
184 /* Cleanup and return */
186 return 0;
187}
HRESULT WINAPI DECLSPEC_HOTPATCH CoInitializeEx(LPVOID lpReserved, DWORD dwCoInit)
Definition: compobj.c:2002
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067
static void TestNotification(void)
@ COINIT_APARTMENTTHREADED
Definition: objbase.h:278

Referenced by START_TEST().