File indexing completed on 2024-04-21 15:32:18

0001 #ifndef LIBQGIT2_TEST_HELPERS_H
0002 #define LIBQGIT2_TEST_HELPERS_H
0003 
0004 #include <QTest>
0005 #include <QDebug>
0006 
0007 #include <QThread>
0008 
0009 #include "qgitexception.h"
0010 
0011 #define TO_STR(s) #s
0012 #define VALUE_TO_STR(s) TO_STR(s)
0013 #define VALUE_TO_QSTR(s) QLatin1String(TO_STR(s))
0014 
0015 const QString HttpRemoteUrl("http://anongit.kde.org/libqgit2");
0016 const QString HttpsRemoteUrl("https://github.com/libqgit2/libqgit2.git");
0017 const QString GitRemoteUrl("git://anongit.kde.org/libqgit2");
0018 const QString ExistingRepository(VALUE_TO_QSTR(TEST_EXISTING_REPOSITORY));
0019 const QString FileRepositoryUrl("file://" + ExistingRepository + "/.git");
0020 
0021 
0022 struct sleep : QThread
0023 {
0024     static void ms(int msec);
0025 };
0026 
0027 
0028 bool removeDir(const QString & dirName);
0029 
0030 bool copyDir(QString srcPath, QString destPath);
0031 
0032 bool libgit2HasSSH();
0033 
0034 
0035 class TestBase : public QObject
0036 {
0037     Q_OBJECT
0038 protected slots:
0039     virtual void init();
0040     virtual void cleanup();
0041     virtual void initTestCase();
0042     virtual void cleanupTestCase();
0043 
0044 protected:
0045     void initTestRepo();
0046 
0047     QString testdir;
0048 };
0049 
0050 #define EXPECT_THROW(statement, exClass) \
0051 do {\
0052     try {\
0053         statement;\
0054         QTest::qFail(#statement " didn't throw", __FILE__, __LINE__);\
0055         return;\
0056     } catch (const exClass&) {\
0057     } catch (...) {\
0058         QTest::qFail(#statement " threw an unexpected kind of exception", __FILE__, __LINE__);\
0059         return;\
0060     }\
0061 } while (0)
0062 
0063 
0064 #define SKIPTEST(description) QSKIP(description);
0065 
0066 
0067 #endif  // LIBQGIT2_TEST_HELPERS_H