ReactOS 0.4.17-dev-696-g5483dc0
SetupDiGetActualModelsSection.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS API Tests
3 * LICENSE: MIT (https://spdx.org/licenses/MIT)
4 * PURPOSE: Tests for SetupDiGetActualModelsSectionA/W
5 * COPYRIGHT: Copyright 2026 Alex Mendoza <05alex.mendozaa@gmail.com>
6 */
7
8#include <apitest.h>
9
10#define WIN32_NO_STATUS
11#include <stdio.h>
12#include <windef.h>
13#include <winbase.h>
14#include <winreg.h>
15#include <winuser.h>
16#include <setupapi.h>
17
18static const char TestInfData[] =
19 "[Version]\n"
20 "Signature=\"$Windows NT$\"\n"
21 "Class=TestClass\n"
22 "ClassGuid={12345678-1234-1234-1234-123456789ABC}\n"
23 "\n"
24 "[Manufacturer]\n"
25 "%TestMfg%=TestModels,NTx86,NTamd64,NT\n"
26 "\n"
27 "[TestModels.NTx86]\n"
28 "%DeviceDesc%=InstallSection,TEST\\VID_1234&PID_5678\n"
29 "\n"
30 "[TestModels.NTamd64]\n"
31 "%DeviceDesc%=InstallSection,TEST\\VID_1234&PID_5678\n"
32 "\n"
33 "[TestModels.NT]\n"
34 "%DeviceDesc%=InstallSection,TEST\\VID_1234&PID_5678\n"
35 "\n"
36 "[TestModels]\n"
37 "%DeviceDesc%=InstallSection,TEST\\VID_1234&PID_5678\n"
38 "\n"
39 "[InstallSection]\n"
40 "\n"
41 "[Strings]\n"
42 "TestMfg=\"Test Manufacturer\"\n"
43 "DeviceDesc=\"Test Device\"\n";
44
46{
48 DWORD written;
49
52 ok(hFile != INVALID_HANDLE_VALUE, "CreateFile failed\n");
54 return;
55
56 WriteFile(hFile, TestInfData, sizeof(TestInfData) - 1, &written, NULL);
58}
59
61{
62 HINF hInf;
65 DWORD Required = 0;
66 BOOL ret;
67 char path[MAX_PATH];
68
69 GetTempPathA(sizeof(path), path);
70 lstrcatA(path, "test_models.inf");
72
74 ok(hInf != INVALID_HANDLE_VALUE, "SetupOpenInfFileA failed: %lu\n", GetLastError());
75 if (hInf == INVALID_HANDLE_VALUE)
76 {
78 return;
79 }
80
81 /* Find the manufacturer line */
82 ret = SetupFindFirstLineW(hInf, L"Manufacturer", NULL, &ctx);
83 ok(ret, "SetupFindFirstLineW failed: %lu\n", GetLastError());
84
85 /* NULL context must fail */
86 SetLastError(0xdeadbeef);
88 ok(!ret, "Expected failure with NULL Context\n");
90 "Expected ERROR_INVALID_PARAMETER, got %lu\n", GetLastError());
91
92 /* Query required size only */
93 Required = 0;
95 ok(ret, "SetupDiGetActualModelsSectionW (size query) failed: %lu\n", GetLastError());
96 ok(Required > 1, "Expected Required > 1, got %lu\n", Required);
97
98 /* Actual call */
99 ZeroMemory(Buffer, sizeof(Buffer));
100 Required = 0;
102 ok(ret, "SetupDiGetActualModelsSectionW failed: %lu\n", GetLastError());
103 ok(Buffer[0] != 0, "Expected non-empty section name\n");
104 ok(Required == lstrlenW(Buffer) + 1,
105 "Required size mismatch: %lu vs %u\n", Required, lstrlenW(Buffer) + 1);
106
107 trace("Got Models section: %s\n", wine_dbgstr_w(Buffer));
108
109 /* Too small buffer */
110 SetLastError(0xdeadbeef);
112 ok(!ret, "Expected failure with tiny buffer\n");
114 "Expected ERROR_INSUFFICIENT_BUFFER, got %lu\n", GetLastError());
115
116 SetupCloseInfFile(hInf);
118}
119
121{
122 HINF hInf;
124 char Buffer[LINE_LEN];
125 DWORD Required = 0;
126 BOOL ret;
127 char path[MAX_PATH];
128
129 GetTempPathA(sizeof(path), path);
130 lstrcatA(path, "test_models.inf");
132
134 ok(hInf != INVALID_HANDLE_VALUE, "SetupOpenInfFileA failed\n");
135 if (hInf == INVALID_HANDLE_VALUE)
136 {
138 return;
139 }
140
141 ret = SetupFindFirstLineA(hInf, "Manufacturer", NULL, &ctx);
142 ok(ret, "SetupFindFirstLineA failed\n");
143
144 /* Size query */
145 Required = 0;
147 ok(ret, "SetupDiGetActualModelsSectionA (size query) failed: %lu\n", GetLastError());
148 ok(Required > 1, "Expected Required > 1\n");
149
150 /* Actual call */
151 ZeroMemory(Buffer, sizeof(Buffer));
153 ok(ret, "SetupDiGetActualModelsSectionA failed: %lu\n", GetLastError());
154 ok(Buffer[0] != 0, "Expected non-empty section name\n");
155
156 trace("Got Models section (A): %s\n", Buffer);
157
158 SetupCloseInfFile(hInf);
160}
161
163{
166}
static void test_SetupDiGetActualModelsSectionA(void)
static void test_SetupDiGetActualModelsSectionW(void)
static const char TestInfData[]
static void create_test_inf(LPCSTR filename)
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
Definition: bufpool.h:45
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define NULL
Definition: types.h:112
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define CloseHandle
Definition: compat.h:739
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:740
#define MAX_PATH
Definition: compat.h:34
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define lstrlenW
Definition: compat.h:750
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
BOOL WINAPI WriteFile(_In_ HANDLE hFile, _In_reads_bytes_opt_(nNumberOfBytesToWrite) LPCVOID lpBuffer, _In_ DWORD nNumberOfBytesToWrite, _Out_opt_ LPDWORD lpNumberOfBytesWritten, _Inout_opt_ LPOVERLAPPED lpOverlapped)
Definition: rw.c:25
DWORD WINAPI GetTempPathA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:1973
BOOL WINAPI SetupDiGetActualModelsSectionA(_In_ PINFCONTEXT Context, _In_opt_ PSP_ALTPLATFORM_INFO AlternatePlatformInfo, _Out_writes_opt_(InfSectionWithExtSize) PSTR InfSectionWithExt, _In_ DWORD InfSectionWithExtSize, _Out_opt_ PDWORD RequiredSize, _Reserved_ PVOID Reserved)
ANSI version of SetupDiGetActualModelsSectionW.
Definition: devinst.c:725
BOOL WINAPI SetupDiGetActualModelsSectionW(_In_ PINFCONTEXT Context, _In_opt_ PSP_ALTPLATFORM_INFO AlternatePlatformInfo, _Out_writes_opt_(InfSectionWithExtSize) PWSTR InfSectionWithExt, _In_ DWORD InfSectionWithExtSize, _Out_opt_ PDWORD RequiredSize, _Reserved_ PVOID Reserved)
Returns the appropriate decorated INF Models section for a device.
Definition: devinst.c:552
BOOL WINAPI SetupFindFirstLineA(HINF hinf, PCSTR section, PCSTR key, INFCONTEXT *context)
Definition: parser.c:1571
HINF WINAPI SetupOpenInfFileA(PCSTR name, PCSTR class, DWORD style, UINT *error)
Definition: parser.c:1139
return ret
Definition: mutex.c:147
#define L(x)
Definition: resources.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
#define INF_STYLE_WIN4
Definition: infsupp.h:43
const char * filename
Definition: ioapi.h:137
#define wine_dbgstr_w
Definition: kernel32.h:34
LPSTR WINAPI lstrcatA(LPSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:123
#define ZeroMemory
Definition: minwinbase.h:31
#define CREATE_ALWAYS
Definition: disk.h:72
_In_ HANDLE hFile
Definition: mswsock.h:90
_In_ PMEMORY_AREA _In_ PVOID _In_ BOOLEAN _Inout_ PMM_REQUIRED_RESOURCES Required
Definition: newmm.h:210
#define GENERIC_WRITE
Definition: nt_native.h:90
short WCHAR
Definition: pedump.c:58
#define SetupDiGetActualModelsSection
Definition: setupapi.h:1497
#define LINE_LEN
Definition: setupapi.h:22
const char * LPCSTR
Definition: typedefs.h:52
BOOL WINAPI SetupFindFirstLineW(IN HINF InfHandle, IN PCWSTR Section, IN PCWSTR Key, IN OUT PINFCONTEXT Context)
Definition: infsupp.c:56
VOID WINAPI SetupCloseInfFile(IN HINF InfHandle)
Definition: infsupp.c:45
DWORD WINAPI GetLastError(void)
Definition: except.c:1042