File indexing completed on 2024-11-10 04:40:09

0001 /*
0002     SPDX-FileCopyrightText: 2016 Sandro Knauß <knauss@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "collectioncolorattribute.h"
0008 
0009 #include <QObject>
0010 
0011 #include <QTest>
0012 
0013 using namespace Akonadi;
0014 
0015 class CollectionColorAttributeTest : public QObject
0016 {
0017     Q_OBJECT
0018 private Q_SLOTS:
0019     void testDeserialize_data()
0020     {
0021         QTest::addColumn<QByteArray>("input");
0022         QTest::addColumn<QColor>("color");
0023         QTest::addColumn<QByteArray>("output");
0024 
0025         QTest::newRow("empty") << QByteArray("") << QColor() << QByteArray("");
0026         QTest::newRow("white") << QByteArray("white") << QColor("#ffffff") << QByteArray("#ffffffff");
0027         QTest::newRow("#123") << QByteArray("#123") << QColor("#112233") << QByteArray("#ff112233");
0028         QTest::newRow("#123456") << QByteArray("#123456") << QColor("#123456") << QByteArray("#ff123456");
0029         QTest::newRow("#1234567") << QByteArray("#1234567") << QColor() << QByteArray("");
0030         QTest::newRow("#12345678") << QByteArray("#12345678") << QColor("#12345678") << QByteArray("#12345678");
0031         QTest::newRow("#ff345678") << QByteArray("#ff123456") << QColor("#123456") << QByteArray("#ff123456");
0032     }
0033 
0034     void testDeserialize()
0035     {
0036         QFETCH(QByteArray, input);
0037         QFETCH(QColor, color);
0038         QFETCH(QByteArray, output);
0039 
0040         auto attr = new CollectionColorAttribute();
0041         attr->deserialize(input);
0042         QCOMPARE(attr->color(), color);
0043 
0044         QCOMPARE(attr->serialized(), output);
0045 
0046         CollectionColorAttribute *copy = attr->clone();
0047         QCOMPARE(copy->serialized(), output);
0048 
0049         delete attr;
0050         delete copy;
0051     }
0052 };
0053 
0054 QTEST_MAIN(CollectionColorAttributeTest)
0055 
0056 #include "collectioncolorattributetest.moc"