From 47a0f836dd0e2ec49cd9f40c78a05f5c281dbdd6 Mon Sep 17 00:00:00 2001 From: Michael Meeks Date: Mon, 6 May 2019 20:02:52 +0100 Subject: tests: re-factor PNG save to allow easy re-use elsewhere. Change-Id: Ic24f67d9a078ae49fa4ac187cc924fe36f482879 --- test/helpers.hpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/helpers.hpp b/test/helpers.hpp index 0bbd3c686..c0f9d112c 100644 --- a/test/helpers.hpp +++ b/test/helpers.hpp @@ -586,6 +586,20 @@ inline void sendText(std::shared_ptr& socket, const std::string& } } +inline void saveTileAs(const std::vector &tileResponse, + const std::string &filename, + const std::string &testname) +{ + const std::string firstLine = LOOLProtocol::getFirstLine(tileResponse); + std::vector res(tileResponse.begin() + firstLine.size() + 1, tileResponse.end()); + std::stringstream streamRes; + std::copy(res.begin(), res.end(), std::ostream_iterator(streamRes)); + std::fstream outStream(filename, std::ios::out); + outStream.write(res.data(), res.size()); + outStream.close(); + TST_LOG("Saved [" << firstLine << "] to [" << filename << "]"); +} + inline std::vector getTileAndSave(std::shared_ptr& socket, const std::string& req, const std::string& filename, @@ -603,12 +617,7 @@ inline std::vector getTileAndSave(std::shared_ptr& socket, std::copy(res.begin(), res.end(), std::ostream_iterator(streamRes)); if (!filename.empty()) - { - std::fstream outStream(filename, std::ios::out); - outStream.write(res.data(), res.size()); - outStream.close(); - TST_LOG("Saved [" << firstLine << "] to [" << filename << "]"); - } + saveTileAs(tile, filename, testname); return res; } -- cgit v1.2.3