summaryrefslogtreecommitdiffstats
path: root/test/source/text/baseindex.cxx
blob: 172cabb5798148c52690e7c1b27fc3be5ccebe1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#include <cppunit/TestAssert.h>

#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/graphic/XGraphic.hpp>
#include <com/sun/star/text/XTextColumns.hpp>
#include <com/sun/star/text/XTextSection.hpp>

#include <vcl/BitmapTools.hxx>
#include <vcl/filter/PngImageWriter.hxx>
#include <unotools/tempfile.hxx>
#include <tools/stream.hxx>

#include <test/unoapi_property_testers.hxx>
#include <test/text/baseindex.hxx>

namespace
{
BitmapEx createExampleBitmap()
{
    vcl::bitmap::RawBitmap aRawBitmap(Size(4, 4), 24);
    aRawBitmap.SetPixel(0, 0, COL_LIGHTBLUE);
    aRawBitmap.SetPixel(0, 1, COL_LIGHTGREEN);
    aRawBitmap.SetPixel(1, 0, COL_LIGHTRED);
    aRawBitmap.SetPixel(1, 1, COL_LIGHTMAGENTA);
    return vcl::bitmap::CreateFromData(std::move(aRawBitmap));
}

void writerFileWithBitmap(OUString const& rURL)
{
    BitmapEx aBitmapEx = createExampleBitmap();
    SvFileStream aFileStream(rURL, StreamMode::READ | StreamMode::WRITE);
    vcl::PngImageWriter aWriter(aFileStream);
    aWriter.write(aBitmapEx);
    aFileStream.Seek(STREAM_SEEK_TO_BEGIN);
    aFileStream.Close();
}
}

namespace apitest
{
BaseIndex::~BaseIndex() {}

void BaseIndex::testBaseIndexProperties()
{
    css::uno::Reference<css::beans::XPropertySet> xBaseIndex(init(), css::uno::UNO_QUERY_THROW);
    testStringProperty(xBaseIndex, "Title", "Value");
    testBooleanProperty(xBaseIndex, "IsProtected");

    testStringProperty(xBaseIndex, "ParaStyleHeading", "Value");
    testStringProperty(xBaseIndex, "ParaStyleLevel1", "Value");
    testStringOptionalProperty(xBaseIndex, "ParaStyleLevel2");
    testStringOptionalProperty(xBaseIndex, "ParaStyleLevel3");
    testStringOptionalProperty(xBaseIndex, "ParaStyleLevel4");
    testStringOptionalProperty(xBaseIndex, "ParaStyleLevel5");
    testStringOptionalProperty(xBaseIndex, "ParaStyleLevel6");
    testStringOptionalProperty(xBaseIndex, "ParaStyleLevel7");
    testStringOptionalProperty(xBaseIndex, "ParaStyleLevel8");
    testStringOptionalProperty(xBaseIndex, "ParaStyleLevel9");
    testStringOptionalProperty(xBaseIndex, "ParaStyleLevel10");
    testStringOptionalProperty(xBaseIndex, "ParaStyleSeparator");

    //      [property] XTextColumns TextColumns;
    {
        OUString name = "TextColumns";

        css::uno::Reference<css::text::XTextColumns> xGetTextColumns;
        CPPUNIT_ASSERT(xBaseIndex->getPropertyValue(name) >>= xGetTextColumns);

        xGetTextColumns->setColumnCount(xGetTextColumns->getColumnCount() + 1);
        xBaseIndex->setPropertyValue(name, css::uno::Any(xGetTextColumns));

        css::uno::Reference<css::text::XTextColumns> xSetTextColumns;
        CPPUNIT_ASSERT(xBaseIndex->getPropertyValue(name) >>= xSetTextColumns);

        //CPPUNIT_ASSERT_EQUAL(xGetTextColumns->getColumnCount(), xSetTextColumns->getColumnCount());
    }

    //      [property] com::sun::star::graphic::XGraphic BackGraphic;
    //      [property] string BackGraphicURL;
    {
        OUString name = "BackGraphicURL";
        bool bOK = false;
        try
        {
            xBaseIndex->getPropertyValue(name);
        }
        catch (css::uno::RuntimeException const& /*ex*/)
        {
            bOK = true;
        }
        // BackGraphicURL is "set-only" attribute
        CPPUNIT_ASSERT_MESSAGE("Expected RuntimeException wasn't thrown", bOK);

        utl::TempFileNamed aTempFile;
        aTempFile.EnableKillingFile();
        writerFileWithBitmap(aTempFile.GetURL());

        css::uno::Reference<css::graphic::XGraphic> xGraphic;
        CPPUNIT_ASSERT(xBaseIndex->getPropertyValue("BackGraphic") >>= xGraphic);
        CPPUNIT_ASSERT(!xGraphic.is());

        xBaseIndex->setPropertyValue(name, css::uno::Any(aTempFile.GetURL()));

        CPPUNIT_ASSERT(xBaseIndex->getPropertyValue("BackGraphic") >>= xGraphic);
        CPPUNIT_ASSERT(xGraphic.is());
    }

    testStringProperty(xBaseIndex, "BackGraphicFilter", "Value");

    //      [property] com::sun::star::style::GraphicLocation BackGraphicLocation;

    testColorProperty(xBaseIndex, "BackColor");
    testBooleanProperty(xBaseIndex, "BackTransparent");

    //      [optional, property] com::sun::star::container::XIndexReplace LevelFormat;

    testBooleanOptionalProperty(xBaseIndex, "CreateFromChapter");

    //      [property] com::sun::star::text::XTextSection ContentSection;
    {
        OUString name = "ContentSection";

        css::uno::Reference<css::text::XTextSection> xGetTextSection;
        CPPUNIT_ASSERT_MESSAGE(name.toUtf8().getStr(),
                               xBaseIndex->getPropertyValue(name) >>= xGetTextSection);
        CPPUNIT_ASSERT_EQUAL_MESSAGE(name.toUtf8().getStr(), OUString(""),
                                     xGetTextSection->getAnchor()->getString());
    }

    //      [property] com::sun::star::text::XTextSection HeaderSection;
    {
        OUString name = "HeaderSection";

        css::uno::Reference<css::text::XTextSection> xGetTextSection;
        if (xBaseIndex->getPropertyValue(name).hasValue())
            CPPUNIT_ASSERT_MESSAGE(name.toUtf8().getStr(),
                                   xBaseIndex->getPropertyValue(name) >>= xGetTextSection);
    }
}
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */