ReactOS  0.4.14-dev-323-g6fe6a88
SetupDiInstallClassExA.c File Reference
#include <apitest.h>
#include <stdio.h>
#include <assert.h>
#include <winuser.h>
#include <winreg.h>
#include <winsvc.h>
#include <setupapi.h>
#include <strsafe.h>
Include dependency graph for SetupDiInstallClassExA.c:

Go to the source code of this file.

Functions

static void create_inf_file (LPCSTR filename, const char *data)
 
static void test_SetupDiInstallClassExA (void)
 
 START_TEST (SetupDiInstallClassExA)
 

Variables

static const char inffile [] = "test.inf"
 
static char CURR_DIR [MAX_PATH]
 

Function Documentation

◆ create_inf_file()

static void create_inf_file ( LPCSTR  filename,
const char data 
)
static

Definition at line 35 of file SetupDiInstallClassExA.c.

36 {
37  DWORD res;
38  BOOL ret;
43  assert(ret != 0);
45 }
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 CloseHandle
Definition: compat.h:398
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
#define assert(x)
Definition: debug.h:53
const char * filename
Definition: ioapi.h:135
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GENERIC_WRITE
Definition: nt_native.h:90
smooth NULL
Definition: ftsmooth.c:416
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
int ret
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
#define CREATE_ALWAYS
Definition: disk.h:72
GLuint res
Definition: glext.h:9613
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:399

Referenced by test_SetupDiInstallClassExA().

◆ START_TEST()

START_TEST ( SetupDiInstallClassExA  )

Definition at line 277 of file SetupDiInstallClassExA.c.

278 {
279  char temp_path[MAX_PATH], prev_path[MAX_PATH];
280  DWORD len;
281 
282  GetCurrentDirectoryA(MAX_PATH, prev_path);
285 
287  len = strlen(CURR_DIR);
288  if (len && (CURR_DIR[len - 1] == '\\'))
289  CURR_DIR[len - 1] = 0;
290 
292  SetCurrentDirectoryA(prev_path);
293 
294 }
static void test_SetupDiInstallClassExA(void)
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
static char CURR_DIR[MAX_PATH]
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL WINAPI SetCurrentDirectoryA(IN LPCSTR lpPathName)
Definition: path.c:2205
GLenum GLsizei len
Definition: glext.h:6722
DWORD WINAPI GetTempPathA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2053
DWORD WINAPI GetCurrentDirectoryA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2145
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
char temp_path[MAX_PATH]
Definition: mspatcha.c:123

◆ test_SetupDiInstallClassExA()

static void test_SetupDiInstallClassExA ( void  )
static

Definition at line 47 of file SetupDiInstallClassExA.c.

48 {
49  char inf[2048];
50  char path[MAX_PATH];
51  BOOL ret;
52  ULONG del;
54  HINF infhandle;
55  SC_HANDLE scm_handle, svc_handle;
56 
57  /* [Version]:Signature */
58  strcpy(inf, "[Version]\nSignature=\"$Chicago$\"\n");
60  StringCbPrintfA(path, sizeof(path), "%s\\%s", CURR_DIR, inffile);
61 
62  SetLastError(0xdeadbeef);
64  ok(!ret, "Expected failure\n");
66  "Expected ERROR_INVALID_CLASS, got %08x\n", (int)GetLastError());
68 
69  /* [Version]:Signature+Class */
70  strcat(inf, "Class=MySampleClass\n");
72  StringCbPrintfA(path, sizeof(path), "%s\\%s", CURR_DIR, inffile);
73 
74  SetLastError(0xdeadbeef);
76  ok(!ret, "Expected failure\n");
78  "Expected ERROR_INVALID_CLASS, got %08x\n", (int)GetLastError());
80 
81  /* [Version]:Signature+Class+ClassGUID */
82  strcat(inf, "ClassGuid={3b409830-5f9d-432a-abf5-7d2e4e102467}\n");
84  StringCbPrintfA(path, sizeof(path), "%s\\%s", CURR_DIR, inffile);
85 
86  SetLastError(0xdeadbeef);
88  ok(!ret, "Expected failure\n");
90  "Expected ERROR_SECTION_NOT_FOUND, got %08x\n", (int)GetLastError());
92 
93  /* [Version]Signature+Class+ClassGUID;[ClassInstall32.NT]Empty */
94  strcat(inf, "[ClassInstall32.NT]\n");
96  StringCbPrintfA(path, sizeof(path), "%s\\%s", CURR_DIR, inffile);
97 
98  SetLastError(0xdeadbeef);
100  ok(ret, "Expected success\n");
101  ok(!GetLastError(),
102  "Expected no error, got %08x\n", (int)GetLastError());
104  if (ret == TRUE)
105  {
107  del = RegDeleteKeyW(RegHandle, L"CurrentControlSet\\Control\\Class\\{3B409830-5F9D-432A-ABF5-7D2E4E102467}");
108  ok(del == ERROR_SUCCESS, "Expected success \n");
109  }
110 
111  /* [Version]Signature+Class+ClassGUID;[ClassInstall32.NT]AddReg */
112  strcat(inf, "AddReg=SampleClassAddReg\n");
113  create_inf_file(inffile, inf);
114  StringCbPrintfA(path, sizeof(path), "%s\\%s", CURR_DIR, inffile);
115 
116  SetLastError(0xdeadbeef);
118  ok(ret, "Expected success\n");
119  ok(!GetLastError(),
120  "Expected no error, got %08x\n", (int)GetLastError());
122  if (ret == TRUE)
123  {
125  del = RegDeleteKeyW(RegHandle, L"CurrentControlSet\\Control\\Class\\{3B409830-5F9D-432A-ABF5-7D2E4E102467}");
126  ok(del == ERROR_SUCCESS, "Expected success \n");
127  }
128 
129  /* [Version]Signature+Class+ClassGUID;[ClassInstall32.NT]AddReg; [SampleClassAddReg];*/
130  strcat(inf, "[SampleClassAddReg]\n");
131  create_inf_file(inffile, inf);
132  StringCbPrintfA(path, sizeof(path), "%s\\%s", CURR_DIR, inffile);
133 
134  SetLastError(0xdeadbeef);
136  ok(ret, "Expected success\n");
137  ok(!GetLastError(),
138  "Expected no error, got %08x\n", (int)GetLastError());
140  if (ret == TRUE)
141  {
143  del = RegDeleteKeyW(RegHandle, L"CurrentControlSet\\Control\\Class\\{3B409830-5F9D-432A-ABF5-7D2E4E102467}");
144  ok(del == ERROR_SUCCESS, "Expected success \n");
145  }
146 
147  /* [Version]Signature+Class+ClassGUID;[ClassInstall32.NT]AddReg; [SampleClassAddReg]HKR;*/
148  strcat(inf, "HKR,,,,\"ReactOS Test SetupDiInstallClassExA\"\n");
149  create_inf_file(inffile, inf);
150  StringCbPrintfA(path, sizeof(path), "%s\\%s", CURR_DIR, inffile);
151 
152  SetLastError(0xdeadbeef);
154  ok(ret, "Expected success\n");
155  ok(!GetLastError(),
156  "Expected no error, got %08x\n", (int)GetLastError());
158  if (ret == TRUE)
159  {
161  del = RegDeleteKeyW(RegHandle, L"CurrentControlSet\\Control\\Class\\{3B409830-5F9D-432A-ABF5-7D2E4E102467}");
162  ok(del == ERROR_SUCCESS, "Expected success \n");
163  }
164 
165  /*[Version]Signature+Class+ClassGUID;[ClassInstall32.NT]AddReg;[SampleClassAddReg]HKR;[ClassInstall32.NT.Services]*/
166  strcat(inf, "[ClassInstall32.NT.Services]\n");
167  create_inf_file(inffile, inf);
168  StringCbPrintfA(path, sizeof(path), "%s\\%s", CURR_DIR, inffile);
169 
170  SetLastError(0xdeadbeef);
172  ok(ret, "Expected success\n");
173  ok(!GetLastError(),
174  "Expected no error, got %08x\n", (int)GetLastError());
176  if (ret == TRUE)
177  {
179  del = RegDeleteKeyW(RegHandle, L"CurrentControlSet\\Control\\Class\\{3B409830-5F9D-432A-ABF5-7D2E4E102467}");
180  ok(del == ERROR_SUCCESS, "Expected success\n");
181  }
182 
183  /* Add a reference */
184  strcat(inf, "AddService=Reactostest,,Reactostest.Service\n");
185  create_inf_file(inffile, inf);
187  SetLastError(0xdeadbeef);
189  ok(!ret, "Expected failure\n");
191  "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", (int)GetLastError());
192  SetupCloseInfFile(infhandle);
194 
195  /* Add the section */
196  strcat(inf, "[Reactostest.Service]\n");
197  create_inf_file(inffile, inf);
199  SetLastError(0xdeadbeef);
201  ok(!ret, "Expected failure\n");
203  "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", (int)GetLastError());
204  SetupCloseInfFile(infhandle);
206 
207  /* Just the ServiceBinary */
208  strcat(inf, "ServiceBinary=%12%\\reactostest.sys\n");
209  create_inf_file(inffile, inf);
211  SetLastError(0xdeadbeef);
213  ok(!ret, "Expected failure\n");
215  "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", (int)GetLastError());
216  SetupCloseInfFile(infhandle);
218 
219  /* Add the ServiceType */
220  strcat(inf, "ServiceType=1\n");
221  create_inf_file(inffile, inf);
223  SetLastError(0xdeadbeef);
225  ok(!ret, "Expected failure\n");
227  "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", (int)GetLastError());
228  SetupCloseInfFile(infhandle);
230 
231  /* Add the StartType */
232  strcat(inf, "StartType=4\n");
233  create_inf_file(inffile, inf);
235  SetLastError(0xdeadbeef);
237  ok(!ret, "Expected failure\n");
239  "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", (int)GetLastError());
240  SetupCloseInfFile(infhandle);
242 
243  /* This should be it, the minimal entries to install a service */
244  strcat(inf, "ErrorControl=1");
245  create_inf_file(inffile, inf);
247  SetLastError(0xdeadbeef);
249  if (!ret && GetLastError() == ERROR_ACCESS_DENIED)
250  {
251  skip("Not enough rights to install the service\n");
252  SetupCloseInfFile(infhandle);
254  return;
255  }
256  ok(ret, "Expected success\n");
258  "Expected ERROR_SUCCESS, got %08x\n", (int)GetLastError());
259  SetupCloseInfFile(infhandle);
261 
263 
264  /* Open the service to see if it's really there */
265  svc_handle = OpenServiceA(scm_handle, "Reactostest", DELETE);
266  ok(svc_handle != NULL, "Service was not created\n");
267 
268  SetLastError(0xdeadbeef);
269  ret = DeleteService(svc_handle);
270  ok(ret, "Service could not be deleted : %d\n", (int)GetLastError());
271 
272  CloseServiceHandle(svc_handle);
274 }
#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 INF_STYLE_WIN4
Definition: infsupp.h:41
#define ERROR_SUCCESS
Definition: deptool.c:10
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
static SC_HANDLE scm_handle
Definition: ServiceArgs.c:20
LONG WINAPI RegDeleteKeyW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey)
Definition: reg.c:1237
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI DeleteService(SC_HANDLE hService)
Definition: scm.c:916
VOID WINAPI SetupCloseInfFile(IN HINF InfHandle)
Definition: infsupp.c:43
static char CURR_DIR[MAX_PATH]
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
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
#define ERROR_BAD_SERVICE_INSTALLSECT
Definition: setupapi.h:314
STRSAFEAPI StringCbPrintfA(STRSAFE_LPSTR pszDest, size_t cbDest, STRSAFE_LPCSTR pszFormat,...)
Definition: strsafe.h:547
#define MAX_PATH
Definition: compat.h:26
#define SetLastError(x)
Definition: compat.h:409
#define DI_QUIETINSTALL
Definition: setupapi.h:68
int ret
static const WCHAR L[]
Definition: oid.c:1250
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 KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define ERROR_INVALID_CLASS
Definition: setupapi.h:297
#define ok(value,...)
Definition: atltest.h:57
Definition: services.c:325
SC_HANDLE WINAPI OpenServiceA(SC_HANDLE hSCManager, LPCSTR lpServiceName, DWORD dwDesiredAccess)
Definition: scm.c:2055
#define skip(...)
Definition: atltest.h:64
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:3366
#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

Referenced by START_TEST().

Variable Documentation

◆ CURR_DIR

char CURR_DIR[MAX_PATH]
static

Definition at line 31 of file SetupDiInstallClassExA.c.

Referenced by START_TEST(), and test_SetupDiInstallClassExA().

◆ inffile

const char inffile[] = "test.inf"
static

Definition at line 30 of file SetupDiInstallClassExA.c.

Referenced by test_get_inf_class(), and test_SetupDiInstallClassExA().