Warning, file /libraries/perceptualcolor/autotests/testcielchd50values.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // SPDX-FileCopyrightText: Lukas Sommer <sommerluk@gmail.com>
0002 // SPDX-License-Identifier: BSD-2-Clause OR MIT
0003 
0004 // First included header is the public header of the class we are testing;
0005 // this forces the header to be self-contained.
0006 #include "cielchd50values.h"
0007 
0008 #include "helperposixmath.h"
0009 #include "lchdouble.h"
0010 #include "rgbcolorspace.h"
0011 #include <qglobal.h>
0012 #include <qobject.h>
0013 #include <qsharedpointer.h>
0014 #include <qtest.h>
0015 #include <qtestcase.h>
0016 
0017 #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
0018 #include <qtmetamacros.h>
0019 #else
0020 #include <qobjectdefs.h>
0021 #include <qstring.h>
0022 #endif
0023 
0024 namespace PerceptualColor
0025 {
0026 class TestCielchD50Values : public QObject
0027 {
0028     Q_OBJECT
0029 
0030 public:
0031     explicit TestCielchD50Values(QObject *parent = nullptr)
0032         : QObject(parent)
0033     {
0034     }
0035 
0036 private Q_SLOTS:
0037 
0038     void initTestCase()
0039     {
0040         // Called before the first test function is executed
0041     }
0042 
0043     void cleanupTestCase()
0044     {
0045         // Called after the last test function was executed
0046     }
0047 
0048     void init()
0049     {
0050         // Called before each test function is executed
0051     }
0052     void cleanup()
0053     {
0054         // Called after every test function
0055     }
0056 
0057     void testNeutralValues()
0058     {
0059         // Is the value as documented?
0060         QCOMPARE(static_cast<qreal>(PerceptualColor::CielchD50Values::neutralChroma), 0);
0061         // Is the value as documented?
0062         QCOMPARE(static_cast<qreal>(PerceptualColor::CielchD50Values::neutralHue), 0);
0063         // Is the value as documented?
0064         QCOMPARE(static_cast<qreal>(PerceptualColor::CielchD50Values::neutralLightness), 50);
0065     }
0066 
0067     void testCielchD50Values()
0068     {
0069         auto temp = RgbColorSpace::createSrgb();
0070         LchDouble color;
0071         qreal presicion = 0.1;
0072         qreal hue = 0;
0073         bool inGamutValueFound = false;
0074 
0075         // Test if versatile is small enough
0076         qreal precisionVersatileSrgbChroma = //
0077             presicion / 360 * 2 * pi * PerceptualColor::CielchD50Values::srgbVersatileChroma;
0078         color.c = PerceptualColor::CielchD50Values::srgbVersatileChroma;
0079         color.l = 50;
0080         hue = 0;
0081         while (hue <= 360) {
0082             color.h = hue;
0083             QVERIFY2(temp->isCielchD50InGamut(color), "Test if versatile is small enough");
0084             hue += precisionVersatileSrgbChroma;
0085         }
0086 
0087         // Test if versatile is as big as possible
0088         color.c = PerceptualColor::CielchD50Values::srgbVersatileChroma + 1;
0089         color.l = 50;
0090         inGamutValueFound = true;
0091         hue = 0;
0092         while (hue <= 360) {
0093             color.h = hue;
0094             if (!temp->isCielchD50InGamut(color)) {
0095                 inGamutValueFound = false;
0096                 break;
0097             }
0098             hue += precisionVersatileSrgbChroma;
0099         }
0100         QVERIFY2(!inGamutValueFound, "Test if versatile is as big as possible");
0101     }
0102 
0103     void testNeutralGray()
0104     {
0105         // Test that the unified initialization is done in the correct order.
0106         QCOMPARE(CielchD50Values::neutralGray.l,
0107                  50 // Should be half the way between light and dark
0108         );
0109         QCOMPARE(CielchD50Values::neutralGray.c,
0110                  0 // Should have no chroma
0111         );
0112         QCOMPARE(CielchD50Values::neutralGray.h,
0113                  0 // Hue does not matter, but by convention should be 0
0114         );
0115     }
0116 };
0117 
0118 } // namespace PerceptualColor
0119 
0120 QTEST_MAIN(PerceptualColor::TestCielchD50Values)
0121 // The following “include” is necessary because we do not use a header file:
0122 #include "testcielchd50values.moc"