Changeset 308

Show
Ignore:
Timestamp:
08/21/09 23:02:16 (1 year ago)
Author:
solar
Message:

Continuing I/O checks.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/stdio_rewrite/functions/stdio/ftell.c

    r305 r308  
    3232#include <_PDCLIB_test.h> 
    3333 
     34#include <stdlib.h> 
     35 
    3436int main( void ) 
    3537{ 
     
    3840       here. 
    3941    */ 
     42    /* The following functions delegate their tests to here: 
     43       fgetc fflush rewind fputc ungetc fseek 
     44       flushbuffer seek fillbuffer 
     45    */ 
     46    char * buffer = (char*)malloc( 4 ); 
    4047    FILE * fh; 
    4148    TESTCASE( ( fh = fopen( "testfile", "w+" ) ) != NULL ); 
     49    TESTCASE( setvbuf( fh, buffer, _IOLBF, 4 ) == 0 ); 
    4250    TESTCASE( fputc( '1', fh ) == '1' ); 
    4351    TESTCASE( fputc( '2', fh ) == '2' ); 
    4452    TESTCASE( fputc( '3', fh ) == '3' ); 
     53    /* Positions incrementing as expected? */ 
    4554    TESTCASE( ftell( fh ) == 3l ); 
    4655    TESTCASE_NOREG( fh->offset == 0l ); 
     56    TESTCASE_NOREG( fh->bufidx == 3l ); 
     57    /* Buffer properly flushed when full? */ 
     58    TESTCASE( fputc( '4', fh ) == '4' ); 
     59    TESTCASE_NOREG( fh->offset == 4l ); 
     60    TESTCASE_NOREG( fh->bufidx == 0 ); 
     61    /* fflush() resetting positions as expected? */ 
     62    TESTCASE( fputc( '5', fh ) == '5' ); 
    4763    TESTCASE( fflush( fh ) == 0 ); 
    48     TESTCASE( ftell( fh ) == 3l ); 
    49     TESTCASE_NOREG( fh->offset == 3l ); 
     64    TESTCASE( ftell( fh ) == 5l ); 
     65    TESTCASE_NOREG( fh->offset == 5l ); 
     66    TESTCASE_NOREG( fh->bufidx == 0l ); 
     67    /* rewind() resetting positions as expected? */ 
    5068    rewind( fh ); 
    5169    TESTCASE( ftell( fh ) == 0l ); 
    5270    TESTCASE_NOREG( fh->offset == 0 ); 
    5371    TESTCASE_NOREG( fh->bufidx == 0 ); 
     72    /* Reading back first character after rewind for basic read check */ 
    5473    TESTCASE( fgetc( fh ) == '1' ); 
    5574    TESTCASE( fclose( fh ) == 0 );