First attempt at unit testing. Victim of choice: _hread()

Jakob Eriksson jakob at vmlinux.org
Thu Apr 25 18:59:46 CDT 2002


Thanks to Vincent Béron and Francois Gouget I've managed to do my
own little unit test.

I post it here hoping for comments of any kind:
possible improvements, additions, advice etc.

(I guess I could add some more limit-tests, trying to read
many small chunks in a row see that I still end up in the right place
in the file. Things like that.)

--------

#include "winbase.h"
#include "winerror.h"
#include "wine/test.h"

static void test__hread( void )
{
    LPCSTR filename = "testfile.xxx";
    LPCSTR sillytext = "en larvig liten text dx \033 gx hej 84 hej 4484 ! \001\033 bla bla...";
    HFILE filehandle;
    char buffer[10000];
    long bytes_read;
    UINT bytes_wanted;
    UINT i;

    filehandle = _lcreat( filename, 0 );

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

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

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

    filehandle = _lopen( filename, OF_READ );
    
    bytes_read = _hread( filehandle, buffer, 2 * strlen( sillytext ));
    
    ok( strlen( sillytext ) == bytes_read, "file has wrong size.");

    for (bytes_wanted = 0; bytes_wanted < strlen( sillytext ); bytes_wanted++)
    {
        ok( 0 == _llseek( filehandle, 0, FILE_BEGIN ), "_llseek complains." );
        ok( _hread( 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." );
}


START_TEST(file)
{
    test__hread( );
}

-- 
regards,
Jakob Eriksson

The wages of sin
  is debugging.
		  	-- Ron Jeffries




More information about the wine-devel mailing list