2 * Unit test suite for comdlg32 API functions: file dialogs
4 * Copyright 2007 Google (Lei Zhang)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include <wine/test.h>
28 static UINT CALLBACK OFNHookProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
34 nmh = (LPNMHDR) lParam;
35 if( nmh->code == CDN_INITDONE)
37 PostMessage( GetParent(hDlg), WM_COMMAND, IDCANCEL, FALSE);
38 } else if (nmh->code == CDN_FOLDERCHANGE )
43 memset(buf, 0x66, sizeof(buf));
44 ret = SendMessage( GetParent(hDlg), CDM_GETFOLDERIDLIST, 5, (LPARAM)buf);
45 ok(ret > 0, "CMD_GETFOLDERIDLIST not implemented\n");
47 ok(buf[0] == 0x66 && buf[1] == 0x66, "CMD_GETFOLDERIDLIST: The buffer was touched on failure\n");
55 static void test_DialogCancel(void)
59 char szFileName[MAX_PATH] = "";
60 char szInitialDir[MAX_PATH];
62 GetWindowsDirectory(szInitialDir, MAX_PATH);
64 ZeroMemory(&ofn, sizeof(ofn));
66 ofn.lStructSize = sizeof(ofn);
68 ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
69 ofn.lpstrFile = szFileName;
70 ofn.nMaxFile = MAX_PATH;
71 ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_ENABLEHOOK;
72 ofn.lpstrDefExt = "txt";
73 ofn.lpfnHook = (LPOFNHOOKPROC) OFNHookProc;
74 ofn.lpstrInitialDir = szInitialDir;
77 ok(CDERR_INITIALIZATION == CommDlgExtendedError(), "expected %d, got %d\n",
78 CDERR_INITIALIZATION, CommDlgExtendedError());
80 result = GetOpenFileNameA(&ofn);
81 ok(0 == result, "expected %d, got %d\n", 0, result);
82 ok(0 == CommDlgExtendedError(), "expected %d, got %d\n", 0,
83 CommDlgExtendedError());
86 ok(CDERR_INITIALIZATION == CommDlgExtendedError(), "expected %d, got %d\n",
87 CDERR_INITIALIZATION, CommDlgExtendedError());
89 result = GetSaveFileNameA(&ofn);
90 ok(0 == result, "expected %d, got %d\n", 0, result);
91 ok(0 == CommDlgExtendedError(), "expected %d, got %d\n", 0,
92 CommDlgExtendedError());
95 ok(CDERR_INITIALIZATION == CommDlgExtendedError(), "expected %d, got %d\n",
96 CDERR_INITIALIZATION, CommDlgExtendedError());
98 /* Before passing the ofn to Unicode functions, remove the ANSI strings */
99 ofn.lpstrFilter = NULL;
100 ofn.lpstrInitialDir = NULL;
101 ofn.lpstrDefExt = NULL;
104 ok(CDERR_INITIALIZATION == CommDlgExtendedError(), "expected %d, got %d\n",
105 CDERR_INITIALIZATION, CommDlgExtendedError());
107 SetLastError(0xdeadbeef);
108 result = GetOpenFileNameW((LPOPENFILENAMEW) &ofn);
109 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
110 skip("GetOpenFileNameW is not implemented\n");
113 ok(0 == result, "expected %d, got %d\n", 0, result);
114 ok(0 == CommDlgExtendedError() ||
115 CDERR_INITIALIZATION == CommDlgExtendedError(), /* win9x */
116 "expected %d or %d, got %d\n", 0, CDERR_INITIALIZATION,
117 CommDlgExtendedError());
120 SetLastError(0xdeadbeef);
121 result = GetSaveFileNameW((LPOPENFILENAMEW) &ofn);
122 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
123 skip("GetSaveFileNameW is not implemented\n");
126 ok(0 == result, "expected %d, got %d\n", 0, result);
127 ok(0 == CommDlgExtendedError() ||
128 CDERR_INITIALIZATION == CommDlgExtendedError(), /* win9x */
129 "expected %d or %d, got %d\n", 0, CDERR_INITIALIZATION,
130 CommDlgExtendedError());