Skip to content

Commit

Permalink
Refactoring unit tests (#15)
Browse files Browse the repository at this point in the history
- Simplify tests & adding utility functions
- Adding tests to test prober en- & decoding ISO20 bpt control mode
- Fixing session setup res tests

Co-authored-by: aw <[email protected]>
Signed-off-by: Sebastian Lukas <[email protected]>
  • Loading branch information
SebaLukas and a-w50 authored Jun 21, 2024
1 parent 1d8704f commit ec437e6
Show file tree
Hide file tree
Showing 14 changed files with 757 additions and 326 deletions.
6 changes: 5 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ FetchContent_MakeAvailable(Catch2)
list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras)
include(Catch)

# source helper functions and library
add_subdirectory(test_utils)

add_subdirectory(app_handshake)
add_subdirectory(DIN)
add_subdirectory(din)
add_subdirectory(iso20)
20 changes: 0 additions & 20 deletions tests/DIN/CMakeLists.txt

This file was deleted.

225 changes: 0 additions & 225 deletions tests/DIN/session_setup.cpp

This file was deleted.

10 changes: 1 addition & 9 deletions tests/app_handshake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
add_executable(test_app_handshake app_handshake.cpp)

target_link_libraries(test_app_handshake
PRIVATE
cbv2g::din
Catch2::Catch2WithMain
)

catch_discover_tests(test_app_handshake)
add_codec_test(app_handshake)
35 changes: 14 additions & 21 deletions tests/app_handshake/app_handshake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,22 @@
#include <cbv2g/app_handshake/appHand_Datatypes.h>
#include <cbv2g/app_handshake/appHand_Decoder.h>

#include "test_utils/codec.hpp"

SCENARIO("Encode and decode app protocol request messages") {

GIVEN("Decode an AppProtocolReq document") {

uint8_t doc_raw[] = "\x80"
"\x00\xf3\xab\x93\x71\xd3\x4b\x9b\x79\xd3\x9b\xa3\x21\xd3\x4b\x9b\x79"
"\xd1\x89\xa9\x89\x89\xc1\xd1\x69\x91\x81\xd2\x0a\x18\x01\x00\x00\x04"
"\x00\x40";

exi_bitstream_t exi_stream_in;
size_t pos1 = 0;
int errn = 0;

exi_bitstream_init(&exi_stream_in, reinterpret_cast<uint8_t*>(doc_raw), sizeof(doc_raw), pos1, nullptr);
uint8_t doc_raw[] = {0x80, 0x00, 0xf3, 0xab, 0x93, 0x71, 0xd3, 0x4b, 0x9b, 0x79, 0xd3, 0x9b, 0xa3,
0x21, 0xd3, 0x4b, 0x9b, 0x79, 0xd1, 0x89, 0xa9, 0x89, 0x89, 0xc1, 0xd1, 0x69,
0x91, 0x81, 0xd2, 0x0a, 0x18, 0x01, 0x00, 0x00, 0x04, 0x00, 0x40};

THEN("It should be decoded succussfully") {
appHand_exiDocument request;
const auto result = test_utils::decode<appHand_exiDocument>(doc_raw, sizeof(doc_raw));
REQUIRE(result.decoding_successful);

const auto& request = result.value;

REQUIRE(decode_appHand_exiDocument(&exi_stream_in, &request) == 0);
REQUIRE(request.supportedAppProtocolReq_isUsed == 1);

REQUIRE(request.supportedAppProtocolReq.AppProtocol.arrayLen == 1);
Expand All @@ -45,18 +42,14 @@ SCENARIO("Encode and decode app protocol response messages") {

GIVEN("Decode an AppProtocolRes document") {

uint8_t doc_raw[] = "\x80\x40\x00\x40";

exi_bitstream_t exi_stream_in;
size_t pos1 = 0;
int errn = 0;

exi_bitstream_init(&exi_stream_in, reinterpret_cast<uint8_t*>(doc_raw), sizeof(doc_raw), pos1, nullptr);
uint8_t doc_raw[] = {0x80, 0x40, 0x00, 0x40};

THEN("It should be decoded succussfully") {
appHand_exiDocument response;
const auto result = test_utils::decode<appHand_exiDocument>(doc_raw, sizeof(doc_raw));
REQUIRE(result.decoding_successful);

const auto& response = result.value;

REQUIRE(decode_appHand_exiDocument(&exi_stream_in, &response) == 0);
REQUIRE(response.supportedAppProtocolRes_isUsed == 1);

REQUIRE(response.supportedAppProtocolRes.ResponseCode == appHand_responseCodeType_OK_SuccessfulNegotiation);
Expand Down
2 changes: 2 additions & 0 deletions tests/din/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_codec_test(session_setup)
add_codec_test(service_discovery)
Loading

0 comments on commit ec437e6

Please sign in to comment.