~ubuntu-branches/ubuntu/karmic/psi/karmic

« back to all changes in this revision

Viewing changes to src/tools/iconset/unittest/testiconset.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2008-04-14 18:57:30 UTC
  • mfrom: (2.1.9 hardy)
  • Revision ID: james.westby@ubuntu.com-20080414185730-528re3zp0m2hdlhi
Tags: 0.11-8
* added CONFIG -= link_prl to .pro files and removed dependencies
  which are made unnecessary by this change
* Fix segfault when closing last chat tab with qt4.4
  (This is from upstream svn, rev. 1101) (Closes: Bug#476122)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <QtTest/QtTest>
 
2
 
 
3
#include "iconset.h"
 
4
#include "anim.h"
 
5
 
 
6
class TestIconset: public QObject
 
7
{
 
8
        Q_OBJECT
 
9
private:
 
10
        Iconset *iconset;
 
11
 
 
12
private slots:
 
13
        void initTestCase()
 
14
        {
 
15
                iconset = new Iconset();
 
16
                QVERIFY(iconset->load("iconsets/roster/default.jisp"));
 
17
                iconset->addToFactory();
 
18
        }
 
19
 
 
20
        void cleanupTestCase()
 
21
        {
 
22
                iconset->clear();
 
23
                QCOMPARE(iconset->count(), 0);
 
24
 
 
25
                delete iconset;
 
26
        }
 
27
 
 
28
        void testIconsetData()
 
29
        {
 
30
                // verify metadata
 
31
                QCOMPARE(iconset->name(),            QString("Stellar (default)"));
 
32
                QCOMPARE(iconset->version(),         QString("1.0"));
 
33
                QCOMPARE(iconset->authors().count(), 2);
 
34
                QCOMPARE(iconset->authors()[0],      QString("Jason Kim<br>&nbsp;&nbsp;Email: <a href='mailto:jmkim@uci.edu'>jmkim@uci.edu</a>"));
 
35
                QCOMPARE(iconset->authors()[1],      QString("Michail Pishchagin (icondef.xml)<br>&nbsp;&nbsp;Email: <a href='mailto:mblsha@users.sourceforge.net'>mblsha@users.sourceforge.net</a><br>&nbsp;&nbsp;JID: <a href='jabber:mblsha@jabber.ru'>mblsha@jabber.ru</a><br>&nbsp;&nbsp;WWW: <a href='http://maz.sf.net'>http://maz.sf.net</a>"));
 
36
                QCOMPARE(iconset->creation(),        QString("2003-07-08"));
 
37
                QCOMPARE(iconset->description(),     QString("Default Psi 0.9.1 iconset"));
 
38
                
 
39
                // verify icons
 
40
                QCOMPARE(iconset->count(), 19);
 
41
        }
 
42
 
 
43
        void testIterator() 
 
44
        {
 
45
                QStringList iconNames;
 
46
                QListIterator<PsiIcon *> it = iconset->iterator();
 
47
                while ( it.hasNext() ) {
 
48
                        PsiIcon *icon = it.next();
 
49
                        iconNames << icon->name();
 
50
                }
 
51
                QCOMPARE(iconNames.count(), iconset->count());
 
52
        }
 
53
        
 
54
        void testHeadlineIcon() 
 
55
        {
 
56
                const PsiIcon *messageHeadline = IconsetFactory::iconPtr("psi/headline");
 
57
                QVERIFY(messageHeadline != 0);
 
58
                QCOMPARE(messageHeadline->name(),        QString("psi/headline"));
 
59
                QCOMPARE(messageHeadline->isAnimated(),  false);
 
60
                QCOMPARE(messageHeadline->frameNumber(), 0);
 
61
                QCOMPARE(messageHeadline->anim(),        (const Anim *)0);
 
62
                QCOMPARE(messageHeadline->pixmap().width(),  16);
 
63
                QCOMPARE(messageHeadline->pixmap().height(), 16);
 
64
        }
 
65
        
 
66
        void testAnim()
 
67
        {
 
68
                const PsiIcon *chat = IconsetFactory::iconPtr("psi/chat");
 
69
                QVERIFY(chat->anim() != 0);
 
70
 
 
71
                const Anim *anim = chat->anim();
 
72
                Anim *copy1 = new Anim(*anim);
 
73
                Anim *copy2 = new Anim(*copy1);
 
74
                Anim *copy3 = new Anim(*copy2);
 
75
                
 
76
                // at first, all animations should contain 15 frames
 
77
                QCOMPARE(copy3->numFrames(), 15);
 
78
                
 
79
                copy3->stripFirstFrame();
 
80
                QCOMPARE(copy3->numFrames(), 14);
 
81
                QCOMPARE(copy2->numFrames(), 15);
 
82
                QCOMPARE(copy1->numFrames(), 15);
 
83
                QCOMPARE(anim->numFrames(),  15);
 
84
                
 
85
                int i;
 
86
                for (i = 0; i < 2; i++)
 
87
                        copy2->stripFirstFrame();
 
88
                QCOMPARE(copy3->numFrames(), 14);
 
89
                QCOMPARE(copy2->numFrames(), 13);
 
90
                QCOMPARE(copy1->numFrames(), 15);
 
91
                QCOMPARE(anim->numFrames(),  15);
 
92
 
 
93
                for (i = 0; i < 5; i++)
 
94
                        copy1->stripFirstFrame();
 
95
                QCOMPARE(copy3->numFrames(), 14);
 
96
                QCOMPARE(copy2->numFrames(), 13);
 
97
                QCOMPARE(copy1->numFrames(), 10);
 
98
                QCOMPARE(anim->numFrames(),  15);
 
99
                
 
100
                delete copy3;
 
101
                delete copy2;
 
102
                delete copy1;
 
103
        }
 
104
                
 
105
        void testIconStripping()
 
106
        {
 
107
                const PsiIcon *chat = IconsetFactory::iconPtr("psi/chat");
 
108
                QVERIFY(chat != 0);
 
109
 
 
110
                QVERIFY(chat->isAnimated() == true);
 
111
                QCOMPARE(chat->anim()->numFrames(), 15);
 
112
                
 
113
                PsiIcon *stripping = new PsiIcon(*chat);
 
114
                QCOMPARE(chat->name(),      QString("psi/chat"));
 
115
                QCOMPARE(stripping->name(), QString("psi/chat"));
 
116
 
 
117
                stripping->stripFirstAnimFrame();
 
118
                QCOMPARE(stripping->anim()->numFrames(), 14);
 
119
                QCOMPARE(chat->anim()->numFrames(),      15);
 
120
 
 
121
                stripping->setName("yohimbo");
 
122
                QCOMPARE(chat->name(),      QString("psi/chat"));
 
123
                QCOMPARE(stripping->name(), QString("yohimbo"));
 
124
 
 
125
                delete stripping;
 
126
        }
 
127
        
 
128
        void testIconsetFactory()
 
129
        {
 
130
                QCOMPARE(IconsetFactory::icons().count(), 19);
 
131
                QVERIFY(IconsetFactory::iconPtr("psi/message"));
 
132
        }
 
133
 
 
134
        void testCombineIconsets()
 
135
        {
 
136
                Iconset *is = new Iconset();
 
137
                QVERIFY(is->load("iconsets/roster/small.jisp"));
 
138
                
 
139
                Iconset *combined = new Iconset(*is);
 
140
                QCOMPARE(combined->count(), is->count());
 
141
 
 
142
                *combined += *is;
 
143
                QCOMPARE(combined->count(), is->count());
 
144
                
 
145
                QListIterator<PsiIcon*> it = is->iterator();
 
146
                while (it.hasNext()) {
 
147
                        PsiIcon *icon = new PsiIcon(*it.next());
 
148
                        icon->setName(icon->name() + "2");
 
149
                        combined->setIcon(icon->name(), *icon);
 
150
                        delete icon;
 
151
                }
 
152
                QCOMPARE(combined->count(), 4);
 
153
                
 
154
                combined->clear();
 
155
                QCOMPARE(combined->count(), 0);
 
156
                QCOMPARE(is->count(),       2);
 
157
                
 
158
                delete combined;
 
159
                delete is;
 
160
        }
 
161
        
 
162
        void testLoadGifIconset()
 
163
        {
 
164
                Iconset *is = new Iconset();
 
165
                QVERIFY(is->load("iconsets/emoticons/puz.jisp"));
 
166
                QVERIFY(is->count() > 0);
 
167
                delete is;
 
168
        }
 
169
                
 
170
        void testMultipleIconTextStrings()
 
171
        {
 
172
                // all puz iconset icons contain multiple
 
173
                // text strings. we need to verify that.
 
174
                Iconset *is = new Iconset();
 
175
                QVERIFY(is->load("iconsets/emoticons/puz.jisp"));
 
176
                QVERIFY(is->count() > 0);
 
177
                
 
178
                QListIterator<PsiIcon*> it = is->iterator();
 
179
                while (it.hasNext()) {
 
180
                        const QHash<QString, QString> text = it.next()->text();
 
181
                        QVERIFY(text.count() > 1);
 
182
                }
 
183
                
 
184
                delete is;
 
185
        }
 
186
                
 
187
        void testCreateQIcon()
 
188
        {
 
189
                const PsiIcon *chat = IconsetFactory::iconPtr("psi/chat");
 
190
                QVERIFY(chat != 0);
 
191
                
 
192
                QIcon icon = chat->iconSet();
 
193
                QVERIFY(!icon.isNull());
 
194
        }
 
195
};
 
196
 
 
197
QTEST_MAIN(TestIconset)
 
198
#include "testiconset.moc"