From 27e4bd8accb0a58c6ceb98c0329862a7f1efc116 Mon Sep 17 00:00:00 2001 From: scatterflower Date: Thu, 7 Jul 2022 11:08:52 -0500 Subject: [PATCH] Add new tests --- core/src/packet/packet_casea.cpp | 2 +- core/src/packet/packet_setcase.cpp | 2 +- .../tst_unittest_aopacket.cpp | 88 +++++++++++++++++++ 3 files changed, 90 insertions(+), 2 deletions(-) diff --git a/core/src/packet/packet_casea.cpp b/core/src/packet/packet_casea.cpp index 2dd7452..b811696 100644 --- a/core/src/packet/packet_casea.cpp +++ b/core/src/packet/packet_casea.cpp @@ -15,7 +15,7 @@ PacketInfo PacketCasea::getPacketInfo() const PacketInfo info{ .acl_permission = ACLRole::Permission::NONE, .min_args = 6, - .header = "Casea"}; + .header = "CASEA"}; return info; } diff --git a/core/src/packet/packet_setcase.cpp b/core/src/packet/packet_setcase.cpp index 1453b35..9303194 100644 --- a/core/src/packet/packet_setcase.cpp +++ b/core/src/packet/packet_setcase.cpp @@ -13,7 +13,7 @@ PacketInfo PacketSetcase::getPacketInfo() const PacketInfo info{ .acl_permission = ACLRole::Permission::NONE, .min_args = 7, - .header = "Setcase"}; + .header = "SETCASE"}; return info; } diff --git a/tests/unittest_aopacket/tst_unittest_aopacket.cpp b/tests/unittest_aopacket/tst_unittest_aopacket.cpp index 3232610..e8d7743 100644 --- a/tests/unittest_aopacket/tst_unittest_aopacket.cpp +++ b/tests/unittest_aopacket/tst_unittest_aopacket.cpp @@ -35,6 +35,12 @@ class Packet : public QObject * @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() @@ -42,6 +48,88 @@ void Packet::init() AOPacket::registerPackets(); } +void Packet::createPacketSubclass_data() +{ + QTest::addColumn("incoming_packet"); + QTest::addColumn("expected_header"); + QTest::addColumn("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" + << 0; +} + +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"});