From 87eefbf5938e091c11e334e319691ec3cae0b24a Mon Sep 17 00:00:00 2001 From: kh1 Date: Tue, 26 Feb 2013 17:26:44 +0100 Subject: Add repository class auto test and fix missing operator export. Change-Id: Ie7b490fa66c20ddd59788f00a75e363d7bb80697 Reviewed-by: Tim Jenssen --- tests/auto/installer/installer.pro | 3 +- tests/auto/installer/repository/repository.pro | 6 ++ tests/auto/installer/repository/tst_repository.cpp | 119 +++++++++++++++++++++ 3 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 tests/auto/installer/repository/repository.pro create mode 100644 tests/auto/installer/repository/tst_repository.cpp (limited to 'tests') diff --git a/tests/auto/installer/installer.pro b/tests/auto/installer/installer.pro index c01c4125c..0c1b7f975 100644 --- a/tests/auto/installer/installer.pro +++ b/tests/auto/installer/installer.pro @@ -1,4 +1,5 @@ TEMPLATE = subdirs SUBDIRS += \ - settings + settings \ + repository diff --git a/tests/auto/installer/repository/repository.pro b/tests/auto/installer/repository/repository.pro new file mode 100644 index 000000000..2d192eeaa --- /dev/null +++ b/tests/auto/installer/repository/repository.pro @@ -0,0 +1,6 @@ +include(../../qttest.pri) + +QT += network +QT -= gui + +SOURCES += tst_repository.cpp diff --git a/tests/auto/installer/repository/tst_repository.cpp b/tests/auto/installer/repository/tst_repository.cpp new file mode 100644 index 000000000..e3b7b74a6 --- /dev/null +++ b/tests/auto/installer/repository/tst_repository.cpp @@ -0,0 +1,119 @@ +#include "repository.h" + +#include + +using namespace QInstaller; + +class tst_Repository : public QObject +{ + Q_OBJECT + +private slots: + void testRepository() + { + Repository repo; + QCOMPARE(repo.isValid(), false); + QCOMPARE(repo.isDefault(), false); + QCOMPARE(repo.isEnabled(), false); + + QCOMPARE(repo.url(), QUrl()); + QCOMPARE(repo.username(), QString()); + QCOMPARE(repo.password(), QString()); + + repo.setUrl(QUrl("http://www.digia.com")); + QCOMPARE(repo.isValid(), true); + QCOMPARE(repo.url(), QUrl("http://www.digia.com")); + + repo.setEnabled(true); + QCOMPARE(repo.isEnabled(), true); + + repo.setUsername("tester"); + QCOMPARE(repo.username(), QString("tester")); + + repo.setPassword("test"); + QCOMPARE(repo.password(), QString("test")); + } + + void testRepositoryFromUrl() + { + Repository repo(QUrl("http://www.digia.com"), true); + QCOMPARE(repo.isValid(), true); + QCOMPARE(repo.isDefault(), true); + QCOMPARE(repo.isEnabled(), true); + + QCOMPARE(repo.url(), QUrl("http://www.digia.com")); + QCOMPARE(repo.username(), QString()); + QCOMPARE(repo.password(), QString()); + + repo.setUrl(QUrl()); + QCOMPARE(repo.isValid(), false); + + repo.setEnabled(false); + QCOMPARE(repo.isEnabled(), false); + + repo.setUsername("tester"); + QCOMPARE(repo.username(), QString("tester")); + + repo.setPassword("test"); + QCOMPARE(repo.password(), QString("test")); + } + + void testRepositoryFromUserInput() + { + Repository repo = Repository::fromUserInput("ftp://tester:test@www.digia.com"); + QCOMPARE(repo.isValid(), true); + QCOMPARE(repo.isDefault(), false); + QCOMPARE(repo.isEnabled(), true); + + QCOMPARE(repo.url(), QUrl("ftp://www.digia.com")); + QCOMPARE(repo.username(), QString("tester")); + QCOMPARE(repo.password(), QString("test")); + + repo.setUrl(QUrl()); + QCOMPARE(repo.isValid(), false); + + repo.setEnabled(false); + QCOMPARE(repo.isEnabled(), false); + + repo.setUsername(""); + QCOMPARE(repo.username(), QString()); + + repo.setPassword(""); + QCOMPARE(repo.password(), QString()); + } + + void testRepositoryOperators() + { + Repository lhs, rhs; + + // operator== + QVERIFY(lhs == rhs); + + // assignment operator + rhs = Repository::fromUserInput("ftp://tester:test@www.digia.com"); + + // operator!= + QVERIFY(lhs != rhs); + + // copy constructor + Repository clhs(rhs); + + // operator== + QVERIFY(clhs == rhs); + + QByteArray ba1, ba2; + QDataStream s1(&ba1, QIODevice::ReadWrite), s2(&ba2, QIODevice::ReadWrite); + + // QDatastream operator + s1 << clhs; s2 << rhs; + QCOMPARE(ba1, ba2); + + Repository r1, r2; + s1 >> r1; s2 >> r2; + QCOMPARE(r1, r2); + } +}; + +QTEST_MAIN(tst_Repository) + +#include "tst_repository.moc" -- cgit v1.2.3