From 5c27f0a2fb772279fb3e4d60f7c879f5cecb3352 Mon Sep 17 00:00:00 2001 From: Holger Ihrig Date: Fri, 26 Aug 2011 15:03:33 +0200 Subject: Moving relevant tests to corelib/tools Task-number: QTBUG-21066 Change-Id: I650f8f7826b9feea7c1484f06e03e10c68ec2b65 Reviewed-on: http://codereview.qt.nokia.com/3712 Reviewed-by: Qt Sanity Bot Reviewed-by: Sergio Ahumada --- tests/auto/corelib/tools/qfreelist/qfreelist.pro | 5 + .../auto/corelib/tools/qfreelist/tst_qfreelist.cpp | 179 +++++++++++++++++++++ 2 files changed, 184 insertions(+) create mode 100644 tests/auto/corelib/tools/qfreelist/qfreelist.pro create mode 100644 tests/auto/corelib/tools/qfreelist/tst_qfreelist.cpp (limited to 'tests/auto/corelib/tools/qfreelist') diff --git a/tests/auto/corelib/tools/qfreelist/qfreelist.pro b/tests/auto/corelib/tools/qfreelist/qfreelist.pro new file mode 100644 index 0000000000..0afa12b8a8 --- /dev/null +++ b/tests/auto/corelib/tools/qfreelist/qfreelist.pro @@ -0,0 +1,5 @@ +load(qttest_p4) +SOURCES += tst_qfreelist.cpp +QT += core-private +QT -= gui +!contains(QT_CONFIG,private_tests): SOURCES += $$QT.core.sources/tools/qfreelist.cpp diff --git a/tests/auto/corelib/tools/qfreelist/tst_qfreelist.cpp b/tests/auto/corelib/tools/qfreelist/tst_qfreelist.cpp new file mode 100644 index 0000000000..139d76e64a --- /dev/null +++ b/tests/auto/corelib/tools/qfreelist/tst_qfreelist.cpp @@ -0,0 +1,179 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia 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. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include +#include +#include +#include +#include +#include + +//TESTED_CLASS=QFreeList +//TESTED_FILES=corelib/tools/qfreelist_p.h + +class tst_QFreeList : public QObject +{ + Q_OBJECT + +private slots: + void basicTest(); + void customized(); + void threadedTest(); +}; + +void tst_QFreeList::basicTest() +{ + { + QFreeList voidFreeList; + int zero = voidFreeList.next(); + int one = voidFreeList.next(); + int two = voidFreeList.next(); + QCOMPARE(zero, 0); + QCOMPARE(one, 1); + QCOMPARE(two, 2); + voidFreeList[zero]; + voidFreeList[one]; + voidFreeList[two]; + voidFreeList.at(zero); + voidFreeList.at(one); + voidFreeList.at(two); + voidFreeList.release(one); + int next = voidFreeList.next(); + QCOMPARE(next, 1); + voidFreeList[next]; + voidFreeList.at(next); + } + + { + QFreeList intFreeList; + int zero = intFreeList.next(); + int one = intFreeList.next(); + int two = intFreeList.next(); + QCOMPARE(zero, 0); + QCOMPARE(one, 1); + QCOMPARE(two, 2); + intFreeList[zero] = zero; + intFreeList[one] = one; + intFreeList[two] = two; + QCOMPARE(intFreeList.at(zero), zero); + QCOMPARE(intFreeList.at(one), one); + QCOMPARE(intFreeList.at(two), two); + intFreeList.release(one); + int next = intFreeList.next(); + QCOMPARE(next, 1); + QCOMPARE(intFreeList.at(next), one); + intFreeList[next] = -one; + QCOMPARE(intFreeList.at(next), -one); + } +} + +struct CustomFreeListConstants : public QFreeListDefaultConstants +{ + enum { + InitialNextValue = 50, + BlockCount = 10 + }; + + static const int Sizes[10]; +}; + +const int CustomFreeListConstants::Sizes[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 16777216 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 }; + +void tst_QFreeList::customized() +{ + QFreeList customFreeList; + int next = customFreeList.next(); + QCOMPARE(next, int(CustomFreeListConstants::InitialNextValue)); + customFreeList[next]; + customFreeList.at(next); + customFreeList.release(next); +} + +enum { TimeLimit = 3000 }; + +class FreeListThread : public QThread +{ + static QFreeList freelist; + +public: + inline FreeListThread() : QThread() { } + inline void run() + { + QElapsedTimer t; + t.start(); + QList needToRelease; + do { + int i = freelist.next(); + int j = freelist.next(); + int k = freelist.next(); + int l = freelist.next(); + freelist.release(k); + int n = freelist.next(); + int m = freelist.next(); + freelist.release(l); + freelist.release(m); + freelist.release(n); + freelist.release(j); + // freelist.release(i); + needToRelease << i; + } while (t.elapsed() < TimeLimit); + + foreach (int x, needToRelease) + freelist.release(x); + } +}; + +QFreeList FreeListThread::freelist; + +void tst_QFreeList::threadedTest() +{ + const int ThreadCount = QThread::idealThreadCount(); + FreeListThread *threads = new FreeListThread[ThreadCount]; + for (int i = 0; i < ThreadCount; ++i) + threads[i].start(); + for (int i = 0; i < ThreadCount; ++i) + threads[i].wait(); + delete [] threads; +} + +QTEST_MAIN(tst_QFreeList) +#include "tst_qfreelist.moc" -- cgit v1.2.3