diff options
author | Lars Knoll <lars.knoll@nokia.com> | 2009-03-23 09:34:13 (GMT) |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2009-03-23 09:34:13 (GMT) |
commit | 67ad0519fd165acee4a4d2a94fa502e9e4847bd0 (patch) | |
tree | 1dbf50b3dff8d5ca7e9344733968c72704eb15ff /tests/auto/qsharedmemory/qsystemlock | |
download | Qt-67ad0519fd165acee4a4d2a94fa502e9e4847bd0.zip Qt-67ad0519fd165acee4a4d2a94fa502e9e4847bd0.tar.gz Qt-67ad0519fd165acee4a4d2a94fa502e9e4847bd0.tar.bz2 |
Long live Qt!
Diffstat (limited to 'tests/auto/qsharedmemory/qsystemlock')
-rw-r--r-- | tests/auto/qsharedmemory/qsystemlock/qsystemlock.pro | 16 | ||||
-rw-r--r-- | tests/auto/qsharedmemory/qsystemlock/tst_qsystemlock.cpp | 222 |
2 files changed, 238 insertions, 0 deletions
diff --git a/tests/auto/qsharedmemory/qsystemlock/qsystemlock.pro b/tests/auto/qsharedmemory/qsystemlock/qsystemlock.pro new file mode 100644 index 0000000..042ab3f --- /dev/null +++ b/tests/auto/qsharedmemory/qsystemlock/qsystemlock.pro @@ -0,0 +1,16 @@ +CONFIG += qttest_p4 +#QT = core + +include(../src/src.pri) +win32: CONFIG += console +mac:CONFIG -= app_bundle + +DESTDIR = ./ + +DEFINES += QSHAREDMEMORY_DEBUG +DEFINES += QSYSTEMSEMAPHORE_DEBUG + +SOURCES += tst_qsystemlock.cpp +TARGET = tst_qsystemlock + + diff --git a/tests/auto/qsharedmemory/qsystemlock/tst_qsystemlock.cpp b/tests/auto/qsharedmemory/qsystemlock/tst_qsystemlock.cpp new file mode 100644 index 0000000..c72b586 --- /dev/null +++ b/tests/auto/qsharedmemory/qsystemlock/tst_qsystemlock.cpp @@ -0,0 +1,222 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, 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. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include <QtTest/QtTest> +#include <qsystemlock.h> + +//TESTED_CLASS= +//TESTED_FILES= + +#define EXISTING_SHARE "existing" + +class tst_QSystemLock : public QObject +{ + Q_OBJECT + +public: + tst_QSystemLock(); + virtual ~tst_QSystemLock(); + +public Q_SLOTS: + void init(); + void cleanup(); + +private slots: + void key_data(); + void key(); + + void basicLock(); + void complexLock(); + void lockModes(); + void sucessive(); + void processes_data(); + void processes(); + +private: + QSystemLock *existingLock; + +}; + +tst_QSystemLock::tst_QSystemLock() +{ +} + +tst_QSystemLock::~tst_QSystemLock() +{ +} + +void tst_QSystemLock::init() +{ + existingLock = new QSystemLock(EXISTING_SHARE); +} + +void tst_QSystemLock::cleanup() +{ + delete existingLock; +} + +void tst_QSystemLock::key_data() +{ + QTest::addColumn<QString>("constructorKey"); + QTest::addColumn<QString>("setKey"); + + QTest::newRow("null, null") << QString() << QString(); + QTest::newRow("null, one") << QString() << QString("one"); + QTest::newRow("one, two") << QString("one") << QString("two"); +} + +/*! + Basic key testing + */ +void tst_QSystemLock::key() +{ + QFETCH(QString, constructorKey); + QFETCH(QString, setKey); + + QSystemLock sl(constructorKey); + QCOMPARE(sl.key(), constructorKey); + sl.setKey(setKey); + QCOMPARE(sl.key(), setKey); +} + +void tst_QSystemLock::basicLock() +{ + QSystemLock lock("foo"); + QVERIFY(lock.lock()); + QVERIFY(lock.unlock()); +} + +void tst_QSystemLock::complexLock() +{ + QSystemLock lock("foo"); + QVERIFY(lock.lock(QSystemLock::ReadOnly)); + QVERIFY(lock.unlock()); + + QVERIFY(lock.lock(QSystemLock::ReadWrite)); + QVERIFY(lock.unlock()); + + QVERIFY(lock.lock(QSystemLock::ReadOnly)); + QVERIFY(lock.lock(QSystemLock::ReadOnly)); + QVERIFY(lock.unlock()); + QVERIFY(lock.unlock()); +} + +void tst_QSystemLock::lockModes() +{ + QSystemLock reader1("library"); + QSystemLock reader2("library"); + + QSystemLock librarian("library"); + QVERIFY(reader1.lock(QSystemLock::ReadOnly)); + QVERIFY(reader2.lock(QSystemLock::ReadOnly)); + QVERIFY(reader1.unlock()); + QVERIFY(reader2.unlock()); + QVERIFY(librarian.lock(QSystemLock::ReadWrite)); + QVERIFY(librarian.unlock()); +} + +void tst_QSystemLock::sucessive() +{ + QSystemLock lock("library"); + QVERIFY(lock.lock(QSystemLock::ReadOnly)); + QVERIFY(lock.lock(QSystemLock::ReadOnly)); + QVERIFY(lock.lock(QSystemLock::ReadOnly)); + QVERIFY(lock.lock(QSystemLock::ReadOnly)); + QVERIFY(lock.lock(QSystemLock::ReadOnly)); + QVERIFY(lock.unlock()); + QVERIFY(lock.unlock()); + QVERIFY(lock.unlock()); + QVERIFY(lock.unlock()); + QVERIFY(lock.unlock()); + QVERIFY(!lock.unlock()); +} + +void tst_QSystemLock::processes_data() +{ + QTest::addColumn<int>("readOnly"); + QTest::addColumn<int>("readWrite"); + for (int i = 0; i < 5; ++i) { + QTest::newRow("1/0 process") << 1 << 0; + QTest::newRow("0/1 process") << 0 << 1; + QTest::newRow("0/4 process") << 0 << 4; + QTest::newRow("1/1 process") << 1 << 1; + QTest::newRow("10/1 process") << 10 << 1; + QTest::newRow("1/10 process") << 1 << 10; + QTest::newRow("10/10 processes") << 10 << 10; + } +} + +/*! + Create external processes + */ +void tst_QSystemLock::processes() +{ + QFETCH(int, readOnly); + QFETCH(int, readWrite); + + QStringList scripts; + for (int i = 0; i < readOnly; ++i) + scripts.append("../lackey/scripts/systemlock_read.js"); + for (int i = 0; i < readWrite; ++i) + scripts.append("../lackey/scripts/systemlock_readwrite.js"); + + QList<QProcess*> consumers; + for (int i = 0; i < scripts.count(); ++i) { + QStringList arguments = QStringList() << scripts.at(i); + QProcess *p = new QProcess; + p->setProcessChannelMode(QProcess::ForwardedChannels); + consumers.append(p); + p->start("../lackey/lackey", arguments); + } + + while (!consumers.isEmpty()) { + consumers.first()->waitForFinished(3000); + consumers.first()->kill(); + QCOMPARE(consumers.first()->exitStatus(), QProcess::NormalExit); + QCOMPARE(consumers.first()->exitCode(), 0); + delete consumers.takeFirst(); + } +} + +QTEST_MAIN(tst_QSystemLock) +#include "tst_qsystemlock.moc" + |