From 6c865a2b9cdebdb6c6e7678952039b35fc68bbe3 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Mon, 6 Sep 2004 06:39:57 +0000 Subject: [PATCH] update test_file_readers; write data with RageFile, too --- stepmania/src/tests/test_file_readers.cpp | 86 +++++++++++++++++------ 1 file changed, 65 insertions(+), 21 deletions(-) diff --git a/stepmania/src/tests/test_file_readers.cpp b/stepmania/src/tests/test_file_readers.cpp index 267f1849c0..8b21bea80d 100644 --- a/stepmania/src/tests/test_file_readers.cpp +++ b/stepmania/src/tests/test_file_readers.cpp @@ -5,16 +5,14 @@ #include "RageUtil_FileDB.h" #include "test_misc.h" -#include - bool CreateTestFiles = false; -void CreateBinaryTestFile( FILE *out, int size ) +void CreateBinaryTestFile( RageFile &f, int size ) { char c = 0; while( size-- ) { - fprintf( out, "%c", c ); + f.Write( ssprintf("%c", c) ); ++c; } } @@ -23,11 +21,11 @@ extern CString g_Root; void CreateBinaryTestFile( CString fn, int size ) { - FILE *out = fopen( g_Root + "/" + fn, "w+b" ); - CreateBinaryTestFile( out, size ); - fclose( out ); + RageFile f; + f.Open( g_Root + "/" + fn, RageFile::WRITE ); + CreateBinaryTestFile( f, size ); + f.Close(); - RageFile f(fn); if( !f.Open(fn) ) { LOG->Warn("CreateBinaryTestFile: error reopening %s: %s", fn.c_str(), f.GetError().c_str() ); @@ -103,23 +101,25 @@ void TestText( int LineSize, bool DOS ) filename += ssprintf( ".%i", LineSize ); if( CreateTestFiles ) { - FILE *out = fopen( g_Root + "/" + filename, "w+b" ); + RageFile f; + f.Open( g_Root + "/" + filename, RageFile::WRITE ); for( unsigned line = 0; line < NumLines; ++line ) { const CString TestLine = MakeTextTestLine( line, LineSize ); - fprintf( out, "%s", TestLine.c_str() ); + f.Write( TestLine ); if( DOS ) - fprintf( out, "\r" ); - fprintf( out, "\n" ); + f.Write( "\r" ); + f.Write( "\n" ); } /* Write a binary test block at the end. */ - CreateBinaryTestFile( out, 4096 ); + CreateBinaryTestFile( f, 4096 ); - fclose( out ); - out = NULL; - return; + /* Write a text line, with no NL. */ + f.Write( "final" ); + + return; } RageFile test; @@ -140,6 +140,14 @@ void TestText( int LineSize, bool DOS ) return; } + /* If we successfully got data, we should not be at EOF. */ + if( test.AtEOF() ) + { + LOG->Warn("Unexpected EOF in text read, line %i, size %i, DOS %i", + line, LineSize, DOS ); + return; + } + if( !CheckTextData( buf, line, LineSize ) ) { LOG->Warn("Text read check failure, line %i, size %i, DOS %i: '%s'", @@ -163,6 +171,42 @@ void TestText( int LineSize, bool DOS ) TestBinaryRead( test, 1024, true, test.Tell(), 1024*1 ); TestBinaryRead( test, 1024, true, test.Tell(), 1024*2 ); TestBinaryRead( test, 1024, true, test.Tell(), 1024*3 ); + + { + CString buf; + if( test.GetLine( buf ) <= 0 ) + { + LOG->Warn( "Unexpected EOF in final line read, DOS %i", DOS ); + return; + } + + if( buf != "final" ) + { + LOG->Warn( "Final text read check failure, DOS %i: '%s'", + DOS, buf.c_str() ); + return; + } + if( test.AtEOF() ) + { + LOG->Warn( "Unexpected EOF (2) in final text read, DOS %i", DOS ); + return; + } + } + + { + CString buf; + if( test.GetLine( buf ) != 0 ) + { + LOG->Warn( "Expected EOF in final text read, but didn't get it" ); + return; + } + + if( !test.AtEOF() ) + { + LOG->Warn( "Expected EOF (2) in final text read, but didn't get it" ); + return; + } + } } void TestText() @@ -204,11 +248,11 @@ void TestSeek( bool relative ) { /* Output a line of text, followed by some junk, followed by binary * test data. */ - FILE *out = fopen( g_Root + "/" + "test.seek", "w+b" ); - fprintf( out, "%s", TestLine.c_str() ); - fprintf( out, "%s", junk.c_str() ); - CreateBinaryTestFile( out, 1024 ); - fclose( out ); + RageFile f; + f.Open( g_Root + "/" + "test.seek", RageFile::WRITE ); + f.Write( TestLine ); + f.Write( junk ); + CreateBinaryTestFile( f, 1024 ); return; }