2 * Unit tests for SetupIterateCabinet
4 * Copyright 2007 Hans Leidekker
5 * Copyright 2010 Andrew Nguyen
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "wine/test.h"
32 static void create_source_fileA(LPSTR filename
, const BYTE
*data
, DWORD size
)
37 handle
= CreateFileA(filename
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
38 FILE_ATTRIBUTE_NORMAL
, NULL
);
39 WriteFile(handle
, data
, size
, &written
, NULL
);
43 static void create_source_fileW(LPWSTR filename
, const BYTE
*data
, DWORD size
)
48 handle
= CreateFileW(filename
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
49 FILE_ATTRIBUTE_NORMAL
, NULL
);
50 WriteFile(handle
, data
, size
, &written
, NULL
);
54 static UINT CALLBACK
dummy_callbackA(PVOID Context
, UINT Notification
,
55 UINT_PTR Param1
, UINT_PTR Param2
)
57 ok(0, "Received unexpected notification (%p, %u, %lu, %lu)\n", Context
,
58 Notification
, Param1
, Param2
);
62 static UINT CALLBACK
dummy_callbackW(PVOID Context
, UINT Notification
,
63 UINT_PTR Param1
, UINT_PTR Param2
)
65 ok(0, "Received unexpected notification (%p, %u, %lu, %lu)\n", Context
,
66 Notification
, Param1
, Param2
);
70 static void test_invalid_parametersA(void)
73 char source
[MAX_PATH
], temp
[MAX_PATH
];
79 PSP_FILE_CALLBACK MsgHandler
;
80 DWORD expected_lasterror
;
82 } invalid_parameters
[] =
84 {NULL
, NULL
, ERROR_INVALID_PARAMETER
},
85 {NULL
, dummy_callbackA
, ERROR_INVALID_PARAMETER
},
86 {"c:\\nonexistent.cab", NULL
, ERROR_FILE_NOT_FOUND
},
87 {"c:\\nonexistent.cab", dummy_callbackA
, ERROR_FILE_NOT_FOUND
},
88 {source
, NULL
, ERROR_INVALID_DATA
, 1},
89 {source
, dummy_callbackA
, ERROR_INVALID_DATA
, 1},
92 GetTempPathA(sizeof(temp
), temp
);
93 GetTempFileNameA(temp
, "doc", 0, source
);
95 create_source_fileA(source
, NULL
, 0);
97 for (i
= 0; i
< sizeof(invalid_parameters
)/sizeof(invalid_parameters
[0]); i
++)
99 SetLastError(0xdeadbeef);
100 ret
= SetupIterateCabinetA(invalid_parameters
[i
].CabinetFile
, 0,
101 invalid_parameters
[i
].MsgHandler
, NULL
);
102 ok(!ret
, "[%d] Expected SetupIterateCabinetA to return 0, got %d\n", i
, ret
);
103 if (invalid_parameters
[i
].todo_lasterror
)
106 ok(GetLastError() == invalid_parameters
[i
].expected_lasterror
,
107 "[%d] Expected GetLastError() to return %u, got %u\n",
108 i
, invalid_parameters
[i
].expected_lasterror
, GetLastError());
112 ok(GetLastError() == invalid_parameters
[i
].expected_lasterror
,
113 "[%d] Expected GetLastError() to return %u, got %u\n",
114 i
, invalid_parameters
[i
].expected_lasterror
, GetLastError());
118 SetLastError(0xdeadbeef);
119 ret
= SetupIterateCabinetA("", 0, NULL
, NULL
);
120 ok(!ret
, "Expected SetupIterateCabinetA to return 0, got %d\n", ret
);
121 ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY
||
122 GetLastError() == ERROR_FILE_NOT_FOUND
, /* Win9x/NT4/Win2k */
123 "Expected GetLastError() to return ERROR_NOT_ENOUGH_MEMORY, got %u\n",
126 SetLastError(0xdeadbeef);
127 ret
= SetupIterateCabinetA("", 0, dummy_callbackA
, NULL
);
128 ok(!ret
, "Expected SetupIterateCabinetA to return 0, got %d\n", ret
);
129 ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY
||
130 GetLastError() == ERROR_FILE_NOT_FOUND
, /* Win9x/NT4/Win2k */
131 "Expected GetLastError() to return ERROR_NOT_ENOUGH_MEMORY, got %u\n",
137 static void test_invalid_parametersW(void)
139 static const WCHAR nonexistentW
[] = {'c',':','\\','n','o','n','e','x','i','s','t','e','n','t','.','c','a','b',0};
140 static const WCHAR docW
[] = {'d','o','c',0};
141 static const WCHAR emptyW
[] = {0};
144 WCHAR source
[MAX_PATH
], temp
[MAX_PATH
];
150 PSP_FILE_CALLBACK MsgHandler
;
151 DWORD expected_lasterror
;
153 } invalid_parameters
[] =
155 {nonexistentW
, NULL
, ERROR_FILE_NOT_FOUND
},
156 {nonexistentW
, dummy_callbackW
, ERROR_FILE_NOT_FOUND
},
157 {source
, NULL
, ERROR_INVALID_DATA
, 1},
158 {source
, dummy_callbackW
, ERROR_INVALID_DATA
, 1},
161 ret
= SetupIterateCabinetW(NULL
, 0, NULL
, NULL
);
162 if (!ret
&& GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
164 win_skip("SetupIterateCabinetW is not available\n");
168 GetTempPathW(sizeof(temp
)/sizeof(WCHAR
), temp
);
169 GetTempFileNameW(temp
, docW
, 0, source
);
171 create_source_fileW(source
, NULL
, 0);
173 for (i
= 0; i
< sizeof(invalid_parameters
)/sizeof(invalid_parameters
[0]); i
++)
175 SetLastError(0xdeadbeef);
176 ret
= SetupIterateCabinetW(invalid_parameters
[i
].CabinetFile
, 0,
177 invalid_parameters
[i
].MsgHandler
, NULL
);
178 ok(!ret
, "[%d] Expected SetupIterateCabinetW to return 0, got %d\n", i
, ret
);
179 if (invalid_parameters
[i
].todo_lasterror
)
182 ok(GetLastError() == invalid_parameters
[i
].expected_lasterror
,
183 "[%d] Expected GetLastError() to return %u, got %u\n",
184 i
, invalid_parameters
[i
].expected_lasterror
, GetLastError());
188 ok(GetLastError() == invalid_parameters
[i
].expected_lasterror
,
189 "[%d] Expected GetLastError() to return %u, got %u\n",
190 i
, invalid_parameters
[i
].expected_lasterror
, GetLastError());
194 SetLastError(0xdeadbeef);
195 ret
= SetupIterateCabinetW(NULL
, 0, NULL
, NULL
);
196 ok(!ret
, "Expected SetupIterateCabinetW to return 0, got %d\n", ret
);
197 ok(GetLastError() == ERROR_INVALID_PARAMETER
||
198 GetLastError() == ERROR_NOT_ENOUGH_MEMORY
, /* Vista/Win2k8 */
199 "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n",
202 SetLastError(0xdeadbeef);
203 ret
= SetupIterateCabinetW(NULL
, 0, dummy_callbackW
, NULL
);
204 ok(!ret
, "Expected SetupIterateCabinetW to return 0, got %d\n", ret
);
205 ok(GetLastError() == ERROR_INVALID_PARAMETER
||
206 GetLastError() == ERROR_NOT_ENOUGH_MEMORY
, /* Vista/Win2k8 */
207 "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n",
210 SetLastError(0xdeadbeef);
211 ret
= SetupIterateCabinetW(emptyW
, 0, NULL
, NULL
);
212 ok(!ret
, "Expected SetupIterateCabinetW to return 0, got %d\n", ret
);
213 ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY
||
214 GetLastError() == ERROR_FILE_NOT_FOUND
, /* NT4/Win2k */
215 "Expected GetLastError() to return ERROR_NOT_ENOUGH_MEMORY, got %u\n",
218 SetLastError(0xdeadbeef);
219 ret
= SetupIterateCabinetW(emptyW
, 0, dummy_callbackW
, NULL
);
220 ok(!ret
, "Expected SetupIterateCabinetW to return 0, got %d\n", ret
);
221 ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY
||
222 GetLastError() == ERROR_FILE_NOT_FOUND
, /* NT4/Win2k */
223 "Expected GetLastError() to return ERROR_NOT_ENOUGH_MEMORY, got %u\n",
231 test_invalid_parametersA();
232 test_invalid_parametersW();