diff --git a/sammy/src/io/tests/OdfIOTest.cpp b/sammy/src/io/tests/OdfIOTest.cpp index a6277947bcd4c955d6fdc4dec77568ef909b8045..dccc8c14c65ad4da730788f8920f19c2cde066df 100644 --- a/sammy/src/io/tests/OdfIOTest.cpp +++ b/sammy/src/io/tests/OdfIOTest.cpp @@ -20,23 +20,10 @@ TEST(OdfIO,readFloatVax) int vax = 0b00000001000000010000010000000011; // byte order 2--, 1, 4, 3 - std::ofstream out("deleteme",std::ios::binary | std::ios::out ); - if( !out ){ - throw std::runtime_error("Could not write to temp file in odf test."); - } - // --- write it out byte-by-byte --- - out.write( (char*) &byte1, sizeof(char) ); - out.write( (char*) &byte2, sizeof(char) ); - out.write( (char*) &byte3, sizeof(char) ); - out.write( (char*) &byte4, sizeof(char) ); - out.close(); + std::stringstream in; + in << byte1 << byte2 << byte3 << byte4; - std::ifstream in("deleteme",std::ios::binary | std::ios::in ); - if( !in ){ - throw std::runtime_error("Could not read from temp file in odf test."); - } readVal = odf.readFloat(in,is_unix); - in.close(); dummy = (float *) &vax; gold = *dummy; @@ -61,23 +48,10 @@ TEST(OdfIO,readFloatUnix) // | | | | int unix = 0b00000100000000110000001000000001; - std::ofstream out("deleteme",std::ios::binary | std::ios::out ); - if( !out ){ - throw std::runtime_error("Could not write to temp file in odf test."); - } - // --- write it out byte-by-byte --- - out.write( (char*) &byte1, sizeof(char) ); - out.write( (char*) &byte2, sizeof(char) ); - out.write( (char*) &byte3, sizeof(char) ); - out.write( (char*) &byte4, sizeof(char) ); - out.close(); + std::stringstream in; + in << byte1 << byte2 << byte3 << byte4; - std::ifstream in("deleteme",std::ios::binary | std::ios::in ); - if( !in ){ - throw std::runtime_error("Could not read from temp file in odf test."); - } readVal = odf.readFloat(in,is_unix); - in.close(); dummy = (float *) &unix; gold = *dummy; @@ -92,24 +66,16 @@ TEST(OdfIO,readInteger) { sammy::OdfIO odf; int gold = 16909060; - // | | | | - int writeval = 0b00000001000000100000001100000100; + char byte1 = 0b00000001; + char byte2 = 0b00000010; + char byte3 = 0b00000011; + char byte4 = 0b00000100; int readVal; - std::ofstream out("deleteme",std::ios::binary | std::ios::out ); - if( !out ){ - throw std::runtime_error("Could not write to temp file in odf test."); - } - // --- write int to file ---- - out.write( (char*) &writeval, sizeof(int) ); - out.close(); + std::stringstream in; + in << byte4 << byte3 << byte2 << byte1; - std::ifstream in("deleteme",std::ios::binary | std::ios::in ); - if( !in ){ - throw std::runtime_error("Could not read from temp file in odf test."); - } readVal = odf.readInteger(in); - in.close(); ASSERT_EQ( readVal, gold ); }