NOISSUE Make tests no longer use the MultiMC object
They do not require the application part anymore
This commit is contained in:
parent
6f3aa65bd6
commit
9249768db5
@ -18,6 +18,6 @@ before_script:
|
||||
- cmake -DCMAKE_PREFIX_PATH=/opt/qt52/lib/cmake ..
|
||||
script:
|
||||
- make -j4
|
||||
- make test
|
||||
- make test ARGS="-V"
|
||||
notifications:
|
||||
email: false
|
||||
|
@ -4,11 +4,12 @@
|
||||
#include <QNetworkProxy>
|
||||
#include <QNetworkAccessManager>
|
||||
#include "logger/QsLog.h"
|
||||
#include "MultiMC.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
Env::Env()
|
||||
{
|
||||
// null
|
||||
m_qnam = std::make_shared<QNetworkAccessManager>();
|
||||
}
|
||||
|
||||
void Env::destroy()
|
||||
@ -23,6 +24,18 @@ Env& Env::Env::getInstance()
|
||||
return instance;
|
||||
}
|
||||
|
||||
std::shared_ptr< HttpMetaCache > Env::metacache()
|
||||
{
|
||||
Q_ASSERT(m_metacache != nullptr);
|
||||
return m_metacache;
|
||||
}
|
||||
|
||||
std::shared_ptr< QNetworkAccessManager > Env::qnam()
|
||||
{
|
||||
return m_qnam;
|
||||
}
|
||||
|
||||
|
||||
void Env::initHttpMetaCache(QString rootPath, QString staticDataPath)
|
||||
{
|
||||
m_metacache.reset(new HttpMetaCache("metacache"));
|
||||
|
10
logic/Env.h
10
logic/Env.h
@ -22,15 +22,9 @@ public:
|
||||
// call when Qt stuff is being torn down
|
||||
void destroy();
|
||||
|
||||
std::shared_ptr<QNetworkAccessManager> qnam()
|
||||
{
|
||||
return m_qnam;
|
||||
}
|
||||
std::shared_ptr<QNetworkAccessManager> qnam();
|
||||
|
||||
std::shared_ptr<HttpMetaCache> metacache()
|
||||
{
|
||||
return m_metacache;
|
||||
}
|
||||
std::shared_ptr<HttpMetaCache> metacache();
|
||||
|
||||
/// init the cache. FIXME: possible future hook point
|
||||
void initHttpMetaCache(QString rootPath, QString staticDataPath);
|
||||
|
@ -15,11 +15,10 @@
|
||||
|
||||
#include "UpdateChecker.h"
|
||||
|
||||
#include "logger/QsLog.h"
|
||||
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonValue>
|
||||
#include <QDebug>
|
||||
|
||||
#define API_VERSION 0
|
||||
#define CHANLIST_FORMAT 0
|
||||
@ -46,13 +45,13 @@ bool UpdateChecker::hasChannels() const
|
||||
|
||||
void UpdateChecker::checkForUpdate(QString updateChannel, bool notifyNoUpdate)
|
||||
{
|
||||
QLOG_DEBUG() << "Checking for updates.";
|
||||
qDebug() << "Checking for updates.";
|
||||
|
||||
// If the channel list hasn't loaded yet, load it and defer checking for updates until
|
||||
// later.
|
||||
if (!m_chanListLoaded)
|
||||
{
|
||||
QLOG_DEBUG() << "Channel list isn't loaded yet. Loading channel list and deferring "
|
||||
qDebug() << "Channel list isn't loaded yet. Loading channel list and deferring "
|
||||
"update check.";
|
||||
m_checkUpdateWaiting = true;
|
||||
m_deferredUpdateChannel = updateChannel;
|
||||
@ -62,7 +61,7 @@ void UpdateChecker::checkForUpdate(QString updateChannel, bool notifyNoUpdate)
|
||||
|
||||
if (m_updateChecking)
|
||||
{
|
||||
QLOG_DEBUG() << "Ignoring update check request. Already checking for updates.";
|
||||
qDebug() << "Ignoring update check request. Already checking for updates.";
|
||||
return;
|
||||
}
|
||||
|
||||
@ -77,9 +76,12 @@ void UpdateChecker::checkForUpdate(QString updateChannel, bool notifyNoUpdate)
|
||||
m_repoUrl = entry.url;
|
||||
}
|
||||
|
||||
qDebug() << "m_repoUrl = " << m_repoUrl;
|
||||
|
||||
// If we didn't find our channel, error.
|
||||
if (m_repoUrl.isEmpty())
|
||||
{
|
||||
qCritical() << "m_repoUrl is empty!";
|
||||
emit updateCheckFailed();
|
||||
return;
|
||||
}
|
||||
@ -97,7 +99,7 @@ void UpdateChecker::checkForUpdate(QString updateChannel, bool notifyNoUpdate)
|
||||
|
||||
void UpdateChecker::updateCheckFinished(bool notifyNoUpdate)
|
||||
{
|
||||
QLOG_DEBUG() << "Finished downloading repo index. Checking for new versions.";
|
||||
qDebug() << "Finished downloading repo index. Checking for new versions.";
|
||||
|
||||
QJsonParseError jsonError;
|
||||
QByteArray data;
|
||||
@ -111,7 +113,7 @@ void UpdateChecker::updateCheckFinished(bool notifyNoUpdate)
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError);
|
||||
if (jsonError.error != QJsonParseError::NoError || !jsonDoc.isObject())
|
||||
{
|
||||
QLOG_ERROR() << "Failed to parse GoUpdate repository index. JSON error"
|
||||
qCritical() << "Failed to parse GoUpdate repository index. JSON error"
|
||||
<< jsonError.errorString() << "at offset" << jsonError.offset;
|
||||
return;
|
||||
}
|
||||
@ -122,12 +124,12 @@ void UpdateChecker::updateCheckFinished(bool notifyNoUpdate)
|
||||
int apiVersion = object.value("ApiVersion").toVariant().toInt(&success);
|
||||
if (apiVersion != API_VERSION || !success)
|
||||
{
|
||||
QLOG_ERROR() << "Failed to check for updates. API version mismatch. We're using"
|
||||
qCritical() << "Failed to check for updates. API version mismatch. We're using"
|
||||
<< API_VERSION << "server has" << apiVersion;
|
||||
return;
|
||||
}
|
||||
|
||||
QLOG_DEBUG() << "Processing repository version list.";
|
||||
qDebug() << "Processing repository version list.";
|
||||
QJsonObject newestVersion;
|
||||
QJsonArray versions = object.value("Versions").toArray();
|
||||
for (QJsonValue versionVal : versions)
|
||||
@ -145,7 +147,7 @@ void UpdateChecker::updateCheckFinished(bool notifyNoUpdate)
|
||||
int newBuildNumber = newestVersion.value("Id").toVariant().toInt();
|
||||
if (newBuildNumber != m_currentBuild)
|
||||
{
|
||||
QLOG_DEBUG() << "Found newer version with ID" << newBuildNumber;
|
||||
qDebug() << "Found newer version with ID" << newBuildNumber;
|
||||
// Update!
|
||||
emit updateAvailable(m_repoUrl, newestVersion.value("Name").toVariant().toString(),
|
||||
newBuildNumber);
|
||||
@ -160,18 +162,17 @@ void UpdateChecker::updateCheckFinished(bool notifyNoUpdate)
|
||||
|
||||
void UpdateChecker::updateCheckFailed()
|
||||
{
|
||||
// TODO: log errors better
|
||||
QLOG_ERROR() << "Update check failed for reasons unknown.";
|
||||
qCritical() << "Update check failed for reasons unknown.";
|
||||
}
|
||||
|
||||
void UpdateChecker::updateChanList(bool notifyNoUpdate)
|
||||
{
|
||||
QLOG_DEBUG() << "Loading the channel list.";
|
||||
qDebug() << "Loading the channel list.";
|
||||
|
||||
if (m_channelListUrl.isEmpty())
|
||||
{
|
||||
QLOG_ERROR() << "Failed to update channel list. No channel list URL set."
|
||||
<< "If you'd like to use MultiMC's update system, please pass the channel "
|
||||
qCritical() << "Failed to update channel list. No channel list URL set."
|
||||
<< "If you'd like to use MultiMC's update system, please pass the channel "
|
||||
"list URL to CMake at compile time.";
|
||||
return;
|
||||
}
|
||||
@ -201,7 +202,7 @@ void UpdateChecker::chanListDownloadFinished(bool notifyNoUpdate)
|
||||
if (jsonError.error != QJsonParseError::NoError)
|
||||
{
|
||||
// TODO: Report errors to the user.
|
||||
QLOG_ERROR() << "Failed to parse channel list JSON:" << jsonError.errorString() << "at"
|
||||
qCritical() << "Failed to parse channel list JSON:" << jsonError.errorString() << "at"
|
||||
<< jsonError.offset;
|
||||
return;
|
||||
}
|
||||
@ -212,7 +213,7 @@ void UpdateChecker::chanListDownloadFinished(bool notifyNoUpdate)
|
||||
int formatVersion = object.value("format_version").toVariant().toInt(&success);
|
||||
if (formatVersion != CHANLIST_FORMAT || !success)
|
||||
{
|
||||
QLOG_ERROR()
|
||||
qCritical()
|
||||
<< "Failed to check for updates. Channel list format version mismatch. We're using"
|
||||
<< CHANLIST_FORMAT << "server has" << formatVersion;
|
||||
return;
|
||||
@ -230,7 +231,7 @@ void UpdateChecker::chanListDownloadFinished(bool notifyNoUpdate)
|
||||
channelObj.value("url").toVariant().toString()};
|
||||
if (entry.id.isEmpty() || entry.name.isEmpty() || entry.url.isEmpty())
|
||||
{
|
||||
QLOG_ERROR() << "Channel list entry with empty ID, name, or URL. Skipping.";
|
||||
qCritical() << "Channel list entry with empty ID, name, or URL. Skipping.";
|
||||
continue;
|
||||
}
|
||||
loadedChannels.append(entry);
|
||||
@ -241,7 +242,7 @@ void UpdateChecker::chanListDownloadFinished(bool notifyNoUpdate)
|
||||
|
||||
m_chanListLoading = false;
|
||||
m_chanListLoaded = true;
|
||||
QLOG_INFO() << "Successfully loaded UpdateChecker channel list.";
|
||||
qDebug() << "Successfully loaded UpdateChecker channel list.";
|
||||
|
||||
// If we're waiting to check for updates, do that now.
|
||||
if (m_checkUpdateWaiting)
|
||||
@ -253,7 +254,7 @@ void UpdateChecker::chanListDownloadFinished(bool notifyNoUpdate)
|
||||
void UpdateChecker::chanListDownloadFailed()
|
||||
{
|
||||
m_chanListLoading = false;
|
||||
QLOG_ERROR() << "Failed to download channel list.";
|
||||
qCritical() << "Failed to download channel list.";
|
||||
emit channelListLoaded();
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
# run the unit tests with `make test`
|
||||
find_package(Qt5 COMPONENTS Test Core Network Widgets)
|
||||
find_package(Qt5 COMPONENTS Test Core Network)
|
||||
|
||||
include_directories(${MMC_SRC})
|
||||
|
||||
@ -13,7 +13,7 @@ macro(add_unit_test name)
|
||||
endif()
|
||||
endforeach()
|
||||
add_executable(tst_${name} ${srcs})
|
||||
qt5_use_modules(tst_${name} Test Core Network Widgets)
|
||||
qt5_use_modules(tst_${name} Test Core Network)
|
||||
target_link_libraries(tst_${name} MultiMC_common)
|
||||
list(APPEND MultiMC_TESTS tst_${name})
|
||||
add_test(NAME ${name} COMMAND tst_${name})
|
||||
@ -30,7 +30,7 @@ add_unit_test(UpdateChecker tst_UpdateChecker.cpp)
|
||||
add_unit_test(DownloadUpdateTask tst_DownloadUpdateTask.cpp)
|
||||
|
||||
# Tests END #
|
||||
|
||||
|
||||
set(COVERAGE_SOURCE_DIRS
|
||||
${MMC_SRC}/logic/*
|
||||
${MMC_SRC}/logic/auth/*
|
||||
@ -88,6 +88,7 @@ if(MultiMC_CODE_COVERAGE)
|
||||
endif(MultiMC_CODE_COVERAGE)
|
||||
|
||||
set(MultiMC_TEST_DATA_PATH "${CMAKE_CURRENT_BINARY_DIR}/data")
|
||||
message("${CMAKE_CURRENT_BINARY_DIR}/data")
|
||||
if(UNIX)
|
||||
# on unix we get the third / from the filename
|
||||
set(MultiMC_TEST_DATA_PATH "file://${MultiMC_TEST_DATA_PATH}")
|
||||
|
@ -5,8 +5,6 @@
|
||||
#include <QTest>
|
||||
#include <QDir>
|
||||
|
||||
#include "MultiMC.h"
|
||||
|
||||
#include "test_config.h"
|
||||
|
||||
class TestsInternal
|
||||
@ -27,23 +25,3 @@ public:
|
||||
#define MULTIMC_GET_TEST_FILE(file) TestsInternal::readFile(QFINDTESTDATA(file))
|
||||
#define MULTIMC_GET_TEST_FILE_UTF8(file) TestsInternal::readFileUtf8(QFINDTESTDATA(file))
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
#define _MMC_EXTRA_ARGV , "-platform", "offscreen"
|
||||
#define _MMC_EXTRA_ARGC 2
|
||||
#else
|
||||
#define _MMC_EXTRA_ARGV
|
||||
#define _MMC_EXTRA_ARGC 0
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#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); \
|
||||
app.setAttribute(Qt::AA_Use96Dpi, true); \
|
||||
TestObject tc; \
|
||||
return QTest::qExec(&tc, argc, argv); \
|
||||
}
|
||||
|
@ -268,6 +268,6 @@ slots:
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_GUILESS_MAIN_MULTIMC(DownloadUpdateTaskTest)
|
||||
QTEST_GUILESS_MAIN(DownloadUpdateTaskTest)
|
||||
|
||||
#include "tst_DownloadUpdateTask.moc"
|
||||
|
@ -140,7 +140,8 @@ slots:
|
||||
checker.updateChanList(false);
|
||||
QVERIFY(channelListLoadedSpy.wait());
|
||||
|
||||
checker.m_channels[0].url = QUrl::fromLocalFile(QDir::current().absoluteFilePath("tests/data/")).toString();
|
||||
qDebug() << "CWD:" << QDir::current().absolutePath();
|
||||
checker.m_channels[0].url = findTestDataUrl("tests/data/");
|
||||
|
||||
checker.checkForUpdate(channel, false);
|
||||
|
||||
@ -151,6 +152,6 @@ slots:
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_GUILESS_MAIN_MULTIMC(UpdateCheckerTest)
|
||||
QTEST_GUILESS_MAIN(UpdateCheckerTest)
|
||||
|
||||
#include "tst_UpdateChecker.moc"
|
||||
|
@ -32,7 +32,7 @@ slots:
|
||||
QFETCH(QString, through);
|
||||
|
||||
QString converted = GradleSpecifier(through);
|
||||
|
||||
|
||||
QCOMPARE(converted, through);
|
||||
}
|
||||
|
||||
@ -50,7 +50,7 @@ slots:
|
||||
QFETCH(QString, expected);
|
||||
|
||||
QString converted = GradleSpecifier(spec).toPath();
|
||||
|
||||
|
||||
QCOMPARE(converted, expected);
|
||||
}
|
||||
void test_Negative_data()
|
||||
@ -72,6 +72,6 @@ slots:
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_GUILESS_MAIN_MULTIMC(GradleSpecifierTest)
|
||||
QTEST_GUILESS_MAIN(GradleSpecifierTest)
|
||||
|
||||
#include "tst_gradlespecifier.moc"
|
||||
|
@ -33,11 +33,11 @@ slots:
|
||||
|
||||
QString there = INIFile::escape(through);
|
||||
QString back = INIFile::unescape(there);
|
||||
|
||||
|
||||
QCOMPARE(back, through);
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_GUILESS_MAIN_MULTIMC(IniFileTest)
|
||||
QTEST_GUILESS_MAIN(IniFileTest)
|
||||
|
||||
#include "tst_inifile.moc"
|
||||
|
@ -69,6 +69,6 @@ slots:
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_GUILESS_MAIN_MULTIMC(PathUtilsTest)
|
||||
QTEST_GUILESS_MAIN(PathUtilsTest)
|
||||
|
||||
#include "tst_pathutils.moc"
|
||||
|
@ -66,6 +66,6 @@ slots:
|
||||
};
|
||||
|
||||
|
||||
QTEST_GUILESS_MAIN_MULTIMC(UserUtilsTest)
|
||||
QTEST_GUILESS_MAIN(UserUtilsTest)
|
||||
|
||||
#include "tst_userutils.moc"
|
||||
|
Loading…
Reference in New Issue
Block a user