void GCF::Components::ClipboardComponent::addContext(const QString& contextName)
{
    if(!d->contextStore.contains(contextName))
    {
        ClipboardDataList list;
        d->contextStore[contextName] = list;
        d->contextStoreKeys.append(contextName);
    }

    emit contextAdded(contextName);

    activateContext(contextName);
}
    void tst_provisioning()
    {
        QSignalSpy conadd(m, SIGNAL(contextAdded(QString)));

        Q_FOREACH (const QString con, m->contexts()) {
            m->removeContext(con);
        }
        QTRY_COMPARE(m->contexts(), QStringList());

        m->addContext("internet");
        QTRY_COMPARE(conadd.count(), 1);
        QString contextid = conadd.takeFirst().at(0).toString();
        QVERIFY(m->contexts().contains(contextid));

        QOfonoConnectionContext* context = new QOfonoConnectionContext(this);
        context->setContextPath(contextid);
        QSignalSpy apn(context, SIGNAL(accessPointNameChanged(QString)));

        context->setAccessPointName("internet");
        QTRY_COMPARE(apn.count(), 1);
        QCOMPARE(apn.takeFirst().at(0).toString(), QString("internet"));

        QString operatorString = "Optus";
        QString mcc = "505";
        QString mnc = "02";

        QCOMPARE(context->validateProvisioning(operatorString, mcc, mnc),true);

        context->setAccessPointName("yesinternet");
        QTRY_COMPARE(apn.count(), 1);
        QCOMPARE(apn.takeFirst().at(0).toString(), QString("yesinternet"));
        QCOMPARE(context->validateProvisioning(operatorString, mcc, mnc),true);

        context->setAccessPointName("connect");
        QTRY_COMPARE(apn.count(), 1);
        QCOMPARE(apn.takeFirst().at(0).toString(), QString("connect"));
        QCOMPARE(context->validateProvisioning(operatorString, mcc, mnc),true);

        context->setAccessPointName("connectcap");
        QTRY_COMPARE(apn.count(), 1);
        QCOMPARE(apn.takeFirst().at(0).toString(), QString("connectcap"));
        QCOMPARE(context->validateProvisioning(operatorString, mcc, mnc),true);

        context->setAccessPointName("test");
        QTRY_COMPARE(apn.count(), 1);
        QCOMPARE(apn.takeFirst().at(0).toString(), QString("test"));
        QCOMPARE(context->validateProvisioning(operatorString, mcc, mnc),false);
    }
Beispiel #3
0
void Tst_qofonoTest::testConnectionManager()
{
    QOfonoManager manager;
    QOfonoConnectionManager connman;
    QOfonoModem modem;
    modem.setModemPath(manager.modems()[0]);

    if (!modem.online()) {
        modem.setOnline(true);
    }
    QVERIFY(modem.online());

    connman.setModemPath(manager.modems()[0]);
    QVERIFY(!connman.modemPath().isEmpty());

    QSignalSpy spy(&connman, SIGNAL(contextAdded(QString)));
    connman.addContext("internet");
    ::waitForSignal(&connman,SIGNAL(contextAdded(QString)),1000);
    QCOMPARE(spy.count(),1);

//    QList<QVariant> arguments ;
//    arguments = spy.takeFirst();

    // attached

    // bearer
    // suspended
    // roamingAllowed
//    QSignalSpy spy_roaming(&connman, SIGNAL(roamingAllowedChanged(bool)));
//    bool expected = !connman.roamingAllowed();
//    connman.setRoamingAllowed(expected);
//    QTest::qWait(3000);
//    QCOMPARE(spy_roaming.count(),1);
//    QList<QVariant> argumentsspy_roaming;
//    argumentsspy_roaming = spy_roaming.takeFirst();
//    QCOMPARE(argumentsspy_roaming[0].toBool(), expected);

//    connman.setRoamingAllowed(false);
//    QTest::qWait(3000);
//    QCOMPARE(spy_roaming.count(),1);
//    QList<QVariant> argumentsspy_roaming2;
//    argumentsspy_roaming2 = spy_roaming.takeFirst();
//    if (manager.modems()[0].contains("phonesim"))
//        QEXPECT_FAIL("","seems to nt work on phonesim",Continue);
//    QCOMPARE(argumentsspy_roaming[0].toBool(), false);

//    // powered

//    QSignalSpy spy_powered(&connman, SIGNAL(poweredChanged(bool)));
//    QList<QVariant> argumentsspy_powered;
    //  bool isPowered = connman.powered();

//    qDebug() << Q_FUNC_INFO << "modem powered" << connman.powered();

//    connman.setPowered(!isPowered);
//    QTest::qWait(3000);
//    QCOMPARE(spy_powered.count(),2); //powers itself back on
//    argumentsspy_powered = spy_powered.takeFirst();
//    QCOMPARE(argumentsspy_powered[0].toBool(), !isPowered);

//    if(!connman.powered()) {
//        connman.setPowered(true);
//        QTest::qWait(3000);
//        QVERIFY(connman.powered());
//    }

    //TODO other signals
}
    void testQOfonoConnectionManagerContext ()
    {
        QSignalSpy conadd(m, SIGNAL(contextAdded(QString)));
        QSignalSpy conrem(m, SIGNAL(contextRemoved(QString)));

        m->addContext("internet");
        QTRY_COMPARE(conadd.count(), 1);
        QString contextid = conadd.takeFirst().at(0).toString();
        QVERIFY(m->contexts().contains(contextid));

        QOfonoConnectionContext* context = new QOfonoConnectionContext(this);
        context->setContextPath(contextid);

        QSignalSpy active(context, SIGNAL(activeChanged(bool)));
        QSignalSpy apn(context,SIGNAL(accessPointNameChanged(QString)));
        QSignalSpy name(context, SIGNAL(nameChanged(QString)));
        QSignalSpy type (context, SIGNAL(typeChanged(QString)));
        QSignalSpy uname (context, SIGNAL(usernameChanged(QString)));
        QSignalSpy pw (context, SIGNAL(passwordChanged(QString)));
        QSignalSpy proto (context, SIGNAL(protocolChanged(QString)));
        QSignalSpy sett (context, SIGNAL(settingsChanged(QVariantMap)));
        QSignalSpy sett6 (context, SIGNAL(IPv6SettingsChanged(QVariantMap)));

        context->setAccessPointName("hyva");
        QTRY_COMPARE(apn.count(), 1);
        QCOMPARE(apn.takeFirst().at(0).toString(), QString("hyva"));
        context->setUsername("huomenta");
        QTRY_COMPARE(uname.count(), 1);
        QCOMPARE(uname.takeFirst().at(0).toString(), QString("huomenta"));
        context->setPassword("HYVA");
        QTRY_COMPARE(pw.count(), 1);
        QCOMPARE(pw.takeFirst().at(0).toString(), QString("HYVA"));
        context->setName("yota");
        QTRY_COMPARE(name.count(), 1);
        QCOMPARE(name.takeFirst().at(0).toString(), QString("yota"));
        context->setType("mms");
        QTRY_COMPARE(type.count(), 1);
        QCOMPARE(type.takeFirst().at(0).toString(), QString("mms"));
        context->setProtocol("ipv6");
        QTRY_COMPARE(proto.count(), 1);
        QCOMPARE(proto.takeFirst().at(0).toString(), QString("ipv6"));

        context->setActive(true);
        QTRY_COMPARE(active.count(), 1);
        QCOMPARE(active.takeFirst().at(0).toBool(), true);

        QTRY_COMPARE(sett6.count(), 1);
        QCOMPARE(sett6.takeFirst().at(0).toMap()["Interface"].value<QString>().left(5),
            QString("dummy")); // "dummy" plus number
        QVariantMap settings = context->IPv6Settings();
        QCOMPARE(settings["Interface"].value<QString>().left(5),QString("dummy")); // "dummy" plus number

        QTest::qWait(REASONABLE_TIMEOUT);

        QCOMPARE(apn.count(), 0);
        QCOMPARE(uname.count(), 0);
        QCOMPARE(pw.count(), 0);
        QCOMPARE(name.count(), 0);
        QCOMPARE(type.count(), 0);
        QCOMPARE(sett.count(), 0);
        QCOMPARE(proto.count(), 0);
        QCOMPARE(active.count(), 0);

        context->setActive(false);
        QTRY_COMPARE(active.count(), 1);
        QCOMPARE(active.takeFirst().at(0).toBool(), false);

        delete context;

        m->removeContext(contextid);
        QTRY_COMPARE(conrem.count(), 1);
        QCOMPARE(conrem.takeFirst().at(0).toString(), contextid);
    }