sw/qa/extras/uiwriter/data/select-column.fodt | 42 +++++++++++++++ sw/qa/extras/uiwriter/uiwriter5.cxx | 70 ++++++++++++++++++++++++++ 2 files changed, 112 insertions(+)
New commits: commit 3442a46995f967dbd4c99797f7f13794912f0f58 Author: László Németh <[email protected]> AuthorDate: Thu Oct 13 14:59:09 2022 +0200 Commit: László Németh <[email protected]> CommitDate: Thu Oct 13 21:27:31 2022 +0200 tdf#47979 sw: test row & column selection with mouse Commit 0140fd6501c2322cffddaaa14b49137009ffcae4 "tdf#151478 sw: fix row/column selection at nested table" fixed also selection with mouse, not only selection with Table->Select->Row and Table->Select->Column. Add unit tests for fixed row and column selections using code path of mouse clicks. Change-Id: I96c56a65e908a56fcaf43b8cfc2adbc091c65fc5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141297 Tested-by: László Németh <[email protected]> Reviewed-by: László Németh <[email protected]> diff --git a/sw/qa/extras/uiwriter/data/select-column.fodt b/sw/qa/extras/uiwriter/data/select-column.fodt new file mode 100644 index 000000000000..b6dddb2235d7 --- /dev/null +++ b/sw/qa/extras/uiwriter/data/select-column.fodt @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:ooow="http://openoffice.org/2004/writer" office:version="1.2" office:mimetype="application/vnd.oasis.opendocument.text"> + <office:body> + <office:text> + <text:p/> + <table:table table:name="Table1" table:style-name="Table1"> + <table:table-column table:style-name="Table1.A"/> + <table:table-column table:style-name="Table1.B"/> + <table:table-row> + <table:table-cell office:value-type="string"> + <text:p text:style-name="P3">a1</text:p> + </table:table-cell> + <table:table-cell office:value-type="string"> + <text:p text:style-name="P3">b1</text:p> + </table:table-cell> + </table:table-row> + <table:table-row table:style-name="Table1.1"> + <table:table-cell table:style-name="Table1.A1" office:value-type="string"> + <text:p text:style-name="P3">a2</text:p> + </table:table-cell> + <table:table-cell table:style-name="Table1.B1" office:value-type="string"> + <table:table table:name="Table2" table:style-name="Table2"> + <table:table-column table:style-name="Table2.A"/> + <table:table-column table:style-name="Table2.B"/> + <table:table-row> + <table:table-cell table:style-name="Table2.A1" office:value-type="string"> + <text:p text:style-name="P3">nested-a1</text:p> + </table:table-cell> + <table:table-cell table:style-name="Table2.B1" office:value-type="string"> + <text:p text:style-name="P3">nested-b1</text:p> + </table:table-cell> + </table:table-row> + </table:table> + <text:p text:style-name="Table_20_Contents"/> + </table:table-cell> + </table:table-row> + </table:table> + <text:p/> + </office:text> + </office:body> +</office:document> diff --git a/sw/qa/extras/uiwriter/uiwriter5.cxx b/sw/qa/extras/uiwriter/uiwriter5.cxx index 0d191cb1f069..cc132640c2b1 100644 --- a/sw/qa/extras/uiwriter/uiwriter5.cxx +++ b/sw/qa/extras/uiwriter/uiwriter5.cxx @@ -1880,6 +1880,76 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, testSelectRowWithNestedTable) assertXPathContent(pXmlDoc, "//page[1]//body/tab/row/cell[2]/tab/row/cell[2]/txt", "NESTED-B1"); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, testTdf47979_row) +{ + // load a 2-row table, and select row 2 by clicking before it + SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "select-column.fodt"); + CPPUNIT_ASSERT(pDoc); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + CPPUNIT_ASSERT(pWrtShell); + + SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout(); + SwFrame* pPage = pLayout->Lower(); + SwFrame* pBody = pPage->GetLower(); + SwFrame* pTable = pBody->GetLower()->GetNext(); + SwFrame* pRow2 = pTable->GetLower()->GetNext(); + const SwRect& rRow2Rect = pRow2->getFrameArea(); + Point ptRow(rRow2Rect.Left(), rRow2Rect.Top() + rRow2Rect.Height() / 2); + + pWrtShell->SelectTableRowCol(ptRow); + + // convert selected text content to uppercase + dispatchCommand(mxComponent, ".uno:ChangeCaseToUpper", {}); + Scheduler::ProcessEventsToIdle(); + + xmlDocUniquePtr pXmlDoc = parseLayoutDump(); + assertXPathContent(pXmlDoc, "//page[1]//body/tab/row[1]/cell[1]/txt[1]", "a1"); + assertXPathContent(pXmlDoc, "//page[1]//body/tab/row[1]/cell[2]/txt[1]", "b1"); + assertXPathContent(pXmlDoc, "//page[1]//body/tab/row[2]/cell[2]/tab/row/cell[1]/txt", + "NESTED-A1"); + // This was "a2" (bad selection of the table row) + assertXPathContent(pXmlDoc, "//page[1]//body/tab/row[2]/cell[1]/txt[1]", "A2"); + // This was "nested-b1" (bad selection of the table row) + assertXPathContent(pXmlDoc, "//page[1]//body/tab/row[2]/cell[2]/tab/row/cell[2]/txt", + "NESTED-B1"); +} + +CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, testTdf47979_column) +{ + // load a 2-row table, and select column B by clicking before them + SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "select-column.fodt"); + CPPUNIT_ASSERT(pDoc); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + CPPUNIT_ASSERT(pWrtShell); + + // select table column by using the middle point of the top border of column B + SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout(); + SwFrame* pPage = pLayout->Lower(); + SwFrame* pBody = pPage->GetLower(); + SwFrame* pTable = pBody->GetLower()->GetNext(); + SwFrame* pRow1 = pTable->GetLower(); + SwFrame* pCellB1 = pRow1->GetLower()->GetNext(); + const SwRect& rCellB1Rect = pCellB1->getFrameArea(); + Point ptColumn(rCellB1Rect.Left() + rCellB1Rect.Width() / 2, rCellB1Rect.Top() - 5); + + pWrtShell->SelectTableRowCol(ptColumn); + + // convert selected text content to uppercase + dispatchCommand(mxComponent, ".uno:ChangeCaseToUpper", {}); + Scheduler::ProcessEventsToIdle(); + + xmlDocUniquePtr pXmlDoc = parseLayoutDump(); + + assertXPathContent(pXmlDoc, "//page[1]//body/tab/row[1]/cell[1]/txt[1]", "a1"); + assertXPathContent(pXmlDoc, "//page[1]//body/tab/row[2]/cell[1]/txt[1]", "a2"); + assertXPathContent(pXmlDoc, "//page[1]//body/tab/row[2]/cell[2]/tab/row/cell[1]/txt", + "NESTED-A1"); + assertXPathContent(pXmlDoc, "//page[1]//body/tab/row[2]/cell[2]/tab/row/cell[2]/txt", + "NESTED-B1"); + // This was "b1" (bad selection of the table column) + assertXPathContent(pXmlDoc, "//page[1]//body/tab/row[1]/cell[2]/txt[1]", "B1"); +} + CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, testRedlineTableRowDeletionWithExport) { // load a 1-row table, and delete the row with enabled change tracking:
