diff options
Diffstat (limited to 'desktop')
-rw-r--r-- | desktop/qa/data/sheets.ods | bin | 6946 -> 8898 bytes | |||
-rw-r--r-- | desktop/qa/desktop_lib/test_desktop_lib.cxx | 112 |
2 files changed, 112 insertions, 0 deletions
diff --git a/desktop/qa/data/sheets.ods b/desktop/qa/data/sheets.ods Binary files differindex 42226b27e00a..0acf86541ba9 100644 --- a/desktop/qa/data/sheets.ods +++ b/desktop/qa/data/sheets.ods diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index da4e5fb9f547..0c44341b364f 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -85,6 +85,7 @@ public: void testWriterComments(); void testModifiedStatus(); void testSheetOperations(); + void testSheetSelections(); CPPUNIT_TEST_SUITE(DesktopLOKTest); CPPUNIT_TEST(testGetStyles); @@ -105,6 +106,7 @@ public: CPPUNIT_TEST(testWriterComments); CPPUNIT_TEST(testModifiedStatus); CPPUNIT_TEST(testSheetOperations); + CPPUNIT_TEST(testSheetSelections); CPPUNIT_TEST_SUITE_END(); uno::Reference<lang::XComponent> mxComponent; @@ -725,6 +727,116 @@ void DesktopLOKTest::testSheetOperations() comphelper::LibreOfficeKit::setActive(false); } +void DesktopLOKTest::testSheetSelections() +{ + comphelper::LibreOfficeKit::setActive(); + LibLODocument_Impl* pDocument = loadDoc("sheets.ods", LOK_DOCTYPE_SPREADSHEET); + pDocument->pClass->initializeForRendering(pDocument, nullptr); + pDocument->pClass->registerCallback(pDocument, &DesktopLOKTest::callback, this); + + /* + * Check if selection data is correct + */ + // Values in twips + int row5 = 1150; + int col1 = 1100; + int col2 = 2200; + int col3 = 3300; + int col4 = 4400; + int col5 = 5500; + + // Select row 5 from column 1 through column 5 + pDocument->pClass->postMouseEvent(pDocument, + LOK_MOUSEEVENT_MOUSEBUTTONDOWN, + col1, row5, + 1, 1, 0); + pDocument->pClass->postMouseEvent(pDocument, + LOK_MOUSEEVENT_MOUSEMOVE, + col2, row5, + 1, 1, 0); + pDocument->pClass->postMouseEvent(pDocument, + LOK_MOUSEEVENT_MOUSEMOVE, + col3, row5, + 1, 1, 0); + pDocument->pClass->postMouseEvent(pDocument, + LOK_MOUSEEVENT_MOUSEMOVE, + col4, row5, + 1, 1, 0); + pDocument->pClass->postMouseEvent(pDocument, + LOK_MOUSEEVENT_MOUSEMOVE, + col5, row5, + 1, 1, 0); + pDocument->pClass->postMouseEvent(pDocument, + LOK_MOUSEEVENT_MOUSEBUTTONUP, + col5, row5, + 1, 1, 0); + + // Copy the contents and check if matches expected data + { + char* pUsedMimeType = nullptr; + char* pCopiedContent = pDocument->pClass->getTextSelection(pDocument, nullptr, &pUsedMimeType); + std::vector<int> pExpected = {5, 6, 7, 8, 9}; + std::istringstream iss(pCopiedContent); + for (uint i = 0; i < pExpected.size(); i++) + { + std::string token; + iss >> token; + CPPUNIT_ASSERT_EQUAL(pExpected[i], std::stoi(token)); + } + + free(pUsedMimeType); + free(pCopiedContent); + } + + /* + * Check if clicking inside the selection deselects the whole selection + */ + int row10 = 2400; + // Select starting from row5, col1 to row10, col5 + pDocument->pClass->postMouseEvent(pDocument, + LOK_MOUSEEVENT_MOUSEBUTTONDOWN, + col1, row5, + 1, 1, 0); + pDocument->pClass->postMouseEvent(pDocument, + LOK_MOUSEEVENT_MOUSEMOVE, + col5, row5, + 1, 1, 0); + pDocument->pClass->postMouseEvent(pDocument, + LOK_MOUSEEVENT_MOUSEBUTTONUP, + col5, row10, + 1, 1, 0); + + // Click at row5, col4 + pDocument->pClass->postMouseEvent(pDocument, + LOK_MOUSEEVENT_MOUSEBUTTONDOWN, + col4, row5, + 1, 1, 0); + pDocument->pClass->postMouseEvent(pDocument, + LOK_MOUSEEVENT_MOUSEBUTTONUP, + col4, row5, + 1, 1, 0); + + // Selected text should get deselected and copying should give us + // content of only one cell, now + { + char* pUsedMimeType = nullptr; + char* pCopiedContent = pDocument->pClass->getTextSelection(pDocument, nullptr, &pUsedMimeType); + std::vector<int> pExpected = { 8 }; + std::istringstream iss(pCopiedContent); + for (uint i = 0; i < pExpected.size(); i++) + { + std::string token; + iss >> token; + CPPUNIT_ASSERT_EQUAL(pExpected[i], std::stoi(token)); + } + + free(pUsedMimeType); + free(pCopiedContent); + } + + comphelper::LibreOfficeKit::setActive(false); +} + CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest); CPPUNIT_PLUGIN_IMPLEMENT(); |