diff --git a/tests/din/session_setup.cpp b/tests/din/session_setup.cpp index bf6de7c..beaaef0 100644 --- a/tests/din/session_setup.cpp +++ b/tests/din/session_setup.cpp @@ -89,121 +89,98 @@ SCENARIO("Encode and decode DIN session setup message") { } } - // EXI stream: 80980214b22ca1afff8d8b51e020451114a9413960a914c4c8ccd0d4a8c412d71bd3c0c0 + // EXI stream: 809a0211d63f74d2297ac911e0201526a2698d8017da353360c0 // XML: // // - // 52C8B286BFFE362D + // 4758FDD348A5EB24 // // // // OK_NewSessionEstablished - // DE*PNX*E12345*1 - // 1675074582 + // 49A89A6360 + // 1667918014 // // // - // 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{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{'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(stream, stream + exi_bitstream_get_length(&exi_stream_in) + 1); - // - // const auto expected_exi_stream = std::vector(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(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{0x52, 0xC8, 0xB2, 0x86, 0xBF, 0xFE, 0x36, 0x2D}; - // const auto session_id = - // std::vector(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(std::begin(session_setup_res.EVSEID.bytes), - // std::end(session_setup_res.EVSEID.bytes)); - // REQUIRE(evse_id == - // std::vector({'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{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{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{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(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(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(std::begin(session_setup_res.EVSEID.bytes), + std::begin(session_setup_res.EVSEID.bytes) + session_setup_res.EVSEID.bytesLen); + REQUIRE(evse_id == std::vector({0x49, 0xA8, 0x9A, 0x63, 0x60})); + + // check the EVSE timestamp + REQUIRE(session_setup_res.DateTimeNow_isUsed == true); + REQUIRE(session_setup_res.DateTimeNow == 1667918014); + } + } }