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 = "%SYSTEMROOT%\\subdir1";
32 static char * sTestpath2 = "%USERPROFILE%\\subdir1";
34 static char sExpTestpath1[MAX_PATH];
35 static char sExpTestpath2[MAX_PATH];
37 static char * sEmptyBuffer ="0123456789";
39 static void create_test_entrys()
43 ok(!RegCreateKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hKey), "");
47 ok(!RegSetValueExA(hKey,"Test1",0,REG_EXPAND_SZ, sTestpath1, strlen(sTestpath1)), "");
48 ok(!RegSetValueExA(hKey,"Test2",0,REG_SZ, sTestpath1, strlen(sTestpath1)), "");
49 ok(!RegSetValueExA(hKey,"Test3",0,REG_EXPAND_SZ, sTestpath2, strlen(sTestpath2)), "");
53 ExpandEnvironmentStringsA(sTestpath1, sExpTestpath1, sizeof(sExpTestpath1));
54 ExpandEnvironmentStringsA(sTestpath2, sExpTestpath2, sizeof(sExpTestpath2));
55 ok(strlen(sExpTestpath2) > 25, "%USERPROFILE% is set to a short value on this machine. we cant perform all tests.");
58 static void test_SHGetValue(void)
64 strcpy(buf, sEmptyBuffer);
67 ok(! SHGetValueA(HKEY_CURRENT_USER, "Software\\Wine\\Test", "Test1", &dwType, buf, &dwSize), "");
68 ok( 0 == strcmp(sExpTestpath1, buf), "(%s,%s)", buf, sExpTestpath1);
69 ok( REG_SZ == dwType, "(%lx)", dwType);
71 strcpy(buf, sEmptyBuffer);
74 ok(! SHGetValueA(HKEY_CURRENT_USER, "Software\\Wine\\Test", "Test2", &dwType, buf, &dwSize), "");
75 ok( 0 == strcmp(sTestpath1, buf) , "(%s)", buf);
76 ok( REG_SZ == dwType , "(%lx)", dwType);
79 static void test_SHGetTegPath(void)
83 strcpy(buf, sEmptyBuffer);
84 ok(! SHRegGetPathA(HKEY_CURRENT_USER, "Software\\Wine\\Test", "Test1", buf, 0), "");
85 ok( 0 == strcmp(sExpTestpath1, buf) , "(%s)", buf);
88 static void test_SHQUeryValueEx(void)
95 char * sTestedFunction = "";
99 ok(! RegOpenKeyExA(HKEY_CURRENT_USER, "Software\\Wine\\Test", 0, KEY_QUERY_VALUE, &hKey), "test4 RegOpenKey");
101 /****** SHQueryValueExA ******/
103 sTestedFunction = "SHQueryValueExA";
104 nUsedBuffer1 = max(strlen(sExpTestpath1)+1, strlen(sTestpath1));
105 nUsedBuffer2 = max(strlen(sExpTestpath2)+1, strlen(sTestpath2));
107 * Case 1.1 All arguments are NULL
109 ok(! SHQueryValueExA( hKey, "Test1", NULL, NULL, NULL, NULL), "");
112 * Case 1.2 dwType is set
115 ok(! SHQueryValueExA( hKey, "Test1", NULL, &dwType, NULL, NULL), "");
116 ok( dwType == REG_SZ, "(%lu)", dwType);
120 * dwExpanded < dwUnExpanded
123 ok(! SHQueryValueExA( hKey, "Test1", NULL, NULL, NULL, &dwSize), "");
124 ok( dwSize == nUsedBuffer1, "(%lu,%lu)", dwSize, nUsedBuffer1);
127 * dwExpanded > dwUnExpanded
130 ok(! SHQueryValueExA( hKey, "Test3", NULL, NULL, NULL, &dwSize), "");
131 ok( dwSize == nUsedBuffer2, "(%lu,%lu)", dwSize, nUsedBuffer2);
135 * Case 1 string shrinks during expanding
137 strcpy(buf, sEmptyBuffer);
140 dwRet = SHQueryValueExA( hKey, "Test1", NULL, &dwType, buf, &dwSize);
141 ok( dwRet == ERROR_MORE_DATA, "(%lu)", dwRet);
142 ok( 0 == strcmp(sEmptyBuffer, buf), "(%s)", buf);
143 ok( dwType == REG_SZ, "(%lu)" , dwType);
144 ok( dwSize == nUsedBuffer1, "(%lu,%lu)" , dwSize, nUsedBuffer1);
147 * string grows during expanding
149 strcpy(buf, sEmptyBuffer);
152 dwRet = SHQueryValueExA( hKey, "Test3", NULL, &dwType, buf, &dwSize);
153 ok( ERROR_MORE_DATA == dwRet, "");
154 ok( 0 == strcmp(sEmptyBuffer, buf), "(%s)", buf);
155 ok( dwSize == nUsedBuffer2, "(%lu,%lu)" , dwSize, nUsedBuffer2);
156 ok( dwType == REG_SZ, "(%lu)" , dwType);
159 * if the unexpanded string fits into the buffer it can get cut when expanded
161 strcpy(buf, sEmptyBuffer);
164 ok( ERROR_MORE_DATA == SHQueryValueExA( hKey, "Test3", NULL, &dwType, buf, &dwSize), "");
165 ok( 0 == strncmp(sExpTestpath2, buf, 24-1), "(%s)", buf);
166 ok( 24-1 == strlen(buf), "(%s)", buf);
167 ok( dwSize == nUsedBuffer2, "(%lu,%lu)" , dwSize, nUsedBuffer2);
168 ok( dwType == REG_SZ, "(%lu)" , dwType);
171 * The buffer is NULL but the size is set
173 strcpy(buf, sEmptyBuffer);
176 dwRet = SHQueryValueExA( hKey, "Test3", NULL, &dwType, NULL, &dwSize);
177 ok( ERROR_SUCCESS == dwRet, "(%lu)", dwRet);
178 ok( dwSize == nUsedBuffer2, "(%lu,%lu)" , dwSize, nUsedBuffer2);
179 ok( dwType == REG_SZ, "(%lu)" , dwType);
187 create_test_entrys();
189 test_SHQUeryValueEx();