File indexing completed on 2024-05-05 08:54:38
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 #include "TestHelpers.h" 0035 0036 using namespace LibQGit2; 0037 0038 0039 class TestClone : public TestBase 0040 { 0041 Q_OBJECT 0042 0043 public: 0044 TestClone(); 0045 0046 public slots: 0047 void cloneProgress(int p) 0048 { 0049 m_clone_progress = p; 0050 if (p % 20 == 0) { 0051 qDebug() << qPrintable(QString("Progress : %1%").arg(p)); 0052 } 0053 } 0054 0055 private slots: 0056 void fileProtocol(); 0057 void gitProtocol(); 0058 void httpProtocol(); 0059 void httpsProtocol(); 0060 0061 private: 0062 int m_clone_progress; 0063 const QString testdir; 0064 0065 void clone(const QString& url, const Credentials &credentials = Credentials()); 0066 }; 0067 0068 0069 0070 TestClone::TestClone() : testdir(VALUE_TO_STR(TEST_DIR)) 0071 { 0072 } 0073 0074 void TestClone::clone(const QString& url, const Credentials &credentials) 0075 { 0076 Repository repo; 0077 repo.setRemoteCredentials("origin", credentials); 0078 connect(&repo, SIGNAL(cloneProgress(int)), this, SLOT(cloneProgress(int))); 0079 0080 QString dirname = url; 0081 dirname.replace(":", ""); 0082 dirname.replace("//", "/"); 0083 dirname.replace("//", "/"); 0084 dirname.replace("/", "_"); 0085 dirname.replace(".", "_"); 0086 const QString repoPath = testdir + "/clone_test/" + dirname; 0087 0088 removeDir(repoPath); 0089 sleep::ms(500); 0090 m_clone_progress = 0; 0091 0092 qDebug() << "Cloning " << url; 0093 try { 0094 repo.clone(url, repoPath); 0095 } 0096 catch (const Exception& ex) { 0097 QFAIL(ex.what()); 0098 } 0099 0100 QCOMPARE(m_clone_progress, 100); 0101 } 0102 0103 0104 void TestClone::fileProtocol() 0105 { 0106 clone(FileRepositoryUrl); 0107 } 0108 0109 0110 void TestClone::gitProtocol() 0111 { 0112 clone(GitRemoteUrl); 0113 } 0114 0115 0116 void TestClone::httpProtocol() 0117 { 0118 clone(HttpRemoteUrl); 0119 } 0120 0121 0122 void TestClone::httpsProtocol() 0123 { 0124 clone(HttpsRemoteUrl); 0125 } 0126 0127 0128 QTEST_MAIN(TestClone) 0129 0130 #include "Clone.moc"