File indexing completed on 2024-12-22 04:11:22

0001 /* SPDX-FileCopyrightText: 2017 Boudewijn Rempt <boud@valdyas.org>
0002 
0003    SPDX-License-Identifier: LGPL-2.0-or-later
0004 */
0005 #include "TestManagedColor.h"
0006 #include <simpletest.h>
0007 #include <QColor>
0008 #include <QVector>
0009 
0010 #include <KritaVersionWrapper.h>
0011 #include <ManagedColor.h>
0012 
0013 #include <KoColorSpaceRegistry.h>
0014 #include <KoColorProfile.h>
0015 #include <KoColor.h>
0016 
0017 #include <testui.h>
0018 
0019 KISTEST_MAIN(TestManagedColor)
0020 
0021 void TestManagedColor::testOperatorIs()
0022 {
0023     ManagedColor c1("RGBA", "U8", "");
0024     ManagedColor c2("RGBA", "U8", "");
0025     ManagedColor c3("RGBA", "U16", "");
0026 
0027     QVERIFY(c1 == c2);
0028 }
0029 
0030 void TestManagedColor::testSetColorSpace()
0031 {
0032     ManagedColor c("RGBA", "U8", "");
0033     c.setColorSpace("LABA", "U16", "");
0034     QVERIFY(c.colorDepth() == "U16");
0035     QVERIFY(c.colorModel() == "LABA");
0036 }
0037 
0038 void TestManagedColor::testComponentsRoundTrip()
0039 {
0040     ManagedColor c("RGBA", "U8", "");
0041     QVector<float> components = c.components();
0042     QVERIFY(components.size() == 4);
0043     QVERIFY(components[0] == 0);
0044     QVERIFY(components[1] == 0);
0045     QVERIFY(components[2] == 0);
0046     QVERIFY(components[3] == 0);
0047 
0048     components[0] = 0.5;
0049     components[1] = 0.5;
0050     components[2] = 0.5;
0051     components[3] = 0.5;
0052     c.setComponents(components);
0053 
0054     QVERIFY(c.toQString() == "Red 127 Green 127 Blue 127 Alpha 127");
0055 
0056 }
0057 
0058 void TestManagedColor::testXMLRoundTrip()
0059 {
0060     ManagedColor c("RGBA", "U8", "");
0061     QVector<float> components;
0062     components << 0.5 << 0.5 << 0.5 << 0.5;
0063     c.setComponents(components);
0064 
0065     QString xml = c.toXML();
0066     c.fromXML(xml);
0067     components = c.components();
0068     QVERIFY(components.size() == 4);
0069     QVERIFY(c.toQString() == "Red 127 Green 127 Blue 127 Alpha 127");
0070 
0071 
0072 }
0073 
0074 void TestManagedColor::testToQString()
0075 {
0076     ManagedColor c("RGBA", "U8", "");
0077     QVector<float> components;
0078     components << 0.5 << 0.5 << 0.5 << 0.5;
0079     c.setComponents(components);
0080     QVERIFY(c.toQString() == "Red 127 Green 127 Blue 127 Alpha 127");
0081 }