author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 19 Feb 2010 23:40:16 +0200 | |
branch | RCL_3 |
changeset 4 | 3b1da2848fc7 |
parent 3 | 41300fa6a67c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
||
43 |
#include <QtTest/QtTest> |
|
44 |
#include <qsystemlock.h> |
|
45 |
||
46 |
//TESTED_CLASS= |
|
47 |
//TESTED_FILES= |
|
48 |
||
49 |
#ifdef Q_OS_SYMBIAN |
|
50 |
// In Symbian OS test data is located in applications private dir |
|
51 |
// And underlying Open C have application private dir in default search path |
|
52 |
#define SRCDIR "" |
|
53 |
#endif |
|
54 |
||
55 |
||
56 |
#define EXISTING_SHARE "existing" |
|
57 |
||
58 |
class tst_QSystemLock : public QObject |
|
59 |
{ |
|
60 |
Q_OBJECT |
|
61 |
||
62 |
public: |
|
63 |
tst_QSystemLock(); |
|
64 |
virtual ~tst_QSystemLock(); |
|
65 |
||
66 |
public Q_SLOTS: |
|
67 |
void init(); |
|
68 |
void cleanup(); |
|
69 |
||
70 |
private slots: |
|
71 |
void key_data(); |
|
72 |
void key(); |
|
73 |
||
74 |
void basicLock(); |
|
75 |
void complexLock(); |
|
76 |
void lockModes(); |
|
77 |
void sucessive(); |
|
78 |
void processes_data(); |
|
79 |
void processes(); |
|
80 |
||
81 |
private: |
|
82 |
QSystemLock *existingLock; |
|
83 |
||
84 |
}; |
|
85 |
||
86 |
tst_QSystemLock::tst_QSystemLock() |
|
87 |
{ |
|
88 |
} |
|
89 |
||
90 |
tst_QSystemLock::~tst_QSystemLock() |
|
91 |
{ |
|
92 |
} |
|
93 |
||
94 |
void tst_QSystemLock::init() |
|
95 |
{ |
|
96 |
existingLock = new QSystemLock(EXISTING_SHARE); |
|
97 |
} |
|
98 |
||
99 |
void tst_QSystemLock::cleanup() |
|
100 |
{ |
|
101 |
delete existingLock; |
|
102 |
} |
|
103 |
||
104 |
void tst_QSystemLock::key_data() |
|
105 |
{ |
|
106 |
QTest::addColumn<QString>("constructorKey"); |
|
107 |
QTest::addColumn<QString>("setKey"); |
|
108 |
||
109 |
QTest::newRow("null, null") << QString() << QString(); |
|
110 |
QTest::newRow("null, one") << QString() << QString("one"); |
|
111 |
QTest::newRow("one, two") << QString("one") << QString("two"); |
|
112 |
} |
|
113 |
||
114 |
/*! |
|
115 |
Basic key testing |
|
116 |
*/ |
|
117 |
void tst_QSystemLock::key() |
|
118 |
{ |
|
119 |
QFETCH(QString, constructorKey); |
|
120 |
QFETCH(QString, setKey); |
|
121 |
||
122 |
QSystemLock sl(constructorKey); |
|
123 |
QCOMPARE(sl.key(), constructorKey); |
|
124 |
sl.setKey(setKey); |
|
125 |
QCOMPARE(sl.key(), setKey); |
|
126 |
} |
|
127 |
||
128 |
void tst_QSystemLock::basicLock() |
|
129 |
{ |
|
130 |
QSystemLock lock("foo"); |
|
131 |
QVERIFY(lock.lock()); |
|
132 |
QVERIFY(lock.unlock()); |
|
133 |
} |
|
134 |
||
135 |
void tst_QSystemLock::complexLock() |
|
136 |
{ |
|
137 |
QSystemLock lock("foo"); |
|
138 |
QVERIFY(lock.lock(QSystemLock::ReadOnly)); |
|
139 |
QVERIFY(lock.unlock()); |
|
140 |
||
141 |
QVERIFY(lock.lock(QSystemLock::ReadWrite)); |
|
142 |
QVERIFY(lock.unlock()); |
|
143 |
||
144 |
QVERIFY(lock.lock(QSystemLock::ReadOnly)); |
|
145 |
QVERIFY(lock.lock(QSystemLock::ReadOnly)); |
|
146 |
QVERIFY(lock.unlock()); |
|
147 |
QVERIFY(lock.unlock()); |
|
148 |
} |
|
149 |
||
150 |
void tst_QSystemLock::lockModes() |
|
151 |
{ |
|
152 |
QSystemLock reader1("library"); |
|
153 |
QSystemLock reader2("library"); |
|
154 |
||
155 |
QSystemLock librarian("library"); |
|
156 |
QVERIFY(reader1.lock(QSystemLock::ReadOnly)); |
|
157 |
QVERIFY(reader2.lock(QSystemLock::ReadOnly)); |
|
158 |
QVERIFY(reader1.unlock()); |
|
159 |
QVERIFY(reader2.unlock()); |
|
160 |
QVERIFY(librarian.lock(QSystemLock::ReadWrite)); |
|
161 |
QVERIFY(librarian.unlock()); |
|
162 |
} |
|
163 |
||
164 |
void tst_QSystemLock::sucessive() |
|
165 |
{ |
|
166 |
QSystemLock lock("library"); |
|
167 |
QVERIFY(lock.lock(QSystemLock::ReadOnly)); |
|
168 |
QVERIFY(lock.lock(QSystemLock::ReadOnly)); |
|
169 |
QVERIFY(lock.lock(QSystemLock::ReadOnly)); |
|
170 |
QVERIFY(lock.lock(QSystemLock::ReadOnly)); |
|
171 |
QVERIFY(lock.lock(QSystemLock::ReadOnly)); |
|
172 |
QVERIFY(lock.unlock()); |
|
173 |
QVERIFY(lock.unlock()); |
|
174 |
QVERIFY(lock.unlock()); |
|
175 |
QVERIFY(lock.unlock()); |
|
176 |
QVERIFY(lock.unlock()); |
|
177 |
QVERIFY(!lock.unlock()); |
|
178 |
} |
|
179 |
||
180 |
void tst_QSystemLock::processes_data() |
|
181 |
{ |
|
182 |
QTest::addColumn<int>("readOnly"); |
|
183 |
QTest::addColumn<int>("readWrite"); |
|
184 |
for (int i = 0; i < 5; ++i) { |
|
185 |
QTest::newRow("1/0 process") << 1 << 0; |
|
186 |
QTest::newRow("0/1 process") << 0 << 1; |
|
187 |
QTest::newRow("0/4 process") << 0 << 4; |
|
188 |
QTest::newRow("1/1 process") << 1 << 1; |
|
189 |
QTest::newRow("10/1 process") << 10 << 1; |
|
190 |
QTest::newRow("1/10 process") << 1 << 10; |
|
191 |
QTest::newRow("10/10 processes") << 10 << 10; |
|
192 |
} |
|
193 |
} |
|
194 |
||
195 |
/*! |
|
196 |
Create external processes |
|
197 |
*/ |
|
198 |
void tst_QSystemLock::processes() |
|
199 |
{ |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
200 |
QSKIP("This test takes about 15 minutes and needs to be trimmed down before we can re-enable it", SkipAll); |
0 | 201 |
QFETCH(int, readOnly); |
202 |
QFETCH(int, readWrite); |
|
203 |
||
204 |
QStringList scripts; |
|
205 |
for (int i = 0; i < readOnly; ++i) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
206 |
scripts.append(QFileInfo(SRCDIR "/../lackey/scripts/systemlock_read.js").absoluteFilePath() ); |
0 | 207 |
for (int i = 0; i < readWrite; ++i) |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
208 |
scripts.append(QFileInfo(SRCDIR "/../lackey/scripts/systemlock_readwrite.js").absoluteFilePath()); |
0 | 209 |
|
210 |
QList<QProcess*> consumers; |
|
211 |
unsigned int failedProcesses = 0; |
|
212 |
for (int i = 0; i < scripts.count(); ++i) { |
|
213 |
||
214 |
QStringList arguments = QStringList() << scripts.at(i); |
|
215 |
QProcess *p = new QProcess; |
|
216 |
p->setProcessChannelMode(QProcess::ForwardedChannels); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
217 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
218 |
p->start("../lackey/lackey", arguments); |
0 | 219 |
// test, if the process could be started. |
220 |
||
221 |
if (p->waitForStarted(2000)) |
|
222 |
consumers.append(p); |
|
223 |
else |
|
224 |
++failedProcesses; |
|
225 |
} |
|
226 |
||
227 |
while (!consumers.isEmpty()) { |
|
228 |
consumers.first()->waitForFinished(3000); |
|
229 |
consumers.first()->kill(); |
|
230 |
QCOMPARE(consumers.first()->exitStatus(), QProcess::NormalExit); |
|
231 |
QCOMPARE(consumers.first()->exitCode(), 0); |
|
232 |
delete consumers.takeFirst(); |
|
233 |
} |
|
234 |
QCOMPARE(failedProcesses, (unsigned int)(0)); |
|
235 |
} |
|
236 |
||
237 |
QTEST_MAIN(tst_QSystemLock) |
|
238 |
#include "tst_qsystemlock.moc" |
|
239 |