bool File::Test( ) { bool ok = true; cout << "Testing File" << endl; try { const string testDataFileName = "FileTest.dat"; char testData[ 266 ] = { 0, '\r', '\n', '\r', '\n', '\n', '\r', '\r', 0, '\n' }; for ( int i = 0; i < 256; ++i ) testData[ i + 10 ] = static_cast< char >( i ); DataBuffer buff; buff.Add( testData, 266 ); { cout << "FileWriter( string ) constructor" << endl; FileWriter writer( testDataFileName ); cout << "writer.Save( DataBuffer )" << endl; writer.Save( buff ); } TESTCHECK( FileExists( testDataFileName ), true, &ok ); TESTCHECK( FileSize( testDataFileName ), (int) (ARRAY_LENGTH( testData )), &ok ); DateTime now( true ); DateTime then = now; then.Increment( 0, 0, 0, 0, -1 ); //1 minute ago TESTCHECK( (now < FileModDate( testDataFileName )), false, &ok ); TESTCHECK( (then < FileModDate( testDataFileName )), true, &ok ); buff.Clear( ); { cout << "FileReader( string ) constructor" << endl; FileReader reader( testDataFileName ); cout << "writer.Load( DataBuffer * )" << endl; reader.Load( &buff ); } const vector< char > & testData1 = buff.Buffer(); TESTCHECK( testData1.size(), ARRAY_LENGTH( testData ), &ok ); TESTCHECK( memcmp( &testData1[0], testData, ARRAY_LENGTH( testData ) ), 0, &ok ); cout << "DeleteFile( string )" << endl; DeleteFile( testDataFileName ); TESTCHECK( FileExists( testDataFileName ), false, &ok ); const string testTextFileName = "FileTest.txt"; const string testText = "Four score and seven years ago\n" "our fathers set forth upon this continent\n\r" "a new nation,\r\n" "conceived in liberty\r" "and dedicated to the proposition\x0" "that all men are created equal."; { cout << "FileWriter( string, File::Text ) constructor" << endl; FileWriter writer( testTextFileName, File::Text ); cout << "writer.Save( string )" << endl; writer.Save( testText ); } TESTCHECK( FileExists( testTextFileName ), true, &ok ); string testText1; { cout << "FileReader( string, File::Text ) constructor" << endl; FileReader reader( testTextFileName, File::Text ); cout << "reader.Load( string * )" << endl; reader.Load( &testText1 ); } TESTCHECK( (testText1 == testText), true, &ok ); cout << "DeleteFile( string )" << endl; DeleteFile( testTextFileName ); TESTCHECK( FileExists( testTextFileName ), false, &ok ); } catch ( FileException & except ) { cout << except.Description() << endl; ok = false; } if ( ok ) cout << "File PASSED." << endl << endl; else cout << "File FAILED." << endl << endl; return ok; }