Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-cw
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-cw
Commits
c49b9485
Commit
c49b9485
authored
Apr 28, 2004
by
Jakob Eriksson
Committed by
Alexandre Julliard
Apr 28, 2004
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed tests to succeed on all Windows versions.
parent
253ffd50
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
112 additions
and
32 deletions
+112
-32
file.c
dlls/kernel/tests/file.c
+112
-32
No files found.
dlls/kernel/tests/file.c
View file @
c49b9485
/*
* Unit tests for file functions in Wine
*
* Copyright (c) 2002 Jakob Eriksson
* Copyright (c) 2002
, 2004
Jakob Eriksson
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
...
...
@@ -28,6 +28,15 @@
#include "winbase.h"
#include "winerror.h"
static
int
dll_capable
(
const
char
*
dll
,
const
char
*
function
)
{
HMODULE
module
=
GetModuleHandleA
(
dll
);
if
(
!
module
)
return
0
;
return
(
GetProcAddress
(
module
,
function
)
!=
NULL
);
}
LPCSTR
filename
=
"testfile.xxx"
;
LPCSTR
sillytext
=
"en larvig liten text dx
\033
gx hej 84 hej 4484 !
\001\033
bla bl
\n
a.. bla bla."
...
...
@@ -681,7 +690,8 @@ static void test_DeleteFileA( void )
ret
=
DeleteFileA
(
"nul"
);
ok
(
!
ret
&&
(
GetLastError
()
==
ERROR_FILE_NOT_FOUND
||
GetLastError
()
==
ERROR_INVALID_PARAMETER
),
GetLastError
()
==
ERROR_INVALID_PARAMETER
||
GetLastError
()
==
ERROR_ACCESS_DENIED
),
"DeleteFileA(
\"
nul
\"
) returned ret=%d error=%ld
\n
"
,
ret
,
GetLastError
());
}
...
...
@@ -879,6 +889,9 @@ static void test_LockFile(void)
HANDLE
handle
;
DWORD
written
;
OVERLAPPED
overlapped
;
int
limited_LockFile
;
int
limited_UnLockFile
;
int
lockfileex_capable
;
handle
=
CreateFileA
(
filename
,
GENERIC_READ
|
GENERIC_WRITE
,
FILE_SHARE_READ
|
FILE_SHARE_WRITE
,
NULL
,
...
...
@@ -892,7 +905,12 @@ static void test_LockFile(void)
ok
(
LockFile
(
handle
,
0
,
0
,
0
,
0
),
"LockFile failed
\n
"
);
ok
(
UnlockFile
(
handle
,
0
,
0
,
0
,
0
),
"UnlockFile failed
\n
"
);
ok
(
!
UnlockFile
(
handle
,
0
,
0
,
0
,
0
),
"UnlockFile succeeded
\n
"
);
limited_UnLockFile
=
0
;
if
(
UnlockFile
(
handle
,
0
,
0
,
0
,
0
))
{
limited_UnLockFile
=
1
;
}
ok
(
LockFile
(
handle
,
10
,
0
,
20
,
0
),
"LockFile 10,20 failed
\n
"
);
/* overlapping locks must fail */
...
...
@@ -909,18 +927,39 @@ static void test_LockFile(void)
overlapped
.
Offset
=
100
;
overlapped
.
OffsetHigh
=
0
;
overlapped
.
hEvent
=
0
;
ok
(
LockFileEx
(
handle
,
0
,
0
,
100
,
0
,
&
overlapped
),
"LockFileEx 100,100 failed
\n
"
);
lockfileex_capable
=
dll_capable
(
"kernel32"
,
"LockFileEx"
);
if
(
lockfileex_capable
)
{
/* Test for broken LockFileEx a la Windows 95 OSR2. */
if
(
LockFileEx
(
handle
,
0
,
0
,
100
,
0
,
&
overlapped
))
{
/* LockFileEx is probably OK, test it more. */
ok
(
LockFileEx
(
handle
,
0
,
0
,
100
,
0
,
&
overlapped
),
"LockFileEx 100,100 failed
\n
"
);
}
}
/* overlapping shared locks are OK */
overlapped
.
Offset
=
150
;
ok
(
LockFileEx
(
handle
,
0
,
0
,
100
,
0
,
&
overlapped
),
"LockFileEx 150,100 failed
\n
"
);
limited_UnLockFile
||
ok
(
LockFileEx
(
handle
,
0
,
0
,
100
,
0
,
&
overlapped
),
"LockFileEx 150,100 failed
\n
"
);
/* but exclusive is not */
ok
(
!
LockFileEx
(
handle
,
LOCKFILE_EXCLUSIVE_LOCK
|
LOCKFILE_FAIL_IMMEDIATELY
,
0
,
50
,
0
,
&
overlapped
),
"LockFileEx exclusive 150,50 succeeded
\n
"
);
ok
(
UnlockFileEx
(
handle
,
0
,
100
,
0
,
&
overlapped
),
"UnlockFileEx 150,100 failed
\n
"
);
ok
(
!
UnlockFileEx
(
handle
,
0
,
100
,
0
,
&
overlapped
),
"UnlockFileEx 150,100 again succeeded
\n
"
);
overlapped
.
Offset
=
100
;
ok
(
UnlockFileEx
(
handle
,
0
,
100
,
0
,
&
overlapped
),
"UnlockFileEx 100,100 failed
\n
"
);
ok
(
!
UnlockFileEx
(
handle
,
0
,
100
,
0
,
&
overlapped
),
"UnlockFileEx 100,100 again succeeded
\n
"
);
if
(
lockfileex_capable
)
{
ok
(
!
LockFileEx
(
handle
,
LOCKFILE_EXCLUSIVE_LOCK
|
LOCKFILE_FAIL_IMMEDIATELY
,
0
,
50
,
0
,
&
overlapped
),
"LockFileEx exclusive 150,50 succeeded
\n
"
);
if
(
dll_capable
(
"kernel32.dll"
,
"UnlockFileEx"
))
{
if
(
!
UnlockFileEx
(
handle
,
0
,
100
,
0
,
&
overlapped
))
{
/* UnLockFile is capable. */
overlapped
.
Offset
=
100
;
ok
(
!
UnlockFileEx
(
handle
,
0
,
100
,
0
,
&
overlapped
),
"UnlockFileEx 150,100 again succeeded
\n
"
);
}
}
}
ok
(
LockFile
(
handle
,
0
,
0x10000000
,
0
,
0xf0000000
),
"LockFile failed
\n
"
);
ok
(
!
LockFile
(
handle
,
~
0
,
~
0
,
1
,
0
),
"LockFile ~0,1 succeeded
\n
"
);
...
...
@@ -930,16 +969,24 @@ static void test_LockFile(void)
/* wrap-around lock should not do anything */
/* (but still succeeds on NT4 so we don't check result) */
LockFile
(
handle
,
0
,
0x10000000
,
0
,
0xf0000001
);
ok
(
LockFile
(
handle
,
~
0
,
~
0
,
1
,
0
),
"LockFile ~0,1 failed
\n
"
);
ok
(
UnlockFile
(
handle
,
~
0
,
~
0
,
1
,
0
),
"Unlockfile ~0,1 failed
\n
"
);
limited_LockFile
=
0
;
if
(
!
LockFile
(
handle
,
~
0
,
~
0
,
1
,
0
))
{
limited_LockFile
=
1
;
}
limited_UnLockFile
||
ok
(
UnlockFile
(
handle
,
~
0
,
~
0
,
1
,
0
),
"Unlockfile ~0,1 failed
\n
"
);
/* zero-byte lock */
ok
(
LockFile
(
handle
,
100
,
0
,
0
,
0
),
"LockFile 100,0 failed
\n
"
);
ok
(
!
LockFile
(
handle
,
98
,
0
,
4
,
0
),
"LockFile 98,4 succeeded
\n
"
);
limited_LockFile
||
ok
(
!
LockFile
(
handle
,
98
,
0
,
4
,
0
),
"LockFile 98,4 succeeded
\n
"
);
ok
(
LockFile
(
handle
,
90
,
0
,
10
,
0
),
"LockFile 90,10 failed
\n
"
);
ok
(
LockFile
(
handle
,
100
,
0
,
10
,
0
),
"LockFile 100,10 failed
\n
"
);
limited_LockFile
||
ok
(
!
LockFile
(
handle
,
100
,
0
,
10
,
0
),
"LockFile 100,10 failed
\n
"
);
ok
(
UnlockFile
(
handle
,
90
,
0
,
10
,
0
),
"UnlockFile 90,10 failed
\n
"
);
ok
(
UnlockFile
(
handle
,
100
,
0
,
10
,
0
),
"UnlockFile 100,10 failed
\n
"
);
!
ok
(
UnlockFile
(
handle
,
100
,
0
,
10
,
0
),
"UnlockFile 100,10 failed
\n
"
);
ok
(
UnlockFile
(
handle
,
100
,
0
,
0
,
0
),
"UnlockFile 100,0 failed
\n
"
);
CloseHandle
(
handle
);
...
...
@@ -961,6 +1008,7 @@ static void test_file_sharing(void)
static
const
DWORD
access_modes
[
4
]
=
{
0
,
GENERIC_READ
,
GENERIC_WRITE
,
GENERIC_READ
|
GENERIC_WRITE
};
static
const
DWORD
sharing_modes
[
4
]
=
{
0
,
FILE_SHARE_READ
,
FILE_SHARE_WRITE
,
FILE_SHARE_READ
|
FILE_SHARE_WRITE
};
int
a1
,
s1
,
a2
,
s2
;
int
ret
;
/* make sure the file exists */
HANDLE
h
=
CreateFileA
(
filename
,
GENERIC_READ
|
GENERIC_WRITE
,
0
,
NULL
,
CREATE_ALWAYS
,
0
,
0
);
...
...
@@ -986,10 +1034,17 @@ static void test_file_sharing(void)
if
(
is_sharing_compatible
(
access_modes
[
a1
],
sharing_modes
[
s1
],
access_modes
[
a2
],
sharing_modes
[
s2
]
))
{
ok
(
h2
!=
INVALID_HANDLE_VALUE
,
"open failed for modes %lx/%lx/%lx/%lx err %ld
\n
"
,
ret
=
GetLastError
();
ok
(
ERROR_SHARING_VIOLATION
==
ret
||
0
==
ret
,
"Windows 95 sets GetLastError() = ERROR_SHARING_VIOLATION and
\n
"
" Windows XP GetLastError() = 0, but now it is %d.
\n
"
" indexes = %d, %d, %d, %d
\n
"
" modes =
\n
%lx/%lx/%lx/%lx
\n
"
,
ret
,
a1
,
s1
,
a2
,
s2
,
access_modes
[
a1
],
sharing_modes
[
s1
],
access_modes
[
a2
],
sharing_modes
[
s2
],
GetLastError
()
);
access_modes
[
a2
],
sharing_modes
[
s2
]
);
}
else
{
...
...
@@ -1043,33 +1098,58 @@ static void test_FindNextFileA()
ok
(
err
==
ERROR_NO_MORE_FILES
,
"GetLastError should return ERROR_NO_MORE_FILES
\n
"
);
}
static
void
test_MapFile
(
)
static
int
test_Mapfile_createtemp
(
HANDLE
*
handle
)
{
HANDLE
handle
,
hmap
;
/* be sure to remove stale files */
SetFileAttributesA
(
filename
,
FILE_ATTRIBUTE_NORMAL
);
DeleteFile
(
filename
);
handle
=
CreateFile
(
filename
,
GENERIC_READ
|
GENERIC_WRITE
,
0
,
0
,
CREATE_ALWAYS
,
FILE_ATTRIBUTE_NORMAL
,
NULL
);
ok
(
handle
!=
INVALID_HANDLE_VALUE
,
"couldn't create test file
\n
"
);
*
handle
=
CreateFile
(
filename
,
GENERIC_READ
|
GENERIC_WRITE
,
0
,
0
,
CREATE_ALWAYS
,
FILE_ATTRIBUTE_NORMAL
,
NULL
);
if
(
*
handle
!=
INVALID_HANDLE_VALUE
)
{
return
1
;
}
return
0
;
}
static
void
test_MapFile
()
{
HANDLE
handle
;
HANDLE
hmap
;
ok
(
test_Mapfile_createtemp
(
&
handle
),
"Couldn't create test file.
\n
"
);
hmap
=
CreateFileMapping
(
handle
,
NULL
,
PAGE_READWRITE
,
0
,
0x1000
,
"named_file_map"
);
ok
(
hmap
!=
NULL
,
"mapping should work, I named it!
\n
"
);
ok
(
CloseHandle
(
hmap
),
"can't close mapping handle
\n
"
);
/* We have to close file before we try new stuff with mapping again.
Else we would always succeed on XP or block descriptors on 95. */
hmap
=
CreateFileMapping
(
handle
,
NULL
,
PAGE_READWRITE
,
0
,
0
,
NULL
);
ok
(
hmap
!=
NULL
,
"We should still be able to map!
\n
"
);
ok
(
CloseHandle
(
hmap
),
"can't close mapping handle
\n
"
);
ok
(
CloseHandle
(
handle
),
"can't close file handle
\n
"
);
handle
=
NULL
;
ok
(
test_Mapfile_createtemp
(
&
handle
),
"Couldn't create test file.
\n
"
);
hmap
=
CreateFileMapping
(
handle
,
NULL
,
PAGE_READWRITE
,
0
,
0
,
NULL
);
ok
(
hmap
==
NULL
,
"Mapping should not work, no name provided.
\n
"
);
ok
(
hmap
==
NULL
,
"mapped zero size file
\n
"
);
ok
(
GetLastError
()
==
ERROR_FILE_INVALID
,
"not ERROR_FILE_INVALID
\n
"
);
hmap
=
CreateFileMapping
(
handle
,
NULL
,
PAGE_READWRITE
,
0x1000
,
0
,
NULL
);
ok
(
hmap
==
NULL
,
"mapping should fail
\n
"
);
/* GetLastError() varies between win9x and WinNT */
/* GetLastError() varies between win9x and WinNT
and also depends on the filesystem
*/
hmap
=
CreateFileMapping
(
handle
,
NULL
,
PAGE_READWRITE
,
0x1000
,
0x10000
,
NULL
);
ok
(
hmap
==
NULL
,
"mapping should fail
\n
"
);
/* GetLastError() varies between win9x and WinNT */
/* GetLastError() varies between win9x and WinNT
and also depends on the filesystem
*/
hmap
=
CreateFileMapping
(
handle
,
NULL
,
PAGE_READWRITE
,
0
,
0x1000
,
NULL
);
ok
(
hmap
!=
NULL
,
"mapping should succeed
\n
"
);
/* On XP you can now map again, on Win 95 you can not. */
ok
(
CloseHandle
(
hmap
),
"can't close mapping handle
\n
"
);
ok
(
CloseHandle
(
handle
),
"can't close file handle
\n
"
);
ok
(
DeleteFileA
(
filename
),
"DeleteFile failed after map
\n
"
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment