2002-04-29 19:14:50 +02:00
|
|
|
/*
|
2002-05-09 22:29:15 +02:00
|
|
|
* Unit tests for file functions in Wine
|
2002-04-29 19:14:50 +02:00
|
|
|
*
|
2004-04-28 05:52:02 +02:00
|
|
|
* Copyright (c) 2002, 2004 Jakob Eriksson
|
2002-04-29 19:14:50 +02:00
|
|
|
*
|
|
|
|
* 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
|
2002-05-09 22:29:15 +02:00
|
|
|
*
|
2002-04-29 19:14:50 +02:00
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2002-04-29 19:14:50 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2002-05-23 04:40:07 +02:00
|
|
|
#include "wine/test.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2002-05-23 04:40:07 +02:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
|
2004-04-28 05:52:02 +02:00
|
|
|
static int dll_capable(const char *dll, const char *function)
|
|
|
|
{
|
|
|
|
HMODULE module = GetModuleHandleA(dll);
|
|
|
|
if (!module) return 0;
|
|
|
|
|
|
|
|
return (GetProcAddress(module, function) != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-04-29 19:14:50 +02:00
|
|
|
LPCSTR filename = "testfile.xxx";
|
|
|
|
LPCSTR sillytext =
|
|
|
|
"en larvig liten text dx \033 gx hej 84 hej 4484 ! \001\033 bla bl\na.. bla bla."
|
|
|
|
"1234 43 4kljf lf &%%%&&&&&& 34 4 34 3############# 33 3 3 3 # 3## 3"
|
|
|
|
"1234 43 4kljf lf &%%%&&&&&& 34 4 34 3############# 33 3 3 3 # 3## 3"
|
|
|
|
"1234 43 4kljf lf &%%%&&&&&& 34 4 34 3############# 33 3 3 3 # 3## 3"
|
|
|
|
"1234 43 4kljf lf &%%%&&&&&& 34 4 34 3############# 33 3 3 3 # 3## 3"
|
|
|
|
"1234 43 4kljf lf &%%%&&&&&& 34 4 34 3############# 33 3 3 3 # 3## 3"
|
|
|
|
"1234 43 4kljf lf &%%%&&&&&& 34 4 34 3############# 33 3 3 3 # 3## 3"
|
|
|
|
"1234 43 4kljf lf &%%%&&&&&& 34 4 34 3############# 33 3 3 3 # 3## 3"
|
|
|
|
"1234 43 4kljf lf &%%%&&&&&& 34 4 34 3############# 33 3 3 3 # 3## 3"
|
|
|
|
"sdlkfjasdlkfj a dslkj adsklf \n \nasdklf askldfa sdlkf \nsadklf asdklf asdf ";
|
|
|
|
|
2002-05-09 22:29:15 +02:00
|
|
|
|
2002-04-29 19:14:50 +02:00
|
|
|
static void test__hread( void )
|
|
|
|
{
|
|
|
|
HFILE filehandle;
|
|
|
|
char buffer[10000];
|
|
|
|
long bytes_read;
|
2002-05-09 22:29:15 +02:00
|
|
|
long bytes_wanted;
|
2002-12-18 03:22:51 +01:00
|
|
|
long i;
|
2004-12-27 18:26:37 +01:00
|
|
|
BOOL ret;
|
2002-04-29 19:14:50 +02:00
|
|
|
|
2002-06-05 02:47:38 +02:00
|
|
|
SetFileAttributesA(filename,FILE_ATTRIBUTE_NORMAL); /* be sure to remove stale files */
|
|
|
|
DeleteFileA( filename );
|
2002-04-29 19:14:50 +02:00
|
|
|
filehandle = _lcreat( filename, 0 );
|
2002-05-23 18:29:37 +02:00
|
|
|
if (filehandle == HFILE_ERROR)
|
|
|
|
{
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
|
2002-05-23 18:29:37 +02:00
|
|
|
return;
|
|
|
|
}
|
2002-04-29 19:14:50 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" );
|
2002-04-29 19:14:50 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
|
2002-04-29 19:14:50 +02:00
|
|
|
|
|
|
|
filehandle = _lopen( filename, OF_READ );
|
2002-05-06 22:12:55 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR != filehandle, "couldn't open file \"%s\" again (err=%ld)\n", filename, GetLastError( ) );
|
2002-05-23 18:29:37 +02:00
|
|
|
|
2002-04-29 19:14:50 +02:00
|
|
|
bytes_read = _hread( filehandle, buffer, 2 * strlen( sillytext ) );
|
2002-05-23 18:29:37 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( lstrlenA( sillytext ) == bytes_read, "file read size error\n" );
|
2002-04-29 19:14:50 +02:00
|
|
|
|
2002-12-18 03:22:51 +01:00
|
|
|
for (bytes_wanted = 0; bytes_wanted < lstrlenA( sillytext ); bytes_wanted++)
|
2002-04-29 19:14:50 +02:00
|
|
|
{
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( 0 == _llseek( filehandle, 0, FILE_BEGIN ), "_llseek complains\n" );
|
|
|
|
ok( _hread( filehandle, buffer, bytes_wanted ) == bytes_wanted, "erratic _hread return value\n" );
|
2002-04-29 19:14:50 +02:00
|
|
|
for (i = 0; i < bytes_wanted; i++)
|
|
|
|
{
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( buffer[i] == sillytext[i], "that's not what's written\n" );
|
2002-04-29 19:14:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains\n" );
|
2002-04-29 19:14:50 +02:00
|
|
|
|
2004-12-27 18:26:37 +01:00
|
|
|
ret = DeleteFileA( filename );
|
|
|
|
ok( ret != 0, "DeleteFile failed (%ld)\n", GetLastError( ) );
|
2002-04-29 19:14:50 +02:00
|
|
|
}
|
|
|
|
|
2002-05-09 22:29:15 +02:00
|
|
|
|
2002-04-29 19:14:50 +02:00
|
|
|
static void test__hwrite( void )
|
|
|
|
{
|
|
|
|
HFILE filehandle;
|
|
|
|
char buffer[10000];
|
|
|
|
long bytes_read;
|
2002-12-18 03:22:51 +01:00
|
|
|
long bytes_written;
|
|
|
|
long blocks;
|
|
|
|
long i;
|
2002-04-29 19:14:50 +02:00
|
|
|
char *contents;
|
|
|
|
HLOCAL memory_object;
|
|
|
|
char checksum[1];
|
2004-12-27 18:26:37 +01:00
|
|
|
BOOL ret;
|
2002-04-29 19:14:50 +02:00
|
|
|
|
|
|
|
filehandle = _lcreat( filename, 0 );
|
2002-05-23 18:29:37 +02:00
|
|
|
if (filehandle == HFILE_ERROR)
|
|
|
|
{
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
|
2002-05-23 18:29:37 +02:00
|
|
|
return;
|
|
|
|
}
|
2002-04-29 19:14:50 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR != _hwrite( filehandle, "", 0 ), "_hwrite complains\n" );
|
2002-04-29 19:14:50 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
|
2002-04-29 19:14:50 +02:00
|
|
|
|
|
|
|
filehandle = _lopen( filename, OF_READ );
|
2002-05-23 18:29:37 +02:00
|
|
|
|
2002-04-29 19:14:50 +02:00
|
|
|
bytes_read = _hread( filehandle, buffer, 1);
|
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( 0 == bytes_read, "file read size error\n" );
|
2002-04-29 19:14:50 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
|
2002-04-29 19:14:50 +02:00
|
|
|
|
|
|
|
filehandle = _lopen( filename, OF_READWRITE );
|
|
|
|
|
|
|
|
bytes_written = 0;
|
|
|
|
checksum[0] = '\0';
|
|
|
|
srand( (unsigned)time( NULL ) );
|
|
|
|
for (blocks = 0; blocks < 100; blocks++)
|
|
|
|
{
|
2003-07-19 05:06:19 +02:00
|
|
|
for (i = 0; i < (long)sizeof( buffer ); i++)
|
2002-04-29 19:14:50 +02:00
|
|
|
{
|
|
|
|
buffer[i] = rand( );
|
|
|
|
checksum[0] = checksum[0] + buffer[i];
|
|
|
|
}
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR != _hwrite( filehandle, buffer, sizeof( buffer ) ), "_hwrite complains\n" );
|
2002-04-29 19:14:50 +02:00
|
|
|
bytes_written = bytes_written + sizeof( buffer );
|
|
|
|
}
|
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR != _hwrite( filehandle, checksum, 1 ), "_hwrite complains\n" );
|
2002-04-29 19:14:50 +02:00
|
|
|
bytes_written++;
|
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains\n" );
|
2002-04-29 19:14:50 +02:00
|
|
|
|
|
|
|
memory_object = LocalAlloc( LPTR, bytes_written );
|
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( 0 != memory_object, "LocalAlloc fails. (Could be out of memory.)\n" );
|
2002-04-29 19:14:50 +02:00
|
|
|
|
|
|
|
contents = LocalLock( memory_object );
|
|
|
|
|
|
|
|
filehandle = _lopen( filename, OF_READ );
|
|
|
|
|
|
|
|
contents = LocalLock( memory_object );
|
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( NULL != contents, "LocalLock whines\n" );
|
2002-04-29 19:14:50 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( bytes_written == _hread( filehandle, contents, bytes_written), "read length differ from write length\n" );
|
2002-04-29 19:14:50 +02:00
|
|
|
|
|
|
|
checksum[0] = '\0';
|
|
|
|
i = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
checksum[0] = checksum[0] + contents[i];
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
while (i < bytes_written - 1);
|
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( checksum[0] == contents[i], "stored checksum differ from computed checksum\n" );
|
2002-05-06 22:12:55 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains\n" );
|
2002-04-29 19:14:50 +02:00
|
|
|
|
2004-12-27 18:26:37 +01:00
|
|
|
ret = DeleteFileA( filename );
|
|
|
|
ok( ret != 0, "DeleteFile failed (%ld)\n", GetLastError( ) );
|
2002-04-29 19:14:50 +02:00
|
|
|
}
|
|
|
|
|
2002-05-09 22:29:15 +02:00
|
|
|
|
2002-04-29 19:14:50 +02:00
|
|
|
static void test__lclose( void )
|
|
|
|
{
|
|
|
|
HFILE filehandle;
|
2004-12-27 18:26:37 +01:00
|
|
|
BOOL ret;
|
2002-04-29 19:14:50 +02:00
|
|
|
|
|
|
|
filehandle = _lcreat( filename, 0 );
|
2002-05-23 18:29:37 +02:00
|
|
|
if (filehandle == HFILE_ERROR)
|
|
|
|
{
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
|
2002-05-23 18:29:37 +02:00
|
|
|
return;
|
|
|
|
}
|
2002-04-29 19:14:50 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" );
|
2002-04-29 19:14:50 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
|
2002-04-29 19:14:50 +02:00
|
|
|
|
2004-12-27 18:26:37 +01:00
|
|
|
ret = DeleteFileA( filename );
|
|
|
|
ok( ret != 0, "DeleteFile failed (%ld)\n", GetLastError( ) );
|
2002-04-29 19:14:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-06 22:12:55 +02:00
|
|
|
static void test__lcreat( void )
|
|
|
|
{
|
|
|
|
HFILE filehandle;
|
|
|
|
char buffer[10000];
|
|
|
|
WIN32_FIND_DATAA search_results;
|
2003-05-19 23:50:32 +02:00
|
|
|
char slashname[] = "testfi/";
|
2003-10-22 01:42:50 +02:00
|
|
|
int err;
|
2003-05-19 23:50:32 +02:00
|
|
|
HANDLE find;
|
2004-12-27 18:26:37 +01:00
|
|
|
BOOL ret;
|
2002-05-06 22:12:55 +02:00
|
|
|
|
|
|
|
filehandle = _lcreat( filename, 0 );
|
2002-05-23 18:29:37 +02:00
|
|
|
if (filehandle == HFILE_ERROR)
|
|
|
|
{
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
|
2002-05-23 18:29:37 +02:00
|
|
|
return;
|
|
|
|
}
|
2002-05-06 22:12:55 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" );
|
2002-05-06 22:12:55 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( 0 == _llseek( filehandle, 0, FILE_BEGIN ), "_llseek complains\n" );
|
2002-05-06 22:12:55 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( _hread( filehandle, buffer, strlen( sillytext ) ) == lstrlenA( sillytext ), "erratic _hread return value\n" );
|
2002-05-06 22:12:55 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
|
2002-05-06 22:12:55 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( INVALID_HANDLE_VALUE != FindFirstFileA( filename, &search_results ), "should be able to find file\n" );
|
2002-05-06 22:12:55 +02:00
|
|
|
|
2004-12-27 18:26:37 +01:00
|
|
|
ret = DeleteFileA(filename);
|
|
|
|
ok( ret != 0, "DeleteFile failed (%ld)\n", GetLastError());
|
2002-05-06 22:12:55 +02:00
|
|
|
|
2002-05-29 18:58:14 +02:00
|
|
|
filehandle = _lcreat( filename, 1 ); /* readonly */
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR != filehandle, "couldn't create file \"%s\" (err=%ld)\n", filename, GetLastError( ) );
|
2002-05-06 22:12:55 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite shouldn't be able to write never the less\n" );
|
2002-05-06 22:12:55 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
|
2002-05-06 22:12:55 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( INVALID_HANDLE_VALUE != FindFirstFileA( filename, &search_results ), "should be able to find file\n" );
|
2002-05-06 22:12:55 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( 0 == DeleteFileA( filename ), "shouldn't be able to delete a readonly file\n" );
|
2002-05-06 22:12:55 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( SetFileAttributesA(filename, FILE_ATTRIBUTE_NORMAL ) != 0, "couldn't change attributes on file\n" );
|
2002-05-29 18:58:14 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( DeleteFileA( filename ) != 0, "now it should be possible to delete the file!\n" );
|
2002-05-06 22:12:55 +02:00
|
|
|
|
|
|
|
filehandle = _lcreat( filename, 2 );
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR != filehandle, "couldn't create file \"%s\" (err=%ld)\n", filename, GetLastError( ) );
|
2002-05-06 22:12:55 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" );
|
2002-05-06 22:12:55 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( 0 == _llseek( filehandle, 0, FILE_BEGIN ), "_llseek complains\n" );
|
2002-05-06 22:12:55 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( _hread( filehandle, buffer, strlen( sillytext ) ) == lstrlenA( sillytext ), "erratic _hread return value\n" );
|
2002-05-06 22:12:55 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
|
2002-05-06 22:12:55 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( INVALID_HANDLE_VALUE != FindFirstFileA( filename, &search_results ), "should STILL be able to find file\n" );
|
2002-05-06 22:12:55 +02:00
|
|
|
|
2004-12-27 18:26:37 +01:00
|
|
|
ret = DeleteFileA( filename );
|
|
|
|
ok( ret, "DeleteFile failed (%ld)\n", GetLastError( ) );
|
2002-05-23 18:29:37 +02:00
|
|
|
|
2002-05-29 18:58:14 +02:00
|
|
|
filehandle = _lcreat( filename, 4 ); /* SYSTEM file */
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR != filehandle, "couldn't create file \"%s\" (err=%ld)\n", filename, GetLastError( ) );
|
2002-05-06 22:12:55 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" );
|
2002-05-06 22:12:55 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( 0 == _llseek( filehandle, 0, FILE_BEGIN ), "_llseek complains\n" );
|
2002-05-06 22:12:55 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( _hread( filehandle, buffer, strlen( sillytext ) ) == lstrlenA( sillytext ), "erratic _hread return value\n" );
|
2002-05-06 22:12:55 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
|
2002-05-06 22:12:55 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( INVALID_HANDLE_VALUE != FindFirstFileA( filename, &search_results ), "should STILL be able to find file\n" );
|
2002-05-06 22:12:55 +02:00
|
|
|
|
2004-12-27 18:26:37 +01:00
|
|
|
ret = DeleteFileA( filename );
|
|
|
|
ok( ret, "DeleteFile failed (%ld)\n", GetLastError( ) );
|
2003-05-19 23:50:32 +02:00
|
|
|
|
|
|
|
filehandle=_lcreat (slashname, 0); /* illegal name */
|
2003-10-22 01:42:50 +02:00
|
|
|
if (HFILE_ERROR==filehandle) {
|
|
|
|
err=GetLastError ();
|
|
|
|
ok (err==ERROR_INVALID_NAME || err==ERROR_PATH_NOT_FOUND,
|
2004-01-27 21:13:03 +01:00
|
|
|
"creating file \"%s\" failed with error %d\n", slashname, err);
|
2003-10-22 01:42:50 +02:00
|
|
|
} else { /* only NT succeeds */
|
2003-05-19 23:50:32 +02:00
|
|
|
_lclose(filehandle);
|
|
|
|
find=FindFirstFileA (slashname, &search_results);
|
2004-03-17 21:57:09 +01:00
|
|
|
if (INVALID_HANDLE_VALUE!=find)
|
|
|
|
{
|
2004-12-27 18:26:37 +01:00
|
|
|
ret = FindClose (find);
|
|
|
|
ok (0 != ret, "FindClose complains (%ld)\n", GetLastError ());
|
2003-05-19 23:50:32 +02:00
|
|
|
slashname[strlen(slashname)-1]=0;
|
|
|
|
ok (!strcmp (slashname, search_results.cFileName),
|
2004-01-27 21:13:03 +01:00
|
|
|
"found unexpected name \"%s\"\n", search_results.cFileName);
|
2003-05-19 23:50:32 +02:00
|
|
|
ok (FILE_ATTRIBUTE_ARCHIVE==search_results.dwFileAttributes,
|
2004-01-27 21:13:03 +01:00
|
|
|
"attributes of file \"%s\" are 0x%04lx\n", search_results.cFileName,
|
2003-05-19 23:50:32 +02:00
|
|
|
search_results.dwFileAttributes);
|
|
|
|
}
|
2004-12-27 18:26:37 +01:00
|
|
|
ret = DeleteFileA( slashname );
|
|
|
|
ok( ret, "DeleteFile failed (%ld)\n", GetLastError( ) );
|
2003-05-19 23:50:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
filehandle=_lcreat (filename, 8); /* illegal attribute */
|
|
|
|
if (HFILE_ERROR==filehandle)
|
2004-01-27 21:13:03 +01:00
|
|
|
ok (0, "couldn't create volume label \"%s\"\n", filename);
|
2003-05-19 23:50:32 +02:00
|
|
|
else {
|
|
|
|
_lclose(filehandle);
|
|
|
|
find=FindFirstFileA (filename, &search_results);
|
|
|
|
if (INVALID_HANDLE_VALUE==find)
|
2004-01-27 21:13:03 +01:00
|
|
|
ok (0, "file \"%s\" not found\n", filename);
|
2003-05-19 23:50:32 +02:00
|
|
|
else {
|
2004-12-27 18:26:37 +01:00
|
|
|
ret = FindClose(find);
|
|
|
|
ok ( 0 != ret, "FindClose complains (%ld)\n", GetLastError ());
|
2003-05-19 23:50:32 +02:00
|
|
|
ok (!strcmp (filename, search_results.cFileName),
|
2004-01-27 21:13:03 +01:00
|
|
|
"found unexpected name \"%s\"\n", search_results.cFileName);
|
2003-05-19 23:50:32 +02:00
|
|
|
ok (FILE_ATTRIBUTE_ARCHIVE==search_results.dwFileAttributes,
|
2004-01-27 21:13:03 +01:00
|
|
|
"attributes of file \"%s\" are 0x%04lx\n", search_results.cFileName,
|
2003-05-19 23:50:32 +02:00
|
|
|
search_results.dwFileAttributes);
|
|
|
|
}
|
2004-12-27 18:26:37 +01:00
|
|
|
ret = DeleteFileA( filename );
|
|
|
|
ok( ret, "DeleteFile failed (%ld)\n", GetLastError( ) );
|
2003-05-19 23:50:32 +02:00
|
|
|
}
|
2002-05-06 22:12:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-08 23:21:20 +01:00
|
|
|
static void test__llseek( void )
|
2002-05-06 22:12:55 +02:00
|
|
|
{
|
|
|
|
INT i;
|
|
|
|
HFILE filehandle;
|
|
|
|
char buffer[1];
|
|
|
|
long bytes_read;
|
2004-12-27 18:26:37 +01:00
|
|
|
BOOL ret;
|
2002-05-06 22:12:55 +02:00
|
|
|
|
|
|
|
filehandle = _lcreat( filename, 0 );
|
2002-05-23 18:29:37 +02:00
|
|
|
if (filehandle == HFILE_ERROR)
|
|
|
|
{
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
|
2002-05-23 18:29:37 +02:00
|
|
|
return;
|
|
|
|
}
|
2002-05-06 22:12:55 +02:00
|
|
|
|
|
|
|
for (i = 0; i < 400; i++)
|
|
|
|
{
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" );
|
2002-05-06 22:12:55 +02:00
|
|
|
}
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR != _llseek( filehandle, 400 * strlen( sillytext ), FILE_CURRENT ), "should be able to seek\n" );
|
|
|
|
ok( HFILE_ERROR != _llseek( filehandle, 27 + 35 * strlen( sillytext ), FILE_BEGIN ), "should be able to seek\n" );
|
2002-05-06 22:12:55 +02:00
|
|
|
|
|
|
|
bytes_read = _hread( filehandle, buffer, 1);
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( 1 == bytes_read, "file read size error\n" );
|
|
|
|
ok( buffer[0] == sillytext[27], "_llseek error, it got lost seeking\n" );
|
|
|
|
ok( HFILE_ERROR != _llseek( filehandle, -400 * strlen( sillytext ), FILE_END ), "should be able to seek\n" );
|
2002-05-06 22:12:55 +02:00
|
|
|
|
|
|
|
bytes_read = _hread( filehandle, buffer, 1);
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( 1 == bytes_read, "file read size error\n" );
|
|
|
|
ok( buffer[0] == sillytext[0], "_llseek error, it got lost seeking\n" );
|
|
|
|
ok( HFILE_ERROR != _llseek( filehandle, 1000000, FILE_END ), "should be able to seek past file; poor, poor Windows programmers\n" );
|
|
|
|
ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
|
2002-05-09 22:29:15 +02:00
|
|
|
|
2004-12-27 18:26:37 +01:00
|
|
|
ret = DeleteFileA( filename );
|
|
|
|
ok( ret, "DeleteFile failed (%ld)\n", GetLastError( ) );
|
2002-05-06 22:12:55 +02:00
|
|
|
}
|
|
|
|
|
2002-05-09 22:29:15 +02:00
|
|
|
|
|
|
|
static void test__llopen( void )
|
2002-05-06 22:12:55 +02:00
|
|
|
{
|
|
|
|
HFILE filehandle;
|
|
|
|
UINT bytes_read;
|
|
|
|
char buffer[10000];
|
2004-12-27 18:26:37 +01:00
|
|
|
BOOL ret;
|
2002-05-06 22:12:55 +02:00
|
|
|
|
|
|
|
filehandle = _lcreat( filename, 0 );
|
2002-05-23 18:29:37 +02:00
|
|
|
if (filehandle == HFILE_ERROR)
|
|
|
|
{
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
|
2002-05-23 18:29:37 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" );
|
|
|
|
ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
|
2002-05-06 22:12:55 +02:00
|
|
|
|
|
|
|
filehandle = _lopen( filename, OF_READ );
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR == _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite shouldn't be able to write!\n" );
|
2002-05-06 22:12:55 +02:00
|
|
|
bytes_read = _hread( filehandle, buffer, strlen( sillytext ) );
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( strlen( sillytext ) == bytes_read, "file read size error\n" );
|
|
|
|
ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
|
2002-05-23 18:29:37 +02:00
|
|
|
|
2002-05-06 22:12:55 +02:00
|
|
|
filehandle = _lopen( filename, OF_READWRITE );
|
|
|
|
bytes_read = _hread( filehandle, buffer, 2 * strlen( sillytext ) );
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( strlen( sillytext ) == bytes_read, "file read size error\n" );
|
|
|
|
ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite should write just fine\n" );
|
|
|
|
ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
|
2002-05-06 22:12:55 +02:00
|
|
|
|
|
|
|
filehandle = _lopen( filename, OF_WRITE );
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR == _hread( filehandle, buffer, 1 ), "you should only be able to write this file\n" );
|
|
|
|
ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite should write just fine\n" );
|
|
|
|
ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
|
2002-05-06 22:12:55 +02:00
|
|
|
|
2004-12-27 18:26:37 +01:00
|
|
|
ret = DeleteFileA( filename );
|
|
|
|
ok( ret, "DeleteFile failed (%ld)\n", GetLastError( ) );
|
2002-05-09 22:29:15 +02:00
|
|
|
/* TODO - add tests for the SHARE modes - use two processes to pull this one off */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void test__lread( void )
|
|
|
|
{
|
|
|
|
HFILE filehandle;
|
|
|
|
char buffer[10000];
|
|
|
|
long bytes_read;
|
|
|
|
UINT bytes_wanted;
|
|
|
|
UINT i;
|
2004-12-27 18:26:37 +01:00
|
|
|
BOOL ret;
|
2002-05-09 22:29:15 +02:00
|
|
|
|
|
|
|
filehandle = _lcreat( filename, 0 );
|
2002-05-23 18:29:37 +02:00
|
|
|
if (filehandle == HFILE_ERROR)
|
|
|
|
{
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
|
2002-05-23 18:29:37 +02:00
|
|
|
return;
|
|
|
|
}
|
2002-05-09 22:29:15 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" );
|
2002-05-09 22:29:15 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
|
2002-05-09 22:29:15 +02:00
|
|
|
|
|
|
|
filehandle = _lopen( filename, OF_READ );
|
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR != filehandle, "couldn't open file \"%s\" again (err=%ld)\n", filename, GetLastError());
|
2002-05-23 18:29:37 +02:00
|
|
|
|
2002-05-09 22:29:15 +02:00
|
|
|
bytes_read = _lread( filehandle, buffer, 2 * strlen( sillytext ) );
|
2002-05-23 18:29:37 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( lstrlenA( sillytext ) == bytes_read, "file read size error\n" );
|
2002-05-09 22:29:15 +02:00
|
|
|
|
|
|
|
for (bytes_wanted = 0; bytes_wanted < strlen( sillytext ); bytes_wanted++)
|
|
|
|
{
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( 0 == _llseek( filehandle, 0, FILE_BEGIN ), "_llseek complains\n" );
|
|
|
|
ok( _lread( filehandle, buffer, bytes_wanted ) == bytes_wanted, "erratic _hread return value\n" );
|
2002-05-09 22:29:15 +02:00
|
|
|
for (i = 0; i < bytes_wanted; i++)
|
|
|
|
{
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( buffer[i] == sillytext[i], "that's not what's written\n" );
|
2002-05-09 22:29:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
|
2002-05-09 22:29:15 +02:00
|
|
|
|
2004-12-27 18:26:37 +01:00
|
|
|
ret = DeleteFileA( filename );
|
|
|
|
ok( ret, "DeleteFile failed (%ld)\n", GetLastError( ) );
|
2002-05-06 22:12:55 +02:00
|
|
|
}
|
|
|
|
|
2002-05-09 22:29:15 +02:00
|
|
|
|
|
|
|
static void test__lwrite( void )
|
|
|
|
{
|
|
|
|
HFILE filehandle;
|
|
|
|
char buffer[10000];
|
|
|
|
long bytes_read;
|
2002-12-18 03:22:51 +01:00
|
|
|
long bytes_written;
|
|
|
|
long blocks;
|
|
|
|
long i;
|
2002-05-09 22:29:15 +02:00
|
|
|
char *contents;
|
|
|
|
HLOCAL memory_object;
|
|
|
|
char checksum[1];
|
2004-12-27 18:26:37 +01:00
|
|
|
BOOL ret;
|
2002-05-09 22:29:15 +02:00
|
|
|
|
|
|
|
filehandle = _lcreat( filename, 0 );
|
2002-05-23 18:29:37 +02:00
|
|
|
if (filehandle == HFILE_ERROR)
|
|
|
|
{
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
|
2002-05-23 18:29:37 +02:00
|
|
|
return;
|
|
|
|
}
|
2002-05-09 22:29:15 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR != _lwrite( filehandle, "", 0 ), "_hwrite complains\n" );
|
2002-05-09 22:29:15 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
|
2002-05-09 22:29:15 +02:00
|
|
|
|
|
|
|
filehandle = _lopen( filename, OF_READ );
|
2002-05-23 18:29:37 +02:00
|
|
|
|
2002-05-09 22:29:15 +02:00
|
|
|
bytes_read = _hread( filehandle, buffer, 1);
|
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( 0 == bytes_read, "file read size error\n" );
|
2002-05-09 22:29:15 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
|
2002-05-09 22:29:15 +02:00
|
|
|
|
|
|
|
filehandle = _lopen( filename, OF_READWRITE );
|
|
|
|
|
|
|
|
bytes_written = 0;
|
|
|
|
checksum[0] = '\0';
|
|
|
|
srand( (unsigned)time( NULL ) );
|
|
|
|
for (blocks = 0; blocks < 100; blocks++)
|
|
|
|
{
|
2003-07-19 05:06:19 +02:00
|
|
|
for (i = 0; i < (long)sizeof( buffer ); i++)
|
2002-05-09 22:29:15 +02:00
|
|
|
{
|
|
|
|
buffer[i] = rand( );
|
|
|
|
checksum[0] = checksum[0] + buffer[i];
|
|
|
|
}
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR != _lwrite( filehandle, buffer, sizeof( buffer ) ), "_hwrite complains\n" );
|
2002-05-09 22:29:15 +02:00
|
|
|
bytes_written = bytes_written + sizeof( buffer );
|
|
|
|
}
|
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR != _lwrite( filehandle, checksum, 1 ), "_hwrite complains\n" );
|
2002-05-09 22:29:15 +02:00
|
|
|
bytes_written++;
|
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains\n" );
|
2002-05-09 22:29:15 +02:00
|
|
|
|
|
|
|
memory_object = LocalAlloc( LPTR, bytes_written );
|
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( 0 != memory_object, "LocalAlloc fails, could be out of memory\n" );
|
2002-05-09 22:29:15 +02:00
|
|
|
|
|
|
|
contents = LocalLock( memory_object );
|
|
|
|
|
|
|
|
filehandle = _lopen( filename, OF_READ );
|
|
|
|
|
|
|
|
contents = LocalLock( memory_object );
|
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( NULL != contents, "LocalLock whines\n" );
|
2002-05-09 22:29:15 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( bytes_written == _hread( filehandle, contents, bytes_written), "read length differ from write length\n" );
|
2002-05-09 22:29:15 +02:00
|
|
|
|
|
|
|
checksum[0] = '\0';
|
|
|
|
i = 0;
|
|
|
|
do
|
|
|
|
{
|
2002-05-29 18:58:14 +02:00
|
|
|
checksum[0] += contents[i];
|
2002-05-09 22:29:15 +02:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
while (i < bytes_written - 1);
|
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( checksum[0] == contents[i], "stored checksum differ from computed checksum\n" );
|
2002-05-10 03:10:04 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains\n" );
|
2002-05-09 22:29:15 +02:00
|
|
|
|
2004-12-27 18:26:37 +01:00
|
|
|
ret = DeleteFileA( filename );
|
|
|
|
ok( ret, "DeleteFile failed (%ld)\n", GetLastError( ) );
|
2002-05-09 22:29:15 +02:00
|
|
|
}
|
|
|
|
|
2003-12-08 23:21:20 +01:00
|
|
|
static void test_CopyFileA(void)
|
2002-08-27 03:56:08 +02:00
|
|
|
{
|
|
|
|
char temp_path[MAX_PATH];
|
|
|
|
char source[MAX_PATH], dest[MAX_PATH];
|
|
|
|
static const char prefix[] = "pfx";
|
2004-05-22 05:14:17 +02:00
|
|
|
HANDLE hfile;
|
2005-03-01 11:42:04 +01:00
|
|
|
FILETIME ft1, ft2;
|
2004-05-22 05:14:17 +02:00
|
|
|
char buf[10];
|
2002-08-27 03:56:08 +02:00
|
|
|
DWORD ret;
|
2004-12-27 18:26:37 +01:00
|
|
|
BOOL retok;
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
ret = GetTempPathA(MAX_PATH, temp_path);
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(ret != 0, "GetTempPathA error %ld\n", GetLastError());
|
|
|
|
ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
ret = GetTempFileNameA(temp_path, prefix, 0, source);
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(ret != 0, "GetTempFileNameA error %ld\n", GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
|
2004-05-22 05:14:17 +02:00
|
|
|
/* make the source have not zero size */
|
|
|
|
hfile = CreateFileA(source, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0 );
|
|
|
|
ok(hfile != INVALID_HANDLE_VALUE, "failed to open source file\n");
|
2004-12-27 18:26:37 +01:00
|
|
|
retok = WriteFile(hfile, prefix, sizeof(prefix), &ret, NULL );
|
|
|
|
ok( retok && ret == sizeof(prefix),
|
2004-05-22 05:14:17 +02:00
|
|
|
"WriteFile error %ld\n", GetLastError());
|
|
|
|
ok(GetFileSize(hfile, NULL) == sizeof(prefix), "source file has wrong size\n");
|
2005-03-01 11:42:04 +01:00
|
|
|
/* get the file time and change it to prove the difference */
|
2005-03-31 21:07:08 +02:00
|
|
|
ret = GetFileTime(hfile, NULL, NULL, &ft1);
|
|
|
|
ok( ret, "GetFileTime error %ld\n", GetLastError());
|
2005-03-01 11:42:04 +01:00
|
|
|
ft1.dwLowDateTime -= 600000000; /* 60 second */
|
2005-03-31 21:07:08 +02:00
|
|
|
ret = SetFileTime(hfile, NULL, NULL, &ft1);
|
|
|
|
ok( ret, "SetFileTime error %ld\n", GetLastError());
|
2005-03-22 22:14:51 +01:00
|
|
|
GetFileTime(hfile, NULL, NULL, &ft1); /* get the actual time back */
|
2004-05-22 05:14:17 +02:00
|
|
|
CloseHandle(hfile);
|
|
|
|
|
2002-08-27 03:56:08 +02:00
|
|
|
ret = GetTempFileNameA(temp_path, prefix, 0, dest);
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(ret != 0, "GetTempFileNameA error %ld\n", GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
|
2004-05-22 05:14:17 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2002-08-27 03:56:08 +02:00
|
|
|
ret = CopyFileA(source, dest, TRUE);
|
|
|
|
ok(!ret && GetLastError() == ERROR_FILE_EXISTS,
|
|
|
|
"CopyFileA: unexpected error %ld\n", GetLastError());
|
|
|
|
|
|
|
|
ret = CopyFileA(source, dest, FALSE);
|
2004-05-22 05:14:17 +02:00
|
|
|
ok(ret, "CopyFileA: error %ld\n", GetLastError());
|
|
|
|
|
|
|
|
/* make sure that destination has correct size */
|
|
|
|
hfile = CreateFileA(dest, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
|
|
|
|
ok(hfile != INVALID_HANDLE_VALUE, "failed to open destination file\n");
|
|
|
|
ret = GetFileSize(hfile, NULL);
|
|
|
|
ok(ret == sizeof(prefix), "destination file has wrong size %ld\n", ret);
|
|
|
|
|
2005-03-01 11:42:04 +01:00
|
|
|
/* make sure that destination has the same filetime */
|
2005-03-31 21:07:08 +02:00
|
|
|
ret = GetFileTime(hfile, NULL, NULL, &ft2);
|
|
|
|
ok( ret, "GetFileTime error %ld\n", GetLastError());
|
2005-03-02 14:53:50 +01:00
|
|
|
ok(CompareFileTime(&ft1, &ft2) == 0, "destination file has wrong filetime\n");
|
2005-03-01 11:42:04 +01:00
|
|
|
|
2004-05-22 05:14:17 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CopyFileA(source, dest, FALSE);
|
|
|
|
ok(!ret && GetLastError() == ERROR_SHARING_VIOLATION,
|
|
|
|
"CopyFileA: ret = %ld, unexpected error %ld\n", ret, GetLastError());
|
|
|
|
|
|
|
|
/* make sure that destination still has correct size */
|
|
|
|
ret = GetFileSize(hfile, NULL);
|
|
|
|
ok(ret == sizeof(prefix), "destination file has wrong size %ld\n", ret);
|
2004-12-27 18:26:37 +01:00
|
|
|
retok = ReadFile(hfile, buf, sizeof(buf), &ret, NULL);
|
|
|
|
ok( retok && ret == sizeof(prefix),
|
2004-05-22 05:14:17 +02:00
|
|
|
"ReadFile: error %ld\n", GetLastError());
|
|
|
|
ok(!memcmp(prefix, buf, sizeof(prefix)), "buffer contents mismatch\n");
|
|
|
|
CloseHandle(hfile);
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
ret = DeleteFileA(source);
|
|
|
|
ok(ret, "DeleteFileA: error %ld\n", GetLastError());
|
|
|
|
ret = DeleteFileA(dest);
|
|
|
|
ok(ret, "DeleteFileA: error %ld\n", GetLastError());
|
|
|
|
}
|
|
|
|
|
2003-12-08 23:21:20 +01:00
|
|
|
static void test_CopyFileW(void)
|
2002-08-27 03:56:08 +02:00
|
|
|
{
|
|
|
|
WCHAR temp_path[MAX_PATH];
|
|
|
|
WCHAR source[MAX_PATH], dest[MAX_PATH];
|
|
|
|
static const WCHAR prefix[] = {'p','f','x',0};
|
|
|
|
DWORD ret;
|
|
|
|
|
|
|
|
ret = GetTempPathW(MAX_PATH, temp_path);
|
2002-12-12 04:54:01 +01:00
|
|
|
if (ret==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
|
|
|
|
return;
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(ret != 0, "GetTempPathW error %ld\n", GetLastError());
|
|
|
|
ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
ret = GetTempFileNameW(temp_path, prefix, 0, source);
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(ret != 0, "GetTempFileNameW error %ld\n", GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
ret = GetTempFileNameW(temp_path, prefix, 0, dest);
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(ret != 0, "GetTempFileNameW error %ld\n", GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
ret = CopyFileW(source, dest, TRUE);
|
|
|
|
ok(!ret && GetLastError() == ERROR_FILE_EXISTS,
|
|
|
|
"CopyFileW: unexpected error %ld\n", GetLastError());
|
|
|
|
|
|
|
|
ret = CopyFileW(source, dest, FALSE);
|
2004-05-22 05:14:17 +02:00
|
|
|
ok(ret, "CopyFileW: error %ld\n", GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
ret = DeleteFileW(source);
|
|
|
|
ok(ret, "DeleteFileW: error %ld\n", GetLastError());
|
|
|
|
ret = DeleteFileW(dest);
|
|
|
|
ok(ret, "DeleteFileW: error %ld\n", GetLastError());
|
|
|
|
}
|
|
|
|
|
2003-12-08 23:21:20 +01:00
|
|
|
static void test_CreateFileA(void)
|
2002-08-27 03:56:08 +02:00
|
|
|
{
|
|
|
|
HANDLE hFile;
|
|
|
|
char temp_path[MAX_PATH];
|
|
|
|
char filename[MAX_PATH];
|
|
|
|
static const char prefix[] = "pfx";
|
|
|
|
DWORD ret;
|
|
|
|
|
|
|
|
ret = GetTempPathA(MAX_PATH, temp_path);
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(ret != 0, "GetTempPathA error %ld\n", GetLastError());
|
|
|
|
ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
ret = GetTempFileNameA(temp_path, prefix, 0, filename);
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(ret != 0, "GetTempFileNameA error %ld\n", GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
hFile = CreateFileA(filename, GENERIC_READ, 0, NULL,
|
|
|
|
CREATE_NEW, FILE_FLAG_RANDOM_ACCESS, 0);
|
|
|
|
ok(hFile == INVALID_HANDLE_VALUE && GetLastError() == ERROR_FILE_EXISTS,
|
2004-01-27 21:13:03 +01:00
|
|
|
"CREATE_NEW should fail if file exists and last error value should be ERROR_FILE_EXISTS\n");
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
ret = DeleteFileA(filename);
|
|
|
|
ok(ret, "DeleteFileA: error %ld\n", GetLastError());
|
|
|
|
}
|
|
|
|
|
2003-12-08 23:21:20 +01:00
|
|
|
static void test_CreateFileW(void)
|
2002-08-27 03:56:08 +02:00
|
|
|
{
|
|
|
|
HANDLE hFile;
|
|
|
|
WCHAR temp_path[MAX_PATH];
|
|
|
|
WCHAR filename[MAX_PATH];
|
2004-04-20 03:12:17 +02:00
|
|
|
static const WCHAR emptyW[]={'\0'};
|
2002-08-27 03:56:08 +02:00
|
|
|
static const WCHAR prefix[] = {'p','f','x',0};
|
2004-07-06 23:31:24 +02:00
|
|
|
static const WCHAR bogus[] = { '\\', '\\', '.', '\\', 'B', 'O', 'G', 'U', 'S', 0 };
|
2002-08-27 03:56:08 +02:00
|
|
|
DWORD ret;
|
|
|
|
|
|
|
|
ret = GetTempPathW(MAX_PATH, temp_path);
|
2002-12-12 04:54:01 +01:00
|
|
|
if (ret==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
|
|
|
|
return;
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(ret != 0, "GetTempPathW error %ld\n", GetLastError());
|
|
|
|
ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
ret = GetTempFileNameW(temp_path, prefix, 0, filename);
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(ret != 0, "GetTempFileNameW error %ld\n", GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
hFile = CreateFileW(filename, GENERIC_READ, 0, NULL,
|
|
|
|
CREATE_NEW, FILE_FLAG_RANDOM_ACCESS, 0);
|
|
|
|
ok(hFile == INVALID_HANDLE_VALUE && GetLastError() == ERROR_FILE_EXISTS,
|
2004-01-27 21:13:03 +01:00
|
|
|
"CREATE_NEW should fail if file exists and last error value should be ERROR_FILE_EXISTS\n");
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
ret = DeleteFileW(filename);
|
|
|
|
ok(ret, "DeleteFileW: error %ld\n", GetLastError());
|
2004-04-03 02:05:24 +02:00
|
|
|
|
2005-04-19 13:59:46 +02:00
|
|
|
#if 0 /* this test crashes on NT4.0 */
|
2004-04-03 02:05:24 +02:00
|
|
|
hFile = CreateFileW(NULL, GENERIC_READ, 0, NULL,
|
|
|
|
CREATE_NEW, FILE_FLAG_RANDOM_ACCESS, 0);
|
|
|
|
ok(hFile == INVALID_HANDLE_VALUE && GetLastError() == ERROR_PATH_NOT_FOUND,
|
|
|
|
"CreateFileW(NULL) returned ret=%p error=%ld\n",hFile,GetLastError());
|
2005-04-19 13:59:46 +02:00
|
|
|
#endif
|
2004-04-03 02:05:24 +02:00
|
|
|
|
|
|
|
hFile = CreateFileW(emptyW, GENERIC_READ, 0, NULL,
|
|
|
|
CREATE_NEW, FILE_FLAG_RANDOM_ACCESS, 0);
|
|
|
|
ok(hFile == INVALID_HANDLE_VALUE && GetLastError() == ERROR_PATH_NOT_FOUND,
|
|
|
|
"CreateFileW(\"\") returned ret=%p error=%ld\n",hFile,GetLastError());
|
2004-07-06 23:31:24 +02:00
|
|
|
|
2005-02-10 20:19:35 +01:00
|
|
|
/* test the result of opening a nonexistent driver name */
|
2004-07-06 23:31:24 +02:00
|
|
|
hFile = CreateFileW(bogus, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
|
|
|
|
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
ok(hFile == INVALID_HANDLE_VALUE && GetLastError() == ERROR_FILE_NOT_FOUND,
|
|
|
|
"CreateFileW on invalid VxD name returned ret=%p error=%ld\n",hFile,GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
}
|
|
|
|
|
2005-06-20 16:18:03 +02:00
|
|
|
static void test_GetTempFileNameA(void)
|
2004-04-23 01:44:14 +02:00
|
|
|
{
|
2004-01-16 05:49:13 +01:00
|
|
|
UINT result;
|
|
|
|
char out[MAX_PATH];
|
2004-04-23 01:44:14 +02:00
|
|
|
char expected[MAX_PATH + 10];
|
|
|
|
char windowsdir[MAX_PATH + 10];
|
|
|
|
char windowsdrive[3];
|
2004-01-16 05:49:13 +01:00
|
|
|
|
2004-04-23 01:44:14 +02:00
|
|
|
result = GetWindowsDirectory(windowsdir, sizeof(windowsdir));
|
|
|
|
ok(result < sizeof(windowsdir), "windowsdir is abnormally long!\n");
|
|
|
|
ok(result != 0, "GetWindowsDirectory: error %ld\n", GetLastError());
|
2004-01-16 05:49:13 +01:00
|
|
|
|
2004-04-23 01:44:14 +02:00
|
|
|
/* If the Windows directory is the root directory, it ends in backslash, not else. */
|
|
|
|
if (strlen(windowsdir) != 3) /* As in "C:\" or "F:\" */
|
|
|
|
{
|
|
|
|
strcat(windowsdir, "\\");
|
|
|
|
}
|
2004-01-16 05:49:13 +01:00
|
|
|
|
2004-04-23 01:44:14 +02:00
|
|
|
windowsdrive[0] = windowsdir[0];
|
|
|
|
windowsdrive[1] = windowsdir[1];
|
|
|
|
windowsdrive[2] = '\0';
|
|
|
|
|
|
|
|
result = GetTempFileNameA(windowsdrive, "abc", 1, out);
|
|
|
|
ok(result != 0, "GetTempFileNameA: error %ld\n", GetLastError());
|
|
|
|
ok(((out[0] == windowsdrive[0]) && (out[1] == ':')) && (out[2] == '\\'),
|
|
|
|
"GetTempFileNameA: first three characters should be %c:\\, string was actually %s\n",
|
|
|
|
windowsdrive[0], out);
|
|
|
|
|
|
|
|
result = GetTempFileNameA(windowsdir, "abc", 2, out);
|
|
|
|
ok(result != 0, "GetTempFileNameA: error %ld\n", GetLastError());
|
|
|
|
expected[0] = '\0';
|
|
|
|
strcat(expected, windowsdir);
|
|
|
|
strcat(expected, "abc2.tmp");
|
|
|
|
ok(lstrcmpiA(out, expected) == 0, "GetTempFileNameA: Unexpected output \"%s\" vs \"%s\"\n",
|
|
|
|
out, expected);
|
|
|
|
}
|
2004-01-16 05:49:13 +01:00
|
|
|
|
2002-11-12 03:11:52 +01:00
|
|
|
static void test_DeleteFileA( void )
|
|
|
|
{
|
|
|
|
BOOL ret;
|
2002-12-12 04:54:01 +01:00
|
|
|
|
|
|
|
ret = DeleteFileA(NULL);
|
|
|
|
ok(!ret && (GetLastError() == ERROR_INVALID_PARAMETER ||
|
|
|
|
GetLastError() == ERROR_PATH_NOT_FOUND),
|
2004-01-27 21:13:03 +01:00
|
|
|
"DeleteFileA(NULL) returned ret=%d error=%ld\n",ret,GetLastError());
|
2002-12-12 04:54:01 +01:00
|
|
|
|
2002-11-12 03:11:52 +01:00
|
|
|
ret = DeleteFileA("");
|
2002-12-12 04:54:01 +01:00
|
|
|
ok(!ret && (GetLastError() == ERROR_PATH_NOT_FOUND ||
|
|
|
|
GetLastError() == ERROR_BAD_PATHNAME),
|
2004-01-27 21:13:03 +01:00
|
|
|
"DeleteFileA(\"\") returned ret=%d error=%ld\n",ret,GetLastError());
|
2004-04-03 02:05:24 +02:00
|
|
|
|
|
|
|
ret = DeleteFileA("nul");
|
|
|
|
ok(!ret && (GetLastError() == ERROR_FILE_NOT_FOUND ||
|
2004-04-28 05:52:02 +02:00
|
|
|
GetLastError() == ERROR_INVALID_PARAMETER ||
|
|
|
|
GetLastError() == ERROR_ACCESS_DENIED),
|
2004-04-03 02:05:24 +02:00
|
|
|
"DeleteFileA(\"nul\") returned ret=%d error=%ld\n",ret,GetLastError());
|
2002-12-12 04:54:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_DeleteFileW( void )
|
|
|
|
{
|
|
|
|
BOOL ret;
|
2004-04-20 03:12:17 +02:00
|
|
|
static const WCHAR emptyW[]={'\0'};
|
2002-12-12 04:54:01 +01:00
|
|
|
|
|
|
|
ret = DeleteFileW(NULL);
|
|
|
|
if (ret==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
|
|
|
|
return;
|
|
|
|
ok(!ret && GetLastError() == ERROR_PATH_NOT_FOUND,
|
2004-01-27 21:13:03 +01:00
|
|
|
"DeleteFileW(NULL) returned ret=%d error=%ld\n",ret,GetLastError());
|
2002-12-12 04:54:01 +01:00
|
|
|
|
|
|
|
ret = DeleteFileW(emptyW);
|
|
|
|
ok(!ret && GetLastError() == ERROR_PATH_NOT_FOUND,
|
2004-01-27 21:13:03 +01:00
|
|
|
"DeleteFileW(\"\") returned ret=%d error=%ld\n",ret,GetLastError());
|
2002-11-12 03:11:52 +01:00
|
|
|
}
|
|
|
|
|
2003-09-16 03:19:21 +02:00
|
|
|
#define IsDotDir(x) ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))))
|
|
|
|
|
2003-12-08 23:21:20 +01:00
|
|
|
static void test_MoveFileA(void)
|
2003-09-16 03:19:21 +02:00
|
|
|
{
|
|
|
|
char tempdir[MAX_PATH];
|
|
|
|
char source[MAX_PATH], dest[MAX_PATH];
|
|
|
|
static const char prefix[] = "pfx";
|
|
|
|
DWORD ret;
|
|
|
|
|
|
|
|
ret = GetTempPathA(MAX_PATH, tempdir);
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(ret != 0, "GetTempPathA error %ld\n", GetLastError());
|
|
|
|
ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
|
2003-09-16 03:19:21 +02:00
|
|
|
|
|
|
|
ret = GetTempFileNameA(tempdir, prefix, 0, source);
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(ret != 0, "GetTempFileNameA error %ld\n", GetLastError());
|
2003-09-16 03:19:21 +02:00
|
|
|
|
|
|
|
ret = GetTempFileNameA(tempdir, prefix, 0, dest);
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(ret != 0, "GetTempFileNameA error %ld\n", GetLastError());
|
2003-09-16 03:19:21 +02:00
|
|
|
|
|
|
|
ret = MoveFileA(source, dest);
|
2003-12-15 21:15:20 +01:00
|
|
|
ok(!ret && GetLastError() == ERROR_ALREADY_EXISTS,
|
2003-09-16 03:19:21 +02:00
|
|
|
"MoveFileA: unexpected error %ld\n", GetLastError());
|
|
|
|
|
|
|
|
ret = DeleteFileA(dest);
|
|
|
|
ok(ret, "DeleteFileA: error %ld\n", GetLastError());
|
|
|
|
|
|
|
|
ret = MoveFileA(source, dest);
|
|
|
|
ok(ret, "MoveFileA: failed, error %ld\n", GetLastError());
|
|
|
|
|
|
|
|
lstrcatA(tempdir, "Remove Me");
|
|
|
|
ret = CreateDirectoryA(tempdir, NULL);
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(ret == TRUE, "CreateDirectoryA failed\n");
|
2003-09-16 03:19:21 +02:00
|
|
|
|
|
|
|
lstrcpyA(source, dest);
|
|
|
|
lstrcpyA(dest, tempdir);
|
|
|
|
lstrcatA(dest, "\\wild?.*");
|
2004-04-03 02:05:24 +02:00
|
|
|
/* FIXME: if we create a file with wildcards we can't delete it now that DeleteFile works correctly */
|
2003-09-16 03:19:21 +02:00
|
|
|
ret = MoveFileA(source, dest);
|
2004-04-27 04:27:47 +02:00
|
|
|
ok(!ret, "MoveFileA: shouldn't move to wildcard file\n");
|
2004-05-25 02:20:50 +02:00
|
|
|
ok(GetLastError() == ERROR_INVALID_NAME || /* NT */
|
|
|
|
GetLastError() == ERROR_FILE_NOT_FOUND, /* Win9x */
|
2004-04-27 04:27:47 +02:00
|
|
|
"MoveFileA: with wildcards, unexpected error %ld\n", GetLastError());
|
|
|
|
if (ret || (GetLastError() != ERROR_INVALID_NAME))
|
|
|
|
{
|
2003-09-16 03:19:21 +02:00
|
|
|
WIN32_FIND_DATAA fd;
|
|
|
|
char temppath[MAX_PATH];
|
|
|
|
HANDLE hFind;
|
2003-09-25 22:29:40 +02:00
|
|
|
|
2003-09-16 03:19:21 +02:00
|
|
|
lstrcpyA(temppath, tempdir);
|
|
|
|
lstrcatA(temppath, "\\*.*");
|
|
|
|
hFind = FindFirstFileA(temppath, &fd);
|
|
|
|
if (INVALID_HANDLE_VALUE != hFind)
|
2003-12-08 23:21:20 +01:00
|
|
|
{
|
2003-09-16 03:19:21 +02:00
|
|
|
LPSTR lpName;
|
|
|
|
do
|
2003-12-08 23:21:20 +01:00
|
|
|
{
|
2003-09-16 03:19:21 +02:00
|
|
|
lpName = fd.cAlternateFileName;
|
|
|
|
if (!lpName[0])
|
|
|
|
lpName = fd.cFileName;
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(IsDotDir(lpName), "MoveFileA: wildcards file created!\n");
|
2003-12-08 23:21:20 +01:00
|
|
|
}
|
2003-09-16 03:19:21 +02:00
|
|
|
while (FindNextFileA(hFind, &fd));
|
|
|
|
FindClose(hFind);
|
2003-12-08 23:21:20 +01:00
|
|
|
}
|
2003-09-16 03:19:21 +02:00
|
|
|
}
|
2004-04-27 04:27:47 +02:00
|
|
|
ret = DeleteFileA(source);
|
|
|
|
ok(ret, "DeleteFileA: error %ld\n", GetLastError());
|
|
|
|
ret = DeleteFileA(dest);
|
|
|
|
ok(!ret, "DeleteFileA: error %ld\n", GetLastError());
|
2003-09-16 03:19:21 +02:00
|
|
|
ret = RemoveDirectoryA(tempdir);
|
|
|
|
ok(ret, "DeleteDirectoryA: error %ld\n", GetLastError());
|
|
|
|
}
|
|
|
|
|
2003-12-08 23:21:20 +01:00
|
|
|
static void test_MoveFileW(void)
|
2003-09-16 03:19:21 +02:00
|
|
|
{
|
|
|
|
WCHAR temp_path[MAX_PATH];
|
|
|
|
WCHAR source[MAX_PATH], dest[MAX_PATH];
|
|
|
|
static const WCHAR prefix[] = {'p','f','x',0};
|
|
|
|
DWORD ret;
|
|
|
|
|
|
|
|
ret = GetTempPathW(MAX_PATH, temp_path);
|
|
|
|
if (ret==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
|
|
|
|
return;
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(ret != 0, "GetTempPathW error %ld\n", GetLastError());
|
|
|
|
ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
|
2003-09-16 03:19:21 +02:00
|
|
|
|
|
|
|
ret = GetTempFileNameW(temp_path, prefix, 0, source);
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(ret != 0, "GetTempFileNameW error %ld\n", GetLastError());
|
2003-09-16 03:19:21 +02:00
|
|
|
|
|
|
|
ret = GetTempFileNameW(temp_path, prefix, 0, dest);
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(ret != 0, "GetTempFileNameW error %ld\n", GetLastError());
|
2003-09-16 03:19:21 +02:00
|
|
|
|
|
|
|
ret = MoveFileW(source, dest);
|
2003-12-15 21:15:20 +01:00
|
|
|
ok(!ret && GetLastError() == ERROR_ALREADY_EXISTS,
|
2003-09-16 03:19:21 +02:00
|
|
|
"CopyFileW: unexpected error %ld\n", GetLastError());
|
|
|
|
|
|
|
|
ret = DeleteFileW(source);
|
|
|
|
ok(ret, "DeleteFileW: error %ld\n", GetLastError());
|
|
|
|
ret = DeleteFileW(dest);
|
|
|
|
ok(ret, "DeleteFileW: error %ld\n", GetLastError());
|
|
|
|
}
|
|
|
|
|
2002-12-12 04:54:01 +01:00
|
|
|
#define PATTERN_OFFSET 0x10
|
2002-08-27 03:56:08 +02:00
|
|
|
|
2003-12-08 23:21:20 +01:00
|
|
|
static void test_offset_in_overlapped_structure(void)
|
2002-08-27 03:56:08 +02:00
|
|
|
{
|
|
|
|
HANDLE hFile;
|
|
|
|
OVERLAPPED ov;
|
|
|
|
DWORD done;
|
2003-02-11 23:11:56 +01:00
|
|
|
BOOL rc;
|
2002-08-27 03:56:08 +02:00
|
|
|
BYTE buf[256], pattern[] = "TeSt";
|
|
|
|
UINT i;
|
|
|
|
char temp_path[MAX_PATH], temp_fname[MAX_PATH];
|
2004-12-27 18:26:37 +01:00
|
|
|
BOOL ret;
|
2002-08-27 03:56:08 +02:00
|
|
|
|
2004-12-27 18:26:37 +01:00
|
|
|
ret =GetTempPathA(MAX_PATH, temp_path);
|
|
|
|
ok( ret, "GetTempPathA error %ld\n", GetLastError());
|
|
|
|
ret =GetTempFileNameA(temp_path, "pfx", 0, temp_fname);
|
|
|
|
ok( ret, "GetTempFileNameA error %ld\n", GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
/*** Write File *****************************************************/
|
|
|
|
|
|
|
|
hFile = CreateFileA(temp_fname, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(hFile != INVALID_HANDLE_VALUE, "CreateFileA error %ld\n", GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
for(i = 0; i < sizeof(buf); i++) buf[i] = i;
|
2004-12-27 18:26:37 +01:00
|
|
|
ret = WriteFile(hFile, buf, sizeof(buf), &done, NULL);
|
|
|
|
ok( ret, "WriteFile error %ld\n", GetLastError());
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(done == sizeof(buf), "expected number of bytes written %lu\n", done);
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
memset(&ov, 0, sizeof(ov));
|
2005-03-17 20:00:08 +01:00
|
|
|
S(U(ov)).Offset = PATTERN_OFFSET;
|
|
|
|
S(U(ov)).OffsetHigh = 0;
|
2003-02-11 23:11:56 +01:00
|
|
|
rc=WriteFile(hFile, pattern, sizeof(pattern), &done, &ov);
|
|
|
|
/* Win 9x does not support the overlapped I/O on files */
|
|
|
|
if (rc || GetLastError()!=ERROR_INVALID_PARAMETER) {
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(rc, "WriteFile error %ld\n", GetLastError());
|
|
|
|
ok(done == sizeof(pattern), "expected number of bytes written %lu\n", done);
|
2004-04-03 02:05:24 +02:00
|
|
|
/*trace("Current offset = %04lx\n", SetFilePointer(hFile, 0, NULL, FILE_CURRENT));*/
|
2003-02-11 23:11:56 +01:00
|
|
|
ok(SetFilePointer(hFile, 0, NULL, FILE_CURRENT) == (PATTERN_OFFSET + sizeof(pattern)),
|
2004-01-27 21:13:03 +01:00
|
|
|
"expected file offset %d\n", PATTERN_OFFSET + sizeof(pattern));
|
2003-02-11 23:11:56 +01:00
|
|
|
|
2005-03-17 20:00:08 +01:00
|
|
|
S(U(ov)).Offset = sizeof(buf) * 2;
|
|
|
|
S(U(ov)).OffsetHigh = 0;
|
2004-12-27 18:26:37 +01:00
|
|
|
ret = WriteFile(hFile, pattern, sizeof(pattern), &done, &ov);
|
|
|
|
ok( ret, "WriteFile error %ld\n", GetLastError());
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(done == sizeof(pattern), "expected number of bytes written %lu\n", done);
|
2003-02-11 23:11:56 +01:00
|
|
|
/*trace("Current offset = %04lx\n", SetFilePointer(hFile, 0, NULL, FILE_CURRENT));*/
|
|
|
|
ok(SetFilePointer(hFile, 0, NULL, FILE_CURRENT) == (sizeof(buf) * 2 + sizeof(pattern)),
|
2004-01-27 21:13:03 +01:00
|
|
|
"expected file offset %d\n", sizeof(buf) * 2 + sizeof(pattern));
|
2003-02-11 23:11:56 +01:00
|
|
|
}
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
CloseHandle(hFile);
|
|
|
|
|
|
|
|
/*** Read File *****************************************************/
|
|
|
|
|
|
|
|
hFile = CreateFileA(temp_fname, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0);
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(hFile != INVALID_HANDLE_VALUE, "CreateFileA error %ld\n", GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
memset(buf, 0, sizeof(buf));
|
|
|
|
memset(&ov, 0, sizeof(ov));
|
2005-03-17 20:00:08 +01:00
|
|
|
S(U(ov)).Offset = PATTERN_OFFSET;
|
|
|
|
S(U(ov)).OffsetHigh = 0;
|
2003-02-11 23:11:56 +01:00
|
|
|
rc=ReadFile(hFile, buf, sizeof(pattern), &done, &ov);
|
|
|
|
/* Win 9x does not support the overlapped I/O on files */
|
|
|
|
if (rc || GetLastError()!=ERROR_INVALID_PARAMETER) {
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(rc, "ReadFile error %ld\n", GetLastError());
|
|
|
|
ok(done == sizeof(pattern), "expected number of bytes read %lu\n", done);
|
2004-04-03 02:05:24 +02:00
|
|
|
/*trace("Current offset = %04lx\n", SetFilePointer(hFile, 0, NULL, FILE_CURRENT));*/
|
2003-02-11 23:11:56 +01:00
|
|
|
ok(SetFilePointer(hFile, 0, NULL, FILE_CURRENT) == (PATTERN_OFFSET + sizeof(pattern)),
|
2004-01-27 21:13:03 +01:00
|
|
|
"expected file offset %d\n", PATTERN_OFFSET + sizeof(pattern));
|
|
|
|
ok(!memcmp(buf, pattern, sizeof(pattern)), "pattern match failed\n");
|
2003-02-11 23:11:56 +01:00
|
|
|
}
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
CloseHandle(hFile);
|
|
|
|
|
2004-12-27 18:26:37 +01:00
|
|
|
ret = DeleteFileA(temp_fname);
|
|
|
|
ok( ret, "DeleteFileA error %ld\n", GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
}
|
2002-05-09 22:29:15 +02:00
|
|
|
|
2003-03-18 06:04:33 +01:00
|
|
|
static void test_LockFile(void)
|
|
|
|
{
|
|
|
|
HANDLE handle;
|
|
|
|
DWORD written;
|
|
|
|
OVERLAPPED overlapped;
|
2004-04-28 05:52:02 +02:00
|
|
|
int limited_LockFile;
|
|
|
|
int limited_UnLockFile;
|
|
|
|
int lockfileex_capable;
|
2003-03-18 06:04:33 +01:00
|
|
|
|
|
|
|
handle = CreateFileA( filename, GENERIC_READ | GENERIC_WRITE,
|
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
|
|
|
|
CREATE_ALWAYS, 0, 0 );
|
|
|
|
if (handle == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
|
2003-03-18 06:04:33 +01:00
|
|
|
return;
|
|
|
|
}
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( WriteFile( handle, sillytext, strlen(sillytext), &written, NULL ), "write failed\n" );
|
2003-03-18 06:04:33 +01:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( LockFile( handle, 0, 0, 0, 0 ), "LockFile failed\n" );
|
|
|
|
ok( UnlockFile( handle, 0, 0, 0, 0 ), "UnlockFile failed\n" );
|
2004-04-28 05:52:02 +02:00
|
|
|
|
|
|
|
limited_UnLockFile = 0;
|
|
|
|
if (UnlockFile( handle, 0, 0, 0, 0 ))
|
|
|
|
{
|
|
|
|
limited_UnLockFile = 1;
|
|
|
|
}
|
2003-03-18 06:04:33 +01:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( LockFile( handle, 10, 0, 20, 0 ), "LockFile 10,20 failed\n" );
|
2003-03-18 06:04:33 +01:00
|
|
|
/* overlapping locks must fail */
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( !LockFile( handle, 12, 0, 10, 0 ), "LockFile 12,10 succeeded\n" );
|
|
|
|
ok( !LockFile( handle, 5, 0, 6, 0 ), "LockFile 5,6 succeeded\n" );
|
2003-03-18 06:04:33 +01:00
|
|
|
/* non-overlapping locks must succeed */
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( LockFile( handle, 5, 0, 5, 0 ), "LockFile 5,5 failed\n" );
|
2003-03-18 06:04:33 +01:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( !UnlockFile( handle, 10, 0, 10, 0 ), "UnlockFile 10,10 succeeded\n" );
|
|
|
|
ok( UnlockFile( handle, 10, 0, 20, 0 ), "UnlockFile 10,20 failed\n" );
|
|
|
|
ok( !UnlockFile( handle, 10, 0, 20, 0 ), "UnlockFile 10,20 again succeeded\n" );
|
|
|
|
ok( UnlockFile( handle, 5, 0, 5, 0 ), "UnlockFile 5,5 failed\n" );
|
2003-03-18 06:04:33 +01:00
|
|
|
|
2005-03-17 20:00:08 +01:00
|
|
|
S(U(overlapped)).Offset = 100;
|
|
|
|
S(U(overlapped)).OffsetHigh = 0;
|
2003-03-18 06:04:33 +01:00
|
|
|
overlapped.hEvent = 0;
|
2004-04-28 05:52:02 +02:00
|
|
|
|
|
|
|
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" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-18 06:04:33 +01:00
|
|
|
/* overlapping shared locks are OK */
|
2005-03-17 20:00:08 +01:00
|
|
|
S(U(overlapped)).Offset = 150;
|
2004-04-28 05:52:02 +02:00
|
|
|
limited_UnLockFile || ok( LockFileEx( handle, 0, 0, 100, 0, &overlapped ), "LockFileEx 150,100 failed\n" );
|
|
|
|
|
2003-03-18 06:04:33 +01:00
|
|
|
/* but exclusive is not */
|
2004-04-28 05:52:02 +02:00
|
|
|
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. */
|
2005-03-17 20:00:08 +01:00
|
|
|
S(U(overlapped)).Offset = 100;
|
2004-04-28 05:52:02 +02:00
|
|
|
ok( !UnlockFileEx( handle, 0, 100, 0, &overlapped ),
|
|
|
|
"UnlockFileEx 150,100 again succeeded\n" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-03-18 06:04:33 +01:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( LockFile( handle, 0, 0x10000000, 0, 0xf0000000 ), "LockFile failed\n" );
|
|
|
|
ok( !LockFile( handle, ~0, ~0, 1, 0 ), "LockFile ~0,1 succeeded\n" );
|
|
|
|
ok( !LockFile( handle, 0, 0x20000000, 20, 0 ), "LockFile 0x20000000,20 succeeded\n" );
|
|
|
|
ok( UnlockFile( handle, 0, 0x10000000, 0, 0xf0000000 ), "UnlockFile failed\n" );
|
2003-03-18 06:04:33 +01:00
|
|
|
|
|
|
|
/* wrap-around lock should not do anything */
|
|
|
|
/* (but still succeeds on NT4 so we don't check result) */
|
|
|
|
LockFile( handle, 0, 0x10000000, 0, 0xf0000001 );
|
2004-04-28 05:52:02 +02:00
|
|
|
|
|
|
|
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" );
|
2003-03-18 06:04:33 +01:00
|
|
|
|
|
|
|
/* zero-byte lock */
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( LockFile( handle, 100, 0, 0, 0 ), "LockFile 100,0 failed\n" );
|
2004-04-28 05:52:02 +02:00
|
|
|
limited_LockFile || ok( !LockFile( handle, 98, 0, 4, 0 ), "LockFile 98,4 succeeded\n" );
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( LockFile( handle, 90, 0, 10, 0 ), "LockFile 90,10 failed\n" );
|
2004-04-28 05:52:02 +02:00
|
|
|
limited_LockFile || ok( !LockFile( handle, 100, 0, 10, 0 ), "LockFile 100,10 failed\n" );
|
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( UnlockFile( handle, 90, 0, 10, 0 ), "UnlockFile 90,10 failed\n" );
|
2004-04-28 05:52:02 +02:00
|
|
|
!ok( UnlockFile( handle, 100, 0, 10, 0 ), "UnlockFile 100,10 failed\n" );
|
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( UnlockFile( handle, 100, 0, 0, 0 ), "UnlockFile 100,0 failed\n" );
|
2003-03-18 06:04:33 +01:00
|
|
|
|
|
|
|
CloseHandle( handle );
|
|
|
|
DeleteFileA( filename );
|
|
|
|
}
|
|
|
|
|
2004-03-27 21:48:42 +01:00
|
|
|
static inline int is_sharing_compatible( DWORD access1, DWORD sharing1, DWORD access2, DWORD sharing2 )
|
|
|
|
{
|
|
|
|
if (!access1 || !access2) return 1;
|
|
|
|
if ((access1 & GENERIC_READ) && !(sharing2 & FILE_SHARE_READ)) return 0;
|
|
|
|
if ((access1 & GENERIC_WRITE) && !(sharing2 & FILE_SHARE_WRITE)) return 0;
|
|
|
|
if ((access2 & GENERIC_READ) && !(sharing1 & FILE_SHARE_READ)) return 0;
|
|
|
|
if ((access2 & GENERIC_WRITE) && !(sharing1 & FILE_SHARE_WRITE)) return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2004-04-28 05:52:02 +02:00
|
|
|
int ret;
|
2005-03-01 11:42:04 +01:00
|
|
|
HANDLE h, h2;
|
2004-03-27 21:48:42 +01:00
|
|
|
|
2004-04-03 02:05:24 +02:00
|
|
|
/* make sure the file exists */
|
2005-03-01 11:42:04 +01:00
|
|
|
h = CreateFileA( filename, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0 );
|
|
|
|
if (h == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
ok(0, "couldn't create file \"%s\" (err=%ld)\n", filename, GetLastError());
|
|
|
|
return;
|
|
|
|
}
|
2004-04-03 02:05:24 +02:00
|
|
|
CloseHandle( h );
|
|
|
|
|
2004-03-27 21:48:42 +01:00
|
|
|
for (a1 = 0; a1 < 4; a1++)
|
|
|
|
{
|
|
|
|
for (s1 = 0; s1 < 4; s1++)
|
|
|
|
{
|
2005-03-01 11:42:04 +01:00
|
|
|
h = CreateFileA( filename, access_modes[a1], sharing_modes[s1],
|
|
|
|
NULL, OPEN_EXISTING, 0, 0 );
|
2004-03-27 21:48:42 +01:00
|
|
|
if (h == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (a2 = 0; a2 < 4; a2++)
|
|
|
|
{
|
|
|
|
for (s2 = 0; s2 < 4; s2++)
|
|
|
|
{
|
2005-03-01 11:42:04 +01:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
h2 = CreateFileA( filename, access_modes[a2], sharing_modes[s2],
|
|
|
|
NULL, OPEN_EXISTING, 0, 0 );
|
2004-03-27 21:48:42 +01:00
|
|
|
if (is_sharing_compatible( access_modes[a1], sharing_modes[s1],
|
|
|
|
access_modes[a2], sharing_modes[s2] ))
|
|
|
|
{
|
2004-04-28 05:52:02 +02:00
|
|
|
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,
|
2004-03-27 21:48:42 +01:00
|
|
|
access_modes[a1], sharing_modes[s1],
|
2004-04-28 05:52:02 +02:00
|
|
|
access_modes[a2], sharing_modes[s2]
|
|
|
|
);
|
2004-03-27 21:48:42 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ok( h2 == INVALID_HANDLE_VALUE,
|
|
|
|
"open succeeded for modes %lx/%lx/%lx/%lx\n",
|
|
|
|
access_modes[a1], sharing_modes[s1],
|
|
|
|
access_modes[a2], sharing_modes[s2] );
|
|
|
|
if (h2 == INVALID_HANDLE_VALUE)
|
|
|
|
ok( GetLastError() == ERROR_SHARING_VIOLATION,
|
|
|
|
"wrong error code %ld\n", GetLastError() );
|
|
|
|
}
|
|
|
|
if (h2 != INVALID_HANDLE_VALUE) CloseHandle( h2 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CloseHandle( h );
|
|
|
|
}
|
|
|
|
}
|
2005-03-01 11:42:04 +01:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
h = CreateFileA( filename, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, 0 );
|
|
|
|
ok( h != INVALID_HANDLE_VALUE, "CreateFileA error %ld\n", GetLastError() );
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
h2 = CreateFileA( filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0 );
|
|
|
|
ok( h2 == INVALID_HANDLE_VALUE, "CreateFileA should fail\n");
|
|
|
|
ok( GetLastError() == ERROR_SHARING_VIOLATION, "wrong error code %ld\n", GetLastError() );
|
|
|
|
|
|
|
|
h2 = CreateFileA( filename, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
|
|
|
|
ok( h2 != INVALID_HANDLE_VALUE, "CreateFileA error %ld\n", GetLastError() );
|
|
|
|
|
|
|
|
CloseHandle(h);
|
|
|
|
CloseHandle(h2);
|
|
|
|
|
2004-03-27 21:48:42 +01:00
|
|
|
DeleteFileA( filename );
|
|
|
|
}
|
|
|
|
|
2005-06-20 16:18:03 +02:00
|
|
|
static char get_windows_drive(void)
|
2004-08-30 20:40:20 +02:00
|
|
|
{
|
|
|
|
char windowsdir[MAX_PATH];
|
|
|
|
GetWindowsDirectory(windowsdir, sizeof(windowsdir));
|
|
|
|
return windowsdir[0];
|
|
|
|
}
|
|
|
|
|
2005-06-20 16:18:03 +02:00
|
|
|
static void test_FindFirstFileA(void)
|
2003-04-17 04:10:04 +02:00
|
|
|
{
|
|
|
|
HANDLE handle;
|
|
|
|
WIN32_FIND_DATAA search_results;
|
|
|
|
int err;
|
2004-08-30 20:40:20 +02:00
|
|
|
char buffer[5] = "C:\\";
|
2003-04-17 04:10:04 +02:00
|
|
|
|
2004-08-30 20:40:20 +02:00
|
|
|
/* try FindFirstFileA on "C:\" */
|
|
|
|
buffer[0] = get_windows_drive();
|
|
|
|
handle = FindFirstFileA(buffer,&search_results);
|
2003-04-17 04:10:04 +02:00
|
|
|
err = GetLastError();
|
2004-08-30 20:40:20 +02:00
|
|
|
ok ( handle == INVALID_HANDLE_VALUE , "FindFirstFile on root directory should Fail\n");
|
2003-04-17 04:10:04 +02:00
|
|
|
if (handle == INVALID_HANDLE_VALUE)
|
2003-10-22 01:42:50 +02:00
|
|
|
ok ( err == ERROR_FILE_NOT_FOUND, "Bad Error number %d\n", err);
|
2004-08-30 20:40:20 +02:00
|
|
|
|
|
|
|
/* try FindFirstFileA on "C:\*" */
|
|
|
|
strcat(buffer, "*");
|
|
|
|
handle = FindFirstFileA(buffer,&search_results);
|
|
|
|
ok ( handle != INVALID_HANDLE_VALUE, "FindFirstFile on %s should succeed\n", buffer );
|
2004-01-27 21:13:03 +01:00
|
|
|
ok ( FindClose(handle) == TRUE, "Failed to close handle\n");
|
2003-04-17 04:10:04 +02:00
|
|
|
}
|
2003-03-18 06:04:33 +01:00
|
|
|
|
2005-06-20 16:18:03 +02:00
|
|
|
static void test_FindNextFileA(void)
|
2003-09-16 03:22:05 +02:00
|
|
|
{
|
|
|
|
HANDLE handle;
|
|
|
|
WIN32_FIND_DATAA search_results;
|
|
|
|
int err;
|
2004-08-30 20:40:20 +02:00
|
|
|
char buffer[5] = "C:\\*";
|
2003-09-16 03:22:05 +02:00
|
|
|
|
2004-08-30 20:40:20 +02:00
|
|
|
buffer[0] = get_windows_drive();
|
|
|
|
handle = FindFirstFileA(buffer,&search_results);
|
2004-01-27 21:13:03 +01:00
|
|
|
ok ( handle != INVALID_HANDLE_VALUE, "FindFirstFile on C:\\* should succeed\n" );
|
2003-09-16 03:22:05 +02:00
|
|
|
while (FindNextFile(handle, &search_results))
|
|
|
|
{
|
|
|
|
/* get to the end of the files */
|
|
|
|
}
|
2004-01-27 21:13:03 +01:00
|
|
|
ok ( FindClose(handle) == TRUE, "Failed to close handle\n");
|
2003-09-16 03:22:05 +02:00
|
|
|
err = GetLastError();
|
2004-01-27 21:13:03 +01:00
|
|
|
ok ( err == ERROR_NO_MORE_FILES, "GetLastError should return ERROR_NO_MORE_FILES\n");
|
2003-09-16 03:22:05 +02:00
|
|
|
}
|
|
|
|
|
2004-04-28 05:52:02 +02:00
|
|
|
static int test_Mapfile_createtemp(HANDLE *handle)
|
2004-01-09 01:34:37 +01:00
|
|
|
{
|
|
|
|
SetFileAttributesA(filename,FILE_ATTRIBUTE_NORMAL);
|
|
|
|
DeleteFile(filename);
|
2004-04-28 05:52:02 +02:00
|
|
|
*handle = CreateFile(filename, GENERIC_READ|GENERIC_WRITE, 0, 0,
|
|
|
|
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
if (*handle != INVALID_HANDLE_VALUE) {
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-06-20 16:18:03 +02:00
|
|
|
static void test_MapFile(void)
|
2004-04-28 05:52:02 +02:00
|
|
|
{
|
|
|
|
HANDLE handle;
|
|
|
|
HANDLE hmap;
|
2004-01-09 01:34:37 +01:00
|
|
|
|
2004-04-28 05:52:02 +02:00
|
|
|
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. */
|
2004-01-09 01:34:37 +01:00
|
|
|
hmap = CreateFileMapping( handle, NULL, PAGE_READWRITE, 0, 0, NULL );
|
2004-04-28 05:52:02 +02:00
|
|
|
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 );
|
2004-01-09 01:34:37 +01:00
|
|
|
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");
|
2004-04-28 05:52:02 +02:00
|
|
|
/* GetLastError() varies between win9x and WinNT and also depends on the filesystem */
|
2004-01-09 01:34:37 +01:00
|
|
|
|
|
|
|
hmap = CreateFileMapping( handle, NULL, PAGE_READWRITE, 0x1000, 0x10000, NULL );
|
|
|
|
ok( hmap == NULL, "mapping should fail\n");
|
2004-04-28 05:52:02 +02:00
|
|
|
/* GetLastError() varies between win9x and WinNT and also depends on the filesystem */
|
2004-01-09 01:34:37 +01:00
|
|
|
|
2005-05-06 17:44:31 +02:00
|
|
|
/* On XP you can now map again, on Win 95 you cannot. */
|
2004-01-09 01:34:37 +01:00
|
|
|
|
|
|
|
ok( CloseHandle( handle ), "can't close file handle\n");
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( DeleteFileA( filename ), "DeleteFile failed after map\n" );
|
2004-01-09 01:34:37 +01:00
|
|
|
}
|
|
|
|
|
2004-04-08 06:39:59 +02:00
|
|
|
static void test_GetFileType(void)
|
|
|
|
{
|
|
|
|
DWORD type;
|
|
|
|
HANDLE h = CreateFileA( filename, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0 );
|
|
|
|
ok( h != INVALID_HANDLE_VALUE, "open %s failed\n", filename );
|
|
|
|
type = GetFileType(h);
|
|
|
|
ok( type == FILE_TYPE_DISK, "expected type disk got %ld\n", type );
|
|
|
|
CloseHandle( h );
|
|
|
|
h = CreateFileA( "nul", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0 );
|
|
|
|
ok( h != INVALID_HANDLE_VALUE, "open nul failed\n" );
|
|
|
|
type = GetFileType(h);
|
|
|
|
ok( type == FILE_TYPE_CHAR, "expected type char for nul got %ld\n", type );
|
|
|
|
CloseHandle( h );
|
|
|
|
DeleteFileA( filename );
|
|
|
|
}
|
|
|
|
|
2004-08-19 04:34:51 +02:00
|
|
|
static int completion_count;
|
|
|
|
|
|
|
|
static void CALLBACK FileIOComplete(DWORD dwError, DWORD dwBytes, LPOVERLAPPED ovl)
|
|
|
|
{
|
|
|
|
/* printf("(%ld, %ld, %p { %ld, %ld, %ld, %ld, %p })\n", dwError, dwBytes, ovl, ovl->Internal, ovl->InternalHigh, ovl->Offset, ovl->OffsetHigh, ovl->hEvent);*/
|
|
|
|
ReleaseSemaphore(ovl->hEvent, 1, NULL);
|
|
|
|
completion_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_async_file_errors(void)
|
|
|
|
{
|
|
|
|
char szFile[MAX_PATH];
|
|
|
|
HANDLE hSem = CreateSemaphoreW(NULL, 1, 1, NULL);
|
|
|
|
HANDLE hFile;
|
|
|
|
LPVOID lpBuffer = HeapAlloc(GetProcessHeap(), 0, 4096);
|
|
|
|
OVERLAPPED ovl;
|
2005-03-17 20:00:08 +01:00
|
|
|
S(U(ovl)).Offset = 0;
|
|
|
|
S(U(ovl)).OffsetHigh = 0;
|
2004-08-19 04:34:51 +02:00
|
|
|
ovl.hEvent = hSem;
|
|
|
|
completion_count = 0;
|
|
|
|
szFile[0] = '\0';
|
|
|
|
GetWindowsDirectoryA(szFile, sizeof(szFile)/sizeof(szFile[0])-1-strlen("\\win.ini"));
|
|
|
|
strcat(szFile, "\\win.ini");
|
|
|
|
hFile = CreateFileA(szFile, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_ALWAYS, FILE_FLAG_OVERLAPPED, NULL);
|
|
|
|
ok(hFile != NULL, "CreateFileA(%s ...) failed\n", szFile);
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
BOOL res;
|
|
|
|
while (WaitForSingleObjectEx(hSem, INFINITE, TRUE) == WAIT_IO_COMPLETION)
|
|
|
|
;
|
|
|
|
res = ReadFileEx(hFile, lpBuffer, 4096, &ovl, FileIOComplete);
|
|
|
|
/*printf("Offset = %ld, result = %s\n", ovl.Offset, res ? "TRUE" : "FALSE");*/
|
|
|
|
if (!res)
|
|
|
|
break;
|
2005-03-17 20:00:08 +01:00
|
|
|
S(U(ovl)).Offset += 4096;
|
2004-08-19 04:34:51 +02:00
|
|
|
/* i/o completion routine only called if ReadFileEx returned success.
|
|
|
|
* we only care about violations of this rule so undo what should have
|
|
|
|
* been done */
|
|
|
|
completion_count--;
|
|
|
|
}
|
|
|
|
ok(completion_count == 0, "completion routine should only be called when ReadFileEx succeeds (this rule was violated %d times)\n", completion_count);
|
|
|
|
/*printf("Error = %ld\n", GetLastError());*/
|
|
|
|
}
|
|
|
|
|
2004-11-28 15:58:11 +01:00
|
|
|
static void test_read_write(void)
|
|
|
|
{
|
|
|
|
DWORD bytes, ret;
|
|
|
|
HANDLE hFile;
|
|
|
|
char temp_path[MAX_PATH];
|
|
|
|
char filename[MAX_PATH];
|
|
|
|
static const char prefix[] = "pfx";
|
|
|
|
|
|
|
|
ret = GetTempPathA(MAX_PATH, temp_path);
|
|
|
|
ok(ret != 0, "GetTempPathA error %ld\n", GetLastError());
|
|
|
|
ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
|
|
|
|
|
|
|
|
ret = GetTempFileNameA(temp_path, prefix, 0, filename);
|
|
|
|
ok(ret != 0, "GetTempFileNameA error %ld\n", GetLastError());
|
|
|
|
|
|
|
|
hFile = CreateFileA(filename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
|
|
|
|
CREATE_ALWAYS, FILE_FLAG_RANDOM_ACCESS, 0);
|
|
|
|
ok(hFile != INVALID_HANDLE_VALUE, "CreateFileA: error %ld\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(12345678);
|
|
|
|
bytes = 12345678;
|
|
|
|
ret = WriteFile(hFile, NULL, 0, &bytes, NULL);
|
|
|
|
ok(ret && GetLastError() == 12345678,
|
|
|
|
"ret = %ld, error %ld\n", ret, GetLastError());
|
|
|
|
ok(!bytes, "bytes = %ld\n", bytes);
|
|
|
|
|
|
|
|
SetLastError(12345678);
|
|
|
|
bytes = 12345678;
|
|
|
|
ret = WriteFile(hFile, NULL, 10, &bytes, NULL);
|
|
|
|
ok((!ret && GetLastError() == ERROR_INVALID_USER_BUFFER) || /* Win2k */
|
|
|
|
(ret && GetLastError() == 12345678), /* Win9x */
|
|
|
|
"ret = %ld, error %ld\n", ret, GetLastError());
|
|
|
|
ok(!bytes || /* Win2k */
|
|
|
|
bytes == 10, /* Win9x */
|
|
|
|
"bytes = %ld\n", bytes);
|
|
|
|
|
|
|
|
SetLastError(12345678);
|
|
|
|
bytes = 12345678;
|
|
|
|
ret = ReadFile(hFile, NULL, 0, &bytes, NULL);
|
|
|
|
ok(ret && GetLastError() == 12345678,
|
|
|
|
"ret = %ld, error %ld\n", ret, GetLastError());
|
|
|
|
ok(!bytes, "bytes = %ld\n", bytes);
|
|
|
|
|
|
|
|
SetLastError(12345678);
|
|
|
|
bytes = 12345678;
|
|
|
|
ret = ReadFile(hFile, NULL, 10, &bytes, NULL);
|
|
|
|
ok(!ret && (GetLastError() == ERROR_NOACCESS || /* Win2k */
|
|
|
|
GetLastError() == ERROR_INVALID_PARAMETER), /* Win9x */
|
|
|
|
"ret = %ld, error %ld\n", ret, GetLastError());
|
|
|
|
ok(!bytes, "bytes = %ld\n", bytes);
|
|
|
|
|
2004-12-27 18:26:37 +01:00
|
|
|
ret = CloseHandle(hFile);
|
|
|
|
ok( ret, "CloseHandle: error %ld\n", GetLastError());
|
|
|
|
ret = DeleteFileA(filename);
|
|
|
|
ok( ret, "DeleteFileA: error %ld\n", GetLastError());
|
2004-11-28 15:58:11 +01:00
|
|
|
}
|
|
|
|
|
2002-04-29 19:14:50 +02:00
|
|
|
START_TEST(file)
|
|
|
|
{
|
|
|
|
test__hread( );
|
|
|
|
test__hwrite( );
|
|
|
|
test__lclose( );
|
2002-05-06 22:12:55 +02:00
|
|
|
test__lcreat( );
|
|
|
|
test__llseek( );
|
|
|
|
test__llopen( );
|
2002-05-09 22:29:15 +02:00
|
|
|
test__lread( );
|
|
|
|
test__lwrite( );
|
2004-01-16 05:49:13 +01:00
|
|
|
test_GetTempFileNameA();
|
2002-08-27 03:56:08 +02:00
|
|
|
test_CopyFileA();
|
|
|
|
test_CopyFileW();
|
|
|
|
test_CreateFileA();
|
|
|
|
test_CreateFileW();
|
2002-11-12 03:11:52 +01:00
|
|
|
test_DeleteFileA();
|
2002-12-12 04:54:01 +01:00
|
|
|
test_DeleteFileW();
|
2003-12-08 23:21:20 +01:00
|
|
|
test_MoveFileA();
|
|
|
|
test_MoveFileW();
|
2003-04-17 04:10:04 +02:00
|
|
|
test_FindFirstFileA();
|
2003-09-16 03:22:05 +02:00
|
|
|
test_FindNextFileA();
|
2003-03-18 06:04:33 +01:00
|
|
|
test_LockFile();
|
2004-03-27 21:48:42 +01:00
|
|
|
test_file_sharing();
|
2002-08-27 03:56:08 +02:00
|
|
|
test_offset_in_overlapped_structure();
|
2004-01-09 01:34:37 +01:00
|
|
|
test_MapFile();
|
2004-04-08 06:39:59 +02:00
|
|
|
test_GetFileType();
|
2004-08-19 04:34:51 +02:00
|
|
|
test_async_file_errors();
|
2004-11-28 15:58:11 +01:00
|
|
|
test_read_write();
|
2002-04-29 19:14:50 +02:00
|
|
|
}
|