diff options
Diffstat (limited to 'tests/auto/gui/painting/qcolor/tst_qcolor.cpp')
-rw-r--r-- | tests/auto/gui/painting/qcolor/tst_qcolor.cpp | 362 |
1 files changed, 183 insertions, 179 deletions
diff --git a/tests/auto/gui/painting/qcolor/tst_qcolor.cpp b/tests/auto/gui/painting/qcolor/tst_qcolor.cpp index 5c558ea1b3..f592db5544 100644 --- a/tests/auto/gui/painting/qcolor/tst_qcolor.cpp +++ b/tests/auto/gui/painting/qcolor/tst_qcolor.cpp @@ -1,33 +1,9 @@ -/**************************************************************************** -** -** Copyright (C) 2016 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$ -** -****************************************************************************/ - - -#include <QtTest/QtTest> +// Copyright (C) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + + +#include <QTest> +#include <QFloat16> #include <limits.h> @@ -37,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 @@ -53,8 +35,8 @@ private slots: void name(); void namehex_data(); void namehex(); - void setNamedColor_data(); - void setNamedColor(); + void fromString_data(); + void fromString(); void constructNamedColorWithSpace(); @@ -64,10 +46,8 @@ private slots: void globalColors_data(); void globalColors(); -#if defined(Q_COMPILER_CONSTEXPR) & defined(Q_COMPILER_UNIFORM_INIT) void colorConstants_data(); void colorConstants(); -#endif void setRed(); void setGreen(); @@ -93,7 +73,7 @@ private slots: void toCmykNonDestructive(); void toHsl_data(); - void toHsl();; + void toHsl(); void toHslNonDestructive(); void convertTo(); @@ -136,16 +116,16 @@ void tst_QColor::getSetCheck() obj1.setAlpha(INT_MAX); QCOMPARE(obj1.alpha(), 255); // range<0, 255> - // qreal QColor::alphaF() - // void QColor::setAlphaF(qreal) + // float QColor::alphaF() + // void QColor::setAlphaF(float) obj1.setAlphaF(0.0); - QCOMPARE(obj1.alphaF(), qreal(0.0)); // range<0.0, 1.0> - obj1.setAlphaF(-0.2); - QCOMPARE(obj1.alphaF(), qreal(0.0)); // range<0.0, 1.0> - obj1.setAlphaF(1.0); - QCOMPARE(obj1.alphaF(), qreal(1.0)); // range<0.0, 1.0> - obj1.setAlphaF(1.1); - QCOMPARE(obj1.alphaF(), qreal(1.0)); // range<0.0, 1.0> + QCOMPARE(obj1.alphaF(), 0.0f); // range<0.0, 1.0> + obj1.setAlphaF(-0.2f); + QCOMPARE(obj1.alphaF(), 0.0f); // range<0.0, 1.0> + obj1.setAlphaF(1.0f); + QCOMPARE(obj1.alphaF(), 1.0f); // range<0.0, 1.0> + obj1.setAlphaF(1.1f); + QCOMPARE(obj1.alphaF(), 1.0f); // range<0.0, 1.0> // int QColor::red() // void QColor::setRed(int) @@ -186,32 +166,32 @@ void tst_QColor::getSetCheck() obj1.setBlue(INT_MAX); QCOMPARE(obj1.blue(), 255); // range<0, 255> - // qreal QColor::redF() - // void QColor::setRedF(qreal) + // float QColor::redF() + // void QColor::setRedF(float) obj1.setRedF(0.0); - QCOMPARE(obj1.redF(), qreal(0.0)); + QCOMPARE(obj1.redF(), 0.0f); obj1.setRedF(-0.25); - QCOMPARE(obj1.redF(), qreal(-0.25)); + QCOMPARE(obj1.redF(), -0.25f); obj1.setRedF(1.25); - QCOMPARE(obj1.redF(), qreal(1.25)); + QCOMPARE(obj1.redF(), 1.25f); - // qreal QColor::greenF() - // void QColor::setGreenF(qreal) + // float QColor::greenF() + // void QColor::setGreenF(float) obj1.setGreenF(0.0); - QCOMPARE(obj1.greenF(), qreal(0.0)); + QCOMPARE(obj1.greenF(), 0.0f); obj1.setGreenF(-0.25); - QCOMPARE(obj1.greenF(), qreal(-0.25)); + QCOMPARE(obj1.greenF(), -0.25f); obj1.setGreenF(1.5); - QCOMPARE(obj1.greenF(), qreal(1.5)); + QCOMPARE(obj1.greenF(), 1.5f); - // qreal QColor::blueF() - // void QColor::setBlueF(qreal) + // float QColor::blueF() + // void QColor::setBlueF(float) obj1.setBlueF(0.0); - QCOMPARE(obj1.blueF(), qreal(0.0)); + QCOMPARE(obj1.blueF(), 0.0f); obj1.setBlueF(-0.5); - QCOMPARE(obj1.blueF(), qreal(-0.5)); + QCOMPARE(obj1.blueF(), -0.5f); obj1.setBlueF(2.0); - QCOMPARE(obj1.blueF(), qreal(2.0)); + QCOMPARE(obj1.blueF(), 2.0f); // QRgb QColor::rgba() // void QColor::setRgba(QRgb) @@ -244,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() @@ -336,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() @@ -373,7 +356,6 @@ void tst_QColor::globalColors() QCOMPARE(color.rgba(), argb); } -#if defined(Q_COMPILER_CONSTEXPR) & defined(Q_COMPILER_UNIFORM_INIT) void tst_QColor::colorConstants_data() { QTest::addColumn<QColor>("color"); @@ -556,7 +538,6 @@ void tst_QColor::colorConstants() QFETCH(QRgb, argb); QCOMPARE(color.rgba(), argb); } -#endif // defined(Q_COMPILER_CONSTEXPR) & defined(Q_COMPILER_UNIFORM_INIT) /* CSS color names = SVG 1.0 color names + transparent (rgba(0,0,0,0)) @@ -724,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(); @@ -769,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() @@ -829,8 +834,8 @@ void tst_QColor::setRed() c = QColor(Qt::blue).toHsv(); c.setRedF(0.5); QVERIFY(veryFuzzyCompare(c.redF(), 0.5)); - QCOMPARE(c.greenF(), qreal(0.0)); - QCOMPARE(c.blueF(), qreal(1.0)); + QCOMPARE(c.greenF(), 0.0f); + QCOMPARE(c.blueF(), 1.0f); } void tst_QColor::setGreen() @@ -843,9 +848,9 @@ void tst_QColor::setGreen() c = QColor(Qt::blue).toHsv(); c.setGreenF(0.5); - QCOMPARE(c.redF(), qreal(0.0)); + QCOMPARE(c.redF(), 0.0f); QVERIFY(veryFuzzyCompare(c.greenF(), 0.5)); - QCOMPARE(c.blueF(), qreal(1.0)); + QCOMPARE(c.blueF(), 1.0f); } void tst_QColor::setBlue() @@ -858,8 +863,8 @@ void tst_QColor::setBlue() c = QColor(Qt::red).toHsv(); c.setBlueF(0.5); - QCOMPARE(c.redF(), qreal(1.0)); - QCOMPARE(c.greenF(), qreal(0.0)); + QCOMPARE(c.redF(), 1.0f); + QCOMPARE(c.greenF(), 0.0f); QVERIFY(veryFuzzyCompare(c.blueF(), 0.5)); } @@ -945,11 +950,11 @@ void tst_QColor::setRgbF() for (int A = 0; A <= USHRT_MAX; ++A) { { // 0.0-1.0 - qreal a = A / qreal(USHRT_MAX); + float a = A / float(USHRT_MAX); color.setRgbF(0.0, 0.0, 0.0, a); QCOMPARE(color.alphaF(), a); - qreal r, g, b, a2; + float r, g, b, a2; color.getRgbF(&r, &g, &b, &a2); QCOMPARE(a2, a); @@ -963,11 +968,11 @@ void tst_QColor::setRgbF() for (int R = 0; R <= USHRT_MAX; ++R) { { // 0.0-1.0 - qreal r = R / qreal(USHRT_MAX); + float r = R / float(USHRT_MAX); color.setRgbF(r, 0.0, 0.0); QCOMPARE(color.redF(), r); - qreal r2, g, b, a; + float r2, g, b, a; color.getRgbF(&r2, &g, &b, &a); QCOMPARE(r2, r); } @@ -976,11 +981,11 @@ void tst_QColor::setRgbF() for (int G = 0; G <= USHRT_MAX; ++G) { { // 0.0-1.0 - qreal g = G / qreal(USHRT_MAX); + float g = G / float(USHRT_MAX); color.setRgbF(0.0, g, 0.0); QCOMPARE(color.greenF(), g); - qreal r, g2, b, a; + float r, g2, b, a; color.getRgbF(&r, &g2, &b, &a); QCOMPARE(g2, g); } @@ -989,11 +994,11 @@ void tst_QColor::setRgbF() for (int B = 0; B <= USHRT_MAX; ++B) { { // 0.0-1.0 - qreal b = B / qreal(USHRT_MAX); + float b = B / float(USHRT_MAX); color.setRgbF(0.0, 0.0, b); QCOMPARE(color.blueF(), b); - qreal r, g, b2, a; + float r, g, b2, a; color.getRgbF(&r, &g, &b2, &a); QCOMPARE(b2, b); } @@ -1002,11 +1007,11 @@ void tst_QColor::setRgbF() for (int R = -128; R <= 512; ++R) { { // extended RGB - qreal r = R / qreal(256); + float r = R / 256.0f; color.setRgbF(r, 0.0, 0.0); QCOMPARE(qfloat16(color.redF()), qfloat16(r)); - qreal r2, g, b, a; + float r2, g, b, a; color.getRgbF(&r2, &g, &b, &a); QCOMPARE(qfloat16(r2), qfloat16(r)); } @@ -1015,11 +1020,11 @@ void tst_QColor::setRgbF() for (int G = -128; G <= 512; ++G) { { // extended RGB - qreal g = G / qreal(256); + float g = G / 256.0f; color.setRgbF(0.0, g, 0.0); QCOMPARE(qfloat16(color.greenF()), qfloat16(g)); - qreal r, g2, b, a; + float r, g2, b, a; color.getRgbF(&r, &g2, &b, &a); QCOMPARE(qfloat16(g2), qfloat16(g)); } @@ -1028,11 +1033,11 @@ void tst_QColor::setRgbF() for (int B = -128; B <= 512; ++B) { { // extended RGB - qreal b = B / qreal(256); + float b = B / 256.0f; color.setRgbF(0.0, 0.0, b); QCOMPARE(qfloat16(color.blueF()), qfloat16(b)); - qreal r, g, b2, a; + float r, g, b2, a; color.getRgbF(&r, &g, &b2, &a); QCOMPARE(qfloat16(b2), qfloat16(b)); } @@ -1079,10 +1084,10 @@ void tst_QColor::setHsv() { // 0.0-1.0 - qreal a = A / qreal(USHRT_MAX); + float a = A / float(USHRT_MAX); color.setHsvF(0.0, 0.0, 0.0, a); QCOMPARE(color.alphaF(), a); - qreal h, s, v, a2; + float h, s, v, a2; color.getHsvF(&h, &s, &v, &a2); QCOMPARE(a2, a); } @@ -1103,11 +1108,11 @@ void tst_QColor::setHsv() { // 0.0-1.0 - qreal h = H / 36000.0; + float h = H / 36000.0; color.setHsvF(h, 0.0, 0.0, 0.0); QCOMPARE(color.hueF(), h); - qreal h2, s, v, a; + float h2, s, v, a; color.getHsvF(&h2, &s, &v, &a); QCOMPARE(h2, h); } @@ -1127,11 +1132,11 @@ void tst_QColor::setHsv() { // 0.0-1.0 - qreal s = S / qreal(USHRT_MAX); + float s = S / float(USHRT_MAX); color.setHsvF(0.0, s, 0.0, 0.0); QCOMPARE(color.saturationF(), s); - qreal h, s2, v, a; + float h, s2, v, a; color.getHsvF(&h, &s2, &v, &a); QCOMPARE(s2, s); } @@ -1151,11 +1156,11 @@ void tst_QColor::setHsv() { // 0.0-1.0 - qreal v = V / qreal(USHRT_MAX); + float v = V / float(USHRT_MAX); color.setHsvF(0.0, 0.0, v, 0.0); QCOMPARE(color.valueF(), v); - qreal h, s, v2, a; + float h, s, v2, a; color.getHsvF(&h, &s, &v2, &a); QCOMPARE(v2, v); } @@ -1190,11 +1195,11 @@ void tst_QColor::setCmyk() { // 0.0-1.0 - qreal a = A / qreal(USHRT_MAX); + float a = A / float(USHRT_MAX); color.setCmykF(0.0, 0.0, 0.0, 0.0, a); QCOMPARE(color.alphaF(), a); - qreal c, m, y, k, a2; + float c, m, y, k, a2; color.getCmykF(&c, &m, &y, &k, &a2); QCOMPARE(a2, a); } @@ -1214,11 +1219,11 @@ void tst_QColor::setCmyk() { // 0.0-1.0 - qreal c = C / qreal(USHRT_MAX); + float c = C / float(USHRT_MAX); color.setCmykF(c, 0.0, 0.0, 0.0, 0.0); QCOMPARE(color.cyanF(), c); - qreal c2, m, y, k, a; + float c2, m, y, k, a; color.getCmykF(&c2, &m, &y, &k, &a); QCOMPARE(c2, c); } @@ -1238,11 +1243,11 @@ void tst_QColor::setCmyk() { // 0.0-1.0 - qreal m = M / qreal(USHRT_MAX); + float m = M / float(USHRT_MAX); color.setCmykF(0.0, m, 0.0, 0.0, 0.0); QCOMPARE(color.magentaF(), m); - qreal c, m2, y, k, a; + float c, m2, y, k, a; color.getCmykF(&c, &m2, &y, &k, &a); QCOMPARE(m2, m); } @@ -1262,11 +1267,11 @@ void tst_QColor::setCmyk() { // 0.0-1.0 - qreal y = Y / qreal(USHRT_MAX); + float y = Y / float(USHRT_MAX); color.setCmykF(0.0, 0.0, y, 0.0, 0.0); QCOMPARE(color.yellowF(), y); - qreal c, m, y2, k, a; + float c, m, y2, k, a; color.getCmykF(&c, &m, &y2, &k, &a); QCOMPARE(y2, y); } @@ -1286,11 +1291,11 @@ void tst_QColor::setCmyk() { // 0.0-1.0 - qreal k = K / qreal(USHRT_MAX); + float k = K / float(USHRT_MAX); color.setCmykF(0.0, 0.0, 0.0, k, 0.0); QCOMPARE(color.blackF(), k); - qreal c, m, y, k2, a; + float c, m, y, k2, a; color.getCmykF(&c, &m, &y, &k2, &a); QCOMPARE(k2, k); } @@ -1324,10 +1329,10 @@ void tst_QColor::setHsl() { // 0.0-1.0 - qreal a = A / qreal(USHRT_MAX); + float a = A / float(USHRT_MAX); color.setHslF(0.0, 0.0, 0.0, a); QCOMPARE(color.alphaF(), a); - qreal h, s, l, a2; + float h, s, l, a2; color.getHslF(&h, &s, &l, &a2); QCOMPARE(a2, a); } @@ -1348,11 +1353,11 @@ void tst_QColor::setHsl() { // 0.0-1.0 - qreal h = H / 36000.0; + float h = H / 36000.0; color.setHslF(h, 0.0, 0.0, 0.0); QCOMPARE(color.hslHueF(), h); - qreal h2, s, l, a; + float h2, s, l, a; color.getHslF(&h2, &s, &l, &a); QCOMPARE(h2, h); } @@ -1372,11 +1377,11 @@ void tst_QColor::setHsl() { // 0.0-1.0 - qreal s = S / qreal(USHRT_MAX); + float s = S / float(USHRT_MAX); color.setHslF(0.0, s, 0.0, 0.0); QCOMPARE(color.hslSaturationF(), s); - qreal h, s2, l, a; + float h, s2, l, a; color.getHslF(&h, &s2, &l, &a); QCOMPARE(s2, s); } @@ -1396,11 +1401,11 @@ void tst_QColor::setHsl() { // 0.0-1.0 - qreal l = L / qreal(USHRT_MAX); + float l = L / float(USHRT_MAX); color.setHslF(0.0, 0.0, l, 0.0); QCOMPARE(color.lightnessF(), l); - qreal h, s, l2, a; + float h, s, l2, a; color.getHslF(&h, &s, &l2, &a); QCOMPARE(l2, l); } @@ -1424,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 } @@ -1506,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.) @@ -1517,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()); } @@ -1537,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()); } @@ -1549,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); @@ -1577,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()); } @@ -1590,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.); @@ -1621,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()); } @@ -1850,21 +1855,21 @@ void tst_QColor::qrgba64Equivalence() void tst_QColor::qcolorprofile_data() { - QTest::addColumn<qreal>("gammaC"); + QTest::addColumn<float>("gammaC"); QTest::addColumn<int>("tolerance"); - QTest::newRow("gamma=1.0") << qreal(1.0) << 0; - QTest::newRow("gamma=1.5") << qreal(1.5) << 1; - QTest::newRow("gamma=1.7") << qreal(1.7) << 2; - QTest::newRow("gamma=2.0") << qreal(2.0) << 8; - QTest::newRow("gamma=2.31") << qreal(2.31) << 33; + QTest::newRow("gamma=1.0") << 1.0f << 0; + QTest::newRow("gamma=1.5") << 1.5f << 1; + QTest::newRow("gamma=1.7") << 1.7f << 2; + QTest::newRow("gamma=2.0") << 2.0f << 8; + QTest::newRow("gamma=2.31") << 2.31f << 33; } void tst_QColor::qcolorprofile() { - QFETCH(qreal, gammaC); + 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; @@ -1875,7 +1880,6 @@ void tst_QColor::qcolorprofile() error += qAbs(qRed(cin) - qRed(cout)); } QVERIFY(error <= tolerance); - delete cp; } QTEST_MAIN(tst_QColor) |