Add tests aopacket
This commit is contained in:
parent
9c6e703bfc
commit
07450e9fe8
16
CMakeLists.txt
Normal file
16
CMakeLists.txt
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.1.0)
|
||||||
|
|
||||||
|
project(ao)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
set(CMAKE_AUTOMOC ON)
|
||||||
|
set(CMAKE_AUTORCC ON)
|
||||||
|
set(CMAKE_AUTOUIC ON)
|
||||||
|
|
||||||
|
if(CMAKE_VERSION VERSION_LESS "3.7.0")
|
||||||
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_subdirectory(test)
|
8
README_TEST.md
Normal file
8
README_TEST.md
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
Running tests requires Catch2 and cmake
|
||||||
|
|
||||||
|
```sh
|
||||||
|
mkdir cbuild && cd cbuild
|
||||||
|
cmake ..
|
||||||
|
make
|
||||||
|
./test/test
|
||||||
|
```
|
6
test/CMakeLists.txt
Normal file
6
test/CMakeLists.txt
Normal file
@ -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)
|
47
test/test_aopacket.cpp
Normal file
47
test/test_aopacket.cpp
Normal file
@ -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);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user