1 parent
ebf8ff7869
commit
41599fa82f
67 files changed
+8775
-4
No files matched your search
@@ -0,0 +1,88 @@
|
||||
// Qt Quick Test для QML-компонентов лаунчера.
|
||||
//
|
||||
// Модуль BiLauncher у приложения вшит в исполняемый файл и плагина не имеет,
|
||||
// поэтому qmltestrunner его не импортирует. Здесь тот же модуль собран
|
||||
// статической библиотекой (bilauncher_testlib) и подключён через
|
||||
// Q_IMPORT_QML_PLUGIN — тесты пишут обычный «import BiLauncher».
|
||||
|
||||
#include "testenv.h"
|
||||
#include "fakeinternet.h"
|
||||
#include "fixtures.h"
|
||||
|
||||
#include "launcherpaths.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QDir>
|
||||
#include <QJsonArray>
|
||||
|
||||
#include <QQmlEngine>
|
||||
#include <QQuickStyle>
|
||||
#include <QtQml/qqmlextensionplugin.h>
|
||||
#include <QtQuickTest/quicktest.h>
|
||||
|
||||
Q_IMPORT_QML_PLUGIN(BiLauncherPlugin)
|
||||
|
||||
class Setup : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public slots:
|
||||
void applicationAvailable()
|
||||
{
|
||||
TestEnv::finishSetup();
|
||||
QQuickStyle::setStyle(QStringLiteral("Basic"));
|
||||
seedData();
|
||||
// Диалоги создают настоящий LauncherBackend — наружу он не должен ходить.
|
||||
QString error;
|
||||
if (m_net.start(&error))
|
||||
m_net.setFallback(FakeResponse::error(503));
|
||||
}
|
||||
|
||||
void qmlEngineAvailable(QQmlEngine *engine)
|
||||
{
|
||||
engine->addImportPath(QStringLiteral("qrc:/qt/qml"));
|
||||
}
|
||||
|
||||
private:
|
||||
// Данные, на которых работают диалоги (см. tst_dialogs.qml).
|
||||
static void seedData()
|
||||
{
|
||||
const QString game = TestEnv::freshDir(QStringLiteral("game"));
|
||||
const QString now = QDateTime::currentDateTimeUtc().toString(Qt::ISODate);
|
||||
Fixtures::writeJson(LauncherPaths::settingsFile(), QJsonObject{{"gameDir", game}, {"language", "en"}});
|
||||
|
||||
const auto version = [](const QString &id, const QString &type, const QString &time) {
|
||||
return QJsonObject{{"id", id}, {"type", type}, {"releaseTime", time}, {"sha1", "00"},
|
||||
{"url", "https://piston-meta.mojang.com/v1/packages/x/" + id + ".json"}};
|
||||
};
|
||||
Fixtures::writeJson(LauncherPaths::versionManifestFile(), QJsonObject{
|
||||
{"fetchedAt", now},
|
||||
{"versions", QJsonArray{version("25w33a", "snapshot", "2025-08-13T12:00:00Z"),
|
||||
version("1.20.1", "release", "2023-06-12T13:25:51Z"),
|
||||
version("b1.7.3", "old_beta", "2011-07-08T00:00:00Z")}}});
|
||||
Fixtures::write(game + "/versions/1.20.1/1.20.1.json",
|
||||
"{\"id\":\"1.20.1\",\"mainClass\":\"net.minecraft.client.main.Main\"}");
|
||||
|
||||
const QJsonObject archive{{"url", "https://launcher-builds.galeonworx.com/packs/q.zip"},
|
||||
{"size", 3 * 1024 * 1024}, {"sha256", QString(64, u'a')}};
|
||||
const QJsonObject build{{"id", "season-qml"}, {"name", "QML Season"}, {"revision", 1},
|
||||
{"minecraftVersion", "1.20.1"}, {"loader", "fabric"},
|
||||
{"loaderVersion", "0.16.10"}, {"seasonStart", "2026-01-01"},
|
||||
{"archive", archive}};
|
||||
Fixtures::writeJson(LauncherPaths::seasonalCatalogFile(), QJsonObject{
|
||||
{"formatVersion", 1}, {"fetchedAt", now},
|
||||
{"baseUrl", "https://launcher-builds.galeonworx.com"}, {"builds", QJsonArray{build}}});
|
||||
}
|
||||
|
||||
FakeInternet m_net;
|
||||
};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
TestEnv::prepareSandbox();
|
||||
QTEST_SET_MAIN_SOURCE_PATH
|
||||
Setup setup;
|
||||
return quick_test_main_with_setup(argc, argv, "bilauncher_qml", QUICK_TEST_SOURCE_DIR, &setup);
|
||||
}
|
||||
|
||||
#include "tst_qml.moc"
|
||||
Reference in new issue
Block a user