Kaydet (Commit) 75be2ba9 authored tarafından Ashod Nakashian's avatar Ashod Nakashian Kaydeden (comit) Ashod Nakashian

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/67893
Tested-by: Jenkins
Reviewed-by: 's avatarAshod Nakashian <ashnakash@gmail.com>
üst 8410ce03
...@@ -111,8 +111,14 @@ namespace desktop { ...@@ -111,8 +111,14 @@ namespace desktop {
/// Return the parsed JSON instance. /// Return the parsed JSON instance.
const boost::property_tree::ptree& getJson() const; const boost::property_tree::ptree& getJson() const;
/// Validate that the payload and parsed object match.
bool validate() const;
int Type; int Type;
std::string PayloadString; std::string PayloadString;
private:
/// The parsed payload cache. Update validate() when changing this.
boost::variant<boost::blank, RectangleAndPart, boost::property_tree::ptree> PayloadObject; boost::variant<boost::blank, RectangleAndPart, boost::property_tree::ptree> PayloadObject;
}; };
......
...@@ -464,6 +464,7 @@ RectangleAndPart& CallbackFlushHandler::CallbackData::setRectangleAndPart(const ...@@ -464,6 +464,7 @@ RectangleAndPart& CallbackFlushHandler::CallbackData::setRectangleAndPart(const
const RectangleAndPart& CallbackFlushHandler::CallbackData::getRectangleAndPart() const const RectangleAndPart& CallbackFlushHandler::CallbackData::getRectangleAndPart() const
{ {
assert(PayloadObject.which() == 1);
return boost::get<RectangleAndPart>(PayloadObject); return boost::get<RectangleAndPart>(PayloadObject);
} }
...@@ -491,9 +492,38 @@ void CallbackFlushHandler::CallbackData::setJson(const boost::property_tree::ptr ...@@ -491,9 +492,38 @@ void CallbackFlushHandler::CallbackData::setJson(const boost::property_tree::ptr
const boost::property_tree::ptree& CallbackFlushHandler::CallbackData::getJson() const const boost::property_tree::ptree& CallbackFlushHandler::CallbackData::getJson() const
{ {
assert(PayloadObject.which() == 2);
return boost::get<boost::property_tree::ptree>(PayloadObject); 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 { namespace {
...@@ -886,6 +916,20 @@ void CallbackFlushHandler::queue(const int type, const char* data) ...@@ -886,6 +916,20 @@ void CallbackFlushHandler::queue(const int type, const char* data)
std::string& payload = aCallbackData.PayloadString; std::string& payload = aCallbackData.PayloadString;
SAL_INFO("lok", "Queue: " << type << " : " << payload); 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) if (m_bPartTilePainting)
{ {
...@@ -1294,6 +1338,7 @@ void CallbackFlushHandler::queue(const int type, const char* data) ...@@ -1294,6 +1338,7 @@ void CallbackFlushHandler::queue(const int type, const char* data)
aTree.put("rectangle", aNewRect.toString().getStr()); aTree.put("rectangle", aNewRect.toString().getStr());
aCallbackData.setJson(aTree); aCallbackData.setJson(aTree);
assert(aCallbackData.validate() && "Validation after setJson failed!");
} }
} }
} }
...@@ -1301,6 +1346,8 @@ void CallbackFlushHandler::queue(const int type, const char* data) ...@@ -1301,6 +1346,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); m_queue.emplace_back(aCallbackData);
SAL_INFO("lok", "Queued #" << (m_queue.size() - 1) << SAL_INFO("lok", "Queued #" << (m_queue.size() - 1) <<
" [" << type << "]: [" << payload << "] to have " << m_queue.size() << " entries."); " [" << type << "]: [" << payload << "] to have " << m_queue.size() << " entries.");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment