File indexing completed on 2024-04-28 04:42:59
0001 #include "TestHelpers.h" 0002 0003 #include <QDir> 0004 0005 #include "qgitglobal.h" 0006 #include "qgitrepository.h" 0007 0008 using namespace LibQGit2; 0009 0010 void sleep::ms(int msec) 0011 { 0012 QThread::msleep(msec); 0013 } 0014 0015 0016 bool removeDir(const QString & dirName) 0017 { 0018 bool result = true; 0019 QDir dir(dirName); 0020 0021 if (dir.exists(dirName)) { 0022 Q_FOREACH(QFileInfo info, dir.entryInfoList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden | QDir::AllDirs | QDir::Files, QDir::DirsFirst)) { 0023 if (info.isDir()) { 0024 result = removeDir(info.absoluteFilePath()); 0025 } 0026 else { 0027 result = QFile::remove(info.absoluteFilePath()); 0028 if (!result) { 0029 QFile(info.absoluteFilePath()).setPermissions(QFile::WriteOwner); 0030 result = QFile::remove(info.absoluteFilePath()); 0031 } 0032 if (!result) { 0033 qDebug() << "Could not remove " << info.absoluteFilePath(); 0034 } 0035 } 0036 0037 if (!result) { 0038 return result; 0039 } 0040 } 0041 result = dir.rmdir(dirName); 0042 if (!result) { 0043 qDebug() << "Could not remove " << dirName; 0044 } 0045 } 0046 return result; 0047 } 0048 0049 bool copyDir(QString srcPath, QString destPath) 0050 { 0051 QDir srcDir(srcPath); 0052 if (!srcDir.exists()) { 0053 qDebug() << "Source directory does not exist:" << srcPath; 0054 return false; 0055 } 0056 0057 foreach (QString dir, srcDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) { 0058 QString subDestPath = destPath + QDir::separator() + dir; 0059 if (!srcDir.mkpath(subDestPath)) { 0060 qDebug() << "Could not create target directory:" << subDestPath; 0061 return false; 0062 } 0063 if (!copyDir(srcPath + QDir::separator() + dir, subDestPath)) { 0064 return false; 0065 } 0066 } 0067 0068 foreach (QString file, srcDir.entryList(QDir::Files)) { 0069 if (!QFile::copy(srcPath + QDir::separator() + file, destPath + QDir::separator() + file)) { 0070 qDebug() << "Could not copy" << file << "from" << srcPath << "to" << destPath; 0071 return false; 0072 } 0073 } 0074 0075 return true; 0076 } 0077 0078 bool libgit2HasSSH() { 0079 return git_libgit2_features() & GIT_FEATURE_SSH; 0080 } 0081 0082 0083 void TestBase::init() { 0084 testdir = VALUE_TO_QSTR(TEST_DIR) + "/" + QFileInfo(QTest::currentAppName()).fileName() + "/" + QTest::currentTestFunction(); 0085 QVERIFY(removeDir(testdir)); 0086 } 0087 0088 void TestBase::cleanup() { 0089 0090 } 0091 0092 void TestBase::initTestCase() { 0093 initLibQGit2(); 0094 } 0095 0096 void TestBase::cleanupTestCase() { 0097 shutdownLibQGit2(); 0098 } 0099 0100 void TestBase::initTestRepo() 0101 { 0102 try { 0103 Repository repo; 0104 repo.clone(FileRepositoryUrl, testdir); 0105 } catch (const Exception& ex) { 0106 QFAIL(ex.what()); 0107 } 0108 }