File indexing completed on 2024-05-12 04:44:25

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 "interlacingpass.h"
0007 
0008 #include <qglobal.h>
0009 #include <qobject.h>
0010 #include <qsize.h>
0011 #include <qtest.h>
0012 #include <qtestcase.h>
0013 
0014 #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
0015 #include <qtmetamacros.h>
0016 #else
0017 #include <qobjectdefs.h>
0018 #include <qstring.h>
0019 #endif
0020 
0021 namespace PerceptualColor
0022 {
0023 class TestInterlacingPass : public QObject
0024 {
0025     Q_OBJECT
0026 
0027 public:
0028     explicit TestInterlacingPass(QObject *parent = nullptr)
0029         : QObject(parent)
0030     {
0031     }
0032 
0033 private Q_SLOTS:
0034     void initTestCase()
0035     {
0036         // Called before the first test function is executed
0037     }
0038 
0039     void cleanupTestCase()
0040     {
0041         // Called after the last test function was executed
0042     }
0043 
0044     void init()
0045     {
0046         // Called before each test function is executed
0047     }
0048 
0049     void cleanup()
0050     {
0051         // Called after every test function
0052     }
0053 
0054     void testConstructorDestructor()
0055     {
0056         QVERIFY_EXCEPTION_THROWN(InterlacingPass test{2}, int);
0057         QVERIFY_EXCEPTION_THROWN(InterlacingPass test{0}, int);
0058         QVERIFY_EXCEPTION_THROWN(InterlacingPass test{-0}, int);
0059         QVERIFY_EXCEPTION_THROWN(InterlacingPass test{-1}, int);
0060         QVERIFY_EXCEPTION_THROWN(InterlacingPass test{-2}, int);
0061         InterlacingPass testA{3};
0062         InterlacingPass testB{5};
0063         InterlacingPass testC{7};
0064         InterlacingPass testD{9};
0065         InterlacingPass testE{11};
0066     }
0067 
0068     void testMake()
0069     {
0070         InterlacingPass testA = InterlacingPass::make<3>();
0071         InterlacingPass testB = InterlacingPass::make<5>();
0072         InterlacingPass testC = InterlacingPass::make<7>();
0073         InterlacingPass testD = InterlacingPass::make<9>();
0074         InterlacingPass testE = InterlacingPass::make<11>();
0075         Q_UNUSED(testA);
0076         Q_UNUSED(testB);
0077         Q_UNUSED(testC);
0078         Q_UNUSED(testD);
0079         Q_UNUSED(testE);
0080     }
0081 
0082     void testAdam3()
0083     {
0084         InterlacingPass test = InterlacingPass::make<3>();
0085         QCOMPARE(test.countdown, 3);
0086         QCOMPARE(test.rectangleSize.width(), 2);
0087         QCOMPARE(test.rectangleSize.height(), 2);
0088         QCOMPARE(test.columnFrequency, 2);
0089         QCOMPARE(test.columnOffset, 0);
0090         QCOMPARE(test.lineFrequency, 2);
0091         QCOMPARE(test.lineOffset, 0);
0092 
0093         test.switchToNextPass();
0094         QCOMPARE(test.countdown, 2);
0095         QCOMPARE(test.rectangleSize.width(), 1);
0096         QCOMPARE(test.rectangleSize.height(), 2);
0097         QCOMPARE(test.columnFrequency, 2);
0098         QCOMPARE(test.columnOffset, 1);
0099         QCOMPARE(test.lineFrequency, 2);
0100         QCOMPARE(test.lineOffset, 0);
0101 
0102         test.switchToNextPass();
0103         QCOMPARE(test.countdown, 1);
0104         QCOMPARE(test.rectangleSize.width(), 1);
0105         QCOMPARE(test.rectangleSize.height(), 1);
0106         QCOMPARE(test.columnFrequency, 1);
0107         QCOMPARE(test.columnOffset, 0);
0108         QCOMPARE(test.lineFrequency, 2);
0109         QCOMPARE(test.lineOffset, 1);
0110     }
0111 };
0112 
0113 } // namespace PerceptualColor
0114 
0115 QTEST_MAIN(PerceptualColor::TestInterlacingPass)
0116 
0117 // The following “include” is necessary because we do not use a header file:
0118 #include "testinterlacingpass.moc"