Files
libreoffice/sw/qa/extras/uiwriter/uiwriter3.cxx

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

597 lines
26 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <swmodeltestbase.hxx>
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
#include <vcl/scheduler.hxx>
#include <com/sun/star/text/TextContentAnchorType.hpp>
#include <comphelper/propertysequence.hxx>
namespace
{
char const DATA_DIRECTORY[] = "/sw/qa/extras/uiwriter/data3/";
} // namespace
/// Third set of tests asserting the behavior of Writer user interface shells.
class SwUiWriterTest3 : public SwModelTestBase
{
};
CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf129382)
{
load(DATA_DIRECTORY, "tdf129382.docx");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<container::XIndexAccess> xDraws = xDrawPageSupplier->getDrawPage();
CPPUNIT_ASSERT_EQUAL(sal_Int32(8), xDraws->getCount());
CPPUNIT_ASSERT_EQUAL(2, getPages());
dispatchCommand(mxComponent, ".uno:SelectAll", {});
dispatchCommand(mxComponent, ".uno:Cut", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xDraws->getCount());
CPPUNIT_ASSERT_EQUAL(1, getPages());
dispatchCommand(mxComponent, ".uno:Paste", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(8), xDraws->getCount());
CPPUNIT_ASSERT_EQUAL(2, getPages());
dispatchCommand(mxComponent, ".uno:Undo", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xDraws->getCount());
CPPUNIT_ASSERT_EQUAL(1, getPages());
// without the fix, it crashes
dispatchCommand(mxComponent, ".uno:Undo", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(8), xDraws->getCount());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf126626)
{
load(DATA_DIRECTORY, "tdf126626.docx");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<container::XIndexAccess> xDraws = xDrawPageSupplier->getDrawPage();
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xDraws->getCount());
dispatchCommand(mxComponent, ".uno:SelectAll", {});
dispatchCommand(mxComponent, ".uno:Copy", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xDraws->getCount());
dispatchCommand(mxComponent, ".uno:Paste", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xDraws->getCount());
dispatchCommand(mxComponent, ".uno:Paste", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xDraws->getCount());
dispatchCommand(mxComponent, ".uno:Undo", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xDraws->getCount());
// without the fix, it crashes
dispatchCommand(mxComponent, ".uno:Paste", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xDraws->getCount());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf128739)
{
load(DATA_DIRECTORY, "tdf128739.docx");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
CPPUNIT_ASSERT_EQUAL(OUString("Fehler: Verweis nicht gefunden"), getParagraph(1)->getString());
dispatchCommand(mxComponent, ".uno:SelectAll", {});
dispatchCommand(mxComponent, ".uno:Cut", {});
CPPUNIT_ASSERT_EQUAL(OUString(""), getParagraph(1)->getString());
dispatchCommand(mxComponent, ".uno:Paste", {});
CPPUNIT_ASSERT_EQUAL(OUString("Fehler: Verweis nicht gefunden"), getParagraph(1)->getString());
// without the fix, it crashes
dispatchCommand(mxComponent, ".uno:Undo", {});
CPPUNIT_ASSERT_EQUAL(OUString(""), getParagraph(1)->getString());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf124722)
{
load(DATA_DIRECTORY, "tdf124722.rtf");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
CPPUNIT_ASSERT_EQUAL(22, getPages());
dispatchCommand(mxComponent, ".uno:SelectAll", {});
dispatchCommand(mxComponent, ".uno:Copy", {});
CPPUNIT_ASSERT_EQUAL(22, getPages());
dispatchCommand(mxComponent, ".uno:Paste", {});
CPPUNIT_ASSERT_EQUAL(43, getPages());
dispatchCommand(mxComponent, ".uno:Undo", {});
CPPUNIT_ASSERT_EQUAL(22, getPages());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf125261)
{
load(DATA_DIRECTORY, "tdf125261.odt");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
CPPUNIT_ASSERT_EQUAL(OUString("https://www.example.com/"),
getProperty<OUString>(getRun(getParagraph(1), 1), "HyperLinkURL"));
//apply autocorrect StartAutoCorrect
dispatchCommand(mxComponent, ".uno:AutoFormatApply", {});
CPPUNIT_ASSERT_EQUAL(OUString("https://www.example.com/"),
getProperty<OUString>(getRun(getParagraph(1), 1), "HyperLinkURL"));
// without the fix, it hangs
dispatchCommand(mxComponent, ".uno:Undo", {});
CPPUNIT_ASSERT_EQUAL(OUString("https://www.example.com/"),
getProperty<OUString>(getRun(getParagraph(1), 1), "HyperLinkURL"));
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf76636)
{
load(DATA_DIRECTORY, "tdf76636.doc");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<container::XIndexAccess> xIndexAccess(xTextTablesSupplier->getTextTables(),
uno::UNO_QUERY);
uno::Reference<text::XTextTable> xTextTable(xIndexAccess->getByIndex(0), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable->getRows()->getCount());
CPPUNIT_ASSERT_EQUAL(sal_Int32(6), xTextTable->getColumns()->getCount());
//go to middle row
pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DOWN);
pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DOWN);
Scheduler::ProcessEventsToIdle();
pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_TAB);
pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_TAB);
pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_TAB);
Scheduler::ProcessEventsToIdle();
pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_LEFT | KEY_SHIFT);
pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_LEFT | KEY_SHIFT);
Scheduler::ProcessEventsToIdle();
dispatchCommand(mxComponent, ".uno:MergeCells", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable->getRows()->getCount());
CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xTextTable->getColumns()->getCount());
dispatchCommand(mxComponent, ".uno:Undo", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable->getRows()->getCount());
CPPUNIT_ASSERT_EQUAL(sal_Int32(6), xTextTable->getColumns()->getCount());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf76636_2)
{
load(DATA_DIRECTORY, "tdf76636.doc");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<container::XIndexAccess> xIndexAccess(xTextTablesSupplier->getTextTables(),
uno::UNO_QUERY);
uno::Reference<text::XTextTable> xTextTable(xIndexAccess->getByIndex(0), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable->getRows()->getCount());
CPPUNIT_ASSERT_EQUAL(sal_Int32(6), xTextTable->getColumns()->getCount());
pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DOWN);
pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DOWN);
Scheduler::ProcessEventsToIdle();
pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_TAB);
pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_TAB);
Scheduler::ProcessEventsToIdle();
pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_RIGHT | KEY_SHIFT);
Scheduler::ProcessEventsToIdle();
dispatchCommand(mxComponent, ".uno:MergeCells", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable->getRows()->getCount());
CPPUNIT_ASSERT_EQUAL(sal_Int32(5), xTextTable->getColumns()->getCount());
dispatchCommand(mxComponent, ".uno:Undo", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable->getRows()->getCount());
CPPUNIT_ASSERT_EQUAL(sal_Int32(6), xTextTable->getColumns()->getCount());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf126340)
{
load(DATA_DIRECTORY, "tdf126340.odt");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
dispatchCommand(mxComponent, ".uno:GoDown", {});
// without the fix, it crashes
dispatchCommand(mxComponent, ".uno:Delete", {});
CPPUNIT_ASSERT_EQUAL(OUString("foo"), getParagraph(1)->getString());
dispatchCommand(mxComponent, ".uno:Undo", {});
CPPUNIT_ASSERT_EQUAL(OUString("foo"), getParagraph(1)->getString());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf107975)
{
// This test also covers tdf#117185 tdf#110442
load(DATA_DIRECTORY, "tdf107975.odt");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
uno::Reference<text::XTextGraphicObjectsSupplier> xTextGraphicObjectsSupplier(mxComponent,
uno::UNO_QUERY);
uno::Reference<container::XIndexAccess> xIndexAccess(
xTextGraphicObjectsSupplier->getGraphicObjects(), uno::UNO_QUERY);
uno::Reference<drawing::XShape> xShape(xIndexAccess->getByIndex(0), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(text::TextContentAnchorType_AT_CHARACTER,
getProperty<text::TextContentAnchorType>(xShape, "AnchorType"));
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
dispatchCommand(mxComponent, ".uno:SelectAll", {});
dispatchCommand(mxComponent, ".uno:Copy", {});
//Position the mouse cursor (caret) after "ABC" below the blue image
dispatchCommand(mxComponent, ".uno:GoRight", {});
dispatchCommand(mxComponent, ".uno:Paste", {});
// without the fix, it crashes
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount());
CPPUNIT_ASSERT_EQUAL(OUString("ABC"), getParagraph(1)->getString());
dispatchCommand(mxComponent, ".uno:Undo", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
dispatchCommand(mxComponent, ".uno:Redo", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount());
dispatchCommand(mxComponent, ".uno:Undo", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
dispatchCommand(mxComponent, ".uno:Redo", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount());
dispatchCommand(mxComponent, ".uno:Undo", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
//try again with anchor at start of doc which is another special case
xShape.set(xIndexAccess->getByIndex(0), uno::UNO_QUERY);
uno::Reference<text::XTextContent> xShapeContent(xShape, uno::UNO_QUERY);
uno::Reference<text::XTextRange> const xStart = pTextDoc->getText()->getStart();
xShapeContent->attach(xStart);
CPPUNIT_ASSERT_EQUAL(text::TextContentAnchorType_AT_CHARACTER,
getProperty<text::TextContentAnchorType>(xShape, "AnchorType"));
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
dispatchCommand(mxComponent, ".uno:SelectAll", {});
dispatchCommand(mxComponent, ".uno:Copy", {});
//Position the mouse cursor (caret) after "ABC" below the blue image
dispatchCommand(mxComponent, ".uno:GoRight", {});
dispatchCommand(mxComponent, ".uno:Paste", {});
// without the fix, it crashes
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount());
CPPUNIT_ASSERT_EQUAL(OUString("ABC"), getParagraph(1)->getString());
dispatchCommand(mxComponent, ".uno:Undo", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
dispatchCommand(mxComponent, ".uno:Redo", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount());
dispatchCommand(mxComponent, ".uno:Undo", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
dispatchCommand(mxComponent, ".uno:Redo", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount());
dispatchCommand(mxComponent, ".uno:Undo", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf130746)
{
load(DATA_DIRECTORY, "tdf130746.odt");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<container::XIndexAccess> xIndexAccess(xTextTablesSupplier->getTextTables(),
uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
dispatchCommand(mxComponent, ".uno:JumpToNextTable", {});
uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
uno::Reference<text::XTextViewCursorSupplier> xTextViewCursorSupplier(
xModel->getCurrentController(), uno::UNO_QUERY);
uno::Reference<text::XPageCursor> xCursor(xTextViewCursorSupplier->getViewCursor(),
uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(sal_Int16(1), xCursor->getPage());
pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_RETURN);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL(sal_Int16(2), xCursor->getPage());
pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_UP | KEY_MOD2);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL(sal_Int16(2), xCursor->getPage());
dispatchCommand(mxComponent, ".uno:Undo", {});
CPPUNIT_ASSERT_EQUAL(sal_Int16(1), xCursor->getPage());
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf130685)
{
load(DATA_DIRECTORY, "tdf130685.odt");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
CPPUNIT_ASSERT_EQUAL(2, getPages());
dispatchCommand(mxComponent, ".uno:SelectAll", {});
dispatchCommand(mxComponent, ".uno:Cut", {});
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL(1, getPages());
dispatchCommand(mxComponent, ".uno:Paste", {});
dispatchCommand(mxComponent, ".uno:Paste", {});
// Without fix in place, this test would have failed with:
//- Expected: 2
//- Actual : 4
CPPUNIT_ASSERT_EQUAL(2, getPages());
dispatchCommand(mxComponent, ".uno:Undo", {});
dispatchCommand(mxComponent, ".uno:Undo", {});
CPPUNIT_ASSERT_EQUAL(1, getPages());
dispatchCommand(mxComponent, ".uno:Undo", {});
CPPUNIT_ASSERT_EQUAL(2, getPages());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf130680)
{
load(DATA_DIRECTORY, "tdf130680.odt");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<container::XIndexAccess> xIndexAccess(xTextTablesSupplier->getTextTables(),
uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(sal_Int32(23), xIndexAccess->getCount());
dispatchCommand(mxComponent, ".uno:SelectAll", {});
// without the fix, it crashes
dispatchCommand(mxComponent, ".uno:Cut", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount());
dispatchCommand(mxComponent, ".uno:Paste", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
dispatchCommand(mxComponent, ".uno:Undo", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount());
dispatchCommand(mxComponent, ".uno:Undo", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(23), xIndexAccess->getCount());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf131684)
{
load(DATA_DIRECTORY, "tdf131684.docx");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<container::XIndexAccess> xIndexAccess(xTextTablesSupplier->getTextTables(),
uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
//Use selectAll 3 times in a row
dispatchCommand(mxComponent, ".uno:SelectAll", {});
dispatchCommand(mxComponent, ".uno:SelectAll", {});
dispatchCommand(mxComponent, ".uno:SelectAll", {});
dispatchCommand(mxComponent, ".uno:Cut", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount());
dispatchCommand(mxComponent, ".uno:Undo", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
dispatchCommand(mxComponent, ".uno:Paste", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
// without the fix, it crashes
dispatchCommand(mxComponent, ".uno:Undo", {});
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf80663)
{
mxComponent = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
uno::Sequence<beans::PropertyValue> aArgs(comphelper::InitPropertySequence(
{ { "Rows", uno::makeAny(sal_Int32(2)) }, { "Columns", uno::makeAny(sal_Int32(2)) } }));
dispatchCommand(mxComponent, ".uno:InsertTable", aArgs);
Scheduler::ProcessEventsToIdle();
uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<container::XIndexAccess> xIndexAccess(xTextTablesSupplier->getTextTables(),
uno::UNO_QUERY);
uno::Reference<text::XTextTable> xTextTable(xIndexAccess->getByIndex(0), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTextTable->getRows()->getCount());
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTextTable->getColumns()->getCount());
dispatchCommand(mxComponent, ".uno:DeleteRows", {});
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTextTable->getRows()->getCount());
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTextTable->getColumns()->getCount());
dispatchCommand(mxComponent, ".uno:Undo", {});
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTextTable->getRows()->getCount());
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTextTable->getColumns()->getCount());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf96067)
{
mxComponent = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
uno::Sequence<beans::PropertyValue> aArgs(comphelper::InitPropertySequence(
{ { "Rows", uno::makeAny(sal_Int32(3)) }, { "Columns", uno::makeAny(sal_Int32(3)) } }));
dispatchCommand(mxComponent, ".uno:InsertTable", aArgs);
Scheduler::ProcessEventsToIdle();
uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<container::XIndexAccess> xIndexAccess(xTextTablesSupplier->getTextTables(),
uno::UNO_QUERY);
uno::Reference<text::XTextTable> xTextTable(xIndexAccess->getByIndex(0), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable->getRows()->getCount());
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable->getColumns()->getCount());
dispatchCommand(mxComponent, ".uno:SelectTable", {});
dispatchCommand(mxComponent, ".uno:InsertRowsBefore", {});
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
CPPUNIT_ASSERT_EQUAL(sal_Int32(6), xTextTable->getRows()->getCount());
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable->getColumns()->getCount());
dispatchCommand(mxComponent, ".uno:Undo", {});
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable->getRows()->getCount());
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable->getColumns()->getCount());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf87199)
{
mxComponent = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
uno::Sequence<beans::PropertyValue> aArgs(comphelper::InitPropertySequence(
{ { "Rows", uno::makeAny(sal_Int32(2)) }, { "Columns", uno::makeAny(sal_Int32(1)) } }));
dispatchCommand(mxComponent, ".uno:InsertTable", aArgs);
uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<container::XIndexAccess> xIndexAccess(xTextTablesSupplier->getTextTables(),
uno::UNO_QUERY);
uno::Reference<text::XTextTable> xTextTable(xIndexAccess->getByIndex(0), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTextTable->getRows()->getCount());
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTextTable->getColumns()->getCount());
uno::Reference<text::XTextRange> xCellA1(xTextTable->getCellByName("A1"), uno::UNO_QUERY);
xCellA1->setString("test1");
uno::Reference<text::XTextRange> xCellA2(xTextTable->getCellByName("A2"), uno::UNO_QUERY);
xCellA2->setString("test2");
dispatchCommand(mxComponent, ".uno:EntireColumn", {});
dispatchCommand(mxComponent, ".uno:MergeCells", {});
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTextTable->getRows()->getCount());
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTextTable->getColumns()->getCount());
CPPUNIT_ASSERT(xCellA1->getString().endsWith("test2"));
dispatchCommand(mxComponent, ".uno:Undo", {});
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTextTable->getRows()->getCount());
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTextTable->getColumns()->getCount());
xCellA1.set(xTextTable->getCellByName("A1"), uno::UNO_QUERY);
CPPUNIT_ASSERT(xCellA1->getString().endsWith("test1"));
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf117601)
{
mxComponent = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
uno::Sequence<beans::PropertyValue> aArgs(comphelper::InitPropertySequence(
{ { "Rows", uno::makeAny(sal_Int32(5)) }, { "Columns", uno::makeAny(sal_Int32(3)) } }));
dispatchCommand(mxComponent, ".uno:InsertTable", aArgs);
Scheduler::ProcessEventsToIdle();
uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<container::XIndexAccess> xIndexAccess(xTextTablesSupplier->getTextTables(),
uno::UNO_QUERY);
uno::Reference<text::XTextTable> xTextTable(xIndexAccess->getByIndex(0), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
CPPUNIT_ASSERT_EQUAL(sal_Int32(5), xTextTable->getRows()->getCount());
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable->getColumns()->getCount());
uno::Reference<text::XTextRange> xCellB1(xTextTable->getCellByName("B1"), uno::UNO_QUERY);
xCellB1->setString("test1");
uno::Reference<text::XTextRange> xCellB2(xTextTable->getCellByName("B2"), uno::UNO_QUERY);
xCellB2->setString("test2");
//go to middle row
pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_UP);
pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_RIGHT);
Scheduler::ProcessEventsToIdle();
dispatchCommand(mxComponent, ".uno:EntireColumn", {});
dispatchCommand(mxComponent, ".uno:MergeCells", {});
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
CPPUNIT_ASSERT_EQUAL(sal_Int32(5), xTextTable->getRows()->getCount());
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable->getColumns()->getCount());
CPPUNIT_ASSERT(xCellB1->getString().endsWith("test2"));
dispatchCommand(mxComponent, ".uno:Undo", {});
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
CPPUNIT_ASSERT_EQUAL(sal_Int32(5), xTextTable->getRows()->getCount());
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable->getColumns()->getCount());
CPPUNIT_ASSERT(xCellB1->getString().endsWith("test1"));
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */