| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* This file is part of the LibreOffice project. |
| 4 |
* |
| 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/. |
| 8 |
*/ |
| 9 |
|
| 10 |
#include <test/unoapixml_test.hxx> |
| 11 |
|
| 12 |
#include <com/sun/star/text/XTextDocument.hpp> |
| 13 |
#include <com/sun/star/beans/XPropertySet.hpp> |
| 14 |
#include <com/sun/star/style/ParagraphAdjust.hpp> |
| 15 |
#include <com/sun/star/qa/XDumper.hpp> |
| 16 |
|
| 17 |
using namespace ::com::sun::star; |
| 18 |
|
| 19 |
namespace |
| 20 |
{ |
| 21 |
/// Tests for sw/source/writerfilter/rtftok/rtfdispatchsymbol.cxx. |
| 22 |
class Test : public UnoApiXmlTest |
| 23 |
{ |
| 24 |
public: |
| 25 |
Test() |
| 26 |
: UnoApiXmlTest(u"/sw/qa/writerfilter/rtftok/data/"_ustr) |
| 27 |
{ |
| 28 |
} |
| 29 |
}; |
| 30 |
|
| 31 |
CPPUNIT_TEST_FIXTURE(Test, testPage) |
| 32 |
{ |
| 33 |
// Given a file with a \page and 2 \par tokens: |
| 34 |
loadFromFile(u"page.rtf"); |
| 35 |
|
| 36 |
// Then make sure we get exactly two paragraphs: |
| 37 |
uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); |
| 38 |
uno::Reference<container::XEnumerationAccess> xText(xTextDocument->getText(), uno::UNO_QUERY); |
| 39 |
uno::Reference<container::XEnumeration> xParagraphs = xText->createEnumeration(); |
| 40 |
xParagraphs->nextElement(); |
| 41 |
xParagraphs->nextElement(); |
| 42 |
// Without the accompanying fix in place, this test would have failed, the document had 3 |
| 43 |
// paragraphs, not 2. |
| 44 |
CPPUNIT_ASSERT(!xParagraphs->hasMoreElements()); |
| 45 |
} |
| 46 |
|
| 47 |
CPPUNIT_TEST_FIXTURE(Test, testCenterAfterPage) |
| 48 |
{ |
| 49 |
// Given a file with a \page, followed by a \qc: |
| 50 |
// When loading that file: |
| 51 |
loadFromFile(u"center-after-page.rtf"); |
| 52 |
|
| 53 |
// Then make sure that the last paragraph is centered: |
| 54 |
uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); |
| 55 |
uno::Reference<container::XEnumerationAccess> xText(xTextDocument->getText(), uno::UNO_QUERY); |
| 56 |
uno::Reference<container::XEnumeration> xParagraphs = xText->createEnumeration(); |
| 57 |
xParagraphs->nextElement(); |
| 58 |
xParagraphs->nextElement(); |
| 59 |
uno::Reference<beans::XPropertySet> xParagraph(xParagraphs->nextElement(), uno::UNO_QUERY); |
| 60 |
sal_Int16 eActual{}; |
| 61 |
CPPUNIT_ASSERT(xParagraph->getPropertyValue(u"ParaAdjust"_ustr) >>= eActual); |
| 62 |
// Without the accompanying fix in place, this test would have failed with: |
| 63 |
// - Expected: 3 (CENTER) |
| 64 |
// - Actual : 0 (LEFT) |
| 65 |
// i.e. the paragraph alignment on the second page was lost. |
| 66 |
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(style::ParagraphAdjust_CENTER), eActual); |
| 67 |
} |
| 68 |
|
| 69 |
CPPUNIT_TEST_FIXTURE(Test, testFloattableThenSectBreak) |
| 70 |
{ |
| 71 |
// Given a document with a floating table, immediately followed by \sect: |
| 72 |
// When loading that file: |
| 73 |
loadFromFile(u"floattable-then-sect-break.rtf"); |
| 74 |
|
| 75 |
// Then make sure that the floating table is on the first page: |
| 76 |
uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY); |
| 77 |
css::uno::Reference<qa::XDumper> xDumper(xModel->getCurrentController(), uno::UNO_QUERY); |
| 78 |
OString aDump = xDumper->dump(u"layout"_ustr).toUtf8(); |
| 79 |
auto pCharBuffer = reinterpret_cast<const xmlChar*>(aDump.getStr()); |
| 80 |
xmlDocUniquePtr pXmlDoc(xmlParseDoc(pCharBuffer)); |
| 81 |
// Without the accompanying fix in place, this test would have failed with: |
| 82 |
// - Expected: 1 |
| 83 |
// - Actual : 0 |
| 84 |
// i.e. the floating table was on the 2nd page, not on the 1st page. |
| 85 |
assertXPath(pXmlDoc, "/root/page[1]/sorted_objs/fly", 1); |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |