android: Update app-specific/MIME type icons
[LibreOffice.git] / writerfilter / qa / cppunittests / dmapper / PropertyMap.cxx
blobb50c0996d1af71119d04b7fc106a322f0333937d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include <test/unoapi_test.hxx>
12 #include <com/sun/star/text/XPageCursor.hpp>
13 #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
14 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
15 #include <com/sun/star/beans/XPropertySet.hpp>
16 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
17 #include <com/sun/star/table/BorderLine2.hpp>
19 using namespace ::com::sun::star;
21 namespace
23 /// Tests for writerfilter/source/dmapper/PropertyMap.cxx.
24 class Test : public UnoApiTest
26 public:
27 Test()
28 : UnoApiTest("/writerfilter/qa/cppunittests/dmapper/data/")
33 CPPUNIT_TEST_FIXTURE(Test, testFloatingTableHeader)
35 loadFromURL(u"floating-table-header.docx");
36 uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
37 uno::Reference<text::XTextViewCursorSupplier> xTextViewCursorSupplier(
38 xModel->getCurrentController(), uno::UNO_QUERY);
39 uno::Reference<text::XPageCursor> xCursor(xTextViewCursorSupplier->getViewCursor(),
40 uno::UNO_QUERY);
41 xCursor->jumpToLastPage();
42 // Without the accompanying fix in place, this test would have failed with:
43 // - Expected: 1
44 // - Actual : 3
45 // i.e. a document which is 1 page in Word was imported as a 3 page one.
46 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(1), xCursor->getPage());
49 CPPUNIT_TEST_FIXTURE(Test, testFollowPageTopMargin)
51 // Load a document with 2 pages: first page has larger top margin, second page has smaller top
52 // margin.
53 loadFromURL(u"follow-page-top-margin.docx");
54 uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(mxComponent,
55 uno::UNO_QUERY);
56 uno::Reference<container::XNameAccess> xStyleFamilies
57 = xStyleFamiliesSupplier->getStyleFamilies();
58 uno::Reference<container::XNameAccess> xStyleFamily(xStyleFamilies->getByName("PageStyles"),
59 uno::UNO_QUERY);
60 uno::Reference<beans::XPropertySet> xStyle(xStyleFamily->getByName("Standard"), uno::UNO_QUERY);
61 auto nTopMargin = xStyle->getPropertyValue("TopMargin").get<sal_Int32>();
63 // Without the accompanying fix in place, this test would have failed with:
64 // - Expected: 250
65 // - Actual : 1249
66 // i.e. the top margin on page 2 was too large.
67 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(250), nTopMargin);
70 CPPUNIT_TEST_FIXTURE(Test, testTableNegativeVerticalPos)
72 // Given a document with a table which has a negative vertical position (moves up to overlap
73 // with the header):
74 loadFromURL(u"table-negative-vertical-pos.docx");
76 // Then make sure we don't import that as a plain table, which can't have a negative top margin:
77 uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
78 uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage();
79 // Without the accompanying fix in place, this test would have failed with:
80 // - Expected: 1
81 // - Actual : 0
82 // i.e. this was imported as a plain table, resulting in a 0 top margin (y pos too large).
83 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xDrawPage->getCount());
86 CPPUNIT_TEST_FIXTURE(Test, testNegativePageBorder)
88 // Given a document with a top margin and a border which has more spacing than the margin:
89 loadFromURL(u"negative-page-border.docx");
91 // Then make sure that the border distance is negative, so it can appear at the correct
92 // position:
93 uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(mxComponent,
94 uno::UNO_QUERY);
95 uno::Reference<container::XNameAccess> xStyleFamilies
96 = xStyleFamiliesSupplier->getStyleFamilies();
97 uno::Reference<container::XNameAccess> xStyleFamily(xStyleFamilies->getByName("PageStyles"),
98 uno::UNO_QUERY);
99 uno::Reference<beans::XPropertySet> xStyle(xStyleFamily->getByName("Standard"), uno::UNO_QUERY);
100 auto nTopMargin = xStyle->getPropertyValue("TopMargin").get<sal_Int32>();
101 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(501), nTopMargin);
102 auto aTopBorder = xStyle->getPropertyValue("TopBorder").get<table::BorderLine2>();
103 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(159), aTopBorder.LineWidth);
104 auto nTopBorderDistance = xStyle->getPropertyValue("TopBorderDistance").get<sal_Int32>();
105 // Without the accompanying fix in place, this test would have failed with:
106 // - Expected: -646
107 // - Actual : 0
108 // i.e. the border negative distance was lost.
109 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(-646), nTopBorderDistance);
112 CPPUNIT_TEST_FIXTURE(Test, testNegativePageBorderNoMargin)
114 // Given a document with no top margin and a border which has spacing:
115 loadFromURL(u"negative-page-border-no-margin.docx");
117 // Then make sure that the border distance is negative, so it can appear at the correct
118 // position:
119 uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(mxComponent,
120 uno::UNO_QUERY);
121 uno::Reference<container::XNameAccess> xStyleFamilies
122 = xStyleFamiliesSupplier->getStyleFamilies();
123 uno::Reference<container::XNameAccess> xStyleFamily(xStyleFamilies->getByName("PageStyles"),
124 uno::UNO_QUERY);
125 uno::Reference<beans::XPropertySet> xStyle(xStyleFamily->getByName("Standard"), uno::UNO_QUERY);
126 auto nTopMargin = xStyle->getPropertyValue("TopMargin").get<sal_Int32>();
127 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), nTopMargin);
128 auto aTopBorder = xStyle->getPropertyValue("TopBorder").get<table::BorderLine2>();
129 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(159), aTopBorder.LineWidth);
130 auto nTopBorderDistance = xStyle->getPropertyValue("TopBorderDistance").get<sal_Int32>();
131 // Without the accompanying fix in place, this test would have failed with:
132 // - Expected: -1147
133 // - Actual : 0
134 // i.e. the border negative distance was lost.
135 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(-1147), nTopBorderDistance);
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */