Warning, file /libraries/libqgit2/tests/Fetch.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /******************************************************************************
0002 * Copyright (C) 2014 Peter Kümmel <syntheticpp@gmx.net>
0003 *
0004 * Permission to use, copy, modify, and distribute the software
0005 * and its documentation for any purpose and without fee is hereby
0006 * granted, provided that the above copyright notice appear in all
0007 * copies and that both that the copyright notice and this
0008 * permission notice and warranty disclaimer appear in supporting
0009 * documentation, and that the name of the author not be used in
0010 * advertising or publicity pertaining to distribution of the
0011 * software without specific, written prior permission.
0012 *
0013 * The author disclaim all warranties with regard to this
0014 * software, including all implied warranties of merchantability
0015 * and fitness.  In no event shall the author be liable for any
0016 * special, indirect or consequential damages or any damages
0017 * whatsoever resulting from loss of use, data or profits, whether
0018 * in an action of contract, negligence or other tortious action,
0019 * arising out of or in connection with the use or performance of
0020 * this software.
0021 */
0022 #include "TestHelpers.h"
0023 
0024 #include <QCoreApplication>
0025 #include <QTimer>
0026 
0027 #include <iostream>
0028 #include <bitset>
0029 
0030 #include "qgitcommit.h"
0031 #include "qgitrepository.h"
0032 #include "qgitcredentials.h"
0033 
0034 using namespace LibQGit2;
0035 
0036 
0037 class TestFetch : public TestBase
0038 {
0039     Q_OBJECT
0040 
0041 public:
0042     TestFetch() : testdir(VALUE_TO_STR(TEST_DIR)) {}
0043 
0044 public slots:
0045     void fetchProgress(int p) 
0046     { 
0047         m_progress = p;
0048         if (p % 20 == 0) {
0049             qDebug() << qPrintable(QString("Progress : %1%").arg(p));
0050         }
0051     }
0052 
0053 private slots:
0054     void remoteBranches();
0055     void remoteAdd();
0056     void remoteAddExisiting();
0057     void remoteAddExisitingDifferentUrl();
0058     void fetchMaster();
0059     void fetchAdditionalBranch();
0060     void fetchAll();
0061 
0062 private:
0063     int m_progress;
0064     const QString testdir;
0065 
0066     void fetch(const QString& branch, const QString dirname);
0067 };
0068 
0069 
0070 void TestFetch::remoteAdd()
0071 {
0072     LibQGit2::Repository repo;
0073 
0074     const QString repoPath = testdir + "/fetch_test/remote_add";
0075 
0076     QVERIFY(removeDir(repoPath));
0077     sleep::ms(500);
0078     m_progress = 0;
0079 
0080     try {
0081         repo.init(repoPath);
0082         repo.remoteAdd("kde", HttpRemoteUrl);
0083     }
0084     catch (const LibQGit2::Exception& ex) {
0085         QFAIL(ex.what());
0086     }
0087 }
0088 
0089 
0090 void TestFetch::remoteAddExisiting()
0091 {
0092     LibQGit2::Repository repo;
0093 
0094     const QString repoPath = testdir + "/fetch_test/add_exisiting";
0095 
0096     QVERIFY(removeDir(repoPath));
0097     sleep::ms(500);
0098 
0099     try {
0100         repo.init(repoPath);
0101         repo.remoteAdd("kde", HttpRemoteUrl);
0102         repo.remoteAdd("kde", HttpRemoteUrl);
0103     }
0104     catch (const LibQGit2::Exception& ex) {
0105         QFAIL(ex.what());
0106     }
0107 
0108     // TODO verify remote branches with unit test
0109 }
0110 
0111 
0112 
0113 void TestFetch::remoteAddExisitingDifferentUrl()
0114 {
0115     LibQGit2::Repository repo;
0116 
0117     const QString repoPath = testdir + "/fetch_test/add_existing_url";
0118 
0119     QVERIFY(removeDir(repoPath));
0120     sleep::ms(500);
0121 
0122     try {
0123         repo.init(repoPath);
0124         repo.remoteAdd("kde", HttpRemoteUrl);
0125     }
0126     catch (const LibQGit2::Exception& ex) {
0127         QFAIL(ex.what());
0128     }
0129 
0130     try {
0131         repo.remoteAdd("kde", "XYZ");
0132     }
0133     catch (const LibQGit2::Exception&) {
0134         return;
0135     }
0136 
0137     QFAIL("Could add invalid remote URL");
0138 }
0139 
0140 
0141 void TestFetch::fetch(const QString& branch, const QString dirname)
0142 {
0143     LibQGit2::Repository repo;
0144 
0145     const QString repoPath = testdir + "/fetch_test/" + dirname;
0146 
0147     QVERIFY(removeDir(repoPath));
0148     sleep::ms(500);
0149 
0150     try {
0151         repo.init(repoPath);
0152         repo.remoteAdd("kde", HttpRemoteUrl);
0153         repo.fetch("kde", branch);
0154     }
0155     catch (const LibQGit2::Exception& ex) {
0156         QFAIL(ex.what());
0157     }
0158 
0159     // TODO verify remote branches with unit test
0160 }
0161 
0162 
0163 void TestFetch::fetchMaster()
0164 {
0165     fetch("master", "fetch_master");
0166 }
0167 
0168 
0169 void TestFetch::fetchAll()
0170 {
0171     fetch("", "fetch_default");
0172 }
0173 
0174 
0175 void TestFetch::fetchAdditionalBranch()
0176 {
0177     fetch("master", "fetch_additional");
0178 
0179     LibQGit2::Repository repo;
0180 
0181     const QString repoPath = testdir + "/fetch_test/fetch_additional";
0182 
0183     try {
0184         repo.open(repoPath);
0185         repo.fetch("kde", "develop");
0186     }
0187     catch (const LibQGit2::Exception& ex) {
0188         QFAIL(ex.what());
0189     }
0190 
0191     // TODO verify remote branches with unit test
0192 }
0193 
0194 
0195 void TestFetch::remoteBranches()
0196 {
0197     LibQGit2::Repository repo;
0198 
0199     const QString repoPath = testdir + "/fetch_test/remote_branches";
0200 
0201     QVERIFY(removeDir(repoPath));
0202     sleep::ms(500);
0203 
0204     QStringList heads;
0205     try {
0206         repo.init(repoPath);
0207         repo.remoteAdd("kde", HttpRemoteUrl);
0208         heads = repo.remoteBranches("kde");
0209     }
0210     catch (const LibQGit2::Exception& ex) {
0211         QFAIL(ex.what());
0212     }
0213 
0214     qDebug() << "heads" << heads;
0215 
0216     QVERIFY(!heads.isEmpty());
0217     QVERIFY(heads.size() > 1);
0218     QVERIFY(heads.contains("master"));
0219 }
0220 
0221 
0222 QTEST_MAIN(TestFetch)
0223 
0224 #include "Fetch.moc"