Commit a8d83108 authored by Cyrille Berger's avatar Cyrille Berger

add a test for KoColor serialization/unserialization

svn path=/trunk/koffice/; revision=743987
parent 5200997a
/*
* Copyright (c) 2005 Boudewijn Rempt <boud@valdyas.org>
* Copyright (C) 2007 Thomas Zander <zander@kde.org>
* Copyright (C) 2007 Cyrille Berger <cberger@cberger.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -290,6 +291,10 @@ KoColor KoColor::fromXML(const QDomElement& elt, QString bitDepthId, QHash<QStri
{
profileName = aliases.value(profileName);
}
if( not KoColorSpaceRegistry::instance()->profileByName( profileName))
{
profileName = "";
}
}
QString csId = KoColorSpaceRegistry::instance()->colorSpaceId(modelId, bitDepthId);
if(csId == "")
......
......@@ -54,6 +54,15 @@ kde4_add_unit_test(TestColorConversionSystem TESTNAME libs-pigment-TestColorConv
target_link_libraries(TestColorConversionSystem ${KDE4_KDECORE_LIBS} pigmentcms ${QT_QTTEST_LIBRARY})
########### next target ###############
set(TestKoColor_test_SRCS TestKoColor.cpp )
kde4_add_unit_test(TestKoColor TESTNAME libs-pigment-TestKoColor ${TestKoColor_test_SRCS})
target_link_libraries(TestKoColor ${KDE4_KDECORE_LIBS} pigmentcms ${QT_QTTEST_LIBRARY})
########### next target ###############
set(TestKoIntegerMaths_test_SRCS TestKoIntegerMaths.cpp )
......
/*
* Copyright (C) 2007 Cyrille Berger <cberger@cberger.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "TestKoColor.h"
#include <qtest_kde.h>
#include <QDomElement>
#include "KoColorModelStandardIds.h"
#include "KoColor.h"
#include "KoColorSpace.h"
#include "KoColorSpaceRegistry.h"
bool nearEqualValue(int a, int b)
{
return qAbs(a -b) <= 1;
}
void TestKoColor::testForModel(QString model)
{
QColor qc(200,125,100);
QList<KoID> depthIDs = KoColorSpaceRegistry::instance()->colorDepthList(model, KoColorSpaceRegistry::AllColorSpaces);
foreach( KoID depthId, depthIDs)
{
const KoColorSpace* cs = KoColorSpaceRegistry::instance()->colorSpace( KoColorSpaceRegistry::instance()->colorSpaceId( model, depthId.id() ) , "");
KoColor kc(cs);
kc.fromQColor( qc );
QDomDocument doc;
QDomElement elt = doc.createElement("color");
kc.toXML(doc, elt);
doc.appendChild(elt);
KoColor kcu = KoColor::fromXML(elt.firstChildElement(), depthId.id(), QHash<QString,QString>());
QVERIFY2(*(kc.colorSpace()) == *(kcu.colorSpace()), QString("Not identical color space colorModelId = %1 depthId = %2").arg(model).arg(depthId.id()).latin1());
QColor qc2 = kc.toQColor();
QColor qcu = kcu.toQColor();
QVERIFY2( nearEqualValue(qcu.red(), qc2.red()), QString("Unserialization failed colorModelId = %1 depthId = %2 red = %3 red = %4").arg(model).arg(depthId.id()).arg(qcu.red()).arg(qc2.red()).latin1());
QVERIFY2( nearEqualValue(qcu.green(), qc2.green()), QString("Unserialization failed colorModelId = %1 depthId = %2 green = %3 green = %4").arg(model).arg(depthId.id()).arg(qcu.green()).arg(qc2.green()).latin1());
QVERIFY2( nearEqualValue(qcu.blue(), qc2.blue()), QString("Unserialization failed colorModelId = %1 depthId = %2 blue = %3 blue = %4").arg(model).arg(depthId.id()).arg(qcu.blue()).arg(qc2.blue()).latin1());
}
}
void TestKoColor::testSerialization()
{
testForModel(RGBAColorModelID.id());
testForModel(XYZAColorModelID.id());
testForModel(LABAColorModelID.id());
testForModel(CMYKAColorModelID.id());
testForModel(GrayAColorModelID.id());
testForModel(YCbCrAColorModelID.id());
}
QTEST_KDEMAIN(TestKoColor, NoGUI)
#include "TestKoColor.moc"
/*
* Copyright (C) 2007 Cyrille Berger <cberger@cberger.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef _TEST_KO_COLOR_H_
#define _TEST_KO_COLOR_H_
#include <QtTest/QtTest>
class TestKoColor : public QObject
{
Q_OBJECT
private:
void testForModel(QString model);
private slots:
void testSerialization();
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment