ReactOS 0.4.17-dev-696-g5483dc0
SetupDiGetActualModelsSection.c File Reference
#include <apitest.h>
#include <stdio.h>
#include <windef.h>
#include <winbase.h>
#include <winreg.h>
#include <winuser.h>
#include <setupapi.h>
Include dependency graph for SetupDiGetActualModelsSection.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 

Functions

static void create_test_inf (LPCSTR filename)
 
static void test_SetupDiGetActualModelsSectionW (void)
 
static void test_SetupDiGetActualModelsSectionA (void)
 
 START_TEST (SetupDiGetActualModelsSection)
 

Variables

static const char TestInfData []
 

Macro Definition Documentation

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 10 of file SetupDiGetActualModelsSection.c.

Function Documentation

◆ create_test_inf()

static void create_test_inf ( LPCSTR  filename)
static

Definition at line 45 of file SetupDiGetActualModelsSection.c.

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}
static const char TestInfData[]
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
#define CloseHandle
Definition: compat.h:739
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:740
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
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
unsigned long DWORD
Definition: ntddk_ex.h:95
const char * filename
Definition: ioapi.h:137
#define CREATE_ALWAYS
Definition: disk.h:72
_In_ HANDLE hFile
Definition: mswsock.h:90
#define GENERIC_WRITE
Definition: nt_native.h:90

Referenced by test_SetupDiGetActualModelsSectionA(), and test_SetupDiGetActualModelsSectionW().

◆ START_TEST()

Definition at line 162 of file SetupDiGetActualModelsSection.c.

163{
166}
static void test_SetupDiGetActualModelsSectionA(void)
static void test_SetupDiGetActualModelsSectionW(void)

◆ test_SetupDiGetActualModelsSectionA()

static void test_SetupDiGetActualModelsSectionA ( void  )
static

Definition at line 120 of file SetupDiGetActualModelsSection.c.

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}
static void create_test_inf(LPCSTR filename)
#define trace
Definition: atltest.h:70
Definition: bufpool.h:45
#define MAX_PATH
Definition: compat.h:34
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
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 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
unsigned int BOOL
Definition: ntddk_ex.h:94
#define INF_STYLE_WIN4
Definition: infsupp.h:43
LPSTR WINAPI lstrcatA(LPSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:123
#define ZeroMemory
Definition: minwinbase.h:31
_In_ PMEMORY_AREA _In_ PVOID _In_ BOOLEAN _Inout_ PMM_REQUIRED_RESOURCES Required
Definition: newmm.h:210
#define LINE_LEN
Definition: setupapi.h:22
VOID WINAPI SetupCloseInfFile(IN HINF InfHandle)
Definition: infsupp.c:45
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

Referenced by START_TEST().

◆ test_SetupDiGetActualModelsSectionW()

static void test_SetupDiGetActualModelsSectionW ( void  )
static

Definition at line 60 of file SetupDiGetActualModelsSection.c.

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}
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
#define lstrlenW
Definition: compat.h:750
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
#define L(x)
Definition: resources.c:13
#define wine_dbgstr_w
Definition: kernel32.h:34
short WCHAR
Definition: pedump.c:58
BOOL WINAPI SetupFindFirstLineW(IN HINF InfHandle, IN PCWSTR Section, IN PCWSTR Key, IN OUT PINFCONTEXT Context)
Definition: infsupp.c:56

Referenced by START_TEST().

Variable Documentation

◆ TestInfData

const char TestInfData[]
static
Initial value:
=
"[Version]\n"
"Signature=\"$Windows NT$\"\n"
"Class=TestClass\n"
"ClassGuid={12345678-1234-1234-1234-123456789ABC}\n"
"\n"
"[Manufacturer]\n"
"%TestMfg%=TestModels,NTx86,NTamd64,NT\n"
"\n"
"[TestModels.NTx86]\n"
"%DeviceDesc%=InstallSection,TEST\\VID_1234&PID_5678\n"
"\n"
"[TestModels.NTamd64]\n"
"%DeviceDesc%=InstallSection,TEST\\VID_1234&PID_5678\n"
"\n"
"[TestModels.NT]\n"
"%DeviceDesc%=InstallSection,TEST\\VID_1234&PID_5678\n"
"\n"
"[TestModels]\n"
"%DeviceDesc%=InstallSection,TEST\\VID_1234&PID_5678\n"
"\n"
"[InstallSection]\n"
"\n"
"[Strings]\n"
"TestMfg=\"Test Manufacturer\"\n"
"DeviceDesc=\"Test Device\"\n"

Definition at line 18 of file SetupDiGetActualModelsSection.c.

Referenced by create_test_inf().