summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorQt Continuous Integration System <qt-info@nokia.com>2011-02-20 19:56:49 (GMT)
committerQt Continuous Integration System <qt-info@nokia.com>2011-02-20 19:56:49 (GMT)
commit81c8759c23969dad0d300d844341379bfcd6611a (patch)
tree6cc7bb3f15e28d1444b13035930cb38079b2927f /tests
parent5981173f0451736bf2b53e7bf36dbbd02d8f3904 (diff)
parent13e9642616ab480d09bda2603cc89dcaea7a1ad6 (diff)
downloadQt-81c8759c23969dad0d300d844341379bfcd6611a.zip
Qt-81c8759c23969dad0d300d844341379bfcd6611a.tar.gz
Qt-81c8759c23969dad0d300d844341379bfcd6611a.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/oslo-staging-1 into 4.7-integration
* '4.7' of scm.dev.nokia.troll.no:qt/oslo-staging-1: (21 commits) Autotest: make at least one update before checking if more are needed Fix warning about id maybe used when uninitialised Doc: setSslConfiguration also sets the CA certificates Autotest: check that the type received is the expected one Attempt to fix symbian 3.1 and 3.2 compile break. Prevents crashing when ICO file has bad color table value directfb: fix crash in client/server mode of qws Make Qt/DirectFB less verbose about failing to load pixmaps. Autotest: don't use the deprecated signal from QDBusConnectionInterface Autotest: be nicer to the subprocess and SIGTERM it Fix warnings in QtDeclarative Autotest: avoid memory leaks if test fails QtDBus: Make sure we can receive unknown types QtDBus meta object: keep methods, signals and props with unknown types Autotest: add a new test for parsing an introspection with unknown types Make the QtDBus parser not complain about unknown things fix-layer-getsurface-result-check-for-screen-size-determination Bump QtWebKit version to 2.0.2 SSL: fix memory leak when loading certificates on Mac OS X Add a mutex to protect the access to the QSet. ...
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qdbusinterface/tst_qdbusinterface.cpp44
-rw-r--r--tests/auto/qdbusmarshall/test/test.pro3
-rw-r--r--tests/auto/qdbusmarshall/tst_qdbusmarshall.cpp210
-rw-r--r--tests/auto/qdbusxmlparser/tst_qdbusxmlparser.cpp13
-rw-r--r--tests/auto/qfuturewatcher/tst_qfuturewatcher.cpp12
-rw-r--r--tests/auto/qtconcurrentiteratekernel/tst_qtconcurrentiteratekernel.cpp5
6 files changed, 236 insertions, 51 deletions
diff --git a/tests/auto/qdbusinterface/tst_qdbusinterface.cpp b/tests/auto/qdbusinterface/tst_qdbusinterface.cpp
index c1938b1..39f0677 100644
--- a/tests/auto/qdbusinterface/tst_qdbusinterface.cpp
+++ b/tests/auto/qdbusinterface/tst_qdbusinterface.cpp
@@ -169,6 +169,25 @@ public slots:
int MyObject::callCount = 0;
QVariantList MyObject::callArgs;
+class MyObjectUnknownType: public QObject
+{
+ Q_OBJECT
+ Q_CLASSINFO("D-Bus Interface", "com.trolltech.QtDBus.MyObject")
+ Q_CLASSINFO("D-Bus Introspection", ""
+" <interface name=\"com.trolltech.QtDBus.MyObjectUnknownTypes\" >\n"
+" <property access=\"readwrite\" type=\"~\" name=\"prop1\" />\n"
+" <signal name=\"somethingHappened\" >\n"
+" <arg direction=\"out\" type=\"~\" />\n"
+" </signal>\n"
+" <method name=\"ping\" >\n"
+" <arg direction=\"in\" type=\"~\" name=\"ping\" />\n"
+" <arg direction=\"out\" type=\"~\" name=\"ping\" />\n"
+" </method>\n"
+" <method name=\"regularMethod\" />\n"
+" </interface>\n"
+ "")
+};
+
class Spy: public QObject
{
Q_OBJECT
@@ -228,6 +247,7 @@ private slots:
void notValidDerived();
void invalidAfterServiceOwnerChanged();
void introspect();
+ void introspectUnknownTypes();
void callMethod();
void invokeMethod();
void invokeMethodWithReturn();
@@ -250,8 +270,7 @@ void tst_QDBusInterface::initTestCase()
con.registerObject("/", &obj, QDBusConnection::ExportAllProperties
| QDBusConnection::ExportAllSlots
- | QDBusConnection::ExportAllInvokables
- | QDBusConnection::ExportChildObjects);
+ | QDBusConnection::ExportAllInvokables);
}
void tst_QDBusInterface::notConnected()
@@ -322,6 +341,27 @@ void tst_QDBusInterface::introspect()
QVERIFY(mo->indexOfProperty("complexProp") != -1);
}
+void tst_QDBusInterface::introspectUnknownTypes()
+{
+ QDBusConnection con = QDBusConnection::sessionBus();
+ MyObjectUnknownType obj;
+ con.registerObject("/unknownTypes", &obj, QDBusConnection::ExportAllContents);
+ QDBusInterface iface(QDBusConnection::sessionBus().baseService(), QLatin1String("/unknownTypes"),
+ "com.trolltech.QtDBus.MyObjectUnknownTypes");
+
+ const QMetaObject *mo = iface.metaObject();
+ QVERIFY(mo->indexOfMethod("regularMethod()") != -1); // this is the control
+ QVERIFY(mo->indexOfMethod("somethingHappened(QDBusRawType<0x7e>*)") != -1);
+
+ QVERIFY(mo->indexOfMethod("ping(QDBusRawType<0x7e>*)") != -1);
+ int midx = mo->indexOfMethod("ping(QDBusRawType<0x7e>*)");
+ QCOMPARE(mo->method(midx).typeName(), "QDBusRawType<0x7e>*");
+
+ QVERIFY(mo->indexOfProperty("prop1") != -1);
+ int pidx = mo->indexOfProperty("prop1");
+ QCOMPARE(mo->property(pidx).typeName(), "QDBusRawType<0x7e>*");
+}
+
void tst_QDBusInterface::callMethod()
{
QDBusConnection con = QDBusConnection::sessionBus();
diff --git a/tests/auto/qdbusmarshall/test/test.pro b/tests/auto/qdbusmarshall/test/test.pro
index 8901999..71fc656 100644
--- a/tests/auto/qdbusmarshall/test/test.pro
+++ b/tests/auto/qdbusmarshall/test/test.pro
@@ -5,4 +5,5 @@ TARGET = ../tst_qdbusmarshall
QT = core
QT += dbus
-
+LIBS += $$QT_LIBS_DBUS
+QMAKE_CXXFLAGS += $$QT_CFLAGS_DBUS
diff --git a/tests/auto/qdbusmarshall/tst_qdbusmarshall.cpp b/tests/auto/qdbusmarshall/tst_qdbusmarshall.cpp
index c05e49c..9bae6af 100644
--- a/tests/auto/qdbusmarshall/tst_qdbusmarshall.cpp
+++ b/tests/auto/qdbusmarshall/tst_qdbusmarshall.cpp
@@ -38,7 +38,6 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#define DBUS_API_SUBJECT_TO_CHANGE
#include <QtCore/QtCore>
#include <QtTest/QtTest>
#include <QtDBus/QtDBus>
@@ -47,6 +46,8 @@
#include "common.h"
#include <limits>
+#include <dbus/dbus.h>
+
static const char serviceName[] = "com.trolltech.autotests.qpong";
static const char objectPath[] = "/com/trolltech/qpong";
static const char *interfaceName = serviceName;
@@ -88,66 +89,59 @@ private slots:
void sendCallErrors_data();
void sendCallErrors();
+ void receiveUnknownType_data();
+ void receiveUnknownType();
+
private:
QProcess proc;
};
-struct UnregisteredType { };
-Q_DECLARE_METATYPE(UnregisteredType)
-
-class WaitForQPong: public QObject
+class QDBusMessageSpy: public QObject
{
Q_OBJECT
-public:
- WaitForQPong();
- bool ok();
-public Q_SLOTS:
- void ownerChange(const QString &name)
+public slots:
+ Q_SCRIPTABLE int theSlot(const QDBusMessage &msg)
{
- if (name == serviceName)
- loop.quit();
+ list << msg;
+ return 42;
}
-
-private:
- QEventLoop loop;
+public:
+ QList<QDBusMessage> list;
};
-WaitForQPong::WaitForQPong()
-{
- QDBusConnection con = QDBusConnection::sessionBus();
- if (!ok()) {
- connect(con.interface(), SIGNAL(serviceOwnerChanged(QString,QString,QString)),
- SLOT(ownerChange(QString)));
- QTimer::singleShot(2000, &loop, SLOT(quit()));
- loop.exec();
- }
-}
-
-bool WaitForQPong::ok()
-{
- return QDBusConnection::sessionBus().isConnected() &&
- QDBusConnection::sessionBus().interface()->isServiceRegistered(serviceName);
-}
+struct UnregisteredType { };
+Q_DECLARE_METATYPE(UnregisteredType)
void tst_QDBusMarshall::initTestCase()
{
commonInit();
+ QDBusConnection con = QDBusConnection::sessionBus();
#ifdef Q_OS_WIN
proc.start("qpong");
#else
proc.start("./qpong/qpong");
#endif
- QVERIFY(proc.waitForStarted());
-
- WaitForQPong w;
- QVERIFY(w.ok());
- //QTest::qWait(2000);
+ if (!QDBusConnection::sessionBus().interface()->isServiceRegistered(serviceName)) {
+ QVERIFY(proc.waitForStarted());
+
+ QVERIFY(con.isConnected());
+ con.connect("org.freedesktop.DBus", QString(), "org.freedesktop.DBus", "NameOwnerChanged",
+ QStringList() << serviceName << QString(""), QString(),
+ &QTestEventLoop::instance(), SLOT(exitLoop()));
+ QTestEventLoop::instance().enterLoop(2);
+ QVERIFY(!QTestEventLoop::instance().timeout());
+ QVERIFY(QDBusConnection::sessionBus().interface()->isServiceRegistered(serviceName));
+ con.disconnect("org.freedesktop.DBus", QString(), "org.freedesktop.DBus", "NameOwnerChanged",
+ QStringList() << serviceName << QString(""), QString(),
+ &QTestEventLoop::instance(), SLOT(exitLoop()));
+ }
}
void tst_QDBusMarshall::cleanupTestCase()
{
proc.close();
- proc.kill();
+ proc.terminate();
+ proc.waitForFinished(200);
}
void tst_QDBusMarshall::sendBasic_data()
@@ -700,6 +694,8 @@ void tst_QDBusMarshall::sendBasic()
msg << value;
QDBusMessage reply = con.call(msg);
+ QVERIFY2(reply.type() == QDBusMessage::ReplyMessage,
+ qPrintable(reply.errorName() + ": " + reply.errorMessage()));
//qDebug() << reply;
QCOMPARE(reply.arguments().count(), msg.arguments().count());
@@ -938,5 +934,145 @@ void tst_QDBusMarshall::sendCallErrors()
QCOMPARE(reply.errorMessage(), errorMsg);
}
+void tst_QDBusMarshall::receiveUnknownType_data()
+{
+ QTest::addColumn<int>("receivedTypeId");
+ QTest::newRow("in-call") << qMetaTypeId<void*>();
+ QTest::newRow("type-variant") << qMetaTypeId<QDBusVariant>();
+ QTest::newRow("type-array") << qMetaTypeId<QDBusArgument>();
+ QTest::newRow("type-struct") << qMetaTypeId<QDBusArgument>();
+ QTest::newRow("type-naked") << qMetaTypeId<void *>();
+}
+
+struct DisconnectRawDBus {
+ static void cleanup(DBusConnection *connection)
+ {
+ if (!connection)
+ return;
+ dbus_connection_close(connection);
+ dbus_connection_unref(connection);
+ }
+};
+template <typename T, void (*unref)(T *)> struct GenericUnref
+{
+ static void cleanup(T *type)
+ {
+ if (!type) return;
+ unref(type);
+ }
+};
+
+// use these scoped types to avoid memory leaks if QVERIFY or QCOMPARE fails
+typedef QScopedPointer<DBusConnection, DisconnectRawDBus> ScopedDBusConnection;
+typedef QScopedPointer<DBusMessage, GenericUnref<DBusMessage, dbus_message_unref> > ScopedDBusMessage;
+typedef QScopedPointer<DBusPendingCall, GenericUnref<DBusPendingCall, dbus_pending_call_unref> > ScopedDBusPendingCall;
+
+void tst_QDBusMarshall::receiveUnknownType()
+{
+#ifndef DBUS_TYPE_UNIX_FD
+ QSKIP("Your system's D-Bus library is too old for this test", SkipAll);
+#else
+ QDBusConnection con = QDBusConnection::sessionBus();
+ QVERIFY(con.isConnected());
+
+ // this needs to be implemented in raw
+ // open a new connection to the bus daemon
+ DBusError error;
+ dbus_error_init(&error);
+ ScopedDBusConnection rawcon(dbus_bus_get_private(DBUS_BUS_SESSION, &error));
+ QVERIFY2(rawcon.data(), error.name);
+
+ // check if this bus supports passing file descriptors
+ if (!dbus_connection_can_send_type(rawcon.data(), DBUS_TYPE_UNIX_FD))
+ QSKIP("Your session bus does not allow sending Unix file descriptors", SkipAll);
+
+ if (qstrcmp(QTest::currentDataTag(), "in-call") == 0) {
+ // create a call back to us containing a file descriptor
+ QDBusMessageSpy spy;
+ con.registerObject("/spyObject", &spy, QDBusConnection::ExportAllSlots);
+ ScopedDBusMessage msg(dbus_message_new_method_call(con.baseService().toLatin1(), "/spyObject", NULL, "theSlot"));
+
+ int fd = fileno(stdout);
+ dbus_message_append_args(msg.data(), DBUS_TYPE_UNIX_FD, &fd, DBUS_TYPE_INVALID);
+
+ // try to send to us
+ DBusPendingCall *pending_ptr;
+ dbus_connection_send_with_reply(rawcon.data(), msg.data(), &pending_ptr, 1000);
+ ScopedDBusPendingCall pending(pending_ptr);
+
+ // check that it got sent
+ while (dbus_connection_dispatch(rawcon.data()) == DBUS_DISPATCH_DATA_REMAINS)
+ ;
+
+ // now spin our event loop. We don't catch this call, so let's get the reply
+ QEventLoop loop;
+ QTimer::singleShot(200, &loop, SLOT(quit()));
+ loop.exec();
+
+ // now try to receive the reply
+ dbus_pending_call_block(pending.data());
+
+ // check that the spy received what it was supposed to receive
+ QCOMPARE(spy.list.size(), 1);
+ QCOMPARE(spy.list.at(0).arguments().size(), 1);
+ QFETCH(int, receivedTypeId);
+ QCOMPARE(spy.list.at(0).arguments().at(0).userType(), receivedTypeId);
+
+ msg.reset(dbus_pending_call_steal_reply(pending.data()));
+ QVERIFY(msg);
+ QCOMPARE(dbus_message_get_type(msg.data()), DBUS_MESSAGE_TYPE_METHOD_RETURN);
+ QCOMPARE(dbus_message_get_signature(msg.data()), DBUS_TYPE_INT32_AS_STRING);
+
+ int retval;
+ QVERIFY(dbus_message_get_args(msg.data(), &error, DBUS_TYPE_INT32, &retval, DBUS_TYPE_INVALID));
+ QCOMPARE(retval, 42);
+ } else {
+ // create a signal that we'll emit
+ static const char signalName[] = "signalName";
+ static const char interfaceName[] = "local.interface.name";
+ ScopedDBusMessage msg(dbus_message_new_signal("/", interfaceName, signalName));
+ con.connect(dbus_bus_get_unique_name(rawcon.data()), QString(), interfaceName, signalName, &QTestEventLoop::instance(), SLOT(exitLoop()));
+
+ QDBusMessageSpy spy;
+ con.connect(dbus_bus_get_unique_name(rawcon.data()), QString(), interfaceName, signalName, &spy, SLOT(theSlot(QDBusMessage)));
+
+ DBusMessageIter iter;
+ dbus_message_iter_init_append(msg.data(), &iter);
+ int fd = fileno(stdout);
+
+ if (qstrcmp(QTest::currentDataTag(), "type-naked") == 0) {
+ // send naked
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_UNIX_FD, &fd);
+ } else {
+ DBusMessageIter subiter;
+ if (qstrcmp(QTest::currentDataTag(), "type-variant") == 0)
+ dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_UNIX_FD_AS_STRING, &subiter);
+ else if (qstrcmp(QTest::currentDataTag(), "type-array") == 0)
+ dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_UNIX_FD_AS_STRING, &subiter);
+ else if (qstrcmp(QTest::currentDataTag(), "type-struct") == 0)
+ dbus_message_iter_open_container(&iter, DBUS_TYPE_STRUCT, 0, &subiter);
+ dbus_message_iter_append_basic(&subiter, DBUS_TYPE_UNIX_FD, &fd);
+ dbus_message_iter_close_container(&iter, &subiter);
+ }
+
+ // send it
+ dbus_connection_send(rawcon.data(), msg.data(), 0);
+
+ // check that it got sent
+ while (dbus_connection_dispatch(rawcon.data()) == DBUS_DISPATCH_DATA_REMAINS)
+ ;
+
+ // now let's see what happens
+ QTestEventLoop::instance().enterLoop(1);
+ QVERIFY(!QTestEventLoop::instance().timeout());
+ QCOMPARE(spy.list.size(), 1);
+ QCOMPARE(spy.list.at(0).arguments().count(), 1);
+ QFETCH(int, receivedTypeId);
+ //qDebug() << spy.list.at(0).arguments().at(0).typeName();
+ QCOMPARE(spy.list.at(0).arguments().at(0).userType(), receivedTypeId);
+ }
+#endif
+}
+
QTEST_MAIN(tst_QDBusMarshall)
#include "tst_qdbusmarshall.moc"
diff --git a/tests/auto/qdbusxmlparser/tst_qdbusxmlparser.cpp b/tests/auto/qdbusxmlparser/tst_qdbusxmlparser.cpp
index 25595c5..f83795c 100644
--- a/tests/auto/qdbusxmlparser/tst_qdbusxmlparser.cpp
+++ b/tests/auto/qdbusxmlparser/tst_qdbusxmlparser.cpp
@@ -287,11 +287,14 @@ void tst_QDBusXmlParser::methods_data()
"</method>" << map;
// one invalid arg
+ method.inputArgs << arg("~", "invalid");
+ map.clear();
+ map << method;
QTest::newRow("two-in-one-invalid") <<
"<method name=\"Method\">"
"<arg type=\"s\" direction=\"in\"/>"
- "<arg type=\"~\" name=\"invalid\" direction=\"in\"/>" // this line should be ignored
"<arg type=\"v\" direction=\"in\"/>"
+ "<arg type=\"~\" name=\"invalid\" direction=\"in\"/>"
"</method>" << map;
// one out argument
@@ -380,8 +383,6 @@ void tst_QDBusXmlParser::methods()
QFETCH(QString, xmlDataFragment);
- if (strcmp(QTest::currentDataTag(), "two-in-one-invalid") == 0)
- QTest::ignoreMessage(QtWarningMsg, "Invalid D-BUS type signature '~' found while parsing introspection");
QDBusIntrospection::Interface iface =
QDBusIntrospection::parseInterface(xmlHeader + xmlDataFragment + xmlFooter);
@@ -390,9 +391,9 @@ void tst_QDBusXmlParser::methods()
QFETCH(MethodMap, methodMap);
MethodMap parsedMap = iface.methods;
- QCOMPARE(methodMap.count(), parsedMap.count());
- QCOMPARE(methodMap, parsedMap);
-}
+ QCOMPARE(parsedMap.count(), methodMap.count());
+ QCOMPARE(parsedMap, methodMap);
+}
void tst_QDBusXmlParser::signals__data()
{
diff --git a/tests/auto/qfuturewatcher/tst_qfuturewatcher.cpp b/tests/auto/qfuturewatcher/tst_qfuturewatcher.cpp
index 2ca1a47..9875fb5 100644
--- a/tests/auto/qfuturewatcher/tst_qfuturewatcher.cpp
+++ b/tests/auto/qfuturewatcher/tst_qfuturewatcher.cpp
@@ -484,8 +484,6 @@ class ProgressTextTask : public RunFunctionTask<T>
public:
void runFunctor()
{
- while (this->isProgressUpdateNeeded() == false)
- QTest::qSleep(1);
this->setProgressValueAndText(1, QLatin1String("Foo 1"));
while (this->isProgressUpdateNeeded() == false)
@@ -495,6 +493,10 @@ public:
while (this->isProgressUpdateNeeded() == false)
QTest::qSleep(1);
this->setProgressValueAndText(3, QLatin1String("Foo 3"));
+
+ while (this->isProgressUpdateNeeded() == false)
+ QTest::qSleep(1);
+ this->setProgressValueAndText(4, QLatin1String("Foo 4"));
}
};
@@ -522,14 +524,16 @@ void tst_QFutureWatcher::progressText()
QTestEventLoop::instance().enterLoop(5);
QVERIFY(!QTestEventLoop::instance().timeout());
- QCOMPARE(f.progressText(), QLatin1String("Foo 3"));
- QCOMPARE(f.progressValue(), 3);
+ QCOMPARE(f.progressText(), QLatin1String("Foo 4"));
+ QCOMPARE(f.progressValue(), 4);
QVERIFY(progressValues.contains(1));
QVERIFY(progressValues.contains(2));
QVERIFY(progressValues.contains(3));
+ QVERIFY(progressValues.contains(4));
QVERIFY(progressTexts.contains(QLatin1String("Foo 1")));
QVERIFY(progressTexts.contains(QLatin1String("Foo 2")));
QVERIFY(progressTexts.contains(QLatin1String("Foo 3")));
+ QVERIFY(progressTexts.contains(QLatin1String("Foo 4")));
}
}
diff --git a/tests/auto/qtconcurrentiteratekernel/tst_qtconcurrentiteratekernel.cpp b/tests/auto/qtconcurrentiteratekernel/tst_qtconcurrentiteratekernel.cpp
index a6499ff..92e8608 100644
--- a/tests/auto/qtconcurrentiteratekernel/tst_qtconcurrentiteratekernel.cpp
+++ b/tests/auto/qtconcurrentiteratekernel/tst_qtconcurrentiteratekernel.cpp
@@ -201,6 +201,7 @@ void tst_QtConcurrentIterateKernel::noIterations()
startThreadEngine(new IterateKernel<TestIterator, void>(0, 0)).startBlocking();
}
+QMutex threadsMutex;
QSet<QThread *> threads;
class ThrottleFor : public IterateKernel<TestIterator, void>
{
@@ -219,8 +220,10 @@ public:
QThread *thread = QThread::currentThread();
- if (begin > 140 && end < 160)
+ if (begin > 140 && end < 160) {
+ QMutexLocker locker(&threadsMutex);
threads.insert(thread);
+ }
if (100 >= begin && 100 < end) {
throttling = true;