You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
191 lines
6.3 KiB
191 lines
6.3 KiB
/* |
|
Copyright 2010 by Kurt Hindenburg <kurt.hindenburg@gmail.com> |
|
|
|
This program is free software; you can redistribute it and/or modify |
|
it under the terms of the GNU General Public License as published by |
|
the Free Software Foundation; either version 2 of the License, or |
|
(at your option) any later version. |
|
|
|
This program is distributed in the hope that it will be useful, |
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
GNU General Public License for more details. |
|
|
|
You should have received a copy of the GNU General Public License |
|
along with this program; if not, write to the Free Software |
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
02110-1301 USA. |
|
*/ |
|
|
|
// Own |
|
#include "DBusTest.h" |
|
|
|
using namespace Konsole; |
|
|
|
/* Exec a new Konsole and grab its dbus */ |
|
void DBusTest::initTestCase() |
|
{ |
|
const QString interfaceName = "org.kde.konsole"; |
|
QDBusConnectionInterface* bus = 0; |
|
QStringList konsoleServices; |
|
|
|
if (!QDBusConnection::sessionBus().isConnected() || |
|
!(bus = QDBusConnection::sessionBus().interface())) |
|
kFatal() << "Session bus not found"; |
|
|
|
QDBusReply<QStringList> serviceReply = bus->registeredServiceNames(); |
|
if (!serviceReply.isValid()) |
|
kFatal() << "SessionBus interfaces not available"; |
|
|
|
// Find all current Konsoles' services running |
|
QStringList allServices = serviceReply; |
|
for (QStringList::const_iterator it = allServices.begin(), |
|
end = allServices.end(); it != end; ++it) { |
|
const QString service = *it; |
|
if (service.startsWith(interfaceName)) |
|
konsoleServices << service; |
|
} |
|
|
|
// Create a new Konsole |
|
int result = KToolInvocation::kdeinitExec("konsole"); |
|
if (result) |
|
kFatal() << "Unable to exec a new Konsole : " << result; |
|
|
|
// Wait for above Konsole to finish starting |
|
#ifdef HAVE_USLEEP |
|
usleep(5*1000); |
|
#else |
|
sleep(5); |
|
#endif |
|
|
|
serviceReply = bus->registeredServiceNames(); |
|
if (!serviceReply.isValid()) |
|
kFatal() << "SessionBus interfaces not available"; |
|
|
|
// Find dbus service of above Konsole |
|
allServices = serviceReply; |
|
for (QStringList::const_iterator it = allServices.begin(), |
|
end = allServices.end(); it != end; ++it) { |
|
const QString service = *it; |
|
if (service.startsWith(interfaceName)) |
|
if (!konsoleServices.contains(service)) |
|
_interfaceName = service; |
|
} |
|
|
|
if (_interfaceName.isEmpty()) |
|
kFatal() << "No services matching " << interfaceName << " were found."; |
|
//kDebug()<< "Using service: " + _interfaceName.toLatin1(); |
|
|
|
_iface = new QDBusInterface(_interfaceName, |
|
QLatin1String("/Konsole"), |
|
QLatin1String("org.kde.konsole.Konsole"), |
|
QDBusConnection::sessionBus(), this); |
|
QVERIFY(_iface); |
|
QVERIFY(_iface->isValid()); |
|
} |
|
|
|
/* Close the Konsole window that was opened to test the DBus interface |
|
*/ |
|
void DBusTest::cleanupTestCase() |
|
{ |
|
QVERIFY(_iface); |
|
QVERIFY(_iface->isValid()); |
|
|
|
// Need to take care of when user has CloseAllTabs=False otherwise |
|
// they will get a popup dialog when we try to close this. |
|
|
|
QDBusInterface iface(_interfaceName, |
|
QLatin1String("/konsole/MainWindow_1"), |
|
QLatin1String("com.trolltech.Qt.QWidget")); |
|
if (!iface.isValid()) |
|
kFatal() << "Unable to get a dbus interface to Konsole!"; |
|
|
|
QDBusReply<void> instanceReply = iface.call("close"); |
|
if (!instanceReply.isValid()) |
|
kFatal() << "Unable to close Konsole :" << instanceReply.error(); |
|
} |
|
|
|
void DBusTest::testSessions() |
|
{ |
|
QDBusReply<void> voidReply; |
|
QDBusReply<bool> boolReply; |
|
QDBusReply<QByteArray> arrayReply; |
|
|
|
QVERIFY(_iface); |
|
QVERIFY(_iface->isValid()); |
|
|
|
QDBusInterface iface(_interfaceName, |
|
QLatin1String("/Sessions/1"), |
|
QLatin1String("org.kde.konsole.Session")); |
|
QVERIFY(iface.isValid()); |
|
|
|
//****************** Test is/set MonitorActivity |
|
voidReply = iface.call("setMonitorActivity", false); |
|
QVERIFY(voidReply.isValid()); |
|
|
|
boolReply = iface.call("isMonitorActivity"); |
|
QVERIFY(boolReply.isValid()); |
|
QCOMPARE(boolReply.value(), false); |
|
|
|
voidReply = iface.call("setMonitorActivity", true); |
|
QVERIFY(voidReply.isValid()); |
|
|
|
boolReply = iface.call("isMonitorActivity"); |
|
QVERIFY(boolReply.isValid()); |
|
QCOMPARE(boolReply.value(), true); |
|
|
|
//****************** Test is/set MonitorSilence |
|
voidReply = iface.call("setMonitorSilence", false); |
|
QVERIFY(voidReply.isValid()); |
|
|
|
boolReply = iface.call("isMonitorSilence"); |
|
QVERIFY(boolReply.isValid()); |
|
QCOMPARE(boolReply.value(), false); |
|
|
|
voidReply = iface.call("setMonitorSilence", true); |
|
QVERIFY(voidReply.isValid()); |
|
|
|
boolReply = iface.call("isMonitorSilence"); |
|
QVERIFY(boolReply.isValid()); |
|
QCOMPARE(boolReply.value(), true); |
|
|
|
//****************** Test codec and setCodec |
|
arrayReply = iface.call("codec"); |
|
QVERIFY(arrayReply.isValid()); |
|
|
|
// Obtain a list of system's Codecs |
|
QList<QByteArray> availableCodecs = QTextCodec::availableCodecs(); |
|
for (int i = 0; i < availableCodecs.count(); ++i) { |
|
boolReply = iface.call("setCodec", availableCodecs[i]); |
|
QVERIFY(boolReply.isValid()); |
|
QCOMPARE(boolReply.value(), true); |
|
|
|
arrayReply = iface.call("codec"); |
|
QVERIFY(arrayReply.isValid()); |
|
// Compare result with name due to aliases issue |
|
// Better way to do this? |
|
QCOMPARE((QTextCodec::codecForName(arrayReply.value()))->name(), |
|
(QTextCodec::codecForName(availableCodecs[i]))->name()); |
|
} |
|
|
|
//****************** Test is/set flowControlEnabled |
|
voidReply = iface.call("setFlowControlEnabled", true); |
|
QVERIFY(voidReply.isValid()); |
|
|
|
boolReply = iface.call("flowControlEnabled"); |
|
QVERIFY(boolReply.isValid()); |
|
QCOMPARE(boolReply.value(), true); |
|
|
|
voidReply = iface.call("setFlowControlEnabled", false); |
|
QVERIFY(voidReply.isValid()); |
|
|
|
boolReply = iface.call("flowControlEnabled"); |
|
QVERIFY(boolReply.isValid()); |
|
QCOMPARE(boolReply.value(), false); |
|
|
|
} |
|
|
|
QTEST_MAIN(DBusTest) |
|
|
|
#include "DBusTest.moc" |
|
|
|
|