Changelog: made bug 646 go away and polished a unit test a little. License: LGPL ------------------------------------------------------------------------ ? HOW.txt ? console/Makefile ? dlls/gdi/gdi.spec.c ? dlls/kernel/patch.diff ? dlls/kernel/tests/profile.c ? dlls/user/user.spec.c ? graphics/enhmetafiledrv/Makefile ? graphics/metafiledrv/Makefile ? graphics/win16drv/Makefile ? graphics/win16drv/prtdrv.glue.c ? windows/x11drv/Makefile ? windows/x11drv/wineclipsrv Index: dlls/kernel/tests/directory.c =================================================================== RCS file: /home/wine/wine/dlls/kernel/tests/directory.c,v retrieving revision 1.2 diff -u -r1.2 directory.c --- dlls/kernel/tests/directory.c 1 Apr 2002 21:00:26 -0000 1.2 +++ dlls/kernel/tests/directory.c 7 May 2002 23:28:33 -0000 @@ -126,3 +126,4 @@ test_GetSystemDirectoryA(); test_GetSystemDirectoryW(); } + Index: dlls/kernel/tests/file.c =================================================================== RCS file: /home/wine/wine/dlls/kernel/tests/file.c,v retrieving revision 1.2 diff -u -r1.2 file.c --- dlls/kernel/tests/file.c 6 May 2002 20:12:55 -0000 1.2 +++ dlls/kernel/tests/file.c 7 May 2002 23:28:33 -0000 @@ -1,27 +1,40 @@ -/* - * Unit tests for file functions +/* -*- wine-c -*- * - * Copyright 2002 Jakob Eriksson + * Unit tests for file functions in Wine * - * 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. + * Copyright (c) 2002 Jakob Eriksson * - * 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. + * This file can be redistributed under either this license: + * + * -------- + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * -------- * - * 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 */ #include "winbase.h" #include "winerror.h" #include "wine/test.h" + #include <stdlib.h> #include <time.h> @@ -39,12 +52,13 @@ "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 "; + static void test__hread( void ) { HFILE filehandle; char buffer[10000]; long bytes_read; - UINT bytes_wanted; + long bytes_wanted; UINT i; filehandle = _lcreat( filename, 0 ); @@ -77,6 +91,7 @@ ok( DeleteFileA( filename ) != 0, "DeleteFile complains." ); } + static void test__hwrite( void ) { HFILE filehandle; @@ -170,6 +185,261 @@ ok( HFILE_ERROR == _lclose(filehandle), "_lclose should whine about this." ); +<<<<<<< file.c + 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." ); +} + + +static 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." ); +} + + +static 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 one off */ +} + + +static void test__lread( void ) +{ + HFILE filehandle; + char buffer[10000]; + long bytes_read; + UINT bytes_wanted; + UINT i; + + 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 != filehandle, "couldn't open file again?"); + + bytes_read = _lread( filehandle, buffer, 2 * strlen( sillytext ) ); + + ok( strlen( sillytext ) == bytes_read, "file read size error." ); + + for (bytes_wanted = 0; bytes_wanted < strlen( sillytext ); bytes_wanted++) + { + ok( 0 == _llseek( filehandle, 0, FILE_BEGIN ), "_llseek complains." ); + ok( _lread( filehandle, buffer, bytes_wanted ) == bytes_wanted, "erratic _hread return value." ); + for (i = 0; i < bytes_wanted; i++) + { + ok( buffer[i] == sillytext[i], "that's not what's written." ); + } + } + + ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains." ); + + ok( DeleteFileA( filename ) != 0, "DeleteFile complains." ); +} + + +static void test__lwrite( void ) +{ + HFILE filehandle; + char buffer[10000]; + long bytes_read; + UINT bytes_written; + UINT blocks; + UINT i; + char *contents; + HLOCAL memory_object; + char checksum[1]; + + filehandle = _lcreat( filename, 0 ); + ok( HFILE_ERROR != filehandle, "couldn't create file. Wrong permissions on directory?" ); + + ok( HFILE_ERROR != _lwrite( filehandle, "", 0 ), "_hwrite complains." ); + + ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains." ); + + filehandle = _lopen( filename, OF_READ ); + + bytes_read = _hread( filehandle, buffer, 1); + + ok( 0 == bytes_read, "file read size error." ); + + ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains." ); + + filehandle = _lopen( filename, OF_READWRITE ); + + bytes_written = 0; + checksum[0] = '\0'; + srand( (unsigned)time( NULL ) ); + for (blocks = 0; blocks < 100; blocks++) + { + for (i = 0; i < sizeof( buffer ); i++) + { + buffer[i] = rand( ); + checksum[0] = checksum[0] + buffer[i]; + } + ok( HFILE_ERROR != _lwrite( filehandle, buffer, sizeof( buffer ) ), "_hwrite complains." ); + bytes_written = bytes_written + sizeof( buffer ); + } + + ok( HFILE_ERROR != _lwrite( filehandle, checksum, 1 ), "_hwrite complains." ); + bytes_written++; + + ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains." ); + + memory_object = LocalAlloc( LPTR, bytes_written ); + + ok( 0 != memory_object, "LocalAlloc fails. (Could be out of memory.)" ); + + contents = LocalLock( memory_object ); + + filehandle = _lopen( filename, OF_READ ); + + contents = LocalLock( memory_object ); + + ok( NULL != contents, "LocalLock whines." ); + + ok( bytes_written == _hread( filehandle, contents, bytes_written), "read length differ from write length." ); + + checksum[0] = '\0'; + i = 0; + do + { + checksum[0] = checksum[0] + contents[i]; + i++; + } + while (i < bytes_written - 1); + + ok( checksum[0] == contents[i], "stored checksum differ from computed checksum." ); + return; + + ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains." ); + + ok( DeleteFileA( filename ) != 0, "DeleteFile complains." ); +======= ok( DeleteFileA( filename ) != 0, "DeleteFileA complains." ); } @@ -280,6 +550,7 @@ ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains." ); ok( DeleteFileA( filename ) != 0, "DeleteFileA complains." ); +>>>>>>> 1.2 } void test__llopen( void ) @@ -314,12 +585,22 @@ /* TODO - add tests for the SHARE modes - use two processes to pull this off */ } + + + START_TEST(file) { test__hread( ); test__hwrite( ); test__lclose( ); +<<<<<<< file.c + test__lcreat( ); + test__llseek( ); + test__llopen( ); + test__lread( ); +======= test__lcreat( ); test__llseek( ); test__llopen( ); +>>>>>>> 1.2 } Index: files/file.c =================================================================== RCS file: /home/wine/wine/files/file.c,v retrieving revision 1.145 diff -u -r1.145 file.c --- files/file.c 26 Apr 2002 18:31:19 -0000 1.145 +++ files/file.c 7 May 2002 23:28:33 -0000 @@ -1,4 +1,4 @@ -/* +/* -*- wine-c -*- * File handling functions * * Copyright 1993 John Burton @@ -1958,12 +1958,22 @@ */ HFILE WINAPI _lcreat( LPCSTR path, INT attr ) { + INT access; + INT sharing; + /* Mask off all flags not explicitly allowed by the doc */ attr &= FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM; TRACE("%s %02x\n", path, attr ); - return CreateFileA( path, GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, - CREATE_ALWAYS, attr, 0 ); + + access = GENERIC_READ | GENERIC_WRITE; + sharing = FILE_SHARE_READ | FILE_SHARE_WRITE; + if ( FILE_ATTRIBUTE_READONLY & attr ) + { + access = GENERIC_READ; + sharing = FILE_SHARE_READ; + } + + return CreateFileA( path, access, sharing, NULL, CREATE_ALWAYS, attr, 0 ); }