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 ret
=GetPrivateProfileSectionA("section1", buf
, sizeof(buf
), testfile4
);
187 for( p
= buf
+ strlen(buf
) + 1; *p
;p
+= strlen(p
)+1)
189 ok( ret
== 35 && !strcmp( buf
, "name1=val1,name2=,name3,name4=val4"), "wrong section returned(%d): %s\n",
191 ok( buf
[ret
-1] == 0 && buf
[ret
] == 0, "returned buffer not terminated with double-null\n" );
192 ok( GetLastError() == S_OK
, "expected S_OK, got %d\n", GetLastError());
194 DeleteFileA( testfile4
);
197 static void test_profile_sections_names(void)
204 static const char content
[]="[section1]\r\n[section2]\r\n[section3]\r\n";
205 static const char testfile3
[]=".\\testwine3.ini";
206 static const WCHAR testfile3W
[]={ '.','\\','t','e','s','t','w','i','n','e','3','.','i','n','i',0 };
207 static const WCHAR not_here
[] = {'.','\\','n','o','t','_','h','e','r','e','.','i','n','i',0};
208 DeleteFileA( testfile3
);
209 h
= CreateFileA( testfile3
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
210 FILE_ATTRIBUTE_NORMAL
, NULL
);
211 ok( h
!= INVALID_HANDLE_VALUE
, " cannot create %s\n", testfile3
);
212 if( h
== INVALID_HANDLE_VALUE
) return;
213 WriteFile( h
, content
, sizeof(content
), &count
, NULL
);
216 /* Test with sufficiently large buffer */
217 ret
= GetPrivateProfileSectionNamesA( buf
, 29, testfile3
);
218 ok( ret
== 27, "expected return size 27, got %d\n", ret
);
219 ok( buf
[ret
-1] == 0 && buf
[ret
] == 0, "returned buffer not terminated with double-null\n" );
221 /* Test with exactly fitting buffer */
222 ret
= GetPrivateProfileSectionNamesA( buf
, 28, testfile3
);
223 ok( ret
== 26, "expected return size 26, got %d\n", ret
);
224 ok( buf
[ret
+1] == 0 && buf
[ret
] == 0, "returned buffer not terminated with double-null\n" );
226 /* Test with a buffer too small */
227 ret
= GetPrivateProfileSectionNamesA( buf
, 27, testfile3
);
228 ok( ret
== 25, "expected return size 25, got %d\n", ret
);
229 ok( buf
[ret
+1] == 0 && buf
[ret
] == 0, "returned buffer not terminated with double-null\n" );
231 /* Tests on nonexistent file */
232 memset(buf
, 0xcc, sizeof(buf
));
233 ret
= GetPrivateProfileSectionNamesA( buf
, 10, ".\\not_here.ini" );
234 ok( ret
== 0, "expected return size 0, got %d\n", ret
);
235 ok( buf
[0] == 0, "returned buffer not terminated with null\n" );
236 ok( buf
[1] != 0, "returned buffer terminated with double-null\n" );
238 /* Test with sufficiently large buffer */
239 SetLastError(0xdeadbeef);
240 ret
= GetPrivateProfileSectionNamesW( bufW
, 29, testfile3W
);
241 if (ret
== 0 && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
))
243 skip("GetPrivateProfileSectionNamesW is not implemented\n");
244 DeleteFileA( testfile3
);
247 ok( ret
== 27, "expected return size 27, got %d\n", ret
);
248 ok( bufW
[ret
-1] == 0 && bufW
[ret
] == 0, "returned buffer not terminated with double-null\n" );
250 /* Test with exactly fitting buffer */
251 ret
= GetPrivateProfileSectionNamesW( bufW
, 28, testfile3W
);
252 ok( ret
== 26, "expected return size 26, got %d\n", ret
);
253 ok( bufW
[ret
+1] == 0 && bufW
[ret
] == 0, "returned buffer not terminated with double-null\n" );
255 /* Test with a buffer too small */
256 ret
= GetPrivateProfileSectionNamesW( bufW
, 27, testfile3W
);
257 ok( ret
== 25, "expected return size 25, got %d\n", ret
);
258 ok( bufW
[ret
+1] == 0 && bufW
[ret
] == 0, "returned buffer not terminated with double-null\n" );
260 DeleteFileA( testfile3
);
262 /* Tests on nonexistent file */
263 memset(bufW
, 0xcc, sizeof(bufW
));
264 ret
= GetPrivateProfileSectionNamesW( bufW
, 10, not_here
);
265 ok( ret
== 0, "expected return size 0, got %d\n", ret
);
266 ok( bufW
[0] == 0, "returned buffer not terminated with null\n" );
267 ok( bufW
[1] != 0, "returned buffer terminated with double-null\n" );
270 /* If the ini-file has already been opened with CreateFile, WritePrivateProfileString failed in wine with an error ERROR_SHARING_VIOLATION, some testing here */
271 static void test_profile_existing(void)
273 static const char *testfile1
= ".\\winesharing1.ini";
274 static const char *testfile2
= ".\\winesharing2.ini";
276 static const struct {
277 DWORD dwDesiredAccess
;
282 {GENERIC_READ
, FILE_SHARE_READ
, ERROR_SHARING_VIOLATION
, FALSE
},
283 {GENERIC_READ
, FILE_SHARE_WRITE
, ERROR_SHARING_VIOLATION
, TRUE
},
284 {GENERIC_WRITE
, FILE_SHARE_READ
, ERROR_SHARING_VIOLATION
, FALSE
},
285 {GENERIC_WRITE
, FILE_SHARE_WRITE
, ERROR_SHARING_VIOLATION
, TRUE
},
286 {GENERIC_READ
|GENERIC_WRITE
, FILE_SHARE_READ
, ERROR_SHARING_VIOLATION
, FALSE
},
287 {GENERIC_READ
|GENERIC_WRITE
, FILE_SHARE_WRITE
, ERROR_SHARING_VIOLATION
, TRUE
},
288 {GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, 0, FALSE
},
289 {GENERIC_WRITE
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, 0, FALSE
},
290 /*Thief demo (bug 5024) opens .ini file like this*/
291 {GENERIC_READ
|GENERIC_WRITE
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, 0, FALSE
}
298 char buffer
[MAX_PATH
];
300 for (i
=0; i
< sizeof(pe
)/sizeof(pe
[0]); i
++)
302 h
= CreateFile(testfile1
, pe
[i
].dwDesiredAccess
, pe
[i
].dwShareMode
, NULL
,
303 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
304 ok(INVALID_HANDLE_VALUE
!= h
, "%d: CreateFile failed\n",i
);
305 SetLastError(0xdeadbeef);
307 ret
= WritePrivateProfileString(SECTION
, KEY
, "12345", testfile1
);
308 if (!pe
[i
].write_error
)
310 ok( ret
, "%d: WritePrivateProfileString failed with error %u\n", i
, GetLastError() );
312 size
= GetPrivateProfileString(SECTION
, KEY
, 0, buffer
, MAX_PATH
, testfile1
);
313 ok( size
== 5, "%d: test failed, number of characters copied: %d instead of 5\n", i
, size
);
317 DWORD err
= GetLastError();
318 ok( !ret
, "%d: WritePrivateProfileString succeeded\n", i
);
320 ok( err
== pe
[i
].write_error
, "%d: WritePrivateProfileString failed with error %u/%u\n",
321 i
, err
, pe
[i
].write_error
);
323 size
= GetPrivateProfileString(SECTION
, KEY
, 0, buffer
, MAX_PATH
, testfile1
);
324 ok( !size
, "%d: test failed, number of characters copied: %d instead of 0\n", i
, size
);
327 ok( DeleteFile(testfile1
), "delete failed\n" );
330 h
= CreateFile(testfile2
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
331 sprintf( buffer
, "[%s]\r\n%s=123\r\n", SECTION
, KEY
);
332 ok( WriteFile( h
, buffer
, strlen(buffer
), &size
, NULL
), "failed to write\n" );
335 for (i
=0; i
< sizeof(pe
)/sizeof(pe
[0]); i
++)
337 h
= CreateFile(testfile2
, pe
[i
].dwDesiredAccess
, pe
[i
].dwShareMode
, NULL
,
338 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
339 ok(INVALID_HANDLE_VALUE
!= h
, "%d: CreateFile failed\n",i
);
340 SetLastError(0xdeadbeef);
341 ret
= GetPrivateProfileStringA(SECTION
, KEY
, NULL
, buffer
, MAX_PATH
, testfile2
);
342 if (!pe
[i
].read_error
)
343 ok( ret
, "%d: GetPrivateProfileString failed with error %u\n", i
, GetLastError() );
345 ok( !ret
, "%d: GetPrivateProfileString succeeded\n", i
);
348 ok( DeleteFile(testfile2
), "delete failed\n" );
351 static void create_test_file(LPCSTR name
, LPCSTR data
, DWORD size
)
356 hfile
= CreateFileA(name
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
357 ok(hfile
!= INVALID_HANDLE_VALUE
, "cannot create %s\n", name
);
358 WriteFile(hfile
, data
, size
, &count
, NULL
);
362 static void test_GetPrivateProfileString(void)
367 CHAR windir
[MAX_PATH
];
370 static const char filename
[] = ".\\winetest.ini";
371 static const char content
[]=
379 create_test_file(filename
, content
, sizeof(content
));
381 /* lpAppName is NULL */
382 lstrcpyA(buf
, "kumquat");
383 ret
= GetPrivateProfileStringA(NULL
, "name1", "default",
384 buf
, MAX_PATH
, filename
);
385 ok(ret
== 18, "Expected 18, got %d\n", ret
);
386 ok(!memcmp(buf
, "section1\0section2\0", ret
+ 1),
387 "Expected \"section1\\0section2\\0\", got \"%s\"\n", buf
);
389 /* lpAppName is empty */
390 lstrcpyA(buf
, "kumquat");
391 ret
= GetPrivateProfileStringA("", "name1", "default",
392 buf
, MAX_PATH
, filename
);
393 ok(ret
== 7, "Expected 7, got %d\n", ret
);
394 ok(!lstrcmpA(buf
, "default"), "Expected \"default\", got \"%s\"\n", buf
);
396 /* lpAppName is missing */
397 lstrcpyA(buf
, "kumquat");
398 ret
= GetPrivateProfileStringA("notasection", "name1", "default",
399 buf
, MAX_PATH
, filename
);
400 ok(ret
== 7, "Expected 7, got %d\n", ret
);
401 ok(!lstrcmpA(buf
, "default"), "Expected \"default\", got \"%s\"\n", buf
);
403 /* lpAppName is empty, lpDefault is NULL */
404 lstrcpyA(buf
, "kumquat");
405 ret
= GetPrivateProfileStringA("", "name1", NULL
,
406 buf
, MAX_PATH
, filename
);
407 ok(ret
== 0, "Expected 0, got %d\n", ret
);
408 ok(!lstrcmpA(buf
, ""), "Expected \"\", got \"%s\"\n", buf
);
410 /* lpAppName is empty, lpDefault is empty */
411 lstrcpyA(buf
, "kumquat");
412 ret
= GetPrivateProfileStringA("", "name1", "",
413 buf
, MAX_PATH
, filename
);
414 ok(ret
== 0, "Expected 0, got %d\n", ret
);
415 ok(!lstrcmpA(buf
, ""), "Expected \"\", got \"%s\"\n", buf
);
417 /* lpAppName is empty, lpDefault has trailing blank characters */
418 lstrcpyA(buf
, "kumquat");
419 ret
= GetPrivateProfileStringA("", "name1", "default ",
420 buf
, MAX_PATH
, filename
);
421 ok(ret
== 7, "Expected 7, got %d\n", ret
);
422 ok(!lstrcmpA(buf
, "default"), "Expected \"default\", got \"%s\"\n", buf
);
424 /* lpAppName is empty, many blank characters in lpDefault */
425 lstrcpyA(buf
, "kumquat");
426 ret
= GetPrivateProfileStringA("", "name1", "one two ",
427 buf
, MAX_PATH
, filename
);
428 ok(ret
== 7, "Expected 7, got %d\n", ret
);
429 ok(!lstrcmpA(buf
, "one two"), "Expected \"one two\", got \"%s\"\n", buf
);
431 /* lpAppName is empty, blank character but not trailing in lpDefault */
432 lstrcpyA(buf
, "kumquat");
433 ret
= GetPrivateProfileStringA("", "name1", "one two",
434 buf
, MAX_PATH
, filename
);
435 ok(ret
== 7, "Expected 7, got %d\n", ret
);
436 ok(!lstrcmpA(buf
, "one two"), "Expected \"one two\", got \"%s\"\n", buf
);
438 /* lpKeyName is NULL */
439 lstrcpyA(buf
, "kumquat");
440 ret
= GetPrivateProfileStringA("section1", NULL
, "default",
441 buf
, MAX_PATH
, filename
);
442 ok(ret
== 18, "Expected 18, got %d\n", ret
);
443 ok(!memcmp(buf
, "name1\0name2\0name4\0", ret
+ 1),
444 "Expected \"name1\\0name2\\0name4\\0\", got \"%s\"\n", buf
);
446 /* lpKeyName is empty */
447 lstrcpyA(buf
, "kumquat");
448 ret
= GetPrivateProfileStringA("section1", "", "default",
449 buf
, MAX_PATH
, filename
);
452 ok(ret
== 7, "Expected 7, got %d\n", ret
);
453 ok(!lstrcmpA(buf
, "default"), "Expected \"default\", got \"%s\"\n", buf
);
456 /* lpKeyName is missing */
457 lstrcpyA(buf
, "kumquat");
458 ret
= GetPrivateProfileStringA("section1", "notakey", "default",
459 buf
, MAX_PATH
, filename
);
460 ok(ret
== 7, "Expected 7, got %d\n", ret
);
461 ok(!lstrcmpA(buf
, "default"), "Expected \"default\", got \"%s\"\n", buf
);
463 /* lpKeyName is empty, lpDefault is NULL */
464 lstrcpyA(buf
, "kumquat");
465 ret
= GetPrivateProfileStringA("section1", "", NULL
,
466 buf
, MAX_PATH
, filename
);
467 ok(ret
== 0, "Expected 0, got %d\n", ret
);
470 ok(!lstrcmpA(buf
, ""), "Expected \"\", got \"%s\"\n", buf
);
473 /* lpKeyName is empty, lpDefault is empty */
474 lstrcpyA(buf
, "kumquat");
475 ret
= GetPrivateProfileStringA("section1", "", "",
476 buf
, MAX_PATH
, filename
);
477 ok(ret
== 0, "Expected 0, got %d\n", ret
);
480 ok(!lstrcmpA(buf
, ""), "Expected \"\", got \"%s\"\n", buf
);
483 /* lpKeyName is empty, lpDefault has trailing blank characters */
484 lstrcpyA(buf
, "kumquat");
485 ret
= GetPrivateProfileStringA("section1", "", "default ",
486 buf
, MAX_PATH
, filename
);
489 ok(ret
== 7, "Expected 7, got %d\n", ret
);
490 ok(!lstrcmpA(buf
, "default"), "Expected \"default\", got \"%s\"\n", buf
);
495 /* lpReturnedString is NULL */
496 ret
= GetPrivateProfileStringA("section1", "name1", "default",
497 NULL
, MAX_PATH
, filename
);
500 /* lpFileName is NULL */
501 lstrcpyA(buf
, "kumquat");
502 ret
= GetPrivateProfileStringA("section1", "name1", "default",
503 buf
, MAX_PATH
, NULL
);
504 ok(ret
== 7, "Expected 7, got %d\n", ret
);
505 ok(!lstrcmpA(buf
, "default"), "Expected \"default\", got \"%s\"\n", buf
);
507 /* lpFileName is empty */
508 lstrcpyA(buf
, "kumquat");
509 ret
= GetPrivateProfileStringA("section1", "name1", "default",
511 ok(ret
== 7, "Expected 7, got %d\n", ret
);
512 ok(!lstrcmpA(buf
, "default"), "Expected \"default\", got \"%s\"\n", buf
);
514 /* lpFileName is nonexistent */
515 lstrcpyA(buf
, "kumquat");
516 ret
= GetPrivateProfileStringA("section1", "name1", "default",
517 buf
, MAX_PATH
, "nonexistent");
518 ok(ret
== 7, "Expected 7, got %d\n", ret
);
519 ok(!lstrcmpA(buf
, "default"), "Expected \"default\", got \"%s\"\n", buf
);
522 lstrcpyA(buf
, "kumquat");
523 ret
= GetPrivateProfileStringA("section1", "name1", "default",
525 ok(ret
== 0, "Expected 0, got %d\n", ret
);
526 ok(!lstrcmpA(buf
, "kumquat"), "Expected buf to be unchanged, got \"%s\"\n", buf
);
528 /* nSize is exact size of output */
529 lstrcpyA(buf
, "kumquat");
530 ret
= GetPrivateProfileStringA("section1", "name1", "default",
532 ok(ret
== 3, "Expected 3, got %d\n", ret
);
533 ok(!lstrcmpA(buf
, "val"), "Expected \"val\", got \"%s\"\n", buf
);
535 /* nSize has room for NULL terminator */
536 lstrcpyA(buf
, "kumquat");
537 ret
= GetPrivateProfileStringA("section1", "name1", "default",
539 ok(ret
== 4, "Expected 4, got %d\n", ret
);
540 ok(!lstrcmpA(buf
, "val1"), "Expected \"val1\", got \"%s\"\n", buf
);
542 /* output is 1 character */
543 lstrcpyA(buf
, "kumquat");
544 ret
= GetPrivateProfileStringA("section1", "name4", "default",
545 buf
, MAX_PATH
, filename
);
546 ok(ret
== 1, "Expected 1, got %d\n", ret
);
547 ok(!lstrcmpA(buf
, "a"), "Expected \"a\", got \"%s\"\n", buf
);
549 /* output is 1 character, no room for NULL terminator */
550 lstrcpyA(buf
, "kumquat");
551 ret
= GetPrivateProfileStringA("section1", "name4", "default",
553 ok(ret
== 0, "Expected 0, got %d\n", ret
);
554 ok(!lstrcmpA(buf
, ""), "Expected \"\", got \"%s\"\n", buf
);
556 /* lpAppName is NULL, not enough room for final section name */
557 lstrcpyA(buf
, "kumquat");
558 ret
= GetPrivateProfileStringA(NULL
, "name1", "default",
560 ok(ret
== 14, "Expected 14, got %d\n", ret
);
561 ok(!memcmp(buf
, "section1\0secti\0", ret
+ 1),
562 "Expected \"section1\\0secti\\0\", got \"%s\"\n", buf
);
564 /* lpKeyName is NULL, not enough room for final key name */
565 lstrcpyA(buf
, "kumquat");
566 ret
= GetPrivateProfileStringA("section1", NULL
, "default",
568 ok(ret
== 14, "Expected 14, got %d\n", ret
);
569 ok(!memcmp(buf
, "name1\0name2\0na\0", ret
+ 1),
570 "Expected \"name1\\0name2\\0na\\0\", got \"%s\"\n", buf
);
572 /* key value has quotation marks which are stripped */
573 lstrcpyA(buf
, "kumquat");
574 ret
= GetPrivateProfileStringA("section1", "name2", "default",
575 buf
, MAX_PATH
, filename
);
576 ok(ret
== 4, "Expected 4, got %d\n", ret
);
577 ok(!lstrcmpA(buf
, "val2"), "Expected \"val2\", got \"%s\"\n", buf
);
579 /* case does not match */
580 lstrcpyA(buf
, "kumquat");
581 ret
= GetPrivateProfileStringA("section1", "NaMe1", "default",
582 buf
, MAX_PATH
, filename
);
583 ok(ret
== 4, "Expected 4, got %d\n", ret
);
584 ok(!lstrcmpA(buf
, "val1"), "Expected \"val1\", got \"%s\"\n", buf
);
586 /* only filename is used */
587 lstrcpyA(buf
, "kumquat");
588 ret
= GetPrivateProfileStringA("section1", "NaMe1", "default",
589 buf
, MAX_PATH
, "winetest.ini");
590 ok(ret
== 7, "Expected 7, got %d\n", ret
);
591 ok(!lstrcmpA(buf
, "default"), "Expected \"default\", got \"%s\"\n", buf
);
593 GetWindowsDirectoryA(windir
, MAX_PATH
);
594 GetTempFileNameA(windir
, "pre", 0, path
);
595 tempfile
= strrchr(path
, '\\') + 1;
596 create_test_file(path
, content
, sizeof(content
));
598 /* only filename is used, file exists in windows directory */
599 lstrcpyA(buf
, "kumquat");
600 ret
= GetPrivateProfileStringA("section1", "NaMe1", "default",
601 buf
, MAX_PATH
, tempfile
);
602 ok(ret
== 4, "Expected 4, got %d\n", ret
);
603 ok(!lstrcmpA(buf
, "val1"), "Expected \"val1\", got \"%s\"\n", buf
);
605 /* successful case */
606 lstrcpyA(buf
, "kumquat");
607 ret
= GetPrivateProfileStringA("section1", "name1", "default",
608 buf
, MAX_PATH
, filename
);
609 ok(ret
== 4, "Expected 4, got %d\n", ret
);
610 ok(!lstrcmpA(buf
, "val1"), "Expected \"val1\", got \"%s\"\n", buf
);
613 DeleteFileA(filename
);
619 test_profile_string();
620 test_profile_sections();
621 test_profile_sections_names();
622 test_profile_existing();
623 test_GetPrivateProfileString();