From 144885ad15d9c6bbd4a5e4b9c046fa907663060d Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 6 Jun 2004 23:31:20 +0000 Subject: [PATCH] RageFileObjTest::Flush --- stepmania/src/tests/test_file_errors.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/stepmania/src/tests/test_file_errors.cpp b/stepmania/src/tests/test_file_errors.cpp index 33a9f6c699..a96f19e813 100644 --- a/stepmania/src/tests/test_file_errors.cpp +++ b/stepmania/src/tests/test_file_errors.cpp @@ -76,7 +76,7 @@ public: RageFileObjTest( const CString &path, RageFile &p ); int Read(void *buffer, size_t bytes); int Write(const void *buffer, size_t bytes); - int Flush() { return 0; } + int Flush(); void Rewind() { pos = 0; } int Seek( int offset ) { @@ -168,6 +168,26 @@ int RageFileObjTest::Write( const void *buf, size_t bytes ) return bytes; } +/* + * Testing Flush() is important. Writing may buffer. That buffer will be + * flushed, at the latest, when the file is closed in the RageFile dtor. However, + * if you wait until then, there's no way to check for an error; the file is + * going away. The primary purpose of Flush() is to give the user a chance to + * check for these errors. (Flush() is only intended to flush our buffers; + * it is *not* intended to sync data to disk.) + */ +int RageFileObjTest::Flush() +{ + if( g_BytesUntilError != -1 ) + { + SetError( "Fake error" ); + g_BytesUntilError = -1; + return -1; + } + + return 0; +} + #define Fail(s...) \ { \ LOG->Warn( s ); break; \