ReactOS  0.4.14-dev-323-g6fe6a88
shreg.c File Reference
#include <stdarg.h>
#include <stdio.h>
#include "wine/test.h"
#include "windef.h"
#include "winbase.h"
#include "winerror.h"
#include "winreg.h"
#include "winuser.h"
#include "shlwapi.h"
Include dependency graph for shreg.c:

Go to the source code of this file.

Macros

#define REG_TEST_KEY   "Software\\Wine\\Test"
 
#define REG_CURRENT_VERSION   "Software\\Microsoft\\Windows\\CurrentVersion\\explorer"
 

Functions

static DWORD (WINAPI *pSHCopyKeyA)(HKEY
 
static LSTATUS (WINAPI *pSHRegGetValueA)(HKEY
 
static DWORD delete_key (HKEY hkey, LPCSTR parent, LPCSTR keyname)
 
static HKEY create_test_entries (void)
 
static void test_SHGetValue (void)
 
static void test_SHRegGetValue (void)
 
static void test_SHGetRegPath (void)
 
static void test_SHQueryValueEx (void)
 
static void test_SHCopyKey (void)
 
static void test_SHDeleteKey (void)
 
static void test_SHRegCreateUSKeyW (void)
 
static void test_SHRegCloseUSKey (void)
 
 START_TEST (shreg)
 

Variables

static HMODULE hshlwapi
 
static LPCSTR
 
static HKEY
 
static DWORD
 
static LPSTR
 
static SRRF
 
static LPDWORD
 
static LPVOID
 
static REGSAM
 
static HUSKEY
 
static PHUSKEY
 
static BOOL
 
static const char sTestpath1 [] = "%LONGSYSTEMVAR%\\subdir1"
 
static const char sTestpath2 [] = "%FOO%\\subdir1"
 
static const charsEnvvar1 = "bar"
 
static const charsEnvvar2 = "ImARatherLongButIndeedNeededString"
 
static char sExpTestpath1 [MAX_PATH]
 
static char sExpTestpath2 [MAX_PATH]
 
static DWORD nExpLen1
 
static DWORD nExpLen2
 
static const charsEmptyBuffer ="0123456789"
 

Macro Definition Documentation

◆ REG_CURRENT_VERSION

#define REG_CURRENT_VERSION   "Software\\Microsoft\\Windows\\CurrentVersion\\explorer"

Definition at line 33 of file shreg.c.

◆ REG_TEST_KEY

#define REG_TEST_KEY   "Software\\Wine\\Test"

Definition at line 32 of file shreg.c.

Function Documentation

◆ create_test_entries()

static HKEY create_test_entries ( void  )
static

Definition at line 76 of file shreg.c.

77 {
78  HKEY hKey;
79  DWORD ret;
80  DWORD nExpectedLen1, nExpectedLen2;
81 
82  SetEnvironmentVariableA("LONGSYSTEMVAR", sEnvvar1);
84 
86  ok( ERROR_SUCCESS == ret, "RegCreateKeyA failed, ret=%u\n", ret);
87 
88  if (hKey)
89  {
90  ok(!RegSetValueExA(hKey,"Test1",0,REG_EXPAND_SZ, (LPBYTE) sTestpath1, strlen(sTestpath1)+1), "RegSetValueExA failed\n");
91  ok(!RegSetValueExA(hKey,"Test2",0,REG_SZ, (LPBYTE) sTestpath1, strlen(sTestpath1)+1), "RegSetValueExA failed\n");
92  ok(!RegSetValueExA(hKey,"Test3",0,REG_EXPAND_SZ, (LPBYTE) sTestpath2, strlen(sTestpath2)+1), "RegSetValueExA failed\n");
93  }
94 
97 
98  nExpectedLen1 = strlen(sTestpath1) - strlen("%LONGSYSTEMVAR%") + strlen(sEnvvar1) + 1;
99  nExpectedLen2 = strlen(sTestpath2) - strlen("%FOO%") + strlen(sEnvvar2) + 1;
100  /* ExpandEnvironmentStringsA on NT4 returns 2x the correct result */
101  trace("sExplen1 = (%d)\n", nExpLen1);
102  if (nExpectedLen1 != nExpLen1)
103  trace( "Expanding %s failed (expected %d) - known bug in NT4\n", sTestpath1, nExpectedLen1 );
104 
105  trace("sExplen2 = (%d)\n", nExpLen2);
106  if (nExpectedLen2 != nExpLen2)
107  trace( "Expanding %s failed (expected %d) - known bug in NT4\n", sTestpath2, nExpectedLen2 );
108 
109  /* Make sure we carry on with correct values */
110  nExpLen1 = nExpectedLen1;
111  nExpLen2 = nExpectedLen2;
112  return hKey;
113 }
#define ERROR_SUCCESS
Definition: deptool.c:10
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
static DWORD nExpLen2
Definition: shreg.c:53
#define HKEY_CURRENT_USER
Definition: winreg.h:11
static const char sTestpath1[]
Definition: shreg.c:44
static const char sTestpath2[]
Definition: shreg.c:45
static const char * sEnvvar1
Definition: shreg.c:47
unsigned char * LPBYTE
Definition: typedefs.h:52
#define REG_TEST_KEY
Definition: shreg.c:32
static DWORD nExpLen1
Definition: shreg.c:52
DWORD WINAPI ExpandEnvironmentStringsA(IN LPCSTR lpSrc, IN LPSTR lpDst, IN DWORD nSize)
Definition: environ.c:399
LONG WINAPI RegCreateKeyA(HKEY hKey, LPCSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:1177
#define trace
Definition: atltest.h:70
BOOL WINAPI DECLSPEC_HOTPATCH SetEnvironmentVariableA(IN LPCSTR lpName, IN LPCSTR lpValue)
Definition: environ.c:218
unsigned long DWORD
Definition: ntddk_ex.h:95
int ret
static char sExpTestpath1[MAX_PATH]
Definition: shreg.c:50
#define REG_EXPAND_SZ
Definition: nt_native.h:1494
#define ok(value,...)
Definition: atltest.h:57
static const char * sEnvvar2
Definition: shreg.c:48
LONG WINAPI RegSetValueExA(HKEY hKey, LPCSTR lpValueName, DWORD Reserved, DWORD dwType, CONST BYTE *lpData, DWORD cbData)
Definition: reg.c:4812
static char sExpTestpath2[MAX_PATH]
Definition: shreg.c:51
#define REG_SZ
Definition: layer.c:22

Referenced by START_TEST().

◆ delete_key()

static DWORD delete_key ( HKEY  hkey,
LPCSTR  parent,
LPCSTR  keyname 
)
static

Definition at line 58 of file shreg.c.

59 {
60  HKEY parentKey;
61  DWORD ret;
62 
63  RegCloseKey(hkey);
64 
65  /* open the parent of the key to close */
67  if (ret != ERROR_SUCCESS)
68  return ret;
69 
70  ret = SHDeleteKeyA( parentKey, keyname );
71  RegCloseKey(parentKey);
72 
73  return ret;
74 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define HKEY_CURRENT_USER
Definition: winreg.h:11
LONG WINAPI RegOpenKeyExA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey, _In_ DWORD ulOptions, _In_ REGSAM samDesired, _Out_ PHKEY phkResult)
Definition: reg.c:3331
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
r parent
Definition: btrfs.c:2869
unsigned long DWORD
Definition: ntddk_ex.h:95
int ret
DWORD WINAPI SHDeleteKeyA(HKEY hKey, LPCSTR lpszSubKey)
Definition: reg.c:1533
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041

Referenced by START_TEST().

◆ DWORD()

static DWORD ( WINAPI pSHCopyKeyA)
static

◆ LSTATUS()

static LSTATUS ( WINAPI pSHRegGetValueA)
static

Referenced by test_SHRegGetValue().

◆ START_TEST()

START_TEST ( shreg  )

Definition at line 492 of file shreg.c.

493 {
494  HKEY hkey = create_test_entries();
495 
496  if (!hkey) return;
497 
498  hshlwapi = GetModuleHandleA("shlwapi.dll");
499 
500  /* SHCreateStreamOnFileEx was introduced in shlwapi v6.0 */
501  if(!GetProcAddress(hshlwapi, "SHCreateStreamOnFileEx")){
502  win_skip("Too old shlwapi version\n");
503  return;
504  }
505 
506  pSHCopyKeyA = (void*)GetProcAddress(hshlwapi,"SHCopyKeyA");
507  pSHRegGetPathA = (void*)GetProcAddress(hshlwapi,"SHRegGetPathA");
508  pSHRegGetValueA = (void*)GetProcAddress(hshlwapi,"SHRegGetValueA");
509  pSHRegCreateUSKeyW = (void*)GetProcAddress(hshlwapi, "SHRegCreateUSKeyW");
510  pSHRegOpenUSKeyW = (void*)GetProcAddress(hshlwapi, "SHRegOpenUSKeyW");
511  pSHRegCloseUSKey = (void*)GetProcAddress(hshlwapi, "SHRegCloseUSKey");
512 
513  test_SHGetValue();
517  test_SHCopyKey();
521 
522  delete_key( hkey, "Software\\Wine", "Test" );
523 }
static void test_SHCopyKey(void)
Definition: shreg.c:348
static HMODULE hshlwapi
Definition: shreg.c:35
static void test_SHRegCloseUSKey(void)
Definition: shreg.c:463
static DWORD delete_key(HKEY hkey, LPCSTR parent, LPCSTR keyname)
Definition: shreg.c:58
static void test_SHQueryValueEx(void)
Definition: shreg.c:195
static void test_SHGetValue(void)
Definition: shreg.c:115
static void test_SHRegCreateUSKeyW(void)
Definition: shreg.c:448
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:821
static void test_SHGetRegPath(void)
Definition: shreg.c:181
static void test_SHRegGetValue(void)
Definition: shreg.c:143
#define GetProcAddress(x, y)
Definition: compat.h:410
static HKEY create_test_entries(void)
Definition: shreg.c:76
#define win_skip
Definition: test.h:141
static void test_SHDeleteKey(void)
Definition: shreg.c:405

◆ test_SHCopyKey()

static void test_SHCopyKey ( void  )
static

Definition at line 348 of file shreg.c.

349 {
350  HKEY hKeySrc, hKeyDst;
351  DWORD dwRet;
352 
353  if (!pSHCopyKeyA)
354  {
355  win_skip("SHCopyKeyA is not available\n");
356  return;
357  }
358 
359  /* Delete existing destination sub keys */
360  hKeyDst = NULL;
361  if (!RegOpenKeyA(HKEY_CURRENT_USER, REG_TEST_KEY "\\CopyDestination", &hKeyDst) && hKeyDst)
362  {
363  SHDeleteKeyA(hKeyDst, NULL);
364  RegCloseKey(hKeyDst);
365  }
366 
367  hKeyDst = NULL;
368  dwRet = RegCreateKeyA(HKEY_CURRENT_USER, REG_TEST_KEY "\\CopyDestination", &hKeyDst);
369  if (dwRet || !hKeyDst)
370  {
371  ok( 0, "Destination couldn't be created, RegCreateKeyA returned (%u)\n", dwRet);
372  return;
373  }
374 
375  hKeySrc = NULL;
377  if (dwRet || !hKeySrc)
378  {
379  ok( 0, "Source couldn't be opened, RegOpenKeyA returned (%u)\n", dwRet);
380  RegCloseKey(hKeyDst);
381  return;
382  }
383 
384  dwRet = (*pSHCopyKeyA)(hKeySrc, NULL, hKeyDst, 0);
385  ok ( ERROR_SUCCESS == dwRet, "Copy failed, ret=(%u)\n", dwRet);
386 
387  RegCloseKey(hKeySrc);
388  RegCloseKey(hKeyDst);
389 
390  /* Check we copied the sub keys, i.e. something that's on every windows system (including Wine) */
391  hKeyDst = NULL;
392  dwRet = RegOpenKeyA(HKEY_CURRENT_USER, REG_TEST_KEY "\\CopyDestination\\Shell Folders", &hKeyDst);
393  if (dwRet || !hKeyDst)
394  {
395  ok ( 0, "Copy couldn't be opened, RegOpenKeyA returned (%u)\n", dwRet);
396  return;
397  }
398 
399  /* And the we copied the values too */
400  ok(!SHQueryValueExA(hKeyDst, "Common AppData", NULL, NULL, NULL, NULL), "SHQueryValueExA failed\n");
401 
402  RegCloseKey(hKeyDst);
403 }
LONG WINAPI RegOpenKeyA(HKEY hKey, LPCSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:3257
#define ERROR_SUCCESS
Definition: deptool.c:10
#define HKEY_CURRENT_USER
Definition: winreg.h:11
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
#define REG_CURRENT_VERSION
Definition: shreg.c:33
#define REG_TEST_KEY
Definition: shreg.c:32
smooth NULL
Definition: ftsmooth.c:416
LONG WINAPI RegCreateKeyA(HKEY hKey, LPCSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:1177
DWORD WINAPI SHQueryValueExA(HKEY hKey, LPCSTR lpszValue, LPDWORD lpReserved, LPDWORD pwType, LPVOID pvData, LPDWORD pcbData)
Definition: reg.c:1402
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD WINAPI SHDeleteKeyA(HKEY hKey, LPCSTR lpszSubKey)
Definition: reg.c:1533
#define ok(value,...)
Definition: atltest.h:57
#define win_skip
Definition: test.h:141
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by START_TEST().

◆ test_SHDeleteKey()

static void test_SHDeleteKey ( void  )
static

Definition at line 405 of file shreg.c.

406 {
407  HKEY hKeyTest, hKeyS;
408  DWORD dwRet;
409  int sysfail = 1;
410 
411  if (!RegOpenKeyA(HKEY_CURRENT_USER, REG_TEST_KEY, &hKeyTest))
412  {
413  if (!RegCreateKeyA(hKeyTest, "ODBC", &hKeyS))
414  {
415  HKEY hKeyO;
416 
417  if (!RegCreateKeyA(hKeyS, "ODBC.INI", &hKeyO))
418  {
419  RegCloseKey (hKeyO);
420 
421  if (!RegCreateKeyA(hKeyS, "ODBCINST.INI", &hKeyO))
422  {
423  RegCloseKey (hKeyO);
424  sysfail = 0;
425  }
426  }
427  RegCloseKey (hKeyS);
428  }
429  RegCloseKey (hKeyTest);
430  }
431 
432  if (!sysfail)
433  {
434 
435  dwRet = SHDeleteKeyA(HKEY_CURRENT_USER, REG_TEST_KEY "\\ODBC");
436  ok ( ERROR_SUCCESS == dwRet, "SHDeleteKey failed, ret=(%u)\n", dwRet);
437 
438  dwRet = RegOpenKeyA(HKEY_CURRENT_USER, REG_TEST_KEY "\\ODBC", &hKeyS);
439  ok ( ERROR_FILE_NOT_FOUND == dwRet, "SHDeleteKey did not delete\n");
440 
441  if (dwRet == ERROR_SUCCESS)
442  RegCloseKey (hKeyS);
443  }
444  else
445  ok( 0, "Could not set up SHDeleteKey test\n");
446 }
LONG WINAPI RegOpenKeyA(HKEY hKey, LPCSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:3257
#define ERROR_SUCCESS
Definition: deptool.c:10
#define HKEY_CURRENT_USER
Definition: winreg.h:11
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
#define REG_TEST_KEY
Definition: shreg.c:32
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
LONG WINAPI RegCreateKeyA(HKEY hKey, LPCSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:1177
unsigned long DWORD
Definition: ntddk_ex.h:95
void sysfail(const char *what, int errnoval)
Definition: adh-main.c:49
DWORD WINAPI SHDeleteKeyA(HKEY hKey, LPCSTR lpszSubKey)
Definition: reg.c:1533
#define ok(value,...)
Definition: atltest.h:57

Referenced by START_TEST().

◆ test_SHGetRegPath()

static void test_SHGetRegPath ( void  )
static

Definition at line 181 of file shreg.c.

182 {
183  char buf[MAX_PATH];
184  DWORD dwRet;
185 
186  if (!pSHRegGetPathA)
187  return;
188 
190  dwRet = (*pSHRegGetPathA)(HKEY_CURRENT_USER, REG_TEST_KEY, "Test1", buf, 0);
191  ok( ERROR_SUCCESS == dwRet, "SHRegGetPathA failed, ret=%u\n", dwRet);
192  ok( 0 == strcmp(sExpTestpath1, buf) , "Comparing (%s) with (%s) failed\n", buf, sExpTestpath1);
193 }
#define ERROR_SUCCESS
Definition: deptool.c:10
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define REG_TEST_KEY
Definition: shreg.c:32
static const char * sEmptyBuffer
Definition: shreg.c:55
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
static char sExpTestpath1[MAX_PATH]
Definition: shreg.c:50
#define ok(value,...)
Definition: atltest.h:57
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469

Referenced by START_TEST().

◆ test_SHGetValue()

static void test_SHGetValue ( void  )
static

Definition at line 115 of file shreg.c.

116 {
117  DWORD dwSize;
118  DWORD dwType;
119  DWORD dwRet;
120  char buf[MAX_PATH];
121 
123  dwSize = MAX_PATH;
124  dwType = -1;
125  dwRet = SHGetValueA(HKEY_CURRENT_USER, REG_TEST_KEY, "Test1", &dwType, buf, &dwSize);
126  ok( ERROR_SUCCESS == dwRet, "SHGetValueA failed, ret=%u\n", dwRet);
127  ok( 0 == strcmp(sExpTestpath1, buf) ||
128  broken(0 == strcmp(sTestpath1, buf)), /* IE4.x */
129  "Comparing of (%s) with (%s) failed\n", buf, sExpTestpath1);
130  ok( REG_SZ == dwType ||
131  broken(REG_EXPAND_SZ == dwType), /* IE4.x */
132  "Expected REG_SZ, got (%u)\n", dwType);
133 
135  dwSize = MAX_PATH;
136  dwType = -1;
137  dwRet = SHGetValueA(HKEY_CURRENT_USER, REG_TEST_KEY, "Test2", &dwType, buf, &dwSize);
138  ok( ERROR_SUCCESS == dwRet, "SHGetValueA failed, ret=%u\n", dwRet);
139  ok( 0 == strcmp(sTestpath1, buf) , "Comparing of (%s) with (%s) failed\n", buf, sTestpath1);
140  ok( REG_SZ == dwType , "Expected REG_SZ, got (%u)\n", dwType);
141 }
#define ERROR_SUCCESS
Definition: deptool.c:10
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define HKEY_CURRENT_USER
Definition: winreg.h:11
static const char sTestpath1[]
Definition: shreg.c:44
#define REG_TEST_KEY
Definition: shreg.c:32
static const char * sEmptyBuffer
Definition: shreg.c:55
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
static char sExpTestpath1[MAX_PATH]
Definition: shreg.c:50
#define broken(x)
Definition: _sntprintf.h:21
#define REG_EXPAND_SZ
Definition: nt_native.h:1494
#define ok(value,...)
Definition: atltest.h:57
DWORD WINAPI SHGetValueA(HKEY hKey, LPCSTR lpszSubKey, LPCSTR lpszValue, LPDWORD pwType, LPVOID pvData, LPDWORD pcbData)
Definition: reg.c:1207
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
#define REG_SZ
Definition: layer.c:22

Referenced by START_TEST().

◆ test_SHQueryValueEx()

static void test_SHQueryValueEx ( void  )
static

Definition at line 195 of file shreg.c.

196 {
197  HKEY hKey;
198  DWORD dwSize;
199  DWORD dwType;
200  char buf[MAX_PATH];
201  DWORD dwRet;
202  const char * sTestedFunction = "";
203  DWORD nUsedBuffer1,nUsedBuffer2;
204 
205  sTestedFunction = "RegOpenKeyExA";
207  ok( ERROR_SUCCESS == dwRet, "%s failed, ret=%u\n", sTestedFunction, dwRet);
208 
209  /****** SHQueryValueExA ******/
210 
211  sTestedFunction = "SHQueryValueExA";
212  nUsedBuffer1 = max(strlen(sExpTestpath1)+1, strlen(sTestpath1)+1);
213  nUsedBuffer2 = max(strlen(sExpTestpath2)+1, strlen(sTestpath2)+1);
214  /*
215  * Case 1.1 All arguments are NULL
216  */
217  dwRet = SHQueryValueExA( hKey, "Test1", NULL, NULL, NULL, NULL);
218  ok( ERROR_SUCCESS == dwRet, "%s failed, ret=%u\n", sTestedFunction, dwRet);
219 
220  /*
221  * Case 1.2 dwType is set
222  */
223  dwType = -1;
224  dwRet = SHQueryValueExA( hKey, "Test1", NULL, &dwType, NULL, NULL);
225  ok( ERROR_SUCCESS == dwRet, "%s failed, ret=%u\n", sTestedFunction, dwRet);
226  ok( REG_SZ == dwType , "Expected REG_SZ, got (%u)\n", dwType);
227 
228  /*
229  * dwSize is set
230  * dwExpanded < dwUnExpanded
231  */
232  dwSize = 6;
233  dwRet = SHQueryValueExA( hKey, "Test1", NULL, NULL, NULL, &dwSize);
234  ok( ERROR_SUCCESS == dwRet, "%s failed, ret=%u\n", sTestedFunction, dwRet);
235  ok( dwSize == nUsedBuffer1, "Buffer sizes (%u) and (%u) are not equal\n", dwSize, nUsedBuffer1);
236 
237  /*
238  * dwExpanded > dwUnExpanded
239  */
240  dwSize = 6;
241  dwRet = SHQueryValueExA( hKey, "Test3", NULL, NULL, NULL, &dwSize);
242  ok( ERROR_SUCCESS == dwRet, "%s failed, ret=%u\n", sTestedFunction, dwRet);
243  ok( dwSize >= nUsedBuffer2 ||
244  broken(dwSize == (strlen(sTestpath2) + 1)), /* < IE4.x */
245  "Buffer size (%u) should be >= (%u)\n", dwSize, nUsedBuffer2);
246 
247  /*
248  * Case 1 string shrinks during expanding
249  */
251  dwSize = 6;
252  dwType = -1;
253  dwRet = SHQueryValueExA( hKey, "Test1", NULL, &dwType, buf, &dwSize);
254  ok( ERROR_MORE_DATA == dwRet, "Expected ERROR_MORE_DATA, got (%u)\n", dwRet);
255  ok( 0 == strcmp(sEmptyBuffer, buf) , "Comparing (%s) with (%s) failed\n", buf, sEmptyBuffer);
256  ok( dwSize == nUsedBuffer1, "Buffer sizes (%u) and (%u) are not equal\n", dwSize, nUsedBuffer1);
257  ok( REG_SZ == dwType ||
258  broken(REG_EXPAND_SZ == dwType), /* < IE6 */
259  "Expected REG_SZ, got (%u)\n", dwType);
260 
261  /*
262  * string grows during expanding
263  * dwSize is smaller than the size of the unexpanded string
264  */
266  dwSize = 6;
267  dwType = -1;
268  dwRet = SHQueryValueExA( hKey, "Test3", NULL, &dwType, buf, &dwSize);
269  ok( ERROR_MORE_DATA == dwRet, "Expected ERROR_MORE_DATA, got (%u)\n", dwRet);
270  ok( 0 == strcmp(sEmptyBuffer, buf) , "Comparing (%s) with (%s) failed\n", buf, sEmptyBuffer);
271  ok( dwSize >= nUsedBuffer2 ||
272  broken(dwSize == (strlen(sTestpath2) + 1)), /* < IE6 */
273  "Buffer size (%u) should be >= (%u)\n", dwSize, nUsedBuffer2);
274  ok( REG_SZ == dwType ||
275  broken(REG_EXPAND_SZ == dwType), /* < IE6 */
276  "Expected REG_SZ, got (%u)\n", dwType);
277 
278  /*
279  * string grows during expanding
280  * dwSize is larger than the size of the unexpanded string, but
281  * smaller than the part before the backslash. If the unexpanded
282  * string fits into the buffer, it can get cut when expanded.
283  */
285  dwSize = strlen(sEnvvar2) - 2;
286  dwType = -1;
287  dwRet = SHQueryValueExA( hKey, "Test3", NULL, &dwType, buf, &dwSize);
288  ok( ERROR_MORE_DATA == dwRet ||
289  broken(ERROR_ENVVAR_NOT_FOUND == dwRet) || /* IE5.5 */
290  broken(ERROR_SUCCESS == dwRet), /* < IE5.5*/
291  "Expected ERROR_MORE_DATA, got (%u)\n", dwRet);
292 
293  todo_wine
294  {
295  ok( (0 == strcmp("", buf)) || (0 == strcmp(sTestpath2, buf)),
296  "Expected empty or unexpanded string (win98), got (%s)\n", buf);
297  }
298 
299  ok( dwSize >= nUsedBuffer2 ||
300  broken(dwSize == (strlen("") + 1)), /* < IE 5.5 */
301  "Buffer size (%u) should be >= (%u)\n", dwSize, nUsedBuffer2);
302  ok( REG_SZ == dwType , "Expected REG_SZ, got (%u)\n", dwType);
303 
304  /*
305  * string grows during expanding
306  * dwSize is larger than the size of the part before the backslash,
307  * but smaller than the expanded string. If the unexpanded string fits
308  * into the buffer, it can get cut when expanded.
309  */
311  dwSize = nExpLen2 - 4;
312  dwType = -1;
313  dwRet = SHQueryValueExA( hKey, "Test3", NULL, &dwType, buf, &dwSize);
314  ok( ERROR_MORE_DATA == dwRet ||
315  broken(ERROR_ENVVAR_NOT_FOUND == dwRet) || /* IE5.5 */
316  broken(ERROR_SUCCESS == dwRet), /* < IE5.5 */
317  "Expected ERROR_MORE_DATA, got (%u)\n", dwRet);
318 
319  todo_wine
320  {
321  ok( (0 == strcmp("", buf)) || (0 == strcmp(sEnvvar2, buf)) ||
322  broken(0 == strcmp(sTestpath2, buf)), /* IE 5.5 */
323  "Expected empty or first part of the string \"%s\", got \"%s\"\n", sEnvvar2, buf);
324  }
325 
326  ok( dwSize >= nUsedBuffer2 ||
327  broken(dwSize == (strlen(sEnvvar2) + 1)) || /* IE4.01 SP1 (W98) and IE5 (W98SE) */
328  broken(dwSize == (strlen("") + 1)), /* IE4.01 (NT4) and IE5.x (W2K) */
329  "Buffer size (%u) should be >= (%u)\n", dwSize, nUsedBuffer2);
330  ok( REG_SZ == dwType , "Expected REG_SZ, got (%u)\n", dwType);
331 
332  /*
333  * The buffer is NULL but the size is set
334  */
336  dwSize = 6;
337  dwType = -1;
338  dwRet = SHQueryValueExA( hKey, "Test3", NULL, &dwType, NULL, &dwSize);
339  ok( ERROR_SUCCESS == dwRet, "%s failed, ret=%u\n", sTestedFunction, dwRet);
340  ok( dwSize >= nUsedBuffer2 ||
341  broken(dwSize == (strlen(sTestpath2) + 1)), /* IE4.01 SP1 (Win98) */
342  "Buffer size (%u) should be >= (%u)\n", dwSize, nUsedBuffer2);
343  ok( REG_SZ == dwType , "Expected REG_SZ, got (%u)\n", dwType);
344 
345  RegCloseKey(hKey);
346 }
#define max(a, b)
Definition: svc.c:63
#define ERROR_SUCCESS
Definition: deptool.c:10
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
static DWORD nExpLen2
Definition: shreg.c:53
#define HKEY_CURRENT_USER
Definition: winreg.h:11
LONG WINAPI RegOpenKeyExA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey, _In_ DWORD ulOptions, _In_ REGSAM samDesired, _Out_ PHKEY phkResult)
Definition: reg.c:3331
static const char sTestpath1[]
Definition: shreg.c:44
#define ERROR_ENVVAR_NOT_FOUND
Definition: winerror.h:261
static const char sTestpath2[]
Definition: shreg.c:45
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
#define REG_TEST_KEY
Definition: shreg.c:32
static const char * sEmptyBuffer
Definition: shreg.c:55
smooth NULL
Definition: ftsmooth.c:416
#define MAX_PATH
Definition: compat.h:26
DWORD WINAPI SHQueryValueExA(HKEY hKey, LPCSTR lpszValue, LPDWORD lpReserved, LPDWORD pwType, LPVOID pvData, LPDWORD pcbData)
Definition: reg.c:1402
unsigned long DWORD
Definition: ntddk_ex.h:95
#define todo_wine
Definition: test.h:154
#define ERROR_MORE_DATA
Definition: dderror.h:13
static char sExpTestpath1[MAX_PATH]
Definition: shreg.c:50
#define broken(x)
Definition: _sntprintf.h:21
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define REG_EXPAND_SZ
Definition: nt_native.h:1494
#define ok(value,...)
Definition: atltest.h:57
static const char * sEnvvar2
Definition: shreg.c:48
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
static char sExpTestpath2[MAX_PATH]
Definition: shreg.c:51
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
#define REG_SZ
Definition: layer.c:22

Referenced by START_TEST().

◆ test_SHRegCloseUSKey()

static void test_SHRegCloseUSKey ( void  )
static

Definition at line 463 of file shreg.c.

464 {
465  static const WCHAR localW[] = {'S','o','f','t','w','a','r','e',0};
466  LONG ret;
467  HUSKEY key;
468 
469  if (!pSHRegOpenUSKeyW || !pSHRegCloseUSKey)
470  {
471  win_skip("SHRegOpenUSKeyW or SHRegCloseUSKey not available\n");
472  return;
473  }
474 
475  ret = pSHRegCloseUSKey(NULL);
476  ok(ret == ERROR_INVALID_PARAMETER, "got %d\n", ret);
477 
478  ret = pSHRegOpenUSKeyW(localW, KEY_ALL_ACCESS, NULL, &key, FALSE);
479  ok(ret == ERROR_SUCCESS, "got %d\n", ret);
480 
481  ret = pSHRegCloseUSKey(key);
482  ok(ret == ERROR_SUCCESS, "got %d\n", ret);
483 
484  /* Test with limited rights, specially without KEY_SET_VALUE */
485  ret = pSHRegOpenUSKeyW(localW, KEY_QUERY_VALUE, NULL, &key, FALSE);
486  ok(ret == ERROR_SUCCESS, "got %d\n", ret);
487 
488  ret = pSHRegCloseUSKey(key);
489  ok(ret == ERROR_SUCCESS, "got %d\n", ret);
490 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define ERROR_SUCCESS
Definition: deptool.c:10
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
int ret
HKEY key
Definition: reg.c:42
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define ok(value,...)
Definition: atltest.h:57
#define win_skip
Definition: test.h:141
Definition: path.c:42

Referenced by START_TEST().

◆ test_SHRegCreateUSKeyW()

static void test_SHRegCreateUSKeyW ( void  )
static

Definition at line 448 of file shreg.c.

449 {
450  static const WCHAR subkeyW[] = {'s','u','b','k','e','y',0};
451  LONG ret;
452 
453  if (!pSHRegCreateUSKeyW)
454  {
455  win_skip("SHRegCreateUSKeyW not available\n");
456  return;
457  }
458 
459  ret = pSHRegCreateUSKeyW(subkeyW, KEY_ALL_ACCESS, NULL, NULL, SHREGSET_FORCE_HKCU);
460  ok(ret == ERROR_INVALID_PARAMETER, "got %d\n", ret);
461 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
#define SHREGSET_FORCE_HKCU
Definition: shlwapi.h:312
__wchar_t WCHAR
Definition: xmlstorage.h:180
int ret
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define ok(value,...)
Definition: atltest.h:57
#define win_skip
Definition: test.h:141

Referenced by START_TEST().

◆ test_SHRegGetValue()

static void test_SHRegGetValue ( void  )
static

Definition at line 143 of file shreg.c.

144 {
145  LSTATUS ret;
146  DWORD size, type;
147  char data[MAX_PATH];
148 
149  if(!pSHRegGetValueA)
150  return;
151 
152  size = MAX_PATH;
153  ret = pSHRegGetValueA(HKEY_CURRENT_USER, REG_TEST_KEY, "Test1", SRRF_RT_REG_EXPAND_SZ, &type, data, &size);
154  ok(ret == ERROR_INVALID_PARAMETER, "SHRegGetValue failed, ret=%u\n", ret);
155 
156  size = MAX_PATH;
157  ret = pSHRegGetValueA(HKEY_CURRENT_USER, REG_TEST_KEY, "Test1", SRRF_RT_REG_SZ, &type, data, &size);
158  ok(ret == ERROR_SUCCESS, "SHRegGetValue failed, ret=%u\n", ret);
159  ok(!strcmp(data, sExpTestpath1), "data = %s, expected %s\n", data, sExpTestpath1);
160  ok(type == REG_SZ, "type = %d, expected REG_SZ\n", type);
161 
162  size = MAX_PATH;
163  ret = pSHRegGetValueA(HKEY_CURRENT_USER, REG_TEST_KEY, "Test1", SRRF_RT_REG_DWORD, &type, data, &size);
164  ok(ret == ERROR_UNSUPPORTED_TYPE, "SHRegGetValue failed, ret=%u\n", ret);
165 
166  size = MAX_PATH;
167  ret = pSHRegGetValueA(HKEY_CURRENT_USER, REG_TEST_KEY, "Test2", SRRF_RT_REG_EXPAND_SZ, &type, data, &size);
168  ok(ret == ERROR_INVALID_PARAMETER, "SHRegGetValue failed, ret=%u\n", ret);
169 
170  size = MAX_PATH;
171  ret = pSHRegGetValueA(HKEY_CURRENT_USER, REG_TEST_KEY, "Test2", SRRF_RT_REG_SZ, &type, data, &size);
172  ok(ret == ERROR_SUCCESS, "SHRegGetValue failed, ret=%u\n", ret);
173  ok(!strcmp(data, sTestpath1), "data = %s, expected %s\n", data, sTestpath1);
174  ok(type == REG_SZ, "type = %d, expected REG_SZ\n", type);
175 
176  size = MAX_PATH;
177  ret = pSHRegGetValueA(HKEY_CURRENT_USER, REG_TEST_KEY, "Test2", SRRF_RT_REG_QWORD, &type, data, &size);
178  ok(ret == ERROR_UNSUPPORTED_TYPE, "SHRegGetValue failed, ret=%u\n", ret);
179 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define ERROR_SUCCESS
Definition: deptool.c:10
#define SRRF_RT_REG_DWORD
Definition: shlwapi.h:245
#define HKEY_CURRENT_USER
Definition: winreg.h:11
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
static const char sTestpath1[]
Definition: shreg.c:44
#define SRRF_RT_REG_QWORD
Definition: shlwapi.h:247
static LSTATUS(WINAPI *pSHRegGetValueA)(HKEY
#define REG_TEST_KEY
Definition: shreg.c:32
#define ERROR_UNSUPPORTED_TYPE
Definition: winerror.h:988
GLsizeiptr size
Definition: glext.h:5919
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
int ret
static char sExpTestpath1[MAX_PATH]
Definition: shreg.c:50
#define SRRF_RT_REG_EXPAND_SZ
Definition: shlwapi.h:243
#define ok(value,...)
Definition: atltest.h:57
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define SRRF_RT_REG_SZ
Definition: shlwapi.h:242
#define REG_SZ
Definition: layer.c:22

Referenced by START_TEST().

Variable Documentation

◆ BOOL

Definition at line 41 of file shreg.c.

◆ DWORD

Definition at line 37 of file shreg.c.

◆ HKEY

Definition at line 37 of file shreg.c.

◆ hshlwapi

HMODULE hshlwapi
static

Definition at line 35 of file shreg.c.

Referenced by START_TEST().

◆ HUSKEY

Definition at line 40 of file shreg.c.

◆ LPCSTR

Definition at line 37 of file shreg.c.

◆ LPDWORD

Definition at line 39 of file shreg.c.

◆ LPSTR

Definition at line 38 of file shreg.c.

◆ LPVOID

Definition at line 39 of file shreg.c.

◆ nExpLen1

DWORD nExpLen1
static

Definition at line 52 of file shreg.c.

Referenced by create_test_entries().

◆ nExpLen2

DWORD nExpLen2
static

Definition at line 53 of file shreg.c.

Referenced by create_test_entries(), and test_SHQueryValueEx().

◆ PHUSKEY

Definition at line 40 of file shreg.c.

◆ REGSAM

Definition at line 40 of file shreg.c.

◆ sEmptyBuffer

const char* sEmptyBuffer ="0123456789"
static

Definition at line 55 of file shreg.c.

Referenced by test_SHGetRegPath(), test_SHGetValue(), and test_SHQueryValueEx().

◆ sEnvvar1

const char* sEnvvar1 = "bar"
static

Definition at line 47 of file shreg.c.

Referenced by create_test_entries().

◆ sEnvvar2

const char* sEnvvar2 = "ImARatherLongButIndeedNeededString"
static

Definition at line 48 of file shreg.c.

Referenced by create_test_entries(), and test_SHQueryValueEx().

◆ sExpTestpath1

char sExpTestpath1[MAX_PATH]
static

◆ sExpTestpath2

char sExpTestpath2[MAX_PATH]
static

Definition at line 51 of file shreg.c.

Referenced by create_test_entries(), and test_SHQueryValueEx().

◆ SRRF

Definition at line 39 of file shreg.c.

◆ sTestpath1

const char sTestpath1[] = "%LONGSYSTEMVAR%\\subdir1"
static

◆ sTestpath2

const char sTestpath2[] = "%FOO%\\subdir1"
static

Definition at line 45 of file shreg.c.

Referenced by create_test_entries(), and test_SHQueryValueEx().