From 4c1f66a0b2862784fa790deca36a70d885efb4e0 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 15 Mar 2014 20:28:17 +0100 Subject: tst_QHash: Factor qHash()-related test cases into a separate test This is in preparation of adding more qHash()-related tests. Change-Id: Iae65bf8b123e1d6ac6d1eb34d74ba4eb9df8173c Reviewed-by: Olivier Goffart --- tests/auto/corelib/tools/qhash/tst_qhash.cpp | 101 -------------- tests/auto/corelib/tools/qhashfunctions/.gitignore | 1 + .../tools/qhashfunctions/qhashfunctions.pro | 5 + .../tools/qhashfunctions/tst_qhashfunctions.cpp | 153 +++++++++++++++++++++ tests/auto/corelib/tools/tools.pro | 1 + 5 files changed, 160 insertions(+), 101 deletions(-) create mode 100644 tests/auto/corelib/tools/qhashfunctions/.gitignore create mode 100644 tests/auto/corelib/tools/qhashfunctions/qhashfunctions.pro create mode 100644 tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp (limited to 'tests/auto/corelib/tools') diff --git a/tests/auto/corelib/tools/qhash/tst_qhash.cpp b/tests/auto/corelib/tools/qhash/tst_qhash.cpp index a1fc50fb38..39aaee102b 100644 --- a/tests/auto/corelib/tools/qhash/tst_qhash.cpp +++ b/tests/auto/corelib/tools/qhash/tst_qhash.cpp @@ -57,8 +57,6 @@ private slots: void operator_eq(); // copied from tst_QMap void rehash_isnt_quadratic(); void dont_need_default_constructor(); - void qhash(); - void fp_qhash_of_zero_is_zero(); void qmultihash_specific(); void compare(); @@ -70,9 +68,6 @@ private slots: void const_shared_null(); void twoArguments_qHash(); void initializerList(); - - void qthash_data(); - void qthash(); void eraseValidIteratorOnSharedHash(); }; @@ -1009,83 +1004,6 @@ void tst_QHash::dont_need_default_constructor() } } -void tst_QHash::qhash() -{ - { - QBitArray a1; - QBitArray a2; - QVERIFY(qHash(a1) == 0); - - a1.resize(1); - a1.setBit(0, true); - - a2.resize(1); - a2.setBit(0, false); - - uint h1 = qHash(a1); - uint h2 = qHash(a2); - - QVERIFY(h1 != h2); - - a2.setBit(0, true); - QVERIFY(h1 == qHash(a2)); - - a1.fill(true, 8); - a1.resize(7); - - h1 = qHash(a1); - - a2.fill(true, 7); - h2 = qHash(a2); - - QVERIFY(h1 == h2); - - a2.setBit(0, false); - uint h3 = qHash(a2); - QVERIFY(h2 != h3); - - a2.setBit(0, true); - QVERIFY(h2 == qHash(a2)); - - a2.setBit(6, false); - uint h4 = qHash(a2); - QVERIFY(h2 != h4); - - a2.setBit(6, true); - QVERIFY(h2 == qHash(a2)); - - QVERIFY(h3 != h4); - } - - { - QPair p12(1, 2); - QPair p21(2, 1); - - QVERIFY(qHash(p12) == qHash(p12)); - QVERIFY(qHash(p21) == qHash(p21)); - QVERIFY(qHash(p12) != qHash(p21)); - - QPair pA(0x12345678, 0x12345678); - QPair pB(0x12345675, 0x12345675); - - QVERIFY(qHash(pA) != qHash(pB)); - } -} - -void tst_QHash::fp_qhash_of_zero_is_zero() -{ - QCOMPARE(qHash(-0.0f), 0U); - QCOMPARE(qHash( 0.0f), 0U); - - QCOMPARE(qHash(-0.0 ), 0U); - QCOMPARE(qHash( 0.0 ), 0U); - -#ifndef Q_OS_DARWIN - QCOMPARE(qHash(-0.0L), 0U); - QCOMPARE(qHash( 0.0L), 0U); -#endif -} - void tst_QHash::qmultihash_specific() { QMultiHash hash1; @@ -1384,25 +1302,6 @@ void tst_QHash::initializerList() #endif } -void tst_QHash::qthash_data() -{ - QTest::addColumn("key"); - QTest::addColumn("hash"); - - QTest::newRow("null") << QString() << 0u; - QTest::newRow("empty") << QStringLiteral("") << 0u; - QTest::newRow("abcdef") << QStringLiteral("abcdef") << 108567222u; - QTest::newRow("tqbfjotld") << QStringLiteral("The quick brown fox jumps over the lazy dog") << 140865879u; - QTest::newRow("42") << QStringLiteral("42") << 882u; -} - -void tst_QHash::qthash() -{ - QFETCH(QString, key); - const uint result = qt_hash(key); - QTEST(result, "hash"); -} - void tst_QHash::eraseValidIteratorOnSharedHash() { QHash a, b; diff --git a/tests/auto/corelib/tools/qhashfunctions/.gitignore b/tests/auto/corelib/tools/qhashfunctions/.gitignore new file mode 100644 index 0000000000..ca8886e200 --- /dev/null +++ b/tests/auto/corelib/tools/qhashfunctions/.gitignore @@ -0,0 +1 @@ +tst_qhashfunctions diff --git a/tests/auto/corelib/tools/qhashfunctions/qhashfunctions.pro b/tests/auto/corelib/tools/qhashfunctions/qhashfunctions.pro new file mode 100644 index 0000000000..21426a4f55 --- /dev/null +++ b/tests/auto/corelib/tools/qhashfunctions/qhashfunctions.pro @@ -0,0 +1,5 @@ +CONFIG += testcase parallel_test +TARGET = tst_qhashfunctions +QT = core testlib +SOURCES = $$PWD/tst_qhashfunctions.cpp +DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp new file mode 100644 index 0000000000..fb038dd37a --- /dev/null +++ b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp @@ -0,0 +1,153 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include + +class tst_QHashFunctions : public QObject +{ + Q_OBJECT +private Q_SLOTS: + void qhash(); + void fp_qhash_of_zero_is_zero(); + void qthash_data(); + void qthash(); +}; + +void tst_QHashFunctions::qhash() +{ + { + QBitArray a1; + QBitArray a2; + QVERIFY(qHash(a1) == 0); + + a1.resize(1); + a1.setBit(0, true); + + a2.resize(1); + a2.setBit(0, false); + + uint h1 = qHash(a1); + uint h2 = qHash(a2); + + QVERIFY(h1 != h2); + + a2.setBit(0, true); + QVERIFY(h1 == qHash(a2)); + + a1.fill(true, 8); + a1.resize(7); + + h1 = qHash(a1); + + a2.fill(true, 7); + h2 = qHash(a2); + + QVERIFY(h1 == h2); + + a2.setBit(0, false); + uint h3 = qHash(a2); + QVERIFY(h2 != h3); + + a2.setBit(0, true); + QVERIFY(h2 == qHash(a2)); + + a2.setBit(6, false); + uint h4 = qHash(a2); + QVERIFY(h2 != h4); + + a2.setBit(6, true); + QVERIFY(h2 == qHash(a2)); + + QVERIFY(h3 != h4); + } + + { + QPair p12(1, 2); + QPair p21(2, 1); + + QVERIFY(qHash(p12) == qHash(p12)); + QVERIFY(qHash(p21) == qHash(p21)); + QVERIFY(qHash(p12) != qHash(p21)); + + QPair pA(0x12345678, 0x12345678); + QPair pB(0x12345675, 0x12345675); + + QVERIFY(qHash(pA) != qHash(pB)); + } +} + +void tst_QHashFunctions::fp_qhash_of_zero_is_zero() +{ + QCOMPARE(qHash(-0.0f), 0U); + QCOMPARE(qHash( 0.0f), 0U); + + QCOMPARE(qHash(-0.0 ), 0U); + QCOMPARE(qHash( 0.0 ), 0U); + +#ifndef Q_OS_DARWIN + QCOMPARE(qHash(-0.0L), 0U); + QCOMPARE(qHash( 0.0L), 0U); +#endif +} + +void tst_QHashFunctions::qthash_data() +{ + QTest::addColumn("key"); + QTest::addColumn("hash"); + + QTest::newRow("null") << QString() << 0u; + QTest::newRow("empty") << QStringLiteral("") << 0u; + QTest::newRow("abcdef") << QStringLiteral("abcdef") << 108567222u; + QTest::newRow("tqbfjotld") << QStringLiteral("The quick brown fox jumps over the lazy dog") << 140865879u; + QTest::newRow("42") << QStringLiteral("42") << 882u; +} + +void tst_QHashFunctions::qthash() +{ + QFETCH(QString, key); + const uint result = qt_hash(key); + QTEST(result, "hash"); +} + +QTEST_APPLESS_MAIN(tst_QHashFunctions) +#include "tst_qhashfunctions.moc" diff --git a/tests/auto/corelib/tools/tools.pro b/tests/auto/corelib/tools/tools.pro index ce37ccb18b..9024a1a1bb 100644 --- a/tests/auto/corelib/tools/tools.pro +++ b/tests/auto/corelib/tools/tools.pro @@ -23,6 +23,7 @@ SUBDIRS=\ qfreelist \ qhash \ qhash_strictiterators \ + qhashfunctions \ qline \ qlinkedlist \ qlist \ -- cgit v1.2.3