tests/auto/qdbusconnection/tst_qdbusconnection.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
    94     void registerObject2();
    94     void registerObject2();
    95 
    95 
    96     void registerQObjectChildren();
    96     void registerQObjectChildren();
    97 
    97 
    98     void callSelf();
    98     void callSelf();
       
    99     void callSelfByAnotherName_data();
       
   100     void callSelfByAnotherName();
    99     void multipleInterfacesInQObject();
   101     void multipleInterfacesInQObject();
   100 
   102 
   101     void slotsWithLessParameters();
   103     void slotsWithLessParameters();
   102 
   104 
   103 public:
   105 public:
   491     msg << 44;
   493     msg << 44;
   492     reply = connection.call(msg);
   494     reply = connection.call(msg);
   493     QCOMPARE(reply.arguments().value(0).toInt(), 45);
   495     QCOMPARE(reply.arguments().value(0).toInt(), 45);
   494 }
   496 }
   495 
   497 
       
   498 void tst_QDBusConnection::callSelfByAnotherName_data()
       
   499 {
       
   500     QTest::addColumn<int>("registerMethod");
       
   501     QTest::newRow("connection") << 0;
       
   502     QTest::newRow("connection-interface") << 1;
       
   503     QTest::newRow("direct") << 2;
       
   504 }
       
   505 
       
   506 void tst_QDBusConnection::callSelfByAnotherName()
       
   507 {
       
   508     static int counter = 0;
       
   509     QString sname = serviceName() + QString::number(counter++);
       
   510 
       
   511     QDBusConnection con = QDBusConnection::sessionBus();
       
   512     QVERIFY(con.isConnected());
       
   513 
       
   514     TestObject testObject;
       
   515     QVERIFY(con.registerObject("/test", &testObject,
       
   516             QDBusConnection::ExportAllContents));
       
   517     con.connect("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "NameOwnerChanged",
       
   518                 QStringList() << sname << "",
       
   519                 QString(), &QTestEventLoop::instance(), SLOT(exitLoop()));
       
   520 
       
   521     // register the name
       
   522     QFETCH(int, registerMethod);
       
   523     switch (registerMethod) {
       
   524     case 0:
       
   525         QVERIFY(con.registerService(sname));
       
   526         break;
       
   527 
       
   528     case 1:
       
   529         QVERIFY(con.interface()->registerService(sname).value() == QDBusConnectionInterface::ServiceRegistered);
       
   530         break;
       
   531 
       
   532     case 2: {
       
   533             // flag is DBUS_NAME_FLAG_DO_NOT_QUEUE = 0x04
       
   534             // reply is DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER = 1
       
   535             QDBusReply<uint> reply = con.interface()->call("RequestName", sname, 4u);
       
   536             QVERIFY(reply.value() == 1);
       
   537         }
       
   538     }
       
   539 
       
   540     struct Deregisterer {
       
   541         QDBusConnection con;
       
   542         QString sname;
       
   543         Deregisterer(const QDBusConnection &con, const QString &sname) : con(con), sname(sname) {}
       
   544         ~Deregisterer() { con.interface()->unregisterService(sname); }
       
   545     } deregisterer(con, sname);
       
   546 
       
   547     // give the connection a chance to find out that we're good to go
       
   548     QTestEventLoop::instance().enterLoop(2);
       
   549     con.disconnect("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "NameOwnerChanged",
       
   550                  QStringList() << sname << "",
       
   551                  QString(), &QTestEventLoop::instance(), SLOT(exitLoop()));
       
   552     QVERIFY(!QTestEventLoop::instance().timeout());
       
   553 
       
   554     // make the call
       
   555     QDBusMessage msg = QDBusMessage::createMethodCall(sname, "/test",
       
   556                                                       QString(), "test0");
       
   557     QDBusMessage reply = con.call(msg, QDBus::Block, 1000);
       
   558 
       
   559     QVERIFY(reply.type() == QDBusMessage::ReplyMessage);
       
   560 }
       
   561 
   496 void tst_QDBusConnection::multipleInterfacesInQObject()
   562 void tst_QDBusConnection::multipleInterfacesInQObject()
   497 {
   563 {
   498     QDBusConnection con = QDBusConnection::sessionBus();
   564     QDBusConnection con = QDBusConnection::sessionBus();
   499     QVERIFY(!callMethod(con, "/p1"));
   565     QVERIFY(!callMethod(con, "/p1"));
   500 
   566