aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSkye Deving <76892045+skyedeving@users.noreply.github.com>2021-01-04 06:36:47 -0600
committerSkye Deving <76892045+skyedeving@users.noreply.github.com>2021-01-28 11:05:42 -0600
commit07450e9fe80913d280b80cb6eec11572c015ff1c (patch)
treedefe839c4b55b7ced60093b5e98952c73e5c129d /test
parent9c6e703bfc06aec0b6bf1b2056fff5302ed4a241 (diff)
Add tests aopacket
Diffstat (limited to 'test')
-rw-r--r--test/CMakeLists.txt6
-rw-r--r--test/test_aopacket.cpp47
2 files changed, 53 insertions, 0 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
new file mode 100644
index 00000000..cc02859e
--- /dev/null
+++ b/test/CMakeLists.txt
@@ -0,0 +1,6 @@
+find_package(Qt5 COMPONENTS Widgets REQUIRED)
+find_package(Catch2 REQUIRED)
+
+add_executable(test test_aopacket.cpp ../include/aopacket.h ../src/aopacket.cpp)
+target_include_directories(test PRIVATE ../include)
+target_link_libraries(test PRIVATE Qt5::Widgets Catch2::Catch2)
diff --git a/test/test_aopacket.cpp b/test/test_aopacket.cpp
new file mode 100644
index 00000000..a5aeb437
--- /dev/null
+++ b/test/test_aopacket.cpp
@@ -0,0 +1,47 @@
+#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##%";
+ QString header = "CT";
+ QStringList contents = {"MY_OOC_NAME", "/doc https://docs.google.com/document/d/123/edit#"};
+
+ // Packet string only
+ AOPacket p(packet_string);
+ REQUIRE(p.to_string() == packet_string);
+
+ // Header and Contents Separate
+ AOPacket p2(header, contents);
+ REQUIRE(p2.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 header = "CT";
+ QStringList contents = {"MY_OOC_NAME", "/doc https://docs.google.com/document/d/%$&/edit#"};
+
+ // Encodes that get "sent" to the server
+ QString bad_send = "CT#MY_OOC_NAME#/doc https://docs.google.com/document/d/<percent><dollar><and>/edit##%";
+ QString good_send = "CT#MY_OOC_NAME#/doc https://docs.google.com/document/d/<percent><dollar><and>/edit<num>#%";
+
+ // Bad encode/decode for docs because the split on '#' after "edit" in the doc url
+ AOPacket p(packet_string);
+ p.net_encode();
+ REQUIRE(p.to_string() == bad_send);
+
+ p.net_decode();
+ REQUIRE(p.to_string() == packet_string);
+
+ // Good encode/decode for docs because header and contents are separate
+ AOPacket p2(header, contents);
+
+ p2.net_encode();
+ REQUIRE(p2.to_string() == good_send);
+
+ p2.net_decode();
+ REQUIRE(p2.to_string() == packet_string);
+}