Added some tests.
[wine/gsoc_dplay.git] / dlls / shlwapi / tests / shreg.c
blobf2c01c12589f4ad4c4c2de6cca72aa9c33965814
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
20 #include <assert.h>
21 #include <stdlib.h>
22 #include <stdio.h>
24 #include "wine/test.h"
25 #include "winbase.h"
26 #include "winreg.h"
27 #include "winuser.h"
28 #include "wine/obj_base.h"
29 #include "wine/obj_storage.h"
30 #include "shlwapi.h"
32 static char * sTestpath1 = "%SYSTEMROOT%\\subdir1";
33 static char * sTestpath2 = "%USERPROFILE%\\subdir1";
35 static char sExpTestpath1[MAX_PATH];
36 static char sExpTestpath2[MAX_PATH];
38 static char * sEmptyBuffer ="0123456789";
40 static void create_test_entrys()
42 HKEY hKey;
44 ok(!RegCreateKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hKey), "");
46 if (hKey)
48 ok(!RegSetValueExA(hKey,"Test1",0,REG_EXPAND_SZ, sTestpath1, strlen(sTestpath1)), "");
49 ok(!RegSetValueExA(hKey,"Test2",0,REG_SZ, sTestpath1, strlen(sTestpath1)), "");
50 ok(!RegSetValueExA(hKey,"Test3",0,REG_EXPAND_SZ, sTestpath2, strlen(sTestpath2)), "");
51 RegCloseKey(hKey);
54 ExpandEnvironmentStringsA(sTestpath1, sExpTestpath1, sizeof(sExpTestpath1));
55 ExpandEnvironmentStringsA(sTestpath2, sExpTestpath2, sizeof(sExpTestpath2));
56 ok(strlen(sExpTestpath2) > 25, "%USERPROFILE% is set to a short value on this machine. we cant perform all tests.");
59 static void test_SHGetValue(void)
61 DWORD dwSize;
62 DWORD dwType;
63 char buf[MAX_PATH];
65 strcpy(buf, sEmptyBuffer);
66 dwSize = MAX_PATH;
67 dwType = -1;
68 ok(! SHGetValueA(HKEY_CURRENT_USER, "Software\\Wine\\Test", "Test1", &dwType, buf, &dwSize), "");
69 ok( 0 == strcmp(sExpTestpath1, buf), "(%s,%s)", buf, sExpTestpath1);
70 ok( REG_SZ == dwType, "(%lx)", dwType);
72 strcpy(buf, sEmptyBuffer);
73 dwSize = MAX_PATH;
74 dwType = -1;
75 ok(! SHGetValueA(HKEY_CURRENT_USER, "Software\\Wine\\Test", "Test2", &dwType, buf, &dwSize), "");
76 ok( 0 == strcmp(sTestpath1, buf) , "(%s)", buf);
77 ok( REG_SZ == dwType , "(%lx)", dwType);
80 static void test_SHGetTegPath(void)
82 char buf[MAX_PATH];
84 strcpy(buf, sEmptyBuffer);
85 ok(! SHRegGetPathA(HKEY_CURRENT_USER, "Software\\Wine\\Test", "Test1", buf, 0), "");
86 ok( 0 == strcmp(sExpTestpath1, buf) , "(%s)", buf);
89 static void test_SHQUeryValueEx(void)
91 HKEY hKey;
92 DWORD dwSize;
93 DWORD dwType;
94 char buf[MAX_PATH];
95 DWORD dwRet;
96 char * sTestedFunction = "";
97 int nUsedBuffer1;
98 int nUsedBuffer2;
100 ok(! RegOpenKeyExA(HKEY_CURRENT_USER, "Software\\Wine\\Test", 0, KEY_QUERY_VALUE, &hKey), "test4 RegOpenKey");
102 /****** SHQueryValueExA ******/
104 sTestedFunction = "SHQueryValueExA";
105 nUsedBuffer1 = max(strlen(sExpTestpath1)+1, strlen(sTestpath1));
106 nUsedBuffer2 = max(strlen(sExpTestpath2)+1, strlen(sTestpath2));
108 * Case 1.1 All arguments are NULL
110 ok(! SHQueryValueExA( hKey, "Test1", NULL, NULL, NULL, NULL), "");
113 * Case 1.2 dwType is set
115 dwType = -1;
116 ok(! SHQueryValueExA( hKey, "Test1", NULL, &dwType, NULL, NULL), "");
117 ok( dwType == REG_SZ, "(%lu)", dwType);
120 * dwSize is set
121 * dwExpanded < dwUnExpanded
123 dwSize = 6;
124 ok(! SHQueryValueExA( hKey, "Test1", NULL, NULL, NULL, &dwSize), "");
125 ok( dwSize == nUsedBuffer1, "(%lu,%lu)", dwSize, nUsedBuffer1);
128 * dwExpanded > dwUnExpanded
130 dwSize = 6;
131 ok(! SHQueryValueExA( hKey, "Test3", NULL, NULL, NULL, &dwSize), "");
132 ok( dwSize == nUsedBuffer2, "(%lu,%lu)", dwSize, nUsedBuffer2);
136 * Case 1 string shrinks during expanding
138 strcpy(buf, sEmptyBuffer);
139 dwSize = 6;
140 dwType = -1;
141 dwRet = SHQueryValueExA( hKey, "Test1", NULL, &dwType, buf, &dwSize);
142 ok( dwRet == ERROR_MORE_DATA, "(%lu)", dwRet);
143 ok( 0 == strcmp(sEmptyBuffer, buf), "(%s)", buf);
144 ok( dwType == REG_SZ, "(%lu)" , dwType);
145 ok( dwSize == nUsedBuffer1, "(%lu,%lu)" , dwSize, nUsedBuffer1);
148 * string grows during expanding
150 strcpy(buf, sEmptyBuffer);
151 dwSize = 6;
152 dwType = -1;
153 dwRet = SHQueryValueExA( hKey, "Test3", NULL, &dwType, buf, &dwSize);
154 ok( ERROR_MORE_DATA == dwRet, "");
155 ok( 0 == strcmp(sEmptyBuffer, buf), "(%s)", buf);
156 ok( dwSize == nUsedBuffer2, "(%lu,%lu)" , dwSize, nUsedBuffer2);
157 ok( dwType == REG_SZ, "(%lu)" , dwType);
160 * if the unexpanded string fits into the buffer it can get cut when expanded
162 strcpy(buf, sEmptyBuffer);
163 dwSize = 24;
164 dwType = -1;
165 ok( ERROR_MORE_DATA == SHQueryValueExA( hKey, "Test3", NULL, &dwType, buf, &dwSize), "");
166 ok( 0 == strncmp(sExpTestpath2, buf, 24-1), "(%s)", buf);
167 ok( 24-1 == strlen(buf), "(%s)", buf);
168 ok( dwSize == nUsedBuffer2, "(%lu,%lu)" , dwSize, nUsedBuffer2);
169 ok( dwType == REG_SZ, "(%lu)" , dwType);
172 * The buffer is NULL but the size is set
174 strcpy(buf, sEmptyBuffer);
175 dwSize = 6;
176 dwType = -1;
177 dwRet = SHQueryValueExA( hKey, "Test3", NULL, &dwType, NULL, &dwSize);
178 ok( ERROR_SUCCESS == dwRet, "(%lu)", dwRet);
179 ok( dwSize == nUsedBuffer2, "(%lu,%lu)" , dwSize, nUsedBuffer2);
180 ok( dwType == REG_SZ, "(%lu)" , dwType);
183 RegCloseKey(hKey);
186 START_TEST(shreg)
188 create_test_entrys();
189 test_SHGetValue();
190 test_SHQUeryValueEx();
191 test_SHGetTegPath();