summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/painting/qcolor/tst_qcolor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/gui/painting/qcolor/tst_qcolor.cpp')
-rw-r--r--tests/auto/gui/painting/qcolor/tst_qcolor.cpp203
1 files changed, 105 insertions, 98 deletions
diff --git a/tests/auto/gui/painting/qcolor/tst_qcolor.cpp b/tests/auto/gui/painting/qcolor/tst_qcolor.cpp
index a5a2983ce7..f592db5544 100644
--- a/tests/auto/gui/painting/qcolor/tst_qcolor.cpp
+++ b/tests/auto/gui/painting/qcolor/tst_qcolor.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -38,6 +13,12 @@
#include <private/qdrawingprimitive_sse2_p.h>
#include <qrgba64.h>
+#if QT_DEPRECATED_SINCE(6, 6)
+# define DEPRECATED_IN_6_6(...) QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED __VA_ARGS__ QT_WARNING_POP
+#else
+# define DEPRECATED_IN_6_6(...)
+#endif
+
class tst_QColor : public QObject
{
Q_OBJECT
@@ -54,8 +35,8 @@ private slots:
void name();
void namehex_data();
void namehex();
- void setNamedColor_data();
- void setNamedColor();
+ void fromString_data();
+ void fromString();
void constructNamedColorWithSpace();
@@ -92,7 +73,7 @@ private slots:
void toCmykNonDestructive();
void toHsl_data();
- void toHsl();;
+ void toHsl();
void toHslNonDestructive();
void convertTo();
@@ -139,11 +120,11 @@ void tst_QColor::getSetCheck()
// void QColor::setAlphaF(float)
obj1.setAlphaF(0.0);
QCOMPARE(obj1.alphaF(), 0.0f); // range<0.0, 1.0>
- obj1.setAlphaF(-0.2);
+ obj1.setAlphaF(-0.2f);
QCOMPARE(obj1.alphaF(), 0.0f); // range<0.0, 1.0>
- obj1.setAlphaF(1.0);
+ obj1.setAlphaF(1.0f);
QCOMPARE(obj1.alphaF(), 1.0f); // range<0.0, 1.0>
- obj1.setAlphaF(1.1);
+ obj1.setAlphaF(1.1f);
QCOMPARE(obj1.alphaF(), 1.0f); // range<0.0, 1.0>
// int QColor::red()
@@ -243,13 +224,13 @@ void tst_QColor::isValid_data()
QTest::newRow("defaultConstructor") << QColor() << false;
QTest::newRow("rgbConstructor-valid") << QColor(2,5,7) << true;
QTest::newRow("rgbConstructor-invalid") << QColor(2,5,999) << false;
- QTest::newRow("nameQStringConstructor-valid") << QColor(QString("#ffffff")) << true;
- QTest::newRow("nameQStringConstructor-invalid") << QColor(QString("#ffffgg")) << false;
- QTest::newRow("nameQStringConstructor-empty") << QColor(QString("")) << false;
- QTest::newRow("nameQStringConstructor-named") << QColor(QString("red")) << true;
- QTest::newRow("nameCharConstructor-valid") << QColor("#ffffff") << true;
- QTest::newRow("nameCharConstructor-invalid") << QColor("#ffffgg") << false;
- QTest::newRow("nameCharConstructor-invalid-2") << QColor("#fffffg") << false;
+ QTest::newRow("nameQStringConstructor-valid") << QColor::fromString("#ffffff") << true;
+ QTest::newRow("nameQStringConstructor-invalid") << QColor::fromString("#ffffgg") << false;
+ QTest::newRow("nameQStringConstructor-empty") << QColor::fromString("") << false;
+ QTest::newRow("nameQStringConstructor-named") << QColor::fromString("red") << true;
+ QTest::newRow("nameCharConstructor-valid") << QColor::fromString("#ffffff") << true;
+ QTest::newRow("nameCharConstructor-invalid") << QColor::fromString("#ffffgg") << false;
+ QTest::newRow("nameCharConstructor-invalid-2") << QColor::fromString("#fffffg") << false;
}
void tst_QColor::isValid()
@@ -335,7 +316,10 @@ void tst_QColor::namehex()
{
QFETCH(QString, hexcolor);
QFETCH(QColor, color);
+ DEPRECATED_IN_6_6(
QCOMPARE(QColor(hexcolor), color);
+ )
+ QCOMPARE(QColor::fromString(hexcolor), color);
}
void tst_QColor::globalColors_data()
@@ -721,25 +705,36 @@ static const int rgbTblSize = sizeof(rgbTbl) / sizeof(RGBData);
#undef rgb
-void tst_QColor::setNamedColor_data()
+void tst_QColor::fromString_data()
{
+#if QT_DEPRECATED_SINCE(6, 6)
QTest::addColumn<QColor>("byCtor");
QTest::addColumn<QColor>("bySetNamedColor");
+#endif
+ QTest::addColumn<QColor>("byFromString");
QTest::addColumn<QColor>("expected");
for (const auto e : rgbTbl) {
QColor expected;
expected.setRgba(e.value);
-#define ROW(expr) \
- do { \
- QColor bySetNamedColor; \
- bySetNamedColor.setNamedColor(expr); \
- auto byCtor = QColor(expr); \
- QTest::addRow("%s: %s", e.name, #expr) \
- << byCtor << bySetNamedColor << expected; \
- } while (0) \
- /*end*/
+#define ROW(expr) row(expr, #expr)
+ auto row = [&] (auto expr, const char *exprS) {
+ QT_WARNING_PUSH
+ #if QT_DEPRECATED_SINCE(6, 6)
+ QT_WARNING_DISABLE_DEPRECATED
+ QColor bySetNamedColor;
+ bySetNamedColor.setNamedColor(expr);
+ auto byCtor = QColor(expr);
+ #endif
+ QTest::addRow("%s: %s", e.name, exprS)
+ #if QT_DEPRECATED_SINCE(6, 6)
+ << byCtor << bySetNamedColor
+ #endif
+ << QColor::fromString(expr)
+ << expected;
+ QT_WARNING_POP
+ };
const auto l1 = QLatin1String(e.name);
const auto l1UpperBA = QByteArray(e.name).toUpper();
@@ -766,29 +761,42 @@ void tst_QColor::setNamedColor_data()
}
}
-void tst_QColor::setNamedColor()
+void tst_QColor::fromString()
{
+#if QT_DEPRECATED_SINCE(6, 6)
QFETCH(QColor, byCtor);
QFETCH(QColor, bySetNamedColor);
+#endif
+ QFETCH(QColor, byFromString);
QFETCH(QColor, expected);
+#if QT_DEPRECATED_SINCE(6, 6)
QCOMPARE(byCtor, expected);
QCOMPARE(bySetNamedColor, expected);
+#endif
+ QCOMPARE(byFromString, expected);
}
void tst_QColor::constructNamedColorWithSpace()
{
+ DEPRECATED_IN_6_6(
QColor whiteSmoke("white smoke");
QCOMPARE(whiteSmoke, QColor(245, 245, 245));
+ )
+ QCOMPARE(QColor::fromString("white smoke"), QColorConstants::Svg::whitesmoke);
}
void tst_QColor::colorNames()
{
- QStringList all = QColor::colorNames();
+ const QStringList all = QColor::colorNames();
QCOMPARE(all.size(), rgbTblSize);
for (int i = 0; i < all.size(); ++i)
QCOMPARE(all.at(i), QLatin1String(rgbTbl[i].name));
+ for (const QString &name : all)
+ QVERIFY(QColor::isValidColorName(name));
+ for (const auto &e : rgbTbl)
+ QVERIFY(QColor::isValidColorName(e.name));
}
void tst_QColor::spec()
@@ -1421,58 +1429,58 @@ void tst_QColor::toRgb_data()
QTest::addColumn<QColor>("hslColor");
QTest::newRow("black")
- << QColor::fromRgbF(0.0, 0.0, 0.0)
- << QColor::fromHsvF(-1.0, 0.0, 0.0)
- << QColor::fromCmykF(0.0, 0.0, 0.0, 1.0)
- << QColor::fromHslF(-1.0, 0.0, 0.0);
+ << QColor::fromRgbF(0.0f, 0.0f, 0.0f)
+ << QColor::fromHsvF(-1.0f, 0.0f, 0.0f)
+ << QColor::fromCmykF(0.0f, 0.0f, 0.0f, 1.0f)
+ << QColor::fromHslF(-1.0f, 0.0f, 0.0f);
QTest::newRow("white")
- << QColor::fromRgbF(1.0, 1.0, 1.0)
- << QColor::fromHsvF(-1.0, 0.0, 1.0)
- << QColor::fromCmykF(0.0, 0.0, 0.0, 0.0)
- << QColor::fromHslF(-1.0, 0.0, 1.0);
+ << QColor::fromRgbF(1.0f, 1.0f, 1.0f)
+ << QColor::fromHsvF(-1.0f, 0.0f, 1.0f)
+ << QColor::fromCmykF(0.0f, 0.0f, 0.0f, 0.0f)
+ << QColor::fromHslF(-1.0f, 0.0f, 1.0f);
QTest::newRow("red")
- << QColor::fromRgbF(1.0, 0.0, 0.0)
- << QColor::fromHsvF(0.0, 1.0, 1.0)
- << QColor::fromCmykF(0.0, 1.0, 1.0, 0.0)
- << QColor::fromHslF(0.0, 1.0, 0.5, 1.0);
+ << QColor::fromRgbF(1.0f, 0.0f, 0.0f)
+ << QColor::fromHsvF(0.0f, 1.0f, 1.0f)
+ << QColor::fromCmykF(0.0f, 1.0f, 1.0f, 0.0f)
+ << QColor::fromHslF(0.0f, 1.0f, 0.5f, 1.0f);
QTest::newRow("green")
- << QColor::fromRgbF(0.0, 1.0, 0.0)
- << QColor::fromHsvF(0.33333, 1.0, 1.0)
- << QColor::fromCmykF(1.0, 0.0, 1.0, 0.0)
- << QColor::fromHslF(0.33333, 1.0, 0.5);
+ << QColor::fromRgbF(0.0f, 1.0f, 0.0f)
+ << QColor::fromHsvF(0.33333f, 1.0f, 1.0f)
+ << QColor::fromCmykF(1.0, 0.0f, 1.0f, 0.0f)
+ << QColor::fromHslF(0.33333f, 1.0f, 0.5f);
QTest::newRow("blue")
- << QColor::fromRgbF(0.0, 0.0, 1.0)
- << QColor::fromHsvF(0.66667, 1.0, 1.0)
- << QColor::fromCmykF(1.0, 1.0, 0.0, 0.0)
- << QColor::fromHslF(0.66667, 1.0, 0.5);
+ << QColor::fromRgbF(0.0f, 0.0f, 1.0f)
+ << QColor::fromHsvF(0.66667f, 1.0f, 1.0f)
+ << QColor::fromCmykF(1.0f, 1.0f, 0.0f, 0.0f)
+ << QColor::fromHslF(0.66667f, 1.0f, 0.5f);
QTest::newRow("cyan")
- << QColor::fromRgbF(0.0, 1.0, 1.0)
- << QColor::fromHsvF(0.5, 1.0, 1.0)
- << QColor::fromCmykF(1.0, 0.0, 0.0, 0.0)
- << QColor::fromHslF(0.5, 1.0, 0.5);
+ << QColor::fromRgbF(0.0f, 1.0f, 1.0f)
+ << QColor::fromHsvF(0.5f, 1.0f, 1.0f)
+ << QColor::fromCmykF(1.0f, 0.0f, 0.0f, 0.0f)
+ << QColor::fromHslF(0.5f, 1.0f, 0.5f);
QTest::newRow("magenta")
- << QColor::fromRgbF(1.0, 0.0, 1.0)
- << QColor::fromHsvF(0.83333, 1.0, 1.0)
- << QColor::fromCmykF(0.0, 1.0, 0.0, 0.0)
- << QColor::fromHslF(0.83333, 1.0, 0.5);
+ << QColor::fromRgbF(1.0f, 0.0f, 1.0f)
+ << QColor::fromHsvF(0.83333f, 1.0f, 1.0f)
+ << QColor::fromCmykF(0.0f, 1.0f, 0.0f, 0.0f)
+ << QColor::fromHslF(0.83333f, 1.0f, 0.5f);
QTest::newRow("yellow")
- << QColor::fromRgbF(1.0, 1.0, 0.0)
- << QColor::fromHsvF(0.16667, 1.0, 1.0)
- << QColor::fromCmykF(0.0, 0.0, 1.0, 0.0)
- << QColor::fromHslF(0.16667, 1.0, 0.5);
+ << QColor::fromRgbF(1.0f, 1.0f, 0.0f)
+ << QColor::fromHsvF(0.16667f, 1.0f, 1.0f)
+ << QColor::fromCmykF(0.0f, 0.0f, 1.0f, 0.0f)
+ << QColor::fromHslF(0.16667f, 1.0f, 0.5f);
QTest::newRow("gray")
- << QColor::fromRgbF(0.6431375, 0.6431375, 0.6431375)
- << QColor::fromHsvF(-1.0, 0.0, 0.6431375)
- << QColor::fromCmykF(0.0, 0.0, 0.0, 0.356863)
- << QColor::fromHslF(-1.0, 0.0, 0.6431375);
+ << QColor::fromRgbF(0.6431375f, 0.6431375f, 0.6431375f)
+ << QColor::fromHsvF(-1.0f, 0.0f, 0.6431375f)
+ << QColor::fromCmykF(0.0f, 0.0f, 0.0f, 0.356863f)
+ << QColor::fromHslF(-1.0f, 0.0f, 0.6431375f);
// ### add colors using the 0-255 functions
}
@@ -1503,7 +1511,7 @@ void tst_QColor::toHsv_data()
<< QColor::fromHsv(300, 255, 255)
<< QColor(255, 0, 255)
<< QColor::fromCmyk(0, 255, 0, 0)
- << QColor::fromHslF(300./360., 1., 0.5, 1.0);
+ << QColor::fromHslF(300.f/360.f, 1.f, 0.5f, 1.0f);
QTest::newRow("data1")
<< QColor::fromHsvF(1., 1., 1., 1.)
@@ -1514,7 +1522,7 @@ void tst_QColor::toHsv_data()
void tst_QColor::toRgbNonDestructive()
{
- QColor aColor = QColor::fromRgbF(0.11, 0.22, 0.33, 0.44);
+ QColor aColor = QColor::fromRgbF(0.11f, 0.22f, 0.33f, 0.44f);
QCOMPARE(aColor, aColor.toRgb());
}
@@ -1534,7 +1542,7 @@ void tst_QColor::toHsv()
void tst_QColor::toHsvNonDestructive()
{
- QColor aColor = QColor::fromHsvF(0.11, 0.22, 0.33, 0.44);
+ QColor aColor = QColor::fromHsvF(0.11f, 0.22f, 0.33f, 0.44f);
QCOMPARE(aColor, aColor.toHsv());
}
@@ -1546,7 +1554,7 @@ void tst_QColor::toCmyk_data()
QTest::addColumn<QColor>("hslColor");
QTest::newRow("data0")
- << QColor::fromCmykF(1.0, 0.0, 0.0, 0.0)
+ << QColor::fromCmykF(1.0f, 0.0f, 0.0f, 0.0f)
<< QColor(0, 255, 255)
<< QColor::fromHsv(180, 255, 255)
<< QColor::fromHslF(180./360., 1., 0.5, 1.0);
@@ -1574,7 +1582,7 @@ void tst_QColor::toCmyk()
void tst_QColor::toCmykNonDestructive()
{
- QColor aColor = QColor::fromCmykF(0.11, 0.22, 0.33, 0.44);
+ QColor aColor = QColor::fromCmykF(0.11f, 0.22f, 0.33f, 0.44f);
QCOMPARE(aColor, aColor.toCmyk());
}
@@ -1587,13 +1595,13 @@ void tst_QColor::toHsl_data()
QTest::newRow("data0")
- << QColor::fromHslF(300./360., 1., 0.5, 1.0)
+ << QColor::fromHslF(300.f/360.f, 1., 0.5f, 1.0)
<< QColor::fromHsv(300, 255, 255)
<< QColor(255, 0, 255)
<< QColor::fromCmyk(0, 255, 0, 0);
QTest::newRow("data1")
- << QColor::fromHslF(1., 1., 0.5, 1.0)
+ << QColor::fromHslF(1., 1., 0.5f, 1.0)
<< QColor::fromHsvF(1., 1., 1., 1.)
<< QColor(255, 0, 0, 255)
<< QColor::fromCmykF(0., 1., 1., 0.);
@@ -1618,7 +1626,7 @@ void tst_QColor::toHsl()
void tst_QColor::toHslNonDestructive()
{
- QColor aColor = QColor::fromHslF(0.11, 0.22, 0.33, 0.44);
+ QColor aColor = QColor::fromHslF(0.11f, 0.22f, 0.33f, 0.44f);
QCOMPARE(aColor, aColor.toHsl());
}
@@ -1861,7 +1869,7 @@ void tst_QColor::qcolorprofile()
{
QFETCH(float, gammaC);
QFETCH(int, tolerance);
- QColorTrcLut *cp = QColorTrcLut::fromGamma(gammaC);
+ std::shared_ptr cp = QColorTrcLut::fromGamma(gammaC);
// Test we are accurate for most values after converting through gamma-correction.
int error = 0;
@@ -1872,7 +1880,6 @@ void tst_QColor::qcolorprofile()
error += qAbs(qRed(cin) - qRed(cout));
}
QVERIFY(error <= tolerance);
- delete cp;
}
QTEST_MAIN(tst_QColor)