update test_file_readers; write data with RageFile, too
This commit is contained in:
@@ -5,16 +5,14 @@
|
|||||||
#include "RageUtil_FileDB.h"
|
#include "RageUtil_FileDB.h"
|
||||||
#include "test_misc.h"
|
#include "test_misc.h"
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
bool CreateTestFiles = false;
|
bool CreateTestFiles = false;
|
||||||
|
|
||||||
void CreateBinaryTestFile( FILE *out, int size )
|
void CreateBinaryTestFile( RageFile &f, int size )
|
||||||
{
|
{
|
||||||
char c = 0;
|
char c = 0;
|
||||||
while( size-- )
|
while( size-- )
|
||||||
{
|
{
|
||||||
fprintf( out, "%c", c );
|
f.Write( ssprintf("%c", c) );
|
||||||
++c;
|
++c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -23,11 +21,11 @@ extern CString g_Root;
|
|||||||
|
|
||||||
void CreateBinaryTestFile( CString fn, int size )
|
void CreateBinaryTestFile( CString fn, int size )
|
||||||
{
|
{
|
||||||
FILE *out = fopen( g_Root + "/" + fn, "w+b" );
|
RageFile f;
|
||||||
CreateBinaryTestFile( out, size );
|
f.Open( g_Root + "/" + fn, RageFile::WRITE );
|
||||||
fclose( out );
|
CreateBinaryTestFile( f, size );
|
||||||
|
f.Close();
|
||||||
|
|
||||||
RageFile f(fn);
|
|
||||||
if( !f.Open(fn) )
|
if( !f.Open(fn) )
|
||||||
{
|
{
|
||||||
LOG->Warn("CreateBinaryTestFile: error reopening %s: %s", fn.c_str(), f.GetError().c_str() );
|
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 );
|
filename += ssprintf( ".%i", LineSize );
|
||||||
if( CreateTestFiles )
|
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 )
|
for( unsigned line = 0; line < NumLines; ++line )
|
||||||
{
|
{
|
||||||
const CString TestLine = MakeTextTestLine( line, LineSize );
|
const CString TestLine = MakeTextTestLine( line, LineSize );
|
||||||
fprintf( out, "%s", TestLine.c_str() );
|
f.Write( TestLine );
|
||||||
if( DOS )
|
if( DOS )
|
||||||
fprintf( out, "\r" );
|
f.Write( "\r" );
|
||||||
fprintf( out, "\n" );
|
f.Write( "\n" );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write a binary test block at the end. */
|
/* Write a binary test block at the end. */
|
||||||
CreateBinaryTestFile( out, 4096 );
|
CreateBinaryTestFile( f, 4096 );
|
||||||
|
|
||||||
fclose( out );
|
/* Write a text line, with no NL. */
|
||||||
out = NULL;
|
f.Write( "final" );
|
||||||
return;
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
RageFile test;
|
RageFile test;
|
||||||
@@ -140,6 +140,14 @@ void TestText( int LineSize, bool DOS )
|
|||||||
return;
|
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 ) )
|
if( !CheckTextData( buf, line, LineSize ) )
|
||||||
{
|
{
|
||||||
LOG->Warn("Text read check failure, line %i, size %i, DOS %i: '%s'",
|
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*1 );
|
||||||
TestBinaryRead( test, 1024, true, test.Tell(), 1024*2 );
|
TestBinaryRead( test, 1024, true, test.Tell(), 1024*2 );
|
||||||
TestBinaryRead( test, 1024, true, test.Tell(), 1024*3 );
|
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()
|
void TestText()
|
||||||
@@ -204,11 +248,11 @@ void TestSeek( bool relative )
|
|||||||
{
|
{
|
||||||
/* Output a line of text, followed by some junk, followed by binary
|
/* Output a line of text, followed by some junk, followed by binary
|
||||||
* test data. */
|
* test data. */
|
||||||
FILE *out = fopen( g_Root + "/" + "test.seek", "w+b" );
|
RageFile f;
|
||||||
fprintf( out, "%s", TestLine.c_str() );
|
f.Open( g_Root + "/" + "test.seek", RageFile::WRITE );
|
||||||
fprintf( out, "%s", junk.c_str() );
|
f.Write( TestLine );
|
||||||
CreateBinaryTestFile( out, 1024 );
|
f.Write( junk );
|
||||||
fclose( out );
|
CreateBinaryTestFile( f, 1024 );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user