summaryrefslogtreecommitdiff
path: root/meshmc/launcher/updater/UpdateChecker_test.cpp
diff options
context:
space:
mode:
authorMehmet Samet Duman <yongdohyun@projecttick.org>2026-04-02 18:45:07 +0300
committerMehmet Samet Duman <yongdohyun@projecttick.org>2026-04-02 18:45:07 +0300
commit31b9a8949ed0a288143e23bf739f2eb64fdc63be (patch)
tree8a984fa143c38fccad461a77792d6864f3e82cd3 /meshmc/launcher/updater/UpdateChecker_test.cpp
parent934382c8a1ce738589dee9ee0f14e1cec812770e (diff)
parentfad6a1066616b69d7f5fef01178efdf014c59537 (diff)
downloadProject-Tick-31b9a8949ed0a288143e23bf739f2eb64fdc63be.tar.gz
Project-Tick-31b9a8949ed0a288143e23bf739f2eb64fdc63be.zip
Add 'meshmc/' from commit 'fad6a1066616b69d7f5fef01178efdf014c59537'
git-subtree-dir: meshmc git-subtree-mainline: 934382c8a1ce738589dee9ee0f14e1cec812770e git-subtree-split: fad6a1066616b69d7f5fef01178efdf014c59537
Diffstat (limited to 'meshmc/launcher/updater/UpdateChecker_test.cpp')
-rw-r--r--meshmc/launcher/updater/UpdateChecker_test.cpp164
1 files changed, 164 insertions, 0 deletions
diff --git a/meshmc/launcher/updater/UpdateChecker_test.cpp b/meshmc/launcher/updater/UpdateChecker_test.cpp
new file mode 100644
index 0000000000..f79156b3b0
--- /dev/null
+++ b/meshmc/launcher/updater/UpdateChecker_test.cpp
@@ -0,0 +1,164 @@
+/* SPDX-FileCopyrightText: 2026 Project Tick
+ * SPDX-FileContributor: Project Tick
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ *
+ * MeshMC - A Custom Launcher for Minecraft
+ * Copyright (C) 2026 Project Tick
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <QTest>
+#include <QSignalSpy>
+
+#include "TestUtil.h"
+#include "updater/UpdateChecker.h"
+
+Q_DECLARE_METATYPE(UpdateChecker::ChannelListEntry)
+
+bool operator==(const UpdateChecker::ChannelListEntry& e1,
+ const UpdateChecker::ChannelListEntry& e2)
+{
+ qDebug() << e1.url << "vs" << e2.url;
+ return e1.id == e2.id && e1.name == e2.name &&
+ e1.description == e2.description && e1.url == e2.url;
+}
+
+QDebug operator<<(QDebug dbg, const UpdateChecker::ChannelListEntry& c)
+{
+ dbg.nospace() << "ChannelListEntry(id=" << c.id << " name=" << c.name
+ << " description=" << c.description << " url=" << c.url
+ << ")";
+ return dbg.maybeSpace();
+}
+
+QString findTestDataUrl(const char* file)
+{
+ return QUrl::fromLocalFile(QFINDTESTDATA(file)).toString();
+}
+
+class UpdateCheckerTest : public QObject
+{
+ Q_OBJECT
+ private slots:
+ void initTestCase() {}
+ void cleanupTestCase() {}
+
+ void tst_ChannelListParsing_data()
+ {
+ QTest::addColumn<QString>("channel");
+ QTest::addColumn<QString>("channelUrl");
+ QTest::addColumn<bool>("hasChannels");
+ QTest::addColumn<bool>("valid");
+ QTest::addColumn<QList<UpdateChecker::ChannelListEntry>>("result");
+
+ QTest::newRow("garbage")
+ << QString() << findTestDataUrl("data/garbageChannels.json")
+ << false << false << QList<UpdateChecker::ChannelListEntry>();
+ QTest::newRow("errors")
+ << QString() << findTestDataUrl("data/errorChannels.json") << false
+ << true << QList<UpdateChecker::ChannelListEntry>();
+ QTest::newRow("no channels")
+ << QString() << findTestDataUrl("data/noChannels.json") << false
+ << true << QList<UpdateChecker::ChannelListEntry>();
+ QTest::newRow("one channel")
+ << QString("develop") << findTestDataUrl("data/oneChannel.json")
+ << true << true
+ << (QList<UpdateChecker::ChannelListEntry>()
+ << UpdateChecker::ChannelListEntry{
+ "develop", "Develop", "The channel called \"develop\"",
+ "http://example.org/stuff"});
+ QTest::newRow("several channels")
+ << QString("develop") << findTestDataUrl("data/channels.json")
+ << true << true
+ << (QList<UpdateChecker::ChannelListEntry>()
+ << UpdateChecker::
+ ChannelListEntry{"develop", "Develop",
+ "The channel called \"develop\"",
+ findTestDataUrl("data")}
+ << UpdateChecker::ChannelListEntry{"stable", "Stable",
+ "It's stable at least",
+ findTestDataUrl("data")}
+ << 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()
+ {
+
+ QFETCH(QString, channel);
+ QFETCH(QString, channelUrl);
+ QFETCH(bool, hasChannels);
+ QFETCH(bool, valid);
+ QFETCH(QList<UpdateChecker::ChannelListEntry>, result);
+
+ shared_qobject_ptr<QNetworkAccessManager> nam =
+ new QNetworkAccessManager();
+ UpdateChecker checker(nam, channelUrl, channel, 0);
+
+ QSignalSpy channelListLoadedSpy(&checker, SIGNAL(channelListLoaded()));
+ QVERIFY(channelListLoadedSpy.isValid());
+
+ checker.updateChanList(false);
+
+ if (valid) {
+ QVERIFY(channelListLoadedSpy.wait());
+ QCOMPARE(channelListLoadedSpy.size(), 1);
+ } else {
+ channelListLoadedSpy.wait();
+ QCOMPARE(channelListLoadedSpy.size(), 0);
+ }
+
+ QCOMPARE(checker.hasChannels(), hasChannels);
+ QCOMPARE(checker.getChannelList(), result);
+ }
+
+ void tst_UpdateChecking()
+ {
+ QString channel = "develop";
+ QString channelUrl = findTestDataUrl("data/channels.json");
+ int currentBuild = 2;
+
+ shared_qobject_ptr<QNetworkAccessManager> nam =
+ new QNetworkAccessManager();
+ UpdateChecker checker(nam, channelUrl, channel, currentBuild);
+
+ QSignalSpy updateAvailableSpy(
+ &checker, SIGNAL(updateAvailable(GoUpdate::Status)));
+ QVERIFY(updateAvailableSpy.isValid());
+ QSignalSpy channelListLoadedSpy(&checker, SIGNAL(channelListLoaded()));
+ QVERIFY(channelListLoadedSpy.isValid());
+
+ checker.updateChanList(false);
+ QVERIFY(channelListLoadedSpy.wait());
+
+ qDebug() << "CWD:" << QDir::current().absolutePath();
+ checker.m_channels[0].url = findTestDataUrl("data/");
+ checker.checkForUpdate(channel, false);
+
+ QVERIFY(updateAvailableSpy.wait());
+
+ auto status =
+ updateAvailableSpy.first().first().value<GoUpdate::Status>();
+ QCOMPARE(checker.m_channels[0].url, status.newRepoUrl);
+ QCOMPARE(3, status.newVersionId);
+ QCOMPARE(currentBuild, status.currentVersionId);
+ }
+};
+
+QTEST_GUILESS_MAIN(UpdateCheckerTest)
+
+#include "UpdateChecker_test.moc"