1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
/* -*- 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 <com/sun/star/awt/FontSlant.hpp>
#include <com/sun/star/frame/DispatchHelper.hpp>
#include <swdtflvr.hxx>
#include <wrtsh.hxx>
#include <UndoManager.hxx>
#include <comphelper/propertyvalue.hxx>
namespace
{
char const DATA_DIRECTORY[] = "/sw/qa/extras/uiwriter/data2/";
}
/// Second set of tests asserting the behavior of Writer user interface shells.
class SwUiWriterTest2 : public SwModelTestBase
{
public:
void testTdf101534();
void testTdf105330();
CPPUNIT_TEST_SUITE(SwUiWriterTest2);
CPPUNIT_TEST(testTdf101534);
CPPUNIT_TEST(testTdf105330);
CPPUNIT_TEST_SUITE_END();
};
void SwUiWriterTest2::testTdf101534()
{
// Copy the first paragraph of the document.
load(DATA_DIRECTORY, "tdf101534.fodt");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
pWrtShell->EndPara(/*bSelect=*/true);
rtl::Reference<SwTransferable> pTransfer = new SwTransferable(*pWrtShell);
pTransfer->Copy();
// Go to the second paragraph, assert that we have margins as direct
// formatting.
pWrtShell->Down(/*bSelect=*/false);
SfxItemSet aSet(pWrtShell->GetAttrPool(), svl::Items<RES_LR_SPACE, RES_LR_SPACE>{});
pWrtShell->GetCurAttr(aSet);
CPPUNIT_ASSERT(aSet.HasItem(RES_LR_SPACE));
// Make sure that direct formatting is preserved during paste.
pWrtShell->EndPara(/*bSelect=*/false);
TransferableDataHelper aHelper(pTransfer.get());
SwTransferable::Paste(*pWrtShell, aHelper);
pWrtShell->GetCurAttr(aSet);
// This failed, direct formatting was lost.
CPPUNIT_ASSERT(aSet.HasItem(RES_LR_SPACE));
}
static void lcl_dispatchCommand(const uno::Reference<lang::XComponent>& xComponent,
const OUString& rCommand,
const uno::Sequence<beans::PropertyValue>& rPropertyValues)
{
uno::Reference<frame::XController> xController
= uno::Reference<frame::XModel>(xComponent, uno::UNO_QUERY_THROW)->getCurrentController();
CPPUNIT_ASSERT(xController.is());
uno::Reference<frame::XDispatchProvider> xFrame(xController->getFrame(), uno::UNO_QUERY);
CPPUNIT_ASSERT(xFrame.is());
uno::Reference<uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext();
uno::Reference<frame::XDispatchHelper> xDispatchHelper(frame::DispatchHelper::create(xContext));
CPPUNIT_ASSERT(xDispatchHelper.is());
xDispatchHelper->executeDispatch(xFrame, rCommand, OUString(), 0, rPropertyValues);
}
void SwUiWriterTest2::testTdf105330()
{
load(DATA_DIRECTORY, "tdf105330.odt");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
pWrtShell->Down(/*bSelect=*/false);
uno::Sequence<beans::PropertyValue> aTableArgs = {
comphelper::makePropertyValue("Rows", static_cast<sal_uInt16>(1)),
comphelper::makePropertyValue("Columns", static_cast<sal_uInt16>(1)),
};
lcl_dispatchCommand(mxComponent, ".uno:InsertTable", aTableArgs);
SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
sw::UndoManager& rUndoManager = pDoc->GetUndoManager();
rUndoManager.Undo();
// Without the accompanying fix in place, height was only 1 twips (practically invisible).
CPPUNIT_ASSERT_EQUAL(static_cast<long>(276),
pWrtShell->GetVisibleCursor()->GetTextCursor().GetSize().getHeight());
}
CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest2);
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|