|
| 1 | +#include <gmock/gmock.h> |
| 2 | +#include <gtest/gtest.h> |
| 3 | + |
| 4 | +#include <exi_v2gtp.h> |
| 5 | +#include <iso20_CommonMessages_Decoder.h> |
| 6 | +#include <iso20_CommonMessages_Encoder.h> |
| 7 | + |
| 8 | +#include "../test_header_utils.hpp" |
| 9 | + |
| 10 | +class Test_SessionSetup : public testing::Test { |
| 11 | +protected: |
| 12 | + uint8_t data[256] = {0}; |
| 13 | + exi_bitstream_t stream; |
| 14 | +}; |
| 15 | + |
| 16 | +/** \param xml_input (that was used to generate the EXI binary using EXIficient) |
| 17 | + * <?xml version="1.0" encoding="UTF-8"?> |
| 18 | + * <ns0:SessionSetupReq xmlns:ns0="urn:iso:std:iso:15118:-20:CommonMessages"> |
| 19 | + * <ns1:Header xmlns:ns1="urn:iso:std:iso:15118:-20:CommonTypes"> |
| 20 | + * <ns1:SessionID>3030303030303030</ns1:SessionID> |
| 21 | + * <ns1:TimeStamp>1707896956850052</ns1:TimeStamp> |
| 22 | + * </ns1:Header> |
| 23 | + * <ns0:EVCCID>PIXV12345678901231</ns0:EVCCID> |
| 24 | + * </ns0:SessionSetupReq> |
| 25 | + */ |
| 26 | +TEST_F(Test_SessionSetup, WhenEncodingKnownSessionSetupRequest_ThenResultMatchesExpected) { |
| 27 | + static constexpr uint8_t expected[] = |
| 28 | + "\x01\xFE\x80\x02\x00\x00\x00\x28" //<- header |
| 29 | + "\x80\x8c\x04\x18\x18\x18\x18\x18\x18\x18\x18\x08\x49\xfb\x4f\xba\xba\xa8\x40\x32\x0a\x28\x24\xac\x2b\x18\x99" |
| 30 | + "\x19\x9a\x1a\x9b\x1b\x9c\x1c\x98\x18\x99\x19\x98\x80"; |
| 31 | + static constexpr size_t streamLen = 0x28; |
| 32 | + exi_bitstream_init(&stream, data, sizeof(data), 8, NULL); |
| 33 | + iso20_exiDocument exiDoc = {}; |
| 34 | + exiDoc.SessionSetupReq_isUsed = 1; |
| 35 | + uint8_t sessionID[] = "\x30\x30\x30\x30\x30\x30\x30\x30"; |
| 36 | + setHeader(exiDoc.SessionSetupReq.Header, sessionID, 1707896956850052); |
| 37 | + setString(exiDoc.SessionSetupReq.EVCCID, "PIXV12345678901231"); |
| 38 | + |
| 39 | + int res = encode_iso20_exiDocument(&stream, &exiDoc); |
| 40 | + size_t len = exi_bitstream_get_length(&stream); |
| 41 | + V2GTP20_WriteHeader(&data[0], len, V2GTP20_MAINSTREAM_PAYLOAD_ID); |
| 42 | + |
| 43 | + ASSERT_EQ(res, 0); |
| 44 | + ASSERT_EQ(len, streamLen); |
| 45 | + ASSERT_EQ(memcmp(data, expected, sizeof(expected) - 1), 0) |
| 46 | + << std::string("\\x") << toHexStr(data, data + sizeof(expected) - 1, "\\x") << '\n' |
| 47 | + << std::string("\\x") << toHexStr(&expected[0], &expected[0] + sizeof(expected) - 1, "\\x"); |
| 48 | +} |
| 49 | + |
| 50 | +TEST_F(Test_SessionSetup, WhenDecodingKnownSessionSetupRequest_ThenResultMatchesExpected) { |
| 51 | + uint8_t input[] = |
| 52 | + "\x01\xFE\x80\x02\x00\x00\x00\x28" //<- header |
| 53 | + "\x80\x8c\x04\x18\x18\x18\x18\x18\x18\x18\x18\x08\x49\xfb\x4f\xba\xba\xa8\x40\x32\x0a\x28\x24\xac\x2b\x18\x99" |
| 54 | + "\x19\x9a\x1a\x9b\x1b\x9c\x1c\x98\x18\x99\x19\x98\x80"; |
| 55 | + iso20_exiDocument exiDoc = {}; |
| 56 | + exi_bitstream_init(&stream, &input[0], sizeof(input), 8, NULL); |
| 57 | + uint32_t len = 0; |
| 58 | + |
| 59 | + int res = V2GTP20_ReadHeader(&input[0], &len, V2GTP20_MAINSTREAM_PAYLOAD_ID); |
| 60 | + ASSERT_EQ(res, 0); |
| 61 | + res = decode_iso20_exiDocument(&stream, &exiDoc); |
| 62 | + ASSERT_EQ(res, 0); |
| 63 | + |
| 64 | + static constexpr size_t streamLen = 0x28; |
| 65 | + ASSERT_EQ(len, streamLen); |
| 66 | + ASSERT_EQ((int)exiDoc.SessionSetupReq_isUsed, 1); |
| 67 | + static const uint8_t sessionID[] = "\x30\x30\x30\x30\x30\x30\x30\x30"; |
| 68 | + ASSERT_ISO20_HEADER_EQ(exiDoc.SessionSetupReq.Header, sessionID, 1707896956850052); |
| 69 | + ASSERT_ISO20_STREQ(exiDoc.SessionSetupReq.EVCCID, "PIXV12345678901231"); |
| 70 | +} |
0 commit comments