Merge branch 'fix_tests' of https://github.com/02JanDal/MultiMC5 into develop
This commit is contained in:
commit
50c441a773
@ -30,7 +30,6 @@
|
||||
|
||||
UpdateChecker::UpdateChecker()
|
||||
{
|
||||
m_currentChannel = VERSION_CHANNEL;
|
||||
m_channelListUrl = CHANLIST_URL;
|
||||
m_updateChecking = false;
|
||||
m_chanListLoading = false;
|
||||
|
@ -27,7 +27,6 @@ public:
|
||||
UpdateChecker();
|
||||
void checkForUpdate(bool notifyNoUpdate);
|
||||
|
||||
void setCurrentChannel(const QString &channel) { m_currentChannel = channel; }
|
||||
void setChannelListUrl(const QString &url) { m_channelListUrl = url; }
|
||||
|
||||
/*!
|
||||
@ -83,7 +82,6 @@ private:
|
||||
QString m_repoUrl;
|
||||
|
||||
QString m_channelListUrl;
|
||||
QString m_currentChannel;
|
||||
|
||||
QList<ChannelListEntry> m_channels;
|
||||
|
||||
|
@ -84,9 +84,18 @@ if(MultiMC_CODE_COVERAGE)
|
||||
add_custom_target(MultiMC_RUN_TESTS DEPENDS MultiMC_GENERATE_COVERAGE_HTML)
|
||||
endif(MultiMC_CODE_COVERAGE)
|
||||
|
||||
set(MultiMC_TEST_DATA_PATH "${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}")
|
||||
else()
|
||||
# we don't on windows, so we have to add it ourselves
|
||||
set(MultiMC_TEST_DATA_PATH "file:///${MultiMC_TEST_DATA_PATH}")
|
||||
endif()
|
||||
file(GLOB data_files "data/*")
|
||||
foreach(data_file ${data_files})
|
||||
get_filename_component(filename ${data_file} NAME)
|
||||
configure_file(${data_file} ${CMAKE_CURRENT_BINARY_DIR}/data/${filename} @ONLY)
|
||||
endforeach()
|
||||
|
||||
add_custom_target(MultiMC_Test_Data
|
||||
ALL
|
||||
COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_CURRENT_BINARY_DIR}/data
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/data ${CMAKE_CURRENT_BINARY_DIR}/data
|
||||
)
|
||||
configure_file(test_config.h.in test_config.h @ONLY)
|
||||
|
@ -7,6 +7,8 @@
|
||||
|
||||
#include "MultiMC.h"
|
||||
|
||||
#include "test_config.h"
|
||||
|
||||
struct TestsInternal
|
||||
{
|
||||
static QByteArray readFile(const QString &fileName)
|
||||
|
@ -8,7 +8,7 @@
|
||||
"Sources": [
|
||||
{
|
||||
"SourceType": "http",
|
||||
"Url": "$PWD/tests/data/fileOneA"
|
||||
"Url": "@MultiMC_TEST_DATA_PATH@/fileOneA"
|
||||
}
|
||||
],
|
||||
"Executable": true,
|
||||
@ -20,7 +20,7 @@
|
||||
"Sources": [
|
||||
{
|
||||
"SourceType": "http",
|
||||
"Url": "$PWD/tests/data/fileTwo"
|
||||
"Url": "@MultiMC_TEST_DATA_PATH@/fileTwo"
|
||||
}
|
||||
],
|
||||
"Executable": false,
|
||||
@ -32,7 +32,7 @@
|
||||
"Sources": [
|
||||
{
|
||||
"SourceType": "http",
|
||||
"Url": "$PWD/tests/data/fileThree"
|
||||
"Url": "@MultiMC_TEST_DATA_PATH@/fileThree"
|
||||
}
|
||||
],
|
||||
"Executable": false,
|
||||
|
@ -8,7 +8,7 @@
|
||||
"Sources": [
|
||||
{
|
||||
"SourceType": "http",
|
||||
"Url": "$PWD/tests/data/fileOneB"
|
||||
"Url": "@MultiMC_TEST_DATA_PATH@/fileOneB"
|
||||
}
|
||||
],
|
||||
"Executable": true,
|
||||
@ -20,7 +20,7 @@
|
||||
"Sources": [
|
||||
{
|
||||
"SourceType": "http",
|
||||
"Url": "$PWD/tests/data/fileTwo"
|
||||
"Url": "@MultiMC_TEST_DATA_PATH@/fileTwo"
|
||||
}
|
||||
],
|
||||
"Executable": false,
|
||||
|
@ -5,13 +5,13 @@
|
||||
"id": "develop",
|
||||
"name": "Develop",
|
||||
"description": "The channel called \"develop\"",
|
||||
"url": "$PWD/tests/data/"
|
||||
"url": "@MultiMC_TEST_DATA_PATH@"
|
||||
},
|
||||
{
|
||||
"id": "stable",
|
||||
"name": "Stable",
|
||||
"description": "It's stable at least",
|
||||
"url": "$PWD/tests/data/"
|
||||
"url": "@MultiMC_TEST_DATA_PATH@"
|
||||
},
|
||||
{
|
||||
"id": "42",
|
||||
|
3
tests/test_config.h.in
Normal file
3
tests/test_config.h.in
Normal file
@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#define MultiMC_TEST_DATA_PATH "@MultiMC_TEST_DATA_PATH@"
|
@ -1,6 +1,9 @@
|
||||
#include <QTest>
|
||||
#include <QSignalSpy>
|
||||
|
||||
#include "depends/settings/settingsobject.h"
|
||||
#include "depends/settings/setting.h"
|
||||
|
||||
#include "TestUtil.h"
|
||||
#include "logic/updater/UpdateChecker.h"
|
||||
|
||||
@ -20,6 +23,19 @@ QDebug operator<<(QDebug dbg, const UpdateChecker::ChannelListEntry &c)
|
||||
return dbg.maybeSpace();
|
||||
}
|
||||
|
||||
class ResetSetting
|
||||
{
|
||||
public:
|
||||
ResetSetting(std::shared_ptr<Setting> setting) : setting(setting), oldValue(setting->get()) {}
|
||||
~ResetSetting()
|
||||
{
|
||||
setting->set(oldValue);
|
||||
}
|
||||
|
||||
std::shared_ptr<Setting> setting;
|
||||
QVariant oldValue;
|
||||
};
|
||||
|
||||
class UpdateCheckerTest : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -76,24 +92,27 @@ slots:
|
||||
<< true
|
||||
<< true
|
||||
<< (QList<UpdateChecker::ChannelListEntry>()
|
||||
<< UpdateChecker::ChannelListEntry{"develop", "Develop", "The channel called \"develop\"", "$PWD/tests/data/"}
|
||||
<< UpdateChecker::ChannelListEntry{"stable", "Stable", "It's stable at least", "$PWD/tests/data/"}
|
||||
<< UpdateChecker::ChannelListEntry{"develop", "Develop", "The channel called \"develop\"", MultiMC_TEST_DATA_PATH}
|
||||
<< UpdateChecker::ChannelListEntry{"stable", "Stable", "It's stable at least", MultiMC_TEST_DATA_PATH}
|
||||
<< UpdateChecker::ChannelListEntry{"42", "The Channel", "This is the channel that is going to answer all of your questions", "https://dent.me/tea"});
|
||||
}
|
||||
void tst_ChannelListParsing()
|
||||
{
|
||||
ResetSetting resetUpdateChannel(MMC->settings()->getSetting("UpdateChannel"));
|
||||
|
||||
QFETCH(QString, channel);
|
||||
QFETCH(QString, channelUrl);
|
||||
QFETCH(bool, hasChannels);
|
||||
QFETCH(bool, valid);
|
||||
QFETCH(QList<UpdateChecker::ChannelListEntry>, result);
|
||||
|
||||
MMC->settings()->set("UpdateChannel", channel);
|
||||
|
||||
UpdateChecker checker;
|
||||
|
||||
QSignalSpy channelListLoadedSpy(&checker, SIGNAL(channelListLoaded()));
|
||||
QVERIFY(channelListLoadedSpy.isValid());
|
||||
|
||||
checker.setCurrentChannel(channel);
|
||||
checker.setChannelListUrl(channelUrl);
|
||||
|
||||
checker.updateChanList();
|
||||
@ -112,8 +131,7 @@ slots:
|
||||
QCOMPARE(checker.hasChannels(), hasChannels);
|
||||
QCOMPARE(checker.getChannelList(), result);
|
||||
}
|
||||
// FIXME: fix, comment, explain what it does.
|
||||
/*
|
||||
|
||||
void tst_UpdateChecking_data()
|
||||
{
|
||||
QTest::addColumn<QString>("channel");
|
||||
@ -126,19 +144,19 @@ slots:
|
||||
<< 2
|
||||
<< (QList<QVariant>() << QString() << "1.0.3" << 3);
|
||||
}
|
||||
*/
|
||||
/*
|
||||
void tst_UpdateChecking()
|
||||
{
|
||||
ResetSetting resetUpdateChannel(MMC->settings()->getSetting("UpdateChannel"));
|
||||
|
||||
QFETCH(QString, channel);
|
||||
QFETCH(QString, channelUrl);
|
||||
QFETCH(int, currentBuild);
|
||||
QFETCH(QList<QVariant>, result);
|
||||
|
||||
MMC->settings()->set("UpdateChannel", channel);
|
||||
MMC->m_version.build = currentBuild;
|
||||
|
||||
UpdateChecker checker;
|
||||
checker.setCurrentChannel(channel);
|
||||
checker.setChannelListUrl(channelUrl);
|
||||
|
||||
QSignalSpy updateAvailableSpy(&checker, SIGNAL(updateAvailable(QString,QString,int)));
|
||||
@ -158,7 +176,6 @@ slots:
|
||||
res[0] = checker.m_channels[0].url;
|
||||
QCOMPARE(updateAvailableSpy.first(), res);
|
||||
}
|
||||
*/
|
||||
};
|
||||
|
||||
QTEST_GUILESS_MAIN_MULTIMC(UpdateCheckerTest)
|
||||
|
Loading…
Reference in New Issue
Block a user