[PATCH 2/2] kernel/tests: More tests for OpenFile.
Saulius Krasuckas
saulius.krasuckas at ieee.org
Tue Jul 4 04:12:31 CDT 2006
---
dlls/kernel/tests/file.c | 72 ++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 69 insertions(+), 3 deletions(-)
9d6fae7c968ad628ddb04577256dad48fce17011
diff --git a/dlls/kernel/tests/file.c b/dlls/kernel/tests/file.c
index 78d6983..39e2d8a 100644
--- a/dlls/kernel/tests/file.c
+++ b/dlls/kernel/tests/file.c
@@ -1459,6 +1459,13 @@ static void safe_strcatA(char *dst, DWOR
HeapFree(GetProcessHeap(), 0, buff);
}
+static void fullpath_filename_to_from(char *dst, const char *src)
+{
+ GetCurrentDirectoryA(MAX_PATH, dst);
+ safe_strcatA(dst, MAX_PATH, "\\");
+ safe_strcatA(dst, MAX_PATH, src);
+}
+
static void test_OpenFile(void)
{
HFILE hFile;
@@ -1467,7 +1474,9 @@ static void test_OpenFile(void)
DWORD retval;
static const char *file = "\\regsvr32.exe";
+ static const char *foo = ".\\foo-bar-foo.baz";
char buff[MAX_PATH];
+ char filled_0xA5[OFS_MAXPATHNAME];
/* Check for existing file */
GetSystemDirectoryA(buff, MAX_PATH);
@@ -1475,42 +1484,99 @@ static void test_OpenFile(void)
hFile = OpenFile(buff, &ofs, OF_EXIST);
ok( hFile == TRUE, "%s not found : %ld\n", buff, GetLastError() );
- /* Check for nonexistent file */
+ memset(&filled_0xA5, 0xA5, OFS_MAXPATHNAME);
+ memset(&ofs, 0xA5, sizeof(ofs));
SetLastError(0xfaceabee);
- hFile = OpenFile(".\\foo-bar-foo.baz", &ofs, OF_EXIST);
+ /* Check for nonexistent file */
+ hFile = OpenFile(foo, &ofs, OF_EXIST);
ok( hFile == HFILE_ERROR, "hFile != HFILE_ERROR : %ld\n", GetLastError());
ok( GetLastError() == ERROR_FILE_NOT_FOUND, "GetLastError() returns %ld\n", GetLastError() );
-
+ todo_wine
+ ok( ofs.cBytes == 0xA5, "OpenFile set test.cBytes to %d\n", ofs.cBytes );
+ ok( ofs.nErrCode == ERROR_FILE_NOT_FOUND, "OpenFile set test.nErrCode to %d\n", ofs.nErrCode );
+ fullpath_filename_to_from(buff, foo+2);
+ ok( lstrcmpA(ofs.szPathName, buff) == 0 ||
+ strncmp(ofs.szPathName, filled_0xA5, OFS_MAXPATHNAME) == 0,
+ "OpenFile returned '%s', but was expected to return '%s' or string filled with 0xA5\n",
+ ofs.szPathName, buff );
+
+ memset(&ofs, 0xA5, sizeof(ofs));
+ SetLastError(0xfaceabee);
/* Create an empty file */
hFile = OpenFile(filename, &ofs, OF_CREATE);
ok( hFile != HFILE_ERROR, "OpenFile failed to create nonexistent file\n" );
+ ok( ofs.cBytes == sizeof(OFSTRUCT), "OpenFile set test.cBytes to %d\n", ofs.cBytes );
+ ok( ofs.nErrCode == ERROR_SUCCESS || ofs.nErrCode == ERROR_FILE_NOT_FOUND,
+ "OpenFile set test.nErrCode to %d\n", ofs.nErrCode );
+ fullpath_filename_to_from(buff, filename);
+ ok( lstrcmpA(ofs.szPathName, buff) == 0,
+ "OpenFile returned '%s', but was expected to return '%s'\n",
+ ofs.szPathName, buff );
ret = CloseHandle((HANDLE)hFile);
ok( ret == TRUE, "CloseHandle() returns %d\n", ret );
retval = GetFileAttributesA(filename);
ok( retval != INVALID_FILE_ATTRIBUTES, "GetFileAttributesA: error %ld\n", GetLastError() );
+ memset(&ofs, 0xA5, sizeof(ofs));
+ SetLastError(0xfaceabee);
/* Check various opening options */
hFile = OpenFile(filename, &ofs, OF_READ);
ok( hFile != HFILE_ERROR, "OpenFile failed on read\n" );
+ ok( ofs.cBytes == sizeof(OFSTRUCT), "OpenFile set test.cBytes to %d\n", ofs.cBytes );
+ /* WinME returns 0xD400 here instead of 0x0000, maybe an overflow bug, lets truncate nErrorCode: */
+ ok( (BYTE)ofs.nErrCode == ERROR_SUCCESS, "OpenFile set test.nErrCode to %d\n", ofs.nErrCode );
+ ok( lstrcmpA(ofs.szPathName, buff) == 0,
+ "OpenFile returned '%s', but was expected to return '%s'\n",
+ ofs.szPathName, buff );
ret = CloseHandle((HANDLE)hFile);
ok( ret == TRUE, "CloseHandle() returns %d\n", ret );
+ memset(&ofs, 0xA5, sizeof(ofs));
+ SetLastError(0xfaceabee);
hFile = OpenFile(filename, &ofs, OF_WRITE);
ok( hFile != HFILE_ERROR, "OpenFile failed on write\n" );
+ ok( ofs.cBytes == sizeof(OFSTRUCT), "OpenFile set test.cBytes to %d\n", ofs.cBytes );
+ /* WinME returns 0xD400 here instead of 0x0000, maybe an overflow bug, lets truncate nErrorCode: */
+ ok( (BYTE)ofs.nErrCode == ERROR_SUCCESS, "OpenFile set test.nErrCode to %d\n", ofs.nErrCode );
+ ok( lstrcmpA(ofs.szPathName, buff) == 0,
+ "OpenFile returned '%s', but was expected to return '%s'\n",
+ ofs.szPathName, buff );
ret = CloseHandle((HANDLE)hFile);
ok( ret == TRUE, "CloseHandle() returns %d\n", ret );
+ memset(&ofs, 0xA5, sizeof(ofs));
+ SetLastError(0xfaceabee);
hFile = OpenFile(filename, &ofs, OF_READWRITE);
ok( hFile != HFILE_ERROR, "OpenFile failed on read/write\n" );
+ ok( ofs.cBytes == sizeof(OFSTRUCT), "OpenFile set test.cBytes to %d\n", ofs.cBytes );
+ /* WinME returns 0xD400 here instead of 0x0000, maybe an overflow bug, lets truncate nErrorCode: */
+ ok( (BYTE)ofs.nErrCode == ERROR_SUCCESS, "OpenFile set test.nErrCode to %d\n", ofs.nErrCode );
+ ok( lstrcmpA(ofs.szPathName, buff) == 0,
+ "OpenFile returned '%s', but was expected to return '%s'\n",
+ ofs.szPathName, buff );
ret = CloseHandle((HANDLE)hFile);
ok( ret == TRUE, "CloseHandle() returns %d\n", ret );
+ memset(&ofs, 0xA5, sizeof(ofs));
+ SetLastError(0xfaceabee);
hFile = OpenFile(filename, &ofs, OF_EXIST);
ok( hFile == 1, "OpenFile failed on finding our created file\n" );
+ ok( ofs.cBytes == sizeof(OFSTRUCT), "OpenFile set test.cBytes to %d\n", ofs.cBytes );
+ ok( ofs.nErrCode == ERROR_SUCCESS, "OpenFile set test.nErrCode to %d\n", ofs.nErrCode );
+ ok( lstrcmpA(ofs.szPathName, buff) == 0,
+ "OpenFile returned '%s', but was expected to return '%s'\n",
+ ofs.szPathName, buff );
+ memset(&ofs, 0xA5, sizeof(ofs));
+ SetLastError(0xfaceabee);
/* Delete the file and make sure it doesn't exist anymore */
hFile = OpenFile(filename, &ofs, OF_DELETE);
ok( hFile == 1, "OpenFile failed on delete (%d)\n", hFile );
+ ok( ofs.cBytes == sizeof(OFSTRUCT), "OpenFile set test.cBytes to %d\n", ofs.cBytes );
+ ok( ofs.nErrCode == ERROR_SUCCESS, "OpenFile set test.nErrCode to %d\n", ofs.nErrCode );
+ ok( lstrcmpA(ofs.szPathName, buff) == 0,
+ "OpenFile returned '%s', but was expected to return '%s'\n",
+ ofs.szPathName, buff );
retval = GetFileAttributesA(filename);
ok( retval == INVALID_FILE_ATTRIBUTES, "GetFileAttributesA succeeded on deleted file\n" );
--
1.3.3
More information about the wine-patches
mailing list