2003-03-04 05:34:57 +01:00
|
|
|
/*
|
|
|
|
* Unit tests for profile functions
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003 Stefan Leichter
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2003-03-04 05:34:57 +01:00
|
|
|
#include "wine/test.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2003-03-04 05:34:57 +01:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "windows.h"
|
|
|
|
|
|
|
|
#define KEY "ProfileInt"
|
|
|
|
#define SECTION "Test"
|
|
|
|
#define TESTFILE ".\\testwine.ini"
|
2005-03-02 11:08:18 +01:00
|
|
|
#define TESTFILE2 ".\\testwine2.ini"
|
2003-03-04 05:34:57 +01:00
|
|
|
|
|
|
|
struct _profileInt {
|
|
|
|
LPCSTR section;
|
|
|
|
LPCSTR key;
|
|
|
|
LPCSTR value;
|
|
|
|
LPCSTR iniFile;
|
|
|
|
INT defaultVal;
|
|
|
|
UINT result;
|
2004-06-18 01:00:54 +02:00
|
|
|
UINT result9x;
|
2003-03-04 05:34:57 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static void test_profile_int(void)
|
|
|
|
{
|
|
|
|
struct _profileInt profileInt[]={
|
2004-06-18 01:00:54 +02:00
|
|
|
{ NULL, NULL, NULL, NULL, 70, 0 , 0}, /* 0 */
|
|
|
|
{ NULL, NULL, NULL, TESTFILE, -1, 4294967295U, 0},
|
|
|
|
{ NULL, NULL, NULL, TESTFILE, 1, 1 , 0},
|
|
|
|
{ SECTION, NULL, NULL, TESTFILE, -1, 4294967295U, 0},
|
|
|
|
{ SECTION, NULL, NULL, TESTFILE, 1, 1 , 0},
|
|
|
|
{ NULL, KEY, NULL, TESTFILE, -1, 4294967295U, 0}, /* 5 */
|
|
|
|
{ NULL, KEY, NULL, TESTFILE, 1, 1 , 0},
|
|
|
|
{ SECTION, KEY, NULL, TESTFILE, -1, 4294967295U, 4294967295U},
|
|
|
|
{ SECTION, KEY, NULL, TESTFILE, 1, 1 , 1},
|
|
|
|
{ SECTION, KEY, "-1", TESTFILE, -1, 4294967295U, 4294967295U},
|
|
|
|
{ SECTION, KEY, "-1", TESTFILE, 1, 4294967295U, 4294967295U}, /* 10 */
|
|
|
|
{ SECTION, KEY, "1", TESTFILE, -1, 1 , 1},
|
|
|
|
{ SECTION, KEY, "1", TESTFILE, 1, 1 , 1},
|
|
|
|
{ SECTION, KEY, "+1", TESTFILE, -1, 1 , 0},
|
|
|
|
{ SECTION, KEY, "+1", TESTFILE, 1, 1 , 0},
|
|
|
|
{ SECTION, KEY, "4294967296", TESTFILE, -1, 0 , 0}, /* 15 */
|
|
|
|
{ SECTION, KEY, "4294967296", TESTFILE, 1, 0 , 0},
|
|
|
|
{ SECTION, KEY, "4294967297", TESTFILE, -1, 1 , 1},
|
|
|
|
{ SECTION, KEY, "4294967297", TESTFILE, 1, 1 , 1},
|
|
|
|
{ SECTION, KEY, "-4294967297", TESTFILE, -1, 4294967295U, 4294967295U},
|
|
|
|
{ SECTION, KEY, "-4294967297", TESTFILE, 1, 4294967295U, 4294967295U}, /* 20 */
|
|
|
|
{ SECTION, KEY, "42A94967297", TESTFILE, -1, 42 , 42},
|
|
|
|
{ SECTION, KEY, "42A94967297", TESTFILE, 1, 42 , 42},
|
|
|
|
{ SECTION, KEY, "B4294967297", TESTFILE, -1, 0 , 0},
|
|
|
|
{ SECTION, KEY, "B4294967297", TESTFILE, 1, 0 , 0},
|
2003-03-04 05:34:57 +01:00
|
|
|
};
|
|
|
|
int i, num_test = (sizeof(profileInt)/sizeof(struct _profileInt));
|
|
|
|
UINT res;
|
|
|
|
|
|
|
|
DeleteFileA( TESTFILE);
|
|
|
|
|
|
|
|
for (i=0; i < num_test; i++) {
|
|
|
|
if (profileInt[i].value)
|
|
|
|
WritePrivateProfileStringA(SECTION, KEY, profileInt[i].value,
|
|
|
|
profileInt[i].iniFile);
|
|
|
|
|
|
|
|
res = GetPrivateProfileIntA(profileInt[i].section, profileInt[i].key,
|
|
|
|
profileInt[i].defaultVal, profileInt[i].iniFile);
|
2004-06-18 01:00:54 +02:00
|
|
|
ok((res == profileInt[i].result) || (res == profileInt[i].result9x),
|
|
|
|
"test<%02d>: ret<%010u> exp<%010u><%010u>\n",
|
|
|
|
i, res, profileInt[i].result, profileInt[i].result9x);
|
2003-03-04 05:34:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
DeleteFileA( TESTFILE);
|
|
|
|
}
|
|
|
|
|
2005-06-14 13:40:04 +02:00
|
|
|
static void test_profile_string(void)
|
2005-03-02 11:08:18 +01:00
|
|
|
{
|
|
|
|
HANDLE h;
|
|
|
|
int ret;
|
|
|
|
DWORD count;
|
|
|
|
char buf[100];
|
|
|
|
char *p;
|
|
|
|
/* test that lines without an '=' will not be enumerated */
|
|
|
|
/* in the case below, name2 is a key while name3 is not. */
|
|
|
|
char content[]="[s]\r\nname1=val1\r\nname2=\r\nname3\r\nname4=val4\r\n";
|
|
|
|
DeleteFileA( TESTFILE2);
|
|
|
|
h = CreateFileA( TESTFILE2, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
|
|
|
|
FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
ok( h != INVALID_HANDLE_VALUE, " cannot create %s\n", TESTFILE2);
|
|
|
|
if( h == INVALID_HANDLE_VALUE) return;
|
|
|
|
WriteFile( h, content, sizeof(content), &count, NULL);
|
|
|
|
CloseHandle( h);
|
2005-08-10 14:59:38 +02:00
|
|
|
|
2005-03-02 11:08:18 +01:00
|
|
|
/* enumerate the keys */
|
|
|
|
ret=GetPrivateProfileStringA( "s", NULL, "", buf, sizeof(buf),
|
|
|
|
TESTFILE2);
|
|
|
|
for( p = buf + strlen(buf) + 1; *p;p += strlen(p)+1)
|
|
|
|
p[-1] = ',';
|
|
|
|
/* and test */
|
2005-08-10 14:59:38 +02:00
|
|
|
ok( ret == 18 && !strcmp( buf, "name1,name2,name4"), "wrong keys returned(%d): %s\n", ret,
|
2005-03-02 11:08:18 +01:00
|
|
|
buf);
|
2005-03-04 11:46:55 +01:00
|
|
|
|
|
|
|
ret=GetPrivateProfileSectionA("s", buf, sizeof(buf), TESTFILE2);
|
|
|
|
for( p = buf + strlen(buf) + 1; *p;p += strlen(p)+1)
|
|
|
|
p[-1] = ',';
|
|
|
|
/* and test */
|
2005-08-10 14:59:38 +02:00
|
|
|
ok( ret == 35 && !strcmp( buf, "name1=val1,name2=,name3,name4=val4"), "wrong section returned(%d): %s\n",
|
|
|
|
ret, buf);
|
2005-03-04 11:46:55 +01:00
|
|
|
|
2005-03-02 11:08:18 +01:00
|
|
|
/* add a new key to test that the file is quite usable */
|
|
|
|
WritePrivateProfileStringA( "s", "name5", "val5", TESTFILE2);
|
|
|
|
ret=GetPrivateProfileStringA( "s", NULL, "", buf, sizeof(buf),
|
|
|
|
TESTFILE2);
|
|
|
|
for( p = buf + strlen(buf) + 1; *p;p += strlen(p)+1)
|
|
|
|
p[-1] = ',';
|
2005-08-10 14:59:38 +02:00
|
|
|
ok( ret == 24 && !strcmp( buf, "name1,name2,name4,name5"), "wrong keys returned(%d): %s\n",
|
|
|
|
ret, buf);
|
|
|
|
|
2005-03-02 11:08:18 +01:00
|
|
|
DeleteFileA( TESTFILE2);
|
|
|
|
}
|
|
|
|
|
2003-03-04 05:34:57 +01:00
|
|
|
START_TEST(profile)
|
|
|
|
{
|
|
|
|
test_profile_int();
|
2005-03-02 11:08:18 +01:00
|
|
|
test_profile_string();
|
2003-03-04 05:34:57 +01:00
|
|
|
}
|