~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to libs/odf/tests/KoPropertiesTest.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-09-21 15:36:35 UTC
  • mfrom: (1.4.1 upstream) (60.2.11 maverick)
  • Revision ID: james.westby@ubuntu.com-20100921153635-6tejqkiro2u21ydi
Tags: 1:2.2.2-0ubuntu3
Add kubuntu_03_fix-crash-on-closing-sqlite-connection-2.2.2.diff and
kubuntu_04_support-large-memo-values-for-msaccess-2.2.2.diff as
recommended by upstream http://kexi-
project.org/wiki/wikiview/index.php@Kexi2.2_Patches.html#sqlite_stab
ility

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (c) 2007 Boudewijn Rempt <boud@valdyas.org>
 
3
 *
 
4
 *  This program is free software; you can redistribute it and/or modify
 
5
 *  it under the terms of the GNU General Public License as published by
 
6
 *  the Free Software Foundation; either version 2 of the License, or
 
7
 *  (at your option) any later version.
 
8
 *
 
9
 *  This program is distributed in the hope that it will be useful,
 
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 *  GNU General Public License for more details.
 
13
 *
 
14
 *  You should have received a copy of the GNU General Public License
 
15
 *  along with this program; if not, write to the Free Software
 
16
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
17
 */
 
18
 
 
19
#include "KoPropertiesTest.h"
 
20
 
 
21
#include <qtest_kde.h>
 
22
#include <KoProperties.h>
 
23
 
 
24
void KoPropertiesTest::testDeserialization()
 
25
{
 
26
    QString test = "";
 
27
    KoProperties props;
 
28
    props.setProperty("bla", "bla");
 
29
 
 
30
    QVERIFY(!props.load(test));
 
31
    QVERIFY(!props.isEmpty());
 
32
    QVERIFY(props.stringProperty("bla") == "bla");
 
33
 
 
34
    test = "<bla>asdsadasjk</bla>";
 
35
    QVERIFY(props.load(test));
 
36
    QVERIFY(props.isEmpty());
 
37
 
 
38
    props.setProperty("bla", "bla");
 
39
    test = "<bla>asdsadasjk</";
 
40
    QVERIFY(!props.load(test));
 
41
    QVERIFY(!props.isEmpty());
 
42
    QVERIFY(props.stringProperty("bla") == "bla");
 
43
 
 
44
}
 
45
 
 
46
void KoPropertiesTest::testRoundTrip()
 
47
{
 
48
    KoProperties props;
 
49
    props.setProperty("string", "string");
 
50
    props.setProperty("xmlstring", "<xml>bla</xml>");
 
51
    props.setProperty("xmlstring2", "<xml>&adsa</xml>");
 
52
    props.setProperty("cdata", "<![CDATA[blabla]]>");
 
53
    props.setProperty("int", 10);
 
54
    props.setProperty("bool",  false);
 
55
    props.setProperty("qreal",  1.38);
 
56
 
 
57
    QString stored = props.store();
 
58
    KoProperties restored;
 
59
    restored.load(stored);
 
60
 
 
61
    QVERIFY(restored.stringProperty("string") == "string");
 
62
    QVERIFY(restored.stringProperty("xmlstring") == "<xml>bla</xml>");
 
63
    QVERIFY(restored.stringProperty("xmlstring2") == "<xml>&adsa</xml>");
 
64
    QVERIFY(restored.stringProperty("cdata") == "<![CDATA[blabla]]>");
 
65
    QVERIFY(restored.intProperty("int") == 10);
 
66
    QVERIFY(restored.boolProperty("bool") == false);
 
67
    QVERIFY(restored.doubleProperty("qreal") == 1.38);
 
68
 
 
69
}
 
70
 
 
71
void KoPropertiesTest::testProperties()
 
72
{
 
73
    KoProperties props;
 
74
    QVERIFY(props.isEmpty());
 
75
 
 
76
    QString visible = "visible";
 
77
    QVERIFY(!props.value(visible).isValid());
 
78
 
 
79
    props.setProperty("visible", "bla");
 
80
    QVERIFY(props.value("visible") == "bla");
 
81
    QVERIFY(props.stringProperty("visible", "blabla") == "bla");
 
82
 
 
83
    props.setProperty("bool",  true);
 
84
    QVERIFY(props.boolProperty("bool", false) == true);
 
85
    props.setProperty("bool",  false);
 
86
    QVERIFY(props.boolProperty("bool", true) == false);
 
87
 
 
88
    props.setProperty("qreal",  1.0);
 
89
    QVERIFY(props.doubleProperty("qreal", 2.0) == 1.0);
 
90
    props.setProperty("qreal",  2.0);
 
91
    QVERIFY(props.doubleProperty("qreal", 1.0) == 2.0);
 
92
 
 
93
    props.setProperty("int",  1);
 
94
    QVERIFY(props.intProperty("int", 2) == 1);
 
95
    props.setProperty("int",  2);
 
96
    QVERIFY(props.intProperty("int", 1) == 2);
 
97
 
 
98
    QVariant v;
 
99
    QVERIFY(props.property("sdsadsakldjsajd", v) == false);
 
100
    QVERIFY(!v.isValid());
 
101
    QVERIFY(props.property("visible", v) == true);
 
102
    QVERIFY(v.isValid());
 
103
    QVERIFY(v == "bla");
 
104
 
 
105
    QVERIFY(!props.isEmpty());
 
106
    QVERIFY(props.contains("visible"));
 
107
    QVERIFY(!props.contains("adsajkdsakj dsaieqwewqoie"));
 
108
    QVERIFY(props.contains(visible));
 
109
 
 
110
    int count = 0;
 
111
    QMapIterator<QString, QVariant> iter = props.propertyIterator();
 
112
    while (iter.hasNext()) {
 
113
        iter.next();
 
114
        count++;
 
115
    }
 
116
    QVERIFY(count == 4);
 
117
 
 
118
}
 
119
 
 
120
bool checkProps(const KoProperties & props)
 
121
{
 
122
    return (props.value("bla") == 1);
 
123
}
 
124
 
 
125
void KoPropertiesTest::testPassAround()
 
126
{
 
127
    KoProperties props;
 
128
    props.setProperty("bla", 1);
 
129
    QVERIFY(checkProps(props));
 
130
 
 
131
    KoProperties props2 = props;
 
132
    QVERIFY(checkProps(props2));
 
133
 
 
134
    KoProperties props3(props);
 
135
    checkProps(props3);
 
136
    props3.setProperty("bla", 3);
 
137
    QVERIFY(props3.value("bla") == 3);
 
138
 
 
139
    QVERIFY(checkProps(props));
 
140
    QVERIFY(checkProps(props2));
 
141
 
 
142
}
 
143
 
 
144
QTEST_KDEMAIN(KoPropertiesTest, NoGUI)
 
145
#include <KoPropertiesTest.moc>