Commit 975cbfee authored by Laurent Montel's avatar Laurent Montel 😁

Unit test++

parent b17b85bc
......@@ -22,9 +22,11 @@
#include <qtest_kde.h>
#include <QSignalSpy>
Q_DECLARE_METATYPE(PimCommon::ShortUrlUtils::EngineType)
ShortUrlEnginesTest::ShortUrlEnginesTest(QObject *parent)
: QObject(parent)
{
qRegisterMetaType<PimCommon::ShortUrlUtils::EngineType>();
}
......@@ -42,14 +44,31 @@ void ShortUrlEnginesTest::shouldCreateEngine()
}
}
void ShortUrlEnginesTest::shouldtestenginesData()
void ShortUrlEnginesTest::shouldTestEngines_data()
{
QTest::addColumn<PimCommon::ShortUrlUtils::EngineType>("engine");
QTest::addColumn<QString>("longurl");
QTest::addColumn<QString>("shorturl");
QTest::newRow("google url") << PimCommon::ShortUrlUtils::Google << QString::fromLatin1("http://www.kde.org") << QString::fromLatin1("http://goo.gl/sMKw");
QTest::newRow("tiny url") << PimCommon::ShortUrlUtils::Tinyurl << QString::fromLatin1("http://www.kde.org") << QString::fromLatin1("http://tinyurl.com/l6l0");
//WE can't test migreme...
//QTest::newRow("migreme url") << PimCommon::ShortUrlUtils::MigreMe << QString::fromLatin1("http://www.kde.org") << QString::fromLatin1("http://migre.me/nwh5a");
QTest::newRow("triopAB url") << PimCommon::ShortUrlUtils::TriopAB << QString::fromLatin1("http://www.kde.org") << QString::fromLatin1("http://to.ly/51UP");
}
void ShortUrlEnginesTest::shouldTestEngines()
{
QFETCH( PimCommon::ShortUrlUtils::EngineType, engine );
QFETCH( QString, longurl );
QFETCH( QString, shorturl );
PimCommon::AbstractShortUrl *abstrShortUrl = PimCommon::ShortUrlUtils::loadEngine(engine, 0);
abstrShortUrl->shortUrl(longurl);
QSignalSpy spy(abstrShortUrl, SIGNAL(shortUrlDone(QString)));
abstrShortUrl->start();
QVERIFY(QTest::kWaitForSignal(abstrShortUrl, SIGNAL(shortUrlDone(QString)), 10000));
QCOMPARE(spy.at(0).count(), 1);
QCOMPARE(spy.at(0).at(0).toString(), shorturl);
}
QTEST_KDEMAIN(ShortUrlEnginesTest, NoGUI)
......@@ -28,8 +28,8 @@ public:
explicit ShortUrlEnginesTest(QObject *parent = 0);
~ShortUrlEnginesTest();
private Q_SLOTS:
void shouldTestEngines_data();
void shouldCreateEngine();
void shouldtestenginesData();
void shouldTestEngines();
};
......
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