Changeset View
Changeset View
Standalone View
Standalone View
autotests/libs/collectioncolorattributetest.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright (c) 2016 Sandro Knauß <knauss@kde.org> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or modify it | ||||
5 | under the terms of the GNU Library General Public License as published by | ||||
6 | the Free Software Foundation; either version 2 of the License, or (at your | ||||
7 | option) any later version. | ||||
8 | | ||||
9 | This library is distributed in the hope that it will be useful, but WITHOUT | ||||
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||||
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public | ||||
12 | License for more details. | ||||
13 | | ||||
14 | You should have received a copy of the GNU Library General Public License | ||||
15 | along with this library; see the file COPYING.LIB. If not, write to the | ||||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||||
17 | 02110-1301, USA. | ||||
18 | */ | ||||
19 | | ||||
20 | #include "collectioncolorattribute.h" | ||||
21 | | ||||
22 | #include <QtCore/QObject> | ||||
23 | | ||||
24 | #include <QTest> | ||||
25 | | ||||
26 | using namespace Akonadi; | ||||
27 | | ||||
28 | class CollectionColorAttributeTest : public QObject | ||||
29 | { | ||||
30 | Q_OBJECT | ||||
31 | private Q_SLOTS: | ||||
32 | void testDeserialize_data() | ||||
33 | { | ||||
34 | QTest::addColumn<QByteArray>("input"); | ||||
35 | QTest::addColumn<QColor>("color"); | ||||
36 | QTest::addColumn<QByteArray>("output"); | ||||
37 | | ||||
38 | QTest::newRow("empty") << QByteArray("") << QColor() << QByteArray(""); | ||||
39 | QTest::newRow("white") << QByteArray("white") << QColor("#ffffff") << QByteArray("#ffffffff"); | ||||
40 | QTest::newRow("#123") << QByteArray("#123") << QColor("#112233") << QByteArray("#ff112233"); | ||||
41 | QTest::newRow("#123456") << QByteArray("#123456") << QColor("#123456") << QByteArray("#ff123456"); | ||||
42 | QTest::newRow("#1234567") << QByteArray("#1234567") << QColor() << QByteArray(""); | ||||
43 | QTest::newRow("#12345678") << QByteArray("#12345678") << QColor("#12345678") << QByteArray("#12345678"); | ||||
44 | QTest::newRow("#ff345678") << QByteArray("#ff123456") << QColor("#123456") << QByteArray("#ff123456"); | ||||
45 | } | ||||
46 | | ||||
47 | void testDeserialize() | ||||
48 | { | ||||
49 | QFETCH(QByteArray, input); | ||||
50 | QFETCH(QColor, color); | ||||
51 | QFETCH(QByteArray, output); | ||||
52 | | ||||
53 | CollectionColorAttribute *attr = new CollectionColorAttribute(); | ||||
54 | attr->deserialize(input); | ||||
55 | QCOMPARE(attr->color(), color); | ||||
56 | | ||||
57 | QCOMPARE(attr->serialized(), output); | ||||
58 | | ||||
59 | CollectionColorAttribute *copy = attr->clone(); | ||||
60 | QCOMPARE(copy->serialized(), output); | ||||
61 | | ||||
62 | delete attr; | ||||
63 | delete copy; | ||||
64 | } | ||||
65 | }; | ||||
66 | | ||||
67 | QTEST_MAIN(CollectionColorAttributeTest) | ||||
68 | | ||||
69 | #include "collectioncolorattributetest.moc" | ||||
70 | |