2 * Unit tests for profile functions
4 * Copyright (c) 2003 Stefan Leichter
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #define KEY "ProfileInt"
24 #define SECTION "Test"
25 #define TESTFILE ".\\testwine.ini"
26 #define TESTFILE2 ".\\testwine2.ini"
38 static void test_profile_int(void)
40 struct _profileInt profileInt
[]={
41 { NULL
, NULL
, NULL
, NULL
, 70, 0 , 0}, /* 0 */
42 { NULL
, NULL
, NULL
, TESTFILE
, -1, 4294967295U, 0},
43 { NULL
, NULL
, NULL
, TESTFILE
, 1, 1 , 0},
44 { SECTION
, NULL
, NULL
, TESTFILE
, -1, 4294967295U, 0},
45 { SECTION
, NULL
, NULL
, TESTFILE
, 1, 1 , 0},
46 { NULL
, KEY
, NULL
, TESTFILE
, -1, 4294967295U, 0}, /* 5 */
47 { NULL
, KEY
, NULL
, TESTFILE
, 1, 1 , 0},
48 { SECTION
, KEY
, NULL
, TESTFILE
, -1, 4294967295U, 4294967295U},
49 { SECTION
, KEY
, NULL
, TESTFILE
, 1, 1 , 1},
50 { SECTION
, KEY
, "-1", TESTFILE
, -1, 4294967295U, 4294967295U},
51 { SECTION
, KEY
, "-1", TESTFILE
, 1, 4294967295U, 4294967295U}, /* 10 */
52 { SECTION
, KEY
, "1", TESTFILE
, -1, 1 , 1},
53 { SECTION
, KEY
, "1", TESTFILE
, 1, 1 , 1},
54 { SECTION
, KEY
, "+1", TESTFILE
, -1, 1 , 0},
55 { SECTION
, KEY
, "+1", TESTFILE
, 1, 1 , 0},
56 { SECTION
, KEY
, "4294967296", TESTFILE
, -1, 0 , 0}, /* 15 */
57 { SECTION
, KEY
, "4294967296", TESTFILE
, 1, 0 , 0},
58 { SECTION
, KEY
, "4294967297", TESTFILE
, -1, 1 , 1},
59 { SECTION
, KEY
, "4294967297", TESTFILE
, 1, 1 , 1},
60 { SECTION
, KEY
, "-4294967297", TESTFILE
, -1, 4294967295U, 4294967295U},
61 { SECTION
, KEY
, "-4294967297", TESTFILE
, 1, 4294967295U, 4294967295U}, /* 20 */
62 { SECTION
, KEY
, "42A94967297", TESTFILE
, -1, 42 , 42},
63 { SECTION
, KEY
, "42A94967297", TESTFILE
, 1, 42 , 42},
64 { SECTION
, KEY
, "B4294967297", TESTFILE
, -1, 0 , 0},
65 { SECTION
, KEY
, "B4294967297", TESTFILE
, 1, 0 , 0},
67 int i
, num_test
= (sizeof(profileInt
)/sizeof(struct _profileInt
));
70 DeleteFileA( TESTFILE
);
72 for (i
=0; i
< num_test
; i
++) {
73 if (profileInt
[i
].value
)
74 WritePrivateProfileStringA(SECTION
, KEY
, profileInt
[i
].value
,
75 profileInt
[i
].iniFile
);
77 res
= GetPrivateProfileIntA(profileInt
[i
].section
, profileInt
[i
].key
,
78 profileInt
[i
].defaultVal
, profileInt
[i
].iniFile
);
79 ok((res
== profileInt
[i
].result
) || (res
== profileInt
[i
].result9x
),
80 "test<%02d>: ret<%010u> exp<%010u><%010u>\n",
81 i
, res
, profileInt
[i
].result
, profileInt
[i
].result9x
);
84 DeleteFileA( TESTFILE
);
87 static void test_profile_string(void)
89 static WCHAR emptyW
[] = { 0 }; /* if "const", GetPrivateProfileStringW(emptyW, ...) crashes on win2k */
90 static const WCHAR keyW
[] = { 'k','e','y',0 };
91 static const WCHAR sW
[] = { 's',0 };
92 static const WCHAR TESTFILE2W
[] = {'.','\\','t','e','s','t','w','i','n','e','2','.','i','n','i',0};
93 static const WCHAR valsectionW
[] = {'v','a','l','_','e','_','s','e','c','t','i','o','n',0 };
94 static const WCHAR valnokeyW
[] = {'v','a','l','_','n','o','_','k','e','y',0};
101 /* test that lines without an '=' will not be enumerated */
102 /* in the case below, name2 is a key while name3 is not. */
103 char content
[]="[s]\r\nname1=val1\r\nname2=\r\nname3\r\nname4=val4\r\n";
104 char content2
[]="\r\nkey=val_no_section\r\n[]\r\nkey=val_e_section\r\n"
105 "[s]\r\n=val_no_key\r\n[t]\r\n";
106 DeleteFileA( TESTFILE2
);
107 h
= CreateFileA( TESTFILE2
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
108 FILE_ATTRIBUTE_NORMAL
, NULL
);
109 ok( h
!= INVALID_HANDLE_VALUE
, " cannot create %s\n", TESTFILE2
);
110 if( h
== INVALID_HANDLE_VALUE
) return;
111 WriteFile( h
, content
, sizeof(content
), &count
, NULL
);
114 /* enumerate the keys */
115 ret
=GetPrivateProfileStringA( "s", NULL
, "", buf
, sizeof(buf
),
117 for( p
= buf
+ strlen(buf
) + 1; *p
;p
+= strlen(p
)+1)
120 ok( ret
== 18 && !strcmp( buf
, "name1,name2,name4"), "wrong keys returned(%d): %s\n", ret
,
123 /* add a new key to test that the file is quite usable */
124 WritePrivateProfileStringA( "s", "name5", "val5", TESTFILE2
);
125 ret
=GetPrivateProfileStringA( "s", NULL
, "", buf
, sizeof(buf
),
127 for( p
= buf
+ strlen(buf
) + 1; *p
;p
+= strlen(p
)+1)
129 ok( ret
== 24 && !strcmp( buf
, "name1,name2,name4,name5"), "wrong keys returned(%d): %s\n",
132 h
= CreateFileA( TESTFILE2
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
133 FILE_ATTRIBUTE_NORMAL
, NULL
);
134 ok( h
!= INVALID_HANDLE_VALUE
, " cannot create %s\n", TESTFILE2
);
135 if( h
== INVALID_HANDLE_VALUE
) return;
136 WriteFile( h
, content2
, sizeof(content2
), &count
, NULL
);
139 /* works only in unicode, ascii crashes */
140 ret
=GetPrivateProfileStringW(emptyW
, keyW
, emptyW
, bufW
,
141 sizeof(bufW
)/sizeof(bufW
[0]), TESTFILE2W
);
143 ok(ret
== 13, "expected 13, got %u\n", ret
);
145 ok(!lstrcmpW(valsectionW
,bufW
), "expected %s, got %s\n",
146 wine_dbgstr_w(valsectionW
), wine_dbgstr_w(bufW
) );
148 /* works only in unicode, ascii crashes */
149 ret
=GetPrivateProfileStringW(sW
, emptyW
, emptyW
, bufW
,
150 sizeof(bufW
)/sizeof(bufW
[0]), TESTFILE2W
);
151 ok(ret
== 10, "expected 10, got %u\n", ret
);
152 ok(!lstrcmpW(valnokeyW
,bufW
), "expected %s, got %s\n",
153 wine_dbgstr_w(valnokeyW
), wine_dbgstr_w(bufW
) );
155 DeleteFileA( TESTFILE2
);
158 static void test_profile_sections(void)
165 static const char content
[]="[section1]\r\nname1=val1\r\nname2=\r\nname3\r\nname4=val4\r\n[section2]\r\n";
166 static const char testfile4
[]=".\\testwine4.ini";
167 BOOL on_win98
= FALSE
;
169 DeleteFileA( testfile4
);
170 h
= CreateFileA( testfile4
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
171 ok( h
!= INVALID_HANDLE_VALUE
, " cannot create %s\n", testfile4
);
172 if( h
== INVALID_HANDLE_VALUE
) return;
173 WriteFile( h
, content
, sizeof(content
), &count
, NULL
);
176 /* Some parameter checking */
177 SetLastError(0xdeadbeef);
178 ret
= GetPrivateProfileSectionA( NULL
, NULL
, 0, NULL
);
179 ok( ret
== 0, "expected return size 0, got %d\n", ret
);
180 ok( GetLastError() == ERROR_INVALID_PARAMETER
||
181 GetLastError() == 0xdeadbeef /* Win98 */,
182 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
183 if (GetLastError() == 0xdeadbeef) on_win98
= TRUE
;
185 SetLastError(0xdeadbeef);
186 ret
= GetPrivateProfileSectionA( NULL
, NULL
, 0, testfile4
);
187 ok( ret
== 0, "expected return size 0, got %d\n", ret
);
188 ok( GetLastError() == ERROR_INVALID_PARAMETER
||
189 GetLastError() == 0xdeadbeef /* Win98 */,
190 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
194 SetLastError(0xdeadbeef);
195 ret
= GetPrivateProfileSectionA( "section1", NULL
, 0, testfile4
);
196 ok( ret
== 0, "expected return size 0, got %d\n", ret
);
197 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
200 SetLastError(0xdeadbeef);
201 ret
= GetPrivateProfileSectionA( NULL
, buf
, sizeof(buf
), testfile4
);
202 ok( ret
== 0, "expected return size 0, got %d\n", ret
);
203 ok( GetLastError() == ERROR_INVALID_PARAMETER
||
204 broken(GetLastError() == 0xdeadbeef), /* Win9x, WinME */
205 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
207 SetLastError(0xdeadbeef);
208 ret
= GetPrivateProfileSectionA( "section1", buf
, sizeof(buf
), NULL
);
209 ok( ret
== 0, "expected return size 0, got %d\n", ret
);
211 ok( GetLastError() == ERROR_FILE_NOT_FOUND
||
212 broken(GetLastError() == 0xdeadbeef), /* Win9x, WinME */
213 "expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
215 /* Existing empty section with no keys */
216 SetLastError(0xdeadbeef);
217 ret
=GetPrivateProfileSectionA("section2", buf
, sizeof(buf
), testfile4
);
218 ok( ret
== 0, "expected return size 0, got %d\n", ret
);
219 ok( GetLastError() == ERROR_SUCCESS
||
220 broken(GetLastError() == 0xdeadbeef), /* Win9x, WinME */
221 "expected ERROR_SUCCESS, got %d\n", GetLastError());
223 /* Existing section with keys and values*/
224 SetLastError(0xdeadbeef);
225 ret
=GetPrivateProfileSectionA("section1", buf
, sizeof(buf
), testfile4
);
226 for( p
= buf
+ strlen(buf
) + 1; *p
;p
+= strlen(p
)+1)
228 ok( ret
== 35 && !strcmp( buf
, "name1=val1,name2=,name3,name4=val4"), "wrong section returned(%d): %s\n",
230 ok( buf
[ret
-1] == 0 && buf
[ret
] == 0, "returned buffer not terminated with double-null\n" );
231 ok( GetLastError() == ERROR_SUCCESS
||
232 broken(GetLastError() == 0xdeadbeef), /* Win9x, WinME */
233 "expected ERROR_SUCCESS, got %d\n", GetLastError());
236 ret
=GetPrivateProfileSectionA("section1", buf
, 24, testfile4
);
237 for( p
= buf
+ strlen(buf
) + 1; *p
;p
+= strlen(p
)+1)
239 ok( ret
== 22 && !strcmp( buf
, "name1=val1,name2=,name"), "wrong section returned(%d): %s\n",
241 ok( buf
[ret
] == 0 && buf
[ret
+1] == 0, "returned buffer not terminated with double-null\n" );
243 DeleteFileA( testfile4
);
246 static void test_profile_sections_names(void)
253 static const char content
[]="[section1]\r\n[section2]\r\n[section3]\r\n";
254 static const char testfile3
[]=".\\testwine3.ini";
255 static const WCHAR testfile3W
[]={ '.','\\','t','e','s','t','w','i','n','e','3','.','i','n','i',0 };
256 static const WCHAR not_here
[] = {'.','\\','n','o','t','_','h','e','r','e','.','i','n','i',0};
257 DeleteFileA( testfile3
);
258 h
= CreateFileA( testfile3
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
259 FILE_ATTRIBUTE_NORMAL
, NULL
);
260 ok( h
!= INVALID_HANDLE_VALUE
, " cannot create %s\n", testfile3
);
261 if( h
== INVALID_HANDLE_VALUE
) return;
262 WriteFile( h
, content
, sizeof(content
), &count
, NULL
);
265 /* Test with sufficiently large buffer */
266 memset(buf
, 0xc, sizeof(buf
));
267 ret
= GetPrivateProfileSectionNamesA( buf
, 29, testfile3
);
269 broken(ret
== 28), /* Win9x, WinME */
270 "expected return size 27, got %d\n", ret
);
271 ok( (buf
[ret
-1] == 0 && buf
[ret
] == 0) ||
272 broken(buf
[ret
-1] == 0 && buf
[ret
-2] == 0), /* Win9x, WinME */
273 "returned buffer not terminated with double-null\n" );
275 /* Test with exactly fitting buffer */
276 memset(buf
, 0xc, sizeof(buf
));
277 ret
= GetPrivateProfileSectionNamesA( buf
, 28, testfile3
);
279 broken(ret
== 28), /* Win9x, WinME */
280 "expected return size 26, got %d\n", ret
);
282 ok( (buf
[ret
+1] == 0 && buf
[ret
] == 0) || /* W2K3 and higher */
283 broken(buf
[ret
+1] == 0xc && buf
[ret
] == 0) || /* NT4, W2K, WinXP */
284 broken(buf
[ret
-1] == 0 && buf
[ret
-2] == 0), /* Win9x, WinME */
285 "returned buffer not terminated with double-null\n" );
287 /* Test with a buffer too small */
288 memset(buf
, 0xc, sizeof(buf
));
289 ret
= GetPrivateProfileSectionNamesA( buf
, 27, testfile3
);
290 ok( ret
== 25, "expected return size 25, got %d\n", ret
);
291 /* Win9x and WinME only fills the buffer with complete section names (double-null terminated) */
292 count
= strlen("section1") + sizeof(CHAR
) + strlen("section2");
294 ok( (buf
[ret
+1] == 0 && buf
[ret
] == 0) ||
295 broken(buf
[count
] == 0 && buf
[count
+1] == 0), /* Win9x, WinME */
296 "returned buffer not terminated with double-null\n" );
298 /* Tests on nonexistent file */
299 memset(buf
, 0xc, sizeof(buf
));
300 ret
= GetPrivateProfileSectionNamesA( buf
, 10, ".\\not_here.ini" );
302 broken(ret
== 1), /* Win9x, WinME */
303 "expected return size 0, got %d\n", ret
);
304 ok( buf
[0] == 0, "returned buffer not terminated with null\n" );
305 ok( buf
[1] != 0, "returned buffer terminated with double-null\n" );
307 /* Test with sufficiently large buffer */
308 SetLastError(0xdeadbeef);
309 memset(bufW
, 0xcc, sizeof(bufW
));
310 ret
= GetPrivateProfileSectionNamesW( bufW
, 29, testfile3W
);
311 if (ret
== 0 && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
))
313 win_skip("GetPrivateProfileSectionNamesW is not implemented\n");
314 DeleteFileA( testfile3
);
317 ok( ret
== 27, "expected return size 27, got %d\n", ret
);
318 ok( bufW
[ret
-1] == 0 && bufW
[ret
] == 0, "returned buffer not terminated with double-null\n" );
320 /* Test with exactly fitting buffer */
321 memset(bufW
, 0xcc, sizeof(bufW
));
322 ret
= GetPrivateProfileSectionNamesW( bufW
, 28, testfile3W
);
323 ok( ret
== 26, "expected return size 26, got %d\n", ret
);
324 ok( (bufW
[ret
+1] == 0 && bufW
[ret
] == 0) || /* W2K3 and higher */
325 broken(bufW
[ret
+1] == 0xcccc && bufW
[ret
] == 0), /* NT4, W2K, WinXP */
326 "returned buffer not terminated with double-null\n" );
328 /* Test with a buffer too small */
329 memset(bufW
, 0xcc, sizeof(bufW
));
330 ret
= GetPrivateProfileSectionNamesW( bufW
, 27, testfile3W
);
331 ok( ret
== 25, "expected return size 25, got %d\n", ret
);
332 ok( bufW
[ret
+1] == 0 && bufW
[ret
] == 0, "returned buffer not terminated with double-null\n" );
334 DeleteFileA( testfile3
);
336 /* Tests on nonexistent file */
337 memset(bufW
, 0xcc, sizeof(bufW
));
338 ret
= GetPrivateProfileSectionNamesW( bufW
, 10, not_here
);
339 ok( ret
== 0, "expected return size 0, got %d\n", ret
);
340 ok( bufW
[0] == 0, "returned buffer not terminated with null\n" );
341 ok( bufW
[1] != 0, "returned buffer terminated with double-null\n" );
344 /* If the ini-file has already been opened with CreateFile, WritePrivateProfileString failed in wine with an error ERROR_SHARING_VIOLATION, some testing here */
345 static void test_profile_existing(void)
347 static const char *testfile1
= ".\\winesharing1.ini";
348 static const char *testfile2
= ".\\winesharing2.ini";
350 static const struct {
351 DWORD dwDesiredAccess
;
357 {GENERIC_READ
, FILE_SHARE_READ
, ERROR_SHARING_VIOLATION
, FALSE
},
358 {GENERIC_READ
, FILE_SHARE_WRITE
, ERROR_SHARING_VIOLATION
, TRUE
},
359 {GENERIC_WRITE
, FILE_SHARE_READ
, ERROR_SHARING_VIOLATION
, FALSE
},
360 {GENERIC_WRITE
, FILE_SHARE_WRITE
, ERROR_SHARING_VIOLATION
, TRUE
},
361 {GENERIC_READ
|GENERIC_WRITE
, FILE_SHARE_READ
, ERROR_SHARING_VIOLATION
, FALSE
},
362 {GENERIC_READ
|GENERIC_WRITE
, FILE_SHARE_WRITE
, ERROR_SHARING_VIOLATION
, TRUE
},
363 {GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, 0, FALSE
, ERROR_SHARING_VIOLATION
/* nt4 */},
364 {GENERIC_WRITE
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, 0, FALSE
, ERROR_SHARING_VIOLATION
/* nt4 */},
365 /*Thief demo (bug 5024) opens .ini file like this*/
366 {GENERIC_READ
|GENERIC_WRITE
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, 0, FALSE
, ERROR_SHARING_VIOLATION
/* nt4 */}
373 char buffer
[MAX_PATH
];
375 for (i
=0; i
< sizeof(pe
)/sizeof(pe
[0]); i
++)
377 h
= CreateFileA(testfile1
, pe
[i
].dwDesiredAccess
, pe
[i
].dwShareMode
, NULL
,
378 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
379 ok(INVALID_HANDLE_VALUE
!= h
, "%d: CreateFile failed\n",i
);
380 SetLastError(0xdeadbeef);
382 ret
= WritePrivateProfileStringA(SECTION
, KEY
, "12345", testfile1
);
383 if (!pe
[i
].write_error
)
386 ok( broken(GetLastError() == pe
[i
].broken_error
),
387 "%d: WritePrivateProfileString failed with error %u\n", i
, GetLastError() );
389 size
= GetPrivateProfileStringA(SECTION
, KEY
, 0, buffer
, MAX_PATH
, testfile1
);
391 ok( size
== 5, "%d: test failed, number of characters copied: %d instead of 5\n", i
, size
);
393 ok( !size
, "%d: test failed, number of characters copied: %d instead of 0\n", i
, size
);
397 DWORD err
= GetLastError();
398 ok( !ret
, "%d: WritePrivateProfileString succeeded\n", i
);
400 ok( err
== pe
[i
].write_error
, "%d: WritePrivateProfileString failed with error %u/%u\n",
401 i
, err
, pe
[i
].write_error
);
403 size
= GetPrivateProfileStringA(SECTION
, KEY
, 0, buffer
, MAX_PATH
, testfile1
);
404 ok( !size
, "%d: test failed, number of characters copied: %d instead of 0\n", i
, size
);
407 ok( DeleteFileA(testfile1
), "delete failed\n" );
410 h
= CreateFileA(testfile2
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
411 sprintf( buffer
, "[%s]\r\n%s=123\r\n", SECTION
, KEY
);
412 ok( WriteFile( h
, buffer
, strlen(buffer
), &size
, NULL
), "failed to write\n" );
415 for (i
=0; i
< sizeof(pe
)/sizeof(pe
[0]); i
++)
417 h
= CreateFileA(testfile2
, pe
[i
].dwDesiredAccess
, pe
[i
].dwShareMode
, NULL
,
418 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
419 ok(INVALID_HANDLE_VALUE
!= h
, "%d: CreateFile failed\n",i
);
420 SetLastError(0xdeadbeef);
421 ret
= GetPrivateProfileStringA(SECTION
, KEY
, NULL
, buffer
, MAX_PATH
, testfile2
);
422 /* Win9x and WinME returns 0 for all cases except the first one */
423 if (!pe
[i
].read_error
)
425 broken(!ret
&& GetLastError() == 0xdeadbeef), /* Win9x, WinME */
426 "%d: GetPrivateProfileString failed with error %u\n", i
, GetLastError() );
428 ok( !ret
, "%d: GetPrivateProfileString succeeded\n", i
);
431 ok( DeleteFileA(testfile2
), "delete failed\n" );
434 static void test_profile_delete_on_close(void)
438 static const CHAR testfile
[] = ".\\testwine5.ini";
439 static const char contents
[] = "[" SECTION
"]\n" KEY
"=123\n";
441 h
= CreateFileA(testfile
, GENERIC_WRITE
, FILE_SHARE_READ
, NULL
,
442 CREATE_ALWAYS
, FILE_FLAG_DELETE_ON_CLOSE
, NULL
);
443 res
= WriteFile( h
, contents
, sizeof contents
- 1, &size
, NULL
);
444 ok( res
, "Cannot write test file: %x\n", GetLastError() );
445 ok( size
== sizeof contents
- 1, "Test file: partial write\n");
447 SetLastError(0xdeadbeef);
448 res
= GetPrivateProfileIntA(SECTION
, KEY
, 0, testfile
);
450 broken(res
== 0 && GetLastError() == ERROR_SHARING_VIOLATION
), /* Win9x, WinME */
451 "Got %d instead of 123\n", res
);
453 /* This also deletes the file */
457 static void test_profile_refresh(void)
459 static const CHAR testfile
[] = ".\\winetest4.ini";
462 static const char contents1
[] = "[" SECTION
"]\n" KEY
"=123\n";
463 static const char contents2
[] = "[" SECTION
"]\n" KEY
"=124\n";
465 h
= CreateFileA(testfile
, GENERIC_WRITE
, FILE_SHARE_READ
, NULL
,
466 CREATE_ALWAYS
, FILE_FLAG_DELETE_ON_CLOSE
, NULL
);
467 res
= WriteFile( h
, contents1
, sizeof contents1
- 1, &size
, NULL
);
468 ok( res
, "Cannot write test file: %x\n", GetLastError() );
469 ok( size
== sizeof contents1
- 1, "Test file: partial write\n");
471 SetLastError(0xdeadbeef);
472 res
= GetPrivateProfileIntA(SECTION
, KEY
, 0, testfile
);
474 broken(res
== 0 && GetLastError() == ERROR_SHARING_VIOLATION
), /* Win9x, WinME */
475 "Got %d instead of 123\n", res
);
479 /* Test proper invalidation of wine's profile file cache */
481 h
= CreateFileA(testfile
, GENERIC_WRITE
, FILE_SHARE_READ
, NULL
,
482 CREATE_ALWAYS
, FILE_FLAG_DELETE_ON_CLOSE
, NULL
);
483 res
= WriteFile( h
, contents2
, sizeof contents2
- 1, &size
, NULL
);
484 ok( res
, "Cannot write test file: %x\n", GetLastError() );
485 ok( size
== sizeof contents2
- 1, "Test file: partial write\n");
487 SetLastError(0xdeadbeef);
488 res
= GetPrivateProfileIntA(SECTION
, KEY
, 0, testfile
);
490 broken(res
== 0 && GetLastError() == 0xdeadbeef), /* Win9x, WinME */
491 "Got %d instead of 124\n", res
);
493 /* This also deletes the file */
496 /* Cache must be invalidated if file no longer exists and default must be returned */
497 SetLastError(0xdeadbeef);
498 res
= GetPrivateProfileIntA(SECTION
, KEY
, 421, testfile
);
500 broken(res
== 0 && GetLastError() == 0xdeadbeef), /* Win9x, WinME */
501 "Got %d instead of 421\n", res
);
504 static void create_test_file(LPCSTR name
, LPCSTR data
, DWORD size
)
509 hfile
= CreateFileA(name
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
510 ok(hfile
!= INVALID_HANDLE_VALUE
, "cannot create %s\n", name
);
511 WriteFile(hfile
, data
, size
, &count
, NULL
);
515 static BOOL
emptystr_ok(CHAR emptystr
[MAX_PATH
])
519 for(i
= 0;i
< MAX_PATH
;++i
)
522 trace("emptystr[%d] = %d\n",i
,emptystr
[i
]);
529 static void test_GetPrivateProfileString(const char *content
, const char *descript
)
533 CHAR def_val
[MAX_PATH
];
535 CHAR windir
[MAX_PATH
];
536 /* NT series crashes on r/o empty strings, so pass an r/w
537 empty string and check for modification */
538 CHAR emptystr
[MAX_PATH
] = "";
541 static const char filename
[] = ".\\winetest.ini";
543 trace("test_GetPrivateProfileStringA: %s\n", descript
);
545 if(!lstrcmpA(descript
, "CR only"))
547 SetLastError(0xdeadbeef);
548 ret
= GetPrivateProfileStringW(NULL
, NULL
, NULL
,
550 if (!ret
&& GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
552 win_skip("Win9x and WinME don't handle 'CR only' correctly\n");
557 create_test_file(filename
, content
, lstrlenA(content
));
559 /* Run this test series with caching. Wine won't cache profile
560 files younger than 2.1 seconds. */
563 /* lpAppName is NULL */
564 memset(buf
, 0xc, sizeof(buf
));
565 lstrcpyA(buf
, "kumquat");
566 ret
= GetPrivateProfileStringA(NULL
, "name1", "default",
567 buf
, MAX_PATH
, filename
);
569 broken(ret
== 19), /* Win9x and WinME */
570 "Expected 18, got %d\n", ret
);
571 len
= lstrlenA("section1") + sizeof(CHAR
) + lstrlenA("section2") + 2 * sizeof(CHAR
);
572 ok(!memcmp(buf
, "section1\0section2\0\0", len
),
573 "Expected \"section1\\0section2\\0\\0\", got \"%s\"\n", buf
);
575 /* lpAppName is empty */
576 memset(buf
, 0xc, sizeof(buf
));
577 lstrcpyA(buf
, "kumquat");
578 ret
= GetPrivateProfileStringA(emptystr
, "name1", "default",
579 buf
, MAX_PATH
, filename
);
580 ok(ret
== 7, "Expected 7, got %d\n", ret
);
581 ok(!lstrcmpA(buf
, "default"), "Expected \"default\", got \"%s\"\n", buf
);
582 ok(emptystr_ok(emptystr
), "AppName modified\n");
584 /* lpAppName is missing */
585 memset(buf
, 0xc,sizeof(buf
));
586 lstrcpyA(buf
, "kumquat");
587 ret
= GetPrivateProfileStringA("notasection", "name1", "default",
588 buf
, MAX_PATH
, filename
);
589 ok(ret
== 7, "Expected 7, got %d\n", ret
);
590 ok(!lstrcmpA(buf
, "default"), "Expected \"default\", got \"%s\"\n", buf
);
592 /* lpAppName is empty, lpDefault is NULL */
593 memset(buf
, 0xc,sizeof(buf
));
594 lstrcpyA(buf
, "kumquat");
595 ret
= GetPrivateProfileStringA(emptystr
, "name1", NULL
,
596 buf
, MAX_PATH
, filename
);
597 ok(ret
== 0, "Expected 0, got %d\n", ret
);
598 ok(!lstrcmpA(buf
, "") ||
599 broken(!lstrcmpA(buf
, "kumquat")), /* Win9x, WinME */
600 "Expected \"\", got \"%s\"\n", buf
);
601 ok(emptystr_ok(emptystr
), "AppName modified\n");
603 /* lpAppName is empty, lpDefault is empty */
604 memset(buf
, 0xc,sizeof(buf
));
605 lstrcpyA(buf
, "kumquat");
606 ret
= GetPrivateProfileStringA(emptystr
, "name1", "",
607 buf
, MAX_PATH
, filename
);
608 ok(ret
== 0, "Expected 0, got %d\n", ret
);
609 ok(!lstrcmpA(buf
, ""), "Expected \"\", got \"%s\"\n", buf
);
610 ok(emptystr_ok(emptystr
), "AppName modified\n");
612 /* lpAppName is empty, lpDefault has trailing blank characters */
613 memset(buf
, 0xc,sizeof(buf
));
614 lstrcpyA(buf
, "kumquat");
615 /* lpDefault must be writable (trailing blanks are removed inplace in win9x) */
616 lstrcpyA(def_val
, "default ");
617 ret
= GetPrivateProfileStringA(emptystr
, "name1", def_val
,
618 buf
, MAX_PATH
, filename
);
619 ok(ret
== 7, "Expected 7, got %d\n", ret
);
620 ok(!lstrcmpA(buf
, "default"), "Expected \"default\", got \"%s\"\n", buf
);
621 ok(emptystr_ok(emptystr
), "AppName modified\n");
623 /* lpAppName is empty, many blank characters in lpDefault */
624 memset(buf
, 0xc,sizeof(buf
));
625 lstrcpyA(buf
, "kumquat");
626 /* lpDefault must be writable (trailing blanks are removed inplace in win9x) */
627 lstrcpyA(def_val
, "one two ");
628 ret
= GetPrivateProfileStringA(emptystr
, "name1", def_val
,
629 buf
, MAX_PATH
, filename
);
630 ok(ret
== 7, "Expected 7, got %d\n", ret
);
631 ok(!lstrcmpA(buf
, "one two"), "Expected \"one two\", got \"%s\"\n", buf
);
632 ok(emptystr_ok(emptystr
), "AppName modified\n");
634 /* lpAppName is empty, blank character but not trailing in lpDefault */
635 memset(buf
, 0xc,sizeof(buf
));
636 lstrcpyA(buf
, "kumquat");
637 ret
= GetPrivateProfileStringA(emptystr
, "name1", "one two",
638 buf
, MAX_PATH
, filename
);
639 ok(ret
== 7, "Expected 7, got %d\n", ret
);
640 ok(!lstrcmpA(buf
, "one two"), "Expected \"one two\", got \"%s\"\n", buf
);
641 ok(emptystr_ok(emptystr
), "AppName modified\n");
643 /* lpKeyName is NULL */
644 memset(buf
, 0xc,sizeof(buf
));
645 lstrcpyA(buf
, "kumquat");
646 ret
= GetPrivateProfileStringA("section1", NULL
, "default",
647 buf
, MAX_PATH
, filename
);
648 ok(ret
== 18, "Expected 18, got %d\n", ret
);
649 ok(!memcmp(buf
, "name1\0name2\0name4\0", ret
+ 1),
650 "Expected \"name1\\0name2\\0name4\\0\", got \"%s\"\n", buf
);
652 /* lpKeyName is empty */
653 memset(buf
, 0xc,sizeof(buf
));
654 lstrcpyA(buf
, "kumquat");
655 ret
= GetPrivateProfileStringA("section1", emptystr
, "default",
656 buf
, MAX_PATH
, filename
);
657 ok(ret
== 7, "Expected 7, got %d\n", ret
);
658 ok(!lstrcmpA(buf
, "default"), "Expected \"default\", got \"%s\"\n", buf
);
659 ok(emptystr_ok(emptystr
), "KeyName modified\n");
661 /* lpKeyName is missing */
662 memset(buf
, 0xc,sizeof(buf
));
663 lstrcpyA(buf
, "kumquat");
664 ret
= GetPrivateProfileStringA("section1", "notakey", "default",
665 buf
, MAX_PATH
, filename
);
666 ok(ret
== 7, "Expected 7, got %d\n", ret
);
667 ok(!lstrcmpA(buf
, "default"), "Expected \"default\", got \"%s\"\n", buf
);
669 /* lpKeyName is empty, lpDefault is NULL */
670 memset(buf
, 0xc,sizeof(buf
));
671 lstrcpyA(buf
, "kumquat");
672 ret
= GetPrivateProfileStringA("section1", emptystr
, NULL
,
673 buf
, MAX_PATH
, filename
);
674 ok(ret
== 0, "Expected 0, got %d\n", ret
);
675 ok(!lstrcmpA(buf
, "") ||
676 broken(!lstrcmpA(buf
, "kumquat")), /* Win9x, WinME */
677 "Expected \"\", got \"%s\"\n", buf
);
678 ok(emptystr_ok(emptystr
), "KeyName modified\n");
680 /* lpKeyName is empty, lpDefault is empty */
681 memset(buf
, 0xc,sizeof(buf
));
682 lstrcpyA(buf
, "kumquat");
683 ret
= GetPrivateProfileStringA("section1", emptystr
, "",
684 buf
, MAX_PATH
, filename
);
685 ok(ret
== 0, "Expected 0, got %d\n", ret
);
686 ok(!lstrcmpA(buf
, ""), "Expected \"\", got \"%s\"\n", buf
);
687 ok(emptystr_ok(emptystr
), "KeyName modified\n");
689 /* lpKeyName is empty, lpDefault has trailing blank characters */
690 memset(buf
, 0xc,sizeof(buf
));
691 lstrcpyA(buf
, "kumquat");
692 /* lpDefault must be writable (trailing blanks are removed inplace in win9x) */
693 lstrcpyA(def_val
, "default ");
694 ret
= GetPrivateProfileStringA("section1", emptystr
, def_val
,
695 buf
, MAX_PATH
, filename
);
696 ok(ret
== 7, "Expected 7, got %d\n", ret
);
697 ok(!lstrcmpA(buf
, "default"), "Expected \"default\", got \"%s\"\n", buf
);
698 ok(emptystr_ok(emptystr
), "KeyName modified\n");
702 /* lpReturnedString is NULL */
703 ret
= GetPrivateProfileStringA("section1", "name1", "default",
704 NULL
, MAX_PATH
, filename
);
707 /* lpFileName is NULL */
708 memset(buf
, 0xc,sizeof(buf
));
709 lstrcpyA(buf
, "kumquat");
710 ret
= GetPrivateProfileStringA("section1", "name1", "default",
711 buf
, MAX_PATH
, NULL
);
713 broken(ret
== 0), /* Win9x, WinME */
714 "Expected 7, got %d\n", ret
);
715 ok(!lstrcmpA(buf
, "default") ||
716 broken(!lstrcmpA(buf
, "kumquat")), /* Win9x, WinME */
717 "Expected \"default\", got \"%s\"\n", buf
);
719 /* lpFileName is empty */
720 memset(buf
, 0xc,sizeof(buf
));
721 lstrcpyA(buf
, "kumquat");
722 ret
= GetPrivateProfileStringA("section1", "name1", "default",
724 ok(ret
== 7, "Expected 7, got %d\n", ret
);
725 ok(!lstrcmpA(buf
, "default"), "Expected \"default\", got \"%s\"\n", buf
);
727 /* lpFileName is nonexistent */
728 memset(buf
, 0xc,sizeof(buf
));
729 lstrcpyA(buf
, "kumquat");
730 ret
= GetPrivateProfileStringA("section1", "name1", "default",
731 buf
, MAX_PATH
, "nonexistent");
732 ok(ret
== 7, "Expected 7, got %d\n", ret
);
733 ok(!lstrcmpA(buf
, "default"), "Expected \"default\", got \"%s\"\n", buf
);
736 memset(buf
, 0xc,sizeof(buf
));
737 lstrcpyA(buf
, "kumquat");
738 ret
= GetPrivateProfileStringA("section1", "name1", "default",
740 ok(ret
== 0, "Expected 0, got %d\n", ret
);
741 ok(!lstrcmpA(buf
, "kumquat"), "Expected buf to be unchanged, got \"%s\"\n", buf
);
743 /* nSize is exact size of output */
744 memset(buf
, 0xc,sizeof(buf
));
745 lstrcpyA(buf
, "kumquat");
746 ret
= GetPrivateProfileStringA("section1", "name1", "default",
748 ok(ret
== 3, "Expected 3, got %d\n", ret
);
749 ok(!lstrcmpA(buf
, "val"), "Expected \"val\", got \"%s\"\n", buf
);
751 /* nSize has room for NULL terminator */
752 memset(buf
, 0xc,sizeof(buf
));
753 lstrcpyA(buf
, "kumquat");
754 ret
= GetPrivateProfileStringA("section1", "name1", "default",
756 ok(ret
== 4, "Expected 4, got %d\n", ret
);
757 ok(!lstrcmpA(buf
, "val1"), "Expected \"val1\", got \"%s\"\n", buf
);
759 /* output is 1 character */
760 memset(buf
, 0xc,sizeof(buf
));
761 lstrcpyA(buf
, "kumquat");
762 ret
= GetPrivateProfileStringA("section1", "name4", "default",
763 buf
, MAX_PATH
, filename
);
764 ok(ret
== 1, "Expected 1, got %d\n", ret
);
765 ok(!lstrcmpA(buf
, "a"), "Expected \"a\", got \"%s\"\n", buf
);
767 /* output is 1 character, no room for NULL terminator */
768 memset(buf
, 0xc,sizeof(buf
));
769 lstrcpyA(buf
, "kumquat");
770 ret
= GetPrivateProfileStringA("section1", "name4", "default",
772 ok(ret
== 0, "Expected 0, got %d\n", ret
);
773 ok(!lstrcmpA(buf
, ""), "Expected \"\", got \"%s\"\n", buf
);
775 /* lpAppName is NULL, not enough room for final section name */
776 memset(buf
, 0xc,sizeof(buf
));
777 lstrcpyA(buf
, "kumquat");
778 ret
= GetPrivateProfileStringA(NULL
, "name1", "default",
780 ok(ret
== 14, "Expected 14, got %d\n", ret
);
781 len
= lstrlenA("section1") + 2 * sizeof(CHAR
);
783 ok(!memcmp(buf
, "section1\0secti\0\0", ret
+ 2) ||
784 broken(!memcmp(buf
, "section1\0\0", len
)), /* Win9x, WinME */
785 "Expected \"section1\\0secti\\0\\0\", got \"%s\"\n", buf
);
787 /* lpKeyName is NULL, not enough room for final key name */
788 memset(buf
, 0xc,sizeof(buf
));
789 lstrcpyA(buf
, "kumquat");
790 ret
= GetPrivateProfileStringA("section1", NULL
, "default",
792 ok(ret
== 14, "Expected 14, got %d\n", ret
);
794 ok(!memcmp(buf
, "name1\0name2\0na\0\0", ret
+ 2) ||
795 broken(!memcmp(buf
, "name1\0name2\0n\0\0", ret
+ 1)), /* Win9x, WinME */
796 "Expected \"name1\\0name2\\0na\\0\\0\", got \"%s\"\n", buf
);
798 /* key value has quotation marks which are stripped */
799 memset(buf
, 0xc,sizeof(buf
));
800 lstrcpyA(buf
, "kumquat");
801 ret
= GetPrivateProfileStringA("section1", "name2", "default",
802 buf
, MAX_PATH
, filename
);
803 ok(ret
== 4, "Expected 4, got %d\n", ret
);
804 ok(!lstrcmpA(buf
, "val2"), "Expected \"val2\", got \"%s\"\n", buf
);
806 /* case does not match */
807 memset(buf
, 0xc,sizeof(buf
));
808 lstrcpyA(buf
, "kumquat");
809 ret
= GetPrivateProfileStringA("section1", "NaMe1", "default",
810 buf
, MAX_PATH
, filename
);
811 ok(ret
== 4, "Expected 4, got %d\n", ret
);
812 ok(!lstrcmpA(buf
, "val1"), "Expected \"val1\", got \"%s\"\n", buf
);
814 /* only filename is used */
815 memset(buf
, 0xc,sizeof(buf
));
816 lstrcpyA(buf
, "kumquat");
817 ret
= GetPrivateProfileStringA("section1", "NaMe1", "default",
818 buf
, MAX_PATH
, "winetest.ini");
819 ok(ret
== 7, "Expected 7, got %d\n", ret
);
820 ok(!lstrcmpA(buf
, "default"), "Expected \"default\", got \"%s\"\n", buf
);
822 GetWindowsDirectoryA(windir
, MAX_PATH
);
823 SetLastError(0xdeadbeef);
824 ret
= GetTempFileNameA(windir
, "pre", 0, path
);
825 if (!ret
&& GetLastError() == ERROR_ACCESS_DENIED
)
827 skip("Not allowed to create a file in the Windows directory\n");
828 DeleteFileA(filename
);
831 tempfile
= strrchr(path
, '\\') + 1;
832 create_test_file(path
, content
, lstrlenA(content
));
834 /* only filename is used, file exists in windows directory */
835 memset(buf
, 0xc,sizeof(buf
));
836 lstrcpyA(buf
, "kumquat");
837 ret
= GetPrivateProfileStringA("section1", "NaMe1", "default",
838 buf
, MAX_PATH
, tempfile
);
839 ok(ret
== 4, "Expected 4, got %d\n", ret
);
840 ok(!lstrcmpA(buf
, "val1"), "Expected \"val1\", got \"%s\"\n", buf
);
842 /* successful case */
843 memset(buf
, 0xc,sizeof(buf
));
844 lstrcpyA(buf
, "kumquat");
845 ret
= GetPrivateProfileStringA("section1", "name1", "default",
846 buf
, MAX_PATH
, filename
);
847 ok(ret
== 4, "Expected 4, got %d\n", ret
);
848 ok(!lstrcmpA(buf
, "val1"), "Expected \"val1\", got \"%s\"\n", buf
);
850 /* Existing section with no keys in an existing file */
851 memset(buf
, 0xc,sizeof(buf
));
852 SetLastError(0xdeadbeef);
853 ret
=GetPrivateProfileStringA("section2", "DoesntExist", "",
854 buf
, MAX_PATH
, filename
);
855 ok( ret
== 0, "expected return size 0, got %d\n", ret
);
856 ok(!lstrcmpA(buf
, ""), "Expected \"\", got \"%s\"\n", buf
);
858 ok( GetLastError() == 0xdeadbeef ||
859 GetLastError() == ERROR_FILE_NOT_FOUND
/* Win 7 */,
860 "expected 0xdeadbeef or ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
864 DeleteFileA(filename
);
867 static BOOL
check_binary_file_data(LPCSTR path
, const VOID
*data
, DWORD size
)
873 file
= CreateFileA(path
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, 0);
874 if (file
== INVALID_HANDLE_VALUE
)
877 if(size
!= GetFileSize(file
, NULL
) )
883 ret
= ReadFile(file
, buf
, size
, &size
, NULL
);
888 return !memcmp(buf
, data
, size
);
891 static BOOL
check_file_data(LPCSTR path
, LPCSTR data
)
893 return check_binary_file_data(path
, data
, lstrlenA(data
));
896 static void test_WritePrivateProfileString(void)
903 SetLastError(0xdeadbeef);
904 ret
= WritePrivateProfileStringW(NULL
, NULL
, NULL
, NULL
);
905 if (!ret
&& GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
907 /* Win9x/WinME needs (variable) timeouts between tests and even long timeouts don't
908 * guarantee a correct result.
909 * Win9x/WinMe also produces different ini files where there is always a newline before
910 * a section start (except for the first one).
912 win_skip("WritePrivateProfileString on Win9x/WinME is hard to test reliably\n");
916 GetTempPathA(MAX_PATH
, temp
);
917 GetTempFileNameA(temp
, "wine", 0, path
);
920 /* path is not created yet */
923 SetLastError(0xdeadbeef);
924 ret
= WritePrivateProfileStringA(NULL
, "key", "string", path
);
925 ok(ret
== FALSE
, "Expected FALSE, got %d\n", ret
);
926 ok(GetLastError() == ERROR_FILE_NOT_FOUND
||
927 broken(GetLastError() == ERROR_INVALID_PARAMETER
) || /* NT4 */
928 broken(GetLastError() == 0xdeadbeef), /* Win9x and WinME */
929 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
930 ok(GetFileAttributesA(path
) == INVALID_FILE_ATTRIBUTES
,
931 "Expected path to not exist\n");
933 GetTempFileNameA(temp
, "wine", 0, path
);
935 /* NULL lpAppName, path exists */
937 SetLastError(0xdeadbeef);
938 ret
= WritePrivateProfileStringA(NULL
, "key", "string", path
);
939 ok(ret
== FALSE
, "Expected FALSE, got %d\n", ret
);
940 ok(GetLastError() == ERROR_FILE_NOT_FOUND
||
941 broken(GetLastError() == ERROR_INVALID_PARAMETER
) || /* NT4 */
942 broken(GetLastError() == 0xdeadbeef), /* Win9x and WinME */
943 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
944 ok(check_file_data(path
, data
), "File doesn't match\n");
949 /* empty lpAppName, crashes on NT4 and higher */
952 ret
= WritePrivateProfileStringA("", "key", "string", path
);
953 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
954 ok(check_file_data(path
, data
), "File doesn't match\n");
960 ret
= WritePrivateProfileStringA("App", NULL
, "string", path
);
961 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
964 ok(check_file_data(path
, data
), "File doesn't match\n");
970 /* empty lpKeyName, crashes on NT4 and higher */
973 ret
= WritePrivateProfileStringA("App", "", "string", path
);
974 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
977 ok(check_file_data(path
, data
), "File doesn't match\n");
984 ret
= WritePrivateProfileStringA("App", "key", NULL
, path
);
985 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
988 ok(check_file_data(path
, data
) ||
989 (broken(GetFileAttributesA(path
) == INVALID_FILE_ATTRIBUTES
)), /* Win9x and WinME */
990 "File doesn't match\n");
997 ret
= WritePrivateProfileStringA("App", "key", "", path
);
999 broken(!ret
), /* Win9x and WinME */
1000 "Expected TRUE, got %d\n", ret
);
1001 ok(check_file_data(path
, data
) ||
1002 (broken(GetFileAttributesA(path
) == INVALID_FILE_ATTRIBUTES
)), /* Win9x and WinME */
1003 "File doesn't match\n");
1006 /* empty lpFileName */
1007 SetLastError(0xdeadbeef);
1008 ret
= WritePrivateProfileStringA("App", "key", "string", "");
1009 ok(ret
== FALSE
, "Expected FALSE, got %d\n", ret
);
1010 ok(GetLastError() == ERROR_ACCESS_DENIED
||
1011 broken(GetLastError() == ERROR_PATH_NOT_FOUND
), /* Win9x and WinME */
1012 "Expected ERROR_ACCESS_DENIED, got %d\n", GetLastError());
1014 /* Relative paths are relative to X:\\%WINDIR% */
1015 GetWindowsDirectoryA(temp
, MAX_PATH
);
1016 GetTempFileNameA(temp
, "win", 1, path
);
1017 if (GetFileAttributesA(path
) == INVALID_FILE_ATTRIBUTES
)
1018 skip("Not allowed to create a file in the Windows directory\n");
1025 ret
= WritePrivateProfileStringA("App", "key", "string", "win1.tmp");
1026 ok(ret
== TRUE
, "Expected TRUE, got %d, le=%u\n", ret
, GetLastError());
1027 ok(check_file_data(path
, data
), "File doesn't match\n");
1031 GetTempPathA(MAX_PATH
, temp
);
1032 GetTempFileNameA(temp
, "wine", 0, path
);
1034 /* build up an INI file */
1035 WritePrivateProfileStringA("App1", "key1", "string1", path
);
1036 WritePrivateProfileStringA("App1", "key2", "string2", path
);
1037 WritePrivateProfileStringA("App1", "key3", "string3", path
);
1038 WritePrivateProfileStringA("App2", "key4", "string4", path
);
1040 /* make an addition and verify the INI */
1049 ret
= WritePrivateProfileStringA("App3", "key5", "string5", path
);
1050 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1051 ok(check_file_data(path
, data
), "File doesn't match\n");
1053 /* lpString is NULL, key2 key is deleted */
1061 ret
= WritePrivateProfileStringA("App1", "key2", NULL
, path
);
1062 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1063 ok(check_file_data(path
, data
), "File doesn't match\n");
1065 /* try to delete key2 again */
1073 ret
= WritePrivateProfileStringA("App1", "key2", NULL
, path
);
1074 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1075 ok(check_file_data(path
, data
), "File doesn't match\n");
1077 /* lpKeyName is NULL, App1 section is deleted */
1082 ret
= WritePrivateProfileStringA("App1", NULL
, "string1", path
);
1083 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1084 ok(check_file_data(path
, data
), "File doesn't match\n");
1086 /* lpString is not needed to delete a section */
1089 ret
= WritePrivateProfileStringA("App2", NULL
, NULL
, path
);
1090 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1091 ok(check_file_data(path
, data
), "File doesn't match\n");
1093 /* leave just the section */
1094 data
= "[App3]\r\n";
1095 ret
= WritePrivateProfileStringA("App3", "key5", NULL
, path
);
1096 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1097 ok(check_file_data(path
, data
), "File doesn't match\n");
1100 /* NULLs in file before first section. Should be preserved in output */
1101 data
= "Data \0 before \0 first \0 section" /* 31 bytes */
1102 "\r\n[section1]\r\n" /* 14 bytes */
1103 "key1=string1\r\n"; /* 14 bytes */
1104 GetTempFileNameA(temp
, "wine", 0, path
);
1105 create_test_file(path
, data
, 31);
1106 ret
= WritePrivateProfileStringA("section1", "key1", "string1", path
);
1107 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1109 ok( check_binary_file_data(path
, data
, 59) ||
1110 broken( check_binary_file_data(path
, /* Windows 9x */
1111 "Data \0 before \0 first \0 section" /* 31 bytes */
1112 "\r\n\r\n[section1]\r\n" /* 14 bytes */
1113 "key1=string1" /* 14 bytes */
1114 , 59)), "File doesn't match\n");
1121 test_profile_string();
1122 test_profile_sections();
1123 test_profile_sections_names();
1124 test_profile_existing();
1125 test_profile_delete_on_close();
1126 test_profile_refresh();
1127 test_GetPrivateProfileString(
1130 "name2=\"val2\"\r\n"
1135 test_GetPrivateProfileString(
1143 test_WritePrivateProfileString();