summaryrefslogtreecommitdiffstats
path: root/lib/kofficecore/tests/kooasissettingstest.cpp
blob: a60fbd869420e218c7a5ff28850e2c81e00daead (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
/* This file is part of the KDE project
   Copyright (C) 2004 David Faure <faure@kde.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2 as published by the Free Software Foundation.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#include <KoOasisSettings.h>
#include <KoDom.h>
#include <kdebug.h>
#include <assert.h>

void testSelectItemSet( KoOasisSettings& settings )
{
    KoOasisSettings::Items items = settings.itemSet( "notexist" );
    assert( items.isNull() );
    items = settings.itemSet( "view-settings" );
    assert( !items.isNull() );
    kdDebug() << "testSelectItemSet OK" << endl;
}

void testParseConfigItemString( KoOasisSettings& settings )
{
    KoOasisSettings::Items viewSettings = settings.itemSet( "view-settings" );
    const TQString unit = viewSettings.parseConfigItemString( "unit" );
    qDebug( "%s", unit.latin1() );
    assert( unit == "mm" );
    kdDebug() << "testParseConfigItemString OK" << endl;
}

void testIndexedMap( KoOasisSettings& settings )
{
    KoOasisSettings::Items viewSettings = settings.itemSet( "view-settings" );
    assert( !viewSettings.isNull() );
    KoOasisSettings::IndexedMap viewMap = viewSettings.indexedMap( "Views" );
    assert( !viewMap.isNull() );
    KoOasisSettings::Items firstView = viewMap.entry( 0 );
    assert( !firstView.isNull() );
    const short zoomFactor = firstView.parseConfigItemShort( "ZoomFactor" );
    assert( zoomFactor == 100 );
    KoOasisSettings::Items secondView = viewMap.entry( 1 );
    assert( secondView.isNull() );
    kdDebug() << "testIndexedMap OK" << endl;
}

void testNamedMap( KoOasisSettings& settings )
{
    KoOasisSettings::Items viewSettings = settings.itemSet( "view-settings" );
    assert( !viewSettings.isNull() );
    KoOasisSettings::NamedMap viewMap = viewSettings.namedMap( "NamedMap" );
    assert( !viewMap.isNull() );
    KoOasisSettings::Items foo = viewMap.entry( "foo" );
    assert( !foo.isNull() );
    const int zoomFactor = foo.parseConfigItemShort( "ZoomFactor" );
    assert( zoomFactor == 100 );
    KoOasisSettings::Items secondView = viewMap.entry( "foobar" );
    assert( secondView.isNull() );
    kdDebug() << "testNamedMap OK" << endl;
}

int main( int, char** ) {

    const TQCString xml = "\
<?xml version=\"1.0\" encoding=\"UTF-8\"?> \
<office:document-settings xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\" xmlns:config=\"urn:oasis:names:tc:opendocument:xmlns:config:1.0\"> \
 <office:settings> \
  <config:config-item-set config:name=\"view-settings\"> \
    <config:config-item config:name=\"unit\" config:type=\"string\">mm</config:config-item> \
    <config:config-item-map-indexed config:name=\"Views\"> \
      <config:config-item-map-entry> \
        <config:config-item config:name=\"ZoomFactor\" config:type=\"short\">100</config:config-item> \
      </config:config-item-map-entry> \
    </config:config-item-map-indexed> \
    <config:config-item-map-named config:name=\"NamedMap\"> \
      <config:config-item-map-entry config:name=\"foo\"> \
        <config:config-item config:name=\"ZoomFactor\" config:type=\"int\">100</config:config-item> \
      </config:config-item-map-entry> \
    </config:config-item-map-named> \
  </config:config-item-set> \
 </office:settings> \
</office:document-settings> \
";

    TQDomDocument doc;
    bool ok = doc.setContent( xml, true /* namespace processing */ );
    assert( ok );

    KoOasisSettings settings( doc );

    testSelectItemSet( settings );
    testParseConfigItemString( settings );
    testIndexedMap( settings );
    testNamedMap( settings );
    return 0;
}