Refactor aopacket tests
This commit is contained in:
parent
9c4f8dfc97
commit
7a1d6743e1
@ -6,42 +6,38 @@
|
|||||||
TEST_CASE("AOPacket construct", "[aopacket]") {
|
TEST_CASE("AOPacket construct", "[aopacket]") {
|
||||||
// Parameters
|
// Parameters
|
||||||
QString packet_string = "CT#MY_OOC_NAME#/doc https://docs.google.com/document/d/123/edit##%";
|
QString packet_string = "CT#MY_OOC_NAME#/doc https://docs.google.com/document/d/123/edit##%";
|
||||||
QString header = "CT";
|
|
||||||
QStringList contents = {"MY_OOC_NAME", "/doc https://docs.google.com/document/d/123/edit#"};
|
|
||||||
|
|
||||||
// Packet string only
|
SECTION("Packet string") {
|
||||||
AOPacket p(packet_string);
|
AOPacket p(packet_string);
|
||||||
REQUIRE(p.to_string() == packet_string);
|
REQUIRE(p.to_string() == packet_string);
|
||||||
|
}
|
||||||
// Header and Contents Separate
|
SECTION("Header and contents") {
|
||||||
AOPacket p2(header, contents);
|
AOPacket p("CT", {"MY_OOC_NAME", "/doc https://docs.google.com/document/d/123/edit#"});
|
||||||
REQUIRE(p2.to_string() == packet_string);
|
REQUIRE(p.to_string() == packet_string);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("AOPacket encode/decode", "[aopacket]") {
|
TEST_CASE("AOPacket encode/decode", "[aopacket]") {
|
||||||
// Parameters
|
// Parameters
|
||||||
QString packet_string = "CT#MY_OOC_NAME#/doc https://docs.google.com/document/d/%$&/edit##%";
|
QString packet_string = "CT#MY_OOC_NAME#/doc https://docs.google.com/document/d/%$&/edit##%";
|
||||||
QString header = "CT";
|
QString good_encode = "CT#MY_OOC_NAME#/doc https://docs.google.com/document/d/<percent><dollar><and>/edit<num>#%";
|
||||||
QStringList contents = {"MY_OOC_NAME", "/doc https://docs.google.com/document/d/%$&/edit#"};
|
|
||||||
|
|
||||||
// Encodes that get "sent" to the server
|
SECTION("Bad encode/decode because packet string constructor splits the '#' after 'edit'") {
|
||||||
QString bad_send = "CT#MY_OOC_NAME#/doc https://docs.google.com/document/d/<percent><dollar><and>/edit##%";
|
AOPacket p(packet_string);
|
||||||
QString good_send = "CT#MY_OOC_NAME#/doc https://docs.google.com/document/d/<percent><dollar><and>/edit<num>#%";
|
p.net_encode();
|
||||||
|
REQUIRE(p.to_string() != good_encode);
|
||||||
|
|
||||||
// Bad encode/decode for docs because the split on '#' after "edit" in the doc url
|
p.net_decode();
|
||||||
AOPacket p(packet_string);
|
REQUIRE(p.to_string() == packet_string);
|
||||||
p.net_encode();
|
}
|
||||||
REQUIRE(p.to_string() == bad_send);
|
|
||||||
|
|
||||||
p.net_decode();
|
SECTION("Good encode/decode with header and contents constructor") {
|
||||||
REQUIRE(p.to_string() == packet_string);
|
AOPacket p("CT", {"MY_OOC_NAME", "/doc https://docs.google.com/document/d/%$&/edit#"});
|
||||||
|
|
||||||
// Good encode/decode for docs because header and contents are separate
|
p.net_encode();
|
||||||
AOPacket p2(header, contents);
|
REQUIRE(p.to_string() == good_encode);
|
||||||
|
|
||||||
p2.net_encode();
|
p.net_decode();
|
||||||
REQUIRE(p2.to_string() == good_send);
|
REQUIRE(p.to_string() == packet_string);
|
||||||
|
}
|
||||||
p2.net_decode();
|
|
||||||
REQUIRE(p2.to_string() == packet_string);
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user