forked from MUME/MMapper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestProxy.cpp
More file actions
77 lines (62 loc) · 2.75 KB
/
Copy pathTestProxy.cpp
File metadata and controls
77 lines (62 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2019 The MMapper Authors
#include "TestProxy.h"
#include "../src/global/TextUtils.h"
#include "../src/proxy/GmcpMessage.h"
#include "../src/proxy/GmcpModule.h"
#include "../src/proxy/GmcpUtils.h"
#include "../src/proxy/telnetfilter.h"
#include <QDebug>
#include <QtTest/QtTest>
void TestProxy::escapeTest()
{
QCOMPARE(GmcpUtils::escapeGmcpStringData(R"(12345)"), QString(R"(12345)"));
QCOMPARE(GmcpUtils::escapeGmcpStringData(R"(1.0)"), QString(R"(1.0)"));
QCOMPARE(GmcpUtils::escapeGmcpStringData(R"(true)"), QString(R"(true)"));
QCOMPARE(GmcpUtils::escapeGmcpStringData(R"("Hello")"), QString(R"(\"Hello\")"));
QCOMPARE(GmcpUtils::escapeGmcpStringData("\\\n\r\b\f\t"), QString(R"(\\\n\r\b\f\t)"));
}
void TestProxy::gmcpMessageDeserializeTest()
{
GmcpMessage gmcp1 = GmcpMessage::fromRawBytes(R"(Core.Hello { "Hello": "world" })");
QCOMPARE(gmcp1.getName().toQByteArray(), QByteArray("Core.Hello"));
QCOMPARE(gmcp1.getJson()->toQString(), mmqt::toQStringUtf8(R"({ "Hello": "world" })"));
GmcpMessage gmcp2 = GmcpMessage::fromRawBytes(R"(Core.Goodbye)");
QCOMPARE(gmcp2.getName().toQByteArray(), QByteArray("Core.Goodbye"));
QVERIFY(!gmcp2.getJson());
GmcpMessage gmcp3 = GmcpMessage::fromRawBytes(R"(External.Discord.Hello)");
QCOMPARE(gmcp3.getName().toQByteArray(), QByteArray("External.Discord.Hello"));
QVERIFY(!gmcp3.getJson());
QVERIFY(gmcp3.isExternalDiscordHello());
GmcpMessage gmcp4 = GmcpMessage::fromRawBytes(R"(External.Discord.Get)");
QCOMPARE(gmcp4.getName().toQByteArray(), QByteArray("External.Discord.Get"));
QVERIFY(!gmcp4.getJson());
QVERIFY(gmcp4.isExternalDiscordGet());
}
void TestProxy::gmcpMessageSerializeTest()
{
GmcpMessage gmcp1(GmcpMessageTypeEnum::CORE_HELLO);
QCOMPARE(gmcp1.toRawBytes(), QByteArray("Core.Hello"));
GmcpMessage gmcp2(GmcpMessageTypeEnum::CORE_HELLO, GmcpJson{"{}"});
QCOMPARE(gmcp2.toRawBytes(), QByteArray("Core.Hello {}"));
}
void TestProxy::gmcpModuleTest()
{
GmcpModule module1("Char 1");
QCOMPARE(mmqt::toQByteArrayUtf8(module1.getNormalizedName()), QByteArray("char"));
QCOMPARE(module1.getVersion().asUint32(), 1u);
QVERIFY(module1.isSupported());
GmcpModule module2("Char.Skills 1");
QCOMPARE(mmqt::toQByteArrayUtf8(module2.getNormalizedName()), QByteArray("char.skills"));
QCOMPARE(module2.getVersion().asUint32(), 1u);
QVERIFY(!module2.isSupported());
GmcpModule module3("Room");
QCOMPARE(mmqt::toQByteArrayUtf8(module3.getNormalizedName()), QByteArray("room"));
QCOMPARE(module3.getVersion().asUint32(), 0u);
QVERIFY(module3.isSupported());
}
void TestProxy::telnetFilterTest()
{
test::test_telnetfilter();
}
QTEST_MAIN(TestProxy)