summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJan Dalheimer <jan@dalheimer.de>2014-01-05 23:24:05 +0100
committerJan Dalheimer <jan@dalheimer.de>2014-01-05 23:24:05 +0100
commit6961525faadf5d16fd1323af848ef88b7e1f26d4 (patch)
tree38bb0659d536bf42d7dfe07886a936d8bce78b5e /tests
parentbecaebd60d3c268dd9f95561afbe74bb8cd5f1e1 (diff)
downloadMultiMC-6961525faadf5d16fd1323af848ef88b7e1f26d4.tar
MultiMC-6961525faadf5d16fd1323af848ef88b7e1f26d4.tar.gz
MultiMC-6961525faadf5d16fd1323af848ef88b7e1f26d4.tar.lz
MultiMC-6961525faadf5d16fd1323af848ef88b7e1f26d4.tar.xz
MultiMC-6961525faadf5d16fd1323af848ef88b7e1f26d4.zip
Unbreak and reactivate the some UpdateChecker tests
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt19
-rw-r--r--tests/TestUtil.h2
-rw-r--r--tests/data/1.json6
-rw-r--r--tests/data/2.json4
-rw-r--r--tests/data/channels.json4
-rw-r--r--tests/test_config.h.in3
-rw-r--r--tests/tst_UpdateChecker.cpp35
7 files changed, 52 insertions, 21 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 2d851404..cc7d1a11 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -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)
diff --git a/tests/TestUtil.h b/tests/TestUtil.h
index 57d1fdf2..e9099b15 100644
--- a/tests/TestUtil.h
+++ b/tests/TestUtil.h
@@ -7,6 +7,8 @@
#include "MultiMC.h"
+#include "test_config.h"
+
struct TestsInternal
{
static QByteArray readFile(const QString &fileName)
diff --git a/tests/data/1.json b/tests/data/1.json
index f9f99b22..0f2d6ced 100644
--- a/tests/data/1.json
+++ b/tests/data/1.json
@@ -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,
diff --git a/tests/data/2.json b/tests/data/2.json
index bb59b9b6..6e2b0d3c 100644
--- a/tests/data/2.json
+++ b/tests/data/2.json
@@ -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,
diff --git a/tests/data/channels.json b/tests/data/channels.json
index d7446274..3ad504b0 100644
--- a/tests/data/channels.json
+++ b/tests/data/channels.json
@@ -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",
diff --git a/tests/test_config.h.in b/tests/test_config.h.in
new file mode 100644
index 00000000..69dd38e7
--- /dev/null
+++ b/tests/test_config.h.in
@@ -0,0 +1,3 @@
+#pragma once
+
+#define MultiMC_TEST_DATA_PATH "@MultiMC_TEST_DATA_PATH@"
diff --git a/tests/tst_UpdateChecker.cpp b/tests/tst_UpdateChecker.cpp
index 1e5e682f..0dcb242f 100644
--- a/tests/tst_UpdateChecker.cpp
+++ b/tests/tst_UpdateChecker.cpp
@@ -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)