Better failure messages for file test

Francois Gouget fgouget at free.fr
Mon May 20 19:47:42 CDT 2002


I modified the messages of the 'file' regression test so that it would
print better diagnostics messages when failing on NT.


Changelog:

 * dlls/kernel/tests/file.c

   Improve the failure messages


--
Francois Gouget         fgouget at free.fr        http://fgouget.free.fr/
                            $live{free} || die "";


Index: dlls/kernel/tests/file.c
===================================================================
RCS file: /home/wine/wine/dlls/kernel/tests/file.c,v
retrieving revision 1.4
diff -u -r1.4 file.c
--- dlls/kernel/tests/file.c	10 May 2002 01:10:04 -0000	1.4
+++ dlls/kernel/tests/file.c	21 May 2002 00:43:02 -0000
@@ -49,9 +48,14 @@
     long bytes_read;
     long bytes_wanted;
     UINT i;
+    int rc;

     filehandle = _lcreat( filename, 0 );
-    ok( HFILE_ERROR != filehandle, "couldn't create file. Wrong permissions on directory?" );
+    if (filehandle == HFILE_ERROR)
+    {
+        ok(0,"couldn't create file \"%s\" (err=%d)",filename,GetLastError());
+        return;
+    }

     ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains." );

@@ -59,10 +63,10 @@

     filehandle = _lopen( filename, OF_READ );

-    ok( HFILE_ERROR != filehandle, "couldn't open file again?");
-
+    ok( HFILE_ERROR != filehandle, "couldn't open file \"%s\" again (err=%d)", filename, GetLastError());
+
     bytes_read = _hread( filehandle, buffer, 2 * strlen( sillytext ) );
-
+
     ok( strlen( sillytext ) == bytes_read, "file read size error." );

     for (bytes_wanted = 0; bytes_wanted < strlen( sillytext ); bytes_wanted++)
@@ -77,7 +81,8 @@

     ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains." );

-    ok( DeleteFileA( filename ) != 0, "DeleteFile complains." );
+    rc=DeleteFileA(filename);
+    ok( rc != 0, "DeleteFile failed (%d).", GetLastError());
 }


@@ -92,16 +97,21 @@
     char *contents;
     HLOCAL memory_object;
     char checksum[1];
+    int rc;

     filehandle = _lcreat( filename, 0 );
-    ok( HFILE_ERROR != filehandle, "couldn't create file. Wrong permissions on directory?" );
+    if (filehandle == HFILE_ERROR)
+    {
+        ok(0,"couldn't create file \"%s\" (err=%d)",filename,GetLastError());
+        return;
+    }

     ok( HFILE_ERROR != _hwrite( 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." );
@@ -156,16 +166,22 @@

     ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains." );

-    ok( DeleteFileA( filename ) != 0, "DeleteFile complains." );
+    rc=DeleteFileA(filename);
+    ok( rc != 0, "DeleteFile failed (%d).", GetLastError());
 }


 static void test__lclose( void )
 {
     HFILE filehandle;
+    int rc;

     filehandle = _lcreat( filename, 0 );
-    ok( HFILE_ERROR != filehandle, "couldn't create file. Wrong permissions on directory?" );
+    if (filehandle == HFILE_ERROR)
+    {
+        ok(0,"couldn't create file \"%s\" (err=%d)",filename,GetLastError());
+        return;
+    }

     ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains." );

@@ -175,7 +191,8 @@

     ok( HFILE_ERROR == _lclose(filehandle), "_lclose should whine about this." );

-    ok( DeleteFileA( filename ) != 0, "DeleteFileA complains." );
+    rc=DeleteFileA(filename);
+    ok( rc != 0, "DeleteFile failed (%d).", GetLastError());
 }


@@ -184,9 +201,14 @@
     HFILE filehandle;
     char buffer[10000];
     WIN32_FIND_DATAA search_results;
+    int rc;

     filehandle = _lcreat( filename, 0 );
-    ok( HFILE_ERROR != filehandle, "couldn't create file. Wrong permissions on directory?" );
+    if (filehandle == HFILE_ERROR)
+    {
+        ok(0,"couldn't create file \"%s\" (err=%d)",filename,GetLastError());
+        return;
+    }

     ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains." );

@@ -198,10 +220,11 @@

     ok( INVALID_HANDLE_VALUE != FindFirstFileA( filename, &search_results ), "should be able to find file" );

-    ok( DeleteFileA( filename ) != 0, "DeleteFileA complains." );
+    rc=DeleteFileA(filename);
+    ok( rc != 0, "DeleteFile failed (%d).", GetLastError());

     filehandle = _lcreat( filename, 1 );
-    ok( HFILE_ERROR != filehandle, "couldn't create file!?" );
+    ok( HFILE_ERROR != filehandle, "couldn't create file \"%s\" (err=%d)", filename, GetLastError());

     ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite shouldn't be able to write never the less." );

@@ -209,11 +232,12 @@

     ok( INVALID_HANDLE_VALUE != FindFirstFileA( filename, &search_results ), "should be able to find file" );

-    ok( DeleteFileA( filename ) != 0, "DeleteFileA complains." );
+    rc=DeleteFileA(filename);
+    ok( rc != 0, "DeleteFile failed (%d).", GetLastError());


     filehandle = _lcreat( filename, 2 );
-    ok( HFILE_ERROR != filehandle, "couldn't create file. Wrong permissions on directory?" );
+    ok( HFILE_ERROR != filehandle, "couldn't create file \"%s\" (err=%d)", filename, GetLastError());

     ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains." );

@@ -228,10 +252,11 @@
         ok( INVALID_HANDLE_VALUE == FindFirstFileA( filename, &search_results ), "should NOT be able to find file" );
     }

-    ok( DeleteFileA( filename ) != 0, "DeleteFileA complains." );
-
+    rc=DeleteFileA(filename);
+    ok( rc != 0, "DeleteFile failed (%d).", GetLastError());
+
     filehandle = _lcreat( filename, 4 );
-    ok( HFILE_ERROR != filehandle, "couldn't create file. Wrong permissions on directory?" );
+    ok( HFILE_ERROR != filehandle, "couldn't create file \"%s\" (err=%d)", filename, GetLastError());

     ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains." );

@@ -246,7 +271,8 @@
         ok( INVALID_HANDLE_VALUE == FindFirstFileA( filename, &search_results ), "should NOT be able to find file" );
     }

-    ok( DeleteFileA( filename ) != 0, "DeleteFileA complains." );
+    rc=DeleteFileA(filename);
+    ok( rc != 0, "DeleteFile failed (%d).", GetLastError());
 }


@@ -256,10 +282,15 @@
     HFILE filehandle;
     char buffer[1];
     long bytes_read;
+    int rc;

     filehandle = _lcreat( filename, 0 );
+    if (filehandle == HFILE_ERROR)
+    {
+        ok(0,"couldn't create file \"%s\" (err=%d)",filename,GetLastError());
+        return;
+    }

-    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." );
@@ -278,7 +309,8 @@
     ok( HFILE_ERROR != _llseek( filehandle, 1000000, FILE_END ), "should be able to seek past file. Poor, poor Windows programmers." );
     ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains." );

-    ok( DeleteFileA( filename ) != 0, "DeleteFileA complains." );
+    rc=DeleteFileA(filename);
+    ok( rc != 0, "DeleteFile failed (%d).", GetLastError());
 }


@@ -287,9 +319,15 @@
     HFILE filehandle;
     UINT bytes_read;
     char buffer[10000];
+    int rc;

     filehandle = _lcreat( filename, 0 );
-    ok( HFILE_ERROR != filehandle, "couldn't create file. Wrong permissions on directory?" );
+    if (filehandle == HFILE_ERROR)
+    {
+        ok(0,"couldn't create file \"%s\" (err=%d)",filename,GetLastError());
+        return;
+    }
+
     ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains." );
     ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains." );

@@ -298,7 +336,7 @@
     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." );
@@ -310,7 +348,8 @@
     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." );
+    rc=DeleteFileA(filename);
+    ok( rc != 0, "DeleteFile failed (%d).", GetLastError());
     /* TODO - add tests for the SHARE modes  -  use two processes to pull this one off */
 }

@@ -322,9 +361,14 @@
     long bytes_read;
     UINT bytes_wanted;
     UINT i;
+    int rc;

     filehandle = _lcreat( filename, 0 );
-    ok( HFILE_ERROR != filehandle, "couldn't create file. Wrong permissions on directory?" );
+    if (filehandle == HFILE_ERROR)
+    {
+        ok(0,"couldn't create file \"%s\" (err=%d)",filename,GetLastError());
+        return;
+    }

     ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains." );

@@ -332,10 +376,10 @@

     filehandle = _lopen( filename, OF_READ );

-    ok( HFILE_ERROR != filehandle, "couldn't open file again?");
-
+    ok( HFILE_ERROR != filehandle, "couldn't open file \"%s\" again (err=%d)", filename, GetLastError());
+
     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++)
@@ -350,7 +394,8 @@

     ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains." );

-    ok( DeleteFileA( filename ) != 0, "DeleteFile complains." );
+    rc=DeleteFileA(filename);
+    ok( rc != 0, "DeleteFile failed (%d).", GetLastError());
 }


@@ -365,16 +410,21 @@
     char *contents;
     HLOCAL memory_object;
     char checksum[1];
+    int rc;

     filehandle = _lcreat( filename, 0 );
-    ok( HFILE_ERROR != filehandle, "couldn't create file. Wrong permissions on directory?" );
+    if (filehandle == HFILE_ERROR)
+    {
+        ok(0,"couldn't create file \"%s\" (err=%d)",filename,GetLastError());
+        return;
+    }

     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." );
@@ -429,7 +479,8 @@

     ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains." );

-    ok( DeleteFileA( filename ) != 0, "DeleteFile complains." );
+    rc=DeleteFileA(filename);
+    ok( rc != 0, "DeleteFile failed (%d).", GetLastError());
 }






More information about the wine-patches mailing list