Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sw / qa / api / BaseIndexTest.hxx
blob997f91aa948f49f725bb51029aef8a20631eb6db
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 #ifndef INCLUDED_SW_QA_API_BASEINDEXTEST_HXX
11 #define INCLUDED_SW_QA_API_BASEINDEXTEST_HXX
13 #include "ApiTestBase.hxx"
15 #include <cppunit/TestAssert.h>
16 #include <test/unoapi_property_testers.hxx>
18 #include <com/sun/star/beans/XPropertySet.hpp>
20 #include <com/sun/star/text/XTextColumns.hpp>
21 #include <com/sun/star/text/XTextSection.hpp>
22 #include <com/sun/star/graphic/XGraphic.hpp>
24 #include <vcl/BitmapTools.hxx>
25 #include <vcl/graph.hxx>
26 #include <vcl/pngwrite.hxx>
27 #include <unotools/tempfile.hxx>
28 #include <tools/stream.hxx>
30 namespace apitest
32 namespace
34 BitmapEx createExampleBitmap()
36 vcl::bitmap::RawBitmap aRawBitmap(Size(4, 4), 24);
37 aRawBitmap.SetPixel(0, 0, COL_LIGHTBLUE);
38 aRawBitmap.SetPixel(0, 1, COL_LIGHTGREEN);
39 aRawBitmap.SetPixel(1, 0, COL_LIGHTRED);
40 aRawBitmap.SetPixel(1, 1, COL_LIGHTMAGENTA);
41 return vcl::bitmap::CreateFromData(std::move(aRawBitmap));
44 void writerFileWithBitmap(OUString const& rURL)
46 BitmapEx aBitmapEx = createExampleBitmap();
47 SvFileStream aFileStream(rURL, StreamMode::READ | StreamMode::WRITE);
48 vcl::PNGWriter aWriter(aBitmapEx);
49 aWriter.Write(aFileStream);
50 aFileStream.Seek(STREAM_SEEK_TO_BEGIN);
51 aFileStream.Close();
54 } // end anonymous namespace
56 class BaseIndexTest : public ApiTestBase
58 public:
59 void testBaseIndexProperties()
61 auto map = init();
63 css::uno::Reference<css::beans::XPropertySet> xBaseIndex(map["text::BaseIndex"],
64 css::uno::UNO_QUERY_THROW);
65 testStringProperty(xBaseIndex, "Title", "Value");
66 testBooleanProperty(xBaseIndex, "IsProtected");
68 testStringProperty(xBaseIndex, "ParaStyleHeading", "Value");
69 testStringProperty(xBaseIndex, "ParaStyleLevel1", "Value");
70 testStringOptionalProperty(xBaseIndex, "ParaStyleLevel2");
71 testStringOptionalProperty(xBaseIndex, "ParaStyleLevel3");
72 testStringOptionalProperty(xBaseIndex, "ParaStyleLevel4");
73 testStringOptionalProperty(xBaseIndex, "ParaStyleLevel5");
74 testStringOptionalProperty(xBaseIndex, "ParaStyleLevel6");
75 testStringOptionalProperty(xBaseIndex, "ParaStyleLevel7");
76 testStringOptionalProperty(xBaseIndex, "ParaStyleLevel8");
77 testStringOptionalProperty(xBaseIndex, "ParaStyleLevel9");
78 testStringOptionalProperty(xBaseIndex, "ParaStyleLevel10");
79 testStringOptionalProperty(xBaseIndex, "ParaStyleSeparator");
81 // [property] XTextColumns TextColumns;
83 OUString name = "TextColumns";
85 css::uno::Reference<css::text::XTextColumns> xGetTextColumns;
86 CPPUNIT_ASSERT(xBaseIndex->getPropertyValue(name) >>= xGetTextColumns);
88 xGetTextColumns->setColumnCount(xGetTextColumns->getColumnCount() + 1);
89 xBaseIndex->setPropertyValue(name, css::uno::makeAny(xGetTextColumns));
91 css::uno::Reference<css::text::XTextColumns> xSetTextColumns;
92 CPPUNIT_ASSERT(xBaseIndex->getPropertyValue(name) >>= xSetTextColumns);
94 //CPPUNIT_ASSERT_EQUAL(xGetTextColumns->getColumnCount(), xSetTextColumns->getColumnCount());
97 // [property] com::sun::star::graphic::XGraphic BackGraphic;
98 // [property] string BackGraphicURL;
100 OUString name = "BackGraphicURL";
101 bool bOK = false;
104 xBaseIndex->getPropertyValue(name);
106 catch (css::uno::RuntimeException const& /*ex*/)
108 bOK = true;
110 // BackGraphicURL is "set-only" attribute
111 CPPUNIT_ASSERT_MESSAGE("Expected RuntimeException wasn't thrown", bOK);
113 utl::TempFile aTempFile;
114 aTempFile.EnableKillingFile();
115 writerFileWithBitmap(aTempFile.GetURL());
117 css::uno::Reference<css::graphic::XGraphic> xGraphic;
118 CPPUNIT_ASSERT(xBaseIndex->getPropertyValue("BackGraphic") >>= xGraphic);
119 CPPUNIT_ASSERT(!xGraphic.is());
121 xBaseIndex->setPropertyValue(name, css::uno::makeAny(aTempFile.GetURL()));
123 CPPUNIT_ASSERT(xBaseIndex->getPropertyValue("BackGraphic") >>= xGraphic);
124 CPPUNIT_ASSERT(xGraphic.is());
127 testStringProperty(xBaseIndex, "BackGraphicFilter", "Value");
129 // [property] com::sun::star::style::GraphicLocation BackGraphicLocation;
131 testColorProperty(xBaseIndex, "BackColor");
132 testBooleanProperty(xBaseIndex, "BackTransparent");
134 // [optional, property] com::sun::star::container::XIndexReplace LevelFormat;
136 testBooleanOptionalProperty(xBaseIndex, "CreateFromChapter");
138 // [property] com::sun::star::text::XTextSection ContentSection;
140 OUString name = "ContentSection";
142 css::uno::Reference<css::text::XTextSection> xGetTextSection;
143 CPPUNIT_ASSERT_MESSAGE(name.toUtf8().getStr(),
144 xBaseIndex->getPropertyValue(name) >>= xGetTextSection);
145 CPPUNIT_ASSERT_EQUAL_MESSAGE(name.toUtf8().getStr(), OUString(""),
146 xGetTextSection->getAnchor()->getString());
149 // [property] com::sun::star::text::XTextSection HeaderSection;
151 OUString name = "HeaderSection";
153 css::uno::Reference<css::text::XTextSection> xGetTextSection;
154 if (xBaseIndex->getPropertyValue(name).hasValue())
155 CPPUNIT_ASSERT_MESSAGE(name.toUtf8().getStr(),
156 xBaseIndex->getPropertyValue(name) >>= xGetTextSection);
162 #endif
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */