LibreOffice Module test (master) 1
baseindex.cxx
Go to the documentation of this file.
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 <cppunit/TestAssert.h>
11
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>
16
17#include <vcl/BitmapTools.hxx>
18#include <vcl/pngwrite.hxx>
19#include <unotools/tempfile.hxx>
20#include <tools/stream.hxx>
21
24
25namespace
26{
27BitmapEx createExampleBitmap()
28{
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));
35}
36
37void writerFileWithBitmap(OUString const& rURL)
38{
39 BitmapEx aBitmapEx = createExampleBitmap();
40 SvFileStream aFileStream(rURL, StreamMode::READ | StreamMode::WRITE);
41 vcl::PNGWriter aWriter(aBitmapEx);
42 aWriter.Write(aFileStream);
43 aFileStream.Seek(STREAM_SEEK_TO_BEGIN);
44 aFileStream.Close();
45}
46}
47
48namespace apitest
49{
51
53{
54 css::uno::Reference<css::beans::XPropertySet> xBaseIndex(init(), css::uno::UNO_QUERY_THROW);
55 testStringProperty(xBaseIndex, "Title", "Value");
56 testBooleanProperty(xBaseIndex, "IsProtected");
57
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");
70
71 // [property] XTextColumns TextColumns;
72 {
73 OUString name = "TextColumns";
74
75 css::uno::Reference<css::text::XTextColumns> xGetTextColumns;
76 CPPUNIT_ASSERT(xBaseIndex->getPropertyValue(name) >>= xGetTextColumns);
77
78 xGetTextColumns->setColumnCount(xGetTextColumns->getColumnCount() + 1);
79 xBaseIndex->setPropertyValue(name, css::uno::Any(xGetTextColumns));
80
81 css::uno::Reference<css::text::XTextColumns> xSetTextColumns;
82 CPPUNIT_ASSERT(xBaseIndex->getPropertyValue(name) >>= xSetTextColumns);
83
84 //CPPUNIT_ASSERT_EQUAL(xGetTextColumns->getColumnCount(), xSetTextColumns->getColumnCount());
85 }
86
87 // [property] com::sun::star::graphic::XGraphic BackGraphic;
88 // [property] string BackGraphicURL;
89 {
90 OUString name = "BackGraphicURL";
91 bool bOK = false;
92 try
93 {
94 xBaseIndex->getPropertyValue(name);
95 }
96 catch (css::uno::RuntimeException const& /*ex*/)
97 {
98 bOK = true;
99 }
100 // BackGraphicURL is "set-only" attribute
101 CPPUNIT_ASSERT_MESSAGE("Expected RuntimeException wasn't thrown", bOK);
102
103 utl::TempFile aTempFile;
104 aTempFile.EnableKillingFile();
105 writerFileWithBitmap(aTempFile.GetURL());
106
107 css::uno::Reference<css::graphic::XGraphic> xGraphic;
108 CPPUNIT_ASSERT(xBaseIndex->getPropertyValue("BackGraphic") >>= xGraphic);
109 CPPUNIT_ASSERT(!xGraphic.is());
110
111 xBaseIndex->setPropertyValue(name, css::uno::Any(aTempFile.GetURL()));
112
113 CPPUNIT_ASSERT(xBaseIndex->getPropertyValue("BackGraphic") >>= xGraphic);
114 CPPUNIT_ASSERT(xGraphic.is());
115 }
116
117 testStringProperty(xBaseIndex, "BackGraphicFilter", "Value");
118
119 // [property] com::sun::star::style::GraphicLocation BackGraphicLocation;
120
121 testColorProperty(xBaseIndex, "BackColor");
122 testBooleanProperty(xBaseIndex, "BackTransparent");
123
124 // [optional, property] com::sun::star::container::XIndexReplace LevelFormat;
125
126 testBooleanOptionalProperty(xBaseIndex, "CreateFromChapter");
127
128 // [property] com::sun::star::text::XTextSection ContentSection;
129 {
130 OUString name = "ContentSection";
131
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());
137 }
138
139 // [property] com::sun::star::text::XTextSection HeaderSection;
140 {
141 OUString name = "HeaderSection";
142
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);
147 }
148}
149}
150
151/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual ~BaseIndex()
Definition: baseindex.cxx:50
virtual css::uno::Reference< css::uno::XInterface > init()=0
void testBaseIndexProperties()
Definition: baseindex.cxx:52
OUString const & GetURL() const
void EnableKillingFile(bool bEnable=true)
const char * name
void testStringOptionalProperty(uno::Reference< beans::XPropertySet > const &xPropertySet, const OUString &rName, const OUString &rValue)
void testStringProperty(uno::Reference< beans::XPropertySet > const &xPropertySet, const OUString &name, const OUString &rValue)
void testBooleanProperty(uno::Reference< beans::XPropertySet > const &xPropertySet, const OUString &name)
void testColorProperty(uno::Reference< beans::XPropertySet > const &xPropertySet, const OUString &name, const util::Color &rValue)
void testBooleanOptionalProperty(uno::Reference< beans::XPropertySet > const &xPropertySet, const OUString &rName)
BitmapEx CreateFromData(sal_uInt8 const *pData, sal_Int32 nWidth, sal_Int32 nHeight, sal_Int32 nStride, vcl::PixelFormat ePixelFormat, bool bReversColors, bool bReverseAlpha)