atrooney-online-2/test/test_aopacket.cpp
TrickyLeifa c9f52b7223 Ported to CMake, ...
* Ported the project to CMake
  * Android and Mac support dropped for the time
being.
  * Tests, BASS and Discord-RPC are now options
* Restructured and reformated the project.
  * Merged `include` and `src`
  * Renamed `resource` to `data`
  * Renamed various files
  * External libraries headers are no longer included in `src`
  * Replaced header guards with #pragma once
  * Multiple refactors (keywords, headers)
  * Added Qt6 compatibility
* Removed various unused functions and headers
* Reworked AOPacket
  * When content is passed to AOPacket, it should be ensured that the content is already decoded.
  * Encoding/decoding are now static methods.
* Fixed various memory leaks
* Removed animation code for AOImage
  * AOImage is always using static images
* Simplified ChatLogPiece
2024-05-15 00:04:16 +02:00

52 lines
1.4 KiB
C++

#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
#include "aopacket.h"
TEST_CASE("AOPacket construct", "[aopacket]")
{
// Parameters
QString packet_string = "CT#MY_OOC_NAME#/doc https://docs.google.com/document/d/123/edit##%";
SECTION("Packet string")
{
AOPacket p(packet_string);
REQUIRE(p.to_string() == packet_string);
}
SECTION("Header and contents")
{
QStringList contents = {"MY_OOC_NAME", "/doc https://docs.google.com/document/d/123/edit#"};
AOPacket p("CT", contents);
REQUIRE(p.to_string() == packet_string);
}
}
TEST_CASE("AOPacket encode/decode", "[aopacket]")
{
// Parameters
QString packet_string = "CT#MY_OOC_NAME#/doc https://docs.google.com/document/d/%$&/edit##%";
QString good_encode = "CT#MY_OOC_NAME#/doc https://docs.google.com/document/d/<percent><dollar><and>/edit<num>#%";
SECTION("Bad encode/decode because packet string constructor splits the '#' after 'edit'")
{
AOPacket p(packet_string);
p.net_encode();
REQUIRE(p.to_string() != good_encode);
p.net_decode();
REQUIRE(p.to_string() == packet_string);
}
SECTION("Good encode/decode with header and contents constructor")
{
QStringList contents = {"MY_OOC_NAME", "/doc https://docs.google.com/document/d/%$&/edit#"};
AOPacket p("CT", contents);
p.net_encode();
REQUIRE(p.to_string() == good_encode);
p.net_decode();
REQUIRE(p.to_string() == packet_string);
}
}