Skip to content

Commit

Permalink
Changed doc_raw string arrays to real arrays
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Lukas <[email protected]>
  • Loading branch information
SebaLukas committed Jun 20, 2024
1 parent 284082d commit f61e7ca
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 42 deletions.
9 changes: 4 additions & 5 deletions tests/app_handshake/app_handshake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ 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";
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") {
const auto result = test_utils::decode<appHand_exiDocument>(doc_raw, sizeof(doc_raw));
Expand Down Expand Up @@ -43,7 +42,7 @@ SCENARIO("Encode and decode app protocol response messages") {

GIVEN("Decode an AppProtocolRes document") {

uint8_t doc_raw[] = "\x80\x40\x00\x40";
uint8_t doc_raw[] = {0x80, 0x40, 0x00, 0x40};

THEN("It should be decoded succussfully") {
const auto result = test_utils::decode<appHand_exiDocument>(doc_raw, sizeof(doc_raw));
Expand Down
10 changes: 6 additions & 4 deletions tests/din/service_discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ SCENARIO("Encode and decode a DIN service discovery message") {

GIVEN("Good case - Encode a ServiceDiscoveryReq document") {

uint8_t doc_raw[] = "\x80\x9a\x02\x11\xd6\x3f\x74\xd2\x29\x7a\xc9\x11\x94\x00";
uint8_t doc_raw[] = {0x80, 0x9a, 0x02, 0x11, 0xd6, 0x3f, 0x74, 0xd2, 0x29, 0x7a, 0xc9, 0x11, 0x94, 0x00};

din_exiDocument request;
init_din_exiDocument(&request);
Expand Down Expand Up @@ -65,7 +65,7 @@ SCENARIO("Encode and decode a DIN service discovery message") {
GIVEN("Good case - Decode a ServiceDiscoveryReq document") {

auto expected_session_id = std::vector<uint8_t>{0x47, 0x58, 0xFD, 0xD3, 0x48, 0xA5, 0xEB, 0x24};
uint8_t doc_raw[] = "\x80\x9a\x02\x11\xd6\x3f\x74\xd2\x29\x7a\xc9\x11\x94\x00";
uint8_t doc_raw[] = {0x80, 0x9a, 0x02, 0x11, 0xd6, 0x3f, 0x74, 0xd2, 0x29, 0x7a, 0xc9, 0x11, 0x94, 0x00};

THEN("It should be decoded succussfully") {
const auto result = test_utils::decode<din_exiDocument>(doc_raw, sizeof(doc_raw));
Expand Down Expand Up @@ -116,7 +116,8 @@ SCENARIO("Encode and decode a DIN service discovery message") {
// </ns7:V2G_Message>

GIVEN("Good case - Encode an ServiceDiscoveryRes document") {
uint8_t doc_raw[] = "\x80\x9a\x02\x11\xd6\x3f\x74\xd2\x29\x7a\xc9\x11\xa0\x01\x20\x02\x41\x00\xc4";
uint8_t doc_raw[] = {0x80, 0x9a, 0x02, 0x11, 0xd6, 0x3f, 0x74, 0xd2, 0x29, 0x7a,
0xc9, 0x11, 0xa0, 0x01, 0x20, 0x02, 0x41, 0x00, 0xc4};

din_exiDocument request;
init_din_exiDocument(&request);
Expand Down Expand Up @@ -165,7 +166,8 @@ SCENARIO("Encode and decode a DIN service discovery message") {

GIVEN("Good case - Decode an ServiceDiscoveryRes document") {
auto expected_session_id = std::vector<uint8_t>{0x47, 0x58, 0xFD, 0xD3, 0x48, 0xA5, 0xEB, 0x24};
uint8_t doc_raw[] = "\x80\x9a\x02\x11\xd6\x3f\x74\xd2\x29\x7a\xc9\x11\xa0\x01\x20\x02\x41\x00\xc4";
uint8_t doc_raw[] = {0x80, 0x9a, 0x02, 0x11, 0xd6, 0x3f, 0x74, 0xd2, 0x29, 0x7a,
0xc9, 0x11, 0xa0, 0x01, 0x20, 0x02, 0x41, 0x00, 0xc4};

THEN("It should be decoded succussfully") {
const auto result = test_utils::decode<din_exiDocument>(doc_raw, sizeof(doc_raw));
Expand Down
24 changes: 11 additions & 13 deletions tests/din/session_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ SCENARIO("Encode and decode DIN session setup message") {

GIVEN("Good case - Encode an SessionSetupReq document") {

uint8_t doc_raw[] = "\x80"
"\x9a\x02\x00\x00\x00\x00\x00\x00\x00\x00"
"\x11\xd0\x1a\x12\x1d\xc9\x83\xcd\x60\x00";
uint8_t doc_raw[] = {0x80, 0x9a, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x11, 0xd0, 0x1a, 0x12, 0x1d, 0xc9, 0x83, 0xcd, 0x60, 0x00};

din_exiDocument request;
init_din_exiDocument(&request);
Expand Down Expand Up @@ -60,9 +59,8 @@ SCENARIO("Encode and decode DIN session setup message") {

GIVEN("Good case - Decode an SessionSetupReq document") {

uint8_t doc_raw[] = "\x80"
"\x9a\x02\x00\x00\x00\x00\x00\x00\x00\x00"
"\x11\xd0\x1a\x12\x1d\xc9\x83\xcd\x60\x00";
uint8_t doc_raw[] = {0x80, 0x9a, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x11, 0xd0, 0x1a, 0x12, 0x1d, 0xc9, 0x83, 0xcd, 0x60, 0x00};

THEN("It should be decoded succussfully") {
const auto result = test_utils::decode<din_exiDocument>(doc_raw, sizeof(doc_raw));
Expand Down Expand Up @@ -109,9 +107,9 @@ SCENARIO("Encode and decode DIN session setup message") {
// TODO: These tests should work but at the moment the exi stream is broken.
//
// GIVEN("Good case - Encode an SessionSetupRes document") {
// uint8_t doc_raw[] =
// "\x80\x98\x02\x14\xb2\x2c\xa1\xaf\xff\x8d\x8b\x51\xe0\x20\x45\x11\x14\xa9\x41\x39\x60\xa9"
// "\x14\xc4\xc8\xcc\xd0\xd4\xa8\xc4\x12\xd7\x1b\xd3\xc0\xc0";
// uint8_t doc_raw[] = {0x80, 0x98, 0x02, 0x14, 0xb2, 0x2c, 0xa1, 0xaf, 0xff, 0x8d, 0x8b, 0x51, 0xe0, 0x20,
// 0x45, 0x11, 0x14, 0xa9, 0x41, 0x39, 0x60, 0xa9, 0x14, 0xc4, 0xc8, 0xcc, 0xd0, 0xd4, 0xa8, 0xc4, 0x12,
// 0xd7, 0x1b, 0xd3, 0xc0, 0xc0};
//
// din_exiDocument request;
// init_din_exiDocument(&request);
Expand Down Expand Up @@ -163,9 +161,9 @@ SCENARIO("Encode and decode DIN session setup message") {
//
// GIVEN("Good case - Decode an SessionSetupRes document") {
//
// uint8_t doc_raw[] =
// "\x80\x98\x02\x14\xb2\x2c\xa1\xaf\xff\x8d\x8b\x51\xe0\x20\x45\x11\x14\xa9\x41\x39\x60\xa9"
// "\x14\xc4\xc8\xcc\xd0\xd4\xa8\xc4\x12\xd7\x1b\xd3\xc0\xc0";
// uint8_t doc_raw[] = {0x80, 0x98, 0x02, 0x14, 0xb2, 0x2c, 0xa1, 0xaf, 0xff, 0x8d, 0x8b, 0x51, 0xe0, 0x20,
// 0x45, 0x11, 0x14, 0xa9, 0x41, 0x39, 0x60, 0xa9, 0x14, 0xc4, 0xc8, 0xcc, 0xd0, 0xd4, 0xa8, 0xc4, 0x12,
// 0xd7, 0x1b, 0xd3, 0xc0, 0xc0};
//
// exi_bitstream_t exi_stream_in;
// size_t pos1 = 0;
Expand Down Expand Up @@ -208,4 +206,4 @@ SCENARIO("Encode and decode DIN session setup message") {
// REQUIRE(session_setup_res.DateTimeNow == 1675074582);
// }
// }
}
}
16 changes: 8 additions & 8 deletions tests/iso20/ac_charge_loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ static void setup_header(struct iso20_ac_MessageHeaderType* header,
SCENARIO("Encode and decode AC charge loop message") {

GIVEN("Good case - Encode correct bpt control (AcChargeLoopReq)") {
uint8_t doc_raw[] = "\x80\x08\x04\x1e\x98\x69\xd6\xa6\x1d\xc1\xef\x89\x5b"
"\x9b\x4a\x80\x62\x83\x24\x18\x64\x00\x96";
uint8_t doc_raw[] = {0x80, 0x08, 0x04, 0x1e, 0x98, 0x69, 0xd6, 0xa6, 0x1d, 0xc1, 0xef, 0x89,
0x5b, 0x9b, 0x4a, 0x80, 0x62, 0x83, 0x24, 0x18, 0x64, 0x00, 0x96};

iso20_ac_exiDocument request;
init_iso20_ac_exiDocument(&request);
Expand Down Expand Up @@ -78,8 +78,8 @@ SCENARIO("Encode and decode AC charge loop message") {

GIVEN("Good case - Encode correct bpt control (AcChargeLoopRes)") {

uint8_t doc_raw[] = "\x80\x0c\x04\x1e\x98\x69\xd6\xa6\x1d\xc1\xef"
"\x89\x5b\x9b\x4a\x80\x62\x00\x59\x00";
uint8_t doc_raw[] = {0x80, 0x0c, 0x04, 0x1e, 0x98, 0x69, 0xd6, 0xa6, 0x1d, 0xc1,
0xef, 0x89, 0x5b, 0x9b, 0x4a, 0x80, 0x62, 0x00, 0x59, 0x00};

iso20_ac_exiDocument response;
init_iso20_ac_exiDocument(&response);
Expand Down Expand Up @@ -108,8 +108,8 @@ SCENARIO("Encode and decode AC charge loop message") {
GIVEN("Good case - Decode correct bpt control (AcChargeLoopReq)") {
const auto expected_session_id = std::vector<uint8_t>{0x3D, 0x30, 0xD3, 0xAD, 0x4C, 0x3B, 0x83, 0xDF};

uint8_t doc_raw[] = "\x80\x08\x04\x1e\x98\x69\xd6\xa6\x1d\xc1\xef\x89\x5b"
"\x9b\x4a\x80\x62\x83\x24\x18\x64\x00\x96";
uint8_t doc_raw[] = {0x80, 0x08, 0x04, 0x1e, 0x98, 0x69, 0xd6, 0xa6, 0x1d, 0xc1, 0xef, 0x89,
0x5b, 0x9b, 0x4a, 0x80, 0x62, 0x83, 0x24, 0x18, 0x64, 0x00, 0x96};

THEN("It should be decoded succussfully") {
const auto result = test_utils::decode<iso20_ac_exiDocument>(doc_raw, sizeof(doc_raw));
Expand Down Expand Up @@ -140,8 +140,8 @@ SCENARIO("Encode and decode AC charge loop message") {

const auto expected_session_id = std::vector<uint8_t>{0x3D, 0x30, 0xD3, 0xAD, 0x4C, 0x3B, 0x83, 0xDF};

uint8_t doc_raw[] = "\x80\x0c\x04\x1e\x98\x69\xd6\xa6\x1d\xc1\xef"
"\x89\x5b\x9b\x4a\x80\x62\x00\x59\x00";
uint8_t doc_raw[] = {0x80, 0x0c, 0x04, 0x1e, 0x98, 0x69, 0xd6, 0xa6, 0x1d, 0xc1,
0xef, 0x89, 0x5b, 0x9b, 0x4a, 0x80, 0x62, 0x00, 0x59, 0x00};

THEN("It should be decoded succussfully") {
const auto result = test_utils::decode<iso20_ac_exiDocument>(doc_raw, sizeof(doc_raw));
Expand Down
20 changes: 10 additions & 10 deletions tests/iso20/dc_charge_loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ static void setup_header(struct iso20_dc_MessageHeaderType* header,
SCENARIO("Encode and decode DC charge loop message") {

GIVEN("Good case - Encode correct bpt control (DcChargeLoopReq)") {
uint8_t doc_raw[] = "\x80\x34\x04\x2d\x16\x6f\x29\xfb\x80\xea\x56\x0a"
"\xeb\xdb\xfb\x30\x62\x81\x00\x12\x00\x61\x64\x00"
"\x0a\x02\x00\x24\x00\xc8\x00";
uint8_t doc_raw[] = {0x80, 0x34, 0x04, 0x2d, 0x16, 0x6f, 0x29, 0xfb, 0x80, 0xea, 0x56,
0x0a, 0xeb, 0xdb, 0xfb, 0x30, 0x62, 0x81, 0x00, 0x12, 0x00, 0x61,
0x64, 0x00, 0x0a, 0x02, 0x00, 0x24, 0x00, 0xc8, 0x00};

iso20_dc_exiDocument request;
init_iso20_dc_exiDocument(&request);
Expand Down Expand Up @@ -100,8 +100,8 @@ SCENARIO("Encode and decode DC charge loop message") {

GIVEN("Good case - Encode correct bpt control (DcChargeLoopRes)") {

uint8_t doc_raw[] = "\x80\x38\x04\x2d\x16\x6f\x29\xfb\x80\xea\x56\x0b\x7b\xdb\xfb"
"\x30\x62\x00\x63\xf0\x68\x07\x81\xfc\x28\x07\xc2\x22\x30";
uint8_t doc_raw[] = {0x80, 0x38, 0x04, 0x2d, 0x16, 0x6f, 0x29, 0xfb, 0x80, 0xea, 0x56, 0x0b, 0x7b, 0xdb, 0xfb,
0x30, 0x62, 0x00, 0x63, 0xf0, 0x68, 0x07, 0x81, 0xfc, 0x28, 0x07, 0xc2, 0x22, 0x30};

iso20_dc_exiDocument response;
init_iso20_dc_exiDocument(&response);
Expand Down Expand Up @@ -137,9 +137,9 @@ SCENARIO("Encode and decode DC charge loop message") {
GIVEN("Good case - Decode correct bpt control (DcChargeLoopReq)") {
const auto expected_session_id = std::vector<uint8_t>{0x5A, 0x2C, 0xDE, 0x53, 0xF7, 0x01, 0xD4, 0xAC};

uint8_t doc_raw[] = "\x80\x34\x04\x2d\x16\x6f\x29\xfb\x80\xea\x56\x0a"
"\xeb\xdb\xfb\x30\x62\x81\x00\x12\x00\x61\x64\x00"
"\x0a\x02\x00\x24\x00\xc8\x00";
uint8_t doc_raw[] = {0x80, 0x34, 0x04, 0x2d, 0x16, 0x6f, 0x29, 0xfb, 0x80, 0xea, 0x56,
0x0a, 0xeb, 0xdb, 0xfb, 0x30, 0x62, 0x81, 0x00, 0x12, 0x00, 0x61,
0x64, 0x00, 0x0a, 0x02, 0x00, 0x24, 0x00, 0xc8, 0x00};

THEN("It should be decoded succussfully") {
const auto result = test_utils::decode<iso20_dc_exiDocument>(doc_raw, sizeof(doc_raw));
Expand Down Expand Up @@ -174,8 +174,8 @@ SCENARIO("Encode and decode DC charge loop message") {

const auto expected_session_id = std::vector<uint8_t>{0x5A, 0x2C, 0xDE, 0x53, 0xF7, 0x01, 0xD4, 0xAC};

uint8_t doc_raw[] = "\x80\x38\x04\x2d\x16\x6f\x29\xfb\x80\xea\x56\x0b\x7b\xdb\xfb"
"\x30\x62\x00\x63\xf0\x68\x07\x81\xfc\x28\x07\xc2\x22\x30";
uint8_t doc_raw[] = {0x80, 0x38, 0x04, 0x2d, 0x16, 0x6f, 0x29, 0xfb, 0x80, 0xea, 0x56, 0x0b, 0x7b, 0xdb, 0xfb,
0x30, 0x62, 0x00, 0x63, 0xf0, 0x68, 0x07, 0x81, 0xfc, 0x28, 0x07, 0xc2, 0x22, 0x30};

THEN("It should be decoded succussfully") {
const auto result = test_utils::decode<iso20_dc_exiDocument>(doc_raw, sizeof(doc_raw));
Expand Down
3 changes: 1 addition & 2 deletions tests/test_utils/codec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ static EncodingResult encode(int (*encode_func)(exi_bitstream_t*, DocType*), con
return {false, false};
}

// FIXME (aw): why +1?
const auto encoded_stream = std::vector<uint8_t>(stream, stream + exi_bitstream_get_length(&exi_stream_in) + 1);
const auto encoded_stream = std::vector<uint8_t>(stream, stream + exi_bitstream_get_length(&exi_stream_in));

const auto expected_exi_stream = std::vector<uint8_t>(compare_data, compare_data + length);

Expand Down

0 comments on commit f61e7ca

Please sign in to comment.