sneedmc/tests/TestUtil.h

50 lines
1.1 KiB
C
Raw Normal View History

2013-12-02 10:09:56 +00:00
#pragma once
#include <QFile>
#include <QCoreApplication>
#include <QTest>
#include <QDir>
#include "MultiMC.h"
#include "test_config.h"
2014-09-06 16:16:56 +00:00
class TestsInternal
2013-12-02 10:09:56 +00:00
{
2014-09-06 16:16:56 +00:00
public:
static QByteArray readFile(const QString &fileName)
{
QFile f(fileName);
f.open(QFile::ReadOnly);
return f.readAll();
}
static QString readFileUtf8(const QString &fileName)
{
return QString::fromUtf8(readFile(fileName));
}
2013-12-02 10:09:56 +00:00
};
2014-09-06 16:16:56 +00:00
#define MULTIMC_GET_TEST_FILE(file) TestsInternal::readFile(QFINDTESTDATA(file))
#define MULTIMC_GET_TEST_FILE_UTF8(file) TestsInternal::readFileUtf8(QFINDTESTDATA(file))
2013-12-02 10:09:56 +00:00
#ifdef Q_OS_LINUX
2014-09-06 16:16:56 +00:00
#define _MMC_EXTRA_ARGV , "-platform", "offscreen"
#define _MMC_EXTRA_ARGC 2
#else
2014-09-06 16:16:56 +00:00
#define _MMC_EXTRA_ARGV
#define _MMC_EXTRA_ARGC 0
#endif
2013-12-17 01:09:58 +00:00
2013-12-02 10:09:56 +00:00
#define QTEST_GUILESS_MAIN_MULTIMC(TestObject) \
int main(int argc, char *argv[]) \
{ \
const char *argv_[] = { argv[0] _MMC_EXTRA_ARGV }; \
int argc_ = 1 + _MMC_EXTRA_ARGC; \
MultiMC app(argc_, const_cast<char**>(argv_), true); \
2013-12-02 10:09:56 +00:00
app.setAttribute(Qt::AA_Use96Dpi, true); \
TestObject tc; \
return QTest::qExec(&tc, argc, argv); \
}