File indexing completed on 2024-05-19 15:23:04

0001 /*
0002     This file is part of the syndication library
0003     SPDX-FileCopyrightText: 2006 Frank Osterfeld <osterfeld@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #include "testpersonimpl.h"
0009 #include "person.h"
0010 #include "personimpl.h"
0011 #include "tools.h"
0012 #include <QList>
0013 #include <QString>
0014 #include <QStringList>
0015 
0016 using Syndication::Person;
0017 using Syndication::PersonImpl;
0018 using Syndication::PersonPtr;
0019 
0020 void TestPersonImpl::fromString()
0021 {
0022     QStringList s;
0023     QList<PersonPtr> p;
0024 
0025     s.append(QString());
0026     p.append(PersonPtr(new PersonImpl(QString(), QString(), QString())));
0027 
0028     s.append(QLatin1String(""));
0029     p.append(PersonPtr(new PersonImpl(QString(), QString(), QString())));
0030 
0031     s.append(QStringLiteral("foo@bar.com"));
0032     p.append(PersonPtr(new PersonImpl(QString(), QString(), QStringLiteral("foo@bar.com"))));
0033 
0034     s.append(QStringLiteral("<foo@bar.com>"));
0035     p.append(PersonPtr(new PersonImpl(QString(), QString(), QStringLiteral("foo@bar.com"))));
0036 
0037     s.append(QStringLiteral("Foo"));
0038     p.append(PersonPtr(new PersonImpl(QStringLiteral("Foo"), QString(), QString())));
0039 
0040     s.append(QStringLiteral("Foo M. Bar"));
0041     p.append(PersonPtr(new PersonImpl(QStringLiteral("Foo M. Bar"), QString(), QString())));
0042 
0043     s.append(QStringLiteral("Foo <foo@bar.com>"));
0044     p.append(PersonPtr(new PersonImpl(QStringLiteral("Foo"), QString(), QStringLiteral("foo@bar.com"))));
0045 
0046     s.append(QStringLiteral("Foo Bar <foo@bar.com>"));
0047     p.append(PersonPtr(new PersonImpl(QStringLiteral("Foo Bar"), QString(), QStringLiteral("foo@bar.com"))));
0048 
0049     s.append(QStringLiteral("John Doe (President) <john@doe.com>"));
0050     p.append(PersonPtr(new PersonImpl(QStringLiteral("John Doe (President)"), QString(), QStringLiteral("john@doe.com"))));
0051 
0052     s.append(QStringLiteral("John Doe (President)"));
0053     p.append(PersonPtr(new PersonImpl(QStringLiteral("John Doe (President)"), QString(), QString())));
0054 
0055     s.append(QStringLiteral("John Doe (President)) <john@doe.com>"));
0056     p.append(PersonPtr(new PersonImpl(QStringLiteral("John Doe (President))"), QString(), QStringLiteral("john@doe.com"))));
0057 
0058     s.append(QStringLiteral("(President) John Doe <john@doe.com>"));
0059     p.append(PersonPtr(new PersonImpl(QStringLiteral("(President) John Doe"), QString(), QStringLiteral("john@doe.com"))));
0060 
0061     s.append(QStringLiteral("<foo@bar.com> (Foo Bar)"));
0062     p.append(PersonPtr(new PersonImpl(QStringLiteral("Foo Bar"), QString(), QStringLiteral("foo@bar.com"))));
0063 
0064     // s.append("OnAhlmann(mailto:&amp;#111;&amp;#110;&amp;#97;&amp;#104;&amp;#108;&amp;#109;&amp;#97;&amp;#110;&amp;#110;&amp;#64;&amp;#103;&amp;#109;&amp;#97;&amp;#105;&amp;#108;&amp;#46;&amp;#99;&amp;#111;&amp;#109;)");
0065     // p.append(PersonPtr(new PersonImpl("OnAhlmann", QString(), "onahlmann@gmail.com")));
0066 
0067     QList<PersonPtr> q;
0068 
0069     QStringList::ConstIterator it = s.constBegin();
0070     QStringList::ConstIterator end = s.constEnd();
0071     QList<PersonPtr>::ConstIterator pit = p.constBegin();
0072 
0073     while (it != end) {
0074         PersonPtr q(Syndication::personFromString(*it));
0075         QCOMPARE(q->name(), (*pit)->name());
0076         QCOMPARE(q->email(), (*pit)->email());
0077         QCOMPARE(q->uri(), (*pit)->uri());
0078 
0079         ++it;
0080         ++pit;
0081     }
0082 }
0083 
0084 QTEST_MAIN(TestPersonImpl)
0085 
0086 #include "moc_testpersonimpl.cpp"