File indexing completed on 2024-07-14 08:12: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 "version.h"
0007 
0008 #include <qglobal.h>
0009 #include <qobject.h>
0010 #include <qtest.h>
0011 #include <qtestcase.h>
0012 #include <qversionnumber.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 static void snippet01()
0022 {
0023 //! [Version Macro usage]
0024 // Either with macros:
0025 #if (PERCEPTUALCOLOR_COMPILE_TIME_VERSION >= QT_VERSION_CHECK(1, 2, 3))
0026     // Some code…
0027 #else
0028     // Some different code…
0029 #endif
0030 
0031     // Or with C++ “if constexpr”. Works only if both(!) code paths can
0032     // potentially compile without errors at all versions:
0033     if constexpr (PERCEPTUALCOLOR_COMPILE_TIME_VERSION >= QT_VERSION_CHECK(1, 2, 3)) {
0034         // Some code…
0035     } else {
0036         // Some different code…
0037     }
0038     //! [Version Macro usage]
0039 }
0040 
0041 namespace PerceptualColor
0042 {
0043 class TestVersion : public QObject
0044 {
0045     Q_OBJECT
0046 
0047 public:
0048     explicit TestVersion(QObject *parent = nullptr)
0049         : QObject(parent)
0050     {
0051     }
0052 
0053 private Q_SLOTS:
0054     void initTestCase()
0055     {
0056         // Called before the first test function is executed
0057     }
0058 
0059     void cleanupTestCase()
0060     {
0061         // Called after the last test function was executed
0062     }
0063 
0064     void init()
0065     {
0066         // Called before each test function is executed
0067     }
0068 
0069     void cleanup()
0070     {
0071         // Called after every test function
0072     }
0073 
0074     void testPerceptualColorRunTimeVersion()
0075     {
0076         QVERIFY2(perceptualColorRunTimeVersion() >= QVersionNumber(0, 0, 1), "Verify that the version number is at least 0.0.1.");
0077         QVERIFY2(perceptualColorRunTimeVersion() < QVersionNumber(99, 0, 1), "Verify that the version number is not too big.");
0078     }
0079 
0080     void testSnippet01()
0081     {
0082         snippet01();
0083     }
0084 };
0085 
0086 } // flags
0087 
0088 QTEST_MAIN(PerceptualColor::TestVersion)
0089 
0090 // The following “include” is necessary because we do not use a header file:
0091 #include "testversion.moc"