ReactOS 0.4.16-dev-306-g647d351
query.c File Reference
#include "reg_test.h"
Include dependency graph for query.c:

Go to the source code of this file.

Macros

#define read_reg_output(c, b, s, r)   read_reg_output_(__FILE__,__LINE__,c,b,s,r)
 
#define compare_query(b, e, c, todo)   compare_query_(__FILE__,__LINE__,b,e,c,todo)
 

Functions

static void read_from_pipe (HANDLE child_proc_stdout, BYTE *buf, DWORD buf_size)
 
static BOOL read_reg_output_ (const char *file, unsigned line, const char *cmd, BYTE *buf, DWORD buf_size, DWORD *rc)
 
static void compare_query_ (const char *file, unsigned line, const BYTE *buf, const char *expected, BOOL cmp_len, DWORD todo)
 
static void test_command_syntax (void)
 
static void test_query (void)
 
 START_TEST (query)
 

Macro Definition Documentation

◆ compare_query

#define compare_query (   b,
  e,
  c,
  todo 
)    compare_query_(__FILE__,__LINE__,b,e,c,todo)

Definition at line 87 of file query.c.

◆ read_reg_output

#define read_reg_output (   c,
  b,
  s,
  r 
)    read_reg_output_(__FILE__,__LINE__,c,b,s,r)

Definition at line 38 of file query.c.

Function Documentation

◆ compare_query_()

static void compare_query_ ( const char file,
unsigned  line,
const BYTE buf,
const char expected,
BOOL  cmp_len,
DWORD  todo 
)
static

Definition at line 88 of file query.c.

90{
91 const char *str = (const char *)buf;
92 const char *err = "query output does not match expected output";
93
94 if (!cmp_len)
95 {
97 lok(!strcmp(str, expected), "%s\n", err);
98 }
99 else
100 {
102 lok(!strncmp(str, expected, strlen(expected)), "%s\n", err);
103 }
104}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define lok
Definition: registry.c:202
BOOL todo
Definition: filedlg.c:313
BOOL expected
Definition: store.c:2063
#define todo_wine_if(is_todo)
Definition: custom.c:86
#define err(...)
#define TODO_REG_COMPARE
Definition: reg_test.h:36
const WCHAR * str

◆ read_from_pipe()

static void read_from_pipe ( HANDLE  child_proc_stdout,
BYTE buf,
DWORD  buf_size 
)
static

Definition at line 22 of file query.c.

23{
24 DWORD read, len = 0;
25 BOOL ret;
26
27 while (1)
28 {
29 ret = ReadFile(child_proc_stdout, buf + len, buf_size - len, &read, NULL);
30 if (!ret || !read) break;
31
32 len += read;
33 }
34
35 buf[len] = 0;
36}
#define read
Definition: acwin.h:96
#define NULL
Definition: types.h:112
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum GLsizei len
Definition: glext.h:6722
int ret

Referenced by read_reg_output_().

◆ read_reg_output_()

static BOOL read_reg_output_ ( const char file,
unsigned  line,
const char cmd,
BYTE buf,
DWORD  buf_size,
DWORD rc 
)
static

Definition at line 39 of file query.c.

41{
43 HANDLE pipe_stdout_rd, pipe_stdout_wr;
44 STARTUPINFOA si = {0};
46 char cmdline[256];
47 BOOL bret;
48 DWORD ret;
49
50 sa.nLength = sizeof(SECURITY_ATTRIBUTES);
51 sa.bInheritHandle = TRUE;
52 sa.lpSecurityDescriptor = NULL;
53
54 if (!CreatePipe(&pipe_stdout_rd, &pipe_stdout_wr, &sa, 0))
55 return FALSE;
56
57 if (!SetHandleInformation(pipe_stdout_rd, HANDLE_FLAG_INHERIT, 0))
58 return FALSE;
59
60 si.cb = sizeof(si);
63 si.hStdOutput = pipe_stdout_wr;
65
67 if (!CreateProcessA(NULL, cmdline, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi))
68 return FALSE;
69
70 CloseHandle(pipe_stdout_wr);
71
72 read_from_pipe(pipe_stdout_rd, buf, buf_size);
73
74 ret = WaitForSingleObject(pi.hProcess, 10000);
75 if (ret == WAIT_TIMEOUT)
76 TerminateProcess(pi.hProcess, 1);
77
78 bret = GetExitCodeProcess(pi.hProcess, rc);
79 lok(bret, "GetExitCodeProcess failed: %d\n", GetLastError());
80
81 CloseHandle(pipe_stdout_rd);
82 CloseHandle(pi.hThread);
83 CloseHandle(pi.hProcess);
84 return bret;
85}
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
static struct sockaddr_in sa
Definition: adnsresfilter.c:69
#define WAIT_TIMEOUT
Definition: dderror.h:14
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
struct _SECURITY_ATTRIBUTES SECURITY_ATTRIBUTES
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
BOOL WINAPI SetHandleInformation(IN HANDLE hObject, IN DWORD dwMask, IN DWORD dwFlags)
Definition: handle.c:78
BOOL WINAPI GetExitCodeProcess(IN HANDLE hProcess, IN LPDWORD lpExitCode)
Definition: proc.c:1168
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessA(LPCSTR lpApplicationName, LPSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
Definition: proc.c:4747
BOOL WINAPI TerminateProcess(IN HANDLE hProcess, IN UINT uExitCode)
Definition: proc.c:1532
static void read_from_pipe(HANDLE child_proc_stdout, BYTE *buf, DWORD buf_size)
Definition: query.c:22
static refpint_t pi[]
Definition: server.c:96
BOOL WINAPI CreatePipe(PHANDLE hReadPipe, PHANDLE hWritePipe, LPSECURITY_ATTRIBUTES lpPipeAttributes, DWORD nSize)
Definition: npipe.c:117
TCHAR * cmdline
Definition: stretchblt.cpp:32
HANDLE hStdOutput
Definition: winbase.h:872
HANDLE hStdError
Definition: winbase.h:873
DWORD dwFlags
Definition: winbase.h:867
DWORD cb
Definition: winbase.h:856
HANDLE hStdInput
Definition: winbase.h:871
Definition: ftp_var.h:139
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define HANDLE_FLAG_INHERIT
Definition: winbase.h:290
#define STARTF_USESTDHANDLES
Definition: winbase.h:525

◆ START_TEST()

START_TEST ( query  )

Definition at line 499 of file query.c.

500{
501 DWORD r;
502
503 if (!run_reg_exe("reg.exe /?", &r)) {
504 win_skip("reg.exe not available, skipping 'query' tests\n");
505 return;
506 }
507
509 test_query();
510
511 /* Check if reg.exe is running with elevated privileges */
512 if (!is_elevated_process())
513 {
514 win_skip("reg.exe is not running with elevated privileges; "
515 "skipping registry view tests\n");
516 return;
517 }
518
519#if 0
520 test_registry_view_win32();
521 test_registry_view_win64();
522 test_registry_view_wow64();
523#endif
524
525}
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
BOOL is_elevated_process(void)
Definition: import.c:21
static void test_query(void)
Definition: query.c:147
static void test_command_syntax(void)
Definition: query.c:108
#define run_reg_exe(c, r)
Definition: reg_test.h:39
#define win_skip
Definition: test.h:163

◆ test_command_syntax()

static void test_command_syntax ( void  )
static

Definition at line 108 of file query.c.

109{
110 DWORD r;
111
112 run_reg_exe("reg query", &r);
113 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
114
115 run_reg_exe("reg query /?", &r);
116 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
117
118 run_reg_exe("reg query /h", &r);
119 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
120
121 run_reg_exe("reg query -H", &r);
122 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
123
124 run_reg_exe("reg query HKCU\\" KEY_BASE " /v", &r);
125 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
126
127 run_reg_exe("reg query HKCU\\" KEY_BASE " /v Test1 /v Test2", &r);
128 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
129
130 run_reg_exe("reg query HKCU\\" KEY_BASE " /v Test1 /ve", &r);
131 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
132
133 run_reg_exe("reg query HKCU\\" KEY_BASE " /s /s", &r);
134 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
135
136 /* Test registry view */
137 run_reg_exe("reg query HKCU\\" KEY_BASE " /reg:32 /reg:32", &r);
138 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
139
140 run_reg_exe("reg query HKCU\\" KEY_BASE " /reg:32 /reg:64", &r);
141 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
142
143 run_reg_exe("reg query HKCU\\" KEY_BASE " /reg:64 /reg:64", &r);
144 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
145}
#define ok(value,...)
Definition: atltest.h:57
#define REG_EXIT_FAILURE
Definition: reg_test.h:31
#define REG_EXIT_SUCCESS
Definition: reg_test.h:30
#define KEY_BASE
Definition: reg_test.h:29

Referenced by START_TEST().

◆ test_query()

static void test_query ( void  )
static

Definition at line 147 of file query.c.

148{
149 const char *test1 = "\r\n"
150 "HKEY_CURRENT_USER\\" KEY_BASE "\r\n"
151 " Test1 REG_SZ Hello, World\r\n"
152 " Test2 REG_DWORD 0x123\r\n\r\n";
153
154 const char *test2 = "\r\n"
155 "HKEY_CURRENT_USER\\" KEY_BASE "\r\n"
156 " Test1 REG_SZ Hello, World\r\n\r\n";
157
158 const char *test3 = "\r\n"
159 "HKEY_CURRENT_USER\\" KEY_BASE "\r\n"
160 " Test1 REG_SZ Hello, World\r\n"
161 " Test2 REG_DWORD 0x123\r\n"
162 " Wine REG_SZ First instance\r\n\r\n"
163 "HKEY_CURRENT_USER\\" KEY_BASE "\\subkey\r\n";
164
165 const char *test4 = "\r\n"
166 "HKEY_CURRENT_USER\\" KEY_BASE "\\subkey\r\n"
167 " Test3 REG_SZ Some string data\r\n"
168 " Test4 REG_DWORD 0xabc\r\n\r\n";
169
170 const char *test5 = "\r\n"
171 "HKEY_CURRENT_USER\\" KEY_BASE "\\subkey\r\n"
172 " Test4 REG_DWORD 0xabc\r\n\r\n";
173
174 const char *test6 = "\r\n"
175 "HKEY_CURRENT_USER\\" KEY_BASE "\r\n"
176 " Test1 REG_SZ Hello, World\r\n"
177 " Test2 REG_DWORD 0x123\r\n"
178 " Wine REG_SZ First instance\r\n\r\n"
179 "HKEY_CURRENT_USER\\" KEY_BASE "\\subkey\r\n"
180 " Test3 REG_SZ Some string data\r\n"
181 " Test4 REG_DWORD 0xabc\r\n"
182 " Wine REG_SZ Second instance\r\n\r\n";
183
184 const char *test7 = "\r\n"
185 "HKEY_CURRENT_USER\\" KEY_BASE "\r\n"
186 " Wine REG_SZ First instance\r\n\r\n"
187 "HKEY_CURRENT_USER\\" KEY_BASE "\\subkey\r\n"
188 " Wine REG_SZ Second instance\r\n\r\n";
189
190 const char *test8a = "\r\n"
191 "HKEY_CURRENT_USER\\" KEY_BASE "\\subkey1\r\n"
192 "HKEY_CURRENT_USER\\" KEY_BASE "\\subkey2\r\n"
193 "HKEY_CURRENT_USER\\" KEY_BASE "\\subkey3\r\n"
194 "HKEY_CURRENT_USER\\" KEY_BASE "\\subkey4\r\n";
195
196 const char *test8b = "\r\n"
197 "HKEY_CURRENT_USER\\" KEY_BASE "\\subkey1\r\n\r\n"
198 "HKEY_CURRENT_USER\\" KEY_BASE "\\subkey2\r\n\r\n"
199 "HKEY_CURRENT_USER\\" KEY_BASE "\\subkey3\r\n\r\n"
200 "HKEY_CURRENT_USER\\" KEY_BASE "\\subkey4\r\n\r\n";
201
202 DWORD r, dword = 0x123;
203 HKEY hkey, subkey;
204 BYTE buf[512];
205
207
208 /* Key not present */
209 run_reg_exe("reg query HKCU\\" KEY_BASE, &r);
210 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
211
212 /* Create a test key */
214 add_value(hkey, "Test1", REG_SZ, "Hello, World", 13);
215 add_value(hkey, "Test2", REG_DWORD, &dword, sizeof(dword));
216
217 run_reg_exe("reg query HKCU\\" KEY_BASE " /v Missing", &r);
218 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
219
220 read_reg_output("reg query HKCU\\" KEY_BASE, buf, sizeof(buf), &r);
221 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
223
224 run_reg_exe("reg query HKCU\\" KEY_BASE " /ve", &r);
225 ok(r == REG_EXIT_SUCCESS || broken(r == REG_EXIT_FAILURE /* WinXP */),
226 "got exit code %d, expected 0\n", r);
227
228 read_reg_output("reg query HKCU\\" KEY_BASE " /v Test1", buf, sizeof(buf), &r);
229 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
231
232 run_reg_exe("reg query HKCU\\" KEY_BASE " /v Test2", &r);
233 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
234
235 add_value(hkey, "Wine", REG_SZ, "First instance", 15);
236
237 /* Create a test subkey */
238 add_key(hkey, "subkey", 0, &subkey);
239
240 read_reg_output("reg query HKCU\\" KEY_BASE, buf, sizeof(buf), &r);
241 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
243
244 add_value(subkey, "Test3", REG_SZ, "Some string data", 16);
245 dword = 0xabc;
246 add_value(subkey, "Test4", REG_DWORD, &dword, sizeof(dword));
247
248 read_reg_output("reg query HKCU\\" KEY_BASE "\\subkey", buf, sizeof(buf), &r);
249 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
251
252 run_reg_exe("reg query HKCU\\" KEY_BASE "\\subkey /v Test3", &r);
253 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
254
255 read_reg_output("reg query HKCU\\" KEY_BASE "\\subkey /v Test4", buf, sizeof(buf), &r);
256 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
258
259 add_value(subkey, "Wine", REG_SZ, "Second instance", 16);
260
261 /* Test recursion */
262 read_reg_output("reg query HKCU\\" KEY_BASE " /s", buf, sizeof(buf), &r);
263 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
265
266 read_reg_output("reg query HKCU\\" KEY_BASE "\\ /s", buf, sizeof(buf), &r);
267 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
269
270 read_reg_output("reg query HKCU\\" KEY_BASE " /v Wine /s", buf, sizeof(buf), &r);
271 ok(r == REG_EXIT_SUCCESS || r == REG_EXIT_FAILURE /* WinXP */,
272 "got exit code %d, expected 0\n", r);
274
275 add_value(hkey, NULL, REG_SZ, "Empty", 6);
276 add_value(subkey, NULL, REG_SZ, "Empty", 6);
277 close_key(subkey);
278 close_key(hkey);
279
280 run_reg_exe("reg query HKCU\\" KEY_BASE "\\subkey /ve", &r);
281 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
282
283 run_reg_exe("reg query HKCU\\" KEY_BASE " /ve /s", &r);
284 ok(r == REG_EXIT_SUCCESS || r == REG_EXIT_FAILURE /* WinXP */,
285 "got exit code %d, expected 0\n", r);
286
288
289 /* Subkeys only */
291 add_key(hkey, "subkey1", 0, NULL);
292 add_key(hkey, "subkey2", 0, NULL);
293 add_key(hkey, "subkey3", 0, NULL);
294 add_key(hkey, "subkey4", 0, NULL);
295 close_key(hkey);
296
297 read_reg_output("reg query HKCU\\" KEY_BASE, buf, sizeof(buf), &r);
298 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
299 compare_query(buf, test8a, FALSE, 0);
300
301 read_reg_output("reg query HKCU\\" KEY_BASE " /s", buf, sizeof(buf), &r);
302 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
303 compare_query(buf, test8b, FALSE, 0);
304
306}
#define broken(x)
Definition: atltest.h:178
void test2()
Definition: ehthrow.cxx:284
void test1()
Definition: ehthrow.cxx:277
void test4()
Definition: ehthrow.cxx:298
void test3()
Definition: ehthrow.cxx:291
void test5()
Definition: ehthrow.cxx:305
void test7()
Definition: ehthrow.cxx:346
void test6()
Definition: ehthrow.cxx:312
#define REG_SZ
Definition: layer.c:22
#define read_reg_output(c, b, s, r)
Definition: query.c:38
#define compare_query(b, e, c, todo)
Definition: query.c:87
#define add_value(k, n, t, d, s)
Definition: reg_test.h:70
#define add_key(r, p, s, k)
Definition: reg_test.h:61
#define delete_tree(r, p, s)
Definition: reg_test.h:67
#define close_key(k)
Definition: reg_test.h:52
#define REG_DWORD
Definition: sdbapi.c:596
#define HKEY_CURRENT_USER
Definition: winreg.h:11
unsigned char BYTE
Definition: xxhash.c:193

Referenced by START_TEST().