summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qimagereader/tst_qimagereader.cpp4
-rw-r--r--tests/auto/qlocalsocket/example/client/client.pro6
-rw-r--r--tests/auto/qlocalsocket/example/server/server.pro6
-rw-r--r--tests/auto/qlocalsocket/tst_qlocalsocket.cpp85
-rw-r--r--tests/auto/qtextboundaryfinder/tst_qtextboundaryfinder.cpp111
5 files changed, 162 insertions, 50 deletions
diff --git a/tests/auto/qimagereader/tst_qimagereader.cpp b/tests/auto/qimagereader/tst_qimagereader.cpp
index 7e57973..fe2a719 100644
--- a/tests/auto/qimagereader/tst_qimagereader.cpp
+++ b/tests/auto/qimagereader/tst_qimagereader.cpp
@@ -1912,14 +1912,14 @@ void tst_QImageReader::testIgnoresFormatAndExtension()
QFETCH(QString, expected);
QList<QByteArray> formats = QImageReader::supportedImageFormats();
- QString fileNameBase = "images/" + name + ".";
+ QString fileNameBase = prefix + name + ".";
foreach (const QByteArray &f, formats) {
if (f == extension)
continue;
QFile tmp(QDir::tempPath() + "/" + name + "_" + expected + "." + f);
- QFile::copy(fileNameBase + extension, QFileInfo(tmp).absoluteFilePath());
+ QVERIFY(QFile::copy(fileNameBase + extension, QFileInfo(tmp).absoluteFilePath()));
QString format;
QImage image;
diff --git a/tests/auto/qlocalsocket/example/client/client.pro b/tests/auto/qlocalsocket/example/client/client.pro
index eb7e6e6..84f20d6 100644
--- a/tests/auto/qlocalsocket/example/client/client.pro
+++ b/tests/auto/qlocalsocket/example/client/client.pro
@@ -1,14 +1,8 @@
-######################################################################
-# Automatically generated by qmake (2.01a) Wed Jun 6 17:07:12 2007
-######################################################################
-
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
CONFIG += console
-include(../../src/src.pri)
-# Input
QT = core network
SOURCES += main.cpp
diff --git a/tests/auto/qlocalsocket/example/server/server.pro b/tests/auto/qlocalsocket/example/server/server.pro
index 438462d..bfd14d2 100644
--- a/tests/auto/qlocalsocket/example/server/server.pro
+++ b/tests/auto/qlocalsocket/example/server/server.pro
@@ -1,7 +1,3 @@
-######################################################################
-# Automatically generated by qmake (2.01a) Wed Jun 6 15:16:48 2007
-######################################################################
-
TEMPLATE = app
TARGET =
DEPENDPATH += .
@@ -11,8 +7,6 @@ CONFIG += console
QT = core network
-include(../../src/src.pri)
-
# Input
SOURCES += main.cpp
diff --git a/tests/auto/qlocalsocket/tst_qlocalsocket.cpp b/tests/auto/qlocalsocket/tst_qlocalsocket.cpp
index 44f3c12..9c09917 100644
--- a/tests/auto/qlocalsocket/tst_qlocalsocket.cpp
+++ b/tests/auto/qlocalsocket/tst_qlocalsocket.cpp
@@ -115,7 +115,8 @@ private slots:
void writeToClientAndDisconnect();
void debug();
void bytesWrittenSignal();
-
+ void syncDisconnectNotify();
+ void asyncDisconnectNotify();
#ifdef Q_OS_SYMBIAN
private:
@@ -683,25 +684,11 @@ public:
QString testLine = "test";
LocalSocket socket;
QSignalSpy spyReadyRead(&socket, SIGNAL(readyRead()));
- int tries = 0;
- do {
- socket.connectToServer("qlocalsocket_threadtest");
- if (socket.error() != QLocalSocket::ServerNotFoundError
- && socket.error() != QLocalSocket::ConnectionRefusedError)
- break;
- QTest::qWait(100);
- ++tries;
- } while ((socket.error() == QLocalSocket::ServerNotFoundError
- || socket.error() == QLocalSocket::ConnectionRefusedError)
- && tries < 1000);
- if (tries == 0 && socket.state() != QLocalSocket::ConnectedState) {
- QVERIFY(socket.waitForConnected(7000));
- QVERIFY(socket.state() == QLocalSocket::ConnectedState);
- }
+ socket.connectToServer("qlocalsocket_threadtest");
+ QVERIFY(socket.waitForConnected(1000));
// We should *not* have this signal yet!
- if (tries == 0)
- QCOMPARE(spyReadyRead.count(), 0);
+ QCOMPARE(spyReadyRead.count(), 0);
socket.waitForReadyRead();
QCOMPARE(spyReadyRead.count(), 1);
QTextStream in(&socket);
@@ -715,6 +702,8 @@ class Server : public QThread
public:
int clients;
+ QMutex mutex;
+ QWaitCondition wc;
void run()
{
QString testLine = "test";
@@ -722,6 +711,9 @@ public:
server.setMaxPendingConnections(10);
QVERIFY2(server.listen("qlocalsocket_threadtest"),
server.errorString().toLatin1().constData());
+ mutex.lock();
+ wc.wakeAll();
+ mutex.unlock();
int done = clients;
while (done > 0) {
bool timedOut = true;
@@ -746,14 +738,9 @@ void tst_QLocalSocket::threadedConnection_data()
QTest::addColumn<int>("threads");
QTest::newRow("1 client") << 1;
QTest::newRow("2 clients") << 2;
-#ifdef Q_OS_WINCE
- QTest::newRow("4 clients") << 4;
-#endif
-#ifndef Q_OS_WIN
QTest::newRow("5 clients") << 5;
- QTest::newRow("10 clients") << 10;
-#endif
#ifndef Q_OS_WINCE
+ QTest::newRow("10 clients") << 10;
QTest::newRow("20 clients") << 20;
#endif
}
@@ -770,7 +757,9 @@ void tst_QLocalSocket::threadedConnection()
server.setStackSize(0x14000);
#endif
server.clients = threads;
+ server.mutex.lock();
server.start();
+ server.wc.wait(&server.mutex);
QList<Client*> clients;
for (int i = 0; i < threads; ++i) {
@@ -784,9 +773,7 @@ void tst_QLocalSocket::threadedConnection()
server.wait();
while (!clients.isEmpty()) {
QVERIFY(clients.first()->wait(3000));
- Client *client =clients.takeFirst();
- client->terminate();
- delete client;
+ delete clients.takeFirst();
}
}
@@ -994,6 +981,7 @@ void tst_QLocalSocket::writeToClientAndDisconnect()
QLocalServer server;
QLocalSocket client;
+ QSignalSpy readChannelFinishedSpy(&client, SIGNAL(readChannelFinished()));
QVERIFY(server.listen("writeAndDisconnectServer"));
client.connectToServer("writeAndDisconnectServer");
@@ -1006,10 +994,12 @@ void tst_QLocalSocket::writeToClientAndDisconnect()
memset(buffer, 0, sizeof(buffer));
QCOMPARE(clientSocket->write(buffer, sizeof(buffer)), (qint64)sizeof(buffer));
clientSocket->waitForBytesWritten();
- clientSocket->disconnectFromServer();
- QVERIFY(client.waitForReadyRead());
+ clientSocket->close();
+ server.close();
+
+ QTRY_COMPARE(readChannelFinishedSpy.count(), 1);
QCOMPARE(client.read(buffer, sizeof(buffer)), (qint64)sizeof(buffer));
- QVERIFY(client.waitForDisconnected());
+ client.waitForDisconnected();
QCOMPARE(client.state(), QLocalSocket::UnconnectedState);
}
@@ -1065,6 +1055,41 @@ void tst_QLocalSocket::bytesWrittenSignal()
QVERIFY(writeThread.wait(2000));
}
+void tst_QLocalSocket::syncDisconnectNotify()
+{
+#ifdef Q_OS_SYMBIAN
+ unlink("syncDisconnectNotify");
+#endif
+
+ QLocalServer server;
+ QVERIFY(server.listen("syncDisconnectNotify"));
+ QLocalSocket client;
+ client.connectToServer("syncDisconnectNotify");
+ QVERIFY(server.waitForNewConnection());
+ QLocalSocket* serverSocket = server.nextPendingConnection();
+ QVERIFY(serverSocket);
+ delete serverSocket;
+ QCOMPARE(client.waitForReadyRead(), false);
+}
+
+void tst_QLocalSocket::asyncDisconnectNotify()
+{
+#ifdef Q_OS_SYMBIAN
+ unlink("asyncDisconnectNotify");
+#endif
+
+ QLocalServer server;
+ QVERIFY(server.listen("asyncDisconnectNotify"));
+ QLocalSocket client;
+ QSignalSpy disconnectedSpy(&client, SIGNAL(disconnected()));
+ client.connectToServer("asyncDisconnectNotify");
+ QVERIFY(server.waitForNewConnection());
+ QLocalSocket* serverSocket = server.nextPendingConnection();
+ QVERIFY(serverSocket);
+ delete serverSocket;
+ QTRY_VERIFY(!disconnectedSpy.isEmpty());
+}
+
#ifdef Q_OS_SYMBIAN
void tst_QLocalSocket::unlink(QString name)
{
diff --git a/tests/auto/qtextboundaryfinder/tst_qtextboundaryfinder.cpp b/tests/auto/qtextboundaryfinder/tst_qtextboundaryfinder.cpp
index c60af5e..a562fbe 100644
--- a/tests/auto/qtextboundaryfinder/tst_qtextboundaryfinder.cpp
+++ b/tests/auto/qtextboundaryfinder/tst_qtextboundaryfinder.cpp
@@ -71,6 +71,10 @@ private slots:
void isAtWordStart();
void fastConstructor();
void isAtBoundaryLine();
+ void toNextBoundary_data();
+ void toNextBoundary();
+ void toPreviousBoundary_data();
+ void toPreviousBoundary();
};
tst_QTextBoundaryFinder::tst_QTextBoundaryFinder()
@@ -292,25 +296,120 @@ void tst_QTextBoundaryFinder::fastConstructor()
void tst_QTextBoundaryFinder::isAtBoundaryLine()
{
- // idx 0 1 2 3 4 5
- // break? - - - + - +
+ // idx 0 1 2 3 4 5 6
+ // break? - - - - + - +
QChar s[] = { 0x0061, 0x00AD, 0x0062, 0x0009, 0x0063, 0x0064 };
QString text(s, sizeof(s)/sizeof(s[0]));
- qDebug() << "text = " << text << ", length = " << text.length();
+// qDebug() << "text = " << text << ", length = " << text.length();
QTextBoundaryFinder finder(QTextBoundaryFinder::Line, text.constData(), text.length(), /*buffer*/0, /*buffer size*/0);
finder.setPosition(0);
- QVERIFY(!finder.isAtBoundary());
+ QVERIFY(finder.isAtBoundary());
finder.setPosition(1);
QVERIFY(!finder.isAtBoundary());
finder.setPosition(2);
QVERIFY(!finder.isAtBoundary());
finder.setPosition(3);
- QVERIFY(finder.isAtBoundary());
- finder.setPosition(4);
QVERIFY(!finder.isAtBoundary());
+ finder.setPosition(4);
+ QVERIFY(finder.isAtBoundary());
finder.setPosition(5);
+ QVERIFY(!finder.isAtBoundary());
+ finder.setPosition(6);
QVERIFY(finder.isAtBoundary());
}
+Q_DECLARE_METATYPE(QList<int>)
+
+void tst_QTextBoundaryFinder::toNextBoundary_data()
+{
+ QTest::addColumn<QString>("text");
+ QTest::addColumn<int>("type");
+ QTest::addColumn< QList<int> >("boundaries");
+
+ QList<int> boundaries;
+ boundaries << 0 << 3 << 4 << 7 << 8 << 11 << 12 << 13 << 16 << 17 << 20 << 21 << 24 << 25;
+ QTest::newRow("Line") << QString("Aaa bbb ccc. Ddd eee fff.") << int(QTextBoundaryFinder::Word) \
+ << boundaries;
+
+ boundaries.clear();
+ boundaries << 0 << 13 << 25;
+ QTest::newRow("Line") << QString("Aaa bbb ccc. Ddd eee fff.") << int(QTextBoundaryFinder::Sentence) \
+ << boundaries;
+
+ boundaries.clear();
+ boundaries << 0 << 4 << 8 << 13 << 17 << 21 << 25;
+ QTest::newRow("Line") << QString("Aaa bbb ccc. Ddd eee fff.") << int(QTextBoundaryFinder::Line) \
+ << boundaries;
+
+ boundaries.clear();
+ boundaries << 0 << 5 << 9 << 15 << 17 << 21 << 28;
+ QTest::newRow("Line") << QString::fromUtf8("Diga-nos qualé a sua opinião") << int(QTextBoundaryFinder::Line)
+ << boundaries;
+
+}
+
+void tst_QTextBoundaryFinder::toNextBoundary()
+{
+ QFETCH(QString, text);
+ QFETCH(int, type);
+ QFETCH(QList<int>, boundaries);
+
+ QList<int> foundBoundaries;
+ QTextBoundaryFinder boundaryFinder(QTextBoundaryFinder::BoundaryType(type), text);
+ boundaryFinder.toStart();
+ for(int next = 0; next != -1; next = boundaryFinder.toNextBoundary())
+ foundBoundaries << next;
+ QCOMPARE(boundaries, foundBoundaries);
+}
+
+void tst_QTextBoundaryFinder::toPreviousBoundary_data()
+{
+ QTest::addColumn<QString>("text");
+ QTest::addColumn<int>("type");
+ QTest::addColumn< QList<int> >("boundaries");
+
+ QList<int> boundaries;
+ boundaries << 25 << 24 << 21 << 20 << 17 << 16 << 13 << 12 << 11 << 8 << 7 << 4 << 3 << 0;
+ QTest::newRow("Line") << QString("Aaa bbb ccc. Ddd eee fff.") << int(QTextBoundaryFinder::Word)
+ << boundaries;
+
+ boundaries.clear();
+ boundaries << 25 << 13 << 0;
+ QTest::newRow("Line") << QString("Aaa bbb ccc. Ddd eee fff.") << int(QTextBoundaryFinder::Sentence)
+ << boundaries;
+
+ boundaries.clear();
+ boundaries << 25 << 21 << 17 << 13 << 8 << 4 << 0;
+ QTest::newRow("Line") << QString("Aaa bbb ccc. Ddd eee fff.") << int(QTextBoundaryFinder::Line)
+ << boundaries;
+
+ boundaries.clear();
+ boundaries << 28 << 21 << 17 << 15 << 9 << 5 << 0;
+ QTest::newRow("Line") << QString::fromUtf8("Diga-nos qualé a sua opinião") << int(QTextBoundaryFinder::Line)
+ << boundaries;
+
+}
+
+void tst_QTextBoundaryFinder::toPreviousBoundary()
+{
+ QFETCH(QString, text);
+ QFETCH(int, type);
+ QFETCH(QList<int>, boundaries);
+
+ QList<int> foundBoundaries;
+ QTextBoundaryFinder boundaryFinder(QTextBoundaryFinder::BoundaryType(type), text);
+ boundaryFinder.toEnd();
+ for (int previous = boundaryFinder.position();
+ previous != -1;
+ previous = boundaryFinder.toPreviousBoundary())
+ {
+ foundBoundaries << previous;
+ }
+ QCOMPARE(boundaries, foundBoundaries);
+}
+
+
+
+
QTEST_MAIN(tst_QTextBoundaryFinder)
#include "tst_qtextboundaryfinder.moc"