1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <cppunit/TestAssert.h>
12 #include <com/sun/star/beans/XPropertySet.hpp>
13 #include <com/sun/star/graphic/XGraphic.hpp>
14 #include <com/sun/star/text/XTextColumns.hpp>
15 #include <com/sun/star/text/XTextSection.hpp>
17 #include <vcl/BitmapTools.hxx>
18 #include <vcl/filter/PngImageWriter.hxx>
19 #include <unotools/tempfile.hxx>
20 #include <tools/stream.hxx>
22 #include <test/unoapi_property_testers.hxx>
23 #include <test/text/baseindex.hxx>
27 BitmapEx
createExampleBitmap()
29 vcl::bitmap::RawBitmap
aRawBitmap(Size(4, 4), 24);
30 aRawBitmap
.SetPixel(0, 0, COL_LIGHTBLUE
);
31 aRawBitmap
.SetPixel(0, 1, COL_LIGHTGREEN
);
32 aRawBitmap
.SetPixel(1, 0, COL_LIGHTRED
);
33 aRawBitmap
.SetPixel(1, 1, COL_LIGHTMAGENTA
);
34 return vcl::bitmap::CreateFromData(std::move(aRawBitmap
));
37 void writerFileWithBitmap(OUString
const& rURL
)
39 BitmapEx aBitmapEx
= createExampleBitmap();
40 SvFileStream
aFileStream(rURL
, StreamMode::READ
| StreamMode::WRITE
);
41 vcl::PngImageWriter
aWriter(aFileStream
);
42 aWriter
.write(aBitmapEx
);
43 aFileStream
.Seek(STREAM_SEEK_TO_BEGIN
);
50 BaseIndex::~BaseIndex() {}
52 void BaseIndex::testBaseIndexProperties()
54 css::uno::Reference
<css::beans::XPropertySet
> xBaseIndex(init(), css::uno::UNO_QUERY_THROW
);
55 testStringProperty(xBaseIndex
, "Title", "Value");
56 testBooleanProperty(xBaseIndex
, "IsProtected");
58 testStringProperty(xBaseIndex
, "ParaStyleHeading", "Value");
59 testStringProperty(xBaseIndex
, "ParaStyleLevel1", "Value");
60 testStringOptionalProperty(xBaseIndex
, "ParaStyleLevel2");
61 testStringOptionalProperty(xBaseIndex
, "ParaStyleLevel3");
62 testStringOptionalProperty(xBaseIndex
, "ParaStyleLevel4");
63 testStringOptionalProperty(xBaseIndex
, "ParaStyleLevel5");
64 testStringOptionalProperty(xBaseIndex
, "ParaStyleLevel6");
65 testStringOptionalProperty(xBaseIndex
, "ParaStyleLevel7");
66 testStringOptionalProperty(xBaseIndex
, "ParaStyleLevel8");
67 testStringOptionalProperty(xBaseIndex
, "ParaStyleLevel9");
68 testStringOptionalProperty(xBaseIndex
, "ParaStyleLevel10");
69 testStringOptionalProperty(xBaseIndex
, "ParaStyleSeparator");
71 // [property] XTextColumns TextColumns;
73 OUString name
= "TextColumns";
75 css::uno::Reference
<css::text::XTextColumns
> xGetTextColumns
;
76 CPPUNIT_ASSERT(xBaseIndex
->getPropertyValue(name
) >>= xGetTextColumns
);
78 xGetTextColumns
->setColumnCount(xGetTextColumns
->getColumnCount() + 1);
79 xBaseIndex
->setPropertyValue(name
, css::uno::Any(xGetTextColumns
));
81 css::uno::Reference
<css::text::XTextColumns
> xSetTextColumns
;
82 CPPUNIT_ASSERT(xBaseIndex
->getPropertyValue(name
) >>= xSetTextColumns
);
84 //CPPUNIT_ASSERT_EQUAL(xGetTextColumns->getColumnCount(), xSetTextColumns->getColumnCount());
87 // [property] com::sun::star::graphic::XGraphic BackGraphic;
88 // [property] string BackGraphicURL;
90 OUString name
= "BackGraphicURL";
94 xBaseIndex
->getPropertyValue(name
);
96 catch (css::uno::RuntimeException
const& /*ex*/)
100 // BackGraphicURL is "set-only" attribute
101 CPPUNIT_ASSERT_MESSAGE("Expected RuntimeException wasn't thrown", bOK
);
103 utl::TempFileNamed aTempFile
;
104 aTempFile
.EnableKillingFile();
105 writerFileWithBitmap(aTempFile
.GetURL());
107 css::uno::Reference
<css::graphic::XGraphic
> xGraphic
;
108 CPPUNIT_ASSERT(xBaseIndex
->getPropertyValue("BackGraphic") >>= xGraphic
);
109 CPPUNIT_ASSERT(!xGraphic
.is());
111 xBaseIndex
->setPropertyValue(name
, css::uno::Any(aTempFile
.GetURL()));
113 CPPUNIT_ASSERT(xBaseIndex
->getPropertyValue("BackGraphic") >>= xGraphic
);
114 CPPUNIT_ASSERT(xGraphic
.is());
117 testStringProperty(xBaseIndex
, "BackGraphicFilter", "Value");
119 // [property] com::sun::star::style::GraphicLocation BackGraphicLocation;
121 testColorProperty(xBaseIndex
, "BackColor");
122 testBooleanProperty(xBaseIndex
, "BackTransparent");
124 // [optional, property] com::sun::star::container::XIndexReplace LevelFormat;
126 testBooleanOptionalProperty(xBaseIndex
, "CreateFromChapter");
128 // [property] com::sun::star::text::XTextSection ContentSection;
130 OUString name
= "ContentSection";
132 css::uno::Reference
<css::text::XTextSection
> xGetTextSection
;
133 CPPUNIT_ASSERT_MESSAGE(name
.toUtf8().getStr(),
134 xBaseIndex
->getPropertyValue(name
) >>= xGetTextSection
);
135 CPPUNIT_ASSERT_EQUAL_MESSAGE(name
.toUtf8().getStr(), OUString(""),
136 xGetTextSection
->getAnchor()->getString());
139 // [property] com::sun::star::text::XTextSection HeaderSection;
141 OUString name
= "HeaderSection";
143 css::uno::Reference
<css::text::XTextSection
> xGetTextSection
;
144 if (xBaseIndex
->getPropertyValue(name
).hasValue())
145 CPPUNIT_ASSERT_MESSAGE(name
.toUtf8().getStr(),
146 xBaseIndex
->getPropertyValue(name
) >>= xGetTextSection
);
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */