2 * SetupAPI device class-related functions tests
4 * Copyright 2015 Víctor Martínez (victor.martinez@reactos.org)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public Licence as
8 * published by the Free Software Foundation; either version 2 of
9 * 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 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this library; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 static const char inffile
[] = "test.inf";
30 static char CURR_DIR
[MAX_PATH
];
34 static void create_inf_file(LPCSTR filename
, const char *data
)
38 HANDLE handle
= CreateFileA(filename
, GENERIC_WRITE
, 0, NULL
,
39 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
40 assert(handle
!= INVALID_HANDLE_VALUE
);
41 ret
= WriteFile(handle
, data
, strlen(data
), &res
, NULL
);
46 static void test_SetupDiInstallClassExA(void)
54 SC_HANDLE scm_handle
, svc_handle
;
56 /* [Version]:Signature */
57 strcpy(inf
, "[Version]\nSignature=\"$Chicago$\"\n");
58 create_inf_file(inffile
, inf
);
59 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
61 SetLastError(0xdeadbeef);
62 ret
= SetupDiInstallClassExA(NULL
, path
, DI_QUIETINSTALL
, NULL
, NULL
, NULL
,NULL
);
63 ok(!ret
, "Expected failure\n");
64 ok(GetLastError() == ERROR_INVALID_CLASS
,
65 "Expected ERROR_INVALID_CLASS, got %08x\n", (int)GetLastError());
68 /* [Version]:Signature+Class */
69 strcat(inf
, "Class=MySampleClass\n");
70 create_inf_file(inffile
, inf
);
71 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
73 SetLastError(0xdeadbeef);
74 ret
= SetupDiInstallClassExA(NULL
, path
, DI_QUIETINSTALL
, NULL
, NULL
, NULL
,NULL
);
75 ok(!ret
, "Expected failure\n");
76 ok(GetLastError() == ERROR_INVALID_CLASS
,
77 "Expected ERROR_INVALID_CLASS, got %08x\n", (int)GetLastError());
80 /* [Version]:Signature+Class+ClassGUID */
81 strcat(inf
, "ClassGuid={3b409830-5f9d-432a-abf5-7d2e4e102467}\n");
82 create_inf_file(inffile
, inf
);
83 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
85 SetLastError(0xdeadbeef);
86 ret
= SetupDiInstallClassExA(NULL
, path
, DI_QUIETINSTALL
, NULL
, NULL
, NULL
,NULL
);
87 ok(!ret
, "Expected failure\n");
88 ok(GetLastError() == ERROR_SECTION_NOT_FOUND
,
89 "Expected ERROR_SECTION_NOT_FOUND, got %08x\n", (int)GetLastError());
92 /* [Version]Signature+Class+ClassGUID;[ClassInstall32.NT]Empty */
93 strcat(inf
, "[ClassInstall32.NT]\n");
94 create_inf_file(inffile
, inf
);
95 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
97 SetLastError(0xdeadbeef);
98 ret
= SetupDiInstallClassExA(NULL
, path
, DI_QUIETINSTALL
, NULL
, NULL
, NULL
,NULL
);
99 ok(ret
, "Expected success\n");
101 "Expected no error, got %08x\n", (int)GetLastError());
102 DeleteFileA(inffile
);
105 RegOpenKeyExW(HKEY_LOCAL_MACHINE
, L
"SYSTEM", 0, KEY_ALL_ACCESS
, &RegHandle
);
106 del
= RegDeleteKeyW(RegHandle
, L
"CurrentControlSet\\Control\\Class\\{3B409830-5F9D-432A-ABF5-7D2E4E102467}");
107 ok(del
== ERROR_SUCCESS
, "Expected success \n");
110 /* [Version]Signature+Class+ClassGUID;[ClassInstall32.NT]AddReg */
111 strcat(inf
, "AddReg=SampleClassAddReg\n");
112 create_inf_file(inffile
, inf
);
113 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
115 SetLastError(0xdeadbeef);
116 ret
= SetupDiInstallClassExA(NULL
, path
, DI_QUIETINSTALL
, NULL
, NULL
, NULL
,NULL
);
117 ok(ret
, "Expected success\n");
119 "Expected no error, got %08x\n", (int)GetLastError());
120 DeleteFileA(inffile
);
123 RegOpenKeyExW(HKEY_LOCAL_MACHINE
, L
"SYSTEM", 0, KEY_ALL_ACCESS
, &RegHandle
);
124 del
= RegDeleteKeyW(RegHandle
, L
"CurrentControlSet\\Control\\Class\\{3B409830-5F9D-432A-ABF5-7D2E4E102467}");
125 ok(del
== ERROR_SUCCESS
, "Expected success \n");
128 /* [Version]Signature+Class+ClassGUID;[ClassInstall32.NT]AddReg; [SampleClassAddReg];*/
129 strcat(inf
, "[SampleClassAddReg]\n");
130 create_inf_file(inffile
, inf
);
131 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
133 SetLastError(0xdeadbeef);
134 ret
= SetupDiInstallClassExA(NULL
, path
, DI_QUIETINSTALL
, NULL
, NULL
, NULL
,NULL
);
135 ok(ret
, "Expected success\n");
137 "Expected no error, got %08x\n", (int)GetLastError());
138 DeleteFileA(inffile
);
141 RegOpenKeyExW(HKEY_LOCAL_MACHINE
, L
"SYSTEM", 0, KEY_ALL_ACCESS
, &RegHandle
);
142 del
= RegDeleteKeyW(RegHandle
, L
"CurrentControlSet\\Control\\Class\\{3B409830-5F9D-432A-ABF5-7D2E4E102467}");
143 ok(del
== ERROR_SUCCESS
, "Expected success \n");
146 /* [Version]Signature+Class+ClassGUID;[ClassInstall32.NT]AddReg; [SampleClassAddReg]HKR;*/
147 strcat(inf
, "HKR,,,,\"ReactOS Test SetupDiInstallClassExA\"\n");
148 create_inf_file(inffile
, inf
);
149 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
151 SetLastError(0xdeadbeef);
152 ret
= SetupDiInstallClassExA(NULL
, path
, DI_QUIETINSTALL
, NULL
, NULL
, NULL
,NULL
);
153 ok(ret
, "Expected success\n");
155 "Expected no error, got %08x\n", (int)GetLastError());
156 DeleteFileA(inffile
);
159 RegOpenKeyExW(HKEY_LOCAL_MACHINE
, L
"SYSTEM", 0, KEY_ALL_ACCESS
, &RegHandle
);
160 del
= RegDeleteKeyW(RegHandle
, L
"CurrentControlSet\\Control\\Class\\{3B409830-5F9D-432A-ABF5-7D2E4E102467}");
161 ok(del
== ERROR_SUCCESS
, "Expected success \n");
164 /*[Version]Signature+Class+ClassGUID;[ClassInstall32.NT]AddReg;[SampleClassAddReg]HKR;[ClassInstall32.NT.Services]*/
165 strcat(inf
, "[ClassInstall32.NT.Services]\n");
166 create_inf_file(inffile
, inf
);
167 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
169 SetLastError(0xdeadbeef);
170 ret
= SetupDiInstallClassExA(NULL
, path
, DI_QUIETINSTALL
, NULL
, NULL
, NULL
,NULL
);
171 ok(ret
, "Expected success\n");
173 "Expected no error, got %08x\n", (int)GetLastError());
174 DeleteFileA(inffile
);
177 RegOpenKeyExW(HKEY_LOCAL_MACHINE
, L
"SYSTEM", 0, KEY_ALL_ACCESS
, &RegHandle
);
178 del
= RegDeleteKeyW(RegHandle
, L
"CurrentControlSet\\Control\\Class\\{3B409830-5F9D-432A-ABF5-7D2E4E102467}");
179 ok(del
== ERROR_SUCCESS
, "Expected success\n");
182 /* Add a reference */
183 strcat(inf
, "AddService=Reactostest,,Reactostest.Service\n");
184 create_inf_file(inffile
, inf
);
185 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
186 SetLastError(0xdeadbeef);
187 ret
= SetupDiInstallClassExA(NULL
, path
, DI_QUIETINSTALL
, NULL
, NULL
, NULL
,NULL
);
188 ok(!ret
, "Expected failure\n");
189 ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT
,
190 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", (int)GetLastError());
191 SetupCloseInfFile(infhandle
);
192 DeleteFileA(inffile
);
194 /* Add the section */
195 strcat(inf
, "[Reactostest.Service]\n");
196 create_inf_file(inffile
, inf
);
197 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
198 SetLastError(0xdeadbeef);
199 ret
= SetupDiInstallClassExA(NULL
, path
, DI_QUIETINSTALL
, NULL
, NULL
, NULL
,NULL
);
200 ok(!ret
, "Expected failure\n");
201 ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT
,
202 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", (int)GetLastError());
203 SetupCloseInfFile(infhandle
);
204 DeleteFileA(inffile
);
206 /* Just the ServiceBinary */
207 strcat(inf
, "ServiceBinary=%12%\\reactostest.sys\n");
208 create_inf_file(inffile
, inf
);
209 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
210 SetLastError(0xdeadbeef);
211 ret
= SetupDiInstallClassExA(NULL
, path
, DI_QUIETINSTALL
, NULL
, NULL
, NULL
,NULL
);
212 ok(!ret
, "Expected failure\n");
213 ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT
,
214 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", (int)GetLastError());
215 SetupCloseInfFile(infhandle
);
216 DeleteFileA(inffile
);
218 /* Add the ServiceType */
219 strcat(inf
, "ServiceType=1\n");
220 create_inf_file(inffile
, inf
);
221 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
222 SetLastError(0xdeadbeef);
223 ret
= SetupDiInstallClassExA(NULL
, path
, DI_QUIETINSTALL
, NULL
, NULL
, NULL
,NULL
);
224 ok(!ret
, "Expected failure\n");
225 ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT
,
226 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", (int)GetLastError());
227 SetupCloseInfFile(infhandle
);
228 DeleteFileA(inffile
);
230 /* Add the StartType */
231 strcat(inf
, "StartType=4\n");
232 create_inf_file(inffile
, inf
);
233 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
234 SetLastError(0xdeadbeef);
235 ret
= SetupDiInstallClassExA(NULL
, path
, DI_QUIETINSTALL
, NULL
, NULL
, NULL
,NULL
);
236 ok(!ret
, "Expected failure\n");
237 ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT
,
238 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", (int)GetLastError());
239 SetupCloseInfFile(infhandle
);
240 DeleteFileA(inffile
);
242 /* This should be it, the minimal entries to install a service */
243 strcat(inf
, "ErrorControl=1");
244 create_inf_file(inffile
, inf
);
245 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
246 SetLastError(0xdeadbeef);
247 ret
= SetupDiInstallClassExA(NULL
, path
, DI_QUIETINSTALL
, NULL
, NULL
, NULL
,NULL
);
248 if (!ret
&& GetLastError() == ERROR_ACCESS_DENIED
)
250 skip("Not enough rights to install the service\n");
251 SetupCloseInfFile(infhandle
);
252 DeleteFileA(inffile
);
255 ok(ret
, "Expected success\n");
256 ok(GetLastError() == ERROR_SUCCESS
,
257 "Expected ERROR_SUCCESS, got %08x\n", (int)GetLastError());
258 SetupCloseInfFile(infhandle
);
259 DeleteFileA(inffile
);
261 scm_handle
= OpenSCManagerA(NULL
, NULL
, GENERIC_ALL
);
263 /* Open the service to see if it's really there */
264 svc_handle
= OpenServiceA(scm_handle
, "Reactostest", DELETE
);
265 ok(svc_handle
!= NULL
, "Service was not created\n");
267 SetLastError(0xdeadbeef);
268 ret
= DeleteService(svc_handle
);
269 ok(ret
, "Service could not be deleted : %d\n", (int)GetLastError());
271 CloseServiceHandle(svc_handle
);
272 CloseServiceHandle(scm_handle
);
276 START_TEST(SetupDiInstallClassExA
)
278 char temp_path
[MAX_PATH
], prev_path
[MAX_PATH
];
281 GetCurrentDirectoryA(MAX_PATH
, prev_path
);
282 GetTempPathA(MAX_PATH
, temp_path
);
283 SetCurrentDirectoryA(temp_path
);
285 strcpy(CURR_DIR
, temp_path
);
286 len
= strlen(CURR_DIR
);
287 if (len
&& (CURR_DIR
[len
- 1] == '\\'))
288 CURR_DIR
[len
- 1] = 0;
290 test_SetupDiInstallClassExA();
291 SetCurrentDirectoryA(prev_path
);