void tst_IdentityInterface::identifierPending() { { // test pending identifier with zero (creates new account) QScopedPointer<IdentityInterface> identity(new IdentityInterface); identity->classBegin(); identity->setIdentifierPending(true); QCOMPARE(identity->identifierPending(), true); identity->componentComplete(); // should NOT trigger creation of a new identity QTest::qWait(1000); // give it enough time to ensure that it's staying initializing. QCOMPARE(identity->status(), IdentityInterface::Initializing); // should remain initializing. QCOMPARE(identity->identifier(), 0); QSignalSpy spy(identity.data(), SIGNAL(identifierChanged())); identity->setIdentifier(0); // even though it's the same value, this triggers the creation. QTRY_COMPARE(identity->status(), IdentityInterface::Initialized); identity->setUserName(QString(QLatin1String("test-username"))); identity->setSecret(QString(QLatin1String("test-secret"))); identity->setCaption(QString(QLatin1String("test-caption"))); identity->setMethodMechanisms(QString(QLatin1String("password")), QStringList() << QString(QLatin1String("ClientLogin"))); identity->sync(); QTRY_VERIFY(identity->identifier() > 0); QCOMPARE(spy.count(), 1); // should emit when it gets the "real" value. // cleanup identity->remove(); } { // test pending identifier of non-existent identity identifier QScopedPointer<IdentityInterface> identity(new IdentityInterface); identity->classBegin(); QCOMPARE(identity->identifierPending(), false); identity->setIdentifierPending(true); QCOMPARE(identity->identifierPending(), true); identity->setIdentifierPending(false); QCOMPARE(identity->identifierPending(), false); // should be settable multiple times to avoid binding re-evaluation issues identity->setIdentifierPending(true); QCOMPARE(identity->identifierPending(), true); identity->componentComplete(); // should NOT trigger creation of a new identity, but should stop us from changing identifier pending. identity->setIdentifierPending(false); // should fail QCOMPARE(identity->identifierPending(), true); QTest::qWait(1000); // give it enough time to ensure that it's staying initializing. QCOMPARE(identity->status(), IdentityInterface::Initializing); // should remain initializing. QCOMPARE(identity->identifier(), 0); QSignalSpy spy(identity.data(), SIGNAL(identifierChanged())); identity->setIdentifier(99999999); QCOMPARE(identity->identifier(), 99999999); QTRY_VERIFY(identity->status() != IdentityInterface::Initializing); // should transition out of this state. QTRY_VERIFY(identity->error() != IdentityInterface::NoError); // should be an error, since that identifier shouldn't be valid. QVERIFY(spy.count() > 0); } }
void tst_IdentityInterface::identifier() { QScopedPointer<IdentityInterface> identity(new IdentityInterface); identity->classBegin(); identity->componentComplete(); QTRY_COMPARE(identity->status(), IdentityInterface::Initialized); QCOMPARE(identity->identifier(), 0); QSignalSpy spy(identity.data(), SIGNAL(identifierChanged())); identity->setUserName(QString(QLatin1String("test-username"))); identity->setSecret(QString(QLatin1String("test-secret"))); identity->setCaption(QString(QLatin1String("test-caption"))); identity->setMethodMechanisms(QString(QLatin1String("password")), QStringList() << QString(QLatin1String("ClientLogin"))); identity->sync(); QTRY_COMPARE(spy.count(), 1); QVERIFY(identity->identifier() > 0); QScopedPointer<IdentityInterface> identityTwo(new IdentityInterface); identityTwo->classBegin(); identityTwo->componentComplete(); QTRY_COMPARE(identityTwo->status(), IdentityInterface::Initialized); QCOMPARE(identityTwo->identifier(), 0); QSignalSpy spyTwo(identityTwo.data(), SIGNAL(identifierChanged())); identityTwo->setUserName(QString(QLatin1String("test-username-two"))); identityTwo->setSecret(QString(QLatin1String("test-secret"))); identityTwo->setCaption(QString(QLatin1String("test-caption"))); identityTwo->setMethodMechanisms(QString(QLatin1String("password")), QStringList() << QString(QLatin1String("ClientLogin"))); identityTwo->sync(); QTRY_COMPARE(spyTwo.count(), 1); QVERIFY(identityTwo->identifier() > 0); // this one doesn't create a new identity, but references an existing identity QScopedPointer<IdentityInterface> identityThree(new IdentityInterface); identityThree->classBegin(); identityThree->setIdentifier(identity->identifier()); identityThree->componentComplete(); QTRY_COMPARE(identityThree->status(), IdentityInterface::Initialized); QCOMPARE(identityThree->userName(), QLatin1String("test-username")); identityThree->setIdentifier(identityTwo->identifier()); // test that you can set it after initialization. QCOMPARE(identityThree->status(), IdentityInterface::Initializing); QTRY_COMPARE(identityThree->status(), IdentityInterface::Synced); QCOMPARE(identityThree->userName(), QLatin1String("test-username-two")); // cleanup identity->remove(); identityTwo->remove(); }
void CommentFilterInterface::setIdentifier(const QString &identifier) { Q_D(CommentFilterInterface); if (d->identifier != identifier) { d->identifier = identifier; emit identifierChanged(); } }
/*! \reimp */ void IdentifiableContentItemInterface::emitPropertyChangeSignals(const QVariantMap &oldData, const QVariantMap &newData) { Q_D(IdentifiableContentItemInterface); // most derived types will do: // { // foreach (key, propKeys) { // if (newData.value(key) != oldData.value(key)) { // emit thatPropertyChanged(); // } // } // SuperClass::emitPropertyChangeSignals(oldData, newData); // } // But this one is a bit special, since if the id changed, it's a terrible error. // check identifier - NOTE: derived types MUST fill out this field before calling this class' implementation of emitPropertyChangeSignals. QString oldId = oldData.value(NEMOQMLPLUGINS_SOCIAL_CONTENTITEMID).toString(); QString newId = newData.value(NEMOQMLPLUGINS_SOCIAL_CONTENTITEMID).toString(); if (newId.isEmpty() && oldId.isEmpty()) { // this will fall through to being reported as an error due to identifier change (to empty) below. qWarning() << Q_FUNC_INFO << "ERROR: derived types MUST set the NEMOQMLPLUGINS_SOCIAL_CONTENTITEMID field appropriately prior to calling the superclass emitPropertyChangeSignals() function!"; } if (oldId.isEmpty()) oldId = d->identifier; // might have been set directly by client via icii.setIdentifier() which sets dd->identifier. if (oldId.isEmpty() && !newId.isEmpty()) { // this must be a new object created by the model. We now have an identifier; set it and update. d->identifier = newId; emit identifierChanged(); } else if (newId.isEmpty() || oldId != newId) { // the identifier changed. This shouldn't happen in real life. Must be an error. d->status = SocialNetworkInterface::Invalid; d->error = SocialNetworkInterface::DataUpdateError; d->errorMessage = QString(QLatin1String("identifier changed during data update from %1 to %2")).arg(oldId).arg(newId); d->s = 0; emit statusChanged(); emit errorChanged(); emit errorMessageChanged(); emit socialNetworkChanged(); } // finally, as all derived classes must do, call super class implementation. ContentItemInterface::emitPropertyChangeSignals(oldData, newData); }
void QTQmlSensor::setIdentifier(const QString &identifier) { if (m_parsed) return; m_identifier = identifier; Q_EMIT identifierChanged(); }