[Libreoffice-commits] core.git: desktop/qa

Pranav Kant pranavk at collabora.com
Fri Feb 19 07:23:59 UTC 2016


 desktop/qa/data/sheets.ods                  |binary
 desktop/qa/desktop_lib/test_desktop_lib.cxx |  112 ++++++++++++++++++++++++++++
 2 files changed, 112 insertions(+)

New commits:
commit f6c96946911db267bc79b4bdb4ced7d7414d3cac
Author: Pranav Kant <pranavk at collabora.com>
Date:   Tue Feb 16 21:23:00 2016 +0530

    lok: Add a new sheet selection test
    
    This is a test for commit ab199e4748b45384602479c735dbac538e714d34.
    
    Change-Id: I38905cfab8fe1c5721e5fa628ea564f08e0c2ad3

diff --git a/desktop/qa/data/sheets.ods b/desktop/qa/data/sheets.ods
index 42226b2..0acf865 100644
Binary files a/desktop/qa/data/sheets.ods and b/desktop/qa/data/sheets.ods differ
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index da4e5fb..0c44341 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();


More information about the Libreoffice-commits mailing list