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"
28 #include "wine/obj_base.h"
29 #include "wine/obj_storage.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()
44 ok(!RegCreateKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &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
)), "");
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)
65 strcpy(buf
, sEmptyBuffer
);
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
);
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)
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)
96 char * sTestedFunction
= "";
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
116 ok(! SHQueryValueExA( hKey
, "Test1", NULL
, &dwType
, NULL
, NULL
), "");
117 ok( dwType
== REG_SZ
, "(%lu)", dwType
);
121 * dwExpanded < dwUnExpanded
124 ok(! SHQueryValueExA( hKey
, "Test1", NULL
, NULL
, NULL
, &dwSize
), "");
125 ok( dwSize
== nUsedBuffer1
, "(%lu,%lu)", dwSize
, nUsedBuffer1
);
128 * dwExpanded > dwUnExpanded
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
);
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
);
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
);
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
);
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
);
188 create_test_entrys();
190 test_SHQUeryValueEx();