From 4a915653f5949b2aa173d2bc3466cf84fa92db48 Mon Sep 17 00:00:00 2001 From: Jared Mulconry Date: Sun, 8 Oct 2017 23:42:28 +1100 Subject: [PATCH] Fixed IOStream reporting a file size of 0 for files that have been written, but not yet been flushed to disk. --- test/unit/utDefaultIOStream.cpp | 5 +++++ test/unit/utIOStreamBuffer.cpp | 13 +++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/test/unit/utDefaultIOStream.cpp b/test/unit/utDefaultIOStream.cpp index c0d82b6dc..128e4e6ef 100644 --- a/test/unit/utDefaultIOStream.cpp +++ b/test/unit/utDefaultIOStream.cpp @@ -69,6 +69,11 @@ TEST_F( utDefaultIOStream, FileSizeTest ) { auto vflush = std::fflush( fs ); ASSERT_EQ(vflush, 0); + std::fclose(fs); + fs = std::fopen(fpath, "r"); + + ASSERT_NE(nullptr, fs); + TestDefaultIOStream myStream( fs, fpath); size_t size = myStream.FileSize(); EXPECT_EQ( size, dataSize); diff --git a/test/unit/utIOStreamBuffer.cpp b/test/unit/utIOStreamBuffer.cpp index a1b67da44..f53a9c9d5 100644 --- a/test/unit/utIOStreamBuffer.cpp +++ b/test/unit/utIOStreamBuffer.cpp @@ -90,7 +90,11 @@ TEST_F( IOStreamBufferTest, open_close_Test ) { auto written = std::fwrite( data, sizeof(*data), dataCount, fs ); EXPECT_NE( 0U, written ); - std::fflush( fs ); + auto flushResult = std::fflush( fs ); + ASSERT_EQ(0, flushResult); + std::fclose( fs ); + fs = std::fopen(fname, "r"); + ASSERT_NE(nullptr, fs); { TestDefaultIOStream myStream( fs, fname ); @@ -112,7 +116,12 @@ TEST_F( IOStreamBufferTest, readlineTest ) { auto written = std::fwrite( data, sizeof(*data), dataCount, fs ); EXPECT_NE( 0U, written ); - std::fflush( fs ); + + auto flushResult = std::fflush(fs); + ASSERT_EQ(0, flushResult); + std::fclose(fs); + fs = std::fopen(fname, "r"); + ASSERT_NE(nullptr, fs); const auto tCacheSize = 26u;