2 * Unit tests for registry functions
4 * Copyright (c) 2002 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/test.h"
27 static HKEY hkey_main
;
29 /* delete key and all its subkeys */
30 static DWORD
delete_key( HKEY hkey
)
35 while (!(ret
= RegEnumKeyA(hkey
, 0, name
, sizeof(name
))))
38 if (!(ret
= RegOpenKeyExA( hkey
, name
, 0, KEY_ENUMERATE_SUB_KEYS
, &tmp
)))
40 ret
= delete_key( tmp
);
45 if (ret
!= ERROR_NO_MORE_ITEMS
) return ret
;
46 RegDeleteKeyA( hkey
, NULL
);
50 static void setup_main_key(void)
52 if (RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey_main
)) delete_key( hkey_main
);
54 assert (!RegCreateKeyExA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", 0, NULL
,
55 REG_OPTION_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &hkey_main
, NULL
));
58 static void test_enum_value(void)
61 char value
[20], data
[20];
62 WCHAR valueW
[20], dataW
[20];
63 DWORD val_count
, data_count
, type
;
64 static const WCHAR foobarW
[] = {'f','o','o','b','a','r',0};
65 static const WCHAR testW
[] = {'T','e','s','t',0};
66 static const WCHAR xxxW
[] = {'x','x','x','x','x','x','x','x',0};
68 res
= RegSetValueExA( hkey_main
, "Test", 0, REG_SZ
, (BYTE
*)"foobar", 7 );
69 ok( res
== 0, "RegSetValueExA failed error %ld", res
);
71 /* overflow both name and data */
75 strcpy( value
, "xxxxxxxxxx" );
76 strcpy( data
, "xxxxxxxxxx" );
77 res
= RegEnumValueA( hkey_main
, 0, value
, &val_count
, NULL
, &type
, data
, &data_count
);
78 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %ld", res
);
79 ok( val_count
== 2, "val_count set to %ld", val_count
);
80 ok( data_count
== 7, "data_count set to %ld instead of 7", data_count
);
81 ok( type
== REG_SZ
, "type %ld is not REG_SZ", type
);
82 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'", value
);
83 ok( !strcmp( data
, "xxxxxxxxxx" ), "data set to '%s'", data
);
89 strcpy( value
, "xxxxxxxxxx" );
90 strcpy( data
, "xxxxxxxxxx" );
91 res
= RegEnumValueA( hkey_main
, 0, value
, &val_count
, NULL
, &type
, data
, &data_count
);
92 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %ld", res
);
93 /* Win9x returns 2 as specified by MSDN but NT returns 3... */
94 ok( val_count
== 2 || val_count
== 3, "val_count set to %ld", val_count
);
95 ok( data_count
== 7, "data_count set to %ld instead of 7", data_count
);
96 ok( type
== REG_SZ
, "type %ld is not REG_SZ", type
);
97 ok( !strcmp( value
, "Te" ), "value set to '%s' instead of 'Te'", value
);
98 ok( !strcmp( data
, "foobar" ), "data set to '%s' instead of 'foobar'", data
);
100 /* overflow empty name */
104 strcpy( value
, "xxxxxxxxxx" );
105 strcpy( data
, "xxxxxxxxxx" );
106 res
= RegEnumValueA( hkey_main
, 0, value
, &val_count
, NULL
, &type
, data
, &data_count
);
107 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %ld", res
);
108 ok( val_count
== 0, "val_count set to %ld", val_count
);
109 ok( data_count
== 7, "data_count set to %ld instead of 7", data_count
);
110 ok( type
== REG_SZ
, "type %ld is not REG_SZ", type
);
111 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'", value
);
112 ok( !strcmp( data
, "foobar" ), "data set to '%s' instead of 'foobar'", data
);
118 strcpy( value
, "xxxxxxxxxx" );
119 strcpy( data
, "xxxxxxxxxx" );
120 res
= RegEnumValueA( hkey_main
, 0, value
, &val_count
, NULL
, &type
, data
, &data_count
);
121 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %ld", res
);
122 ok( val_count
== 20, "val_count set to %ld", val_count
);
123 ok( data_count
== 7, "data_count set to %ld instead of 7", data_count
);
124 ok( type
== REG_SZ
, "type %ld is not REG_SZ", type
);
125 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'", value
);
126 ok( !strcmp( data
, "xxxxxxxxxx" ), "data set to '%s'", data
);
132 strcpy( value
, "xxxxxxxxxx" );
133 strcpy( data
, "xxxxxxxxxx" );
134 res
= RegEnumValueA( hkey_main
, 0, value
, &val_count
, NULL
, &type
, data
, &data_count
);
135 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %ld", res
);
136 ok( val_count
== 4, "val_count set to %ld instead of 4", val_count
);
137 ok( data_count
== 7, "data_count set to %ld instead of 7", data_count
);
138 ok( type
== REG_SZ
, "type %ld is not REG_SZ", type
);
139 ok( !strcmp( value
, "Test" ), "value is '%s' instead of Test", value
);
140 ok( !strcmp( data
, "foobar" ), "data is '%s' instead of foobar", data
);
145 res
= RegSetValueExW( hkey_main
, testW
, 0, REG_SZ
, (BYTE
*)foobarW
, 7*sizeof(WCHAR
) );
146 if (res
==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED
)
148 ok( res
== 0, "RegSetValueExW failed error %ld", res
);
150 /* overflow both name and data */
154 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
155 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
156 res
= RegEnumValueW( hkey_main
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
157 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %ld", res
);
158 ok( val_count
== 2, "val_count set to %ld", val_count
);
159 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %ld instead of 7*sizeof(WCHAR)", data_count
);
160 ok( type
== REG_SZ
, "type %ld is not REG_SZ", type
);
161 ok( !memcmp( valueW
, xxxW
, sizeof(xxxW
) ), "value modified" );
162 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified" );
168 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
169 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
170 res
= RegEnumValueW( hkey_main
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
171 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %ld", res
);
172 ok( val_count
== 3, "val_count set to %ld", val_count
);
173 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %ld instead of 7*sizeof(WCHAR)", data_count
);
174 ok( type
== REG_SZ
, "type %ld is not REG_SZ", type
);
175 ok( !memcmp( valueW
, xxxW
, sizeof(xxxW
) ), "value modified" );
176 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified" );
182 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
183 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
184 res
= RegEnumValueW( hkey_main
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
185 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %ld", res
);
186 ok( val_count
== 4, "val_count set to %ld instead of 4", val_count
);
187 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %ld instead of 7*sizeof(WCHAR)", data_count
);
188 ok( type
== REG_SZ
, "type %ld is not REG_SZ", type
);
189 ok( !memcmp( valueW
, testW
, sizeof(testW
) ), "value is not 'Test'" );
190 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified" );
196 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
197 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
198 res
= RegEnumValueW( hkey_main
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
199 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %ld", res
);
200 ok( val_count
== 4, "val_count set to %ld instead of 4", val_count
);
201 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %ld instead of 7*sizeof(WCHAR)", data_count
);
202 ok( type
== REG_SZ
, "type %ld is not REG_SZ", type
);
203 ok( !memcmp( valueW
, testW
, sizeof(testW
) ), "value is not 'Test'" );
204 ok( !memcmp( dataW
, foobarW
, sizeof(foobarW
) ), "data is not 'foobar'" );
208 RegDeleteValueA( hkey_main
, "Test" );
217 delete_key( hkey_main
);