void Ut_AboutBusinessLogic::testBluetooth () { QSignalSpy spy ( m_Api, SIGNAL (requestFinished (AboutBusinessLogic::requestType, QVariant))); QMap <QString, QVariant> properties; properties["Address"] = QString ("fake-bluetooth-address"); /* * Let's initiate the Bluetooth query that will call the * QDBusAbstractInterface::callWithCallback() that is stubbed. */ m_Api->initiateBluetoothQueries (); QCOMPARE (lastCalledMethod, QString ("DefaultAdapter")); /* * Let's answer the previous step by calling the DBus callback manually. * This will initiate an other DBus call also stubbed. */ m_Api->defaultBluetoothAdapterReceived ( QDBusObjectPath("/fakeObjectPath")); QCOMPARE (lastCalledMethod, QString ("GetProperties")); /* * Answering the second DBus call and checking if the businesslogic * processed the data as it should. */ m_Api->defaultBluetoothAdapterAddressReceived (properties); QTest::qWait (100); QCOMPARE (spy.count (), 1); QList<QVariant> args = spy.first (); QCOMPARE (args.at (0).value<AboutBusinessLogic::requestType>(), AboutBusinessLogic::reqBtAddr); #if 0 /* for some strange reason it is not working :-S */ QCOMPARE (args.at (1).toString (), QString ("fake-bluetooth-address")); #endif /* * Let's test the failure socket. This does not do nothing... */ m_Api->DBusMessagingFailure (QDBusError()); delete m_Api; /* * Let's see what happens if we initate the data collection and instead of * producing answers to queries we just destroy the object. */ m_Api = new AboutBusinessLogic; m_Api->initiateBluetoothQueries (); //XXX: delete m_Api; (done in cleanup ()) }
qDebug() << p.name() <<": isvalid->" <<p.isValid() << " type->"<< p.type() << " roaming->" << p.isRoamingAvailable() << "identifier->" << p.identifier() << " purpose->" << p.purpose() << " state->" << p.state(); } void tst_QNetworkConfigurationManager::allConfigurations() { QNetworkConfigurationManager manager; QList<QNetworkConfiguration> preScanConfigs = manager.allConfigurations(); foreach(QNetworkConfiguration c, preScanConfigs) { QVERIFY2(c.type()!=QNetworkConfiguration::UserChoice, "allConfiguration must not return UserChoice configs"); } QSignalSpy spy(&manager, SIGNAL(updateCompleted())); manager.updateConfigurations(); //initiate scans QTRY_VERIFY_WITH_TIMEOUT(spy.count() == 1, TestTimeOut); //wait for scan to complete QList<QNetworkConfiguration> configs = manager.allConfigurations(); int all = configs.count(); qDebug() << "All configurations:" << all; QVERIFY(all); foreach(QNetworkConfiguration p, configs) { QVERIFY(p.isValid()); printConfigurationDetails(p); QVERIFY(p.type() != QNetworkConfiguration::Invalid); QVERIFY(p.type() != QNetworkConfiguration::UserChoice); }
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_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 testQOfonoVoiceCall() { QSignalSpy dialreg(m,SIGNAL(dialComplete(bool))); QSignalSpy dspy(m, SIGNAL(callAdded(QString))); // Dial and hangup m->dial("123",""); QTest::qWait(1000); QCOMPARE(dialreg.count(), 1); QCOMPARE(dialreg.takeFirst().at(0).toBool(),true); QCOMPARE(dspy.count(), 1); QString callid = dspy.takeFirst().at(0).toString(); QOfonoVoiceCall* call = new QOfonoVoiceCall(this); call->setVoiceCallPath(callid); QTRY_VERIFY(call->isValid()); QSignalSpy state(call, SIGNAL(stateChanged(QString))); QSignalSpy discreason(call,SIGNAL(disconnectReason(QString))); QSignalSpy hspy(call, SIGNAL(hangupComplete(bool))); QSignalSpy li (call, SIGNAL(lineIdentificationChanged(QString))); QSignalSpy name (call, SIGNAL(nameChanged(QString))); QSignalSpy info (call, SIGNAL(informationChanged(QString))); QSignalSpy mp (call, SIGNAL(multipartyChanged(bool))); QSignalSpy em (call, SIGNAL(emergencyChanged(bool))); QSignalSpy st (call, SIGNAL(startTimeChanged(QString))); QSignalSpy ic (call, SIGNAL(iconChanged(quint8))); qDebug() << "Please find a call in 'Dialing' state in phonesim window and press 'Active' button"; QTest::qWait(15000); QVERIFY(state.count()>0); QVERIFY(st.count()>0); QVERIFY(ic.count()==0); QVERIFY(em.count()==0); QVERIFY(mp.count()==0); QVERIFY(info.count()==0); QVERIFY(name.count()==0); QVERIFY(li.count()==0); QCOMPARE(call->state(),QString("active")); QCOMPARE(call->lineIdentification(),QString("123")); QCOMPARE(call->emergency(),false); QCOMPARE(call->multiparty(),false); QCOMPARE(call->name(),QString("")); QCOMPARE(call->information(),QString("")); call->hangup(); QTest::qWait(5000); QCOMPARE(hspy.count(), 1); QCOMPARE(hspy.takeFirst().at(0).toBool(),true); QCOMPARE(discreason.count(), 1); QCOMPARE(discreason.takeFirst().at(0).toString(), QString("local")); delete call; }
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()); }
void EventSpyTest::assertEventReceivedSignal(const QSignalSpy& spy, int index, QObject* object, QEvent* event) const { QCOMPARE(spy.at(index).count(), 2); QVariant argument = spy.at(index).at(0); QCOMPARE(argument.userType(), (int)QMetaType::QObjectStar); QCOMPARE(qvariant_cast<QObject*>(argument), object); argument = spy.at(index).at(1); QCOMPARE(argument.userType(), mEventStarType); QCOMPARE(qvariant_cast<QEvent*>(argument), event); }
/** * 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_MTapStateMachine::testLongPressAndRelease() { QSignalSpy *spyDelayedPress = new QSignalSpy(machine, SIGNAL(delayedPress())); QSignalSpy *spyRelease = new QSignalSpy(machine, SIGNAL(release())); QCoreApplication::processEvents(); QCoreApplication::sendEvent(fakeObject, new QGraphicsSceneMouseEvent(QEvent::GraphicsSceneMousePress)); QCoreApplication::processEvents(); sleep(1); QCoreApplication::processEvents(); QCoreApplication::sendEvent(fakeObject, new QGraphicsSceneMouseEvent(QEvent::GraphicsSceneMouseRelease)); QCoreApplication::processEvents(); QCOMPARE(spyDelayedPress->count(),1); QCOMPARE(spyRelease->count(),1); }
static qint64 countBytesWritten(QSignalSpy& bytesWrittenSpy) { qint64 ret = 0; for(int i = 0; i < bytesWrittenSpy.count(); i++) { ret+=bytesWrittenSpy[i].at(0).value<qint64>(); } return ret; }
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 testQOfonoVoiceCallStep2() { //Dial failure, incoming, answer and local hangup QSignalSpy callsignal(m, SIGNAL(callAdded(QString))); m->dial("199",""); QTest::qWait(8000); QCOMPARE(callsignal.count(),1); QString callid = callsignal.takeFirst().at(0).toString(); QOfonoVoiceCall* call = new QOfonoVoiceCall(this); call->setVoiceCallPath(callid); QSignalSpy state(call, SIGNAL(stateChanged(QString))); QSignalSpy time(call,SIGNAL(startTimeChanged(QString))); QSignalSpy discreason(call,SIGNAL(disconnectReason(QString))); QSignalSpy hspy(call, SIGNAL(hangupComplete(bool))); QSignalSpy aspy(call, SIGNAL(answerComplete(bool))); QSignalSpy li (call, SIGNAL(lineIdentificationChanged(QString))); QSignalSpy name (call, SIGNAL(nameChanged(QString))); QSignalSpy info (call, SIGNAL(informationChanged(QString))); QSignalSpy mp (call, SIGNAL(multipartyChanged(bool))); QSignalSpy em (call, SIGNAL(emergencyChanged(bool))); QSignalSpy ic (call, SIGNAL(iconChanged(quint8))); QTest::qWait(8000); QCOMPARE(call->state(),QString("incoming")); call->answer(); QTest::qWait(10000); QVERIFY(state.count()>0); QCOMPARE(call->lineIdentification(),QString("1234567")); //PhoneSim specific value QVERIFY(time.count()>0); QCOMPARE(aspy.count(), 1); QCOMPARE(aspy.takeFirst().at(0).toBool(),true); QVERIFY(ic.count()==0); QVERIFY(em.count()==0); QVERIFY(mp.count()==0); QVERIFY(info.count()==0); QVERIFY(name.count()==0); QVERIFY(li.count()==0); call->hangup(); QTest::qWait(5000); QCOMPARE(hspy.count(), 1); QCOMPARE(hspy.takeFirst().at(0).toBool(), true); QCOMPARE(discreason.count(), 1); QCOMPARE(discreason.takeFirst().at(0).toString(), QString("local")); delete call; }
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 }
QT_USE_NAMESPACE_JSONSTREAM void waitForSpy(QSignalSpy& spy, int count, int timeout=5000) { QTime stopWatch; stopWatch.restart(); forever { if (spy.count() == count) break; QTestEventLoop::instance().enterLoop(1); if (stopWatch.elapsed() >= timeout) QFAIL("Timed out"); } }
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::testInitBattery () { #ifdef HAVE_QMSYSTEM QSignalSpy spy (m_logic, SIGNAL (notificationSent (QString, QString, QString))); /* Set some ret. values for stubs */ gQmBatteryStub->stubSetReturnValue<MeeGo::QmBattery::ChargingState> ( "getChargingState", MeeGo::QmBattery::StateNotCharging); gQmBatteryStub->stubSetReturnValue<MeeGo::QmBattery::BatteryState> ( "getBatteryState", MeeGo::QmBattery::StateOK); /* no notification should be shown, * and battery-charging pattern should be deactivated: */ m_logic->initBattery (); /* wait for signals... if any... */ QTest::qWait (10); QCOMPARE (spy.count (), 0); QVERIFY (gQmLEDStub->stubLastCallTo ("deactivate").parameter<QString>(0) == QString ("PatternBatteryCharging")); #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_qtcontacts_trackerplugin_resourcecache::testTrackerIdResolver() { QFETCH(QStringList, iriList); QctResourceCache::instance().clear(); foreach(const QString &iri, iriList) { QVERIFY2(0 == QctResourceCache::instance().trackerId(iri), qPrintable(iri)); } QEventLoop loop; QctTrackerIdResolver resolver(iriList); connect(&resolver, SIGNAL(finished()), &loop, SLOT(quit())); QSignalSpy spy(&resolver, SIGNAL(finished())); QCOMPARE(spy.count(), 0); QVERIFY(resolver.lookup()); QCOMPARE(spy.count(), 0); loop.exec(); QCOMPARE(spy.count(), 1); QCOMPARE(resolver.trackerIds().count(), iriList.count()); foreach(uint id, resolver.trackerIds()) { QVERIFY(0 != id); } for(int i = 0; i < iriList.count(); ++i) {
#include <QTest> #include <QSignalSpy> #include "TimerTest.h" TimerTest::TimerTest() { myDialog = new Dialog(); } TimerTest::~TimerTest() { delete myDialog; } void TimerTest::testSignals(){ QSignalSpy s(myDialog->timersComboBox,SIGNAL(currentIndexChanged(int))); myDialog->timersComboBox->setCurrentIndex(0); myDialog->timersComboBox->setCurrentIndex(1); myDialog->timersComboBox->setCurrentIndex(0); myDialog->timersComboBox->setCurrentIndex(1); QCOMPARE(3,s.count()); } void TimerTest::testSetValueToTimer() { myDialog->setIntervalLineEdit->setText(""); QTest::keyPress(myDialog->setIntervalLineEdit,Qt::Key_1); QTest::keyPress(myDialog->setIntervalLineEdit,Qt::Key_0); QTest::mouseClick(myDialog->setButton,Qt::LeftButton); int period = myDialog->setIntervalLineEdit->text().toInt(); QCOMPARE(10,period); }
exit(1); } } virtual void TearDown() { } std::shared_ptr<StateExchanger> stateexchanger_; std::shared_ptr<QDBusInterface> dbus_luminosity_; std::shared_ptr<QDBusInterface> dbus_brightness_; std::shared_ptr<QDBusInterface> dbus_moisture_; std::shared_ptr<QDBusInterface> dbus_warning_; std::shared_ptr<QDBusInterface> dbus_proximity_; }; TEST_F(StateExchangerTest, can_get_and_set_luminosity) { QSignalSpy spy(stateexchanger_->luminosity().get(), SIGNAL(luminosityChanged(double))); dbus_luminosity_->setProperty("scaled", 0.5); EXPECT_EQ(spy.count(),1); EXPECT_EQ(dbus_luminosity_->property("scaled"), 0.5); spy.clear(); dbus_luminosity_->setProperty("scaled", -0.1); EXPECT_EQ(spy.count(),0); EXPECT_EQ(dbus_luminosity_->property("scaled"), 0.5); spy.clear(); dbus_luminosity_->setProperty("scaled", 1.1); EXPECT_EQ(spy.count(),0); EXPECT_EQ(dbus_luminosity_->property("scaled"), 0.5); }
//! [1] QSignalSpy spy(myCustomObject, SIGNAL(mySignal(int,QString,double))); myCustomObject->doSomething(); // trigger emission of the signal QList<QVariant> arguments = spy.takeFirst(); QVERIFY(arguments.at(0).type() == QVariant::Int); QVERIFY(arguments.at(1).type() == QVariant::QString); QVERIFY(arguments.at(2).type() == QVariant::double); //! [1] //! [2] qRegisterMetaType<SomeStruct>(); QSignalSpy spy(&model, SIGNAL(whatever(SomeStruct))); //! [2] //! [3] // get the first argument from the first received signal: SomeStruct result = qvariant_cast<SomeStruct>(spy.at(0).at(0)); //! [3] //! [4] QSignalSpy spy(myPushButton, SIGNAL(clicked(bool))); //! [4] //! [5] QVERIFY(spy.wait(1000));
void syntaxHighlightTest() { const QVector<QString> files( {"testdata/grammers/C.tmLanguage", "testdata/grammers/C++.tmLanguage"}); foreach (QString fn, files) { QVERIFY(LanguageProvider::loadLanguage(fn)); } QFile file("testdata/Benchmark_1007.cpp"); QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Text)); QTextStream in(&file); QTextDocument* doc = new QTextDocument(in.readAll()); const auto& text = doc->toPlainText(); QTime startTime = QTime::currentTime(); std::unique_ptr<LanguageParser> parser(LanguageParser::create("source.c++", text)); SyntaxHighlighter cppHighlighter(doc, std::move(parser), theme, font); QSignalSpy spy(&cppHighlighter, &SyntaxHighlighter::parseFinished); QVERIFY(spy.wait()); int passed = startTime.msecsTo(QTime::currentTime()); qDebug() << passed << "[ms]"; QVERIFY(passed < 600); } void largeSyntaxHighlightTest() { const QVector<QString> files( {"testdata/grammers/C.tmLanguage", "testdata/grammers/C++.tmLanguage"}); foreach (QString fn, files) { QVERIFY(LanguageProvider::loadLanguage(fn)); } QFile file("testdata/Benchmark_12867.cpp"); QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Text));
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 }
PlayerId ConfigurationComponentTest::extractPlayerIdFromConfigurationResponse() const { QList<QVariant> arguments = configurationResponseSpy.first(); return arguments.at(0).value<PlayerId>(); }
QString ConfigurationComponentTest::extractPlayerNameFromConfigurationResponse() const { QList<QVariant> arguments = configurationResponseSpy.first(); return arguments.at(1).toString(); }
QCOMPARE(spy.count(),1); } void SpriteFormatToolBarTest::testShouldEmitSignalSettingsChangedOnYMarginChanged() { QSignalSpy spy(this->spriteFormatToolBar, SIGNAL(settingsChanged())); QTest::keyClick( this->spriteFormatToolBar->ui()->yMarginSpinBox, Qt::Key_Up ); QCOMPARE(spy.count(),1); } void SpriteFormatToolBarTest::testShouldEmitSignalRepeatNeedsAutoChangeOnSpriteRepeatChanged() { QSignalSpy spy(this->spriteFormatToolBar, SIGNAL(repeatNeedsAutoChange(bool))); QTest::keyClick( this->spriteFormatToolBar->ui()->spriteRepeatComboBox, Qt::Key_Down ); QCOMPARE(spy.count(),2); } void SpriteFormatToolBarTest::testShouldEmitSignalSettingsChangedOnElementLayoutChanged() { QSignalSpy spy(this->spriteFormatToolBar, SIGNAL(settingsChanged())); QTest::keyClick( this->spriteFormatToolBar->ui()->elementLayoutComboBox, Qt::Key_Down
//! [0] //! [1] QSignalSpy spy(myCustomObject, SIGNAL(mySignal(int, QString, double))); myCustomObject->doSomething(); // trigger emission of the signal QList<QVariant> arguments = spy.takeFirst(); QVERIFY(arguments.at(0).type() == QVariant::Int); QVERIFY(arguments.at(1).type() == QVariant::QString); QVERIFY(arguments.at(2).type() == QVariant::double); //! [1] //! [2] qRegisterMetaType<QModelIndex>("QModelIndex"); QSignalSpy spy(&model, SIGNAL(whatever(QModelIndex))); //! [2] //! [3] // get the first argument from the first received signal: QModelIndex result = qvariant_cast<QModelIndex>(spy.at(0).at(0)); //! [3] //! [4] QSignalSpy spy(myPushButton, SIGNAL(clicked(bool))); //! [4]
void DupeTest::testDupes() { QFETCH(QString, message); QFETCH(int, count); QFETCH(int, delay); // clean sink ItemFetchJob *fjob = new ItemFetchJob(sink, this); AKVERIFYEXEC(fjob); if (fjob->items().count() > 0) { // this test is needed because ItemDeleteJob gives error if no items are found ItemDeleteJob *djob = new ItemDeleteJob(sink, this); AKVERIFYEXEC(djob); } fjob = new ItemFetchJob(sink, this); AKVERIFYEXEC(fjob); QCOMPARE(fjob->items().count(), 0); // queue messages Q_ASSERT(monitor); QSignalSpy *addSpy = new QSignalSpy(monitor, SIGNAL(itemAdded(Akonadi::Item,Akonadi::Collection))); qDebug() << "Queuing" << count << "messages..."; for (int i = 0; i < count; i++) { //qDebug() << "Queuing message" << i + 1 << "of" << count; Message::Ptr msg = Message::Ptr(new Message); msg->setContent(QStringLiteral("%1-msg%2\n").arg(message).arg(i + 1, 2, 10, QLatin1Char('0')).toLatin1()); MessageQueueJob *job = new MessageQueueJob(this); job->setMessage(msg); job->transportAttribute().setTransportId(TransportManager::self()->defaultTransportId()); // default dispatch mode // default sent-mail collection job->addressAttribute().setFrom(QStringLiteral("naiba")); job->addressAttribute().setTo(QStringList() << QStringLiteral("dracu")); //AKVERIFYEXEC( job ); job->start(); QTest::qWait(delay); } qDebug() << "Queued" << count << "messages."; // wait for the MDA to send them int seconds = 0; while (true) { seconds++; QTest::qWait(1000); qDebug() << seconds << "seconds elapsed." << addSpy->count() << "messages got to sink."; if (addSpy->count() >= count) { break; } #if 0 if (seconds >= TIMEOUT_SECONDS) { qDebug() << "Timeout, gdb master!"; QTest::qWait(1000 * 1000); } #endif QVERIFY2(seconds < TIMEOUT_SECONDS, "Timeout"); } // TODO I should verify that the MDA has actually finished its work and has an empty queue QTest::qWait(2000); // verify what has been sent fjob = new ItemFetchJob(sink, this); fjob->fetchScope().fetchFullPayload(); AKVERIFYEXEC(fjob); const Item::List items = fjob->items(); int found[ MAXCOUNT ]; for (int i = 0; i < count; i++) { found[i] = 0; } for (int i = 0; i < items.count(); i++) { QVERIFY(items[i].hasPayload<Message::Ptr>()); Message::Ptr msg = items[i].payload<Message::Ptr>(); const QByteArray content = msg->encodedContent(); //qDebug() << "i" << i << "content" << content; int loc = content.indexOf("-msg"); QVERIFY(loc >= 0); bool ok; int who = content.mid(loc + 4, 2).toInt(&ok); QVERIFY(ok); //qDebug() << "identified msg" << who; QVERIFY(who > 0 && who <= count); found[ who - 1 ]++; } for (int i = 0; i < count; i++) { if (found[i] > 1) { qDebug() << "found duplicate message" << i + 1 << "(" << found[i] << "times )"; } else if (found[i] < 1) { qDebug() << "didn't find message" << i + 1; } QCOMPARE(found[i], 1); } QCOMPARE(addSpy->count(), count); QCOMPARE(items.count(), count); }