Ejemplo n.º 1
0
int main( void )
{
    FILE * fh;
#ifndef REGTEST
    char filename[ L_tmpnam ];
    FILE * fhtest;
#endif
    TESTCASE( ( fh = tmpfile() ) != NULL );
    TESTCASE( fputc( 'x', fh ) == 'x' );
    /* Checking that file is actually there */
    TESTCASE_NOREG( strcpy( filename, fh->filename ) == filename );
    TESTCASE_NOREG( ( fhtest = fopen( filename, "r" ) ) != NULL );
    TESTCASE_NOREG( fclose( fhtest ) == 0 );
    /* Closing tmpfile */
    TESTCASE( fclose( fh ) == 0 );
    /* Checking that file was deleted */
    TESTCASE_NOREG( fopen( filename, "r" ) == NULL );
    return TEST_RESULTS;
}
Ejemplo n.º 2
0
int main( void )
{
    /* Testing all the basic I/O functions individually would result in lots
       of duplicated code, so I took the liberty of lumping it all together
       here.
    */
    /* The following functions delegate their tests to here:
       fgetc fflush rewind fputc ungetc fseek
       flushbuffer seek fillbuffer prepread prepwrite
    */
    char * buffer = (char*)malloc( 4 );
    FILE * fh;
    TESTCASE( ( fh = tmpfile() ) != NULL );
    TESTCASE( setvbuf( fh, buffer, _IOLBF, 4 ) == 0 );
    /* Testing ungetc() at offset 0 */
    rewind( fh );
    TESTCASE( ungetc( 'x', fh ) == 'x' );
    TESTCASE( ftell( fh ) == -1l );
    rewind( fh );
    TESTCASE( ftell( fh ) == 0l );
    /* Commence "normal" tests */
    TESTCASE( fputc( '1', fh ) == '1' );
    TESTCASE( fputc( '2', fh ) == '2' );
    TESTCASE( fputc( '3', fh ) == '3' );
    /* Positions incrementing as expected? */
    TESTCASE( ftell( fh ) == 3l );
    TESTCASE_NOREG( fh->pos.offset == 0l );
    TESTCASE_NOREG( fh->bufidx == 3l );
    /* Buffer properly flushed when full? */
    TESTCASE( fputc( '4', fh ) == '4' );
    TESTCASE_NOREG( fh->pos.offset == 4l );
    TESTCASE_NOREG( fh->bufidx == 0 );
    /* fflush() resetting positions as expected? */
    TESTCASE( fputc( '5', fh ) == '5' );
    TESTCASE( fflush( fh ) == 0 );
    TESTCASE( ftell( fh ) == 5l );
    TESTCASE_NOREG( fh->pos.offset == 5l );
    TESTCASE_NOREG( fh->bufidx == 0l );
    /* rewind() resetting positions as expected? */
    rewind( fh );
    TESTCASE( ftell( fh ) == 0l );
    TESTCASE_NOREG( fh->pos.offset == 0 );
    TESTCASE_NOREG( fh->bufidx == 0 );
    /* Reading back first character after rewind for basic read check */
    TESTCASE( fgetc( fh ) == '1' );
    /* TODO: t.b.c. */
    TESTCASE( fclose( fh ) == 0 );
    return TEST_RESULTS;
}
Ejemplo n.º 3
0
int main( void )
{
    TESTCASE(wctype("")   == 0);
    TESTCASE_NOREG(wctype(NULL) == 0); // mingw libc crashes on this

    TESTCASE(wctype("alpha")  != 0);
    TESTCASE(wctype("alnum")  != 0);
    TESTCASE(wctype("blank")  != 0);
    TESTCASE(wctype("cntrl")  != 0);
    TESTCASE(wctype("digit")  != 0);
    TESTCASE(wctype("graph")  != 0);
    TESTCASE(wctype("lower")  != 0);
    TESTCASE(wctype("print")  != 0);
    TESTCASE(wctype("punct")  != 0);
    TESTCASE(wctype("space")  != 0);
    TESTCASE(wctype("upper")  != 0);
    TESTCASE(wctype("xdigit") != 0);

    TESTCASE_NOREG(wctype("alpha")  == _PDCLIB_CTYPE_ALPHA);
    TESTCASE_NOREG(wctype("alnum")  == (_PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_DIGIT));
    TESTCASE_NOREG(wctype("blank")  == _PDCLIB_CTYPE_BLANK);
    TESTCASE_NOREG(wctype("cntrl")  == _PDCLIB_CTYPE_CNTRL);
    TESTCASE_NOREG(wctype("digit")  == _PDCLIB_CTYPE_DIGIT);
    TESTCASE_NOREG(wctype("graph")  == _PDCLIB_CTYPE_GRAPH);
    TESTCASE_NOREG(wctype("lower")  == _PDCLIB_CTYPE_LOWER);
    TESTCASE_NOREG(wctype("print")  == (_PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_SPACE));
    TESTCASE_NOREG(wctype("punct")  == _PDCLIB_CTYPE_PUNCT);
    TESTCASE_NOREG(wctype("space")  == _PDCLIB_CTYPE_SPACE);
    TESTCASE_NOREG(wctype("upper")  == _PDCLIB_CTYPE_UPPER);
    TESTCASE_NOREG(wctype("xdigit") == _PDCLIB_CTYPE_XDIGT);
    return TEST_RESULTS;
}