diff options
author | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2016-08-28 12:26:01 -0400 |
---|---|---|
committer | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2016-08-28 12:45:12 -0400 |
commit | abdefeec68a0790f5b8ac567fb2ec2edca29697e (patch) | |
tree | d885d0737f042b08185bbea846061fbd8abcee33 | |
parent | f18aebb04e7a0a90e518759c9e48e1251160e376 (diff) |
loolwsd: getrepairactions unittests addedprivate/Ashod/repairactions
Change-Id: I8df51d30e127cdfe0311a4e730de5d40bdd657ce
-rw-r--r-- | loolwsd/test/httpwstest.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/loolwsd/test/httpwstest.cpp b/loolwsd/test/httpwstest.cpp index 423e69825..56756af01 100644 --- a/loolwsd/test/httpwstest.cpp +++ b/loolwsd/test/httpwstest.cpp @@ -88,6 +88,8 @@ class HTTPWSTest : public CPPUNIT_NS::TestFixture CPPUNIT_TEST(testFontList); CPPUNIT_TEST(testStateUnoCommand); CPPUNIT_TEST(testColumnRowResize); + CPPUNIT_TEST(testEmptyRepairActions); + CPPUNIT_TEST(testRepairActions); CPPUNIT_TEST_SUITE_END(); @@ -124,6 +126,8 @@ class HTTPWSTest : public CPPUNIT_NS::TestFixture void testFontList(); void testStateUnoCommand(); void testColumnRowResize(); + void testEmptyRepairActions(); + void testRepairActions(); void loadDoc(const std::string& documentURL); @@ -2030,6 +2034,76 @@ void HTTPWSTest::testColumnRowResize() } } +void HTTPWSTest::testEmptyRepairActions() +{ + try + { + const auto testname = "repairactions "; + auto socket = loadDocAndGetSocket("hello.odt", _uri, testname); + + // Check if the document contains the pasted text. + sendTextFrame(socket, "getrepairactions"); + const std::string prefix = "repairactions:"; + const auto response = getResponseMessage(socket, prefix, testname); + const std::string repairActions(response.data(), response.size()); + CPPUNIT_ASSERT_EQUAL(std::string("repairactions: [{ \"undo\": {\n \"actions\": \"\"\n}\n}, { \"redo\": {\n \"actions\": \"\"\n}\n}]"), repairActions); + + const auto jsonString = repairActions.substr(prefix.size()); + + Poco::JSON::Parser parser; + const auto result = parser.parse(jsonString); + const auto& json = result.extract<Poco::JSON::Array::Ptr>(); + auto redo = json->getObject(0); + auto redoActions = redo->getArray("actions"); + CPPUNIT_ASSERT(!redoActions); + } + catch (const Poco::Exception& exc) + { + CPPUNIT_FAIL(exc.displayText()); + } +} + +void HTTPWSTest::testRepairActions() +{ + try + { + const auto testname = "repairactions "; + auto socket = loadDocAndGetSocket("hello.odt", _uri, testname); + + sendTextFrame(socket, "uno .uno:SelectAll"); + sendTextFrame(socket, "uno .uno:Delete"); + + // Check if the document contains the pasted text. + sendTextFrame(socket, "getrepairactions"); + const std::string prefix = "repairactions:"; + const auto response = getResponseMessage(socket, prefix, testname); + const std::string repairActions(response.data(), response.size()); + + const auto jsonString = repairActions.substr(prefix.size()); + + Poco::JSON::Parser parser; + const auto result = parser.parse(jsonString); + const auto& json = result.extract<Poco::JSON::Array::Ptr>(); + + auto undo = json->getObject(0)->get("undo"); + auto subUndo = undo.extract<Poco::JSON::Object::Ptr>(); + auto undoActionsVar = subUndo->get("actions"); + auto undoActions = undoActionsVar.extract<Poco::JSON::Array::Ptr>(); + CPPUNIT_ASSERT_MESSAGE("Expected one undo action in the actions array.", !!undoActions); + CPPUNIT_ASSERT_EQUAL(std::size_t(1), undoActions->size()); + CPPUNIT_ASSERT_EQUAL(std::string("Delete 'Hello world'"), undoActions->getObject(0)->get("comment").toString()); + + auto redo = json->getObject(1)->get("redo"); + auto subRedo = redo.extract<Poco::JSON::Object::Ptr>(); + auto redoActionsVar = subRedo->get("actions"); + CPPUNIT_ASSERT_EQUAL(std::string(), redoActionsVar.toString()); + } + catch (const Poco::Exception& exc) + { + CPPUNIT_FAIL(exc.displayText()); + } +} + CPPUNIT_TEST_SUITE_REGISTRATION(HTTPWSTest); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |