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)
100 /* test that lines without an '=' will not be enumerated */
101 /* in the case below, name2 is a key while name3 is not. */
102 char content
[]="[s]\r\nname1=val1\r\nname2=\r\nname3\r\nname4=val4\r\n";
103 DeleteFileA( TESTFILE2
);
104 h
= CreateFileA( TESTFILE2
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
105 FILE_ATTRIBUTE_NORMAL
, NULL
);
106 ok( h
!= INVALID_HANDLE_VALUE
, " cannot create %s\n", TESTFILE2
);
107 if( h
== INVALID_HANDLE_VALUE
) return;
108 WriteFile( h
, content
, sizeof(content
), &count
, NULL
);
111 /* enumerate the keys */
112 ret
=GetPrivateProfileStringA( "s", NULL
, "", buf
, sizeof(buf
),
114 for( p
= buf
+ strlen(buf
) + 1; *p
;p
+= strlen(p
)+1)
117 ok( ret
== 18 && !strcmp( buf
, "name1,name2,name4"), "wrong keys returned(%d): %s\n", ret
,
120 /* add a new key to test that the file is quite usable */
121 WritePrivateProfileStringA( "s", "name5", "val5", TESTFILE2
);
122 ret
=GetPrivateProfileStringA( "s", NULL
, "", buf
, sizeof(buf
),
124 for( p
= buf
+ strlen(buf
) + 1; *p
;p
+= strlen(p
)+1)
126 ok( ret
== 24 && !strcmp( buf
, "name1,name2,name4,name5"), "wrong keys returned(%d): %s\n",
129 DeleteFileA( TESTFILE2
);
132 static void test_profile_sections(void)
139 static const char content
[]="[section1]\r\nname1=val1\r\nname2=\r\nname3\r\nname4=val4\r\n[section2]\r\n";
140 static const char testfile4
[]=".\\testwine4.ini";
141 BOOL on_win98
= FALSE
;
143 DeleteFileA( testfile4
);
144 h
= CreateFileA( testfile4
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
145 ok( h
!= INVALID_HANDLE_VALUE
, " cannot create %s\n", testfile4
);
146 if( h
== INVALID_HANDLE_VALUE
) return;
147 WriteFile( h
, content
, sizeof(content
), &count
, NULL
);
150 /* Some parameter checking */
151 SetLastError(0xdeadbeef);
152 ret
= GetPrivateProfileSectionA( NULL
, NULL
, 0, NULL
);
153 ok( ret
== 0, "expected return size 0, got %d\n", ret
);
154 ok( GetLastError() == ERROR_INVALID_PARAMETER
||
155 GetLastError() == 0xdeadbeef /* Win98 */,
156 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
157 if (GetLastError() == 0xdeadbeef) on_win98
= TRUE
;
159 SetLastError(0xdeadbeef);
160 ret
= GetPrivateProfileSectionA( NULL
, NULL
, 0, testfile4
);
161 ok( ret
== 0, "expected return size 0, got %d\n", ret
);
162 ok( GetLastError() == ERROR_INVALID_PARAMETER
||
163 GetLastError() == 0xdeadbeef /* Win98 */,
164 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
168 SetLastError(0xdeadbeef);
169 ret
= GetPrivateProfileSectionA( "section1", NULL
, 0, testfile4
);
170 ok( ret
== 0, "expected return size 0, got %d\n", ret
);
171 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
174 SetLastError(0xdeadbeef);
175 ret
= GetPrivateProfileSectionA( NULL
, buf
, sizeof(buf
), testfile4
);
176 ok( ret
== 0, "expected return size 0, got %d\n", ret
);
177 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
179 SetLastError(0xdeadbeef);
180 ret
= GetPrivateProfileSectionA( "section1", buf
, sizeof(buf
), NULL
);
181 ok( ret
== 0, "expected return size 0, got %d\n", ret
);
183 ok( GetLastError() == ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
186 SetLastError(0xdeadbeef);
187 ret
=GetPrivateProfileSectionA("section1", buf
, sizeof(buf
), testfile4
);
188 for( p
= buf
+ strlen(buf
) + 1; *p
;p
+= strlen(p
)+1)
190 ok( ret
== 35 && !strcmp( buf
, "name1=val1,name2=,name3,name4=val4"), "wrong section returned(%d): %s\n",
192 ok( buf
[ret
-1] == 0 && buf
[ret
] == 0, "returned buffer not terminated with double-null\n" );
193 ok( GetLastError() == ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", GetLastError());
195 DeleteFileA( testfile4
);
198 static void test_profile_sections_names(void)
205 static const char content
[]="[section1]\r\n[section2]\r\n[section3]\r\n";
206 static const char testfile3
[]=".\\testwine3.ini";
207 static const WCHAR testfile3W
[]={ '.','\\','t','e','s','t','w','i','n','e','3','.','i','n','i',0 };
208 static const WCHAR not_here
[] = {'.','\\','n','o','t','_','h','e','r','e','.','i','n','i',0};
209 DeleteFileA( testfile3
);
210 h
= CreateFileA( testfile3
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
211 FILE_ATTRIBUTE_NORMAL
, NULL
);
212 ok( h
!= INVALID_HANDLE_VALUE
, " cannot create %s\n", testfile3
);
213 if( h
== INVALID_HANDLE_VALUE
) return;
214 WriteFile( h
, content
, sizeof(content
), &count
, NULL
);
217 /* Test with sufficiently large buffer */
218 ret
= GetPrivateProfileSectionNamesA( buf
, 29, testfile3
);
219 ok( ret
== 27, "expected return size 27, got %d\n", ret
);
220 ok( buf
[ret
-1] == 0 && buf
[ret
] == 0, "returned buffer not terminated with double-null\n" );
222 /* Test with exactly fitting buffer */
223 ret
= GetPrivateProfileSectionNamesA( buf
, 28, testfile3
);
224 ok( ret
== 26, "expected return size 26, got %d\n", ret
);
225 ok( buf
[ret
+1] == 0 && buf
[ret
] == 0, "returned buffer not terminated with double-null\n" );
227 /* Test with a buffer too small */
228 ret
= GetPrivateProfileSectionNamesA( buf
, 27, testfile3
);
229 ok( ret
== 25, "expected return size 25, got %d\n", ret
);
230 ok( buf
[ret
+1] == 0 && buf
[ret
] == 0, "returned buffer not terminated with double-null\n" );
232 /* Tests on nonexistent file */
233 memset(buf
, 0xcc, sizeof(buf
));
234 ret
= GetPrivateProfileSectionNamesA( buf
, 10, ".\\not_here.ini" );
235 ok( ret
== 0, "expected return size 0, got %d\n", ret
);
236 ok( buf
[0] == 0, "returned buffer not terminated with null\n" );
237 ok( buf
[1] != 0, "returned buffer terminated with double-null\n" );
239 /* Test with sufficiently large buffer */
240 SetLastError(0xdeadbeef);
241 ret
= GetPrivateProfileSectionNamesW( bufW
, 29, testfile3W
);
242 if (ret
== 0 && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
))
244 skip("GetPrivateProfileSectionNamesW is not implemented\n");
245 DeleteFileA( testfile3
);
248 ok( ret
== 27, "expected return size 27, got %d\n", ret
);
249 ok( bufW
[ret
-1] == 0 && bufW
[ret
] == 0, "returned buffer not terminated with double-null\n" );
251 /* Test with exactly fitting buffer */
252 ret
= GetPrivateProfileSectionNamesW( bufW
, 28, testfile3W
);
253 ok( ret
== 26, "expected return size 26, got %d\n", ret
);
254 ok( bufW
[ret
+1] == 0 && bufW
[ret
] == 0, "returned buffer not terminated with double-null\n" );
256 /* Test with a buffer too small */
257 ret
= GetPrivateProfileSectionNamesW( bufW
, 27, testfile3W
);
258 ok( ret
== 25, "expected return size 25, got %d\n", ret
);
259 ok( bufW
[ret
+1] == 0 && bufW
[ret
] == 0, "returned buffer not terminated with double-null\n" );
261 DeleteFileA( testfile3
);
263 /* Tests on nonexistent file */
264 memset(bufW
, 0xcc, sizeof(bufW
));
265 ret
= GetPrivateProfileSectionNamesW( bufW
, 10, not_here
);
266 ok( ret
== 0, "expected return size 0, got %d\n", ret
);
267 ok( bufW
[0] == 0, "returned buffer not terminated with null\n" );
268 ok( bufW
[1] != 0, "returned buffer terminated with double-null\n" );
271 /* If the ini-file has already been opened with CreateFile, WritePrivateProfileString failed in wine with an error ERROR_SHARING_VIOLATION, some testing here */
272 static void test_profile_existing(void)
274 static const char *testfile1
= ".\\winesharing1.ini";
275 static const char *testfile2
= ".\\winesharing2.ini";
277 static const struct {
278 DWORD dwDesiredAccess
;
283 {GENERIC_READ
, FILE_SHARE_READ
, ERROR_SHARING_VIOLATION
, FALSE
},
284 {GENERIC_READ
, FILE_SHARE_WRITE
, ERROR_SHARING_VIOLATION
, TRUE
},
285 {GENERIC_WRITE
, FILE_SHARE_READ
, ERROR_SHARING_VIOLATION
, FALSE
},
286 {GENERIC_WRITE
, FILE_SHARE_WRITE
, ERROR_SHARING_VIOLATION
, TRUE
},
287 {GENERIC_READ
|GENERIC_WRITE
, FILE_SHARE_READ
, ERROR_SHARING_VIOLATION
, FALSE
},
288 {GENERIC_READ
|GENERIC_WRITE
, FILE_SHARE_WRITE
, ERROR_SHARING_VIOLATION
, TRUE
},
289 {GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, 0, FALSE
},
290 {GENERIC_WRITE
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, 0, FALSE
},
291 /*Thief demo (bug 5024) opens .ini file like this*/
292 {GENERIC_READ
|GENERIC_WRITE
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, 0, FALSE
}
299 char buffer
[MAX_PATH
];
301 for (i
=0; i
< sizeof(pe
)/sizeof(pe
[0]); i
++)
303 h
= CreateFile(testfile1
, pe
[i
].dwDesiredAccess
, pe
[i
].dwShareMode
, NULL
,
304 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
305 ok(INVALID_HANDLE_VALUE
!= h
, "%d: CreateFile failed\n",i
);
306 SetLastError(0xdeadbeef);
308 ret
= WritePrivateProfileString(SECTION
, KEY
, "12345", testfile1
);
309 if (!pe
[i
].write_error
)
311 ok( ret
, "%d: WritePrivateProfileString failed with error %u\n", i
, GetLastError() );
313 size
= GetPrivateProfileString(SECTION
, KEY
, 0, buffer
, MAX_PATH
, testfile1
);
314 ok( size
== 5, "%d: test failed, number of characters copied: %d instead of 5\n", i
, size
);
318 DWORD err
= GetLastError();
319 ok( !ret
, "%d: WritePrivateProfileString succeeded\n", i
);
321 ok( err
== pe
[i
].write_error
, "%d: WritePrivateProfileString failed with error %u/%u\n",
322 i
, err
, pe
[i
].write_error
);
324 size
= GetPrivateProfileString(SECTION
, KEY
, 0, buffer
, MAX_PATH
, testfile1
);
325 ok( !size
, "%d: test failed, number of characters copied: %d instead of 0\n", i
, size
);
328 ok( DeleteFile(testfile1
), "delete failed\n" );
331 h
= CreateFile(testfile2
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
332 sprintf( buffer
, "[%s]\r\n%s=123\r\n", SECTION
, KEY
);
333 ok( WriteFile( h
, buffer
, strlen(buffer
), &size
, NULL
), "failed to write\n" );
336 for (i
=0; i
< sizeof(pe
)/sizeof(pe
[0]); i
++)
338 h
= CreateFile(testfile2
, pe
[i
].dwDesiredAccess
, pe
[i
].dwShareMode
, NULL
,
339 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
340 ok(INVALID_HANDLE_VALUE
!= h
, "%d: CreateFile failed\n",i
);
341 SetLastError(0xdeadbeef);
342 ret
= GetPrivateProfileStringA(SECTION
, KEY
, NULL
, buffer
, MAX_PATH
, testfile2
);
343 if (!pe
[i
].read_error
)
344 ok( ret
, "%d: GetPrivateProfileString failed with error %u\n", i
, GetLastError() );
346 ok( !ret
, "%d: GetPrivateProfileString succeeded\n", i
);
349 ok( DeleteFile(testfile2
), "delete failed\n" );
352 static void test_profile_delete_on_close()
354 static CHAR testfile
[] = ".\\testwine5.ini";
357 static const char contents
[] = "[" SECTION
"]\n" KEY
"=123\n";
359 h
= CreateFile(testfile
, GENERIC_WRITE
, FILE_SHARE_READ
, NULL
,
360 CREATE_ALWAYS
, FILE_FLAG_DELETE_ON_CLOSE
, NULL
);
361 ok( WriteFile( h
, contents
, sizeof contents
- 1, &size
, NULL
),
362 "Cannot write test file: %x\n", GetLastError() );
363 ok( size
== sizeof contents
- 1, "Test file: partial write\n");
365 res
= GetPrivateProfileInt(SECTION
, KEY
, 0, testfile
);
366 ok( res
== 123, "Got %d instead of 123\n", res
);
368 /* This also deletes the file */
372 static void test_profile_refresh(void)
374 static CHAR testfile
[] = ".\\winetest4.ini";
377 static const char contents1
[] = "[" SECTION
"]\n" KEY
"=123\n";
378 static const char contents2
[] = "[" SECTION
"]\n" KEY
"=124\n";
380 h
= CreateFile(testfile
, GENERIC_WRITE
, FILE_SHARE_READ
, NULL
,
381 CREATE_ALWAYS
, FILE_FLAG_DELETE_ON_CLOSE
, NULL
);
382 ok( WriteFile( h
, contents1
, sizeof contents1
- 1, &size
, NULL
),
383 "Cannot write test file: %x\n", GetLastError() );
384 ok( size
== sizeof contents1
- 1, "Test file: partial write\n");
386 res
= GetPrivateProfileInt(SECTION
, KEY
, 0, testfile
);
387 ok( res
== 123, "Got %d instead of 123\n", res
);
391 /* Test proper invalidation of wine's profile file cache */
393 h
= CreateFile(testfile
, GENERIC_WRITE
, FILE_SHARE_READ
, NULL
,
394 CREATE_ALWAYS
, FILE_FLAG_DELETE_ON_CLOSE
, NULL
);
395 ok( WriteFile( h
, contents2
, sizeof contents2
- 1, &size
, NULL
),
396 "Cannot write test file: %x\n", GetLastError() );
397 ok( size
== sizeof contents2
- 1, "Test file: partial write\n");
399 res
= GetPrivateProfileInt(SECTION
, KEY
, 0, testfile
);
400 ok( res
== 124, "Got %d instead of 124\n", res
);
402 /* This also deletes the file */
406 static void create_test_file(LPCSTR name
, LPCSTR data
, DWORD size
)
411 hfile
= CreateFileA(name
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
412 ok(hfile
!= INVALID_HANDLE_VALUE
, "cannot create %s\n", name
);
413 WriteFile(hfile
, data
, size
, &count
, NULL
);
417 static BOOL
emptystr_ok(CHAR emptystr
[MAX_PATH
])
421 for(i
= 0;i
< MAX_PATH
;++i
)
424 trace("emptystr[%d] = %d\n",i
,emptystr
[i
]);
431 static void test_GetPrivateProfileString(void)
435 CHAR def_val
[MAX_PATH
];
437 CHAR windir
[MAX_PATH
];
438 /* NT series crashes on r/o empty strings, so pass an r/w
439 empty string and check for modification */
440 CHAR emptystr
[MAX_PATH
] = "";
443 static const char filename
[] = ".\\winetest.ini";
444 static const char content
[]=
452 create_test_file(filename
, content
, sizeof(content
));
454 /* Run this test series with caching. Wine won't cache profile
455 files younger than 2.1 seconds. */
458 /* lpAppName is NULL */
459 lstrcpyA(buf
, "kumquat");
460 ret
= GetPrivateProfileStringA(NULL
, "name1", "default",
461 buf
, MAX_PATH
, filename
);
462 ok(ret
== 18, "Expected 18, got %d\n", ret
);
463 ok(!memcmp(buf
, "section1\0section2\0", ret
+ 1),
464 "Expected \"section1\\0section2\\0\", got \"%s\"\n", buf
);
466 /* lpAppName is empty */
467 lstrcpyA(buf
, "kumquat");
468 ret
= GetPrivateProfileStringA(emptystr
, "name1", "default",
469 buf
, MAX_PATH
, filename
);
470 ok(ret
== 7, "Expected 7, got %d\n", ret
);
471 ok(!lstrcmpA(buf
, "default"), "Expected \"default\", got \"%s\"\n", buf
);
472 ok(emptystr_ok(emptystr
), "AppName modified\n");
474 /* lpAppName is missing */
475 lstrcpyA(buf
, "kumquat");
476 ret
= GetPrivateProfileStringA("notasection", "name1", "default",
477 buf
, MAX_PATH
, filename
);
478 ok(ret
== 7, "Expected 7, got %d\n", ret
);
479 ok(!lstrcmpA(buf
, "default"), "Expected \"default\", got \"%s\"\n", buf
);
481 /* lpAppName is empty, lpDefault is NULL */
482 lstrcpyA(buf
, "kumquat");
483 ret
= GetPrivateProfileStringA(emptystr
, "name1", NULL
,
484 buf
, MAX_PATH
, filename
);
485 ok(ret
== 0, "Expected 0, got %d\n", ret
);
486 ok(!lstrcmpA(buf
, ""), "Expected \"\", got \"%s\"\n", buf
);
487 ok(emptystr_ok(emptystr
), "AppName modified\n");
489 /* lpAppName is empty, lpDefault is empty */
490 lstrcpyA(buf
, "kumquat");
491 ret
= GetPrivateProfileStringA(emptystr
, "name1", "",
492 buf
, MAX_PATH
, filename
);
493 ok(ret
== 0, "Expected 0, got %d\n", ret
);
494 ok(!lstrcmpA(buf
, ""), "Expected \"\", got \"%s\"\n", buf
);
495 ok(emptystr_ok(emptystr
), "AppName modified\n");
497 /* lpAppName is empty, lpDefault has trailing blank characters */
498 lstrcpyA(buf
, "kumquat");
499 /* lpDefault must be writable (trailing blanks are removed inplace in win9x) */
500 lstrcpyA(def_val
, "default ");
501 ret
= GetPrivateProfileStringA(emptystr
, "name1", def_val
,
502 buf
, MAX_PATH
, filename
);
503 ok(ret
== 7, "Expected 7, got %d\n", ret
);
504 ok(!lstrcmpA(buf
, "default"), "Expected \"default\", got \"%s\"\n", buf
);
505 ok(emptystr_ok(emptystr
), "AppName modified\n");
507 /* lpAppName is empty, many blank characters in lpDefault */
508 lstrcpyA(buf
, "kumquat");
509 /* lpDefault must be writable (trailing blanks are removed inplace in win9x) */
510 lstrcpyA(def_val
, "one two ");
511 ret
= GetPrivateProfileStringA(emptystr
, "name1", def_val
,
512 buf
, MAX_PATH
, filename
);
513 ok(ret
== 7, "Expected 7, got %d\n", ret
);
514 ok(!lstrcmpA(buf
, "one two"), "Expected \"one two\", got \"%s\"\n", buf
);
515 ok(emptystr_ok(emptystr
), "AppName modified\n");
517 /* lpAppName is empty, blank character but not trailing in lpDefault */
518 lstrcpyA(buf
, "kumquat");
519 ret
= GetPrivateProfileStringA(emptystr
, "name1", "one two",
520 buf
, MAX_PATH
, filename
);
521 ok(ret
== 7, "Expected 7, got %d\n", ret
);
522 ok(!lstrcmpA(buf
, "one two"), "Expected \"one two\", got \"%s\"\n", buf
);
523 ok(emptystr_ok(emptystr
), "AppName modified\n");
525 /* lpKeyName is NULL */
526 lstrcpyA(buf
, "kumquat");
527 ret
= GetPrivateProfileStringA("section1", NULL
, "default",
528 buf
, MAX_PATH
, filename
);
529 ok(ret
== 18, "Expected 18, got %d\n", ret
);
530 ok(!memcmp(buf
, "name1\0name2\0name4\0", ret
+ 1),
531 "Expected \"name1\\0name2\\0name4\\0\", got \"%s\"\n", buf
);
533 /* lpKeyName is empty */
534 lstrcpyA(buf
, "kumquat");
535 ret
= GetPrivateProfileStringA("section1", emptystr
, "default",
536 buf
, MAX_PATH
, filename
);
537 ok(ret
== 7, "Expected 7, got %d\n", ret
);
538 ok(!lstrcmpA(buf
, "default"), "Expected \"default\", got \"%s\"\n", buf
);
539 ok(emptystr_ok(emptystr
), "KeyName modified\n");
541 /* lpKeyName is missing */
542 lstrcpyA(buf
, "kumquat");
543 ret
= GetPrivateProfileStringA("section1", "notakey", "default",
544 buf
, MAX_PATH
, filename
);
545 ok(ret
== 7, "Expected 7, got %d\n", ret
);
546 ok(!lstrcmpA(buf
, "default"), "Expected \"default\", got \"%s\"\n", buf
);
548 /* lpKeyName is empty, lpDefault is NULL */
549 lstrcpyA(buf
, "kumquat");
550 ret
= GetPrivateProfileStringA("section1", emptystr
, NULL
,
551 buf
, MAX_PATH
, filename
);
552 ok(ret
== 0, "Expected 0, got %d\n", ret
);
553 ok(!lstrcmpA(buf
, ""), "Expected \"\", got \"%s\"\n", buf
);
554 ok(emptystr_ok(emptystr
), "KeyName modified\n");
556 /* lpKeyName is empty, lpDefault is empty */
557 lstrcpyA(buf
, "kumquat");
558 ret
= GetPrivateProfileStringA("section1", emptystr
, "",
559 buf
, MAX_PATH
, filename
);
560 ok(ret
== 0, "Expected 0, got %d\n", ret
);
561 ok(!lstrcmpA(buf
, ""), "Expected \"\", got \"%s\"\n", buf
);
562 ok(emptystr_ok(emptystr
), "KeyName modified\n");
564 /* lpKeyName is empty, lpDefault has trailing blank characters */
565 lstrcpyA(buf
, "kumquat");
566 /* lpDefault must be writable (trailing blanks are removed inplace in win9x) */
567 lstrcpyA(def_val
, "default ");
568 ret
= GetPrivateProfileStringA("section1", emptystr
, def_val
,
569 buf
, MAX_PATH
, filename
);
570 ok(ret
== 7, "Expected 7, got %d\n", ret
);
571 ok(!lstrcmpA(buf
, "default"), "Expected \"default\", got \"%s\"\n", buf
);
572 ok(emptystr_ok(emptystr
), "KeyName modified\n");
576 /* lpReturnedString is NULL */
577 ret
= GetPrivateProfileStringA("section1", "name1", "default",
578 NULL
, MAX_PATH
, filename
);
581 /* lpFileName is NULL */
582 lstrcpyA(buf
, "kumquat");
583 ret
= GetPrivateProfileStringA("section1", "name1", "default",
584 buf
, MAX_PATH
, NULL
);
585 ok(ret
== 7, "Expected 7, got %d\n", ret
);
586 ok(!lstrcmpA(buf
, "default"), "Expected \"default\", got \"%s\"\n", buf
);
588 /* lpFileName is empty */
589 lstrcpyA(buf
, "kumquat");
590 ret
= GetPrivateProfileStringA("section1", "name1", "default",
592 ok(ret
== 7, "Expected 7, got %d\n", ret
);
593 ok(!lstrcmpA(buf
, "default"), "Expected \"default\", got \"%s\"\n", buf
);
595 /* lpFileName is nonexistent */
596 lstrcpyA(buf
, "kumquat");
597 ret
= GetPrivateProfileStringA("section1", "name1", "default",
598 buf
, MAX_PATH
, "nonexistent");
599 ok(ret
== 7, "Expected 7, got %d\n", ret
);
600 ok(!lstrcmpA(buf
, "default"), "Expected \"default\", got \"%s\"\n", buf
);
603 lstrcpyA(buf
, "kumquat");
604 ret
= GetPrivateProfileStringA("section1", "name1", "default",
606 ok(ret
== 0, "Expected 0, got %d\n", ret
);
607 ok(!lstrcmpA(buf
, "kumquat"), "Expected buf to be unchanged, got \"%s\"\n", buf
);
609 /* nSize is exact size of output */
610 lstrcpyA(buf
, "kumquat");
611 ret
= GetPrivateProfileStringA("section1", "name1", "default",
613 ok(ret
== 3, "Expected 3, got %d\n", ret
);
614 ok(!lstrcmpA(buf
, "val"), "Expected \"val\", got \"%s\"\n", buf
);
616 /* nSize has room for NULL terminator */
617 lstrcpyA(buf
, "kumquat");
618 ret
= GetPrivateProfileStringA("section1", "name1", "default",
620 ok(ret
== 4, "Expected 4, got %d\n", ret
);
621 ok(!lstrcmpA(buf
, "val1"), "Expected \"val1\", got \"%s\"\n", buf
);
623 /* output is 1 character */
624 lstrcpyA(buf
, "kumquat");
625 ret
= GetPrivateProfileStringA("section1", "name4", "default",
626 buf
, MAX_PATH
, filename
);
627 ok(ret
== 1, "Expected 1, got %d\n", ret
);
628 ok(!lstrcmpA(buf
, "a"), "Expected \"a\", got \"%s\"\n", buf
);
630 /* output is 1 character, no room for NULL terminator */
631 lstrcpyA(buf
, "kumquat");
632 ret
= GetPrivateProfileStringA("section1", "name4", "default",
634 ok(ret
== 0, "Expected 0, got %d\n", ret
);
635 ok(!lstrcmpA(buf
, ""), "Expected \"\", got \"%s\"\n", buf
);
637 /* lpAppName is NULL, not enough room for final section name */
638 lstrcpyA(buf
, "kumquat");
639 ret
= GetPrivateProfileStringA(NULL
, "name1", "default",
641 ok(ret
== 14, "Expected 14, got %d\n", ret
);
642 ok(!memcmp(buf
, "section1\0secti\0", ret
+ 1),
643 "Expected \"section1\\0secti\\0\", got \"%s\"\n", buf
);
645 /* lpKeyName is NULL, not enough room for final key name */
646 lstrcpyA(buf
, "kumquat");
647 ret
= GetPrivateProfileStringA("section1", NULL
, "default",
649 ok(ret
== 14, "Expected 14, got %d\n", ret
);
650 ok(!memcmp(buf
, "name1\0name2\0na\0", ret
+ 1),
651 "Expected \"name1\\0name2\\0na\\0\", got \"%s\"\n", buf
);
653 /* key value has quotation marks which are stripped */
654 lstrcpyA(buf
, "kumquat");
655 ret
= GetPrivateProfileStringA("section1", "name2", "default",
656 buf
, MAX_PATH
, filename
);
657 ok(ret
== 4, "Expected 4, got %d\n", ret
);
658 ok(!lstrcmpA(buf
, "val2"), "Expected \"val2\", got \"%s\"\n", buf
);
660 /* case does not match */
661 lstrcpyA(buf
, "kumquat");
662 ret
= GetPrivateProfileStringA("section1", "NaMe1", "default",
663 buf
, MAX_PATH
, filename
);
664 ok(ret
== 4, "Expected 4, got %d\n", ret
);
665 ok(!lstrcmpA(buf
, "val1"), "Expected \"val1\", got \"%s\"\n", buf
);
667 /* only filename is used */
668 lstrcpyA(buf
, "kumquat");
669 ret
= GetPrivateProfileStringA("section1", "NaMe1", "default",
670 buf
, MAX_PATH
, "winetest.ini");
671 ok(ret
== 7, "Expected 7, got %d\n", ret
);
672 ok(!lstrcmpA(buf
, "default"), "Expected \"default\", got \"%s\"\n", buf
);
674 GetWindowsDirectoryA(windir
, MAX_PATH
);
675 GetTempFileNameA(windir
, "pre", 0, path
);
676 tempfile
= strrchr(path
, '\\') + 1;
677 create_test_file(path
, content
, sizeof(content
));
679 /* only filename is used, file exists in windows directory */
680 lstrcpyA(buf
, "kumquat");
681 ret
= GetPrivateProfileStringA("section1", "NaMe1", "default",
682 buf
, MAX_PATH
, tempfile
);
683 ok(ret
== 4, "Expected 4, got %d\n", ret
);
684 ok(!lstrcmpA(buf
, "val1"), "Expected \"val1\", got \"%s\"\n", buf
);
686 /* successful case */
687 lstrcpyA(buf
, "kumquat");
688 ret
= GetPrivateProfileStringA("section1", "name1", "default",
689 buf
, MAX_PATH
, filename
);
690 ok(ret
== 4, "Expected 4, got %d\n", ret
);
691 ok(!lstrcmpA(buf
, "val1"), "Expected \"val1\", got \"%s\"\n", buf
);
694 DeleteFileA(filename
);
700 test_profile_string();
701 test_profile_sections();
702 test_profile_sections_names();
703 test_profile_existing();
704 test_profile_delete_on_close();
705 test_profile_refresh();
706 test_GetPrivateProfileString();