diff options
Diffstat (limited to 'tests/auto/corelib/tools/qcontiguouscache')
3 files changed, 48 insertions, 56 deletions
diff --git a/tests/auto/corelib/tools/qcontiguouscache/CMakeLists.txt b/tests/auto/corelib/tools/qcontiguouscache/CMakeLists.txt new file mode 100644 index 0000000000..5c32c34023 --- /dev/null +++ b/tests/auto/corelib/tools/qcontiguouscache/CMakeLists.txt @@ -0,0 +1,17 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +##################################################################### +## tst_qcontiguouscache Test: +##################################################################### + +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qcontiguouscache LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + +qt_internal_add_test(tst_qcontiguouscache + SOURCES + tst_qcontiguouscache.cpp +) diff --git a/tests/auto/corelib/tools/qcontiguouscache/qcontiguouscache.pro b/tests/auto/corelib/tools/qcontiguouscache/qcontiguouscache.pro deleted file mode 100644 index d79bd16c76..0000000000 --- a/tests/auto/corelib/tools/qcontiguouscache/qcontiguouscache.pro +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG += testcase -TARGET = tst_qcontiguouscache -QT = core testlib -SOURCES = tst_qcontiguouscache.cpp diff --git a/tests/auto/corelib/tools/qcontiguouscache/tst_qcontiguouscache.cpp b/tests/auto/corelib/tools/qcontiguouscache/tst_qcontiguouscache.cpp index f305d63d46..ca110b1240 100644 --- a/tests/auto/corelib/tools/qcontiguouscache/tst_qcontiguouscache.cpp +++ b/tests/auto/corelib/tools/qcontiguouscache/tst_qcontiguouscache.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QObject> #include <QTest> @@ -75,20 +50,24 @@ void tst_QContiguousCache::empty() { QContiguousCache<int> c(10); QCOMPARE(c.capacity(), 10); + QCOMPARE(c.size(), 0); + // NOLINTNEXTLINE(qt-port-to-std-compatible-api): Test both size() and count() QCOMPARE(c.count(), 0); QVERIFY(c.isEmpty()); c.append(1); + // NOLINTNEXTLINE(qt-port-to-std-compatible-api): Test both size() and count() QCOMPARE(c.count(), 1); + QCOMPARE(c.size(), 1); QVERIFY(!c.isEmpty()); c.clear(); QCOMPARE(c.capacity(), 10); - QCOMPARE(c.count(), 0); + QCOMPARE(c.size(), 0); QVERIFY(c.isEmpty()); c.prepend(1); - QCOMPARE(c.count(), 1); + QCOMPARE(c.size(), 1); QVERIFY(!c.isEmpty()); c.clear(); - QCOMPARE(c.count(), 0); + QCOMPARE(c.size(), 0); QVERIFY(c.isEmpty()); QCOMPARE(c.capacity(), 10); } @@ -99,32 +78,32 @@ void tst_QContiguousCache::swap() c1.append(1); c1.swap(c2); QCOMPARE(c1.capacity(), 100); - QCOMPARE(c1.count(), 0 ); + QCOMPARE(c1.size(), 0 ); QCOMPARE(c2.capacity(), 10 ); - QCOMPARE(c2.count(), 1 ); + QCOMPARE(c2.size(), 1 ); } void tst_QContiguousCache::append_data() { - QTest::addColumn<int>("start"); - QTest::addColumn<int>("count"); - QTest::addColumn<int>("cacheSize"); + QTest::addColumn<qsizetype>("start"); + QTest::addColumn<qsizetype>("count"); + QTest::addColumn<qsizetype>("cacheSize"); QTest::addColumn<bool>("invalidIndexes"); - QTest::newRow("0+30[10]") << 0 << 30 << 10 << false; - QTest::newRow("300+30[10]") << 300 << 30 << 10 << false; - QTest::newRow("MAX-10+30[10]") << INT_MAX-10 << 30 << 10 << true; + QTest::newRow("0+30[10]") << qsizetype(0) << qsizetype(30) << qsizetype(10) << false; + QTest::newRow("300+30[10]") << qsizetype(300) << qsizetype(30) << qsizetype(10) << false; + QTest::newRow("MAX-10+30[10]") << std::numeric_limits<qsizetype>::max()-10 << qsizetype(30) << qsizetype(10) << true; } void tst_QContiguousCache::append() { - QFETCH(int, start); - QFETCH(int, count); - QFETCH(int, cacheSize); + QFETCH(qsizetype, start); + QFETCH(qsizetype, count); + QFETCH(qsizetype, cacheSize); QFETCH(bool, invalidIndexes); - int i, j; - QContiguousCache<int> c(cacheSize); + qsizetype i, j; + QContiguousCache<qsizetype> c(cacheSize); i = 1; QCOMPARE(c.available(), cacheSize); @@ -134,10 +113,10 @@ void tst_QContiguousCache::append() c.insert(start, i++); while (i < count) { c.append(i); - QCOMPARE(c.available(), qMax(0, cacheSize - i)); - QCOMPARE(c.first(), qMax(1, i-cacheSize+1)); + QCOMPARE(c.available(), qMax(qsizetype(0), cacheSize - i)); + QCOMPARE(c.first(), qMax(qsizetype(1), i-cacheSize+1)); QCOMPARE(c.last(), i); - QCOMPARE(c.count(), qMin(i, cacheSize)); + QCOMPARE(c.size(), qMin(i, cacheSize)); QCOMPARE(c.isFull(), i >= cacheSize); i++; } @@ -150,7 +129,7 @@ void tst_QContiguousCache::append() // test taking from end until empty. for (j = 0; j < cacheSize; j++, i--) { QCOMPARE(c.takeLast(), i-1); - QCOMPARE(c.count(), cacheSize-j-1); + QCOMPARE(c.size(), cacheSize-j-1); QCOMPARE(c.available(), j+1); QVERIFY(!c.isFull()); QCOMPARE(c.isEmpty(), j==cacheSize-1); @@ -188,7 +167,7 @@ void tst_QContiguousCache::prepend() QCOMPARE(c.available(), qMax(0, cacheSize - i)); QCOMPARE(c.last(), qMax(1, i-cacheSize+1)); QCOMPARE(c.first(), i); - QCOMPARE(c.count(), qMin(i, cacheSize)); + QCOMPARE(c.size(), qMin(i, cacheSize)); QCOMPARE(c.isFull(), i >= cacheSize); i++; } @@ -201,7 +180,7 @@ void tst_QContiguousCache::prepend() // test taking from start until empty. for (j = 0; j < cacheSize; j++, i--) { QCOMPARE(c.takeFirst(), i-1); - QCOMPARE(c.count(), cacheSize-j-1); + QCOMPARE(c.size(), cacheSize-j-1); QCOMPARE(c.available(), j+1); QVERIFY(!c.isFull()); QCOMPARE(c.isEmpty(), j==cacheSize-1); @@ -321,7 +300,7 @@ void tst_QContiguousCache::setCapacity() for (i = 280; i < 310; ++i) contiguousCache.insert(i, i); QCOMPARE(contiguousCache.capacity(), 100); - QCOMPARE(contiguousCache.count(), 30); + QCOMPARE(contiguousCache.size(), 30); QCOMPARE(contiguousCache.firstIndex(), 280); QCOMPARE(contiguousCache.lastIndex(), 309); @@ -333,7 +312,7 @@ void tst_QContiguousCache::setCapacity() contiguousCache.setCapacity(150); QCOMPARE(contiguousCache.capacity(), 150); - QCOMPARE(contiguousCache.count(), 30); + QCOMPARE(contiguousCache.size(), 30); QCOMPARE(contiguousCache.firstIndex(), 280); QCOMPARE(contiguousCache.lastIndex(), 309); @@ -345,7 +324,7 @@ void tst_QContiguousCache::setCapacity() contiguousCache.setCapacity(20); QCOMPARE(contiguousCache.capacity(), 20); - QCOMPARE(contiguousCache.count(), 20); + QCOMPARE(contiguousCache.size(), 20); QCOMPARE(contiguousCache.firstIndex(), 290); QCOMPARE(contiguousCache.lastIndex(), 309); |