Skip to content

Commit

Permalink
Fixing session_setup_res tests
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 f61e7ca commit 929cf56
Showing 1 changed file with 83 additions and 106 deletions.
189 changes: 83 additions & 106 deletions tests/din/session_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,121 +89,98 @@ SCENARIO("Encode and decode DIN session setup message") {
}
}

// EXI stream: 80980214b22ca1afff8d8b51e020451114a9413960a914c4c8ccd0d4a8c412d71bd3c0c0
// EXI stream: 809a0211d63f74d2297ac911e0201526a2698d8017da353360c0
// XML:
// <ns7:V2G_Message>
// <ns7:Header>
// <ns8:SessionID>52C8B286BFFE362D</ns8:SessionID>
// <ns8:SessionID>4758FDD348A5EB24</ns8:SessionID>
// </ns7:Header>
// <ns7:Body>
// <ns5:SessionSetupRes>
// <ns5:ResponseCode>OK_NewSessionEstablished</ns5:ResponseCode>
// <ns5:EVSEID>DE*PNX*E12345*1</ns5:EVSEID>
// <ns5:EVSETimeStamp>1675074582</ns5:EVSETimeStamp>
// <ns5:EVSEID>49A89A6360</ns5:EVSEID>
// <ns5:DateTimeNow>1667918014</ns5:EVSETimeStamp>
// </ns5:SessionSetupRes>
// </ns7:Body>
// </ns7:V2G_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[] = {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);
//
// init_din_MessageHeaderType(&request.V2G_Message.Header);
//
// auto& header = request.V2G_Message.Header;
// header.SessionID.bytesLen = din_sessionIDType_BYTES_SIZE;
// const auto session_id = std::array<uint8_t, 8>{0x52, 0xC8, 0xB2, 0x86, 0xBF, 0xFE, 0x36, 0x2D};
// std::copy(session_id.begin(), session_id.end(), header.SessionID.bytes);
//
// init_din_BodyType(&request.V2G_Message.Body);
// auto& body = request.V2G_Message.Body;
// init_din_SessionSetupResType(&body.SessionSetupRes);
// body.SessionSetupRes_isUsed = true;
//
// // set the response code
// body.SessionSetupRes.ResponseCode = din_responseCodeType_OK_NewSessionEstablished;
//
// // set the EVSE ID
// const auto evse_id =
// std::array<uint8_t, 15>{'D', 'E', '*', 'P', 'N', 'X', '*', 'E', '1', '2', '3', '4', '5', '*', '1'};
// std::copy(evse_id.begin(), evse_id.end(), body.SessionSetupRes.EVSEID.bytes);
// body.SessionSetupRes.EVSEID.bytesLen = evse_id.size();
//
// // set the EVSE timestamp
// body.SessionSetupRes.DateTimeNow_isUsed = true;
// body.SessionSetupRes.DateTimeNow = 1675074582;
//
// uint8_t stream[256] = {};
// exi_bitstream_t exi_stream_in;
// size_t pos1 = 0;
// int errn = 0;
//
// exi_bitstream_init(&exi_stream_in, stream, sizeof(stream), pos1, nullptr);
//
// THEN("It should be encoded succussfully") {
//
// REQUIRE(encode_din_exiDocument(&exi_stream_in, &request) == 0);
//
// const auto encoded_stream =
// std::vector<uint8_t>(stream, stream + exi_bitstream_get_length(&exi_stream_in) + 1);
//
// const auto expected_exi_stream = std::vector<uint8_t>(std::begin(doc_raw), std::end(doc_raw));
//
// // REQUIRE(encoded_stream == expected_exi_stream);
// }
// }
//
// GIVEN("Good case - Decode an SessionSetupRes document") {
//
// 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;
// int errn = 0;
//
// exi_bitstream_init(&exi_stream_in, reinterpret_cast<uint8_t*>(doc_raw), sizeof(doc_raw), pos1, nullptr);
//
// THEN("It should be decoded succussfully") {
// din_exiDocument request;
//
// REQUIRE(decode_din_exiDocument(&exi_stream_in, &request) == 0);
//
// // Check Header
// auto& header = request.V2G_Message.Header;
// const auto expected_session_id = std::vector<uint8_t>{0x52, 0xC8, 0xB2, 0x86, 0xBF, 0xFE, 0x36, 0x2D};
// const auto session_id =
// std::vector<uint8_t>(std::begin(header.SessionID.bytes), std::end(header.SessionID.bytes));
// REQUIRE(session_id == expected_session_id);
// REQUIRE(header.Notification_isUsed == false);
// REQUIRE(header.Signature_isUsed == false);
//
// // Check Body
// REQUIRE(request.V2G_Message.Body.SessionSetupRes_isUsed == true);
//
// auto& session_setup_res = request.V2G_Message.Body.SessionSetupRes;
//
// // check the response code
// REQUIRE(session_setup_res.ResponseCode == din_responseCodeType_OK_NewSessionEstablished);
//
// // check the EVSE ID
// const auto evse_id = std::vector<uint8_t>(std::begin(session_setup_res.EVSEID.bytes),
// std::end(session_setup_res.EVSEID.bytes));
// REQUIRE(evse_id ==
// std::vector<uint8_t>({'D', 'E', '*', 'P', 'N', 'X', '*', 'E', '1', '2', '3', '4', '5', '*',
// '1'}));
// REQUIRE(session_setup_res.EVSEID.bytesLen == 15);
//
// // check the EVSE timestamp
// REQUIRE(session_setup_res.DateTimeNow_isUsed == true);
// REQUIRE(session_setup_res.DateTimeNow == 1675074582);
// }
// }
GIVEN("Good case - Encode an SessionSetupRes document") {
uint8_t doc_raw[] = {0x80, 0x9a, 0x02, 0x11, 0xd6, 0x3f, 0x74, 0xd2, 0x29, 0x7a, 0xc9, 0x11, 0xe0,
0x20, 0x15, 0x26, 0xa2, 0x69, 0x8d, 0x80, 0x17, 0xda, 0x35, 0x33, 0x60, 0xc0};

din_exiDocument request;
init_din_exiDocument(&request);

init_din_MessageHeaderType(&request.V2G_Message.Header);

auto& header = request.V2G_Message.Header;
header.SessionID.bytesLen = din_sessionIDType_BYTES_SIZE;
const auto session_id = std::array<uint8_t, 8>{0x47, 0x58, 0xFD, 0xD3, 0x48, 0xA5, 0xEB, 0x24};
std::copy(session_id.begin(), session_id.end(), header.SessionID.bytes);

init_din_BodyType(&request.V2G_Message.Body);
auto& body = request.V2G_Message.Body;
init_din_SessionSetupResType(&body.SessionSetupRes);
body.SessionSetupRes_isUsed = true;

// set the response code
body.SessionSetupRes.ResponseCode = din_responseCodeType_OK_NewSessionEstablished;

// set the EVSE ID
const auto evse_id = std::array<uint8_t, 5>{0x49, 0xA8, 0x9A, 0x63, 0x60};
std::copy(evse_id.begin(), evse_id.end(), body.SessionSetupRes.EVSEID.bytes);
body.SessionSetupRes.EVSEID.bytesLen = evse_id.size();

// set the EVSE timestamp
body.SessionSetupRes.DateTimeNow_isUsed = true;
body.SessionSetupRes.DateTimeNow = 1667918014;

THEN("It should be encoded succussfully") {
const auto result = test_utils::encode_and_compare(request, doc_raw, sizeof(doc_raw));

REQUIRE(result.encoding_successful);
REQUIRE(result.bitstream_match);
}
}

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

const auto expected_session_id = std::vector<uint8_t>{0x47, 0x58, 0xFD, 0xD3, 0x48, 0xA5, 0xEB, 0x24};
uint8_t doc_raw[] = {0x80, 0x9a, 0x02, 0x11, 0xd6, 0x3f, 0x74, 0xd2, 0x29, 0x7a, 0xc9, 0x11, 0xe0,
0x20, 0x15, 0x26, 0xa2, 0x69, 0x8d, 0x80, 0x17, 0xda, 0x35, 0x33, 0x60, 0xc0};

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

const auto& request = result.value;

// Check Header
auto& header = request.V2G_Message.Header;

const auto session_id =
std::vector<uint8_t>(std::begin(header.SessionID.bytes), std::end(header.SessionID.bytes));
REQUIRE(session_id == expected_session_id);
REQUIRE(header.Notification_isUsed == false);
REQUIRE(header.Signature_isUsed == false);

// Check Body
REQUIRE(request.V2G_Message.Body.SessionSetupRes_isUsed == true);
const auto& session_setup_res = request.V2G_Message.Body.SessionSetupRes;

// check the response code
REQUIRE(session_setup_res.ResponseCode == din_responseCodeType_OK_NewSessionEstablished);

// check the EVSE ID
REQUIRE(session_setup_res.EVSEID.bytesLen == 5);
const auto evse_id =
std::vector<uint8_t>(std::begin(session_setup_res.EVSEID.bytes),
std::begin(session_setup_res.EVSEID.bytes) + session_setup_res.EVSEID.bytesLen);
REQUIRE(evse_id == std::vector<uint8_t>({0x49, 0xA8, 0x9A, 0x63, 0x60}));

// check the EVSE timestamp
REQUIRE(session_setup_res.DateTimeNow_isUsed == true);
REQUIRE(session_setup_res.DateTimeNow == 1667918014);
}
}
}

0 comments on commit 929cf56

Please sign in to comment.