4 * Copyright 2006 Christian Gmeiner
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
32 #include "wine/test.h"
34 /* function pointers */
35 static HMODULE hSetupAPI
;
36 static HDEVINFO (WINAPI
*pSetupDiCreateDeviceInfoListExW
)(GUID
*,HWND
,PCWSTR
,PVOID
);
37 static BOOL (WINAPI
*pSetupDiDestroyDeviceInfoList
)(HDEVINFO
);
38 static HKEY (WINAPI
*pSetupDiOpenClassRegKeyExA
)(GUID
*,REGSAM
,DWORD
,PCSTR
,PVOID
);
40 static void init_function_pointers(void)
42 hSetupAPI
= LoadLibraryA("setupapi.dll");
46 pSetupDiCreateDeviceInfoListExW
= (void *)GetProcAddress(hSetupAPI
, "SetupDiCreateDeviceInfoListExW");
47 pSetupDiDestroyDeviceInfoList
= (void *)GetProcAddress(hSetupAPI
, "SetupDiDestroyDeviceInfoList");
48 pSetupDiOpenClassRegKeyExA
= (void *)GetProcAddress(hSetupAPI
, "SetupDiOpenClassRegKeyExA");
52 static void test_SetupDiCreateDeviceInfoListEx(void)
57 static CHAR notnull
[] = "NotNull";
58 static const WCHAR machine
[] = { 'd','u','m','m','y',0 };
60 SetLastError(0xdeadbeef);
61 /* create empty DeviceInfoList, but set Reserved to a value, which is not NULL */
62 devlist
= pSetupDiCreateDeviceInfoListExW(NULL
, NULL
, NULL
, notnull
);
64 error
= GetLastError();
65 if (error
== ERROR_CALL_NOT_IMPLEMENTED
)
67 skip("SetupDiCreateDeviceInfoListExW is not implemented\n");
70 ok(devlist
== INVALID_HANDLE_VALUE
, "SetupDiCreateDeviceInfoListExW failed : %p %d (expected %p)\n", devlist
, error
, INVALID_HANDLE_VALUE
);
71 ok(error
== ERROR_INVALID_PARAMETER
, "GetLastError returned wrong value : %d, (expected %d)\n", error
, ERROR_INVALID_PARAMETER
);
73 SetLastError(0xdeadbeef);
74 /* create empty DeviceInfoList, but set MachineName to something */
75 devlist
= pSetupDiCreateDeviceInfoListExW(NULL
, NULL
, machine
, NULL
);
77 error
= GetLastError();
78 ok(devlist
== INVALID_HANDLE_VALUE
, "SetupDiCreateDeviceInfoListExW failed : %p %d (expected %p)\n", devlist
, error
, INVALID_HANDLE_VALUE
);
79 ok(error
== ERROR_INVALID_MACHINENAME
, "GetLastError returned wrong value : %d, (expected %d)\n", error
, ERROR_INVALID_MACHINENAME
);
81 /* create empty DeviceInfoList */
82 devlist
= pSetupDiCreateDeviceInfoListExW(NULL
, NULL
, NULL
, NULL
);
83 ok(devlist
&& devlist
!= INVALID_HANDLE_VALUE
, "SetupDiCreateDeviceInfoListExW failed : %p %d (expected != %p)\n", devlist
, error
, INVALID_HANDLE_VALUE
);
85 /* destroy DeviceInfoList */
86 ret
= pSetupDiDestroyDeviceInfoList(devlist
);
87 ok(ret
, "SetupDiDestroyDeviceInfoList failed : %d\n", error
);
90 static void test_SetupDiOpenClassRegKeyExA(void)
92 /* This is a unique guid for testing purposes */
93 GUID guid
= {0x6a55b5a4, 0x3f65, 0x11db, {0xb7,0x04,
94 0x00,0x11,0x95,0x5c,0x2b,0xdb}};
95 static const CHAR guidString
[] = "{6a55b5a4-3f65-11db-b704-0011955c2bdb}";
98 /* Check return value for nonexistent key */
99 hkey
= pSetupDiOpenClassRegKeyExA(&guid
, KEY_ALL_ACCESS
,
100 DIOCR_INSTALLER
, NULL
, NULL
);
101 ok(hkey
== INVALID_HANDLE_VALUE
,
102 "returned %p (expected INVALID_HANDLE_VALUE)\n", hkey
);
104 /* Test it for a key that exists */
105 hkey
= SetupDiOpenClassRegKey(NULL
, KEY_ALL_ACCESS
);
106 if (hkey
!= INVALID_HANDLE_VALUE
)
109 if (RegCreateKeyA(hkey
, guidString
, &classKey
) == ERROR_SUCCESS
)
111 RegCloseKey(classKey
);
112 SetLastError(0xdeadbeef);
113 classKey
= pSetupDiOpenClassRegKeyExA(&guid
, KEY_ALL_ACCESS
,
114 DIOCR_INSTALLER
, NULL
, NULL
);
115 ok(classKey
!= INVALID_HANDLE_VALUE
,
116 "opening class registry key failed with error %d\n",
118 if (classKey
!= INVALID_HANDLE_VALUE
)
119 RegCloseKey(classKey
);
120 RegDeleteKeyA(hkey
, guidString
);
123 trace("failed to create registry key for test\n");
126 trace("failed to open classes key\n");
131 init_function_pointers();
135 if (pSetupDiCreateDeviceInfoListExW
&& pSetupDiDestroyDeviceInfoList
)
136 test_SetupDiCreateDeviceInfoListEx();
138 trace("Needed calls for SetupDiCreateDeviceInfoListEx not all available, skipping test.\n");
140 if (pSetupDiOpenClassRegKeyExA
)
141 test_SetupDiOpenClassRegKeyExA();
143 trace("Needed call for SetupDiOpenClassRegKeyExA not available, skipping test.\n");