void Ut_BatteryBusinessLogic::testPSMStateChanged () { #ifdef HAVE_QMSYSTEM QList<QVariant> arguments; QSignalSpy spy (m_logic, SIGNAL (notificationSent (QString, QString, QString))); /* Entering to power-save mode */ m_logic->devicePSMStateChanged (MeeGo::QmDeviceMode::PSMStateOn); QTest::qWait (10); QCOMPARE (spy.count (), 1); arguments = spy.takeFirst (); QVERIFY (arguments.at (0).toString () == "x-nokia.battery.enterpsm"); QVERIFY (arguments.at (1).toString () == qtTrId ("qtn_ener_ent_psnote")); QVERIFY (arguments.at (2).toString () == ""); spy.clear (); /* Exiting from power-save mode */ m_logic->devicePSMStateChanged (MeeGo::QmDeviceMode::PSMStateOff); QTest::qWait (10); QCOMPARE (spy.count (), 1); arguments = spy.takeFirst (); QVERIFY (arguments.at (0).toString () == "x-nokia.battery.exitpsm"); QVERIFY (arguments.at (1).toString () == qtTrId ("qtn_ener_exit_psnote")); QVERIFY (arguments.at (2).toString () == ""); #endif }
void compare_key_event(QSignalSpy& spy) const { spy.wait(_wait_ms); BOOST_CHECK_EQUAL(spy.count(), 1); QList<QVariant> arguments = spy.takeFirst(); BOOST_CHECK_EQUAL(arguments.at(0).toInt(), static_cast<int>(_key)); }
void compare_key_event(QSignalSpy& spy) const { spy.wait(2*_wait_ms); EXPECT_EQ(spy.count(), 1); auto arguments = spy.takeFirst(); EXPECT_EQ(arguments.at(0).toInt(), static_cast<int>(_key)); }
void compare_mouse_event(QSignalSpy& spy, const QMouseEvent& expected_event) const { spy.wait(_wait_ms); BOOST_CHECK_EQUAL(spy.count(), 1); QList<QVariant> arguments = spy.takeFirst(); BOOST_CHECK_EQUAL(arguments.at(0).toInt(), expected_event.x()); BOOST_CHECK_EQUAL(arguments.at(1).toInt(), expected_event.y()); BOOST_CHECK_EQUAL(arguments.at(2).value<Qt::MouseButtons>(), expected_event.buttons()); }
/** * Check that all mandatory informations are passed * throught the requestFinished signal... */ void Ut_AboutBusinessLogic::testMultiThread () { QSignalSpy spy ( m_Api, SIGNAL (requestFinished (AboutBusinessLogic::requestType, QVariant))); /* * Run the multithreaded data collection ... */ m_Api->start (); /* * Hopefully this does not harm, and enough... */ QTest::qWait (500); QList<AboutBusinessLogic::requestType> mandatoryFields; mandatoryFields << AboutBusinessLogic::reqProdName << AboutBusinessLogic::reqSwName << AboutBusinessLogic::reqLicense << AboutBusinessLogic::reqOsVersion << AboutBusinessLogic::reqImei << AboutBusinessLogic::reqWifiAddr; /* BtAddr also mandatory, but we stubbed that stuff here, * and we have a separate testcase which covers that one... */ /* * Check whether that at least the mandatory field values are arrived */ QVERIFY (spy.count () >= mandatoryFields.count ()); QList<AboutBusinessLogic::requestType> arrivedFields; for ( ; ! spy.isEmpty () ; ) { QList<QVariant> signal = spy.takeFirst (); arrivedFields << signal.at (0).value<AboutBusinessLogic::requestType>(); } foreach (AboutBusinessLogic::requestType req, mandatoryFields) { //SYS_DEBUG ("reqNr = %d", (int) req); QVERIFY (arrivedFields.contains (req)); }
void Ut_BatteryBusinessLogic::testLowBatteryAlert () { #ifdef HAVE_QMSYSTEM QSignalSpy spy (m_logic, SIGNAL (notificationSent (QString, QString, QString))); m_logic->lowBatteryAlert (); QTest::qWait (10); QCOMPARE (spy.count (), 1); QList<QVariant> arguments = spy.takeFirst (); QVERIFY (arguments.at (0).toString () == "x-nokia.battery.lowbattery"); QVERIFY (arguments.at (1).toString () == qtTrId ("qtn_ener_lowbatt")); QVERIFY (arguments.at (2).toString () == ""); #endif }
void Ut_BatteryBusinessLogic::testBatteryChargerEvent () { #ifdef HAVE_QMSYSTEM QList<QVariant> arguments; QSignalSpy spy (m_logic, SIGNAL (notificationSent (QString, QString, QString))); /* Wall charger */ m_logic->batteryChargerEvent (MeeGo::QmBattery::Wall); QCOMPARE (m_logic->m_ChargerType, MeeGo::QmBattery::Wall); /* Plug out : charger type = none */ m_logic->batteryChargerEvent (MeeGo::QmBattery::None); QCOMPARE (m_logic->m_ChargerType, MeeGo::QmBattery::None); QTest::qWait (10); QCOMPARE (spy.count (), 1); arguments = spy.takeFirst (); /* Look for the notification: "Disconnect the charger from..." */ QVERIFY (arguments.at (0).toString () == "x-nokia.battery.removecharger"); QVERIFY (arguments.at (1).toString () == qtTrId ("qtn_ener_remcha")); QVERIFY (arguments.at (2).toString () == ""); spy.clear (); /* USB 500mA */ m_logic->batteryChargerEvent (MeeGo::QmBattery::USB_500mA); QCOMPARE (m_logic->m_ChargerType, MeeGo::QmBattery::USB_500mA); /* USB 100mA */ m_logic->batteryChargerEvent (MeeGo::QmBattery::USB_100mA); QCOMPARE (m_logic->m_ChargerType, MeeGo::QmBattery::USB_100mA); /* Unknown */ m_logic->batteryChargerEvent (MeeGo::QmBattery::Unknown); QCOMPARE (m_logic->m_ChargerType, MeeGo::QmBattery::Unknown); #endif }
void Ut_BatteryBusinessLogic::testLowBatteryNotifierConnection () { #ifdef HAVE_QMSYSTEM QList<QVariant> arguments; QSignalSpy spy (m_logic, SIGNAL (notificationSent (QString, QString, QString))); gQmBatteryStub->stubSetReturnValue ( "getChargerType", MeeGo::QmBattery::USB_500mA); /* LowBatteryNotifier shouldn't be instantiated at first */ QVERIFY (m_logic->m_LowBatteryNotifier == 0); /* Simulate battery-state-low change */ gQmBatteryStub->stubSetReturnValue<MeeGo::QmBattery::ChargingState> ( "getChargingState", MeeGo::QmBattery::StateNotCharging); m_logic->batteryStateChanged (MeeGo::QmBattery::StateLow); /* LowBatteryNotifier should be exists now... */ QVERIFY (m_logic->m_LowBatteryNotifier != 0); QTest::qWait (10); /* And should send a low-battery notification */ QCOMPARE (spy.count (), 1); arguments = spy.takeFirst (); QVERIFY (arguments.at (0).toString () == "x-nokia.battery.lowbattery"); QVERIFY (arguments.at (1).toString () == qtTrId ("qtn_ener_lowbatt")); QVERIFY (arguments.at (2).toString () == ""); /* Simulate now a charging event */ m_logic->chargingStateChanged (MeeGo::QmBattery::StateCharging); /* After this call LowBatteryNotifier should be destroyed */ QVERIFY (m_logic->m_LowBatteryNotifier == 0); #endif }
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); }
void Ut_BatteryBusinessLogic::testChargingStateChanged () { #ifdef HAVE_QMSYSTEM QList<QVariant> arguments; QSignalSpy spy (m_logic, SIGNAL (notificationSent (QString, QString, QString))); gQmBatteryStub->stubReset (); gQmLEDStub->stubReset (); gQmBatteryStub->stubSetReturnValue ( "getChargerType", MeeGo::QmBattery::Wall); for (int i = 0; i <= 100; i += 5) { /* StateCharging */ gQmBatteryStub->stubSetReturnValue<int> ("getRemainingCapacityPct", i); m_logic->chargingStateChanged (MeeGo::QmBattery::StateCharging); QTest::qWait (1); QCOMPARE (spy.count (), 1); arguments = spy.takeFirst (); QVERIFY (arguments.at (0).toString () == "x-nokia.battery"); QVERIFY (arguments.at (1).toString () == qtTrId ("qtn_ener_charging")); QVERIFY (arguments.at (2).toString () == m_logic->chargingImageId ()); QVERIFY (gQmLEDStub->stubLastCallTo ("activate").parameter<QString>(0) == QString ("PatternBatteryCharging")); spy.clear (); } /* StateNotCharging */ m_logic->chargingStateChanged (MeeGo::QmBattery::StateNotCharging); QTest::qWait (10); QCOMPARE (spy.count (), 0); QVERIFY (gQmLEDStub->stubLastCallTo ("deactivate").parameter<QString>(0) == QString ("PatternBatteryCharging")); spy.clear (); /* StateChargingFailed */ m_logic->chargingStateChanged (MeeGo::QmBattery::StateChargingFailed); QTest::qWait (10); QCOMPARE (spy.count (), 1); arguments = spy.takeFirst (); QVERIFY (arguments.at (0).toString () == "x-nokia.battery.chargingnotstarted"); QVERIFY (arguments.at (1).toString () == qtTrId ("qtn_ener_repcharger")); QVERIFY (arguments.at (2).toString () == ""); spy.clear (); /* Test "not enough power to charge" situation... */ gQmBatteryStub->stubSetReturnValue ( "getChargerType", MeeGo::QmBattery::USB_100mA); m_logic->chargingStateChanged (MeeGo::QmBattery::StateCharging); QTest::qWait (10); QCOMPARE (spy.count (), 1); arguments = spy.takeFirst (); QVERIFY (arguments.at (0).toString () == "x-nokia.battery.notenoughpower"); QVERIFY (arguments.at (1).toString () == qtTrId ("qtn_ener_nopowcharge")); QVERIFY (arguments.at (2).toString () == "icon-m-energy-management-insufficient-power"); spy.clear (); #endif }
void Ut_BatteryBusinessLogic::testBatteryStateChanged () { #ifdef HAVE_QMSYSTEM QList<QVariant> arguments; QSignalSpy spy (m_logic, SIGNAL (notificationSent (QString, QString, QString))); gQmBatteryStub->stubReset (); gQmLEDStub->stubReset (); /* StateFull */ spy.clear (); m_logic->batteryStateChanged (MeeGo::QmBattery::StateFull); QTest::qWait (10); QCOMPARE (spy.count (), 1); arguments = spy.takeFirst (); QVERIFY (arguments.at (0).toString () == "x-nokia.battery.chargingcomplete"); QVERIFY (arguments.at (1).toString () == qtTrId ("qtn_ener_charcomp")); QVERIFY (arguments.at (2).toString () == ""); QVERIFY (gQmLEDStub->stubLastCallTo ("activate").parameter<QString>(0) == QString ("PatternBatteryFull")); /* StateOK */ spy.clear (); m_logic->batteryStateChanged (MeeGo::QmBattery::StateOK); QTest::qWait (10); /* no signals/notifications should come, just silently no-op */ QCOMPARE (spy.count (), 0); /* StateEmpty */ spy.clear (); m_logic->batteryStateChanged (MeeGo::QmBattery::StateEmpty); QTest::qWait (10); QCOMPARE (spy.count (), 1); arguments = spy.takeFirst (); QVERIFY (arguments.at (0).toString () == "x-nokia.battery.recharge"); QVERIFY (arguments.at (1).toString () == qtTrId ("qtn_ener_rebatt")); QVERIFY (arguments.at (2).toString () == ""); /* StateError */ spy.clear (); m_logic->batteryStateChanged (MeeGo::QmBattery::StateError); QTest::qWait (10); /* no signals/notifications should come, just silently no-op */ QCOMPARE (spy.count (), 0); /* StateLow and charging */ spy.clear (); gQmBatteryStub->stubSetReturnValue<MeeGo::QmBattery::ChargingState> ( "getChargingState", MeeGo::QmBattery::StateCharging); m_logic->batteryStateChanged (MeeGo::QmBattery::StateLow); QTest::qWait (10); /* no signals/notifications should come, because battery is charging... */ QCOMPARE (spy.count (), 0); /* StateLow and not charging */ spy.clear (); gQmBatteryStub->stubSetReturnValue<MeeGo::QmBattery::ChargingState> ( "getChargingState", MeeGo::QmBattery::StateNotCharging); m_logic->batteryStateChanged (MeeGo::QmBattery::StateLow); QTest::qWait (10); QCOMPARE (spy.count (), 1); arguments = spy.takeFirst (); QVERIFY (arguments.at (0).toString () == "x-nokia.battery.lowbattery"); QVERIFY (arguments.at (1).toString () == qtTrId ("qtn_ener_lowbatt")); QVERIFY (arguments.at (2).toString () == ""); #endif }