Fixed another regression in PlaySound.
[wine.git] / dlls / shlwapi / tests / shreg.c
blob6ce7d41dcea64ef02b9c9c5d1ed6030b0f6cffd8
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 "winerror.h"
27 #include "winreg.h"
28 #include "winuser.h"
29 #include "shlwapi.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()
41 HKEY hKey;
43 ok(!RegCreateKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hKey), "");
45 if (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)), "");
50 RegCloseKey(hKey);
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)
60 DWORD dwSize;
61 DWORD dwType;
62 char buf[MAX_PATH];
64 strcpy(buf, sEmptyBuffer);
65 dwSize = MAX_PATH;
66 dwType = -1;
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);
72 dwSize = MAX_PATH;
73 dwType = -1;
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)
81 char buf[MAX_PATH];
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)
90 HKEY hKey;
91 DWORD dwSize;
92 DWORD dwType;
93 char buf[MAX_PATH];
94 DWORD dwRet;
95 char * sTestedFunction = "";
96 int nUsedBuffer1;
97 int nUsedBuffer2;
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
114 dwType = -1;
115 ok(! SHQueryValueExA( hKey, "Test1", NULL, &dwType, NULL, NULL), "");
116 ok( dwType == REG_SZ, "(%lu)", dwType);
119 * dwSize is set
120 * dwExpanded < dwUnExpanded
122 dwSize = 6;
123 ok(! SHQueryValueExA( hKey, "Test1", NULL, NULL, NULL, &dwSize), "");
124 ok( dwSize == nUsedBuffer1, "(%lu,%lu)", dwSize, nUsedBuffer1);
127 * dwExpanded > dwUnExpanded
129 dwSize = 6;
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);
138 dwSize = 6;
139 dwType = -1;
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);
150 dwSize = 6;
151 dwType = -1;
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);
162 dwSize = 24;
163 dwType = -1;
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);
174 dwSize = 6;
175 dwType = -1;
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);
182 RegCloseKey(hKey);
185 START_TEST(shreg)
187 create_test_entrys();
188 test_SHGetValue();
189 test_SHQUeryValueEx();
190 test_SHGetTegPath();