Skip to content

Commit

Permalink
[connectionagent] add some tests for requestConnect and unerInputRequest
Browse files Browse the repository at this point in the history
Signed-off-by: Lorn Potter <lorn.potter@jollamobile.com>
  • Loading branch information
Lorn Potter committed May 30, 2013
1 parent 074e848 commit a849422
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 13 deletions.
2 changes: 1 addition & 1 deletion connd/qconnectionmanager.cpp
Expand Up @@ -159,7 +159,7 @@ void QConnectionManager::onErrorReported(const QString &error)
// from useragent
void QConnectionManager::onConnectionRequest()
{
qDebug() << Q_FUNC_INFO;
qDebug() << Q_FUNC_INFO << autoConnect();
sendConnectReply("Suppress", 15);
if (!autoConnect()) {
Q_EMIT connectionRequest();
Expand Down
16 changes: 16 additions & 0 deletions connectionagentplugin/connectionagentplugin.cpp
Expand Up @@ -62,6 +62,7 @@ void ConnectionAgentPlugin::connectToConnectiond(QString)
if (!QDBusConnection::sessionBus().interface()->isServiceRegistered(CONND_SERVICE)) {
qDebug() << Q_FUNC_INFO << QString("connection service not available").arg(CONND_SERVICE);
QDBusReply<void> reply = QDBusConnection::sessionBus().interface()->startService(CONND_SERVICE);

if (!reply.isValid()) {
qDebug() << Q_FUNC_INFO << reply.error().message();
return;
Expand Down Expand Up @@ -96,19 +97,34 @@ void ConnectionAgentPlugin::connectToConnectiond(QString)

void ConnectionAgentPlugin::sendUserReply(const QVariantMap &input)
{
if (!connManagerInterface || !connManagerInterface->isValid()) {
Q_EMIT errorReported("ConnectionAgent not available");
return;
}
QDBusPendingReply<> reply = connManagerInterface->sendUserReply(input);
reply.waitForFinished();
if (reply.isError()) {
qDebug() << Q_FUNC_INFO << reply.error().message();
Q_EMIT errorReported(reply.error().message());
}
}

void ConnectionAgentPlugin::sendConnectReply(const QString &replyMessage, int timeout)
{
if (!connManagerInterface || !connManagerInterface->isValid()) {
Q_EMIT errorReported("ConnectionAgent not available");
return;
}
connManagerInterface->sendConnectReply(replyMessage,timeout);
}

void ConnectionAgentPlugin::connectToType(const QString &type)
{
if (!connManagerInterface || !connManagerInterface->isValid()) {
Q_EMIT errorReported("ConnectionAgent not available");
return;
}

connManagerInterface->connectToType(type);
}

Expand Down
Expand Up @@ -28,7 +28,7 @@

#include <QNetworkAccessManager>
#include <QNetworkRequest>

#include <QNetworkReply>

class Tst_connectionagent_pluginTest : public QObject
{
Expand All @@ -42,8 +42,10 @@ private Q_SLOTS:
void testRequestConnection_data();
void testRequestConnection();

// void testError_data();
void testError();
void testUserInputRequested_data();
void testUserInputRequested();

void testErrorReported();
private:
ConnectionAgentPlugin *plugin;
};
Expand Down Expand Up @@ -75,30 +77,30 @@ void Tst_connectionagent_pluginTest::testRequestConnection()

QVector<NetworkService*> wifiServices = netman->getServices("wifi");
for (int i = 0; i < wifiServices.count(); i++) {
// favorite = wifiServices[i]->favorite();
if (wifiServices[i]->autoConnect())
wifiServices[i]->setAutoConnect(false);
if (wifiServices[i]->state() == "online"
|| wifiServices[i]->state() == "ready") {
wifiServices[i]->requestDisconnect();
//autoconnect disables the requestConnect signal
}
}

QSignalSpy spy2(plugin, SIGNAL(connectionRequest()));

QNetworkAccessManager manager;
manager.get(QNetworkRequest(QUrl("http://jolla.com")));

QTest::qWait(4000);
QNetworkReply *reply = manager.get(QNetworkRequest(QUrl("http://llornkcor.com")));
if (reply->error()) {
qDebug() << reply->error();
}
QTest::qWait(2000);
QCOMPARE(spy2.count(),1);
plugin->sendConnectReply("Clear",0);


}

//void Tst_connectionagent_pluginTest::testError_data()
//{
//}

void Tst_connectionagent_pluginTest::testError()
void Tst_connectionagent_pluginTest::testErrorReported()
{
QSignalSpy spy(plugin, SIGNAL(errorReported(QString)));
plugin->connectToType("test");
Expand All @@ -108,6 +110,43 @@ void Tst_connectionagent_pluginTest::testError()
QCOMPARE(arguments.at(0).toString(), QString("Type not valid"));
}

void Tst_connectionagent_pluginTest::testUserInputRequested_data()
{
testRequestConnection_data();
}

void Tst_connectionagent_pluginTest::testUserInputRequested()
{
QFETCH(QString, tech);
NetworkManager *netman = NetworkManagerFactory::createInstance();

QString techPath = netman->technologyPathForType(tech);
NetworkTechnology netTech;
netTech.setPath(techPath);

QSignalSpy spy_userInput(plugin, SIGNAL(userInputRequested(QString,QVariantMap)));

QVector<NetworkService*> wifiServices = netman->getServices("wifi");
for (int i = 0; i < wifiServices.count(); i++) {
if(wifiServices[i]->favorite()) {
//favorite disables the need for user input
wifiServices[i]->remove();
}
if (wifiServices[i]->autoConnect())
wifiServices[i]->setAutoConnect(false);
if (wifiServices[i]->state() == "idle") {
wifiServices[i]->requestConnect();
break;
}
}

QTest::qWait(2000);
QCOMPARE(spy_userInput.count(),1);
QVariantMap map;
plugin->sendUserReply(map); //cancel
}


QTEST_MAIN(Tst_connectionagent_pluginTest)

#include "tst_connectionagent_plugintest.moc"

0 comments on commit a849422

Please sign in to comment.