summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/io/qfile/tst_qfile.cpp2
-rw-r--r--tests/auto/corelib/io/qprocess/tst_qprocess.cpp15
-rw-r--r--tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp10
-rw-r--r--tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp77
-rw-r--r--tests/auto/corelib/tools/qstring/tst_qstring.cpp62
-rw-r--r--tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp13
-rw-r--r--tests/auto/gui/painting/qcolor/tst_qcolor.cpp2
-rw-r--r--tests/auto/network/socket/platformsocketengine/tst_platformsocketengine.cpp1
-rw-r--r--tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp5
-rw-r--r--tests/auto/tools/uic/baseline/imagedialog.ui.h4
-rw-r--r--tests/auto/tools/uic/baseline/newdynamicpropertydialog.ui.h2
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp3
-rw-r--r--tests/benchmarks/gui/painting/painting.pro1
-rw-r--r--tests/benchmarks/gui/painting/qcolor/qcolor.pro7
-rw-r--r--tests/benchmarks/gui/painting/qcolor/tst_qcolor.cpp67
15 files changed, 223 insertions, 48 deletions
diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp
index 68d7a4fe5f..021d581aac 100644
--- a/tests/auto/corelib/io/qfile/tst_qfile.cpp
+++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp
@@ -2509,7 +2509,7 @@ void tst_QFile::rename()
\since 4.5
Some special files have QFile::atEnd() returning true, even though there is
- more data available. True for corner cases, as well as some mounts on OS X.
+ more data available. True for corner cases, as well as some mounts on \macos.
Here, we reproduce that condition by having a QFile sub-class with this
peculiar atEnd() behavior.
diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp
index 0bc1e77925..3f3533c9a1 100644
--- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp
+++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp
@@ -734,6 +734,7 @@ void tst_QProcess::restartProcess()
void tst_QProcess::closeWriteChannel()
{
+ QByteArray testData("Data to read");
QProcess more;
more.start("testProcessEOF/testProcessEOF");
@@ -741,19 +742,21 @@ void tst_QProcess::closeWriteChannel()
QVERIFY(!more.waitForReadyRead(250));
QCOMPARE(more.error(), QProcess::Timedout);
- QVERIFY(more.write("Data to read") != -1);
+ QCOMPARE(more.write(testData), qint64(testData.size()));
QVERIFY(!more.waitForReadyRead(250));
QCOMPARE(more.error(), QProcess::Timedout);
more.closeWriteChannel();
-
- QVERIFY(more.waitForReadyRead(5000));
- QVERIFY(more.readAll().startsWith("Data to read"));
+ // During closeWriteChannel() call, we might also get an I/O completion
+ // on the read pipe. So, take this into account before waiting for
+ // the new incoming data.
+ while (more.bytesAvailable() < testData.size())
+ QVERIFY(more.waitForReadyRead(5000));
+ QCOMPARE(more.readAll(), testData);
if (more.state() == QProcess::Running)
- more.write("q");
- QVERIFY(more.waitForFinished(5000));
+ QVERIFY(more.waitForFinished(5000));
QCOMPARE(more.exitStatus(), QProcess::NormalExit);
QCOMPARE(more.exitCode(), 0);
}
diff --git a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
index 04a7129f01..38e3c6890d 100644
--- a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
+++ b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
@@ -2129,17 +2129,23 @@ void tst_QSortFilterProxyModel::changeSourceDataForwardsRoles_qtbug35440()
QModelIndex index;
+ // QStringListModel doesn't distinguish between edit and display roles,
+ // so changing one always changes the other, too.
+ QVector<int> expectedChangedRoles;
+ expectedChangedRoles.append(Qt::DisplayRole);
+ expectedChangedRoles.append(Qt::EditRole);
+
index = model.index(0, 0);
QVERIFY(index.isValid());
model.setData(index, QStringLiteral("teststring"), Qt::DisplayRole);
QCOMPARE(spy.length(), 1);
- QCOMPARE(spy.at(0).at(2).value<QVector<int> >(), QVector<int>() << Qt::DisplayRole);
+ QCOMPARE(spy.at(0).at(2).value<QVector<int> >(), expectedChangedRoles);
index = model.index(1, 0);
QVERIFY(index.isValid());
model.setData(index, QStringLiteral("teststring2"), Qt::EditRole);
QCOMPARE(spy.length(), 2);
- QCOMPARE(spy.at(1).at(2).value<QVector<int> >(), QVector<int>() << Qt::EditRole);
+ QCOMPARE(spy.at(1).at(2).value<QVector<int> >(), expectedChangedRoles);
}
void tst_QSortFilterProxyModel::sortFilterRole()
diff --git a/tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp b/tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp
index 61dda782d8..f99241da3b 100644
--- a/tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp
+++ b/tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp
@@ -35,6 +35,8 @@
#include "qmodellistener.h"
#include <qstringlistmodel.h>
+#include <algorithm>
+
void QModelListener::rowsAboutToBeRemovedOrInserted(const QModelIndex & parent, int start, int end )
{
for (int i = 0; start + i <= end; i++) {
@@ -75,6 +77,9 @@ private slots:
void rowsAboutToBeInserted_rowsInserted();
void rowsAboutToBeInserted_rowsInserted_data();
+
+ void setData_emits_both_roles_data();
+ void setData_emits_both_roles();
};
void tst_QStringListModel::rowsAboutToBeRemoved_rowsRemoved_data()
@@ -129,22 +134,19 @@ void tst_QStringListModel::rowsAboutToBeRemoved_rowsRemoved()
QFETCH(QStringList, aboutto);
QFETCH(QStringList, res);
- QStringListModel *model = new QStringListModel(input);
- QModelListener *pListener = new QModelListener(&aboutto, &res, model);
- pListener->connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
- pListener, SLOT(rowsAboutToBeRemovedOrInserted(QModelIndex,int,int)) );
+ QStringListModel model(input);
+ QModelListener listener(&aboutto, &res, &model);
+ connect(&model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
+ &listener, SLOT(rowsAboutToBeRemovedOrInserted(QModelIndex,int,int)));
- pListener->connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
- pListener, SLOT(rowsRemovedOrInserted(QModelIndex,int,int)) );
+ connect(&model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
+ &listener, SLOT(rowsRemovedOrInserted(QModelIndex,int,int)));
- model->removeRows(row,count);
+ model.removeRows(row, count);
// At this point, control goes to our connected slots inn this order:
// 1. rowsAboutToBeRemovedOrInserted
// 2. rowsRemovedOrInserted
// Control returns here
-
- delete pListener;
- delete model;
}
void tst_QStringListModel::rowsAboutToBeInserted_rowsInserted_data()
@@ -193,22 +195,59 @@ void tst_QStringListModel::rowsAboutToBeInserted_rowsInserted()
QFETCH(QStringList, aboutto);
QFETCH(QStringList, res);
- QStringListModel *model = new QStringListModel(input);
- QModelListener *pListener = new QModelListener(&aboutto, &res, model);
- connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
- pListener, SLOT(rowsAboutToBeRemovedOrInserted(QModelIndex,int,int)) );
+ QStringListModel model(input);
+ QModelListener listener(&aboutto, &res, &model);
+ connect(&model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
+ &listener, SLOT(rowsAboutToBeRemovedOrInserted(QModelIndex,int,int)));
- connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)),
- pListener, SLOT(rowsRemovedOrInserted(QModelIndex,int,int)) );
+ connect(&model, SIGNAL(rowsInserted(QModelIndex,int,int)),
+ &listener, SLOT(rowsRemovedOrInserted(QModelIndex,int,int)));
- model->insertRows(row,count);
+ model.insertRows(row, count);
// At this point, control goes to our connected slots inn this order:
// 1. rowsAboutToBeRemovedOrInserted
// 2. rowsRemovedOrInserted
// Control returns here
+}
- delete pListener;
- delete model;
+void tst_QStringListModel::setData_emits_both_roles_data()
+{
+ QTest::addColumn<int>("row");
+ QTest::addColumn<QString>("data");
+ QTest::addColumn<int>("role");
+
+#define ROW(row, string, role) \
+ QTest::newRow(#row " -> " string) << row << QString(string) << int(Qt::role)
+ ROW(0, "1", EditRole);
+ ROW(1, "2", DisplayRole);
+#undef ROW
+}
+
+template <class C>
+C sorted(C c)
+{
+ std::sort(c.begin(), c.end());
+ return qMove(c);
+}
+
+void tst_QStringListModel::setData_emits_both_roles()
+{
+ QFETCH(int, row);
+ QFETCH(QString, data);
+ QFETCH(int, role);
+
+ QStringListModel model(QStringList() << "one" << "two");
+ QVector<int> expected;
+ expected.reserve(2);
+ expected.append(Qt::DisplayRole);
+ expected.append(Qt::EditRole);
+
+ QSignalSpy spy(&model, &QAbstractItemModel::dataChanged);
+ QVERIFY(spy.isValid());
+ model.setData(model.index(row, 0), data, role);
+ QCOMPARE(spy.size(), 1);
+ QCOMPARE(sorted(spy.at(0).at(2).value<QVector<int> >()),
+ expected);
}
QTEST_MAIN(tst_QStringListModel)
diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
index 7a37fdfa46..8f0f599622 100644
--- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp
+++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
@@ -496,6 +496,8 @@ private slots:
void fromLocal8Bit();
void local8Bit_data();
void local8Bit();
+ void invalidToLocal8Bit_data();
+ void invalidToLocal8Bit();
void nullFromLocal8Bit();
void fromLatin1Roundtrip_data();
void fromLatin1Roundtrip();
@@ -4290,6 +4292,66 @@ void tst_QString::local8Bit()
QCOMPARE(local8Bit.toLocal8Bit(), QByteArray(result));
}
+void tst_QString::invalidToLocal8Bit_data()
+{
+ QTest::addColumn<QString>("unicode");
+ QTest::addColumn<QByteArray>("expect"); // Initial validly-converted prefix
+
+ {
+ const QChar malformed[] = { 'A', 0xd800, 'B', 0 };
+ const char expected[] = "A";
+ QTest::newRow("LoneHighSurrogate")
+ << QString(malformed, sizeof(malformed) / sizeof(QChar))
+ // Don't include the terminating '\0' of expected:
+ << QByteArray(expected, sizeof(expected) / sizeof(char) - 1);
+ }
+ {
+ const QChar malformed[] = { 'A', 0xdc00, 'B', 0 };
+ const char expected[] = "A";
+ QTest::newRow("LoneLowSurrogate")
+ << QString(malformed, sizeof(malformed) / sizeof(QChar))
+ << QByteArray(expected, sizeof(expected) / sizeof(char) - 1);
+ }
+ {
+ const QChar malformed[] = { 'A', 0xd800, 0xd801, 'B', 0 };
+ const char expected[] = "A";
+ QTest::newRow("DoubleHighSurrogate")
+ << QString(malformed, sizeof(malformed) / sizeof(QChar))
+ << QByteArray(expected, sizeof(expected) / sizeof(char) - 1);
+ }
+ {
+ const QChar malformed[] = { 'A', 0xdc00, 0xdc01, 'B', 0 };
+ const char expected[] = "A";
+ QTest::newRow("DoubleLowSurrogate")
+ << QString(malformed, sizeof(malformed) / sizeof(QChar))
+ << QByteArray(expected, sizeof(expected) / sizeof(char) - 1);
+ }
+ {
+ const QChar malformed[] = { 'A', 0xdc00, 0xd800, 'B', 0 };
+ const char expected[] = "A";
+ QTest::newRow("ReversedSurrogates") // low before high
+ << QString(malformed, sizeof(malformed) / sizeof(QChar))
+ << QByteArray(expected, sizeof(expected) / sizeof(char) - 1);
+ }
+}
+
+void tst_QString::invalidToLocal8Bit()
+{
+ QFETCH(QString, unicode);
+ QFETCH(QByteArray, expect);
+ QByteArray local = unicode.toLocal8Bit();
+ /*
+ The main concern of this test is to check that any error-reporting that
+ toLocal8Bit() prompts on failure isn't dependent on outputting the data
+ it's converting via toLocal8Bit(), which would be apt to recurse. So the
+ real purpose of this QVERIFY(), for all that we should indeed check we get
+ the borked output that matches what we can reliably expect (despite
+ variation in how codecs respond to errors), is to verify that we got here
+ - i.e. we didn't crash in such a recursive stack over-flow.
+ */
+ QVERIFY(local.startsWith(expect));
+}
+
void tst_QString::nullFromLocal8Bit()
{
QString a;
diff --git a/tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp b/tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp
index 9e747f8b11..b66eef5759 100644
--- a/tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp
+++ b/tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp
@@ -55,9 +55,6 @@ class tst_QImageWriter : public QObject
{
Q_OBJECT
-public:
- virtual ~tst_QImageWriter();
-
public slots:
void initTestCase();
@@ -155,16 +152,6 @@ void tst_QImageWriter::getSetCheck()
QCOMPARE(1.1f, obj1.gamma());
}
-tst_QImageWriter::~tst_QImageWriter()
-{
- QDir dir(prefix);
- QStringList filesToDelete = dir.entryList(QStringList() << "gen-*" , QDir::NoDotAndDotDot | QDir::Files);
- foreach( QString file, filesToDelete) {
- QFile::remove(dir.absoluteFilePath(file));
- }
-
-}
-
void tst_QImageWriter::writeImage_data()
{
QTest::addColumn<QString>("fileName");
diff --git a/tests/auto/gui/painting/qcolor/tst_qcolor.cpp b/tests/auto/gui/painting/qcolor/tst_qcolor.cpp
index cffa444c97..00e7436c0f 100644
--- a/tests/auto/gui/painting/qcolor/tst_qcolor.cpp
+++ b/tests/auto/gui/painting/qcolor/tst_qcolor.cpp
@@ -279,6 +279,8 @@ void tst_QColor::name_data()
QTest::newRow("global color darkMagenta") << QColor(Qt::darkMagenta) << "#800080" << QColor::HexRgb;
QTest::newRow("global color darkYellow") << QColor(Qt::darkYellow) << "#808000" << QColor::HexRgb;
QTest::newRow("transparent red") << QColor(255, 0, 0, 102) << "#66ff0000" << QColor::HexArgb;
+ QTest::newRow("fully_transparent_green_rgb") << QColor(0, 0, 255, 0) << "#0000ff" << QColor::HexRgb;
+ QTest::newRow("fully_transparent_green_argb") << QColor(0, 0, 255, 0) << "#000000ff" << QColor::HexArgb;
}
void tst_QColor::name()
diff --git a/tests/auto/network/socket/platformsocketengine/tst_platformsocketengine.cpp b/tests/auto/network/socket/platformsocketengine/tst_platformsocketengine.cpp
index bc9d3cc9bf..43b5422635 100644
--- a/tests/auto/network/socket/platformsocketengine/tst_platformsocketengine.cpp
+++ b/tests/auto/network/socket/platformsocketengine/tst_platformsocketengine.cpp
@@ -111,6 +111,7 @@ void tst_PlatformSocketEngine::construction()
QCOMPARE(socketDevice.peerAddress(), QHostAddress());
QCOMPARE(socketDevice.peerPort(), quint16(0));
QCOMPARE(socketDevice.error(), QAbstractSocket::UnknownSocketError);
+ QCOMPARE(socketDevice.option(QNativeSocketEngine::NonBlockingSocketOption), -1);
QTest::ignoreMessage(QtWarningMsg, PLATFORMSOCKETENGINESTRING "::bytesAvailable() was called in QAbstractSocket::UnconnectedState");
QCOMPARE(socketDevice.bytesAvailable(), -1);
diff --git a/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp b/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp
index cb55c9c1db..384da6b8cb 100644
--- a/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp
+++ b/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp
@@ -1402,7 +1402,8 @@ void tst_QSslSocket::setLocalCertificateChain()
QEventLoop loop;
QTimer::singleShot(5000, &loop, SLOT(quit()));
- socket = new QSslSocket();
+ const QScopedPointer<QSslSocket, QScopedPointerDeleteLater> client(new QSslSocket);
+ socket = client.data();
connect(socket, SIGNAL(encrypted()), &loop, SLOT(quit()));
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), &loop, SLOT(quit()));
connect(socket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(ignoreErrorSlot()));
@@ -1414,8 +1415,6 @@ void tst_QSslSocket::setLocalCertificateChain()
QCOMPARE(chain.size(), 2);
QCOMPARE(chain[0].serialNumber(), QByteArray("10:a0:ad:77:58:f6:6e:ae:46:93:a3:43:f9:59:8a:9e"));
QCOMPARE(chain[1].serialNumber(), QByteArray("3b:eb:99:c5:ea:d8:0b:5d:0b:97:5d:4f:06:75:4b:e1"));
-
- socket->deleteLater();
}
void tst_QSslSocket::setPrivateKey()
diff --git a/tests/auto/tools/uic/baseline/imagedialog.ui.h b/tests/auto/tools/uic/baseline/imagedialog.ui.h
index c02c40c2c1..99e853b7a8 100644
--- a/tests/auto/tools/uic/baseline/imagedialog.ui.h
+++ b/tests/auto/tools/uic/baseline/imagedialog.ui.h
@@ -155,7 +155,7 @@ public:
vboxLayout->addLayout(gridLayout);
- spacerItem = new QSpacerItem(QSizePolicy::Minimum, QSizePolicy::Expanding);
+ spacerItem = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
vboxLayout->addItem(spacerItem);
@@ -166,7 +166,7 @@ public:
hboxLayout->setContentsMargins(1, 1, 1, 1);
hboxLayout->setObjectName(QStringLiteral("hboxLayout"));
hboxLayout->setObjectName(QStringLiteral(""));
- spacerItem1 = new QSpacerItem(QSizePolicy::Expanding, QSizePolicy::Minimum);
+ spacerItem1 = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
hboxLayout->addItem(spacerItem1);
diff --git a/tests/auto/tools/uic/baseline/newdynamicpropertydialog.ui.h b/tests/auto/tools/uic/baseline/newdynamicpropertydialog.ui.h
index ca7bd253a8..3c4e0ba09e 100644
--- a/tests/auto/tools/uic/baseline/newdynamicpropertydialog.ui.h
+++ b/tests/auto/tools/uic/baseline/newdynamicpropertydialog.ui.h
@@ -91,7 +91,7 @@ public:
verticalLayout->addLayout(formLayout);
- spacerItem = new QSpacerItem(QSizePolicy::Minimum, QSizePolicy::Expanding);
+ spacerItem = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
verticalLayout->addItem(spacerItem);
diff --git a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp
index a3aa90168a..6faeb10ce7 100644
--- a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp
@@ -392,6 +392,7 @@ void tst_QGraphicsProxyWidget::setWidget()
QGraphicsScene scene;
QGraphicsView view(&scene);
view.show();
+ QScopedPointer<QStyle> style(QStyleFactory::create(QLatin1String("Fusion")));
QVERIFY(QTest::qWaitForWindowExposed(&view));
QPointer<SubQGraphicsProxyWidget> proxy = new SubQGraphicsProxyWidget;
SubQGraphicsProxyWidget parentProxy;
@@ -414,7 +415,7 @@ void tst_QGraphicsProxyWidget::setWidget()
#endif
widget->setPalette(QPalette(Qt::magenta));
widget->setLayoutDirection(Qt::RightToLeft);
- widget->setStyle(QStyleFactory::create(QLatin1String("Fusion")));
+ widget->setStyle(style.data());
widget->setFont(QFont("Times"));
widget->setVisible(true);
QApplication::setActiveWindow(widget);
diff --git a/tests/benchmarks/gui/painting/painting.pro b/tests/benchmarks/gui/painting/painting.pro
index 0eb7fa92a7..cdcfc9b318 100644
--- a/tests/benchmarks/gui/painting/painting.pro
+++ b/tests/benchmarks/gui/painting/painting.pro
@@ -1,5 +1,6 @@
TEMPLATE = subdirs
SUBDIRS = \
+ qcolor \
qpainter \
qregion \
qtransform \
diff --git a/tests/benchmarks/gui/painting/qcolor/qcolor.pro b/tests/benchmarks/gui/painting/qcolor/qcolor.pro
new file mode 100644
index 0000000000..5ceb702323
--- /dev/null
+++ b/tests/benchmarks/gui/painting/qcolor/qcolor.pro
@@ -0,0 +1,7 @@
+QT += testlib
+QT += gui-private
+
+TEMPLATE = app
+TARGET = tst_bench_qcolor
+
+SOURCES += tst_qcolor.cpp
diff --git a/tests/benchmarks/gui/painting/qcolor/tst_qcolor.cpp b/tests/benchmarks/gui/painting/qcolor/tst_qcolor.cpp
new file mode 100644
index 0000000000..b67fa450d7
--- /dev/null
+++ b/tests/benchmarks/gui/painting/qcolor/tst_qcolor.cpp
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author David Faure <david.faure@kdab.com>
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qtest.h>
+#include <QColor>
+
+
+class tst_QColor : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void nameRgb();
+ void nameArgb();
+};
+
+void tst_QColor::nameRgb()
+{
+ QColor color(128, 255, 10);
+ QCOMPARE(color.name(), QStringLiteral("#80ff0a"));
+ QBENCHMARK {
+ color.name();
+ }
+}
+
+void tst_QColor::nameArgb()
+{
+ QColor color(128, 255, 0, 102);
+ QCOMPARE(color.name(QColor::HexArgb), QStringLiteral("#6680ff00"));
+ QBENCHMARK {
+ color.name(QColor::HexArgb);
+ }
+}
+
+QTEST_MAIN(tst_QColor)
+
+#include "tst_qcolor.moc"