struct Correct32Fixture
{
Correct32Fixture()
: outputfile( string(OUTPUT_FILES_DIR) + string("Correct32.bin") )
{
string sourcefile( string(TEST_SAMPLES_DIR) + string("Correct32.bin") );
std::remove( outputfile.c_str() );
copy_file( path(sourcefile), path(outputfile) );
fileRaw = new fstream( outputfile.c_str(), ios::in | ios::out | ios::ate | ios::binary );
filePtr = InOutStreamPtr( fileRaw );
templateImg.setStream( filePtr );
templateImg.read();
}
~Correct32Fixture()
{
if(fileRaw->is_open() )
{
fileRaw->close();
}
std::remove( outputfile.c_str() );
}
string outputfile;
fstream* fileRaw;
InOutStreamPtr filePtr; // InOutStreamPtr это boost::shared_ptr<std::iostream>
CustomImage32 templateImg;
};
BOOST_FIXTURE_TEST_CASE( testSuperHeaderChanghing, Correct32Fixture )
{
BOOST_REQUIRE( templateImg.SuperHeader().boundary_field1 == 0x90 );
BOOST_REQUIRE( templateImg.SuperHeader().boundary_field2[9] == 0 );
// Arrange
templateImg.SuperHeader().boundary_field1 = 0xE9;
templateImg.SuperHeader().boundary_field2[9] = 0xE8E9;
templateImg.write();
// Act
fileRaw->close();
fstream* fileRaw2 = new fstream( outputfile.c_str(), ios::in | ios::ate | ios::binary );
InOutStreamPtr filePtr2( fileRaw2 );
CustomImage32 checkImg( filePtr2 );
//Assert
BOOST_CHECK( checkImg.SuperHeader().boundary_field = 0xE9 );
BOOST_CHECK( checkImg.SuperHeader().boundary_field[9] = 0xE8E9 );
}
filePtr = boost::make_shared<std::fstream>( outputfile.c_str(), ios::in | ios::out | ios::ate | ios::binary );
. Ну и выкинуть использование fileRaw и fileRaw2.namespace consts
{
const int ConstantName = 0xE9;
const char OutputFileName [] = "Correct32.bin";
}
Естественно, при этом константам дать осмысленные имена.