taskkill: Add Lithuanian translation.
[wine.git] / programs / regedit / tests / regedit.c
blobda8b1e0d1fa5b801931b3934825c904d95483686
1 /*
2 * Copyright 2010 Andrew Eikum for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <windows.h>
21 #include "wine/test.h"
23 static BOOL supports_wchar;
25 #define lok ok_(__FILE__,line)
27 #define exec_import_str(c) r_exec_import_str(__LINE__, c)
28 static BOOL r_exec_import_str(unsigned line, const char *file_contents)
30 STARTUPINFOA si = {sizeof(STARTUPINFOA)};
31 PROCESS_INFORMATION pi;
32 HANDLE regfile;
33 DWORD written, dr;
34 BOOL br;
35 char cmd[] = "regedit /s test.reg";
37 regfile = CreateFileA("test.reg", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
38 FILE_ATTRIBUTE_NORMAL, NULL);
39 lok(regfile != INVALID_HANDLE_VALUE, "Failed to create test.reg file\n");
40 if(regfile == INVALID_HANDLE_VALUE)
41 return FALSE;
43 br = WriteFile(regfile, file_contents, strlen(file_contents), &written,
44 NULL);
45 lok(br == TRUE, "WriteFile failed: %d\n", GetLastError());
47 CloseHandle(regfile);
49 if(!CreateProcessA(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
50 return FALSE;
52 dr = WaitForSingleObject(pi.hProcess, 10000);
53 if(dr == WAIT_TIMEOUT)
54 TerminateProcess(pi.hProcess, 1);
55 CloseHandle(pi.hThread);
56 CloseHandle(pi.hProcess);
58 br = DeleteFileA("test.reg");
59 lok(br == TRUE, "DeleteFileA failed: %d\n", GetLastError());
61 return (dr != WAIT_TIMEOUT);
64 #define exec_import_wstr(c) r_exec_import_wstr(__LINE__, c)
65 static BOOL r_exec_import_wstr(unsigned line, const WCHAR *file_contents)
67 STARTUPINFOA si = {sizeof(STARTUPINFOA)};
68 PROCESS_INFORMATION pi;
69 HANDLE regfile;
70 DWORD written, dr;
71 BOOL br;
72 char cmd[] = "regedit /s test.reg";
74 regfile = CreateFileA("test.reg", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
75 FILE_ATTRIBUTE_NORMAL, NULL);
76 lok(regfile != INVALID_HANDLE_VALUE, "Failed to create test.reg file\n");
77 if(regfile == INVALID_HANDLE_VALUE)
78 return FALSE;
80 br = WriteFile(regfile, file_contents,
81 lstrlenW(file_contents) * sizeof(WCHAR), &written, NULL);
82 lok(br == TRUE, "WriteFile failed: %d\n", GetLastError());
84 CloseHandle(regfile);
86 if(!CreateProcessA(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
87 return FALSE;
89 dr = WaitForSingleObject(pi.hProcess, 10000);
90 if(dr == WAIT_TIMEOUT)
91 TerminateProcess(pi.hProcess, 1);
92 CloseHandle(pi.hThread);
93 CloseHandle(pi.hProcess);
95 br = DeleteFileA("test.reg");
96 lok(br == TRUE, "DeleteFileA failed: %d\n", GetLastError());
98 return (dr != WAIT_TIMEOUT);
101 #define verify_reg_sz(k,s,n,e) r_verify_reg_sz(__LINE__,k,s,n,e)
102 static void r_verify_reg_sz(unsigned line, HKEY key, const char *subkey,
103 const char *value_name, const char *exp_value)
105 LONG lr;
106 DWORD fnd_type, fnd_len;
107 char fnd_value[1024];
108 HKEY fnd_key;
110 lr = RegOpenKeyExA(key, subkey, 0, KEY_READ, &fnd_key);
111 lok(lr == ERROR_SUCCESS, "RegOpenKeyExA failed: %d\n", lr);
112 if(lr != ERROR_SUCCESS)
113 return;
115 fnd_len = sizeof(fnd_value);
116 lr = RegQueryValueExA(fnd_key, value_name, NULL, &fnd_type,
117 (BYTE*)fnd_value, &fnd_len);
118 RegCloseKey(fnd_key);
119 lok(lr == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", lr);
120 if(lr != ERROR_SUCCESS)
121 return;
123 lok(fnd_type == REG_SZ, "Got wrong type: %d\n", fnd_type);
124 if(fnd_type != REG_SZ)
125 return;
126 lok(!strcmp(exp_value, fnd_value),
127 "Strings differ: expected %s, got %s\n", exp_value, fnd_value);
130 #define verify_reg_wsz(k,s,n,e) r_verify_reg_wsz(__LINE__,k,s,n,e)
131 static void r_verify_reg_wsz(unsigned line, HKEY key, const char *subkey,
132 const char *value_name, const WCHAR *exp_value)
134 LONG lr;
135 DWORD fnd_type, fnd_len;
136 WCHAR fnd_value[1024], value_nameW[1024];
137 HKEY fnd_key;
139 lr = RegOpenKeyExA(key, subkey, 0, KEY_READ, &fnd_key);
140 lok(lr == ERROR_SUCCESS, "RegOpenKeyExA failed: %d\n", lr);
141 if(lr != ERROR_SUCCESS)
142 return;
144 MultiByteToWideChar(CP_ACP, 0, value_name, -1, value_nameW,
145 sizeof(value_nameW));
147 fnd_len = sizeof(fnd_value);
148 lr = RegQueryValueExW(fnd_key, value_nameW, NULL, &fnd_type,
149 (BYTE*)fnd_value, &fnd_len);
150 RegCloseKey(fnd_key);
151 lok(lr == ERROR_SUCCESS, "RegQueryValueExW failed: %d\n", lr);
152 if(lr != ERROR_SUCCESS)
153 return;
155 lok(fnd_type == REG_SZ, "Got wrong type: %d\n", fnd_type);
156 if(fnd_type != REG_SZ)
157 return;
158 lok(!lstrcmpW(exp_value, fnd_value),
159 "Strings differ: expected %s, got %s\n",
160 wine_dbgstr_w(exp_value), wine_dbgstr_w(fnd_value));
163 #define verify_reg_dword(k,s,n,e) r_verify_reg_dword(__LINE__,k,s,n,e)
164 static void r_verify_reg_dword(unsigned line, HKEY key, const char *subkey,
165 const char *value_name, DWORD exp_value)
167 LONG lr;
168 DWORD fnd_type, fnd_len, fnd_value;
169 HKEY fnd_key;
171 lr = RegOpenKeyExA(key, subkey, 0, KEY_READ, &fnd_key);
172 lok(lr == ERROR_SUCCESS, "RegOpenKeyExA failed: %d\n", lr);
173 if(lr != ERROR_SUCCESS)
174 return;
176 fnd_len = sizeof(fnd_value);
177 lr = RegQueryValueExA(fnd_key, value_name, NULL, &fnd_type,
178 (BYTE *)&fnd_value, &fnd_len);
179 RegCloseKey(fnd_key);
180 lok(lr == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", lr);
181 if(lr != ERROR_SUCCESS)
182 return;
184 lok(fnd_type == REG_DWORD, "Got wrong type: %d\n", fnd_type);
185 if(fnd_type != REG_DWORD)
186 return;
187 lok(fnd_value == exp_value, "Values differ: expected: 0x%x, got: 0x%x\n",
188 exp_value, fnd_value);
191 #define verify_reg_binary(k,s,n,e,z) r_verify_reg_binary(__LINE__,k,s,n,e,z)
192 static void r_verify_reg_binary(unsigned line, HKEY key, const char *subkey,
193 const char *value_name, const char *exp_value, int exp_len)
195 LONG lr;
196 DWORD fnd_type, fnd_len;
197 char fnd_value[1024];
198 HKEY fnd_key;
200 lr = RegOpenKeyExA(key, subkey, 0, KEY_READ, &fnd_key);
201 lok(lr == ERROR_SUCCESS, "RegOpenKeyExA failed: %d\n", lr);
202 if(lr != ERROR_SUCCESS)
203 return;
205 fnd_len = sizeof(fnd_value);
206 lr = RegQueryValueExA(fnd_key, value_name, NULL, &fnd_type,
207 (BYTE*)fnd_value, &fnd_len);
208 RegCloseKey(fnd_key);
209 lok(lr == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", lr);
210 if(lr != ERROR_SUCCESS)
211 return;
213 lok(fnd_type == REG_BINARY, "Got wrong type: %d\n", fnd_type);
214 if(fnd_type != REG_BINARY)
215 return;
216 lok(fnd_len == exp_len,
217 "Lengths differ: expected %d, got %d\n", exp_len, fnd_len);
218 lok(!memcmp(exp_value, fnd_value, exp_len),
219 "Data differs\n");
222 #define verify_reg_nonexist(k,s,n) r_verify_reg_nonexist(__LINE__,k,s,n)
223 static void r_verify_reg_nonexist(unsigned line, HKEY key, const char *subkey,
224 const char *value_name)
226 LONG lr;
227 DWORD fnd_type, fnd_len;
228 char fnd_value[32];
229 HKEY fnd_key;
231 lr = RegOpenKeyExA(key, subkey, 0, KEY_READ, &fnd_key);
232 lok(lr == ERROR_SUCCESS, "RegOpenKeyExA failed: %d\n", lr);
233 if(lr != ERROR_SUCCESS)
234 return;
236 fnd_len = sizeof(fnd_value);
237 lr = RegQueryValueExA(fnd_key, value_name, NULL, &fnd_type,
238 (BYTE*)fnd_value, &fnd_len);
239 RegCloseKey(fnd_key);
240 lok(lr == ERROR_FILE_NOT_FOUND, "Reg value shouldn't exist: %s\n",
241 value_name);
244 static void test_basic_import(void)
246 char exp_binary[] = {0xAA,0xBB,0xCC,0x11};
247 WCHAR wide_test[] = {0xFEFF,'W','i','n','d','o','w','s',' ','R','e','g',
248 'i','s','t','r','y',' ','E','d','i','t','o','r',' ','V','e','r','s',
249 'i','o','n',' ','5','.','0','0','\n','\n',
250 '[','H','K','E','Y','_','C','U','R','R','E','N','T','_','U','S','E',
251 'R','\\','S','o','f','t','w','a','r','e','\\','W','i','n','e','\\',
252 'r','e','g','e','d','i','t','_','t','e','s','t',']','\n',
253 '"','T','e','s','t','V','a','l','u','e','3','"','=','"',0x3041,'V','a',
254 'l','u','e','"','\n',0};
255 WCHAR wide_test_r[] = {0xFEFF,'W','i','n','d','o','w','s',' ','R','e','g',
256 'i','s','t','r','y',' ','E','d','i','t','o','r',' ','V','e','r','s',
257 'i','o','n',' ','5','.','0','0','\r','\r',
258 '[','H','K','E','Y','_','C','U','R','R','E','N','T','_','U','S','E',
259 'R','\\','S','o','f','t','w','a','r','e','\\','W','i','n','e','\\',
260 'r','e','g','e','d','i','t','_','t','e','s','t',']','\r',
261 '"','T','e','s','t','V','a','l','u','e','5','"','=','"',0x3041,'V','a',
262 'l','u','e','"','\r',0};
263 WCHAR wide_exp[] = {0x3041,'V','a','l','u','e',0};
264 LONG lr;
266 lr = RegDeleteKeyA(HKEY_CURRENT_USER, "Software\\Wine\\regedit_test");
267 ok(lr == ERROR_SUCCESS || lr == ERROR_FILE_NOT_FOUND,
268 "RegDeleteKeyA failed: %d\n", lr);
270 exec_import_str("REGEDIT4\n\n"
271 "[HKEY_CURRENT_USER\\Software\\Wine\\regedit_test]\n"
272 "\"TestValue\"=\"AValue\"\n");
273 verify_reg_sz(HKEY_CURRENT_USER, "Software\\Wine\\regedit_test",
274 "TestValue", "AValue");
276 exec_import_str("REGEDIT4\r\n\r\n"
277 "[HKEY_CURRENT_USER\\Software\\Wine\\regedit_test]\r\n"
278 "\"TestValue2\"=\"BValue\"\r\n");
279 verify_reg_sz(HKEY_CURRENT_USER, "Software\\Wine\\regedit_test",
280 "TestValue2", "BValue");
282 if(supports_wchar){
283 exec_import_wstr(wide_test);
284 verify_reg_wsz(HKEY_CURRENT_USER, "Software\\Wine\\regedit_test",
285 "TestValue3", wide_exp);
287 exec_import_wstr(wide_test_r);
288 verify_reg_wsz(HKEY_CURRENT_USER, "Software\\Wine\\regedit_test",
289 "TestValue5", wide_exp);
290 }else
291 win_skip("Some WCHAR tests skipped\n");
293 exec_import_str("REGEDIT4\r\r"
294 "[HKEY_CURRENT_USER\\Software\\Wine\\regedit_test]\r"
295 "\"TestValue4\"=\"DValue\"\r");
296 verify_reg_sz(HKEY_CURRENT_USER, "Software\\Wine\\regedit_test",
297 "TestValue4", "DValue");
299 exec_import_str("REGEDIT4\n\n"
300 "[HKEY_CURRENT_USER\\Software\\Wine\\regedit_test]\n"
301 "\"TestDword\"=dword:00000017\n");
302 verify_reg_dword(HKEY_CURRENT_USER, "Software\\Wine\\regedit_test",
303 "TestDword", 0x17);
305 exec_import_str("REGEDIT4\n\n"
306 "[HKEY_CURRENT_USER\\Software\\Wine\\regedit_test]\n"
307 "\"TestBinary\"=hex:aa,bb,cc,11\n");
308 verify_reg_binary(HKEY_CURRENT_USER, "Software\\Wine\\regedit_test",
309 "TestBinary", exp_binary, sizeof(exp_binary));
311 exec_import_str("REGEDIT4\n\n"
312 "[HKEY_CURRENT_USER\\Software\\Wine\\regedit_test]\n"
313 "\"With=Equals\"=\"asdf\"\n");
314 verify_reg_sz(HKEY_CURRENT_USER, "Software\\Wine\\regedit_test",
315 "With=Equals", "asdf");
317 lr = RegDeleteKeyA(HKEY_CURRENT_USER, "Software\\Wine\\regedit_test");
318 ok(lr == ERROR_SUCCESS, "RegDeleteKeyA failed: %d\n", lr);
321 static void test_invalid_import(void)
323 LONG lr;
325 lr = RegDeleteKeyA(HKEY_CURRENT_USER, "Software\\Wine\\regedit_test");
326 ok(lr == ERROR_SUCCESS || lr == ERROR_FILE_NOT_FOUND,
327 "RegDeleteKeyA failed: %d\n", lr);
329 exec_import_str("REGEDIT4\n\n"
330 "[HKEY_CURRENT_USER\\Software\\Wine\\regedit_test]\n"
331 "\"TestNoEndQuote\"=\"Asdffdsa\n");
332 verify_reg_nonexist(HKEY_CURRENT_USER, "Software\\Wine\\regedit_test",
333 "TestNoEndQuote");
335 exec_import_str("REGEDIT4\n\n"
336 "[HKEY_CURRENT_USER\\Software\\Wine\\regedit_test]\n"
337 "\"TestNoBeginQuote\"=Asdffdsa\"\n");
338 verify_reg_nonexist(HKEY_CURRENT_USER, "Software\\Wine\\regedit_test",
339 "TestNoBeginQuote");
341 exec_import_str("REGEDIT4\n\n"
342 "[HKEY_CURRENT_USER\\Software\\Wine\\regedit_test]\n"
343 "\"TestNoQuotes\"=Asdffdsa\n");
344 verify_reg_nonexist(HKEY_CURRENT_USER, "Software\\Wine\\regedit_test",
345 "TestNoQuotes");
347 exec_import_str("REGEDIT4\n\n"
348 "[HKEY_CURRENT_USER\\Software\\Wine\\regedit_test]\n"
349 "\"NameNoEndQuote=\"Asdffdsa\"\n");
350 verify_reg_nonexist(HKEY_CURRENT_USER, "Software\\Wine\\regedit_test",
351 "NameNoEndQuote");
353 exec_import_str("REGEDIT4\n\n"
354 "[HKEY_CURRENT_USER\\Software\\Wine\\regedit_test]\n"
355 "NameNoBeginQuote\"=\"Asdffdsa\"\n");
356 verify_reg_nonexist(HKEY_CURRENT_USER, "Software\\Wine\\regedit_test",
357 "NameNoBeginQuote");
359 exec_import_str("REGEDIT4\n\n"
360 "[HKEY_CURRENT_USER\\Software\\Wine\\regedit_test]\n"
361 "NameNoQuotes=\"Asdffdsa\"\n");
362 verify_reg_nonexist(HKEY_CURRENT_USER, "Software\\Wine\\regedit_test",
363 "NameNoQuotes");
365 exec_import_str("REGEDIT4\n\n"
366 "[HKEY_CURRENT_USER\\Software\\Wine\\regedit_test]\n"
367 "\"MixedQuotes=Asdffdsa\"\n");
368 verify_reg_nonexist(HKEY_CURRENT_USER, "Software\\Wine\\regedit_test",
369 "MixedQuotes");
370 verify_reg_nonexist(HKEY_CURRENT_USER, "Software\\Wine\\regedit_test",
371 "MixedQuotes=Asdffdsa");
373 lr = RegDeleteKeyA(HKEY_CURRENT_USER, "Software\\Wine\\regedit_test");
374 ok(lr == ERROR_SUCCESS, "RegDeleteKeyA failed: %d\n", lr);
377 START_TEST(regedit)
379 WCHAR wchar_test[] = {0xFEFF,'W','i','n','d','o','w','s',' ','R','e','g',
380 'i','s','t','r','y',' ','E','d','i','t','o','r',' ','V','e','r','s',
381 'i','o','n',' ','5','.','0','0','\n','\n',0};
383 if(!exec_import_str("REGEDIT4\r\n\r\n")){
384 win_skip("regedit not available, skipping regedit tests\n");
385 return;
388 supports_wchar = exec_import_wstr(wchar_test);
390 test_basic_import();
391 test_invalid_import();