diff options
9 files changed, 199 insertions, 9 deletions
diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index 87e88d74bd..696aeb2efb 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -1657,7 +1657,7 @@ inline bool operator>=(const QStringRef &lhs, QLatin1String rhs) Q_DECL_NOTHROW // QChar <> QString inline bool operator==(QChar lhs, const QString &rhs) Q_DECL_NOTHROW -{ return QString::compare_helper(&lhs, 1, rhs.data(), rhs.size()) == 0; } +{ return rhs.size() == 1 && lhs == rhs.front(); } inline bool operator< (QChar lhs, const QString &rhs) Q_DECL_NOTHROW { return QString::compare_helper(&lhs, 1, rhs.data(), rhs.size()) < 0; } inline bool operator> (QChar lhs, const QString &rhs) Q_DECL_NOTHROW @@ -1676,7 +1676,7 @@ inline bool operator>=(const QString &lhs, QChar rhs) Q_DECL_NOTHROW { return !( // QChar <> QStringRef inline bool operator==(QChar lhs, const QStringRef &rhs) Q_DECL_NOTHROW -{ return QString::compare_helper(&lhs, 1, rhs.data(), rhs.size()) == 0; } +{ return rhs.size() == 1 && lhs == rhs.front(); } inline bool operator< (QChar lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return QString::compare_helper(&lhs, 1, rhs.data(), rhs.size()) < 0; } inline bool operator> (QChar lhs, const QStringRef &rhs) Q_DECL_NOTHROW @@ -1695,7 +1695,7 @@ inline bool operator>=(const QStringRef &lhs, QChar rhs) Q_DECL_NOTHROW { return // QChar <> QLatin1String inline bool operator==(QChar lhs, QLatin1String rhs) Q_DECL_NOTHROW -{ return QString::compare_helper(&lhs, 1, rhs) == 0; } +{ return rhs.size() == 1 && lhs == rhs.front(); } inline bool operator< (QChar lhs, QLatin1String rhs) Q_DECL_NOTHROW { return QString::compare_helper(&lhs, 1, rhs) < 0; } inline bool operator> (QChar lhs, QLatin1String rhs) Q_DECL_NOTHROW diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglcontext.h b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglcontext.h index 5f6d9f92dd..fe50afa62a 100644 --- a/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglcontext.h +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglcontext.h @@ -51,9 +51,8 @@ class QXcbEglContext : public QEGLPlatformContext { public: QXcbEglContext(const QSurfaceFormat &glFormat, QPlatformOpenGLContext *share, - EGLDisplay display, QXcbConnection *c, const QVariant &nativeHandle) + EGLDisplay display, const QVariant &nativeHandle) : QEGLPlatformContext(glFormat, share, display, 0, nativeHandle) - , m_connection(c) { } @@ -83,9 +82,6 @@ public: QVariant nativeHandle() const { return QVariant::fromValue<QEGLNativeContext>(QEGLNativeContext(eglContext(), eglDisplay())); } - -private: - QXcbConnection *m_connection; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglintegration.cpp b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglintegration.cpp index 4852d38f7e..40ecd9e58d 100644 --- a/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglintegration.cpp +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglintegration.cpp @@ -102,7 +102,6 @@ QPlatformOpenGLContext *QXcbEglIntegration::createPlatformOpenGLContext(QOpenGLC QXcbEglContext *platformContext = new QXcbEglContext(screen->surfaceFormatFor(context->format()), context->shareHandle(), eglDisplay(), - screen->connection(), context->nativeHandle()); context->setNativeHandle(platformContext->nativeHandle()); return platformContext; diff --git a/tests/auto/corelib/tools/containerapisymmetry/.gitignore b/tests/auto/corelib/tools/containerapisymmetry/.gitignore new file mode 100644 index 0000000000..172ca970f2 --- /dev/null +++ b/tests/auto/corelib/tools/containerapisymmetry/.gitignore @@ -0,0 +1 @@ +tst_containerapisymmetry diff --git a/tests/auto/corelib/tools/containerapisymmetry/containerapisymmetry.pro b/tests/auto/corelib/tools/containerapisymmetry/containerapisymmetry.pro new file mode 100644 index 0000000000..30dc8026ef --- /dev/null +++ b/tests/auto/corelib/tools/containerapisymmetry/containerapisymmetry.pro @@ -0,0 +1,7 @@ +CONFIG += testcase +TARGET = tst_containerapisymmetry +SOURCES += tst_containerapisymmetry.cpp +QT = core testlib + +# This test does not work with strict iterators +DEFINES -= QT_STRICT_ITERATORS diff --git a/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp b/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp new file mode 100644 index 0000000000..d7ec624804 --- /dev/null +++ b/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz <marc.mutz@kdab.com> +** 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> + +#include "qlinkedlist.h" +#include "qlist.h" +#include "qvarlengtharray.h" +#include "qvector.h" + +#include <vector> // for reference + +class tst_ContainerApiSymmetry : public QObject +{ + Q_OBJECT + +private: + template <typename Container> + void front_back_impl() const; + +private Q_SLOTS: + void front_back_std_vector() { front_back_impl<std::vector<int>>(); } + void front_back_QVector() { front_back_impl<QVector<int>>(); } + void front_back_QList() { front_back_impl<QList<qintptr>>(); } + void front_back_QLinkedList() { front_back_impl<QLinkedList<int>>(); } + void front_back_QVarLengthArray() { front_back_impl<QVarLengthArray<int>>(); } +}; + +template <typename Container> +Container make(int size) +{ + Container c; + int i = 1; + while (size--) + c.push_back(typename Container::value_type(i++)); + return c; +} + +template <typename T> T clean(T &&t) { return std::forward<T>(t); } + +template <typename Container> +void tst_ContainerApiSymmetry::front_back_impl() const +{ + using V = typename Container::value_type; + auto c1 = make<Container>(1); + QCOMPARE(clean(c1.front()), V(1)); + QCOMPARE(clean(c1.back()), V(1)); + QCOMPARE(clean(qAsConst(c1).front()), V(1)); + QCOMPARE(clean(qAsConst(c1).back()), V(1)); + + auto c2 = make<Container>(2); + QCOMPARE(clean(c2.front()), V(1)); + QCOMPARE(clean(c2.back()), V(2)); + QCOMPARE(clean(qAsConst(c2).front()), V(1)); + QCOMPARE(clean(qAsConst(c2).back()), V(2)); +} + +QTEST_APPLESS_MAIN(tst_ContainerApiSymmetry) +#include "tst_containerapisymmetry.moc" diff --git a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp index 1e09da1fe4..a8ea9ccf27 100644 --- a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp +++ b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp @@ -38,6 +38,7 @@ class tst_QHashFunctions : public QObject { Q_OBJECT private Q_SLOTS: + void consistent(); void qhash(); void qhash_of_empty_and_null_qstring(); void qhash_of_empty_and_null_qbytearray(); @@ -50,6 +51,17 @@ private Q_SLOTS: void setGlobalQHashSeed(); }; +void tst_QHashFunctions::consistent() +{ + // QString-like + { + const QString s = QStringLiteral("abcdefghijklmnopqrstuvxyz").repeated(16); + + QCOMPARE(qHash(s), qHash(QStringRef(&s))); + QCOMPARE(qHash(s), qHash(QStringView(s))); + } +} + void tst_QHashFunctions::qhash() { { diff --git a/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp b/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp index dd8cbbfbcd..7bc571c83f 100644 --- a/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp +++ b/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp @@ -191,6 +191,12 @@ private: void right_data(); template <typename String> void right_impl(); + void chop_data(); + template <typename String> void chop_impl(); + + void truncate_data() { left_data(); } + template <typename String> void truncate_impl(); + private Q_SLOTS: void mid_QString_data() { mid_data(); } @@ -226,6 +232,20 @@ private Q_SLOTS: void right_QByteArray_data() { right_data(); } void right_QByteArray() { right_impl<QByteArray>(); } + void chop_QString_data() { chop_data(); } + void chop_QString() { chop_impl<QString>(); } + void chop_QStringRef_data() { chop_data(); } + void chop_QStringRef() { chop_impl<QStringRef>(); } + void chop_QByteArray_data() { chop_data(); } + void chop_QByteArray() { chop_impl<QByteArray>(); } + + void truncate_QString_data() { truncate_data(); } + void truncate_QString() { truncate_impl<QString>(); } + void truncate_QStringRef_data() { truncate_data(); } + void truncate_QStringRef() { truncate_impl<QStringRef>(); } + void truncate_QByteArray_data() { truncate_data(); } + void truncate_QByteArray() { truncate_impl<QByteArray>(); } + // // UTF-16-only checks: // @@ -539,6 +559,76 @@ void tst_QStringApiSymmetry::right_impl() QCOMPARE(right.isEmpty(), result.isEmpty()); } +void tst_QStringApiSymmetry::chop_data() +{ + QTest::addColumn<QStringRef>("unicode"); + QTest::addColumn<QLatin1String>("latin1"); + QTest::addColumn<int>("n"); + QTest::addColumn<QStringRef>("result"); + + QTest::addRow("null") << QStringRef() << QLatin1String() << 0 << QStringRef(); + QTest::addRow("empty") << QStringRef(&empty) << QLatin1String("") << 0 << QStringRef(&empty); + + // Some classes' truncate() implementations have a wide contract, others a narrow one + // so only test valid arguents here: +#define ROW(base, n, res) \ + QTest::addRow("%s%d", #base, n) << QStringRef(&base) << QLatin1String(#base) << n << QStringRef(&res); + + ROW(a, 0, a); + ROW(a, 1, empty); + + ROW(ab, 0, ab); + ROW(ab, 1, a); + ROW(ab, 2, empty); + + ROW(abc, 0, abc); + ROW(abc, 1, ab); + ROW(abc, 2, a); + ROW(abc, 3, empty); +#undef ROW +} + +template <typename String> +void tst_QStringApiSymmetry::chop_impl() +{ + QFETCH(const QStringRef, unicode); + QFETCH(const QLatin1String, latin1); + QFETCH(const int, n); + QFETCH(const QStringRef, result); + + const auto utf8 = unicode.toUtf8(); + + const auto s = make<String>(unicode, latin1, utf8); + + { + auto chopped = s; + chopped.chop(n); + + QVERIFY(chopped == result); + QCOMPARE(chopped.isNull(), result.isNull()); + QCOMPARE(chopped.isEmpty(), result.isEmpty()); + } +} + +template <typename String> +void tst_QStringApiSymmetry::truncate_impl() +{ + QFETCH(const QStringRef, unicode); + QFETCH(const QLatin1String, latin1); + QFETCH(const int, n); + QFETCH(const QStringRef, result); + + const auto utf8 = unicode.toUtf8(); + + auto trunc = make<String>(unicode, latin1, utf8); + + trunc.truncate(n); + + QVERIFY(trunc == result); + QCOMPARE(trunc.isNull(), result.isNull()); + QCOMPARE(trunc.isEmpty(), result.isEmpty()); +} + // // // UTF-16-only checks: diff --git a/tests/auto/corelib/tools/tools.pro b/tests/auto/corelib/tools/tools.pro index e16648c15f..6720307d59 100644 --- a/tests/auto/corelib/tools/tools.pro +++ b/tests/auto/corelib/tools/tools.pro @@ -1,6 +1,7 @@ TEMPLATE=subdirs SUBDIRS=\ collections \ + containerapisymmetry \ qalgorithms \ qarraydata \ qarraydata_strictiterators \ |