From fe268b0e711f7f03671923dfe030f97344e62a30 Mon Sep 17 00:00:00 2001 From: Jiri Drbalek Date: Mon, 13 Nov 2017 21:41:48 +0000 Subject: [PATCH] char_array_buffer should implement also seekpos() --- include/mapnik/util/char_array_buffer.hpp | 7 +++++++ test/unit/util/char_array_buffer.cpp | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 test/unit/util/char_array_buffer.cpp diff --git a/include/mapnik/util/char_array_buffer.hpp b/include/mapnik/util/char_array_buffer.hpp index 9c9ecfd56..6166c2476 100644 --- a/include/mapnik/util/char_array_buffer.hpp +++ b/include/mapnik/util/char_array_buffer.hpp @@ -68,6 +68,13 @@ private: return end_ - current_; } + pos_type seekpos(pos_type off, + std::ios_base::openmode /*which*/) + { + current_ = std::min(begin_ + off, end_); + return pos_type(off_type(current_ - begin_)); + } + pos_type seekoff(off_type off, std::ios_base::seekdir dir, std::ios_base::openmode which = std::ios_base::in | std::ios_base::out ) { diff --git a/test/unit/util/char_array_buffer.cpp b/test/unit/util/char_array_buffer.cpp new file mode 100644 index 000000000..7500f64d8 --- /dev/null +++ b/test/unit/util/char_array_buffer.cpp @@ -0,0 +1,19 @@ +#include "catch.hpp" + +#include +#include + +TEST_CASE("char_array_buffer") { + +SECTION("std::istream seekg, tellg") { + + const std::size_t buffer_size = 66; + char buffer[buffer_size]; + mapnik::util::char_array_buffer array_buff(buffer, buffer_size); + std::istream stream(&array_buff); + + CHECK(stream.seekg(0).tellg() == 0); + CHECK(stream.seekg(buffer_size).tellg() == buffer_size); + CHECK(stream.seekg(70).tellg() == buffer_size); +} +}