File indexing completed on 2024-05-12 04:38:55

0001 /*
0002     SPDX-FileCopyrightText: 2017 Friedrich W. H. Kossebau <kossebau@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "test_vcslocation.h"
0008 
0009 #include <QTest>
0010 #include <QStandardPaths>
0011 
0012 using namespace KDevelop;
0013 
0014 void TestVcsLocation::initTestCase()
0015 {
0016     QStandardPaths::setTestModeEnabled(true);
0017 }
0018 
0019 void TestVcsLocation::setServerLocation(VcsLocation& serverLocation,
0020                                         const QString& repositoryModule,
0021                                         const QString& repositoryBranch,
0022                                         const QString& repositoryTag,
0023                                         const QString& repositoryPath,
0024                                         const QVariant& userData)
0025 {
0026     serverLocation.setRepositoryModule(repositoryModule);
0027     serverLocation.setRepositoryBranch(repositoryBranch);
0028     serverLocation.setRepositoryTag(repositoryTag);
0029     serverLocation.setRepositoryPath(repositoryPath);
0030     serverLocation.setUserData(userData);
0031 }
0032 
0033 void TestVcsLocation::compareServerLocation(const VcsLocation& serverLocation,
0034                                             const QString& repositoryServer,
0035                                             const QString& repositoryModule,
0036                                             const QString& repositoryBranch,
0037                                             const QString& repositoryTag,
0038                                             const QString& repositoryPath,
0039                                             const QVariant& userData)
0040 {
0041     QCOMPARE(serverLocation.isValid(), true);
0042     QCOMPARE(serverLocation.type(), VcsLocation::RepositoryLocation);
0043     QCOMPARE(serverLocation.repositoryServer(), repositoryServer);
0044     QCOMPARE(serverLocation.repositoryModule(), repositoryModule);
0045     QCOMPARE(serverLocation.repositoryBranch(), repositoryBranch);
0046     QCOMPARE(serverLocation.repositoryTag(), repositoryTag);
0047     QCOMPARE(serverLocation.repositoryPath(), repositoryPath);
0048     QCOMPARE(serverLocation.userData(), userData);
0049 }
0050 
0051 void TestVcsLocation::testDefaultConstructor()
0052 {
0053     const VcsLocation location;
0054 
0055     QCOMPARE(location.isValid(), false);
0056 }
0057 
0058 void TestVcsLocation::testLocalUrlConstructor()
0059 {
0060     // valid
0061     {
0062         const QUrl localUrl = QUrl("file:///tmp/foo");
0063 
0064         const VcsLocation localLocation(localUrl);
0065 
0066         QCOMPARE(localLocation.isValid(), true);
0067         QCOMPARE(localLocation.type(), VcsLocation::LocalLocation);
0068         QCOMPARE(localLocation.localUrl(), localUrl);
0069     }
0070 
0071     // invalid
0072     {
0073         const QUrl localUrl;
0074 
0075         const VcsLocation localLocation(localUrl);
0076 
0077         QCOMPARE(localLocation.isValid(), false);
0078         QCOMPARE(localLocation.type(), VcsLocation::LocalLocation);
0079         QCOMPARE(localLocation.localUrl(), localUrl);
0080     }
0081 }
0082 
0083 void TestVcsLocation::testRepositoryServerConstructor()
0084 {
0085     // valid
0086     {
0087         const QString repositoryServer = QStringLiteral("server");
0088         const QString repositoryModule = QStringLiteral("module");
0089         const QString repositoryBranch = QStringLiteral("branch");
0090         const QString repositoryTag = QStringLiteral("tag");
0091         const QString repositoryPath = QStringLiteral("path");
0092         const QVariant userData = QVariant(QStringLiteral("userdata"));
0093 
0094         VcsLocation serverLocation(repositoryServer);
0095         setServerLocation(serverLocation,
0096                           repositoryModule, repositoryBranch, repositoryTag, repositoryPath, userData);
0097 
0098         compareServerLocation(serverLocation,
0099                               repositoryServer, repositoryModule, repositoryBranch, repositoryTag, repositoryPath,
0100                               userData);
0101     }
0102 
0103     // invalid
0104     {
0105         const QString repositoryServer;
0106         VcsLocation serverLocation(repositoryServer);
0107 
0108         QCOMPARE(serverLocation.isValid(), false);
0109         QCOMPARE(serverLocation.type(), VcsLocation::RepositoryLocation);
0110         QCOMPARE(serverLocation.repositoryServer(), repositoryServer);
0111     }
0112 }
0113 
0114 void TestVcsLocation::testCopyConstructor()
0115 {
0116     // test plain copy
0117     const QString repositoryServer = QStringLiteral("server");
0118     const QString repositoryModule = QStringLiteral("module");
0119     const QString repositoryBranch = QStringLiteral("branch");
0120     const QString repositoryTag = QStringLiteral("tag");
0121     const QString repositoryPath = QStringLiteral("path");
0122     const QVariant userData = QVariant(QStringLiteral("userdata"));
0123 
0124     {
0125         VcsLocation serverLocationA(repositoryServer);
0126         setServerLocation(serverLocationA,
0127                           repositoryModule, repositoryBranch, repositoryTag, repositoryPath, userData);
0128 
0129         VcsLocation serverLocationB(serverLocationA);
0130         compareServerLocation(serverLocationA,
0131                               repositoryServer, repositoryModule, repositoryBranch, repositoryTag, repositoryPath,
0132                               userData);
0133         compareServerLocation(serverLocationB,
0134                               repositoryServer, repositoryModule, repositoryBranch, repositoryTag, repositoryPath,
0135                               userData);
0136         QVERIFY(serverLocationB == serverLocationA);
0137         QVERIFY(serverLocationA == serverLocationB);
0138     }
0139 
0140     const QString repositoryServerNew = QStringLiteral("servernew");
0141 
0142     // test detach after changing A
0143     {
0144         VcsLocation serverLocationA(repositoryServer);
0145         setServerLocation(serverLocationA,
0146                           repositoryModule, repositoryBranch, repositoryTag, repositoryPath, userData);
0147 
0148         VcsLocation serverLocationB(serverLocationA);
0149         // change a property of A
0150         serverLocationA.setRepositoryServer(repositoryServerNew);
0151 
0152         compareServerLocation(serverLocationA,
0153                               repositoryServerNew, repositoryModule, repositoryBranch, repositoryTag, repositoryPath,
0154                               userData);
0155         compareServerLocation(serverLocationB,
0156                               repositoryServer,    repositoryModule, repositoryBranch, repositoryTag, repositoryPath,
0157                               userData);
0158         QVERIFY(!(serverLocationB == serverLocationA));
0159         QVERIFY(!(serverLocationA == serverLocationB));
0160     }
0161 }
0162 
0163 void TestVcsLocation::testAssignOperator()
0164 {
0165     // test plain copy
0166     const QString repositoryServer = QStringLiteral("server");
0167     const QString repositoryModule = QStringLiteral("module");
0168     const QString repositoryBranch = QStringLiteral("branch");
0169     const QString repositoryTag = QStringLiteral("tag");
0170     const QString repositoryPath = QStringLiteral("path");
0171     const QVariant userData = QVariant(QStringLiteral("userdata"));
0172 
0173     {
0174         VcsLocation serverLocationA(repositoryServer);
0175         setServerLocation(serverLocationA,
0176                           repositoryModule, repositoryBranch, repositoryTag, repositoryPath, userData);
0177 
0178         VcsLocation serverLocationB;
0179         serverLocationB = serverLocationA;
0180         compareServerLocation(serverLocationA,
0181                               repositoryServer, repositoryModule, repositoryBranch, repositoryTag, repositoryPath,
0182                               userData);
0183         compareServerLocation(serverLocationB,
0184                               repositoryServer, repositoryModule, repositoryBranch, repositoryTag, repositoryPath,
0185                               userData);
0186         QVERIFY(serverLocationB == serverLocationA);
0187         QVERIFY(serverLocationA == serverLocationB);
0188     }
0189 
0190     const QString repositoryServerNew = QStringLiteral("servernew");
0191 
0192     // test detach after changing A
0193     {
0194         VcsLocation serverLocationA(repositoryServer);
0195         setServerLocation(serverLocationA,
0196                           repositoryModule, repositoryBranch, repositoryTag, repositoryPath, userData);
0197 
0198         VcsLocation serverLocationB;
0199         serverLocationB = serverLocationA;
0200         // change a property of A
0201         serverLocationA.setRepositoryServer(repositoryServerNew);
0202 
0203         compareServerLocation(serverLocationA,
0204                               repositoryServerNew, repositoryModule, repositoryBranch, repositoryTag, repositoryPath,
0205                               userData);
0206         compareServerLocation(serverLocationB,
0207                               repositoryServer,    repositoryModule, repositoryBranch, repositoryTag, repositoryPath,
0208                               userData);
0209         QVERIFY(!(serverLocationB == serverLocationA));
0210         QVERIFY(!(serverLocationA == serverLocationB));
0211     }
0212 }
0213 
0214 QTEST_GUILESS_MAIN(TestVcsLocation)
0215 
0216 #include "moc_test_vcslocation.cpp"