File indexing completed on 2024-07-21 04:19:54

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 "rgbcolorspacefactory.h"
0007 
0008 #include "chromahuediagram.h"
0009 #include "colorwheel.h"
0010 #include "rgbcolorspace.h"
0011 #include "settranslation.h"
0012 #include <qcoreapplication.h>
0013 #include <qdebug.h>
0014 #include <qglobal.h>
0015 #include <qlocale.h>
0016 #include <qobject.h>
0017 #include <qsharedpointer.h>
0018 #include <qstringliteral.h>
0019 #include <qtest.h>
0020 #include <qtestcase.h>
0021 
0022 #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
0023 #include <qcontainerfwd.h>
0024 #include <qlist.h>
0025 #include <qtmetamacros.h>
0026 #else
0027 #include <qobjectdefs.h>
0028 #include <qstring.h>
0029 #include <qstringlist.h>
0030 #endif
0031 
0032 static void snippet01()
0033 {
0034     //! [Create]
0035     QSharedPointer<PerceptualColor::RgbColorSpace> myColorSpace =
0036         // Create the color space object with the factory class.
0037         // This call might be slow.
0038         PerceptualColor::RgbColorSpaceFactory::createSrgb();
0039 
0040     // These calls are fast:
0041 
0042     PerceptualColor::ChromaHueDiagram *myDiagram =
0043         // Create a widget with the color space:
0044         new PerceptualColor::ChromaHueDiagram(myColorSpace);
0045 
0046     PerceptualColor::ColorWheel *myWheel =
0047         // Create another widget with the very same color space:
0048         new PerceptualColor::ColorWheel(myColorSpace);
0049     //! [Create]
0050 
0051     delete myDiagram;
0052     delete myWheel;
0053 }
0054 
0055 namespace PerceptualColor
0056 {
0057 class TestRgbColorSpaceFactory : public QObject
0058 {
0059     Q_OBJECT
0060 
0061 public:
0062     explicit TestRgbColorSpaceFactory(QObject *parent = nullptr)
0063         : QObject(parent)
0064     {
0065     }
0066 
0067 private Q_SLOTS:
0068     void initTestCase()
0069     {
0070         // Called before the first test function is executed
0071     }
0072 
0073     void cleanupTestCase()
0074     {
0075         // Called after the last test function was executed
0076     }
0077 
0078     void init()
0079     {
0080         // Called before each test function is executed
0081     }
0082 
0083     void cleanup()
0084     {
0085         // Called after every test function
0086     }
0087 
0088     void testCreate()
0089     {
0090         setTranslation(QCoreApplication::instance(), //
0091                        QLocale(QLocale::English).uiLanguages());
0092         QSharedPointer<PerceptualColor::RgbColorSpace> temp = //
0093             RgbColorSpaceFactory::createSrgb();
0094         QCOMPARE(temp.isNull(), false); // This is no nullptr!
0095         // Make a random call, just to be sure that a method call won’t crash:
0096         Q_UNUSED(temp->profileName());
0097         // Make sure the returned value is actually the sRGB gamut.
0098         QCOMPARE(temp->profileName(), QStringLiteral("sRGB color space"));
0099     }
0100 
0101     void testSnipped01()
0102     {
0103         snippet01();
0104     }
0105 
0106     void testColorProfileDirectories()
0107     {
0108         // colorProfileDirectories() must not throw an exception:
0109         const QStringList temp = //
0110             RgbColorSpaceFactory::colorProfileDirectories();
0111         Q_UNUSED(temp)
0112     }
0113 
0114     void testColorProfileDirectoriesQInfo()
0115     {
0116         qInfo() << RgbColorSpaceFactory::colorProfileDirectories();
0117     }
0118 };
0119 
0120 } // namespace PerceptualColor
0121 
0122 QTEST_MAIN(PerceptualColor::TestRgbColorSpaceFactory)
0123 
0124 // The following “include” is necessary because we do not use a header file:
0125 #include "testrgbcolorspacefactory.moc"