dnsapi: Cast-qual warnings fix.
[wine] / dlls / setupapi / tests / devinst.c
1 /*
2  * Devinst tests
3  *
4  * Copyright 2006 Christian Gmeiner
5  *
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.
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  * Lesser General Public License for more details.
15  *
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
19  */
20
21 #include <assert.h>
22 #include <stdarg.h>
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "winuser.h"
28 #include "winreg.h"
29 #include "setupapi.h"
30
31 #include "wine/test.h"
32
33 /* function pointers */
34 static HMODULE hSetupAPI;
35 static HDEVINFO (WINAPI *pSetupDiCreateDeviceInfoListExW)(GUID*,HWND,PCWSTR,PVOID);
36 static BOOL     (WINAPI *pSetupDiDestroyDeviceInfoList)(HDEVINFO);
37
38 static void init_function_pointers(void)
39 {
40     hSetupAPI = LoadLibraryA("setupapi.dll");
41
42     if (hSetupAPI)
43     {
44         pSetupDiCreateDeviceInfoListExW = (void *)GetProcAddress(hSetupAPI, "SetupDiCreateDeviceInfoListExW");
45         pSetupDiDestroyDeviceInfoList = (void *)GetProcAddress(hSetupAPI, "SetupDiDestroyDeviceInfoList");
46     }
47 }
48
49 static void test_SetupDiCreateDeviceInfoListEx(void) 
50 {
51     HDEVINFO devlist;
52     BOOL ret;
53     DWORD error;
54     static CHAR notnull[] = "NotNull";
55     static const WCHAR machine[] = { 'd','u','m','m','y',0 };
56
57     SetLastError(0xdeadbeef);
58     /* create empty DeviceInfoList, but set Reserved to a value, which is not NULL */
59     devlist = pSetupDiCreateDeviceInfoListExW(NULL, NULL, NULL, notnull);
60
61     error = GetLastError();
62     ok(devlist == INVALID_HANDLE_VALUE, "SetupDiCreateDeviceInfoListExW failed : %p %ld (expected %p)\n", devlist, error, INVALID_HANDLE_VALUE);
63     ok(error == ERROR_INVALID_PARAMETER, "GetLastError returned wrong value : %ld, (expected %d)\n", error, ERROR_INVALID_PARAMETER);
64
65     SetLastError(0xdeadbeef);
66     /* create empty DeviceInfoList, but set MachineName to something */
67     devlist = pSetupDiCreateDeviceInfoListExW(NULL, NULL, machine, NULL);
68
69     error = GetLastError();
70     ok(devlist == INVALID_HANDLE_VALUE, "SetupDiCreateDeviceInfoListExW failed : %p %ld (expected %p)\n", devlist, error, INVALID_HANDLE_VALUE);
71     ok(error == ERROR_INVALID_MACHINENAME, "GetLastError returned wrong value : %ld, (expected %d)\n", error, ERROR_INVALID_MACHINENAME);
72
73     /* create empty DeviceInfoList */
74     devlist = pSetupDiCreateDeviceInfoListExW(NULL, NULL, NULL, NULL);
75     ok(devlist && devlist != INVALID_HANDLE_VALUE, "SetupDiCreateDeviceInfoListExW failed : %p %ld (expected != %p)\n", devlist, error, INVALID_HANDLE_VALUE);
76
77     /* destroy DeviceInfoList */
78     ret = pSetupDiDestroyDeviceInfoList(devlist);
79     ok(ret, "SetupDiDestroyDeviceInfoList failed : %ld\n", error);
80 }
81
82 START_TEST(devinst)
83 {
84     init_function_pointers();
85     if (!hSetupAPI)
86         return;
87
88     if (pSetupDiCreateDeviceInfoListExW && pSetupDiDestroyDeviceInfoList)
89         test_SetupDiCreateDeviceInfoListEx();
90     else
91         trace("Needed calls not all available, skipping tests.\n");
92 }