4 * Copyright 2007 James Hawkins
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
31 #include "wine/test.h"
33 static CHAR CURR_DIR[MAX_PATH];
36 * - fails if not administrator
37 * - what if it's not a .inf file?
38 * - copied to %windir%/Inf
39 * - SourceInfFileName should be a full path
40 * - SourceInfFileName should be <= MAX_PATH
44 static void append_str(char **str, const char *data)
50 static void create_inf_file(LPCSTR filename)
54 DWORD dwNumberOfBytesWritten;
55 HANDLE hf = CreateFile(filename, GENERIC_WRITE, 0, NULL,
56 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
58 append_str(&ptr, "[Version]\n");
59 append_str(&ptr, "Signature=\"$Chicago$\"\n");
60 append_str(&ptr, "AdvancedINF=2.5\n");
61 append_str(&ptr, "[DefaultInstall]\n");
62 append_str(&ptr, "RegisterOCXs=RegisterOCXsSection\n");
63 append_str(&ptr, "[RegisterOCXsSection]\n");
64 append_str(&ptr, "%%11%%\\ole32.dll\n");
66 WriteFile(hf, data, ptr - data, &dwNumberOfBytesWritten, NULL);
70 static void get_temp_filename(LPSTR path)
75 GetTempFileName(CURR_DIR, "set", 0, temp);
76 ptr = strrchr(temp, '\\');
78 lstrcpy(path, ptr + 1);
81 static BOOL file_exists(LPSTR path)
83 return GetFileAttributes(path) != INVALID_FILE_ATTRIBUTES;
86 static BOOL check_format(LPSTR path, LPSTR inf)
91 static const CHAR format[] = "\\INF\\oem";
93 GetWindowsDirectory(check, MAX_PATH);
94 lstrcat(check, format);
95 res = !strncasecmp(check, path, lstrlen(check)) &&
96 path[lstrlen(check)] != '\\';
98 return (!inf) ? res : res && (inf == path + lstrlen(check) - 3);
101 static void test_SetupCopyOEMInf(void)
103 CHAR toolong[MAX_PATH * 2];
104 CHAR path[MAX_PATH], dest[MAX_PATH];
105 CHAR tmpfile[MAX_PATH], dest_save[MAX_PATH];
110 /* try NULL SourceInfFileName */
111 SetLastError(0xdeadbeef);
112 res = SetupCopyOEMInf(NULL, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
113 ok(res == FALSE, "Expected FALSE, got %d\n", res);
114 ok(GetLastError() == ERROR_INVALID_PARAMETER,
115 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
117 /* try empty SourceInfFileName */
118 SetLastError(0xdeadbeef);
119 res = SetupCopyOEMInf("", NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
120 ok(res == FALSE, "Expected FALSE, got %d\n", res);
121 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
122 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
124 /* try a relative nonexistent SourceInfFileName */
125 SetLastError(0xdeadbeef);
126 res = SetupCopyOEMInf("nonexistent", NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
127 ok(res == FALSE, "Expected FALSE, got %d\n", res);
128 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
129 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
131 /* try an absolute nonexistent SourceInfFileName */
132 lstrcpy(path, CURR_DIR);
133 lstrcat(path, "\\nonexistent");
134 SetLastError(0xdeadbeef);
135 res = SetupCopyOEMInf(path, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
136 ok(res == FALSE, "Expected FALSE, got %d\n", res);
137 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
138 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
140 /* try a long SourceInfFileName */
141 memset(toolong, 'a', MAX_PATH * 2);
142 toolong[MAX_PATH * 2 - 1] = '\0';
143 SetLastError(0xdeadbeef);
144 res = SetupCopyOEMInf(toolong, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
145 ok(res == FALSE, "Expected FALSE, got %d\n", res);
146 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
147 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
149 get_temp_filename(tmpfile);
150 create_inf_file(tmpfile);
152 /* try a relative SourceInfFileName */
153 SetLastError(0xdeadbeef);
154 res = SetupCopyOEMInf(tmpfile, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
155 ok(res == FALSE, "Expected FALSE, got %d\n", res);
156 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
157 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
158 ok(file_exists(tmpfile), "Expected tmpfile to exist\n");
160 /* try SP_COPY_REPLACEONLY, dest does not exist */
161 SetLastError(0xdeadbeef);
162 res = SetupCopyOEMInf(path, NULL, SPOST_NONE, SP_COPY_REPLACEONLY, NULL, 0, NULL, NULL);
163 ok(res == FALSE, "Expected FALSE, got %d\n", res);
164 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
165 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
166 ok(file_exists(tmpfile), "Expected source inf to exist\n");
168 /* try an absolute SourceInfFileName, without DestinationInfFileName */
169 lstrcpy(path, CURR_DIR);
171 lstrcat(path, tmpfile);
172 SetLastError(0xdeadbeef);
173 res = SetupCopyOEMInf(path, NULL, SPOST_NONE, 0, NULL, 0, NULL, NULL);
174 ok(res == TRUE, "Expected TRUE, got %d\n", res);
175 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
176 ok(file_exists(path), "Expected source inf to exist\n");
178 /* try SP_COPY_REPLACEONLY, dest exists */
179 SetLastError(0xdeadbeef);
180 res = SetupCopyOEMInf(path, NULL, SPOST_NONE, SP_COPY_REPLACEONLY, NULL, 0, NULL, NULL);
181 ok(res == TRUE, "Expected TRUE, got %d\n", res);
182 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
183 ok(file_exists(path), "Expected source inf to exist\n");
185 /* try SP_COPY_NOOVERWRITE */
186 SetLastError(0xdeadbeef);
187 res = SetupCopyOEMInf(path, NULL, SPOST_NONE, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
188 ok(res == FALSE, "Expected FALSE, got %d\n", res);
189 ok(GetLastError() == ERROR_FILE_EXISTS,
190 "Expected ERROR_FILE_EXISTS, got %d\n", GetLastError());
192 /* get the DestinationInfFileName */
193 SetLastError(0xdeadbeef);
194 res = SetupCopyOEMInf(path, NULL, SPOST_NONE, 0, dest, MAX_PATH, NULL, NULL);
195 ok(res == TRUE, "Expected TRUE, got %d\n", res);
196 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
197 ok(lstrlen(dest) != 0, "Expected a non-zero length string\n");
198 ok(file_exists(dest), "Expected destination inf to exist\n");
199 ok(check_format(dest, NULL), "Expected %%windir%%\\inf\\OEMx.inf, got %s\n", dest);
200 ok(file_exists(path), "Expected source inf to exist\n");
202 lstrcpy(dest_save, dest);
203 DeleteFile(dest_save);
205 /* get the DestinationInfFileName, DestinationInfFileNameSize is too small
206 * - inf is still copied
208 lstrcpy(dest, "aaa");
210 SetLastError(0xdeadbeef);
211 res = SetupCopyOEMInf(path, NULL, SPOST_NONE, 0, dest, 5, &size, NULL);
212 ok(res == FALSE, "Expected FALSE, got %d\n", res);
213 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
214 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
215 ok(file_exists(path), "Expected source inf to exist\n");
216 ok(file_exists(dest_save), "Expected dest inf to exist\n");
217 ok(!lstrcmp(dest, "aaa"), "Expected dest to be unchanged\n");
218 ok(size == lstrlen(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n");
220 /* get the DestinationInfFileName and DestinationInfFileNameSize */
221 SetLastError(0xdeadbeef);
222 res = SetupCopyOEMInf(path, NULL, SPOST_NONE, 0, dest, MAX_PATH, &size, NULL);
223 ok(res == TRUE, "Expected TRUE, got %d\n", res);
224 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
225 ok(lstrlen(dest) + 1 == size, "Expected sizes to match, got (%d, %d)\n", lstrlen(dest), size);
226 ok(file_exists(dest), "Expected destination inf to exist\n");
227 ok(check_format(dest, NULL), "Expected %%windir%%\\inf\\OEMx.inf, got %s\n", dest);
228 ok(file_exists(path), "Expected source inf to exist\n");
229 ok(size == lstrlen(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n");
231 /* get the DestinationInfFileName, DestinationInfFileNameSize, and DestinationInfFileNameComponent */
232 SetLastError(0xdeadbeef);
233 res = SetupCopyOEMInf(path, NULL, SPOST_NONE, 0, dest, MAX_PATH, &size, &inf);
234 ok(res == TRUE, "Expected TRUE, got %d\n", res);
235 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
236 ok(lstrlen(dest) + 1 == size, "Expected sizes to match, got (%d, %d)\n", lstrlen(dest), size);
237 ok(file_exists(dest), "Expected destination inf to exist\n");
238 ok(check_format(dest, inf), "Expected %%windir%%\\inf\\OEMx.inf, got %s\n", dest);
239 ok(file_exists(path), "Expected source inf to exist\n");
240 ok(size == lstrlen(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n");
242 /* try SP_COPY_DELETESOURCE */
243 SetLastError(0xdeadbeef);
244 res = SetupCopyOEMInf(path, NULL, SPOST_NONE, SP_COPY_DELETESOURCE, NULL, 0, NULL, NULL);
245 ok(res == TRUE, "Expected TRUE, got %d\n", res);
246 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
247 ok(!file_exists(path), "Expected source inf to not exist\n");
252 GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
254 test_SetupCopyOEMInf();