1 /* Unit test suite for SHReg* functions
3 * Copyright 2002 Juergen Schmied
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "wine/test.h"
31 static char * sTestpath1 = "%LONGSYSTEMVAR%\\subdir1";
32 static char * sTestpath2 = "%FOO%\\subdir1";
34 static char sExpTestpath1[MAX_PATH];
35 static char sExpTestpath2[MAX_PATH];
36 static unsigned sExpLen1;
37 static unsigned sExpLen2;
39 static char * sEmptyBuffer ="0123456789";
41 static void create_test_entrys(void)
45 SetEnvironmentVariableA("LONGSYSTEMVAR", "bar");
46 SetEnvironmentVariableA("FOO", "ImARatherLongButIndeedNeededString");
48 ok(!RegCreateKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hKey), "RegCreateKeyA failed");
52 ok(!RegSetValueExA(hKey,"Test1",0,REG_EXPAND_SZ, sTestpath1, strlen(sTestpath1)), "RegSetValueExA failed");
53 ok(!RegSetValueExA(hKey,"Test2",0,REG_SZ, sTestpath1, strlen(sTestpath1)), "RegSetValueExA failed");
54 ok(!RegSetValueExA(hKey,"Test3",0,REG_EXPAND_SZ, sTestpath2, strlen(sTestpath2)), "RegSetValueExA failed");
58 sExpLen1 = ExpandEnvironmentStringsA(sTestpath1, sExpTestpath1, sizeof(sExpTestpath1));
59 sExpLen2 = ExpandEnvironmentStringsA(sTestpath2, sExpTestpath2, sizeof(sExpTestpath2));
61 ok(sExpLen1 > 0, "Couldn't expand %s\n", sTestpath1);
62 ok(sExpLen2 > 0, "Couldn't expand %s\n", sTestpath2);
65 static void test_SHGetValue(void)
71 strcpy(buf, sEmptyBuffer);
74 ok(! SHGetValueA(HKEY_CURRENT_USER, "Software\\Wine\\Test", "Test1", &dwType, buf, &dwSize), "SHGetValueA failed");
75 ok( 0 == strcmp(sExpTestpath1, buf), "(%s,%s)", buf, sExpTestpath1);
76 ok( REG_SZ == dwType, "(%lx)", dwType);
78 strcpy(buf, sEmptyBuffer);
81 ok(! SHGetValueA(HKEY_CURRENT_USER, "Software\\Wine\\Test", "Test2", &dwType, buf, &dwSize), "SHGetValueA failed");
82 ok( 0 == strcmp(sTestpath1, buf) , "(%s)", buf);
83 ok( REG_SZ == dwType , "(%lx)", dwType);
86 static void test_SHGetTegPath(void)
90 strcpy(buf, sEmptyBuffer);
91 ok(! SHRegGetPathA(HKEY_CURRENT_USER, "Software\\Wine\\Test", "Test1", buf, 0), "SHRegGetPathA failed");
92 ok( 0 == strcmp(sExpTestpath1, buf) , "(%s)", buf);
95 static void test_SHQUeryValueEx(void)
102 char * sTestedFunction = "";
106 ok(! RegOpenKeyExA(HKEY_CURRENT_USER, "Software\\Wine\\Test", 0, KEY_QUERY_VALUE, &hKey), "test4 RegOpenKey");
108 /****** SHQueryValueExA ******/
110 sTestedFunction = "SHQueryValueExA";
111 nUsedBuffer1 = max(strlen(sExpTestpath1)+1, strlen(sTestpath1));
112 nUsedBuffer2 = max(strlen(sExpTestpath2)+1, strlen(sTestpath2));
114 * Case 1.1 All arguments are NULL
116 ok(! SHQueryValueExA( hKey, "Test1", NULL, NULL, NULL, NULL), "SHQueryValueExA failed");
119 * Case 1.2 dwType is set
122 ok(! SHQueryValueExA( hKey, "Test1", NULL, &dwType, NULL, NULL), "SHQueryValueExA failed");
123 ok( dwType == REG_SZ, "(%lu)", dwType);
127 * dwExpanded < dwUnExpanded
130 ok(! SHQueryValueExA( hKey, "Test1", NULL, NULL, NULL, &dwSize), "SHQueryValueExA failed");
131 ok( dwSize == nUsedBuffer1, "(%lu,%u)", dwSize, nUsedBuffer1);
134 * dwExpanded > dwUnExpanded
137 ok(! SHQueryValueExA( hKey, "Test3", NULL, NULL, NULL, &dwSize), "SHQueryValueExA failed");
138 ok( dwSize == nUsedBuffer2, "(%lu,%u)", dwSize, nUsedBuffer2);
142 * Case 1 string shrinks during expanding
144 strcpy(buf, sEmptyBuffer);
147 dwRet = SHQueryValueExA( hKey, "Test1", NULL, &dwType, buf, &dwSize);
148 ok( dwRet == ERROR_MORE_DATA, "(%lu)", dwRet);
149 ok( 0 == strcmp(sEmptyBuffer, buf), "(%s)", buf);
150 ok( dwType == REG_SZ, "(%lu)" , dwType);
151 ok( dwSize == nUsedBuffer1, "(%lu,%u)" , dwSize, nUsedBuffer1);
154 * string grows during expanding
156 strcpy(buf, sEmptyBuffer);
159 dwRet = SHQueryValueExA( hKey, "Test3", NULL, &dwType, buf, &dwSize);
160 ok( ERROR_MORE_DATA == dwRet, "ERROR_MORE_DATA");
161 ok( 0 == strcmp(sEmptyBuffer, buf), "(%s)", buf);
162 ok( dwSize == nUsedBuffer2, "(%lu,%u)" , dwSize, nUsedBuffer2);
163 ok( dwType == REG_SZ, "(%lu)" , dwType);
166 * if the unexpanded string fits into the buffer it can get cut when expanded
168 strcpy(buf, sEmptyBuffer);
169 dwSize = sExpLen2 - 4;
171 ok( ERROR_MORE_DATA == SHQueryValueExA( hKey, "Test3", NULL, &dwType, buf, &dwSize), "Expected ERROR_MORE_DATA");
172 ok( 0 == strncmp(sExpTestpath2, buf, sExpLen2 - 4 - 1), "(%s)", buf);
173 ok( sExpLen2 - 4 - 1 == strlen(buf), "(%s)", buf);
174 ok( dwSize == nUsedBuffer2, "(%lu,%u)" , dwSize, nUsedBuffer2);
175 ok( dwType == REG_SZ, "(%lu)" , dwType);
178 * The buffer is NULL but the size is set
180 strcpy(buf, sEmptyBuffer);
183 dwRet = SHQueryValueExA( hKey, "Test3", NULL, &dwType, NULL, &dwSize);
184 ok( ERROR_SUCCESS == dwRet, "(%lu)", dwRet);
185 ok( dwSize == nUsedBuffer2, "(%lu,%u)" , dwSize, nUsedBuffer2);
186 ok( dwType == REG_SZ, "(%lu)" , dwType);
194 create_test_entrys();
196 test_SHQUeryValueEx();