Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 8ed26bb5 authored by Laurent Montel's avatar Laurent Montel 😁

improve unitest

parent b9c96887
......@@ -57,13 +57,17 @@ void AttachmentVcardFromAddressBookJob::doStart()
if (mItem.isValid()) {
if ( mItem.hasPayload<KABC::Addressee>() ) {
const KABC::Addressee contact = mItem.payload<KABC::Addressee>();
const QString contactRealName(contact.realName());
const QString attachmentName = (contactRealName.isEmpty() ? QLatin1String("vcard") : contactRealName ) + QLatin1String( ".vcf" );
if (contact.isEmpty()) {
invalidContact();
} else {
const QString contactRealName(contact.realName());
const QString attachmentName = (contactRealName.isEmpty() ? QLatin1String("vcard") : contactRealName ) + QLatin1String( ".vcf" );
QByteArray data = mItem.payloadData();
//Workaround about broken kaddressbook fields.
MessageComposer::Util::adaptVcard(data);
addAttachment( data, attachmentName );
QByteArray data = mItem.payloadData();
//Workaround about broken kaddressbook fields.
MessageComposer::Util::adaptVcard(data);
addAttachment( data, attachmentName );
}
} else if ( mItem.hasPayload<KABC::ContactGroup>() ) {
const KABC::ContactGroup group = mItem.payload<KABC::ContactGroup>();
const QString groupName(group.name());
......@@ -78,12 +82,17 @@ void AttachmentVcardFromAddressBookJob::doStart()
emitResult();
}
} else {
setError( KJob::UserDefinedError );
setErrorText( i18n("Invalid Contact") );
emitResult();
invalidContact();
}
}
void AttachmentVcardFromAddressBookJob::invalidContact()
{
setError( KJob::UserDefinedError );
setErrorText( i18n("Invalid Contact") );
emitResult();
}
void AttachmentVcardFromAddressBookJob::slotExpandGroupResult(KJob* job)
{
Akonadi::ContactGroupExpandJob *expandJob = qobject_cast<Akonadi::ContactGroupExpandJob*>( job );
......
......@@ -37,6 +37,7 @@ private Q_SLOTS:
void slotExpandGroupResult(KJob *job);
private:
void invalidContact();
void addAttachment(const QByteArray &data, const QString &attachmentName);
Akonadi::Item mItem;
};
......
......@@ -39,6 +39,8 @@ void AttachmentVcardFromAddressBookJobTest::testAttachmentVCardWithInvalidItem()
Akonadi::Item item;
MessageComposer::AttachmentVcardFromAddressBookJob *job = new MessageComposer::AttachmentVcardFromAddressBookJob(item);
QVERIFY(!job->exec());
delete job;
job = 0;
}
void AttachmentVcardFromAddressBookJobTest::testAttachmentVCardWithValidItem()
......@@ -70,6 +72,8 @@ void AttachmentVcardFromAddressBookJobTest::testAttachmentVCardWithInvalidVCard(
Akonadi::Item item(42);
MessageComposer::AttachmentVcardFromAddressBookJob *job = new MessageComposer::AttachmentVcardFromAddressBookJob(item);
QVERIFY(!job->exec());
delete job;
job = 0;
}
void AttachmentVcardFromAddressBookJobTest::testAttachmentVCardWithEmptyVCard()
......@@ -79,8 +83,9 @@ void AttachmentVcardFromAddressBookJobTest::testAttachmentVCardWithEmptyVCard()
KABC::Addressee address;
item.setPayload<KABC::Addressee>( address );
MessageComposer::AttachmentVcardFromAddressBookJob *job = new MessageComposer::AttachmentVcardFromAddressBookJob(item);
QVERIFY(job->exec());
//TODO
QVERIFY(!job->exec());
delete job;
job = 0;
}
QTEST_KDEMAIN(AttachmentVcardFromAddressBookJobTest, GUI)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment