Avoid potential negative array index access to cached text.
[LibreOffice.git] / writerfilter / qa / cppunittests / rtftok / rtfdispatchvalue.cxx
blob374c5246ca7a9ceaa690c8b30a7bb32259483177
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/beans/XPropertySet.hpp>
13 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
14 #include <com/sun/star/table/BorderLine2.hpp>
16 using namespace ::com::sun::star;
18 namespace
20 /// Tests for writerfilter/source/rtftok/rtfdispatchvalue.cxx.
21 class Test : public UnoApiTest
23 public:
24 Test()
25 : UnoApiTest("/writerfilter/qa/cppunittests/rtftok/data/")
30 CPPUNIT_TEST_FIXTURE(Test, testFollowStyle)
32 // Given a file with \snext:
33 loadFromFile(u"follow-style.rtf");
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("ParagraphStyles"), uno::UNO_QUERY);
42 uno::Reference<beans::XPropertySet> xStyle(xStyleFamily->getByName("Heading 1"),
43 uno::UNO_QUERY);
44 OUString aFollowStyle;
45 xStyle->getPropertyValue("FollowStyle") >>= 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(OUString("Standard"), aFollowStyle);
53 CPPUNIT_TEST_FIXTURE(Test, testNegativePageBorder)
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");
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(xStyleFamilies->getByName("PageStyles"),
65 uno::UNO_QUERY);
66 uno::Reference<beans::XPropertySet> xStyle(xStyleFamily->getByName("Standard"), uno::UNO_QUERY);
67 auto nTopMargin = xStyle->getPropertyValue("TopMargin").get<sal_Int32>();
68 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(501), nTopMargin);
69 auto aTopBorder = xStyle->getPropertyValue("TopBorder").get<table::BorderLine2>();
70 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(159), aTopBorder.LineWidth);
71 auto nTopBorderDistance = xStyle->getPropertyValue("TopBorderDistance").get<sal_Int32>();
72 // Without the accompanying fix in place, this test would have failed with:
73 // - Expected: -646
74 // - Actual : 342
75 // i.e. the border negative distance was lost.
76 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(-646), nTopBorderDistance);
80 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */