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
|
/* -*- 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/text/XTextAppend.hpp>
#include <com/sun/star/text/XTextFrame.hpp>
#include <wrtsh.hxx>
#include <unotextrange.hxx>
#include <unotxdoc.hxx>
#include <docsh.hxx>
using namespace ::com::sun::star;
namespace
{
OUStringLiteral const DATA_DIRECTORY = u"/sw/qa/core/unocore/data/";
}
/// Covers sw/source/core/unocore/ fixes.
class SwCoreUnocoreTest : public SwModelTestBase
{
};
CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, testTdf119081)
{
// Load a doc with a nested table in it.
load(DATA_DIRECTORY, "tdf119081.odt");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
SwDocShell* pDocShell = pTextDoc->GetDocShell();
SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
// Enter outer A1.
pWrtShell->Down(/*bSelect=*/false, /*nCount=*/3);
// Enter inner A1.
pWrtShell->Right(CRSR_SKIP_CELLS, /*bSelect=*/false, /*nCount=*/1, /*bBasicCall=*/false,
/*bVisual=*/true);
// Enter outer B1.
pWrtShell->Down(/*bSelect=*/false, /*nCount=*/2);
SwDoc* pDoc = pDocShell->GetDoc();
SwPaM& rCursor = pWrtShell->GetCurrentShellCursor();
uno::Reference<text::XTextRange> xInsertPosition
= SwXTextRange::CreateXTextRange(*pDoc, *rCursor.GetPoint(), nullptr);
uno::Reference<text::XTextAppend> xTextAppend(xInsertPosition->getText(), uno::UNO_QUERY);
// Without the accompanying fix in place, this test would have failed with:
// An uncaught exception of type com.sun.star.uno.RuntimeException
xTextAppend->insertTextPortion("x", {}, xInsertPosition);
// Verify that the string is indeed inserted.
pWrtShell->Left(CRSR_SKIP_CELLS, /*bSelect=*/true, /*nCount=*/1, /*bBasicCall=*/false,
/*bVisual=*/true);
CPPUNIT_ASSERT_EQUAL(OUString("x"), pWrtShell->GetCurrentShellCursor().GetText());
}
CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, flyAtParaAnchor)
{
mxComponent = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument");
uno::Reference<lang::XMultiServiceFactory> const xMSF(mxComponent, uno::UNO_QUERY_THROW);
uno::Reference<text::XTextDocument> const xTD(mxComponent, uno::UNO_QUERY_THROW);
uno::Reference<text::XTextFrame> const xTextFrame(
xMSF->createInstance("com.sun.star.text.TextFrame"), uno::UNO_QUERY_THROW);
uno::Reference<beans::XPropertySet> const xFrameProps(xTextFrame, uno::UNO_QUERY_THROW);
xFrameProps->setPropertyValue("AnchorType",
uno::makeAny(text::TextContentAnchorType_AT_PARAGRAPH));
auto const xText = xTD->getText();
auto const xTextCursor = xText->createTextCursor();
CPPUNIT_ASSERT(xTextCursor.is());
xText->insertTextContent(xTextCursor, xTextFrame, false);
auto const xAnchor = xTextFrame->getAnchor();
uno::Reference<text::XTextContent> const xFieldmark(
xMSF->createInstance("com.sun.star.text.Fieldmark"), uno::UNO_QUERY_THROW);
// this crashed because the anchor didn't have SwIndex
xText->insertTextContent(xAnchor, xFieldmark, false);
}
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|