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"
26 static HKEY hkey_main
;
28 /* delete key and all its subkeys */
29 static DWORD
delete_key( HKEY hkey
)
34 while (!(ret
= RegEnumKeyW(hkey
, 0, name
, sizeof(name
))))
36 if ((ret
= delete_key( hkey
))) break;
38 if (ret
!= ERROR_NO_MORE_ITEMS
) return ret
;
39 RegDeleteKeyA( hkey
, NULL
);
43 static void setup_main_key(void)
45 if (RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey_main
)) delete_key( hkey_main
);
47 assert (!RegCreateKeyExA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", 0, NULL
,
48 REG_OPTION_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &hkey_main
, NULL
));
51 static void test_enum_value(void)
54 char value
[20], data
[20];
55 WCHAR valueW
[20], dataW
[20];
56 DWORD val_count
, data_count
, type
;
57 static const WCHAR foobarW
[] = {'f','o','o','b','a','r',0};
58 static const WCHAR testW
[] = {'T','e','s','t',0};
59 static const WCHAR xxxW
[] = {'x','x','x','x','x','x','x','x',0};
61 res
= RegSetValueExA( hkey_main
, "Test", 0, REG_SZ
, (BYTE
*)"foobar", 7 );
62 ok( res
== 0, "RegSetValueExA failed error %ld", res
);
64 /* overflow both name and data */
68 strcpy( value
, "xxxxxxxxxx" );
69 strcpy( data
, "xxxxxxxxxx" );
70 res
= RegEnumValueA( hkey_main
, 0, value
, &val_count
, NULL
, &type
, data
, &data_count
);
71 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %ld", res
);
72 ok( val_count
== 2, "val_count set to %ld", val_count
);
73 ok( data_count
== 7, "data_count set to %ld instead of 7", data_count
);
74 ok( type
== REG_SZ
, "type %ld is not REG_SZ", type
);
75 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'", value
);
76 ok( !strcmp( data
, "xxxxxxxxxx" ), "data set to '%s'", data
);
82 strcpy( value
, "xxxxxxxxxx" );
83 strcpy( data
, "xxxxxxxxxx" );
84 res
= RegEnumValueA( hkey_main
, 0, value
, &val_count
, NULL
, &type
, data
, &data_count
);
85 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %ld", res
);
86 ok( val_count
== 3, "val_count set to %ld", val_count
);
87 ok( data_count
== 7, "data_count set to %ld instead of 7", data_count
);
88 ok( type
== REG_SZ
, "type %ld is not REG_SZ", type
);
89 ok( !strcmp( value
, "Te" ), "value set to '%s' instead of 'Te'", value
);
90 ok( !strcmp( data
, "foobar" ), "data set to '%s' instead of 'foobar'", data
);
92 /* overflow empty name */
96 strcpy( value
, "xxxxxxxxxx" );
97 strcpy( data
, "xxxxxxxxxx" );
98 res
= RegEnumValueA( hkey_main
, 0, value
, &val_count
, NULL
, &type
, data
, &data_count
);
99 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %ld", res
);
100 ok( val_count
== 0, "val_count set to %ld", val_count
);
101 ok( data_count
== 7, "data_count set to %ld instead of 7", data_count
);
102 ok( type
== REG_SZ
, "type %ld is not REG_SZ", type
);
103 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'", value
);
104 ok( !strcmp( data
, "foobar" ), "data set to '%s' instead of 'foobar'", data
);
110 strcpy( value
, "xxxxxxxxxx" );
111 strcpy( data
, "xxxxxxxxxx" );
112 res
= RegEnumValueA( hkey_main
, 0, value
, &val_count
, NULL
, &type
, data
, &data_count
);
113 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %ld", res
);
114 ok( val_count
== 20, "val_count set to %ld", val_count
);
115 ok( data_count
== 7, "data_count set to %ld instead of 7", data_count
);
116 ok( type
== REG_SZ
, "type %ld is not REG_SZ", type
);
117 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'", value
);
118 ok( !strcmp( data
, "xxxxxxxxxx" ), "data set to '%s'", data
);
124 strcpy( value
, "xxxxxxxxxx" );
125 strcpy( data
, "xxxxxxxxxx" );
126 res
= RegEnumValueA( hkey_main
, 0, value
, &val_count
, NULL
, &type
, data
, &data_count
);
127 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %ld", res
);
128 ok( val_count
== 4, "val_count set to %ld instead of 4", val_count
);
129 ok( data_count
== 7, "data_count set to %ld instead of 7", data_count
);
130 ok( type
== REG_SZ
, "type %ld is not REG_SZ", type
);
131 ok( !strcmp( value
, "Test" ), "value is '%s' instead of Test", value
);
132 ok( !strcmp( data
, "foobar" ), "data is '%s' instead of foobar", data
);
136 res
= RegSetValueExW( hkey_main
, testW
, 0, REG_SZ
, (BYTE
*)foobarW
, 7*sizeof(WCHAR
) );
137 ok( res
== 0, "RegSetValueExW failed error %ld", res
);
139 /* overflow both name and data */
143 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
144 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
145 res
= RegEnumValueW( hkey_main
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
146 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %ld", res
);
147 ok( val_count
== 2, "val_count set to %ld", val_count
);
148 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %ld instead of 7*sizeof(WCHAR)", data_count
);
149 ok( type
== REG_SZ
, "type %ld is not REG_SZ", type
);
150 ok( !memcmp( valueW
, xxxW
, sizeof(xxxW
) ), "value modified" );
151 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified" );
157 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
158 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
159 res
= RegEnumValueW( hkey_main
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
160 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %ld", res
);
161 ok( val_count
== 3, "val_count set to %ld", val_count
);
162 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %ld instead of 7*sizeof(WCHAR)", data_count
);
163 ok( type
== REG_SZ
, "type %ld is not REG_SZ", type
);
164 ok( !memcmp( valueW
, xxxW
, sizeof(xxxW
) ), "value modified" );
165 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified" );
171 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
172 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
173 res
= RegEnumValueW( hkey_main
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
174 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %ld", res
);
175 ok( val_count
== 4, "val_count set to %ld instead of 4", val_count
);
176 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %ld instead of 7*sizeof(WCHAR)", data_count
);
177 ok( type
== REG_SZ
, "type %ld is not REG_SZ", type
);
178 ok( !memcmp( valueW
, testW
, sizeof(testW
) ), "value is not 'Test'" );
179 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified" );
185 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
186 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
187 res
= RegEnumValueW( hkey_main
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
188 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %ld", res
);
189 ok( val_count
== 4, "val_count set to %ld instead of 4", val_count
);
190 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %ld instead of 7*sizeof(WCHAR)", data_count
);
191 ok( type
== REG_SZ
, "type %ld is not REG_SZ", type
);
192 ok( !memcmp( valueW
, testW
, sizeof(testW
) ), "value is not 'Test'" );
193 ok( !memcmp( dataW
, foobarW
, sizeof(foobarW
) ), "data is not 'foobar'" );
196 RegDeleteValueA( hkey_main
, "Test" );
205 delete_key( hkey_main
);