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
|
/*
* Copyright (C) 2008-2014 The Communi Project
*
* This test is free, and not covered by the BSD license. There is no
* restriction applied to their modification, redistribution, using and so on.
* You can study them, modify them, use them in your own program - either
* completely or partially.
*/
#include "irc.h"
#include "ircpalette.h"
#include "irctextformat.h"
#include <QtTest/QtTest>
class tst_IrcPalette : public QObject
{
Q_OBJECT
private slots:
void testDefaults();
void testColorNames();
void testProperties_data();
void testProperties();
};
void tst_IrcPalette::testDefaults()
{
IrcTextFormat format;
QVERIFY(format.palette());
IrcPalette* palette = format.palette();
QVERIFY(!palette->colorNames().isEmpty());
for (int i = Irc::White; i <= Irc::LightGray; ++i)
QVERIFY(!palette->colorName(i).isEmpty());
QCOMPARE(palette->colorName(-1, "fallback"), QString("fallback"));
}
void tst_IrcPalette::testColorNames()
{
IrcTextFormat format;
QVERIFY(format.palette());
IrcPalette* palette = format.palette();
QMap<int, QString> colorNames;
for (int i = -1; i <= 123; ++i) {
colorNames.insert(i, QString::number(i));
palette->setColorName(i, QString::number(i));
QCOMPARE(palette->colorName(i), QString::number(i));
}
QCOMPARE(palette->colorNames(), colorNames);
QMap<int, QString> dummies;
for (int i = 0; i < 100; i += 3)
dummies.insert(i, QString::number(i) + "-dummy");
palette->setColorNames(dummies);
QCOMPARE(palette->colorNames(), dummies);
}
void tst_IrcPalette::testProperties_data()
{
QTest::addColumn<Irc::Color>("color");
QTest::addColumn<QString>("prop");
QTest::newRow("white") << Irc::White << "white";
QTest::newRow("black") << Irc::Black << "black";
QTest::newRow("blue") << Irc::Blue << "blue";
QTest::newRow("green") << Irc::Green << "green";
QTest::newRow("red") << Irc::Red << "red";
QTest::newRow("brown") << Irc::Brown << "brown";
QTest::newRow("purple") << Irc::Purple << "purple";
QTest::newRow("orange") << Irc::Orange << "orange";
QTest::newRow("yellow") << Irc::Yellow << "yellow";
QTest::newRow("lightGreen") << Irc::LightGreen << "lightGreen";
QTest::newRow("cyan") << Irc::Cyan << "cyan";
QTest::newRow("lightCyan") << Irc::LightCyan << "lightCyan";
QTest::newRow("lightBlue") << Irc::LightBlue << "lightBlue";
QTest::newRow("pink") << Irc::Pink << "pink";
QTest::newRow("gray") << Irc::Gray << "gray";
QTest::newRow("lightGray") << Irc::LightGray << "lightGray";
}
void tst_IrcPalette::testProperties()
{
QFETCH(Irc::Color, color);
QFETCH(QString, prop);
IrcTextFormat format;
QVERIFY(format.palette());
IrcPalette* palette = format.palette();
QCOMPARE(palette->property(prop.toUtf8()).toString(), prop.toLower());
QVERIFY(palette->setProperty(prop.toUtf8(), QString("dummy")));
QCOMPARE(palette->colorName(color), QString("dummy"));
QCOMPARE(palette->property(prop.toUtf8()).toString(), QString("dummy"));
palette->setColorName(color, QString("dummier"));
QCOMPARE(palette->colorName(color), QString("dummier"));
QCOMPARE(palette->property(prop.toUtf8()).toString(), QString("dummier"));
}
QTEST_MAIN(tst_IrcPalette)
#include "tst_ircpalette.moc"
|