diff options
author | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2019-02-13 18:18:35 -0500 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2019-03-05 10:35:22 +0100 |
commit | 926b4fe7d84fa3aaaddb1a6a8bd1cb943b72aea6 (patch) | |
tree | 50ad662a139955e2d0df16dbfa597568df741f14 /desktop/source/lib | |
parent | b27990077a219b3640e51a31c7d5bd750d792895 (diff) |
LOK: Validate cached queued callback payloads
And with DBG_UTIL validate and dump LOK queue state.
Change-Id: I211ddf89dbcecf17c4f1401e5d96919c4bc966ea
Reviewed-on: https://gerrit.libreoffice.org/68270
Reviewed-by: Andras Timar <andras.timar@collabora.com>
Tested-by: Andras Timar <andras.timar@collabora.com>
Diffstat (limited to 'desktop/source/lib')
-rw-r--r-- | desktop/source/lib/init.cxx | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 59d4f36aebc0..45a68a2a6703 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -467,6 +467,7 @@ RectangleAndPart& CallbackFlushHandler::CallbackData::setRectangleAndPart(const const RectangleAndPart& CallbackFlushHandler::CallbackData::getRectangleAndPart() const { + assert(PayloadObject.which() == 1); return boost::get<RectangleAndPart>(PayloadObject); } @@ -494,9 +495,38 @@ void CallbackFlushHandler::CallbackData::setJson(const boost::property_tree::ptr const boost::property_tree::ptree& CallbackFlushHandler::CallbackData::getJson() const { + assert(PayloadObject.which() == 2); return boost::get<boost::property_tree::ptree>(PayloadObject); } +bool CallbackFlushHandler::CallbackData::validate() const +{ + switch (PayloadObject.which()) + { + // Not cached. + case 0: + return true; + + // RectangleAndPart. + case 1: + return getRectangleAndPart().toString().getStr() == PayloadString; + + // Json. + case 2: + { + std::stringstream aJSONStream; + boost::property_tree::write_json(aJSONStream, getJson(), false); + const std::string aExpected = boost::trim_copy(aJSONStream.str()); + return aExpected == PayloadString; + } + + default: + assert(!"Unknown variant type; please add an entry to validate."); + } + + return false; +} + } namespace { @@ -889,6 +919,20 @@ void CallbackFlushHandler::queue(const int type, const char* data) std::string& payload = aCallbackData.PayloadString; SAL_INFO("lok", "Queue: " << type << " : " << payload); +#ifdef DBG_UTIL + { + // Dump the queue state and validate cached data. + int i = 1; + std::ostringstream oss; + oss << '\n'; + for (const CallbackData& c : m_queue) + oss << i++ << ": [" << c.Type << "] [" << c.PayloadString << "].\n"; + const std::string aQueued = oss.str(); + SAL_INFO("lok", "Current Queue: " << (aQueued.empty() ? "Empty" : aQueued)); + for (const CallbackData& c : m_queue) + assert(c.validate()); + } +#endif if (m_bPartTilePainting) { @@ -1301,6 +1345,7 @@ void CallbackFlushHandler::queue(const int type, const char* data) aTree.put("rectangle", aNewRect.toString().getStr()); aCallbackData.setJson(aTree); + assert(aCallbackData.validate() && "Validation after setJson failed!"); } } } @@ -1308,6 +1353,8 @@ void CallbackFlushHandler::queue(const int type, const char* data) } } + // Validate that the cached data and the payload string are identical. + assert(aCallbackData.validate() && "Cached callback payload object and string mismatch!"); m_queue.emplace_back(aCallbackData); SAL_INFO("lok", "Queued #" << (m_queue.size() - 1) << " [" << type << "]: [" << payload << "] to have " << m_queue.size() << " entries."); |