Andrew Eikum : shell32/tests: Make SHChangeNotify tests more easily extendible.
Alexandre Julliard
julliard at winehq.org
Mon Nov 15 13:28:45 CST 2010
Module: wine
Branch: master
Commit: 71fad7d18d9657e132cb125af8a95ba2cdf9a2ff
URL: http://source.winehq.org/git/wine.git/?a=commit;h=71fad7d18d9657e132cb125af8a95ba2cdf9a2ff
Author: Andrew Eikum <aeikum at codeweavers.com>
Date: Fri Nov 12 15:32:49 2010 -0600
shell32/tests: Make SHChangeNotify tests more easily extendible.
---
dlls/shell32/tests/shlfolder.c | 141 ++++++++++++++++++++--------------------
1 files changed, 71 insertions(+), 70 deletions(-)
diff --git a/dlls/shell32/tests/shlfolder.c b/dlls/shell32/tests/shlfolder.c
index 6294c5d..43b721d 100644
--- a/dlls/shell32/tests/shlfolder.c
+++ b/dlls/shell32/tests/shlfolder.c
@@ -71,6 +71,26 @@ static HRESULT (WINAPI *pSHGetIDListFromObject)(IUnknown*, PIDLIST_ABSOLUTE*);
static HRESULT (WINAPI *pSHGetItemFromObject)(IUnknown*,REFIID,void**);
static BOOL (WINAPI *pIsWow64Process)(HANDLE, PBOOL);
+static WCHAR *make_wstr(const char *str)
+{
+ WCHAR *ret;
+ int len;
+
+ if(!str || strlen(str) == 0)
+ return NULL;
+
+ len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
+ if(!len || len < 0)
+ return NULL;
+
+ ret = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
+ if(!ret)
+ return NULL;
+
+ MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
+ return ret;
+}
+
static int strcmp_wa(LPCWSTR strw, const char *stra)
{
CHAR buf[512];
@@ -4189,13 +4209,19 @@ static void test_ParseDisplayNamePBC(void)
static const CHAR testwindow_class[] = "testwindow";
#define WM_USER_NOTIFY (WM_APP+1)
-static struct {
- const char *id;
- BOOL exp_notify;
+struct ChNotifyTest {
+ const char id[256];
+ const UINT notify_count;
+ UINT missing_events;
UINT signal;
- const WCHAR *path_1;
- const WCHAR *path_2;
-} exp_data;
+ const char path_1[256];
+ const char path_2[256];
+} chnotify_tests[] = {
+ {"MKDIR", 1, 0, SHCNE_MKDIR, "C:\\shell32_cn_test\\test", ""},
+ {"RMDIR", 1, 0, SHCNE_RMDIR, "C:\\shell32_cn_test\\test", ""},
+};
+
+struct ChNotifyTest *exp_data;
static LRESULT CALLBACK testwindow_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
@@ -4203,20 +4229,25 @@ static LRESULT CALLBACK testwindow_wndproc(HWND hwnd, UINT msg, WPARAM wparam, L
switch(msg){
case WM_USER_NOTIFY:
- if(exp_data.exp_notify){
+ if(exp_data->missing_events > 0){
+ WCHAR *path1, *path2;
LPCITEMIDLIST *pidls = (LPCITEMIDLIST*)wparam;
- ok(exp_data.signal == signal,
+ ok(exp_data->signal == signal,
"%s: expected notification type %x, got: %x\n",
- exp_data.id, exp_data.signal, signal);
+ exp_data->id, exp_data->signal, signal);
- trace("verifying pidls for: %s\n", exp_data.id);
- verify_pidl(pidls[0], exp_data.path_1);
- verify_pidl(pidls[1], exp_data.path_2);
+ trace("verifying pidls for: %s\n", exp_data->id);
+ path1 = make_wstr(exp_data->path_1);
+ path2 = make_wstr(exp_data->path_2);
+ verify_pidl(pidls[0], path1);
+ verify_pidl(pidls[1], path2);
+ HeapFree(GetProcessHeap(), 0, path1);
+ HeapFree(GetProcessHeap(), 0, path2);
- exp_data.exp_notify = FALSE;
+ exp_data->missing_events--;
}else
- ok(exp_data.exp_notify, "Didn't expect a WM_USER_NOTIFY message (event: %x)\n", signal);
+ ok(0, "Didn't expect a WM_USER_NOTIFY message (event: %x)\n", signal);
return 0;
}
return DefWindowProc(hwnd, msg, wparam, lparam);
@@ -4244,37 +4275,31 @@ static void register_testwindow_class(void)
static void do_events(void)
{
int c = 0;
- while (exp_data.exp_notify && (c++ < 10)){
+ while (exp_data->missing_events && (c++ < 10)){
MSG msg;
while(PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)){
TranslateMessage(&msg);
DispatchMessageA(&msg);
}
- if(exp_data.exp_notify)
+ if(exp_data->missing_events)
Sleep(500);
}
- trace("%s: took %d tries\n", exp_data.id, c);
+ trace("%s: took %d tries\n", exp_data->id, c);
}
static void test_SHChangeNotify(void)
{
HWND wnd;
- ULONG notifyID;
+ ULONG notifyID, i;
HRESULT hr;
BOOL br, has_unicode;
SHChangeNotifyEntry entries[1];
const CHAR root_dirA[] = "C:\\shell32_cn_test";
const WCHAR root_dirW[] = {'C',':','\\','s','h','e','l','l','3','2','_','c','n','_','t','e','s','t',0};
- const CHAR test_dirA[] = "C:\\shell32_cn_test\\test";
- const WCHAR test_dirW[] = {'C',':','\\','s','h','e','l','l','3','2','_','c','n','_','t','e','s','t','\\','t','e','s','t',0};
CreateDirectoryW(NULL, NULL);
has_unicode = !(GetLastError() == ERROR_CALL_NOT_IMPLEMENTED);
- /* set up the root directory & window */
- br = CreateDirectoryA(root_dirA, NULL);
- ok(br == TRUE, "CreateDirectory failed: %d\n", GetLastError());
-
register_testwindow_class();
wnd = CreateWindowExA(0, testwindow_class, testwindow_class, 0,
@@ -4282,6 +4307,9 @@ static void test_SHChangeNotify(void)
NULL, NULL, GetModuleHandleA(NULL), 0);
ok(wnd != NULL, "Failed to make a window\n");
+ br = CreateDirectoryA(root_dirA, NULL);
+ ok(br == TRUE, "CreateDirectory failed: %d\n", GetLastError());
+
entries[0].pidl = NULL;
if(has_unicode)
hr = SHILCreateFromPath(root_dirW, (LPITEMIDLIST*)&entries[0].pidl, 0);
@@ -4294,55 +4322,28 @@ static void test_SHChangeNotify(void)
SHCNE_ALLEVENTS, WM_USER_NOTIFY, 1, entries);
ok(notifyID != 0, "Failed to register a window for change notifications\n");
- /* MKDIR */
- br = CreateDirectoryA(test_dirA, NULL);
- ok(br == TRUE, "CreateDirectory failed: %d\n", GetLastError());
+ for(i = 0; i < sizeof(chnotify_tests) / sizeof(*chnotify_tests); ++i){
+ exp_data = chnotify_tests + i;
- if(has_unicode){
- exp_data.id = "MKDIR PATHW";
- exp_data.signal = SHCNE_MKDIR;
- exp_data.exp_notify = TRUE;
- exp_data.path_1 = test_dirW;
- exp_data.path_2 = NULL;
- SHChangeNotify(SHCNE_MKDIR, SHCNF_PATHW | SHCNF_FLUSH, test_dirW, NULL);
+ exp_data->missing_events = exp_data->notify_count;
+ SHChangeNotify(exp_data->signal, SHCNF_PATHA | SHCNF_FLUSH,
+ strlen(exp_data->path_1) > 0 ? exp_data->path_1 : NULL,
+ strlen(exp_data->path_2) > 0 ? exp_data->path_2 : NULL);
do_events();
- ok(exp_data.exp_notify == FALSE, "Expected wndproc to be called\n");
- }else
- win_skip("skipping WCHAR tests\n");
-
- exp_data.id = "MKDIR PATHA";
- exp_data.signal = SHCNE_MKDIR;
- exp_data.exp_notify = TRUE;
- exp_data.path_1 = test_dirW;
- exp_data.path_2 = NULL;
- SHChangeNotify(SHCNE_MKDIR, SHCNF_PATHA | SHCNF_FLUSH, test_dirA, NULL);
- do_events();
- ok(exp_data.exp_notify == FALSE, "Expected wndproc to be called\n");
-
- /* RMDIR */
- br = RemoveDirectoryA(test_dirA);
- ok(br == TRUE, "RemoveDirectory failed: %d\n", GetLastError());
+ ok(exp_data->missing_events == 0, "%s: Expected wndproc to be called\n", exp_data->id);
- if(has_unicode){
- exp_data.id = "RMDIR PATHW";
- exp_data.signal = SHCNE_RMDIR;
- exp_data.exp_notify = TRUE;
- exp_data.path_1 = test_dirW;
- exp_data.path_2 = NULL;
- SHChangeNotify(SHCNE_RMDIR, SHCNF_PATHW | SHCNF_FLUSH, test_dirW, NULL);
- do_events();
- ok(exp_data.exp_notify == FALSE, "Expected wndproc to be called\n");
- }else
- win_skip("skipping WCHAR tests\n");
-
- exp_data.id = "RMDIR PATHA";
- exp_data.signal = SHCNE_RMDIR;
- exp_data.exp_notify = TRUE;
- exp_data.path_1 = test_dirW;
- exp_data.path_2 = NULL;
- SHChangeNotify(SHCNE_RMDIR, SHCNF_PATHA | SHCNF_FLUSH, test_dirA, NULL);
- do_events();
- ok(exp_data.exp_notify == FALSE, "Expected wndproc to be called\n");
+ if(has_unicode){
+ WCHAR *path1, *path2;
+
+ path1 = make_wstr(exp_data->path_1);
+ path2 = make_wstr(exp_data->path_2);
+
+ exp_data->missing_events = exp_data->notify_count;
+ SHChangeNotify(exp_data->signal, SHCNF_PATHW | SHCNF_FLUSH, path1, path2);
+ do_events();
+ ok(exp_data->missing_events == 0, "%s: Expected wndproc to be called\n", exp_data->id);
+ }
+ }
SHChangeNotifyDeregister(notifyID);
DestroyWindow(wnd);
More information about the wine-cvs
mailing list