Kaydet (Commit) f6c96946 authored tarafından Pranav Kant's avatar Pranav Kant Kaydeden (comit) Jan Holesovsky

lok: Add a new sheet selection test

This is a test for commit ab199e47.

Change-Id: I38905cfab8fe1c5721e5fa628ea564f08e0c2ad3
üst 324014c9
......@@ -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();
......
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