Debian Codegraph @

sw/qa/writerfilter/rtftok/rtfdispatchvalue.cxx

raw
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/unoapi_test.hxx>
11
12 #include <com/sun/star/beans/XPropertySet.hpp>
13 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
14 #include <com/sun/star/table/BorderLine2.hpp>
15
16 using namespace ::com::sun::star;
17
18 namespace
19 {
20 /// Tests for sw/source/writerfilter/rtftok/rtfdispatchvalue.cxx.
21 class Test : public UnoApiTest
22 {
23 public:
24 Test()
25 : UnoApiTest(u"/sw/qa/writerfilter/rtftok/data/"_ustr)
26 {
27 }
28 };
29
30 CPPUNIT_TEST_FIXTURE(Test, testFollowStyle)
31 {
32 // Given a file with \snext:
33 loadFromFile(u"follow-style.rtf");
34
35 // Then make sure we set the follow of the para style correctly:
36 uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(mxComponent,
37 uno::UNO_QUERY);
38 uno::Reference<container::XNameAccess> xStyleFamilies
39 = xStyleFamiliesSupplier->getStyleFamilies();
40 uno::Reference<container::XNameAccess> xStyleFamily(
41 xStyleFamilies->getByName(u"ParagraphStyles"_ustr), uno::UNO_QUERY);
42 uno::Reference<beans::XPropertySet> xStyle(xStyleFamily->getByName(u"Heading 1"_ustr),
43 uno::UNO_QUERY);
44 OUString aFollowStyle;
45 xStyle->getPropertyValue(u"FollowStyle"_ustr) >>= aFollowStyle;
46 // Without the accompanying fix in place, this test would have failed with:
47 // - Expected: Standard
48 // - Actual : Heading 1
49 // i.e. \snext was ignored.
50 CPPUNIT_ASSERT_EQUAL(u"Standard"_ustr, aFollowStyle);
51 }
52
53 CPPUNIT_TEST_FIXTURE(Test, testNegativePageBorder)
54 {
55 // Given a document with a top margin and a border which has more spacing than the margin:
56 loadFromFile(u"negative-page-border.rtf");
57
58 // Then make sure that the border distance is negative, so it can appear at the correct
59 // position:
60 uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(mxComponent,
61 uno::UNO_QUERY);
62 uno::Reference<container::XNameAccess> xStyleFamilies
63 = xStyleFamiliesSupplier->getStyleFamilies();
64 uno::Reference<container::XNameAccess> xStyleFamily(
65 xStyleFamilies->getByName(u"PageStyles"_ustr), uno::UNO_QUERY);
66 uno::Reference<beans::XPropertySet> xStyle(xStyleFamily->getByName(u"Standard"_ustr),
67 uno::UNO_QUERY);
68 auto nTopMargin = xStyle->getPropertyValue(u"TopMargin"_ustr).get<sal_Int32>();
69 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(501), nTopMargin);
70 auto aTopBorder = xStyle->getPropertyValue(u"TopBorder"_ustr).get<table::BorderLine2>();
71 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(159), aTopBorder.LineWidth);
72 auto nTopBorderDistance = xStyle->getPropertyValue(u"TopBorderDistance"_ustr).get<sal_Int32>();
73 // Without the accompanying fix in place, this test would have failed with:
74 // - Expected: -646
75 // - Actual : 342
76 // i.e. the border negative distance was lost.
77 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(-646), nTopBorderDistance);
78 }
79 }
80
81 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */