ReactOS  0.4.13-dev-79-gcd489d8
SetupDiInstallClassExA.c
Go to the documentation of this file.
1 /*
2  * SetupAPI device class-related functions tests
3  *
4  * Copyright 2015 Víctor Martínez (victor.martinez@reactos.org)
5  *
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.
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  * General Public License for more details.
15  *
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
19  */
20 
21 #include <apitest.h>
22 #include <stdio.h>
23 #include <assert.h>
24 #include <winuser.h>
25 #include <winreg.h>
26 #include <winsvc.h>
27 #include <setupapi.h>
28 
29 static const char inffile[] = "test.inf";
30 static char CURR_DIR[MAX_PATH];
31 
32 /* Helpers */
33 
34 static void create_inf_file(LPCSTR filename, const char *data)
35 {
36  DWORD res;
37  BOOL ret;
42  assert(ret != 0);
44 }
45 
46 static void test_SetupDiInstallClassExA(void)
47 {
48  char inf[2048];
49  char path[MAX_PATH];
50  BOOL ret;
51  ULONG del;
53  HINF infhandle;
54  SC_HANDLE scm_handle, svc_handle;
55 
56  /* [Version]:Signature */
57  strcpy(inf, "[Version]\nSignature=\"$Chicago$\"\n");
59  sprintf(path, "%s\\%s", CURR_DIR, inffile);
60 
61  SetLastError(0xdeadbeef);
63  ok(!ret, "Expected failure\n");
65  "Expected ERROR_INVALID_CLASS, got %08x\n", (int)GetLastError());
67 
68  /* [Version]:Signature+Class */
69  strcat(inf, "Class=MySampleClass\n");
71  sprintf(path, "%s\\%s", CURR_DIR, inffile);
72 
73  SetLastError(0xdeadbeef);
75  ok(!ret, "Expected failure\n");
77  "Expected ERROR_INVALID_CLASS, got %08x\n", (int)GetLastError());
79 
80  /* [Version]:Signature+Class+ClassGUID */
81  strcat(inf, "ClassGuid={3b409830-5f9d-432a-abf5-7d2e4e102467}\n");
83  sprintf(path, "%s\\%s", CURR_DIR, inffile);
84 
85  SetLastError(0xdeadbeef);
87  ok(!ret, "Expected failure\n");
89  "Expected ERROR_SECTION_NOT_FOUND, got %08x\n", (int)GetLastError());
91 
92  /* [Version]Signature+Class+ClassGUID;[ClassInstall32.NT]Empty */
93  strcat(inf, "[ClassInstall32.NT]\n");
95  sprintf(path, "%s\\%s", CURR_DIR, inffile);
96 
97  SetLastError(0xdeadbeef);
99  ok(ret, "Expected success\n");
100  ok(!GetLastError(),
101  "Expected no error, got %08x\n", (int)GetLastError());
103  if (ret == TRUE)
104  {
106  del = RegDeleteKeyW(RegHandle, L"CurrentControlSet\\Control\\Class\\{3B409830-5F9D-432A-ABF5-7D2E4E102467}");
107  ok(del == ERROR_SUCCESS, "Expected success \n");
108  }
109 
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);
114 
115  SetLastError(0xdeadbeef);
117  ok(ret, "Expected success\n");
118  ok(!GetLastError(),
119  "Expected no error, got %08x\n", (int)GetLastError());
121  if (ret == TRUE)
122  {
124  del = RegDeleteKeyW(RegHandle, L"CurrentControlSet\\Control\\Class\\{3B409830-5F9D-432A-ABF5-7D2E4E102467}");
125  ok(del == ERROR_SUCCESS, "Expected success \n");
126  }
127 
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);
132 
133  SetLastError(0xdeadbeef);
135  ok(ret, "Expected success\n");
136  ok(!GetLastError(),
137  "Expected no error, got %08x\n", (int)GetLastError());
139  if (ret == TRUE)
140  {
142  del = RegDeleteKeyW(RegHandle, L"CurrentControlSet\\Control\\Class\\{3B409830-5F9D-432A-ABF5-7D2E4E102467}");
143  ok(del == ERROR_SUCCESS, "Expected success \n");
144  }
145 
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);
150 
151  SetLastError(0xdeadbeef);
153  ok(ret, "Expected success\n");
154  ok(!GetLastError(),
155  "Expected no error, got %08x\n", (int)GetLastError());
157  if (ret == TRUE)
158  {
160  del = RegDeleteKeyW(RegHandle, L"CurrentControlSet\\Control\\Class\\{3B409830-5F9D-432A-ABF5-7D2E4E102467}");
161  ok(del == ERROR_SUCCESS, "Expected success \n");
162  }
163 
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);
168 
169  SetLastError(0xdeadbeef);
171  ok(ret, "Expected success\n");
172  ok(!GetLastError(),
173  "Expected no error, got %08x\n", (int)GetLastError());
175  if (ret == TRUE)
176  {
178  del = RegDeleteKeyW(RegHandle, L"CurrentControlSet\\Control\\Class\\{3B409830-5F9D-432A-ABF5-7D2E4E102467}");
179  ok(del == ERROR_SUCCESS, "Expected success\n");
180  }
181 
182  /* Add a reference */
183  strcat(inf, "AddService=Reactostest,,Reactostest.Service\n");
184  create_inf_file(inffile, inf);
186  SetLastError(0xdeadbeef);
188  ok(!ret, "Expected failure\n");
190  "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", (int)GetLastError());
191  SetupCloseInfFile(infhandle);
193 
194  /* Add the section */
195  strcat(inf, "[Reactostest.Service]\n");
196  create_inf_file(inffile, inf);
198  SetLastError(0xdeadbeef);
200  ok(!ret, "Expected failure\n");
202  "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", (int)GetLastError());
203  SetupCloseInfFile(infhandle);
205 
206  /* Just the ServiceBinary */
207  strcat(inf, "ServiceBinary=%12%\\reactostest.sys\n");
208  create_inf_file(inffile, inf);
210  SetLastError(0xdeadbeef);
212  ok(!ret, "Expected failure\n");
214  "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", (int)GetLastError());
215  SetupCloseInfFile(infhandle);
217 
218  /* Add the ServiceType */
219  strcat(inf, "ServiceType=1\n");
220  create_inf_file(inffile, inf);
222  SetLastError(0xdeadbeef);
224  ok(!ret, "Expected failure\n");
226  "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", (int)GetLastError());
227  SetupCloseInfFile(infhandle);
229 
230  /* Add the StartType */
231  strcat(inf, "StartType=4\n");
232  create_inf_file(inffile, inf);
234  SetLastError(0xdeadbeef);
236  ok(!ret, "Expected failure\n");
238  "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", (int)GetLastError());
239  SetupCloseInfFile(infhandle);
241 
242  /* This should be it, the minimal entries to install a service */
243  strcat(inf, "ErrorControl=1");
244  create_inf_file(inffile, inf);
246  SetLastError(0xdeadbeef);
248  if (!ret && GetLastError() == ERROR_ACCESS_DENIED)
249  {
250  skip("Not enough rights to install the service\n");
251  SetupCloseInfFile(infhandle);
253  return;
254  }
255  ok(ret, "Expected success\n");
257  "Expected ERROR_SUCCESS, got %08x\n", (int)GetLastError());
258  SetupCloseInfFile(infhandle);
260 
262 
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");
266 
267  SetLastError(0xdeadbeef);
268  ret = DeleteService(svc_handle);
269  ok(ret, "Service could not be deleted : %d\n", (int)GetLastError());
270 
271  CloseServiceHandle(svc_handle);
273 }
274 
275 
277 {
278  char temp_path[MAX_PATH], prev_path[MAX_PATH];
279  DWORD len;
280 
281  GetCurrentDirectoryA(MAX_PATH, prev_path);
284 
286  len = strlen(CURR_DIR);
287  if (len && (CURR_DIR[len - 1] == '\\'))
288  CURR_DIR[len - 1] = 0;
289 
291  SetCurrentDirectoryA(prev_path);
292 
293 }
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
#define GENERIC_ALL
Definition: nt_native.h:92
#define ERROR_SECTION_NOT_FOUND
Definition: setupapi.h:288
#define TRUE
Definition: types.h:120
static void create_inf_file(LPCSTR filename, const char *data)
#define CloseHandle
Definition: compat.h:398
#define INF_STYLE_WIN4
Definition: infsupp.h:41
#define ERROR_SUCCESS
Definition: deptool.c:10
static void test_SetupDiInstallClassExA(void)
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
static SC_HANDLE scm_handle
Definition: ServiceArgs.c:20
START_TEST(SetupDiInstallClassExA)
LONG WINAPI RegDeleteKeyW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey)
Definition: reg.c:1240
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
#define assert(x)
Definition: debug.h:53
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI DeleteService(SC_HANDLE hService)
Definition: scm.c:916
const char * filename
Definition: ioapi.h:135
VOID WINAPI SetupCloseInfFile(IN HINF InfHandle)
Definition: infsupp.c:43
static char CURR_DIR[MAX_PATH]
#define sprintf(buf, format,...)
Definition: sprintf.c:55
SC_HANDLE WINAPI OpenSCManagerA(LPCSTR lpMachineName, LPCSTR lpDatabaseName, DWORD dwDesiredAccess)
Definition: scm.c:1967
#define ERROR_ACCESS_DENIED
Definition: compat.h:87
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GENERIC_WRITE
Definition: nt_native.h:90
#define ok(value,...)
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:577
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
_In_opt_ PETWENABLECALLBACK _In_opt_ PVOID _Out_ PREGHANDLE RegHandle
Definition: wmifuncs.h:76
const char * LPCSTR
Definition: xmlstorage.h:183
#define ERROR_BAD_SERVICE_INSTALLSECT
Definition: setupapi.h:314
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:409
#define DI_QUIETINSTALL
Definition: setupapi.h:68
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
int ret
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
static const WCHAR L[]
Definition: oid.c:1250
BOOL WINAPI SetCurrentDirectoryA(IN LPCSTR lpPathName)
Definition: path.c:2205
GLenum GLsizei len
Definition: glext.h:6722
HINF WINAPI SetupOpenInfFileA(PCSTR name, PCSTR class, DWORD style, UINT *error)
Definition: parser.c:1139
static const char inffile[]
static VOID del(LPHIST_ENTRY item)
Definition: history.c:199
#define CREATE_ALWAYS
Definition: disk.h:72
DWORD WINAPI GetTempPathA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2053
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define ERROR_INVALID_CLASS
Definition: setupapi.h:297
DWORD WINAPI GetCurrentDirectoryA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2145
Definition: services.c:325
#define skip(...)
SC_HANDLE WINAPI OpenServiceA(SC_HANDLE hSCManager, LPCSTR lpServiceName, DWORD dwDesiredAccess)
Definition: scm.c:2055
GLuint res
Definition: glext.h:9613
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
unsigned int ULONG
Definition: retypes.h:1
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3381
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:399
#define DELETE
Definition: nt_native.h:57
BOOL WINAPI SetupDiInstallClassExA(IN HWND hwndParent OPTIONAL, IN PCSTR InfFileName OPTIONAL, IN DWORD Flags, IN HSPFILEQ FileQueue OPTIONAL, IN CONST GUID *InterfaceClassGuid OPTIONAL, IN PVOID Reserved1, IN PVOID Reserved2)
Definition: devinst.c:3488
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
char temp_path[MAX_PATH]
Definition: mspatcha.c:123