diff options
-rw-r--r-- | src/libs/installer/repository.h | 8 | ||||
-rw-r--r-- | tests/auto/installer/installer.pro | 3 | ||||
-rw-r--r-- | tests/auto/installer/repository/repository.pro | 6 | ||||
-rw-r--r-- | tests/auto/installer/repository/tst_repository.cpp | 119 |
4 files changed, 131 insertions, 5 deletions
diff --git a/src/libs/installer/repository.h b/src/libs/installer/repository.h index c1a979615..967cae75d 100644 --- a/src/libs/installer/repository.h +++ b/src/libs/installer/repository.h @@ -79,8 +79,8 @@ public: uint qHash(const Repository &repository); const Repository &operator=(const Repository &other); - friend QDataStream &operator>>(QDataStream &istream, Repository &repository); - friend QDataStream &operator<<(QDataStream &ostream, const Repository &repository); + friend INSTALLER_EXPORT QDataStream &operator>>(QDataStream &istream, Repository &repository); + friend INSTALLER_EXPORT QDataStream &operator<<(QDataStream &ostream, const Repository &repository); private: void registerMetaType(); @@ -98,8 +98,8 @@ inline uint qHash(const Repository &repository) return qHash(repository.url()); } -QDataStream &operator>>(QDataStream &istream, Repository &repository); -QDataStream &operator<<(QDataStream &ostream, const Repository &repository); +INSTALLER_EXPORT QDataStream &operator>>(QDataStream &istream, Repository &repository); +INSTALLER_EXPORT QDataStream &operator<<(QDataStream &ostream, const Repository &repository); } // namespace QInstaller 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" |