akashi-esquizolandia/tests/unittest_aopacket/tst_unittest_aopacket.cpp
Leifa 27ef14fa78
Client list support (#365)
* Boilerplate structure for playerlist

* Change id, character and area to private with get/set

* WIP push

* Restructured the project entirely

* Implemented player list

* Build against project-akashi.pro

* Updated coverage location

* Copy gcov files from the proper path

* Update coverage to copy files

* Coverage update.

* Update main.yml

* Disabled coverage for the time being

* Reworked player list implementation, ...

* Reworked player list implementation
  * No longer rely on JSON
* Introduced moderation packets: ban, kick
  * A kick is a duration of 0
  * A ban is a duration between -1 (permanent) and anything above 0
* Packet ZZ has been modified and now include a client id field for client-specific reports
* Ban duration is now explicit.

* Tweak to ban duration calculation

* Resolve failing ZZ test

---------

Co-authored-by: Salanto <62221668+Salanto@users.noreply.github.com>
2024-07-14 15:47:58 +02:00

191 lines
5.6 KiB
C++

#include <QObject>
#include <QTest>
#include "network/aopacket.h"
#include "packet/packet_factory.h"
namespace tests {
namespace unittests {
/**
* @brief Unit Tester class for the area-related functions.
*/
class Packet : public QObject
{
Q_OBJECT
public:
private slots:
/**
* @brief Initializes all tests
*/
void init();
/**
* @brief Creates a packet from a defined header and content.
*/
void createPacket();
/**
* @brief The data function for createPacketFromString();
*/
void createPacketFromString_data();
/**
* @brief Tests the creation of AOPackets from incoming string formatted packets.
*/
void createPacketFromString();
/**
* @brief Test packet-specific classes
*/
void createPacketSubclass_data();
void createPacketSubclass();
};
void Packet::init()
{
AOPacket::registerPackets();
}
void Packet::createPacketSubclass_data()
{
QTest::addColumn<QString>("incoming_packet");
QTest::addColumn<QString>("expected_header");
QTest::addColumn<int>("expected_minargs");
QTest::newRow("askchaa") << "askchaa#"
<< "askchaa"
<< 0;
QTest::newRow("CASEA") << "CASEA#"
<< "CASEA"
<< 6;
QTest::newRow("CC") << "CC#"
<< "CC"
<< 3;
QTest::newRow("CH") << "CH#"
<< "CH"
<< 1;
QTest::newRow("CT") << "CT#"
<< "CT"
<< 2;
QTest::newRow("DE") << "DE#"
<< "DE"
<< 1;
QTest::newRow("EE") << "EE#"
<< "EE"
<< 4;
QTest::newRow("GENERIC") << "GENERIC#"
<< "GENERIC"
<< 0;
QTest::newRow("HI") << "HI#"
<< "HI"
<< 1;
QTest::newRow("HP") << "HP#"
<< "HP"
<< 2;
QTest::newRow("ID") << "ID#"
<< "ID"
<< 2;
QTest::newRow("MC") << "MC#"
<< "MC"
<< 2;
QTest::newRow("MS") << "MS#"
<< "MS"
<< 15;
QTest::newRow("PE") << "PE#"
<< "PE"
<< 3;
QTest::newRow("PW") << "PW#"
<< "PW"
<< 1;
QTest::newRow("RC") << "RC#"
<< "RC"
<< 0;
QTest::newRow("RD") << "RD#"
<< "RD"
<< 0;
QTest::newRow("RM") << "RM#"
<< "RM"
<< 0;
QTest::newRow("RT") << "RT#"
<< "RT"
<< 1;
QTest::newRow("SETCASE") << "SETCASE#"
<< "SETCASE"
<< 7;
QTest::newRow("ZZ") << "ZZ#"
<< "ZZ"
<< 2;
}
void Packet::createPacketSubclass()
{
QFETCH(QString, incoming_packet);
QFETCH(QString, expected_header);
QFETCH(int, expected_minargs);
AOPacket *packet = PacketFactory::createPacket(incoming_packet);
QCOMPARE(packet->getPacketInfo().header, expected_header);
QCOMPARE(packet->getPacketInfo().min_args, expected_minargs);
}
void Packet::createPacket()
{
AOPacket *packet = PacketFactory::createPacket("HI", {"HDID"});
QCOMPARE(packet->getPacketInfo().header, "HI");
QCOMPARE(packet->getContent(), {"HDID"});
}
void Packet::createPacketFromString_data()
{
QTest::addColumn<QString>("incoming_packet");
QTest::addColumn<QString>("expected_header");
QTest::addColumn<QStringList>("expected_content");
QTest::newRow("No Escaped fields") << "HI#1234#"
<< "HI"
<< QStringList{"1234"};
QTest::newRow("Multiple fields") << "ID#34#Akashi#"
<< "ID"
<< QStringList{"34", "Akashi"};
QTest::newRow("Encoded fields") << "MC#[T<and>T]Objection.opus#0#oldmud0#-1#0#0#"
<< "MC"
<< QStringList{"[T&T]Objection.opus", "0", "oldmud0", "-1", "0", "0"};
QTest::newRow("Sequence of encoded characters") << "UNIT#<and><and><percent><num><percent><dollar>#"
<< "UNIT"
<< QStringList{"&&%#%$"};
QTest::newRow("Unescaped characters") << "MC#20% Cooler#"
<< "Unknown"
<< QStringList{"Unknown"};
QTest::newRow("Empty packet") << ""
<< "Unknown"
<< QStringList{"Unknown"};
QTest::newRow("Bogus Packet - PR 328") << "ZZ#%@%#@^#@&^#@$^@&$^*@&$*@^$&*@$@^$&*@^$&#^&#@$#%"
<< "Unknown"
<< QStringList{"Unknown"};
}
void Packet::createPacketFromString()
{
QFETCH(QString, incoming_packet);
QFETCH(QString, expected_header);
QFETCH(QStringList, expected_content);
AOPacket *packet = PacketFactory::createPacket(incoming_packet);
QCOMPARE(packet->getPacketInfo().header, expected_header);
QCOMPARE(packet->getContent(), expected_content);
}
}
}
QTEST_APPLESS_MAIN(tests::unittests::Packet)
#include "tst_unittest_aopacket.moc"