wine/dlls/msvcrt tests/file.c file.c

Alexandre Julliard julliard at wine.codeweavers.com
Wed Nov 16 05:47:51 CST 2005


ChangeSet ID:	21299
CVSROOT:	/opt/cvs-commit
Module name:	wine
Changes by:	julliard at winehq.org	2005/11/16 05:47:51

Modified files:
	dlls/msvcrt/tests: file.c 
	dlls/msvcrt    : file.c 

Log message:
	Saulius Krasuckas <saulius.krasuckas at ieee.org>
	Fix _fcloseall() return value.
	Improve some trace messages.
	Add tests for fopen(), fclose(), _fcloseall().
	Stricten some checks of _unlink().

Patch: http://cvs.winehq.org/patch.py?id=21299

Old revision  New revision  Changes     Path
 1.19          1.20          +46 -4      wine/dlls/msvcrt/tests/file.c
 1.91          1.92          +3 -3       wine/dlls/msvcrt/file.c

Index: wine/dlls/msvcrt/tests/file.c
diff -u -p wine/dlls/msvcrt/tests/file.c:1.19 wine/dlls/msvcrt/tests/file.c:1.20
--- wine/dlls/msvcrt/tests/file.c:1.19	16 Nov 2005 11:47:51 -0000
+++ wine/dlls/msvcrt/tests/file.c	16 Nov 2005 11:47:51 -0000
@@ -265,7 +265,7 @@ static void test_file_write_read( void )
   _close(tempfd);
 
   ret = unlink(tempf);
-  ok( ret !=-1 ,"Can't unlink '%s': %d\n", tempf, errno);
+  ok( ret == 0 ,"Can't unlink '%s': %d\n", tempf, errno);
 
   tempf=_tempnam(".","wne");
   tempfd = _open(tempf,_O_CREAT|_O_TRUNC|_O_BINARY|_O_RDWR,0);
@@ -292,7 +292,7 @@ static void test_file_write_read( void )
   ok( ret == 0,
      "Can't chmod '%s' to read-write: %d\n", tempf, errno);
   ret = unlink(tempf);
-  ok( ret !=-1 ,"Can't unlink '%s': %d\n", tempf, errno);
+  ok( ret == 0 ,"Can't unlink '%s': %d\n", tempf, errno);
 }
 
 static void test_file_inherit_child(const char* fd_s)
@@ -335,7 +335,7 @@ static void test_file_inherit( const cha
     lseek(fd, 0, SEEK_SET);
     ok(read(fd, buffer, sizeof (buffer)) == 8 && memcmp(buffer, "Success", 8) == 0, "Couldn't read back the data\n");
     close (fd);
-    ok(unlink("fdopen.tst") != 1, "Couldn't unlink\n");
+    ok(unlink("fdopen.tst") == 0, "Couldn't unlink\n");
     
     fd = open ("fdopen.tst", O_CREAT | O_RDWR | O_BINARY | O_NOINHERIT, _S_IREAD |_S_IWRITE);
     ok(fd != -1, "Couldn't create test file\n");
@@ -348,7 +348,7 @@ static void test_file_inherit( const cha
     ok(tell(fd) == 0, "bad position %lu expecting 0\n", tell(fd));
     ok(read(fd, buffer, sizeof (buffer)) == 0, "Found unexpected data (%s)\n", buffer);
     close (fd);
-    ok(unlink("fdopen.tst") != 1, "Couldn't unlink\n");
+    ok(unlink("fdopen.tst") == 0, "Couldn't unlink\n");
 }
 
 static void test_tmpnam( void )
@@ -406,6 +406,47 @@ static void test_chsize( void )
     _unlink( tempfile );
 }
 
+static void test_fopen_fclose_fcloseall( void )
+{
+    char fname1[] = "empty1";
+    char fname2[] = "empty2";
+    char fname3[] = "empty3";
+    FILE *stream1, *stream2, *stream3;
+    int ret, numclosed;
+
+    /* testing fopen() */
+    stream1 = fopen(fname1, "w+");
+    ok(stream1 != NULL, "The file '%s' was not opened\n", fname1);
+    stream2 = fopen(fname2, "w ");
+    ok(stream2 != NULL, "The file '%s' was not opened\n", fname2 );
+    _unlink(fname3);
+    stream3 = fopen(fname3, "r");
+    ok(stream3 == NULL, "The file '%s' shouldn't exist before\n", fname3 );
+    stream3 = fopen(fname3, "w+");
+    ok(stream3 != NULL, "The file '%s' should be opened now\n", fname3 );
+
+    /* testing fclose() */
+    ret = fclose(stream2);
+    ok(ret == 0, "The file '%s' was not closed\n", fname2);
+    ret = fclose(stream3);
+    ok(ret == 0, "The file '%s' was not closed\n", fname3);
+    ret = fclose(stream2);
+    ok(ret == EOF, "Closing file '%s' returned %d\n", fname2, ret);
+    ret = fclose(stream3);
+    ok(ret == EOF, "Closing file '%s' returned %d\n", fname3, ret);
+
+    /* testing fcloseall() */
+    numclosed = _fcloseall();
+    /* fname1 should be closed here */
+    ok(numclosed == 1, "Number of files closed by fcloseall(): %u\n", numclosed);
+    numclosed = _fcloseall();
+    ok(numclosed == 0, "Number of files closed by fcloseall(): %u\n", numclosed);
+
+    ok(_unlink(fname1) == 0, "Couldn't unlink file named '%s'\n", fname1);
+    ok(_unlink(fname2) == 0, "Couldn't unlink file named '%s'\n", fname2);
+    ok(_unlink(fname3) == 0, "Couldn't unlink file named '%s'\n", fname3);
+}
+
 START_TEST(file)
 {
     int arg_c;
@@ -420,6 +461,7 @@ START_TEST(file)
     }
 
     test_fdopen();
+    test_fopen_fclose_fcloseall();
     test_fileops();
     test_fgetwc();
     test_file_put_get();
Index: wine/dlls/msvcrt/file.c
diff -u -p wine/dlls/msvcrt/file.c:1.91 wine/dlls/msvcrt/file.c:1.92
--- wine/dlls/msvcrt/file.c:1.91	16 Nov 2005 11:47:51 -0000
+++ wine/dlls/msvcrt/file.c	16 Nov 2005 11:47:51 -0000
@@ -529,7 +529,7 @@ int _wchmod(const MSVCRT_wchar_t *path, 
  */
 int _unlink(const char *path)
 {
-  TRACE("(%s)\n",path);
+  TRACE("%s\n",debugstr_a(path));
   if(DeleteFileA(path))
     return 0;
   TRACE("failed (%ld)\n",GetLastError());
@@ -762,7 +762,7 @@ int MSVCRT__fcloseall(void)
   LOCK_FILES();
   for (i = 3; i < MSVCRT_stream_idx; i++)
     if (MSVCRT_fstreams[i] && MSVCRT_fstreams[i]->_flag &&
-        MSVCRT_fclose(MSVCRT_fstreams[i]))
+        !MSVCRT_fclose(MSVCRT_fstreams[i]))
       num_closed++;
   UNLOCK_FILES();
 
@@ -2083,7 +2083,7 @@ int MSVCRT_fclose(MSVCRT_FILE* file)
 
   file->_flag = 0;
 
-  return ((r==MSVCRT_EOF) || (flag & MSVCRT__IOERR) ? MSVCRT_EOF : 0);
+  return ((r == -1) || (flag & MSVCRT__IOERR) ? MSVCRT_EOF : 0);
 }
 
 /*********************************************************************



More information about the wine-cvs mailing list