diff options
| author | Mehmet Samet Duman <yongdohyun@projecttick.org> | 2026-04-02 18:51:45 +0300 |
|---|---|---|
| committer | Mehmet Samet Duman <yongdohyun@projecttick.org> | 2026-04-02 18:51:45 +0300 |
| commit | d3261e64152397db2dca4d691a990c6bc2a6f4dd (patch) | |
| tree | fac2f7be638651181a72453d714f0f96675c2b8b /archived/projt-launcher/tests/ApplicationMessage_test.cpp | |
| parent | 31b9a8949ed0a288143e23bf739f2eb64fdc63be (diff) | |
| download | Project-Tick-d3261e64152397db2dca4d691a990c6bc2a6f4dd.tar.gz Project-Tick-d3261e64152397db2dca4d691a990c6bc2a6f4dd.zip | |
NOISSUE add archived projects
Signed-off-by: Mehmet Samet Duman <yongdohyun@projecttick.org>
Diffstat (limited to 'archived/projt-launcher/tests/ApplicationMessage_test.cpp')
| -rw-r--r-- | archived/projt-launcher/tests/ApplicationMessage_test.cpp | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/archived/projt-launcher/tests/ApplicationMessage_test.cpp b/archived/projt-launcher/tests/ApplicationMessage_test.cpp new file mode 100644 index 0000000000..66e7eb6df9 --- /dev/null +++ b/archived/projt-launcher/tests/ApplicationMessage_test.cpp @@ -0,0 +1,103 @@ +// SPDX-License-Identifier: GPL-3.0-only +// SPDX-FileCopyrightText: 2026 Project Tick +// SPDX-FileContributor: Project Tick Team + +#include <QJsonObject> +#include <QTest> + +#include <ApplicationMessage.h> +#include <Json.h> + +class ApplicationMessageTest : public QObject +{ + Q_OBJECT + + private slots: + void test_roundTrip_data() + { + QTest::addColumn<QString>("command"); + QTest::addColumn<QStringList>("keys"); + QTest::addColumn<QStringList>("values"); + + QTest::newRow("empty-args") << "open" << QStringList{} << QStringList{}; + QTest::newRow("single-arg") << "launch" << QStringList{ "instance" } << QStringList{ "main" }; + QTest::newRow("multi-args") << "import" + << QStringList{ "path", "mode", "force" } + << QStringList{ "/tmp/test", "zip", "true" }; + QTest::newRow("symbols") << "cmd" + << QStringList{ "k-1", "k_2" } + << QStringList{ "value with spaces", "x=y" }; + } + + void test_roundTrip() + { + QFETCH(QString, command); + QFETCH(QStringList, keys); + QFETCH(QStringList, values); + + QCOMPARE(keys.size(), values.size()); + + ApplicationMessage in; + in.command = command; + for (int i = 0; i < keys.size(); ++i) + { + in.args.insert(keys.at(i), values.at(i)); + } + + ApplicationMessage out; + out.parse(in.serialize()); + + QCOMPARE(out.command, command); + QCOMPARE(out.args.size(), keys.size()); + for (int i = 0; i < keys.size(); ++i) + { + QCOMPARE(out.args.value(keys.at(i)), values.at(i)); + } + } + + void test_parseMissingArgs() + { + QJsonObject root; + root.insert("command", "only-command"); + + ApplicationMessage msg; + msg.parse(Json::toText(root)); + + QCOMPARE(msg.command, QString("only-command")); + QVERIFY(msg.args.isEmpty()); + } + + void test_parseInvalidDocumentThrows() + { + ApplicationMessage msg; + bool threw = false; + try + { + msg.parse("{"); + } + catch (const Json::JsonException&) + { + threw = true; + } + QVERIFY(threw); + } + + void test_parseArrayThrows() + { + ApplicationMessage msg; + bool threw = false; + try + { + msg.parse("[1,2,3]"); + } + catch (const Json::JsonException&) + { + threw = true; + } + QVERIFY(threw); + } +}; + +QTEST_GUILESS_MAIN(ApplicationMessageTest) + +#include "ApplicationMessage_test.moc" |
