winedos: add dos tests

Markus Amsler markus.amsler at oribi.org
Fri Oct 15 09:54:57 CDT 2004


Changelog:
* add dos test suite
-------------- next part --------------
diff -urN dlls/winedos_filesep/tests_dos/dos_func.c dlls/winedos/tests_dos/dos_func.c
--- dlls/winedos_filesep/tests_dos/dos_func.c	1970-01-01 01:00:00.000000000 +0100
+++ dlls/winedos/tests_dos/dos_func.c	2004-10-15 02:56:51.000000000 +0200
@@ -0,0 +1,343 @@
+/*
+ * C DOS native interface
+ *
+ * Copyright (c) 2004 Markus Amsler
+ *
+ * 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 <dos.h>
+#include "dos_func.h"
+
+/*
+ * DOS 2+ internal - GET CURRENT PROCESS ID (GET PSP ADDRESS)
+ * AH = 51h
+ *
+ * RETURNS:
+ *   BX = segment of PSP for current process
+ */
+int dos_get_psp( unsigned *seg )
+{
+	union REGS r;
+	r.h.ah = 0x51;
+	intdos(&r, &r);
+	*seg = r.x.bx;
+	return !r.x.cflag;
+}
+
+
+/* DOS 2+ - CREAT - CREATE OR TRUNCATE FILE
+ * 
+ * AH = 3Ch
+ * CX = file attributes (see #01401)
+ * DS:DX -> ASCIZ filename
+ * 
+ * Return:
+ *   CF clear if successful
+ *     AX = file handle 
+ *   CF set on error
+ *     AX = error code (03h,04h,05h) (see #01680 at AH=59h/BX=0000h)
+ */
+int dos_creat( char far *fn, unsigned attrib, unsigned *ret )
+{
+	union REGS r; struct SREGS sr;
+	r.h.ah = 0x3C;
+	r.x.cx = attrib;
+	r.x.dx = FP_OFF(fn);
+	sr.ds  = FP_SEG(fn);
+	intdosx(&r, &r, &sr);
+	*ret = r.x.ax;
+	return !r.x.cflag;
+}
+
+
+/* DOS 2+ - OPEN - OPEN EXISTING FILE
+ *
+ * AH = 3Dh
+ * AL = access and sharing modes (see #01402)
+ * DS:DX -> ASCIZ filename
+ * CL = attribute mask of files to look for (server call only)
+ * 
+ * Return:
+ * CF clear if successful 
+ * AX = file handle 
+ * CF set on error 
+ * AX = error code (01h,02h,03h,04h,05h,0Ch,56h) (see #01680 at AH=59h)
+ */
+int dos_open( char far *fn, short access, short attrib, unsigned *ret )
+{
+	union REGS r; struct SREGS sr;
+	r.h.ah = 0x3D;
+	r.h.al = access;
+	r.h.cl = attrib;
+	r.x.dx = FP_OFF(fn);
+	sr.ds  = FP_SEG(fn);
+	intdosx(&r, &r, &sr);
+	*ret = r.x.ax;
+	return !r.x.cflag;
+}
+
+
+/* DOS 2+ - CLOSE - CLOSE FILE
+ * 
+ * AH = 3Eh
+ * BX = file handle
+ * 
+ * Return:
+ * CF clear if successful 
+ * AX destroyed 
+ * CF set on error 
+ * AX = error code (06h) (see #01680 at AH=59h/BX=0000h)
+ */
+int dos_close( unsigned fh, unsigned *ret )
+{
+	union REGS r;
+	r.h.ah = 0x3E;
+	r.x.bx = fh;
+	intdos(&r, &r);
+	*ret = r.x.ax;
+	return !r.x.cflag;
+}
+
+
+/* DOS 2+ - UNLINK - DELETE FILE
+ * 
+ * AH = 41h
+ * DS:DX -> ASCIZ filename (no wildcards, but see notes)
+ * CL = attribute mask for deletion (server call only, see notes)
+ * 
+ * Return:
+ * CF clear if successful 
+ * AX destroyed (DOS 3.3) 
+ * AL seems to be drive of deleted file 
+ * CF set on error 
+ * AX = error code (02h,03h,05h) (see #01680 at AH=59h/BX=0000h)
+ */
+int dos_unlink( char far *fn, short attrib, unsigned *ret )
+{
+	union REGS r; struct SREGS sr;
+	r.h.ah = 0x41;
+	r.h.cl = attrib;
+	r.x.dx = FP_OFF(fn);
+	sr.ds  = FP_SEG(fn);
+	intdosx(&r, &r, &sr);
+	*ret = r.x.ax;
+	return !r.x.cflag;
+}
+
+
+/* DOS 2+ - RENAME - RENAME FILE
+ * 
+ * AH = 56h
+ * DS:DX -> ASCIZ filename of existing file (no wildcards, but see below)
+ * ES:DI -> ASCIZ new filename (no wildcards)
+ * CL = attribute mask (server call only, see below)
+ * 
+ * Return:
+ * CF clear if successful 
+ * CF set on error 
+ * AX = error code (02h,03h,05h,11h) (see #01680)
+ */
+int dos_rename( char far *from, char far *to, short attrib, unsigned *ret )
+{
+	union REGS r; struct SREGS sr;
+	r.h.ah = 0x56;
+	r.h.cl = attrib;
+	sr.ds  = FP_SEG(from);
+	r.x.dx = FP_OFF(from);
+	sr.es  = FP_SEG(to);
+	r.x.di = FP_OFF(to);
+	intdosx(&r, &r, &sr);
+	*ret = r.x.ax;
+	return !r.x.cflag;
+}
+
+
+/* DOS 2+ - DUP - DUPLICATE FILE HANDLE
+ * 
+ * AH = 45h
+ * BX = file handle
+ * 
+ * Return:
+ * CF clear if successful 
+ * AX = new handle 
+ * CF set on error 
+ * AX = error code (04h,06h) (see #01680 at AH=59h/BX=0000h)
+ */
+int dos_dup( unsigned fh, unsigned *ret )
+{
+	union REGS r;
+	r.h.ah = 0x45;
+	r.x.bx = fh;
+	intdos(&r, &r);
+	*ret = r.x.ax;
+	return !r.x.cflag;
+}
+
+
+/* DOS 2+ - DUP2, FORCEDUP - FORCE DUPLICATE FILE HANDLE
+ * 
+ * AH = 46h
+ * BX = file handle
+ * CX = file handle to become duplicate of first handle
+ * 
+ * Return:
+ * CF clear if successful 
+ * CF set on error 
+ * AX = error code (04h,06h) (see #01680 at AH=59h/BX=0000h)
+ */
+int dos_dup2( unsigned fh, unsigned fh2, unsigned *ret )
+{
+	union REGS r;
+	r.h.ah = 0x46;
+	r.x.bx = fh;
+	r.x.cx = fh2;
+	intdos(&r, &r);
+	*ret = r.x.ax;
+	return !r.x.cflag;
+}
+
+
+/* DOS 3.3+ - SET HANDLE COUNT
+ * 
+ * AH = 67h
+ * BX = size of new file handle table for process
+ * 
+ * Return:
+ * CF clear if successful 
+ * CF set on error 
+ * AX = error code (see #01680 at AH=59h/BX=0000h)
+ */
+int dos_set_handle_count( unsigned size, unsigned *ret )
+{
+	union REGS r;
+	r.h.ah = 0x67;
+	r.x.bx = size;
+	intdos(&r, &r);
+	*ret = r.x.ax;
+	return !r.x.cflag;
+}
+
+
+/* DOS 2+ - READ - READ FROM FILE OR DEVICE
+ * 
+ * AH = 3Fh
+ * BX = file handle
+ * CX = number of bytes to read
+ * DS:DX -> buffer for data
+ * 
+ * Return:
+ * CF clear if successful 
+ * AX = number of bytes actually read (0 if at EOF before call) 
+ * CF set on error 
+ * AX = error code (05h,06h) (see #01680 at AH=59h/BX=0000h)
+ */
+int dos_read( unsigned handle, char far * buff, unsigned bytes, unsigned *ret )
+{
+	union REGS r; struct SREGS sr;
+	r.h.ah = 0x3f;
+	r.x.bx = handle;
+	r.x.cx = bytes;
+	sr.ds  = FP_SEG(buff);
+	r.x.dx = FP_OFF(buff);
+	intdosx(&r, &r, &sr);
+	*ret = r.x.ax;
+	return !r.x.cflag;
+}
+
+/* DOS 2+ - WRITE - WRITE TO FILE OR DEVICE
+ * 
+ * AH = 40h
+ * BX = file handle
+ * CX = number of bytes to write
+ * DS:DX -> data to write
+ * 
+ * Return:
+ * CF clear if successful 
+ * AX = number of bytes actually written 
+ * CF set on error 
+ * AX = error code (05h,06h) (see #01680 at AH=59h/BX=0000h)
+ */ 
+int dos_write( unsigned handle, char far * buff, unsigned bytes, unsigned *ret )
+{
+	union REGS r; struct SREGS sr;
+	r.h.ah = 0x40;
+	r.x.bx = handle;
+	r.x.cx = bytes;
+	sr.ds  = FP_SEG(buff);
+	r.x.dx = FP_OFF(buff);
+	intdosx(&r, &r, &sr);
+	*ret = r.x.ax;
+	return !r.x.cflag;
+}
+
+/* DOS 2+ - LSEEK - SET CURRENT FILE POSITION
+ * 
+ * AH = 42h
+ * AL = origin of move 00h start of file 01h current file position 02h end of file
+ * BX = file handle
+ * CX:DX = (signed) offset from origin of new file position
+ * 
+ * Return:
+ * CF clear if successful 
+ * DX:AX = new file position in bytes from start of file 
+ * CF set on error 
+ * AX = error code (01h,06h) (see #01680 at AH=59h/BX=0000h)
+ */
+int dos_lseek( unsigned handle, long offset, short origin, long *ret )
+{
+	union REGS r;
+	r.h.ah = 0x42;
+	r.h.al = origin;
+	r.x.bx = handle;
+
+	r.x.cx = HIWORD(offset);
+	r.x.dx = LOWORD(offset);
+	intdos(&r, &r);
+	if (r.x.cflag)
+		*ret = MAKELONG(r.x.ax,0);
+	else
+		*ret = MAKELONG(r.x.ax, r.x.dx);
+
+	return !r.x.cflag;
+}
+
+
+/* INT 21 - DOS 2+ - IOCTL - GET DEVICE INFORMATION
+ * AX = 4400h
+ * BX = handle
+ * 
+ * Return:
+ * CF clear if successful 
+ * DX = device information word (see #01423) 
+ * AX destroyed 
+ * CF set on error 
+ * AX = error code (01h,05h,06h) (see #01680 at AH=59h/BX=0000h)
+ */
+int dos_get_device_info( unsigned handle, unsigned *ret )
+{
+	union REGS r;
+	r.x.ax = 0x4400;
+	r.x.bx = handle;
+
+	intdos(&r, &r);
+	if (r.x.cflag)
+		*ret = r.x.ax;
+	else
+		*ret = r.x.dx;
+
+	return !r.x.cflag;
+}
diff -urN dlls/winedos_filesep/tests_dos/dos_func.h dlls/winedos/tests_dos/dos_func.h
--- dlls/winedos_filesep/tests_dos/dos_func.h	1970-01-01 01:00:00.000000000 +0100
+++ dlls/winedos/tests_dos/dos_func.h	2004-10-13 18:41:24.000000000 +0200
@@ -0,0 +1,99 @@
+/*
+ * Header for C DOS native interface
+ *
+ * Copyright (c) 2004 Markus Amsler
+ *
+ * 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 <dos.h>
+
+#ifndef __DOS_FUNCS_H
+#define __DOS_FUNCS_H
+
+#define BYTE short
+#define WORD unsigned
+#define LONG long
+#define DWORD long
+
+#define LOWORD(l)              ((WORD)(DWORD)(l))
+#define HIWORD(l)              ((WORD)((DWORD)(l) >> 16))
+
+#define MAKEWORD(low,high)     ((WORD)(((BYTE)(low)) | ((WORD)((BYTE)(high))) << 8))
+#define MAKELONG(low,high)     ((LONG)(((WORD)(low)) | (((DWORD)((WORD)(high))) << 16)))
+
+/* DOS File attributes */
+#define AT_READONLY 0x01
+#define AT_HIDDEN   0x02
+#define AT_SYSTEM   0x04
+#define AT_ARCHIVE  0x20
+
+/* DOS File Access modes */
+#define OF_READ 0x00
+#define OF_WRITE 0x01
+#define OF_READWRITE 0x02
+
+/* DOS File Sharing modes */
+#define FS_DENYALL   0x10
+#define FS_DENYWRITE 0x20
+#define FS_DENYREAD  0x30
+#define FS_DENYNONE  0x40
+
+/* DOS seek modes */
+#define FILE_BEGIN              0
+#define FILE_CURRENT            1
+#define FILE_END                2
+
+/* DOS device info */
+#define IOCTL_DEVICE   0x80
+#define DEVICE_STDIN   0x01
+#define DEVICE_STDOUT  0x02
+#define DEVICE_NUL     0x04
+#define DEVICE_CLOCK   0x08
+#define DEVICE_SPECIAL 0x10
+#define DEVICE_RAW     0x20
+#define DEVICE_EOF     0x40
+
+/*
+14    device driver can process IOCTL requests (see AX=4402h"DOS 2+")
+13    output until busy supported
+11    driver supports OPEN/CLOSE calls
+8    ??? (set by MS-DOS 6.2x KEYB)
+7    set (indicates device)
+6    EOF on input
+5    raw (binary) mode
+4    device is special (uses INT 29)
+3    clock device
+2    NUL device
+1    standard output
+0    standard input
+*/
+int dos_get_psp( unsigned* );
+int dos_creat( char far *, unsigned, unsigned * );
+int dos_open( char far *, short, short, unsigned * );
+int dos_close( unsigned , unsigned * );
+int dos_unlink( char far *, short , unsigned * );
+int dos_rename( char far *, char far *, short attrib, unsigned *);
+int dos_dup( unsigned , unsigned *);
+int dos_dup2( unsigned , unsigned , unsigned * );
+int dos_set_handle_count( unsigned , unsigned * );
+int dos_read( unsigned , char far * , unsigned , unsigned * );
+int dos_write( unsigned , char far * , unsigned , unsigned * );
+int dos_lseek( unsigned , long , short , long * );
+int dos_get_device_info( unsigned , unsigned * );
+
+
+#endif
\ Kein Zeilenumbruch am Dateiende.
diff -urN dlls/winedos_filesep/tests_dos/file.c dlls/winedos/tests_dos/file.c
--- dlls/winedos_filesep/tests_dos/file.c	1970-01-01 01:00:00.000000000 +0100
+++ dlls/winedos/tests_dos/file.c	2004-10-15 15:56:56.000000000 +0200
@@ -0,0 +1,395 @@
+/*
+ * Unit tests for dos file functions
+ *
+ * Copyright (c) 2004 Markus Amsler
+ *
+ * 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
+ *
+ */
+
+/*
+ * Compiled with Turbo C 1.01
+ */
+ 
+#include <stdio.h>
+
+#include "dos_func.h"
+
+
+#define ok     winetest_ok
+
+int winetest_ok( int condition, const char *msg, ... )
+{
+    
+    if (!condition)
+        printf ("%s", msg);
+    
+    return 1;
+}
+
+
+char far * filename = "testfile.xxx";
+char far * 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 ";
+
+int max_open_files(){
+    unsigned fhs[255];
+    char fn [255];
+    int i, ret=0;
+    unsigned b;
+    
+    for(i=0;i<255;i++){
+        sprintf(fn, "file_%d.xxx", i );
+        if (!dos_creat( fn, 0, &fhs[i])){
+				ok( (fhs[i] == 0x04), "error should be 0x04 'too many open files\n");
+            ret=i;
+            goto err;
+        }
+    }
+
+err:    
+    for(i=0;i<ret;i++){
+        ok( dos_close(fhs[i], &b), "dos_close complains\n" );
+        sprintf(fn, "file_%d.xxx", i );
+        ok( dos_unlink(fn, 0, &b), "dos_close complains\n" );
+    }
+    return ret;
+}
+
+
+static void test_set_handle_count( void )
+{
+	unsigned ret;
+    ok(max_open_files()==15, "max_open_files != 15\n");
+    ok(dos_set_handle_count(0, &ret), "dos_set_handle_count(0) failed\n");
+    ok(max_open_files()==15, "max_open_files != 15\n");
+    ok(dos_set_handle_count(21, &ret), "dos_set_handle_count(21) failed\n");
+    ok(max_open_files()==16, "max_open_files != 16\n");
+    ok(dos_set_handle_count(22, &ret), "dos_set_handle_count(21) failed\n");
+    ok(max_open_files()==17, "max_open_files != 16\n");
+
+/*
+ * Default System File Table size on windows is 20.
+ * So normally you can only open 17 files (20-3 default system files (stdio,prn.aux).
+ * That's why the foollowing test fails on DOS.
+ */
+/*
+    ok(dos_set_handle_count(100, &ret), "dos_set_handle_count(100) failed\n");
+    ok(max_open_files()==95, "max_open_files != 95\n");
+*/
+
+    ok(dos_set_handle_count(20, &ret), "dos_set_handle_count(20) failed\n");
+    ok(max_open_files()==15, "max_open_files != 15\n");
+}
+
+static void test_dos_read( void )
+{
+    unsigned filehandle;
+    char buffer[1000];
+    unsigned bytes_read;
+    long bytes_wanted;
+    long i;
+    unsigned ret;
+    long seeked;
+
+//    SetFileAttributes(filename,FILE_ATTRIBUTE_NORMAL); /* be sure to remove stale files */
+    dos_unlink( filename, 0, &ret );
+    ok (dos_creat( filename, 0, &filehandle), "couldn't create file\n");
+
+    ok( dos_write( filehandle, sillytext, strlen( sillytext ), &ret ), "dos_write complains\n" );
+
+    ok( dos_close(filehandle, &ret), "dos_close complains\n" );
+	 
+    if (! dos_open( filename, 0, 0, &filehandle)){
+        printf("couldn't open file errno=%d\n", filehandle);
+        return;
+    }
+    ok (dos_read (filehandle, buffer, 2 * strlen( sillytext ), &bytes_read), "couldn't read from file\n");
+
+    ok( strlen( sillytext ) == bytes_read, "file read size error\n" );
+
+    for (bytes_wanted = 0; bytes_wanted < strlen( sillytext ); bytes_wanted++)
+    {
+        ok( dos_lseek( filehandle, 0, FILE_BEGIN, &seeked ), "dos_lseek failed\n" );
+        ok( seeked==0, "dos_lseek seeked wrong 0\n");
+        ok( dos_read( filehandle, buffer, bytes_wanted, &ret ), "dos_read failed\n");
+        ok( ret == bytes_wanted, "erratic _hread return value\n" );
+        for (i = 0; i < bytes_wanted; i++)
+        {
+            ok( buffer[i] == sillytext[i], "that's not what's written\n" );
+        }
+    }
+
+    ok( dos_close(filehandle, &ret), "dos_close complains\n" );
+
+    ok( dos_unlink( filename, 0, &ret ), "dos_unlink failed\n" );
+}
+
+
+static void test_dos_open( void )
+{
+    unsigned filehandle;
+    unsigned bytes_read;
+    unsigned ret;
+    char buffer[1000];
+
+    ok (dos_creat( filename, 0, &filehandle), "couldn't create file\n");
+
+    ok( dos_write( filehandle, sillytext, strlen( sillytext ), &ret ), "dos_write complains\n" );
+
+    ok( dos_close(filehandle, &ret), "dos_close complains\n" );
+
+    ok( dos_open( filename, OF_READ, 0, &filehandle), "couldn't open file\n");
+    ok( !dos_write( filehandle, sillytext, strlen( sillytext ), &ret ), "dos_write shouldn't be able to write!\n" );
+    ok( dos_read( filehandle, buffer, strlen( sillytext ), &bytes_read ), "dos_read failed\n");
+    ok( strlen( sillytext )  == bytes_read, "file read size error\n" );
+    ok( dos_close(filehandle, &ret), "dos_close complains\n" );
+
+    ok( dos_open( filename, OF_READWRITE, 0, &filehandle), "couldn't open file\n");
+    ok( dos_read( filehandle, buffer, 2 * strlen( sillytext ), &bytes_read ), "dos_read failed\n");
+    ok( strlen( sillytext )  == bytes_read, "file read size error\n" );
+    ok( dos_write( filehandle, sillytext, strlen( sillytext ), &ret), "dos_write should write just fine\n" );
+    ok( dos_close(filehandle, &ret), "dos_close complains\n" );
+
+    ok( dos_open( filename, OF_WRITE, 0, &filehandle), "couldn't open file\n");
+    ok( !dos_read( filehandle, buffer, 1, &ret ), "you should only be able to write this file\n" );
+    ok( dos_write( filehandle, sillytext, strlen( sillytext ), &ret ), "dos_write should write just fine\n" );
+    ok( dos_close(filehandle, &ret), "dos_close complains\n" );
+
+    ok( dos_unlink( filename, 0, &ret ), "dos_unlink failed\n" );
+
+    ok( dos_open( "nul", 0, 0, &filehandle), "couldn't open 'nul' file\n");
+    ok( dos_close(filehandle, &ret), "dos_close complains\n" );
+
+    ok( dos_open( "C:\\nul", 0, 0, &filehandle), "couldn't open 'C:\\nul' file\n");
+    ok( dos_close(filehandle, &ret), "dos_close complains\n" );
+
+    ok( dos_open( "C:nul", 0, 0, &filehandle), "couldn't open 'C:\\nul' file\n");
+    ok( dos_close(filehandle, &ret), "dos_close complains\n" );
+
+    /* TODO - add tests for the SHARE modes  -  use two processes to pull this one off */
+}
+
+static void test_dos_dup( void )
+{
+    unsigned h1, h2, h3;
+    unsigned bytes_read;
+    unsigned ret;
+    long pos;
+    char buffer[1000];
+
+    ok (dos_creat( filename, 0, &h1), "couldn't create file\n");
+
+    ok( dos_write( h1, sillytext, strlen( sillytext ), &ret ), "dos_write complains\n" );
+    
+    ok( dos_dup(h1, &h2), "dos_dup failed\n");
+    
+    ok( dos_lseek( h1, 100, FILE_BEGIN, &pos ), "dos_lseek failed\n" );
+    ok( dos_lseek( h2, 0, FILE_CURRENT, &pos ), "dos_lseek failed\n" );
+    ok( pos==100, "dos_lseek should be bound together\n");
+
+    ok( dos_lseek( h2, 0, FILE_END, &pos ), "dos_lseek failed\n" );
+    ok( dos_write( h2, sillytext, strlen( sillytext ), &ret ), "dos_write complains\n" );
+    ok( dos_lseek( h1, 0, FILE_END, &pos ), "dos_lseek failed\n" );
+    ok( pos==2*strlen( sillytext ), "dos_write should be bound together\n");
+
+    ok( dos_close(h1, &ret), "dos_close complains\n" );
+
+    ok( dos_write(h2, sillytext, strlen( sillytext ), &ret ), "dos_write complains\n" );
+    ok( dos_close(h2, &ret), "dos_close complains\n" );
+
+    ok( dos_unlink( filename, 0, &ret ), "dos_unlink failed\n" );
+}
+
+static void test_dos_dup2( void )
+{
+    unsigned h1, h2, h3;
+    unsigned bytes_read;
+    unsigned ret;
+    long pos;
+    char buffer[1000];
+
+    ok (dos_creat( filename, 0, &h1), "couldn't create file\n");
+
+    ok( dos_write( h1, sillytext, strlen( sillytext ), &ret ), "dos_write complains\n" );
+
+    h2=12;    
+    ok( dos_dup2(h1, h2, &ret), "dos_dup2 failed\n");
+    
+    ok( dos_lseek( h1, 100, FILE_BEGIN, &pos ), "dos_lseek failed\n" );
+    ok( dos_lseek( h2, 0, FILE_CURRENT, &pos ), "dos_lseek failed\n" );
+    ok( pos==100, "dos_lseek should be bound together\n");
+
+    ok( dos_lseek( h2, 0, FILE_END, &pos ), "dos_lseek failed\n" );
+    ok( dos_write( h2, sillytext, strlen( sillytext ), &ret ), "dos_write complains\n" );
+    ok( dos_lseek( h1, 0, FILE_END, &pos ), "dos_lseek failed\n" );
+    ok( pos==2*strlen( sillytext ), "dos_write should be bound together\n");
+
+    ok( dos_close(h1, &ret), "dos_close complains\n" );
+
+    ok( dos_write(h2, sillytext, strlen( sillytext ), &ret ), "dos_write complains\n" );
+    ok( dos_close(h2, &ret), "dos_close complains\n" );
+
+    ok( dos_unlink( filename, 0, &ret ), "dos_unlink failed\n" );
+
+    /* check IO redirection */
+    ok( dos_creat( filename, 0, &h1), "couldn't create file\n");
+    ok( dos_dup(1, &h2), "dos_dup failed\n");
+    ok( dos_dup2(h1, 1, &ret), "dos_dup2 failed\n");
+    ok( dos_write( 1, sillytext, strlen( sillytext ), &ret ), "dos_write complains\n" );
+    ok( dos_lseek( 1, 0, FILE_END, &pos ), "dos_lseek failed\n" );
+    ok( pos==strlen( sillytext ), "dos_write should be bound together\n");
+
+    ok( dos_dup2(h2, 1, &ret), "dos_dup2 failed\n");
+    ok( dos_close(h2, &ret), "dos_close complains\n" );
+    ok( dos_close(h1, &ret), "dos_close complains\n" );
+
+    ok( dos_unlink( filename, 0, &ret ), "dos_unlink failed\n" );
+
+}
+
+static void test_dos_get_device_info( void )
+{
+    unsigned h1, h2, h3;
+    unsigned bytes_read;
+    unsigned ret;
+    unsigned flags;
+    long pos;
+    char buffer[1000];
+
+    ok( dos_open( "nul", 0, 0, &h1), "couldn't open 'nul' file\n");
+    ok( dos_get_device_info(h1, &ret), "dos_get_device info failed\n");
+    flags = IOCTL_DEVICE | DEVICE_NUL | DEVICE_EOF;
+    ok( (ret & 0xff) == flags, "nul wrong flags\n");
+
+    ok( dos_dup(1, &h2), "dos_dup failed\n");
+    ok( dos_dup2(h1, 1, &ret), "dos_dup2 failed\n");
+    ok( dos_get_device_info(1, &ret), "dos_get_device info failed\n");
+    ok( (ret & 0xff) == flags, "dup2 wrong flags\n");
+    ok( dos_dup2(h2, 1, &ret), "dos_dup2 failed\n");
+
+    ok( dos_close(h2, &ret), "dos_close complains\n" );
+    ok( dos_close(h1, &ret), "dos_close complains\n" );
+    
+
+    flags = IOCTL_DEVICE | DEVICE_STDIN | DEVICE_STDOUT | DEVICE_SPECIAL | DEVICE_EOF;
+    ok( dos_get_device_info(0, &ret), "dos_get_device info failed\n");
+    ok( (ret & 0xff) == flags, "0 wrong flags\n");
+
+    ok( dos_get_device_info(1, &ret), "dos_get_device info failed\n");
+    ok( (ret & 0xff) == flags, "1 wrong flags\n");
+
+    ok( dos_get_device_info(2, &ret), "dos_get_device info failed\n");
+    ok( (ret & 0xff) == flags, "2 wrong flags\n");
+
+    flags = IOCTL_DEVICE | DEVICE_EOF;
+    ok( dos_get_device_info(3, &ret), "dos_get_device info failed\n");
+    ok( (ret & 0xff) == flags, "3 wrong flags\n");
+
+    ok( dos_get_device_info(4, &ret), "dos_get_device info failed\n");
+    ok( (ret & 0xff) == flags, "4 wrong flags\n");
+
+}
+
+
+static void test_dos_close( void )
+{
+    unsigned filehandle;
+    unsigned ret;
+
+    ok (dos_creat( filename, 0, &filehandle), "couldn't create file\n");
+
+    ok( dos_write( filehandle, sillytext, strlen( sillytext ), &ret ), "dos_write complains\n" );
+
+    ok( dos_close(filehandle, &ret), "dos_close complains\n" );
+
+    ok( dos_unlink( filename, 0, &ret ), "dos_unlink failed\n" );
+}
+
+int main()
+{
+	unsigned seg;
+	unsigned ret, ret2, handle;
+	unsigned i;
+
+	test_set_handle_count();
+	test_dos_close();
+	test_dos_open();
+	test_dos_read();
+	test_dos_dup();
+	test_dos_dup2();
+    test_dos_get_device_info();
+	test_set_handle_count();        /* check for zombie files */
+
+	return 0;
+
+#if 0
+	ret = dos_open( "nul",0, 0, &handle); 
+	printf ("dos_open= %04x, %04x\n", ret, handle);
+	ret = dos_get_device_info( handle, &ret2); 
+	printf ("dos_open= %04x, %04x\n", ret, ret2);
+
+
+	i=20;
+		ret = dos_set_handle_count( 21, &ret2); 
+		printf ("dos_set_handle_count= %04x, %04x %d\n", ret, ret2, i);
+
+	printf ("max_open_files()=%d\n", max_open_files());
+	for (i=0; i<50; i++){
+		ret = dos_set_handle_count( i, &ret2); 
+		printf ("dos_set_handle_count= %04x, %04x %d\n", ret, ret2, i);
+    	printf ("max_open_files()=%d\n", max_open_files());
+	}
+	return 0;
+
+
+	printf ("max_open_files()=%d\n", max_open_files());
+	
+	ret = dos_get_psp(&seg);
+	printf ("dos_get_psp= %04x, %04x\n", ret, seg);
+
+	ret = dos_creat( 0, "tst.xxx", &handle); 
+	printf ("dos_creat= %04x, %04x\n", ret, handle);
+
+
+	ret = dos_dup( handle, &ret2); 
+	printf ("dos_dup= %04x, %04x\n", ret, ret2);
+
+	ret = dos_dup2( handle, 17, &ret2); 
+	printf ("dos_dup2= %04x, %04x\n", ret, ret2);
+
+	ret = dos_close( handle, &ret2); 
+	printf ("dos_close= %04x, %04x\n", ret, ret2);
+
+	ret = dos_unlink( "tst2.xxx", 0, &ret2); 
+	printf ("dos_unlink= %04x, %04x\n", ret, ret2);
+
+	ret = dos_rename( "tst.xxx", "tst3.xxx", 0, &ret2); 
+	printf ("dos_rename= %04x, %04x\n", ret, ret2);
+
+
+	return 0;
+#endif
+
+}
\ Kein Zeilenumbruch am Dateiende.


More information about the wine-patches mailing list