summaryrefslogtreecommitdiffstats
path: root/tests/auto/installer
diff options
context:
space:
mode:
authorkh1 <karsten.heimrich@digia.com>2013-02-26 17:26:44 +0100
committerKarsten Heimrich <karsten.heimrich@digia.com>2013-02-27 11:04:33 +0100
commit87eefbf5938e091c11e334e319691ec3cae0b24a (patch)
tree89787637438896f06ba951a9e220903c4e5768b7 /tests/auto/installer
parentaf28535bbf48fd232e21b19ffb4be87bbea8b9e6 (diff)
Add repository class auto test and fix missing operator export.
Change-Id: Ie7b490fa66c20ddd59788f00a75e363d7bb80697 Reviewed-by: Tim Jenssen <tim.jenssen@digia.com>
Diffstat (limited to 'tests/auto/installer')
-rw-r--r--tests/auto/installer/installer.pro3
-rw-r--r--tests/auto/installer/repository/repository.pro6
-rw-r--r--tests/auto/installer/repository/tst_repository.cpp119
3 files changed, 127 insertions, 1 deletions
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 <QTest>
+
+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"