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
24 #include "wine/test.h"
29 #define KEY "ProfileInt"
30 #define SECTION "Test"
31 #define TESTFILE ".\\testwine.ini"
32 #define TESTFILE2 ".\\testwine2.ini"
44 static void test_profile_int(void)
46 struct _profileInt profileInt
[]={
47 { NULL
, NULL
, NULL
, NULL
, 70, 0 , 0}, /* 0 */
48 { NULL
, NULL
, NULL
, TESTFILE
, -1, 4294967295U, 0},
49 { NULL
, NULL
, NULL
, TESTFILE
, 1, 1 , 0},
50 { SECTION
, NULL
, NULL
, TESTFILE
, -1, 4294967295U, 0},
51 { SECTION
, NULL
, NULL
, TESTFILE
, 1, 1 , 0},
52 { NULL
, KEY
, NULL
, TESTFILE
, -1, 4294967295U, 0}, /* 5 */
53 { NULL
, KEY
, NULL
, TESTFILE
, 1, 1 , 0},
54 { SECTION
, KEY
, NULL
, TESTFILE
, -1, 4294967295U, 4294967295U},
55 { SECTION
, KEY
, NULL
, TESTFILE
, 1, 1 , 1},
56 { SECTION
, KEY
, "-1", TESTFILE
, -1, 4294967295U, 4294967295U},
57 { SECTION
, KEY
, "-1", TESTFILE
, 1, 4294967295U, 4294967295U}, /* 10 */
58 { SECTION
, KEY
, "1", TESTFILE
, -1, 1 , 1},
59 { SECTION
, KEY
, "1", TESTFILE
, 1, 1 , 1},
60 { SECTION
, KEY
, "+1", TESTFILE
, -1, 1 , 0},
61 { SECTION
, KEY
, "+1", TESTFILE
, 1, 1 , 0},
62 { SECTION
, KEY
, "4294967296", TESTFILE
, -1, 0 , 0}, /* 15 */
63 { SECTION
, KEY
, "4294967296", TESTFILE
, 1, 0 , 0},
64 { SECTION
, KEY
, "4294967297", TESTFILE
, -1, 1 , 1},
65 { SECTION
, KEY
, "4294967297", TESTFILE
, 1, 1 , 1},
66 { SECTION
, KEY
, "-4294967297", TESTFILE
, -1, 4294967295U, 4294967295U},
67 { SECTION
, KEY
, "-4294967297", TESTFILE
, 1, 4294967295U, 4294967295U}, /* 20 */
68 { SECTION
, KEY
, "42A94967297", TESTFILE
, -1, 42 , 42},
69 { SECTION
, KEY
, "42A94967297", TESTFILE
, 1, 42 , 42},
70 { SECTION
, KEY
, "B4294967297", TESTFILE
, -1, 0 , 0},
71 { SECTION
, KEY
, "B4294967297", TESTFILE
, 1, 0 , 0},
73 int i
, num_test
= (sizeof(profileInt
)/sizeof(struct _profileInt
));
76 DeleteFileA( TESTFILE
);
78 for (i
=0; i
< num_test
; i
++) {
79 if (profileInt
[i
].value
)
80 WritePrivateProfileStringA(SECTION
, KEY
, profileInt
[i
].value
,
81 profileInt
[i
].iniFile
);
83 res
= GetPrivateProfileIntA(profileInt
[i
].section
, profileInt
[i
].key
,
84 profileInt
[i
].defaultVal
, profileInt
[i
].iniFile
);
85 ok((res
== profileInt
[i
].result
) || (res
== profileInt
[i
].result9x
),
86 "test<%02d>: ret<%010u> exp<%010u><%010u>\n",
87 i
, res
, profileInt
[i
].result
, profileInt
[i
].result9x
);
90 DeleteFileA( TESTFILE
);
93 static void test_profile_string(void)
95 static WCHAR emptyW
[] = { 0 };
96 static WCHAR keyW
[] = { 'k','e','y',0 };
97 static WCHAR sW
[] = { 's',0 };
98 static WCHAR TESTFILE2W
[] = {'.','\\','t','e','s','t','w','i','n','e','2','.','i','n','i',0};
99 static WCHAR valsectionW
[] = {'v','a','l','_','e','_','s','e','c','t','i','o','n',0 };
100 static WCHAR valnokeyW
[] = {'v','a','l','_','n','o','_','k','e','y',0};
107 /* test that lines without an '=' will not be enumerated */
108 /* in the case below, name2 is a key while name3 is not. */
109 char content
[]="[s]\r\nname1=val1\r\nname2=\r\nname3\r\nname4=val4\r\n";
110 char content2
[]="\r\nkey=val_no_section\r\n[]\r\nkey=val_e_section\r\n"
111 "[s]\r\n=val_no_key\r\n[t]\r\n";
112 DeleteFileA( TESTFILE2
);
113 h
= CreateFileA( TESTFILE2
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
114 FILE_ATTRIBUTE_NORMAL
, NULL
);
115 ok( h
!= INVALID_HANDLE_VALUE
, " cannot create %s\n", TESTFILE2
);
116 if( h
== INVALID_HANDLE_VALUE
) return;
117 WriteFile( h
, content
, sizeof(content
), &count
, NULL
);
120 /* enumerate the keys */
121 ret
=GetPrivateProfileStringA( "s", NULL
, "", buf
, sizeof(buf
),
123 for( p
= buf
+ strlen(buf
) + 1; *p
;p
+= strlen(p
)+1)
126 ok( ret
== 18 && !strcmp( buf
, "name1,name2,name4"), "wrong keys returned(%d): %s\n", ret
,
129 /* add a new key to test that the file is quite usable */
130 WritePrivateProfileStringA( "s", "name5", "val5", TESTFILE2
);
131 ret
=GetPrivateProfileStringA( "s", NULL
, "", buf
, sizeof(buf
),
133 for( p
= buf
+ strlen(buf
) + 1; *p
;p
+= strlen(p
)+1)
135 ok( ret
== 24 && !strcmp( buf
, "name1,name2,name4,name5"), "wrong keys returned(%d): %s\n",
138 h
= CreateFileA( TESTFILE2
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
139 FILE_ATTRIBUTE_NORMAL
, NULL
);
140 ok( h
!= INVALID_HANDLE_VALUE
, " cannot create %s\n", TESTFILE2
);
141 if( h
== INVALID_HANDLE_VALUE
) return;
142 WriteFile( h
, content2
, sizeof(content2
), &count
, NULL
);
145 /* works only in unicode, ascii crashes */
146 ret
=GetPrivateProfileStringW(emptyW
, keyW
, emptyW
, bufW
,
147 sizeof(bufW
)/sizeof(bufW
[0]), TESTFILE2W
);
149 ok(!lstrcmpW(valsectionW
,bufW
), "expected %s, got %s\n",
150 wine_dbgstr_w(valsectionW
), wine_dbgstr_w(bufW
) );
152 /* works only in unicode, ascii crashes */
153 ret
=GetPrivateProfileStringW(sW
, emptyW
, emptyW
, bufW
,
154 sizeof(bufW
)/sizeof(bufW
[0]), TESTFILE2W
);
156 ok(!lstrcmpW(valnokeyW
,bufW
), "expected %s, got %s\n",
157 wine_dbgstr_w(valnokeyW
), wine_dbgstr_w(bufW
) );
159 DeleteFileA( TESTFILE2
);
162 static void test_profile_sections(void)
169 static const char content
[]="[section1]\r\nname1=val1\r\nname2=\r\nname3\r\nname4=val4\r\n[section2]\r\n";
170 static const char testfile4
[]=".\\testwine4.ini";
171 BOOL on_win98
= FALSE
;
173 DeleteFileA( testfile4
);
174 h
= CreateFileA( testfile4
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
175 ok( h
!= INVALID_HANDLE_VALUE
, " cannot create %s\n", testfile4
);
176 if( h
== INVALID_HANDLE_VALUE
) return;
177 WriteFile( h
, content
, sizeof(content
), &count
, NULL
);
180 /* Some parameter checking */
181 SetLastError(0xdeadbeef);
182 ret
= GetPrivateProfileSectionA( NULL
, NULL
, 0, NULL
);
183 ok( ret
== 0, "expected return size 0, got %d\n", ret
);
184 ok( GetLastError() == ERROR_INVALID_PARAMETER
||
185 GetLastError() == 0xdeadbeef /* Win98 */,
186 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
187 if (GetLastError() == 0xdeadbeef) on_win98
= TRUE
;
189 SetLastError(0xdeadbeef);
190 ret
= GetPrivateProfileSectionA( NULL
, NULL
, 0, testfile4
);
191 ok( ret
== 0, "expected return size 0, got %d\n", ret
);
192 ok( GetLastError() == ERROR_INVALID_PARAMETER
||
193 GetLastError() == 0xdeadbeef /* Win98 */,
194 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
198 SetLastError(0xdeadbeef);
199 ret
= GetPrivateProfileSectionA( "section1", NULL
, 0, testfile4
);
200 ok( ret
== 0, "expected return size 0, got %d\n", ret
);
201 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
204 SetLastError(0xdeadbeef);
205 ret
= GetPrivateProfileSectionA( NULL
, buf
, sizeof(buf
), testfile4
);
206 ok( ret
== 0, "expected return size 0, got %d\n", ret
);
207 ok( GetLastError() == ERROR_INVALID_PARAMETER
||
208 broken(GetLastError() == 0xdeadbeef), /* Win9x, WinME */
209 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
211 SetLastError(0xdeadbeef);
212 ret
= GetPrivateProfileSectionA( "section1", buf
, sizeof(buf
), NULL
);
213 ok( ret
== 0, "expected return size 0, got %d\n", ret
);
215 ok( GetLastError() == ERROR_FILE_NOT_FOUND
||
216 broken(GetLastError() == 0xdeadbeef), /* Win9x, WinME */
217 "expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
219 /* Existing empty section with no keys */
220 SetLastError(0xdeadbeef);
221 ret
=GetPrivateProfileSectionA("section2", buf
, sizeof(buf
), testfile4
);
222 ok( ret
== 0, "expected return size 0, got %d\n", ret
);
223 ok( GetLastError() == ERROR_SUCCESS
||
224 broken(GetLastError() == 0xdeadbeef), /* Win9x, WinME */
225 "expected ERROR_SUCCESS, got %d\n", GetLastError());
227 /* Existing section with keys and values*/
228 SetLastError(0xdeadbeef);
229 ret
=GetPrivateProfileSectionA("section1", buf
, sizeof(buf
), testfile4
);
230 for( p
= buf
+ strlen(buf
) + 1; *p
;p
+= strlen(p
)+1)
232 ok( ret
== 35 && !strcmp( buf
, "name1=val1,name2=,name3,name4=val4"), "wrong section returned(%d): %s\n",
234 ok( buf
[ret
-1] == 0 && buf
[ret
] == 0, "returned buffer not terminated with double-null\n" );
235 ok( GetLastError() == ERROR_SUCCESS
||
236 broken(GetLastError() == 0xdeadbeef), /* Win9x, WinME */
237 "expected ERROR_SUCCESS, got %d\n", GetLastError());
239 DeleteFileA( testfile4
);
242 static void test_profile_sections_names(void)
249 static const char content
[]="[section1]\r\n[section2]\r\n[section3]\r\n";
250 static const char testfile3
[]=".\\testwine3.ini";
251 static const WCHAR testfile3W
[]={ '.','\\','t','e','s','t','w','i','n','e','3','.','i','n','i',0 };
252 static const WCHAR not_here
[] = {'.','\\','n','o','t','_','h','e','r','e','.','i','n','i',0};
253 DeleteFileA( testfile3
);
254 h
= CreateFileA( testfile3
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
255 FILE_ATTRIBUTE_NORMAL
, NULL
);
256 ok( h
!= INVALID_HANDLE_VALUE
, " cannot create %s\n", testfile3
);
257 if( h
== INVALID_HANDLE_VALUE
) return;
258 WriteFile( h
, content
, sizeof(content
), &count
, NULL
);
261 /* Test with sufficiently large buffer */
262 memset(buf
, 0xc, sizeof(buf
));
263 ret
= GetPrivateProfileSectionNamesA( buf
, 29, testfile3
);
265 broken(ret
== 28), /* Win9x, WinME */
266 "expected return size 27, got %d\n", ret
);
267 ok( (buf
[ret
-1] == 0 && buf
[ret
] == 0) ||
268 broken(buf
[ret
-1] == 0 && buf
[ret
-2] == 0), /* Win9x, WinME */
269 "returned buffer not terminated with double-null\n" );
271 /* Test with exactly fitting buffer */
272 memset(buf
, 0xc, sizeof(buf
));
273 ret
= GetPrivateProfileSectionNamesA( buf
, 28, testfile3
);
275 broken(ret
== 28), /* Win9x, WinME */
276 "expected return size 26, got %d\n", ret
);
278 ok( (buf
[ret
+1] == 0 && buf
[ret
] == 0) || /* W2K3 and higher */
279 broken(buf
[ret
+1] == 0xc && buf
[ret
] == 0) || /* NT4, W2K, WinXP */
280 broken(buf
[ret
-1] == 0 && buf
[ret
-2] == 0), /* Win9x, WinME */
281 "returned buffer not terminated with double-null\n" );
283 /* Test with a buffer too small */
284 memset(buf
, 0xc, sizeof(buf
));
285 ret
= GetPrivateProfileSectionNamesA( buf
, 27, testfile3
);
286 ok( ret
== 25, "expected return size 25, got %d\n", ret
);
287 /* Win9x and WinME only fills the buffer with complete section names (double-null terminated) */
288 count
= strlen("section1") + sizeof(CHAR
) + strlen("section2");
290 ok( (buf
[ret
+1] == 0 && buf
[ret
] == 0) ||
291 broken(buf
[count
] == 0 && buf
[count
+1] == 0), /* Win9x, WinME */
292 "returned buffer not terminated with double-null\n" );
294 /* Tests on nonexistent file */
295 memset(buf
, 0xc, sizeof(buf
));
296 ret
= GetPrivateProfileSectionNamesA( buf
, 10, ".\\not_here.ini" );
298 broken(ret
== 1), /* Win9x, WinME */
299 "expected return size 0, got %d\n", ret
);
300 ok( buf
[0] == 0, "returned buffer not terminated with null\n" );
301 ok( buf
[1] != 0, "returned buffer terminated with double-null\n" );
303 /* Test with sufficiently large buffer */
304 SetLastError(0xdeadbeef);
305 memset(bufW
, 0xcc, sizeof(bufW
));
306 ret
= GetPrivateProfileSectionNamesW( bufW
, 29, testfile3W
);
307 if (ret
== 0 && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
))
309 win_skip("GetPrivateProfileSectionNamesW is not implemented\n");
310 DeleteFileA( testfile3
);
313 ok( ret
== 27, "expected return size 27, got %d\n", ret
);
314 ok( bufW
[ret
-1] == 0 && bufW
[ret
] == 0, "returned buffer not terminated with double-null\n" );
316 /* Test with exactly fitting buffer */
317 memset(bufW
, 0xcc, sizeof(bufW
));
318 ret
= GetPrivateProfileSectionNamesW( bufW
, 28, testfile3W
);
319 ok( ret
== 26, "expected return size 26, got %d\n", ret
);
320 ok( (bufW
[ret
+1] == 0 && bufW
[ret
] == 0) || /* W2K3 and higher */
321 broken(bufW
[ret
+1] == 0xcccc && bufW
[ret
] == 0), /* NT4, W2K, WinXP */
322 "returned buffer not terminated with double-null\n" );
324 /* Test with a buffer too small */
325 memset(bufW
, 0xcc, sizeof(bufW
));
326 ret
= GetPrivateProfileSectionNamesW( bufW
, 27, testfile3W
);
327 ok( ret
== 25, "expected return size 25, got %d\n", ret
);
328 ok( bufW
[ret
+1] == 0 && bufW
[ret
] == 0, "returned buffer not terminated with double-null\n" );
330 DeleteFileA( testfile3
);
332 /* Tests on nonexistent file */
333 memset(bufW
, 0xcc, sizeof(bufW
));
334 ret
= GetPrivateProfileSectionNamesW( bufW
, 10, not_here
);
335 ok( ret
== 0, "expected return size 0, got %d\n", ret
);
336 ok( bufW
[0] == 0, "returned buffer not terminated with null\n" );
337 ok( bufW
[1] != 0, "returned buffer terminated with double-null\n" );
340 /* If the ini-file has already been opened with CreateFile, WritePrivateProfileString failed in wine with an error ERROR_SHARING_VIOLATION, some testing here */
341 static void test_profile_existing(void)
343 static const char *testfile1
= ".\\winesharing1.ini";
344 static const char *testfile2
= ".\\winesharing2.ini";
346 static const struct {
347 DWORD dwDesiredAccess
;
353 {GENERIC_READ
, FILE_SHARE_READ
, ERROR_SHARING_VIOLATION
, FALSE
},
354 {GENERIC_READ
, FILE_SHARE_WRITE
, ERROR_SHARING_VIOLATION
, TRUE
},
355 {GENERIC_WRITE
, FILE_SHARE_READ
, ERROR_SHARING_VIOLATION
, FALSE
},
356 {GENERIC_WRITE
, FILE_SHARE_WRITE
, ERROR_SHARING_VIOLATION
, TRUE
},
357 {GENERIC_READ
|GENERIC_WRITE
, FILE_SHARE_READ
, ERROR_SHARING_VIOLATION
, FALSE
},
358 {GENERIC_READ
|GENERIC_WRITE
, FILE_SHARE_WRITE
, ERROR_SHARING_VIOLATION
, TRUE
},
359 {GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, 0, FALSE
, ERROR_SHARING_VIOLATION
/* nt4 */},
360 {GENERIC_WRITE
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, 0, FALSE
, ERROR_SHARING_VIOLATION
/* nt4 */},
361 /*Thief demo (bug 5024) opens .ini file like this*/
362 {GENERIC_READ
|GENERIC_WRITE
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, 0, FALSE
, ERROR_SHARING_VIOLATION
/* nt4 */}
369 char buffer
[MAX_PATH
];
371 for (i
=0; i
< sizeof(pe
)/sizeof(pe
[0]); i
++)
373 h
= CreateFile(testfile1
, pe
[i
].dwDesiredAccess
, pe
[i
].dwShareMode
, NULL
,
374 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
375 ok(INVALID_HANDLE_VALUE
!= h
, "%d: CreateFile failed\n",i
);
376 SetLastError(0xdeadbeef);
378 ret
= WritePrivateProfileString(SECTION
, KEY
, "12345", testfile1
);
379 if (!pe
[i
].write_error
)
382 ok( broken(GetLastError() == pe
[i
].broken_error
),
383 "%d: WritePrivateProfileString failed with error %u\n", i
, GetLastError() );
385 size
= GetPrivateProfileString(SECTION
, KEY
, 0, buffer
, MAX_PATH
, testfile1
);
387 ok( size
== 5, "%d: test failed, number of characters copied: %d instead of 5\n", i
, size
);
389 ok( !size
, "%d: test failed, number of characters copied: %d instead of 0\n", i
, size
);
393 DWORD err
= GetLastError();
394 ok( !ret
, "%d: WritePrivateProfileString succeeded\n", i
);
396 ok( err
== pe
[i
].write_error
, "%d: WritePrivateProfileString failed with error %u/%u\n",
397 i
, err
, pe
[i
].write_error
);
399 size
= GetPrivateProfileString(SECTION
, KEY
, 0, buffer
, MAX_PATH
, testfile1
);
400 ok( !size
, "%d: test failed, number of characters copied: %d instead of 0\n", i
, size
);
403 ok( DeleteFile(testfile1
), "delete failed\n" );
406 h
= CreateFile(testfile2
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
407 sprintf( buffer
, "[%s]\r\n%s=123\r\n", SECTION
, KEY
);
408 ok( WriteFile( h
, buffer
, strlen(buffer
), &size
, NULL
), "failed to write\n" );
411 for (i
=0; i
< sizeof(pe
)/sizeof(pe
[0]); i
++)
413 h
= CreateFile(testfile2
, pe
[i
].dwDesiredAccess
, pe
[i
].dwShareMode
, NULL
,
414 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
415 ok(INVALID_HANDLE_VALUE
!= h
, "%d: CreateFile failed\n",i
);
416 SetLastError(0xdeadbeef);
417 ret
= GetPrivateProfileStringA(SECTION
, KEY
, NULL
, buffer
, MAX_PATH
, testfile2
);
418 /* Win9x and WinME returns 0 for all cases except the first one */
419 if (!pe
[i
].read_error
)
421 broken(!ret
&& GetLastError() == 0xdeadbeef), /* Win9x, WinME */
422 "%d: GetPrivateProfileString failed with error %u\n", i
, GetLastError() );
424 ok( !ret
, "%d: GetPrivateProfileString succeeded\n", i
);
427 ok( DeleteFile(testfile2
), "delete failed\n" );
430 static void test_profile_delete_on_close(void)
432 static CHAR testfile
[] = ".\\testwine5.ini";
435 static const char contents
[] = "[" SECTION
"]\n" KEY
"=123\n";
437 h
= CreateFile(testfile
, GENERIC_WRITE
, FILE_SHARE_READ
, NULL
,
438 CREATE_ALWAYS
, FILE_FLAG_DELETE_ON_CLOSE
, NULL
);
439 ok( WriteFile( h
, contents
, sizeof contents
- 1, &size
, NULL
),
440 "Cannot write test file: %x\n", GetLastError() );
441 ok( size
== sizeof contents
- 1, "Test file: partial write\n");
443 SetLastError(0xdeadbeef);
444 res
= GetPrivateProfileInt(SECTION
, KEY
, 0, testfile
);
446 broken(res
== 0 && GetLastError() == ERROR_SHARING_VIOLATION
), /* Win9x, WinME */
447 "Got %d instead of 123\n", res
);
449 /* This also deletes the file */
453 static void test_profile_refresh(void)
455 static CHAR testfile
[] = ".\\winetest4.ini";
458 static const char contents1
[] = "[" SECTION
"]\n" KEY
"=123\n";
459 static const char contents2
[] = "[" SECTION
"]\n" KEY
"=124\n";
461 h
= CreateFile(testfile
, GENERIC_WRITE
, FILE_SHARE_READ
, NULL
,
462 CREATE_ALWAYS
, FILE_FLAG_DELETE_ON_CLOSE
, NULL
);
463 ok( WriteFile( h
, contents1
, sizeof contents1
- 1, &size
, NULL
),
464 "Cannot write test file: %x\n", GetLastError() );
465 ok( size
== sizeof contents1
- 1, "Test file: partial write\n");
467 SetLastError(0xdeadbeef);
468 res
= GetPrivateProfileInt(SECTION
, KEY
, 0, testfile
);
470 broken(res
== 0 && GetLastError() == ERROR_SHARING_VIOLATION
), /* Win9x, WinME */
471 "Got %d instead of 123\n", res
);
475 /* Test proper invalidation of wine's profile file cache */
477 h
= CreateFile(testfile
, GENERIC_WRITE
, FILE_SHARE_READ
, NULL
,
478 CREATE_ALWAYS
, FILE_FLAG_DELETE_ON_CLOSE
, NULL
);
479 ok( WriteFile( h
, contents2
, sizeof contents2
- 1, &size
, NULL
),
480 "Cannot write test file: %x\n", GetLastError() );
481 ok( size
== sizeof contents2
- 1, "Test file: partial write\n");
483 SetLastError(0xdeadbeef);
484 res
= GetPrivateProfileInt(SECTION
, KEY
, 0, testfile
);
486 broken(res
== 0 && GetLastError() == 0xdeadbeef), /* Win9x, WinME */
487 "Got %d instead of 124\n", res
);
489 /* This also deletes the file */
493 static void create_test_file(LPCSTR name
, LPCSTR data
, DWORD size
)
498 hfile
= CreateFileA(name
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
499 ok(hfile
!= INVALID_HANDLE_VALUE
, "cannot create %s\n", name
);
500 WriteFile(hfile
, data
, size
, &count
, NULL
);
504 static BOOL
emptystr_ok(CHAR emptystr
[MAX_PATH
])
508 for(i
= 0;i
< MAX_PATH
;++i
)
511 trace("emptystr[%d] = %d\n",i
,emptystr
[i
]);
518 static void test_GetPrivateProfileString(const char *content
, const char *descript
)
522 CHAR def_val
[MAX_PATH
];
524 CHAR windir
[MAX_PATH
];
525 /* NT series crashes on r/o empty strings, so pass an r/w
526 empty string and check for modification */
527 CHAR emptystr
[MAX_PATH
] = "";
530 static const char filename
[] = ".\\winetest.ini";
532 trace("test_GetPrivateProfileStringA: %s\n", descript
);
534 if(!lstrcmpA(descript
, "CR only"))
536 SetLastError(0xdeadbeef);
537 ret
= GetPrivateProfileStringW(NULL
, NULL
, NULL
,
539 if (!ret
&& GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
541 win_skip("Win9x and WinME don't handle 'CR only' correctly\n");
546 create_test_file(filename
, content
, lstrlenA(content
));
548 /* Run this test series with caching. Wine won't cache profile
549 files younger than 2.1 seconds. */
552 /* lpAppName is NULL */
553 memset(buf
, 0xc, sizeof(buf
));
554 lstrcpyA(buf
, "kumquat");
555 ret
= GetPrivateProfileStringA(NULL
, "name1", "default",
556 buf
, MAX_PATH
, filename
);
558 broken(ret
== 19), /* Win9x and WinME */
559 "Expected 18, got %d\n", ret
);
560 len
= lstrlenA("section1") + sizeof(CHAR
) + lstrlenA("section2") + 2 * sizeof(CHAR
);
561 ok(!memcmp(buf
, "section1\0section2\0\0", len
),
562 "Expected \"section1\\0section2\\0\\0\", got \"%s\"\n", buf
);
564 /* lpAppName is empty */
565 memset(buf
, 0xc, sizeof(buf
));
566 lstrcpyA(buf
, "kumquat");
567 ret
= GetPrivateProfileStringA(emptystr
, "name1", "default",
568 buf
, MAX_PATH
, filename
);
569 ok(ret
== 7, "Expected 7, got %d\n", ret
);
570 ok(!lstrcmpA(buf
, "default"), "Expected \"default\", got \"%s\"\n", buf
);
571 ok(emptystr_ok(emptystr
), "AppName modified\n");
573 /* lpAppName is missing */
574 memset(buf
, 0xc,sizeof(buf
));
575 lstrcpyA(buf
, "kumquat");
576 ret
= GetPrivateProfileStringA("notasection", "name1", "default",
577 buf
, MAX_PATH
, filename
);
578 ok(ret
== 7, "Expected 7, got %d\n", ret
);
579 ok(!lstrcmpA(buf
, "default"), "Expected \"default\", got \"%s\"\n", buf
);
581 /* lpAppName is empty, lpDefault is NULL */
582 memset(buf
, 0xc,sizeof(buf
));
583 lstrcpyA(buf
, "kumquat");
584 ret
= GetPrivateProfileStringA(emptystr
, "name1", NULL
,
585 buf
, MAX_PATH
, filename
);
586 ok(ret
== 0, "Expected 0, got %d\n", ret
);
587 ok(!lstrcmpA(buf
, "") ||
588 broken(!lstrcmpA(buf
, "kumquat")), /* Win9x, WinME */
589 "Expected \"\", got \"%s\"\n", buf
);
590 ok(emptystr_ok(emptystr
), "AppName modified\n");
592 /* lpAppName is empty, lpDefault is empty */
593 memset(buf
, 0xc,sizeof(buf
));
594 lstrcpyA(buf
, "kumquat");
595 ret
= GetPrivateProfileStringA(emptystr
, "name1", "",
596 buf
, MAX_PATH
, filename
);
597 ok(ret
== 0, "Expected 0, got %d\n", ret
);
598 ok(!lstrcmpA(buf
, ""), "Expected \"\", got \"%s\"\n", buf
);
599 ok(emptystr_ok(emptystr
), "AppName modified\n");
601 /* lpAppName is empty, lpDefault has trailing blank characters */
602 memset(buf
, 0xc,sizeof(buf
));
603 lstrcpyA(buf
, "kumquat");
604 /* lpDefault must be writable (trailing blanks are removed inplace in win9x) */
605 lstrcpyA(def_val
, "default ");
606 ret
= GetPrivateProfileStringA(emptystr
, "name1", def_val
,
607 buf
, MAX_PATH
, filename
);
608 ok(ret
== 7, "Expected 7, got %d\n", ret
);
609 ok(!lstrcmpA(buf
, "default"), "Expected \"default\", got \"%s\"\n", buf
);
610 ok(emptystr_ok(emptystr
), "AppName modified\n");
612 /* lpAppName is empty, many blank characters in lpDefault */
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
, "one two ");
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
, "one two"), "Expected \"one two\", got \"%s\"\n", buf
);
621 ok(emptystr_ok(emptystr
), "AppName modified\n");
623 /* lpAppName is empty, blank character but not trailing in lpDefault */
624 memset(buf
, 0xc,sizeof(buf
));
625 lstrcpyA(buf
, "kumquat");
626 ret
= GetPrivateProfileStringA(emptystr
, "name1", "one two",
627 buf
, MAX_PATH
, filename
);
628 ok(ret
== 7, "Expected 7, got %d\n", ret
);
629 ok(!lstrcmpA(buf
, "one two"), "Expected \"one two\", got \"%s\"\n", buf
);
630 ok(emptystr_ok(emptystr
), "AppName modified\n");
632 /* lpKeyName is NULL */
633 memset(buf
, 0xc,sizeof(buf
));
634 lstrcpyA(buf
, "kumquat");
635 ret
= GetPrivateProfileStringA("section1", NULL
, "default",
636 buf
, MAX_PATH
, filename
);
637 ok(ret
== 18, "Expected 18, got %d\n", ret
);
638 ok(!memcmp(buf
, "name1\0name2\0name4\0", ret
+ 1),
639 "Expected \"name1\\0name2\\0name4\\0\", got \"%s\"\n", buf
);
641 /* lpKeyName is empty */
642 memset(buf
, 0xc,sizeof(buf
));
643 lstrcpyA(buf
, "kumquat");
644 ret
= GetPrivateProfileStringA("section1", emptystr
, "default",
645 buf
, MAX_PATH
, filename
);
646 ok(ret
== 7, "Expected 7, got %d\n", ret
);
647 ok(!lstrcmpA(buf
, "default"), "Expected \"default\", got \"%s\"\n", buf
);
648 ok(emptystr_ok(emptystr
), "KeyName modified\n");
650 /* lpKeyName is missing */
651 memset(buf
, 0xc,sizeof(buf
));
652 lstrcpyA(buf
, "kumquat");
653 ret
= GetPrivateProfileStringA("section1", "notakey", "default",
654 buf
, MAX_PATH
, filename
);
655 ok(ret
== 7, "Expected 7, got %d\n", ret
);
656 ok(!lstrcmpA(buf
, "default"), "Expected \"default\", got \"%s\"\n", buf
);
658 /* lpKeyName is empty, lpDefault is NULL */
659 memset(buf
, 0xc,sizeof(buf
));
660 lstrcpyA(buf
, "kumquat");
661 ret
= GetPrivateProfileStringA("section1", emptystr
, NULL
,
662 buf
, MAX_PATH
, filename
);
663 ok(ret
== 0, "Expected 0, got %d\n", ret
);
664 ok(!lstrcmpA(buf
, "") ||
665 broken(!lstrcmpA(buf
, "kumquat")), /* Win9x, WinME */
666 "Expected \"\", got \"%s\"\n", buf
);
667 ok(emptystr_ok(emptystr
), "KeyName modified\n");
669 /* lpKeyName is empty, lpDefault is empty */
670 memset(buf
, 0xc,sizeof(buf
));
671 lstrcpyA(buf
, "kumquat");
672 ret
= GetPrivateProfileStringA("section1", emptystr
, "",
673 buf
, MAX_PATH
, filename
);
674 ok(ret
== 0, "Expected 0, got %d\n", ret
);
675 ok(!lstrcmpA(buf
, ""), "Expected \"\", got \"%s\"\n", buf
);
676 ok(emptystr_ok(emptystr
), "KeyName modified\n");
678 /* lpKeyName is empty, lpDefault has trailing blank characters */
679 memset(buf
, 0xc,sizeof(buf
));
680 lstrcpyA(buf
, "kumquat");
681 /* lpDefault must be writable (trailing blanks are removed inplace in win9x) */
682 lstrcpyA(def_val
, "default ");
683 ret
= GetPrivateProfileStringA("section1", emptystr
, def_val
,
684 buf
, MAX_PATH
, filename
);
685 ok(ret
== 7, "Expected 7, got %d\n", ret
);
686 ok(!lstrcmpA(buf
, "default"), "Expected \"default\", got \"%s\"\n", buf
);
687 ok(emptystr_ok(emptystr
), "KeyName modified\n");
691 /* lpReturnedString is NULL */
692 ret
= GetPrivateProfileStringA("section1", "name1", "default",
693 NULL
, MAX_PATH
, filename
);
696 /* lpFileName is NULL */
697 memset(buf
, 0xc,sizeof(buf
));
698 lstrcpyA(buf
, "kumquat");
699 ret
= GetPrivateProfileStringA("section1", "name1", "default",
700 buf
, MAX_PATH
, NULL
);
702 broken(ret
== 0), /* Win9x, WinME */
703 "Expected 7, got %d\n", ret
);
704 ok(!lstrcmpA(buf
, "default") ||
705 broken(!lstrcmpA(buf
, "kumquat")), /* Win9x, WinME */
706 "Expected \"default\", got \"%s\"\n", buf
);
708 /* lpFileName is empty */
709 memset(buf
, 0xc,sizeof(buf
));
710 lstrcpyA(buf
, "kumquat");
711 ret
= GetPrivateProfileStringA("section1", "name1", "default",
713 ok(ret
== 7, "Expected 7, got %d\n", ret
);
714 ok(!lstrcmpA(buf
, "default"), "Expected \"default\", got \"%s\"\n", buf
);
716 /* lpFileName is nonexistent */
717 memset(buf
, 0xc,sizeof(buf
));
718 lstrcpyA(buf
, "kumquat");
719 ret
= GetPrivateProfileStringA("section1", "name1", "default",
720 buf
, MAX_PATH
, "nonexistent");
721 ok(ret
== 7, "Expected 7, got %d\n", ret
);
722 ok(!lstrcmpA(buf
, "default"), "Expected \"default\", got \"%s\"\n", buf
);
725 memset(buf
, 0xc,sizeof(buf
));
726 lstrcpyA(buf
, "kumquat");
727 ret
= GetPrivateProfileStringA("section1", "name1", "default",
729 ok(ret
== 0, "Expected 0, got %d\n", ret
);
730 ok(!lstrcmpA(buf
, "kumquat"), "Expected buf to be unchanged, got \"%s\"\n", buf
);
732 /* nSize is exact size of output */
733 memset(buf
, 0xc,sizeof(buf
));
734 lstrcpyA(buf
, "kumquat");
735 ret
= GetPrivateProfileStringA("section1", "name1", "default",
737 ok(ret
== 3, "Expected 3, got %d\n", ret
);
738 ok(!lstrcmpA(buf
, "val"), "Expected \"val\", got \"%s\"\n", buf
);
740 /* nSize has room for NULL terminator */
741 memset(buf
, 0xc,sizeof(buf
));
742 lstrcpyA(buf
, "kumquat");
743 ret
= GetPrivateProfileStringA("section1", "name1", "default",
745 ok(ret
== 4, "Expected 4, got %d\n", ret
);
746 ok(!lstrcmpA(buf
, "val1"), "Expected \"val1\", got \"%s\"\n", buf
);
748 /* output is 1 character */
749 memset(buf
, 0xc,sizeof(buf
));
750 lstrcpyA(buf
, "kumquat");
751 ret
= GetPrivateProfileStringA("section1", "name4", "default",
752 buf
, MAX_PATH
, filename
);
753 ok(ret
== 1, "Expected 1, got %d\n", ret
);
754 ok(!lstrcmpA(buf
, "a"), "Expected \"a\", got \"%s\"\n", buf
);
756 /* output is 1 character, no room for NULL terminator */
757 memset(buf
, 0xc,sizeof(buf
));
758 lstrcpyA(buf
, "kumquat");
759 ret
= GetPrivateProfileStringA("section1", "name4", "default",
761 ok(ret
== 0, "Expected 0, got %d\n", ret
);
762 ok(!lstrcmpA(buf
, ""), "Expected \"\", got \"%s\"\n", buf
);
764 /* lpAppName is NULL, not enough room for final section name */
765 memset(buf
, 0xc,sizeof(buf
));
766 lstrcpyA(buf
, "kumquat");
767 ret
= GetPrivateProfileStringA(NULL
, "name1", "default",
769 ok(ret
== 14, "Expected 14, got %d\n", ret
);
770 len
= lstrlenA("section1") + 2 * sizeof(CHAR
);
772 ok(!memcmp(buf
, "section1\0secti\0\0", ret
+ 2) ||
773 broken(!memcmp(buf
, "section1\0\0", len
)), /* Win9x, WinME */
774 "Expected \"section1\\0secti\\0\\0\", got \"%s\"\n", buf
);
776 /* lpKeyName is NULL, not enough room for final key name */
777 memset(buf
, 0xc,sizeof(buf
));
778 lstrcpyA(buf
, "kumquat");
779 ret
= GetPrivateProfileStringA("section1", NULL
, "default",
781 ok(ret
== 14, "Expected 14, got %d\n", ret
);
783 ok(!memcmp(buf
, "name1\0name2\0na\0\0", ret
+ 2) ||
784 broken(!memcmp(buf
, "name1\0name2\0n\0\0", ret
+ 1)), /* Win9x, WinME */
785 "Expected \"name1\\0name2\\0na\\0\\0\", got \"%s\"\n", buf
);
787 /* key value has quotation marks which are stripped */
788 memset(buf
, 0xc,sizeof(buf
));
789 lstrcpyA(buf
, "kumquat");
790 ret
= GetPrivateProfileStringA("section1", "name2", "default",
791 buf
, MAX_PATH
, filename
);
792 ok(ret
== 4, "Expected 4, got %d\n", ret
);
793 ok(!lstrcmpA(buf
, "val2"), "Expected \"val2\", got \"%s\"\n", buf
);
795 /* case does not match */
796 memset(buf
, 0xc,sizeof(buf
));
797 lstrcpyA(buf
, "kumquat");
798 ret
= GetPrivateProfileStringA("section1", "NaMe1", "default",
799 buf
, MAX_PATH
, filename
);
800 ok(ret
== 4, "Expected 4, got %d\n", ret
);
801 ok(!lstrcmpA(buf
, "val1"), "Expected \"val1\", got \"%s\"\n", buf
);
803 /* only filename is used */
804 memset(buf
, 0xc,sizeof(buf
));
805 lstrcpyA(buf
, "kumquat");
806 ret
= GetPrivateProfileStringA("section1", "NaMe1", "default",
807 buf
, MAX_PATH
, "winetest.ini");
808 ok(ret
== 7, "Expected 7, got %d\n", ret
);
809 ok(!lstrcmpA(buf
, "default"), "Expected \"default\", got \"%s\"\n", buf
);
811 GetWindowsDirectoryA(windir
, MAX_PATH
);
812 SetLastError(0xdeadbeef);
813 ret
= GetTempFileNameA(windir
, "pre", 0, path
);
814 if (!ret
&& GetLastError() == ERROR_ACCESS_DENIED
)
816 skip("Not allowed to create a file in the Windows directory\n");
817 DeleteFileA(filename
);
820 tempfile
= strrchr(path
, '\\') + 1;
821 create_test_file(path
, content
, lstrlenA(content
));
823 /* only filename is used, file exists in windows directory */
824 memset(buf
, 0xc,sizeof(buf
));
825 lstrcpyA(buf
, "kumquat");
826 ret
= GetPrivateProfileStringA("section1", "NaMe1", "default",
827 buf
, MAX_PATH
, tempfile
);
828 ok(ret
== 4, "Expected 4, got %d\n", ret
);
829 ok(!lstrcmpA(buf
, "val1"), "Expected \"val1\", got \"%s\"\n", buf
);
831 /* successful case */
832 memset(buf
, 0xc,sizeof(buf
));
833 lstrcpyA(buf
, "kumquat");
834 ret
= GetPrivateProfileStringA("section1", "name1", "default",
835 buf
, MAX_PATH
, filename
);
836 ok(ret
== 4, "Expected 4, got %d\n", ret
);
837 ok(!lstrcmpA(buf
, "val1"), "Expected \"val1\", got \"%s\"\n", buf
);
839 /* Existing section with no keys in an existing file */
840 memset(buf
, 0xc,sizeof(buf
));
841 SetLastError(0xdeadbeef);
842 ret
=GetPrivateProfileStringA("section2", "DoesntExist", "",
843 buf
, MAX_PATH
, filename
);
844 ok( ret
== 0, "expected return size 0, got %d\n", ret
);
845 ok(!lstrcmpA(buf
, ""), "Expected \"\", got \"%s\"\n", buf
);
847 ok( GetLastError() == 0xdeadbeef , "expected 0xdeadbeef, got %d\n",
852 DeleteFileA(filename
);
855 static BOOL
check_binary_file_data(LPCSTR path
, const VOID
*data
, DWORD size
)
861 file
= CreateFileA(path
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, 0);
862 if (file
== INVALID_HANDLE_VALUE
)
865 if(size
!= GetFileSize(file
, NULL
) )
871 ret
= ReadFile(file
, buf
, size
, &size
, NULL
);
876 return !memcmp(buf
, data
, size
);
879 static BOOL
check_file_data(LPCSTR path
, LPCSTR data
)
881 return check_binary_file_data(path
, data
, lstrlenA(data
));
884 static void test_WritePrivateProfileString(void)
891 SetLastError(0xdeadbeef);
892 ret
= WritePrivateProfileStringW(NULL
, NULL
, NULL
, NULL
);
893 if (!ret
&& GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
895 /* Win9x/WinME needs (variable) timeouts between tests and even long timeouts don't
896 * guarantee a correct result.
897 * Win9x/WinMe also produces different ini files where there is always a newline before
898 * a section start (except for the first one).
900 win_skip("WritePrivateProfileString on Win9x/WinME is hard to test reliably\n");
904 GetTempPathA(MAX_PATH
, temp
);
905 GetTempFileNameA(temp
, "wine", 0, path
);
908 /* path is not created yet */
911 SetLastError(0xdeadbeef);
912 ret
= WritePrivateProfileStringA(NULL
, "key", "string", path
);
913 ok(ret
== FALSE
, "Expected FALSE, got %d\n", ret
);
914 ok(GetLastError() == ERROR_FILE_NOT_FOUND
||
915 broken(GetLastError() == ERROR_INVALID_PARAMETER
) || /* NT4 */
916 broken(GetLastError() == 0xdeadbeef), /* Win9x and WinME */
917 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
918 ok(GetFileAttributesA(path
) == INVALID_FILE_ATTRIBUTES
,
919 "Expected path to not exist\n");
921 GetTempFileNameA(temp
, "wine", 0, path
);
923 /* NULL lpAppName, path exists */
925 SetLastError(0xdeadbeef);
926 ret
= WritePrivateProfileStringA(NULL
, "key", "string", path
);
927 ok(ret
== FALSE
, "Expected FALSE, got %d\n", ret
);
928 ok(GetLastError() == ERROR_FILE_NOT_FOUND
||
929 broken(GetLastError() == ERROR_INVALID_PARAMETER
) || /* NT4 */
930 broken(GetLastError() == 0xdeadbeef), /* Win9x and WinME */
931 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
932 ok(check_file_data(path
, data
), "File doesn't match\n");
937 /* empty lpAppName, crashes on NT4 and higher */
940 ret
= WritePrivateProfileStringA("", "key", "string", path
);
941 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
942 ok(check_file_data(path
, data
), "File doesn't match\n");
948 ret
= WritePrivateProfileStringA("App", NULL
, "string", path
);
949 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
952 ok(check_file_data(path
, data
), "File doesn't match\n");
958 /* empty lpKeyName, crashes on NT4 and higher */
961 ret
= WritePrivateProfileStringA("App", "", "string", path
);
962 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
965 ok(check_file_data(path
, data
), "File doesn't match\n");
972 ret
= WritePrivateProfileStringA("App", "key", NULL
, path
);
973 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
976 ok(check_file_data(path
, data
) ||
977 (broken(GetFileAttributesA(path
) == INVALID_FILE_ATTRIBUTES
)), /* Win9x and WinME */
978 "File doesn't match\n");
985 ret
= WritePrivateProfileStringA("App", "key", "", path
);
987 broken(!ret
), /* Win9x and WinME */
988 "Expected TRUE, got %d\n", ret
);
989 ok(check_file_data(path
, data
) ||
990 (broken(GetFileAttributesA(path
) == INVALID_FILE_ATTRIBUTES
)), /* Win9x and WinME */
991 "File doesn't match\n");
994 /* empty lpFileName */
995 SetLastError(0xdeadbeef);
996 ret
= WritePrivateProfileStringA("App", "key", "string", "");
997 ok(ret
== FALSE
, "Expected FALSE, got %d\n", ret
);
998 ok(GetLastError() == ERROR_ACCESS_DENIED
||
999 broken(GetLastError() == ERROR_PATH_NOT_FOUND
), /* Win9x and WinME */
1000 "Expected ERROR_ACCESS_DENIED, got %d\n", GetLastError());
1002 /* The resulting file will be X:\\%WINDIR%\\win1.tmp */
1003 GetWindowsDirectoryA(temp
, MAX_PATH
);
1004 GetTempFileNameA(temp
, "win", 1, path
);
1007 /* relative path in lpFileName */
1010 ret
= WritePrivateProfileStringA("App", "key", "string", "win1.tmp");
1011 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1012 ok(check_file_data(path
, data
), "File doesn't match\n");
1015 GetTempPathA(MAX_PATH
, temp
);
1016 GetTempFileNameA(temp
, "wine", 0, path
);
1018 /* build up an INI file */
1019 WritePrivateProfileStringA("App1", "key1", "string1", path
);
1020 WritePrivateProfileStringA("App1", "key2", "string2", path
);
1021 WritePrivateProfileStringA("App1", "key3", "string3", path
);
1022 WritePrivateProfileStringA("App2", "key4", "string4", path
);
1024 /* make an addition and verify the INI */
1033 ret
= WritePrivateProfileStringA("App3", "key5", "string5", path
);
1034 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1035 ok(check_file_data(path
, data
), "File doesn't match\n");
1037 /* lpString is NULL, key2 key is deleted */
1045 ret
= WritePrivateProfileStringA("App1", "key2", NULL
, path
);
1046 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1047 ok(check_file_data(path
, data
), "File doesn't match\n");
1049 /* try to delete key2 again */
1057 ret
= WritePrivateProfileStringA("App1", "key2", NULL
, path
);
1058 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1059 ok(check_file_data(path
, data
), "File doesn't match\n");
1061 /* lpKeyName is NULL, App1 section is deleted */
1066 ret
= WritePrivateProfileStringA("App1", NULL
, "string1", path
);
1067 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1068 ok(check_file_data(path
, data
), "File doesn't match\n");
1070 /* lpString is not needed to delete a section */
1073 ret
= WritePrivateProfileStringA("App2", NULL
, 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 /* leave just the section */
1078 data
= "[App3]\r\n";
1079 ret
= WritePrivateProfileStringA("App3", "key5", NULL
, path
);
1080 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1081 ok(check_file_data(path
, data
), "File doesn't match\n");
1084 /* NULLs in file before first section. Should be preserved in output */
1085 data
= "Data \0 before \0 first \0 section" /* 31 bytes */
1086 "\r\n[section1]\r\n" /* 14 bytes */
1087 "key1=string1\r\n"; /* 14 bytes */
1088 GetTempFileNameA(temp
, "wine", 0, path
);
1089 create_test_file(path
, data
, 31);
1090 ret
= WritePrivateProfileStringA("section1", "key1", "string1", path
);
1091 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1093 ok( check_binary_file_data(path
, data
, 59) ||
1094 broken( check_binary_file_data(path
, /* Windows 9x */
1095 "Data \0 before \0 first \0 section" /* 31 bytes */
1096 "\r\n\r\n[section1]\r\n" /* 14 bytes */
1097 "key1=string1" /* 14 bytes */
1098 , 59)), "File doesn't match\n");
1105 test_profile_string();
1106 test_profile_sections();
1107 test_profile_sections_names();
1108 test_profile_existing();
1109 test_profile_delete_on_close();
1110 test_profile_refresh();
1111 test_GetPrivateProfileString(
1114 "name2=\"val2\"\r\n"
1119 test_GetPrivateProfileString(
1127 test_WritePrivateProfileString();