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 157aa3e1 authored by Laurent Montel's avatar Laurent Montel 😁

Improve unittest

parent 0ad2fe52
......@@ -73,6 +73,25 @@ bool Email::operator==(const Email &other) const
return (d->parameters == other.parameters()) && (d->mail == other.mail()) && (d->preferred == other.preferred());
}
QString Email::toString() const
{
QString str;
str += QString::fromLatin1( "Email {\n" );
str += QString::fromLatin1( " mail: %1\n" ).arg( d->mail );
str += QString::fromLatin1( " prefered: %1\n" ).arg( d->preferred ? QLatin1String("True") : QLatin1String("False") );
if (!d->parameters.isEmpty()) {
QMapIterator<QString, QStringList> i(d->parameters);
QString param;
while (i.hasNext()) {
i.next();
param += QString::fromLatin1("%1 %2").arg(i.key()).arg(i.value().join(QLatin1String(",")));
}
str += QString::fromLatin1( " parameters: %1\n" ).arg( param );
}
str += QString::fromLatin1( "}\n" );
return str;
}
void Email::setPreferred(bool pref)
{
d->preferred = pref;
......
......@@ -59,6 +59,7 @@ public:
bool operator==( const Email &other ) const;
QString toString() const;
private:
class Private;
QSharedDataPointer<Private> d;
......
......@@ -41,4 +41,47 @@ void EmailTest::shouldHaveDefaultValue()
QVERIFY(!email.preferred());
}
void EmailTest::shouldAssignValue()
{
const QString mail(QLatin1String("foo@kde.org"));
const bool preferred = true;
KABC::Email email(mail, preferred);
QVERIFY(email.isValid());
QVERIFY(!email.mail().isEmpty());
QCOMPARE(email.mail(), mail);
QVERIFY(email.preferred());
}
void EmailTest::shouldAssignExternal()
{
KABC::Email email;
const QString mail(QLatin1String("foo@kde.org"));
const bool preferred = true;
email.setEmail(mail);
email.setPreferred(preferred);
QVERIFY(email.isValid());
QVERIFY(!email.mail().isEmpty());
QCOMPARE(email.mail(), mail);
QVERIFY(email.preferred());
}
void EmailTest::shouldSerialized()
{
KABC::Email email;
KABC::Email result;
const QString mail(QLatin1String("foo@kde.org"));
const bool preferred = true;
email.setEmail(mail);
email.setPreferred(preferred);
QByteArray data;
QDataStream s( &data, QIODevice::WriteOnly );
s << email;
QDataStream t( &data, QIODevice::ReadOnly );
t >> result;
QVERIFY( email == result );
}
QTEST_KDEMAIN(EmailTest, NoGUI)
......@@ -32,6 +32,9 @@ public:
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldAssignValue();
void shouldAssignExternal();
void shouldSerialized();
};
#endif // EMAILTEST_H
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