wintrust: Use helper function for setting confidence in SoftpubCheckCert.
[wine] / dlls / comdlg32 / tests / filedlg.c
1 /*
2  * Unit test suite for comdlg32 API functions: file dialogs
3  *
4  * Copyright 2007 Google (Lei Zhang)
5  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #include <windows.h>
23 #include <wine/test.h>
24
25
26 /* ##### */
27
28 static UINT CALLBACK OFNHookProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
29 {
30     LPNMHDR nmh;
31
32     if( msg == WM_NOTIFY)
33     {
34         nmh = (LPNMHDR) lParam;
35         if( nmh->code == CDN_INITDONE)
36         {
37             PostMessage( GetParent(hDlg), WM_COMMAND, IDCANCEL, FALSE);
38         } else if (nmh->code == CDN_FOLDERCHANGE )
39         {
40             char buf[1024];
41             int ret;
42
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");
46             if (ret > 5)
47                 ok(buf[0] == 0x66 && buf[1] == 0x66, "CMD_GETFOLDERIDLIST: The buffer was touched on failure\n");
48         }
49     }
50
51     return 0;
52 }
53
54 /* bug 6829 */
55 static void test_DialogCancel(void)
56 {
57     OPENFILENAMEA ofn;
58     BOOL result;
59     char szFileName[MAX_PATH] = "";
60     char szInitialDir[MAX_PATH];
61
62     GetWindowsDirectory(szInitialDir, MAX_PATH);
63
64     ZeroMemory(&ofn, sizeof(ofn));
65
66     ofn.lStructSize = sizeof(ofn);
67     ofn.hwndOwner = NULL;
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;
75
76     PrintDlgA(NULL);
77     ok(CDERR_INITIALIZATION == CommDlgExtendedError(), "expected %d, got %d\n",
78        CDERR_INITIALIZATION, CommDlgExtendedError());
79
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());
84
85     PrintDlgA(NULL);
86     ok(CDERR_INITIALIZATION == CommDlgExtendedError(), "expected %d, got %d\n",
87               CDERR_INITIALIZATION, CommDlgExtendedError());
88
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());
93
94     PrintDlgA(NULL);
95     ok(CDERR_INITIALIZATION == CommDlgExtendedError(), "expected %d, got %d\n",
96               CDERR_INITIALIZATION, CommDlgExtendedError());
97
98     /* Before passing the ofn to Unicode functions, remove the ANSI strings */
99     ofn.lpstrFilter = NULL;
100     ofn.lpstrInitialDir = NULL;
101     ofn.lpstrDefExt = NULL;
102
103     PrintDlgA(NULL);
104     ok(CDERR_INITIALIZATION == CommDlgExtendedError(), "expected %d, got %d\n",
105               CDERR_INITIALIZATION, CommDlgExtendedError());
106
107     SetLastError(0xdeadbeef);
108     result = GetOpenFileNameW((LPOPENFILENAMEW) &ofn);
109     if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
110         skip("GetOpenFileNameW is not implemented\n");
111     else
112     {
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());
118     }
119
120     SetLastError(0xdeadbeef);
121     result = GetSaveFileNameW((LPOPENFILENAMEW) &ofn);
122     if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
123         skip("GetSaveFileNameW is not implemented\n");
124     else
125     {
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());
131     }
132 }
133
134
135 START_TEST(filedlg)
136 {
137     test_DialogCancel();
138
139 }