diff options
| author | ljfa <ljfa-ag@web.de> | 2015-09-21 10:21:17 +0200 |
|---|---|---|
| committer | ljfa <ljfa-ag@web.de> | 2015-09-21 10:21:17 +0200 |
| commit | f76d4d228b32e72c7de250cb37af264d38ee7e79 (patch) | |
| tree | 5cf26b787a73a45f42198e957da19946b0e0ea85 | |
| parent | 28d735a3261e831f0c65cfe035e0aa53e369b964 (diff) | |
| download | Project-Tick-f76d4d228b32e72c7de250cb37af264d38ee7e79.tar.gz Project-Tick-f76d4d228b32e72c7de250cb37af264d38ee7e79.zip | |
Make close honor the exceptions mask
| -rw-r--r-- | include/io/ozlibstream.h | 2 | ||||
| -rw-r--r-- | src/io/ozlibstream.cpp | 14 | ||||
| -rw-r--r-- | test/zlibstream_test.h | 30 |
3 files changed, 38 insertions, 8 deletions
diff --git a/include/io/ozlibstream.h b/include/io/ozlibstream.h index 770db0029d..bd9faea381 100644 --- a/include/io/ozlibstream.h +++ b/include/io/ozlibstream.h @@ -87,7 +87,7 @@ public: std::ostream& get_ostr() const { return buf.get_ostr(); } ///Finishes compression and writes all pending data to the output - void close() { buf.close(); } + void close(); private: deflate_streambuf buf; }; diff --git a/src/io/ozlibstream.cpp b/src/io/ozlibstream.cpp index 605d1397d0..36c6b42d61 100644 --- a/src/io/ozlibstream.cpp +++ b/src/io/ozlibstream.cpp @@ -92,4 +92,18 @@ int deflate_streambuf::sync() return 0; } +void ozlibstream::close() +{ + try + { + buf.close(); + } + catch(...) + { + setstate(badbit); //FIXME: This will throw the wrong type of exception + //but there's no good way of setting the badbit + //without causing an exception when exceptions is set + } +} + } diff --git a/test/zlibstream_test.h b/test/zlibstream_test.h index 204764e370..5f2ad64c55 100644 --- a/test/zlibstream_test.h +++ b/test/zlibstream_test.h @@ -224,12 +224,28 @@ public: void test_deflate_closed() { std::stringstream str; - ozlibstream ozls(str); - ozls.exceptions(std::ios::failbit | std::ios::badbit); - TS_ASSERT_THROWS_NOTHING(ozls << bigtest); - TS_ASSERT_THROWS_NOTHING(ozls.close()); - TS_ASSERT_THROWS(ozls << "foo" << std::flush, zlib_error); - TS_ASSERT(ozls.bad()); - TS_ASSERT(!str); + { + ozlibstream ozls(str); + ozls.exceptions(std::ios::failbit | std::ios::badbit); + TS_ASSERT_THROWS_NOTHING(ozls << bigtest); + TS_ASSERT_THROWS_NOTHING(ozls.close()); + TS_ASSERT_THROWS_NOTHING(ozls << "foo"); + TS_ASSERT_THROWS_ANYTHING(ozls.close()); + TS_ASSERT(ozls.bad()); + TS_ASSERT(!str); + } + str.clear(); + str.seekp(0); + { + ozlibstream ozls(str); + //this time without exceptions + TS_ASSERT_THROWS_NOTHING(ozls << bigtest); + TS_ASSERT_THROWS_NOTHING(ozls.close()); + TS_ASSERT_THROWS_NOTHING(ozls << "foo" << std::flush); + TS_ASSERT(ozls.bad()); + TS_ASSERT_THROWS_NOTHING(ozls.close()); + TS_ASSERT(ozls.bad()); + TS_ASSERT(!str); + } } }; |
