/* * Unit test suite for file functions * * Copyright 2002 Bill Currie * * 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 */ #include "wine/test.h" #include #include #include #include #include #include #include #include #include static void test_fdopen( void ) { static char buffer[] = {0,1,2,3,4,5,6,7,8,9}; int fd; FILE *file; fd = open ("fdopen.tst", O_WRONLY | O_CREAT | O_BINARY, _S_IREAD |_S_IWRITE); write (fd, buffer, sizeof (buffer)); close (fd); fd = open ("fdopen.tst", O_RDONLY | O_BINARY); lseek (fd, 5, SEEK_SET); file = fdopen (fd, "rb"); ok (fread (buffer, 1, sizeof (buffer), file) == 5, "read wrong byte count\n"); ok (memcmp (buffer, buffer + 5, 5) == 0, "read wrong bytes\n"); fclose (file); unlink ("fdopen.tst"); } static void test_fileops( void ) { static char outbuffer[] = "0,1,2,3,4,5,6,7,8,9"; char buffer[256]; WCHAR wbuffer[256]; int fd; FILE *file; fd = open ("fdopen.tst", O_WRONLY | O_CREAT | O_BINARY, _S_IREAD |_S_IWRITE); write (fd, outbuffer, sizeof (outbuffer)); close (fd); fd = open ("fdopen.tst", O_RDONLY | O_BINARY); file = fdopen (fd, "rb"); ok(strlen(outbuffer) == (sizeof(outbuffer)-1),"strlen/sizeof error\n"); ok(fgets(buffer,sizeof(buffer),file) !=0,"fgets failed unexpected\n"); ok(fgets(buffer,sizeof(buffer),file) ==0,"fgets didn't signal EOF\n"); ok(feof(file) !=0,"feof doesn't signal EOF\n"); rewind(file); ok(fgets(buffer,strlen(outbuffer),file) !=0,"fgets failed unexpected\n"); ok(lstrlenA(buffer) == strlen(outbuffer) -1,"fgets didn't read right size\n"); ok(fgets(buffer,sizeof(outbuffer),file) !=0,"fgets failed unexpected\n"); ok(strlen(buffer) == 1,"fgets dropped chars\n"); ok(buffer[0] == outbuffer[strlen(outbuffer)-1],"fgets exchanged chars\n"); fclose (file); fd = open ("fdopen.tst", O_RDONLY | O_TEXT); file = fdopen (fd, "rt"); /* open in TEXT mode */ ok(fgetws(wbuffer,sizeof(wbuffer),file) !=0,"fgetws failed unexpected\n"); ok(fgetws(wbuffer,sizeof(wbuffer),file) ==0,"fgetws didn't signal EOF\n"); ok(feof(file) !=0,"feof doesn't signal EOF\n"); rewind(file); ok(fgetws(wbuffer,strlen(outbuffer),file) !=0,"fgetws failed unexpected\n"); ok(lstrlenW(wbuffer) == (strlen(outbuffer) -1),"fgetws didn't read right size\n"); ok(fgetws(wbuffer,sizeof(outbuffer),file) !=0,"fgets failed unexpected\n"); ok(lstrlenW(wbuffer) == 1,"fgets dropped chars\n"); fclose (file); unlink ("fdopen.tst"); } static WCHAR* AtoW( char* p ) { WCHAR* buffer; DWORD len = MultiByteToWideChar( CP_ACP, 0, p, -1, NULL, 0 ); buffer = malloc( len * sizeof(WCHAR) ); MultiByteToWideChar( CP_ACP, 0, p, -1, buffer, len ); return buffer; } static void test_fgetwc( void ) { #define LLEN 512 char* tempf; FILE *tempfh; const char mytext[]= "This is test_fgetwc\n"; WCHAR wtextW[LLEN+1]; WCHAR *mytextW = NULL, *aptr, *wptr; BOOL diff_found = FALSE; unsigned int i; tempf=_tempnam(".","wne"); tempfh = fopen(tempf,"wt"); /* open in TEXT mode */ fputs(mytext,tempfh); fclose(tempfh); tempfh = fopen(tempf,"rt"); fgetws(wtextW,LLEN,tempfh); mytextW = AtoW ((char*)mytext); aptr = mytextW; wptr = wtextW; for (i=0; i