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.cpp106
1 files changed, 57 insertions, 49 deletions
diff --git a/tests/auto/gui/painting/qcolor/tst_qcolor.cpp b/tests/auto/gui/painting/qcolor/tst_qcolor.cpp
index 5c93a41b71..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();
@@ -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()