tests / package-smoke-linux (push) Skipped
tests / package-smoke-windows (push) Skipped
tests / package-smoke-macos (push) Skipped
tests / macos (push) Successful in 1m15s
tests / linux (push) Failing after 2m3s
tests / windows (push) Failing after 2m7s
release / create-release (push) Failing after 2s
release / build-linux (push) Skipped
release / build-windows (push) Skipped
release / build-macos (push) Skipped
release / publish (push) Skipped
Signed-off-by: galeon <dertiellis@gmail.com>
199 lines
9.6 KiB
C++
199 lines
9.6 KiB
C++
// Дымовой тест главного окна: Main.qml поднимается так же, как в main.cpp,
|
|
// без единого предупреждения QML, и ни одного запроса в настоящую сеть.
|
|
// Ловит то, что не видно компилятору: опечатки в именах свойств и ключах Loc.t,
|
|
// сломанные биндинги, несуществующие картинки в ресурсах.
|
|
|
|
#include "testenv.h"
|
|
#include "fakeinternet.h"
|
|
#include "fixtures.h"
|
|
|
|
#include "launcherpaths.h"
|
|
#include "launcherupdates.h"
|
|
#include "launcherversion.h"
|
|
#include "localization.h"
|
|
|
|
#include <QGuiApplication>
|
|
#include <QJSValue>
|
|
#include <QJsonArray>
|
|
#include <QJsonDocument>
|
|
#include <QQmlApplicationEngine>
|
|
#include <QQmlContext>
|
|
#include <QQuickStyle>
|
|
#include <QQuickWindow>
|
|
#include <QSignalSpy>
|
|
#include <QtQml/qqmlextensionplugin.h>
|
|
|
|
Q_IMPORT_QML_PLUGIN(BiLauncherPlugin)
|
|
|
|
namespace {
|
|
|
|
QStringList g_problems;
|
|
QtMessageHandler g_previous = nullptr;
|
|
|
|
void collect(QtMsgType type, const QMessageLogContext &context, const QString &message)
|
|
{
|
|
// Предупреждения QML приходят с файлом qrc:/… или с категорией qt.qml.*.
|
|
const QString file = QString::fromUtf8(context.file ? context.file : "");
|
|
const QString category = QString::fromUtf8(context.category ? context.category : "");
|
|
const bool fromQml = file.startsWith(QLatin1String("qrc:")) || file.endsWith(QLatin1String(".qml"))
|
|
|| category.startsWith(QLatin1String("qt.qml"))
|
|
|| message.contains(QLatin1String(".qml:"));
|
|
if (type != QtDebugMsg && type != QtInfoMsg && fromQml)
|
|
g_problems << message;
|
|
if (g_previous)
|
|
g_previous(type, context, message);
|
|
}
|
|
|
|
} // namespace
|
|
|
|
class TestQmlSmoke : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
FakeInternet m_net;
|
|
|
|
private slots:
|
|
void initTestCase()
|
|
{
|
|
QString error;
|
|
QVERIFY2(m_net.start(&error), qPrintable(error));
|
|
m_net.setFallback(FakeResponse::error(503));
|
|
const QString game = TestEnv::freshDir(QStringLiteral("game"));
|
|
Fixtures::writeJson(LauncherPaths::settingsFile(), QJsonObject{{"gameDir", game}, {"language", "en"}});
|
|
QQuickStyle::setStyle(QStringLiteral("Basic"));
|
|
g_previous = qInstallMessageHandler(collect);
|
|
}
|
|
|
|
void cleanupTestCase() { qInstallMessageHandler(g_previous); }
|
|
|
|
void init() { g_problems.clear(); }
|
|
|
|
void mainWindowLoadsCleanly()
|
|
{
|
|
// Один движок на весь тест, как в приложении: Localization держит указатель
|
|
// на JS-движок, создавший синглтон, и второй QQmlApplicationEngine после
|
|
// уничтожения первого оставил бы его висячим.
|
|
const QString releasesUrl = QStringLiteral(
|
|
"https://projects-live.galeonworx.com/api/v1/repos/galeon/BiLauncher/releases");
|
|
const bool candidate = QStringLiteral(LAUNCHER_CHANNEL) == "rc";
|
|
const QString version = candidate ? QStringLiteral("1.0.0-rc1") : QStringLiteral("1.0.0");
|
|
const QString tag = "v" + version;
|
|
QJsonArray assets;
|
|
for (const QString &suffix : {QStringLiteral("-win64-setup.exe"), QStringLiteral("-macOS-universal.dmg"),
|
|
QStringLiteral("-x86_64.AppImage")}) {
|
|
const QString name = "BiLauncher-" + version + suffix;
|
|
const QString url = "https://projects-live.galeonworx.com/galeon/BiLauncher/releases/download/"
|
|
+ tag + "/" + name;
|
|
assets.append(QJsonObject{{"name", name}, {"browser_download_url", url}, {"size", 1024}});
|
|
FakeResponse pending;
|
|
pending.hang = true;
|
|
m_net.route(url, pending);
|
|
}
|
|
const auto release = QJsonDocument(QJsonArray{QJsonObject{
|
|
{"tag_name", tag}, {"prerelease", candidate}, {"published_at", "2026-10-14T10:52:02Z"}, {"assets", assets}
|
|
}}).toJson();
|
|
m_net.route(releasesUrl, [candidate, release](const FakeRequest &request) {
|
|
const auto query = request.queryItems();
|
|
if (query.queryItemValue("pre-release") != (candidate ? "true" : "false"))
|
|
return FakeResponse::error(400);
|
|
return FakeResponse::json(query.queryItemValue("page") == "1" ? release : "[]");
|
|
});
|
|
|
|
QQmlApplicationEngine engine;
|
|
QStringList warnings;
|
|
connect(&engine, &QQmlEngine::warnings, this, [&](const QList<QQmlError> &list) {
|
|
for (const QQmlError &e : list)
|
|
warnings << e.toString();
|
|
});
|
|
engine.loadFromModule("BiLauncher", "Main");
|
|
QCOMPARE(engine.rootObjects().size(), 1);
|
|
auto *window = qobject_cast<QQuickWindow *>(engine.rootObjects().constFirst());
|
|
QVERIFY(window);
|
|
QVERIFY(QTest::qWaitForWindowExposed(window));
|
|
|
|
// Даём отработать отложенным таймерам, загрузке каталогов и анимациям.
|
|
QTest::qWait(2500);
|
|
QVERIFY2(warnings.isEmpty(), qPrintable(warnings.join(u'\n')));
|
|
QVERIFY2(g_problems.isEmpty(), qPrintable(g_problems.join(u'\n')));
|
|
|
|
auto *versions = window->findChild<QObject *>(QStringLiteral("launcherVersions"));
|
|
QVERIFY(versions);
|
|
QVERIFY(QMetaObject::invokeMethod(versions, "open"));
|
|
QTRY_COMPARE(versions->property("state").toString(), QStringLiteral("ready"));
|
|
const auto entriesProperty = versions->property("entries");
|
|
const auto entries = entriesProperty.metaType() == QMetaType::fromType<QJSValue>()
|
|
? entriesProperty.value<QJSValue>().toVariant().toList()
|
|
: entriesProperty.toList();
|
|
QCOMPARE(entries.size(), 1);
|
|
QCOMPARE(entries.first().toMap().value("version").toString(), version);
|
|
|
|
#if defined(Q_OS_WIN) || defined(Q_OS_MACOS) || (defined(Q_OS_LINUX) && defined(Q_PROCESSOR_X86_64))
|
|
auto *mainContext = qmlContext(window);
|
|
auto *updates = qobject_cast<LauncherUpdates *>(mainContext->objectForName("launcherUpdates"));
|
|
auto *panel = mainContext->objectForName("downloadPanel");
|
|
auto *content = versions->property("contentItem").value<QObject *>();
|
|
QVERIFY(content);
|
|
auto *dialogContext = qmlContext(content);
|
|
auto *installButton = dialogContext->objectForName("installButton");
|
|
auto *closeButton = dialogContext->objectForName("closeButton");
|
|
QVERIFY(updates);
|
|
QVERIFY(panel);
|
|
QVERIFY(installButton);
|
|
QVERIFY(closeButton);
|
|
QSignalSpy failed(updates, &LauncherUpdates::installationFailed);
|
|
|
|
QVERIFY(versions->setProperty("selectedVersion", version));
|
|
QVERIFY(installButton->property("enabled").toBool());
|
|
QVERIFY(QMetaObject::invokeMethod(installButton, "clicked"));
|
|
const auto url = entries.first().toMap().value("download").toString();
|
|
QTRY_COMPARE(m_net.hits(url), 1);
|
|
QVERIFY(!installButton->property("enabled").toBool());
|
|
QVERIFY(installButton->property("opacity").toDouble() < 1.0);
|
|
QVERIFY(closeButton->property("enabled").toBool());
|
|
QVERIFY(QMetaObject::invokeMethod(closeButton, "clicked"));
|
|
QTRY_VERIFY(!versions->property("visible").toBool());
|
|
QVERIFY(updates->installing());
|
|
QVERIFY(panel->property("visible").toBool());
|
|
QVERIFY(panel->property("title").toString().contains(version));
|
|
for (const auto *id : {"button", "profileBox", "buildButton", "folderButton", "settingsButton", "seasonsButton"}) {
|
|
auto *control = mainContext->objectForName(QString::fromLatin1(id));
|
|
QVERIFY(control);
|
|
QVERIFY2(!control->property("enabled").toBool(), id);
|
|
}
|
|
auto *seasonsButton = mainContext->objectForName("seasonsButton");
|
|
QCOMPARE(seasonsButton->property("opacity").toDouble(), 0.45);
|
|
QVERIFY(QMetaObject::invokeMethod(panel, "cancelRequested"));
|
|
QTRY_VERIFY(!updates->installing());
|
|
QVERIFY(!panel->property("visible").toBool());
|
|
QVERIFY(seasonsButton->property("enabled").toBool());
|
|
QCOMPARE(seasonsButton->property("opacity").toDouble(), 1.0);
|
|
QCOMPARE(failed.count(), 0);
|
|
#else
|
|
QVERIFY(QMetaObject::invokeMethod(versions, "close"));
|
|
#endif
|
|
|
|
// Смена языка на лету перестраивает Loc.t — биндинги не должны ломаться.
|
|
const QString titleEn = window->title();
|
|
Localization::instance().setLanguage(QStringLiteral("ru"));
|
|
QTest::qWait(500);
|
|
Localization::instance().setLanguage(QStringLiteral("en"));
|
|
QTest::qWait(300);
|
|
QCOMPARE(window->title(), titleEn);
|
|
QVERIFY2(warnings.isEmpty(), qPrintable(warnings.join(u'\n')));
|
|
QVERIFY2(g_problems.isEmpty(), qPrintable(g_problems.join(u'\n')));
|
|
|
|
// Наружу — только через FakeInternet, и только на известные адреса лаунчера.
|
|
static const QStringList known{"mojang.com", "galeonworx.com", "adoptium.net", "fabricmc.net",
|
|
"quiltmc.org", "minecraftforge.net", "neoforged.net"};
|
|
for (const QString &url : m_net.requestedUrls()) {
|
|
const QString host = QUrl(url).host();
|
|
const bool ok = std::any_of(known.cbegin(), known.cend(),
|
|
[&](const QString &domain) { return host.endsWith(domain); });
|
|
QVERIFY2(ok, qPrintable("неожиданный запрос: " + url));
|
|
}
|
|
}
|
|
};
|
|
|
|
BILAUNCHER_GUI_TEST_MAIN(TestQmlSmoke)
|
|
#include "tst_qml_smoke.moc"
|