1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <swmodeltestbase.hxx>
12 #include <vcl/transfer.hxx>
13 #include <editeng/wghtitem.hxx>
14 #include <editeng/postitem.hxx>
15 #include <editeng/udlnitem.hxx>
18 #include <swdtflvr.hxx>
22 /// Covers sw/source/uibase/dochdl/ fixes.
23 class SwUibaseDochdlTest
: public SwModelTestBase
27 CPPUNIT_TEST_FIXTURE(SwUibaseDochdlTest
, testSelectPasteFormat
)
29 // Create a new document and cut a character.
31 SwDoc
* pDoc
= getSwDoc();
32 SwDocShell
* pDocShell
= pDoc
->GetDocShell();
33 SwWrtShell
* pWrtShell
= pDocShell
->GetWrtShell();
34 pWrtShell
->Insert2("x");
35 pWrtShell
->Left(SwCursorSkipMode::Chars
, /*bSelect=*/true, 1, /*bBasicCall=*/false);
36 rtl::Reference
<SwTransferable
> pTransfer
= new SwTransferable(*pWrtShell
);
39 // Decide what format to use when doing a Writer->Writer paste and both RTF and ODF is an
41 TransferableDataHelper
aHelper(pTransfer
);
42 sal_uInt8 nAction
= EXCHG_OUT_ACTION_INSERT_STRING
;
43 SotClipboardFormatId nFormat
= SotClipboardFormatId::RICHTEXT
;
44 SwTransferable::SelectPasteFormat(aHelper
, nAction
, nFormat
);
46 CPPUNIT_ASSERT_EQUAL(EXCHG_OUT_ACTION_INSERT_OLE
, nAction
);
47 // Without the accompanying fix in place, this test would have failed with:
48 // - Expected: 85 (EMBED_SOURCE)
49 // - Actual : 145 (RICHTEXT)
50 // i.e. RTF was selected for Writer->Writer out of process copying, which is worse than ODF.
51 CPPUNIT_ASSERT_EQUAL(SotClipboardFormatId::EMBED_SOURCE
, nFormat
);
54 CPPUNIT_TEST_FIXTURE(SwUibaseDochdlTest
, testComplexSelection
)
56 // Given a document where a text node has hints, but no as-char images.
58 SwDoc
* pDoc
= getSwDoc();
59 SwDocShell
* pDocShell
= pDoc
->GetDocShell();
60 SwWrtShell
* pWrtShell
= pDocShell
->GetWrtShell();
61 pWrtShell
->Insert2("abc");
62 pWrtShell
->Left(SwCursorSkipMode::Chars
, /*bSelect=*/false, 1, /*bBasicCall=*/false);
63 pWrtShell
->Left(SwCursorSkipMode::Chars
, /*bSelect=*/true, 1, /*bBasicCall=*/false);
64 SfxItemSet
aSet(pWrtShell
->GetView().GetPool(),
65 svl::Items
<RES_CHRATR_BEGIN
, RES_CHRATR_END
- 1>);
66 // Bold, italic, underline.
67 aSet
.Put(SvxWeightItem(WEIGHT_BOLD
, RES_CHRATR_WEIGHT
));
68 aSet
.Put(SvxPostureItem(ITALIC_NORMAL
, RES_CHRATR_POSTURE
));
69 aSet
.Put(SvxUnderlineItem(LINESTYLE_SINGLE
, RES_CHRATR_UNDERLINE
));
70 pWrtShell
->SetAttrSet(aSet
);
71 uno::Reference
<datatransfer::XTransferable2
> xTransfer
= new SwTransferable(*pWrtShell
);
73 // When checking if the selection is complex, then there should be no crash.
74 // Without the accompanying fix in place, this test would have crashed, because we read past the
75 // end of the hints array.
76 CPPUNIT_ASSERT(!xTransfer
->isComplex());
79 CPPUNIT_PLUGIN_IMPLEMENT();
81 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */