New file API tests.
Jakob Eriksson
jakob at vmlinux.org
Fri May 3 20:18:47 CDT 2002
ChangeLog:
Tests for _lcreat,_llseek and _llopen added.
------------------------------------------------------------------
? kernel.spec.c
? patch.diff
Index: tests/file.c
===================================================================
RCS file: /home/wine/wine/dlls/kernel/tests/file.c,v
retrieving revision 1.1
diff -u -r1.1 file.c
--- tests/file.c 29 Apr 2002 17:14:50 -0000 1.1
+++ tests/file.c 4 May 2002 01:14:29 -0000
@@ -1,4 +1,4 @@
-/*
+/* -*- wine-c -*-
* Unit tests for file functions
*
* Copyright 2002 Jakob Eriksson
@@ -48,14 +48,15 @@
UINT i;
filehandle = _lcreat( filename, 0 );
-
- ok( HFILE_ERROR != filehandle, "_lcreat complains." );
+ ok( HFILE_ERROR != filehandle, "couldn't create file. Wrong permissions on directory?" );
ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains." );
ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains." );
filehandle = _lopen( filename, OF_READ );
+
+ ok( HFILE_ERROR != filehandle, "couldn't open file again?");
bytes_read = _hread( filehandle, buffer, 2 * strlen( sillytext ) );
@@ -89,8 +90,7 @@
char checksum[1];
filehandle = _lcreat( filename, 0 );
-
- ok( HFILE_ERROR != filehandle, "_lcreat complains." );
+ ok( HFILE_ERROR != filehandle, "couldn't create file. Wrong permissions on directory?" );
ok( HFILE_ERROR != _hwrite( filehandle, "", 0 ), "_hwrite complains." );
@@ -161,8 +161,7 @@
HFILE filehandle;
filehandle = _lcreat( filename, 0 );
-
- ok( HFILE_ERROR != filehandle, "_lcreat complains." );
+ ok( HFILE_ERROR != filehandle, "couldn't create file. Wrong permissions on directory?" );
ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains." );
@@ -172,13 +171,147 @@
ok( HFILE_ERROR == _lclose(filehandle), "_lclose should whine about this." );
- ok( DeleteFileA( filename ) != 0, "DeleteFile complains." );
+ ok( DeleteFileA( filename ) != 0, "DeleteFileA complains." );
+}
+
+
+static void test__lcreat( void )
+{
+ HFILE filehandle;
+ char buffer[10000];
+ WIN32_FIND_DATAA search_results;
+
+ filehandle = _lcreat( filename, 0 );
+ ok( HFILE_ERROR != filehandle, "couldn't create file. Wrong permissions on directory?" );
+
+ ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains." );
+
+ ok( 0 == _llseek( filehandle, 0, FILE_BEGIN ), "_llseek complains." );
+
+ ok( _hread( filehandle, buffer, strlen( sillytext ) ) == strlen( sillytext ), "erratic _hread return value." );
+
+ ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains." );
+
+ ok( INVALID_HANDLE_VALUE != FindFirstFileA( filename, &search_results ), "should be able to find file" );
+
+ ok( DeleteFileA( filename ) != 0, "DeleteFileA complains." );
+
+
+ filehandle = _lcreat( filename, 1 );
+ ok( HFILE_ERROR != filehandle, "couldn't create file!?" );
+
+ ok( HFILE_ERROR == _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite shouldn't succeed writing." );
+
+ ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains." );
+
+ ok( INVALID_HANDLE_VALUE != FindFirstFileA( filename, &search_results ), "should be able to find file" );
+
+ ok( DeleteFileA( filename ) != 0, "DeleteFileA complains." );
+
+
+ filehandle = _lcreat( filename, 2 );
+ ok( HFILE_ERROR != filehandle, "couldn't create file. Wrong permissions on directory?" );
+
+ ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains." );
+
+ ok( 0 == _llseek( filehandle, 0, FILE_BEGIN ), "_llseek complains." );
+
+ ok( _hread( filehandle, buffer, strlen( sillytext ) ) == strlen( sillytext ), "erratic _hread return value." );
+
+ ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains." );
+
+ ok( INVALID_HANDLE_VALUE == FindFirstFileA( filename, &search_results ), "should NOT be able to find file" );
+
+ ok( DeleteFileA( filename ) != 0, "DeleteFileA complains." );
+
+
+ filehandle = _lcreat( filename, 4 );
+ ok( HFILE_ERROR != filehandle, "couldn't create file. Wrong permissions on directory?" );
+
+ ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains." );
+
+ ok( 0 == _llseek( filehandle, 0, FILE_BEGIN ), "_llseek complains." );
+
+ ok( _hread( filehandle, buffer, strlen( sillytext ) ) == strlen( sillytext ), "erratic _hread return value." );
+
+ ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains." );
+
+ ok( INVALID_HANDLE_VALUE == FindFirstFileA( filename, &search_results ), "should NOT be able to find file" );
+
+ ok( DeleteFileA( filename ) != 0, "DeleteFileA complains." );
+}
+
+
+void test__llseek( void )
+{
+ INT i;
+ HFILE filehandle;
+ char buffer[1];
+ long bytes_read;
+
+ filehandle = _lcreat( filename, 0 );
+
+ ok( HFILE_ERROR != filehandle, "couldn't create file. Wrong permissions on directory?" );
+ for (i = 0; i < 400; i++)
+ {
+ ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains." );
+ }
+ ok( HFILE_ERROR != _llseek( filehandle, 400 * strlen( sillytext ), FILE_CURRENT ), "should be able to seek" );
+ ok( HFILE_ERROR != _llseek( filehandle, 27 + 35 * strlen( sillytext ), FILE_BEGIN ), "should be able to seek" );
+
+ bytes_read = _hread( filehandle, buffer, 1);
+ ok( 1 == bytes_read, "file read size error." );
+ ok( buffer[0] == sillytext[27], "_llseek error. It got lost seeking..." );
+ ok( HFILE_ERROR != _llseek( filehandle, -400 * strlen( sillytext ), FILE_END ), "should be able to seek" );
+
+ bytes_read = _hread( filehandle, buffer, 1);
+ ok( 1 == bytes_read, "file read size error." );
+ ok( buffer[0] == sillytext[0], "_llseek error. It got lost seeking..." );
+
+ ok( HFILE_ERROR == _llseek( filehandle, 1000000, FILE_END ), "should get HFILE_ERROR for trying to seek past end of file" );
+
+ ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains." );
+ ok( DeleteFileA( filename ) != 0, "DeleteFileA complains." );
}
+void test__llopen( void )
+{
+ HFILE filehandle;
+ UINT bytes_read;
+ char buffer[10000];
+
+ filehandle = _lcreat( filename, 0 );
+ ok( HFILE_ERROR != filehandle, "couldn't create file. Wrong permissions on directory?" );
+ ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains." );
+ ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains." );
+
+ filehandle = _lopen( filename, OF_READ );
+ ok( HFILE_ERROR == _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite shouldn't be able to write!" );
+ bytes_read = _hread( filehandle, buffer, strlen( sillytext ) );
+ ok( strlen( sillytext ) == bytes_read, "file read size error." );
+ ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains." );
+
+ filehandle = _lopen( filename, OF_READWRITE );
+ bytes_read = _hread( filehandle, buffer, 2 * strlen( sillytext ) );
+ ok( strlen( sillytext ) == bytes_read, "file read size error." );
+ ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite should write just fine." );
+ ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains." );
+
+ filehandle = _lopen( filename, OF_WRITE );
+ ok( HFILE_ERROR == _hread( filehandle, buffer, 1 ), "you should only be able to write this file..." );
+ ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite should write just fine." );
+ ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains." );
+
+ ok( DeleteFileA( filename ) != 0, "DeleteFileA complains." );
+ /* TODO - add tests for the SHARE modes - use two processes to pull this off */
+}
START_TEST(file)
{
test__hread( );
test__hwrite( );
test__lclose( );
+ test__lcreat( );
+ test__llseek( );
+ test__llopen( );
}
More information about the wine-patches
mailing list