File indexing completed on 2025-02-09 05:31:21
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 "helperconstants.h" 0007 0008 #include <qglobal.h> 0009 #include <qobject.h> 0010 #include <qscopedpointer.h> 0011 #include <qstring.h> 0012 #include <qstringbuilder.h> 0013 #include <qstringliteral.h> 0014 #include <qtest.h> 0015 #include <qtestcase.h> 0016 #include <qtextdocument.h> 0017 #include <qwidget.h> 0018 0019 #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) 0020 #include <qtmetamacros.h> 0021 #else 0022 #include <qobjectdefs.h> 0023 #endif 0024 0025 static bool snippet01() 0026 { 0027 const QString myRichText = QStringLiteral(u"abc"); 0028 const QString myPlainText = QStringLiteral(u"abc"); 0029 QScopedPointer<QWidget> myWidget1(new QWidget()); 0030 QScopedPointer<QWidget> myWidget2(new QWidget()); 0031 //! [richTextMarkerExample] 0032 myWidget1->setToolTip( // Make sure rich text is treated as such: 0033 PerceptualColor::richTextMarker + myRichText); 0034 0035 myWidget2->setToolTip( // Make sure plain text is treated as such: 0036 PerceptualColor::richTextMarker + myPlainText.toHtmlEscaped()); 0037 //! [richTextMarkerExample] 0038 return Qt::mightBeRichText(myWidget1->toolTip()) // 0039 && Qt::mightBeRichText(myWidget2->toolTip()); 0040 } 0041 0042 namespace PerceptualColor 0043 { 0044 0045 class TestHelperConstants : public QObject 0046 { 0047 Q_OBJECT 0048 0049 public: 0050 explicit TestHelperConstants(QObject *parent = nullptr) 0051 : QObject(parent) 0052 { 0053 } 0054 0055 private Q_SLOTS: 0056 0057 void initTestCase() 0058 { 0059 // Called before the first test function is executed 0060 } 0061 0062 void cleanupTestCase() 0063 { 0064 // Called after the last test function was executed 0065 } 0066 0067 void init() 0068 { 0069 // Called before each test function is executed 0070 } 0071 void cleanup() 0072 { 0073 // Called after every test function 0074 } 0075 0076 void testCielabGamutPrecision() 0077 { 0078 // The value is somewhat arbitrary. 0079 // Make sure that at least it is not too high. 0080 QVERIFY2(PerceptualColor::gamutPrecisionCielab < 1, // 0081 "Verify that gamut precision value is not too high"); 0082 } 0083 0084 void testOklabPrecision() 0085 { 0086 // The value is somewhat arbitrary. 0087 // Make sure that at least it is not too high. 0088 QVERIFY2(PerceptualColor::gamutPrecisionCielab < 0.01, // 0089 "Verify that gamut precision value is not too high"); 0090 } 0091 0092 void testSteps() 0093 { 0094 QVERIFY2(pageStepChroma > singleStepChroma, // 0095 "Chroma page step is bigger than single step."); 0096 QVERIFY2(singleStepChroma > 0, // 0097 "Chroma single step is positive."); 0098 QVERIFY2(pageStepHue > singleStepHue, // 0099 "Hue page step is bigger than single step."); 0100 QVERIFY2(singleStepHue > 0, // 0101 "Hue single step is positive."); 0102 } 0103 0104 void testRichTextMarkerIsRecognized() 0105 { 0106 const QString myMarker = richTextMarker; 0107 QVERIFY(myMarker.count() > 0); 0108 QVERIFY(Qt::mightBeRichText(myMarker)); 0109 0110 const QString myText = QStringLiteral(u"abc"); 0111 QVERIFY(!Qt::mightBeRichText(myText)); // Assertion 0112 QVERIFY(Qt::mightBeRichText(myMarker + myText)); 0113 } 0114 0115 void testRichTextMarkerSnippet() 0116 { 0117 QVERIFY(snippet01()); 0118 } 0119 0120 void testRichTextMarkerIsInvisible() 0121 { 0122 QTextDocument myDocument; 0123 const QString myRichText = QStringLiteral(u"This <em>is</em> a test."); 0124 myDocument.setHtml(myRichText); 0125 QCOMPARE(myDocument.toRawText(), // Assertion 0126 QStringLiteral(u"This is a test.")); 0127 // Now, test if the rich text marker is actually invisible: 0128 myDocument.setHtml(richTextMarker + myRichText); 0129 QCOMPARE(myDocument.toRawText(), QStringLiteral(u"This is a test.")); 0130 } 0131 }; 0132 0133 } // namespace PerceptualColor 0134 0135 QTEST_MAIN(PerceptualColor::TestHelperConstants) 0136 // The following “include” is necessary because we do not use a header file: 0137 #include "testhelperconstants.moc"