kernel32: Add some test cases for profile file sharing modes.

Based on a patch by Louis Lenders.
This commit is contained in:
Alexandre Julliard 2008-05-21 14:23:44 +02:00
parent 8b97263dae
commit 1dcaddee99
1 changed files with 54 additions and 0 deletions

View File

@ -29,6 +29,7 @@
#define SECTION "Test"
#define TESTFILE ".\\testwine.ini"
#define TESTFILE2 ".\\testwine2.ini"
#define TESTFILE3 ".\\testwine3.ini"
struct _profileInt {
LPCSTR section;
@ -266,10 +267,63 @@ static void test_profile_sections_names(void)
ok( bufW[1] != 0, "returned buffer terminated with double-null\n" );
}
/* If the ini-file has already been opened with CreateFile, WritePrivateProfileString failed in wine with an error ERROR_SHARING_VIOLATION, some testing here */
static void test_profile_existing(void)
{
static const struct {
DWORD dwDesiredAccess;
DWORD dwShareMode;
DWORD error;
} pe[] = {
{GENERIC_READ, FILE_SHARE_READ, ERROR_SHARING_VIOLATION},
{GENERIC_READ, FILE_SHARE_WRITE, ERROR_SHARING_VIOLATION},
{GENERIC_WRITE, FILE_SHARE_READ, ERROR_SHARING_VIOLATION},
{GENERIC_WRITE, FILE_SHARE_WRITE, ERROR_SHARING_VIOLATION},
{GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, ERROR_SHARING_VIOLATION},
{GENERIC_READ|GENERIC_WRITE, FILE_SHARE_WRITE, ERROR_SHARING_VIOLATION},
{GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, 0},
{GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, 0},
/*Thief demo (bug 5024) opens .ini file like this*/
{GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, 0},
};
int i;
BOOL ret;
DWORD size;
HANDLE h = 0;
char buffer[MAX_PATH];
for (i=0; i < sizeof(pe)/sizeof(pe[0]); i++)
{
h = CreateFile(TESTFILE3, pe[i].dwDesiredAccess, pe[i].dwShareMode, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
ok(INVALID_HANDLE_VALUE != h, "%d: CreateFile failed\n",i);
SetLastError(0xdeadbeef);
ret = WritePrivateProfileString(SECTION, KEY, "12345", TESTFILE3);
if (!pe[i].error)
{
ok( ret, "%d: WritePrivateProfileString failed with error %u\n", i, GetLastError() );
CloseHandle(h);
size = GetPrivateProfileString(SECTION, KEY, 0, buffer, MAX_PATH, TESTFILE3);
ok( size == 5, "%d: test failed, number of characters copied: %d instead of 5\n", i, size );
}
else
{
DWORD err = GetLastError();
ok( !ret, "%d: WritePrivateProfileString succeeded\n", i );
if (!ret) ok( err == pe[i].error, "%d: WritePrivateProfileString failed with error %u/%u\n", i, err, pe[i].error );
CloseHandle(h);
size = GetPrivateProfileString(SECTION, KEY, 0, buffer, MAX_PATH, TESTFILE3);
ok( !size, "%d: test failed, number of characters copied: %d instead of 0\n", i, size );
}
ok( DeleteFile(TESTFILE3), "delete failed\n" );
}
}
START_TEST(profile)
{
test_profile_int();
test_profile_string();
test_profile_sections();
test_profile_sections_names();
test_profile_existing();
}