Add extracted tools: CitrineOS, OpenOCPP, ShapeShifter
- CitrineOS core extracted (CSMS OCPP 2.0.1) - OpenOCPP extracted (firmware OCPP 1.6J/2.0.1) - ShapeShifter library installed (pip install -e) - ShapeShifter specification extracted - EVerest extracted TODO updated with progress
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
add_library(test_utilities OBJECT codec.cpp)
|
||||
target_link_libraries(test_utilities
|
||||
PUBLIC
|
||||
cbv2g::din
|
||||
cbv2g::iso2
|
||||
cbv2g::iso20
|
||||
)
|
||||
|
||||
target_include_directories(test_utilities
|
||||
PUBLIC
|
||||
include
|
||||
)
|
||||
|
||||
function(add_codec_test CPP_FILE)
|
||||
set(TEST_TARGET_NAME test_${CPP_FILE})
|
||||
add_executable(${TEST_TARGET_NAME} ${CPP_FILE}.cpp)
|
||||
|
||||
target_link_libraries(${TEST_TARGET_NAME}
|
||||
PRIVATE
|
||||
test_utilities
|
||||
Catch2::Catch2WithMain
|
||||
)
|
||||
|
||||
catch_discover_tests(${TEST_TARGET_NAME})
|
||||
endfunction()
|
||||
102
tools/EVerest-main/lib/everest/cbv2g/tests/test_utils/codec.cpp
Normal file
102
tools/EVerest-main/lib/everest/cbv2g/tests/test_utils/codec.cpp
Normal file
@@ -0,0 +1,102 @@
|
||||
#include "test_utils/codec.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <cbv2g/app_handshake/appHand_Decoder.h>
|
||||
#include <cbv2g/app_handshake/appHand_Encoder.h>
|
||||
|
||||
#include <cbv2g/din/din_msgDefDecoder.h>
|
||||
#include <cbv2g/din/din_msgDefEncoder.h>
|
||||
|
||||
#include <cbv2g/iso_20/iso20_AC_Decoder.h>
|
||||
#include <cbv2g/iso_20/iso20_AC_Encoder.h>
|
||||
#include <cbv2g/iso_20/iso20_DC_Decoder.h>
|
||||
#include <cbv2g/iso_20/iso20_DC_Encoder.h>
|
||||
|
||||
namespace test_utils {
|
||||
|
||||
template <typename DocType>
|
||||
static EncodingResult encode(int (*encode_func)(exi_bitstream_t*, DocType*), const DocType& request,
|
||||
const uint8_t* compare_data, std::size_t length) {
|
||||
// FIXME (aw): what general size to take here?
|
||||
uint8_t stream[256] = {};
|
||||
exi_bitstream_t exi_stream_in;
|
||||
size_t pos1 = 0;
|
||||
|
||||
exi_bitstream_init(&exi_stream_in, stream, sizeof(stream), pos1, nullptr);
|
||||
|
||||
if (0 != encode_func(&exi_stream_in, const_cast<DocType*>(&request))) {
|
||||
return {false, false};
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
return {true, encoded_stream == expected_exi_stream};
|
||||
}
|
||||
|
||||
template <typename DocType>
|
||||
DecodingResult<DocType> decode(int (*decode_func)(exi_bitstream_t*, DocType*), const uint8_t* raw_data,
|
||||
std::size_t length) {
|
||||
exi_bitstream_t exi_stream_in;
|
||||
size_t pos1 = 0;
|
||||
|
||||
exi_bitstream_init(&exi_stream_in, const_cast<uint8_t*>(raw_data), length, pos1, nullptr);
|
||||
|
||||
DecodingResult<DocType> result;
|
||||
result.decoding_successful = (decode_func(&exi_stream_in, &result.value) == 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// app handshake
|
||||
//
|
||||
template <>
|
||||
EncodingResult encode_and_compare(const appHand_exiDocument& request, const uint8_t* compare_data, std::size_t length) {
|
||||
return encode(&encode_appHand_exiDocument, request, compare_data, length);
|
||||
}
|
||||
|
||||
template <> DecodingResult<appHand_exiDocument> decode(const uint8_t* raw_data, std::size_t length) {
|
||||
return decode(&decode_appHand_exiDocument, raw_data, length);
|
||||
}
|
||||
|
||||
//
|
||||
// din
|
||||
//
|
||||
template <>
|
||||
EncodingResult encode_and_compare(const din_exiDocument& request, const uint8_t* compare_data, std::size_t length) {
|
||||
return encode(&encode_din_exiDocument, request, compare_data, length);
|
||||
}
|
||||
|
||||
template <> DecodingResult<din_exiDocument> decode(const uint8_t* raw_data, std::size_t length) {
|
||||
return decode(&decode_din_exiDocument, raw_data, length);
|
||||
}
|
||||
|
||||
//
|
||||
// iso20 ac
|
||||
//
|
||||
template <>
|
||||
EncodingResult encode_and_compare(const iso20_ac_exiDocument& request, const uint8_t* compare_data,
|
||||
std::size_t length) {
|
||||
return encode(&encode_iso20_ac_exiDocument, request, compare_data, length);
|
||||
}
|
||||
|
||||
template <> DecodingResult<iso20_ac_exiDocument> decode(const uint8_t* raw_data, std::size_t length) {
|
||||
return decode(&decode_iso20_ac_exiDocument, raw_data, length);
|
||||
}
|
||||
|
||||
//
|
||||
// iso20 dc
|
||||
//
|
||||
template <>
|
||||
EncodingResult encode_and_compare(const iso20_dc_exiDocument& request, const uint8_t* compare_data,
|
||||
std::size_t length) {
|
||||
return encode(&encode_iso20_dc_exiDocument, request, compare_data, length);
|
||||
}
|
||||
|
||||
template <> DecodingResult<iso20_dc_exiDocument> decode(const uint8_t* raw_data, std::size_t length) {
|
||||
return decode(&decode_iso20_dc_exiDocument, raw_data, length);
|
||||
}
|
||||
|
||||
} // namespace test_utils
|
||||
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
namespace test_utils {
|
||||
|
||||
struct EncodingResult {
|
||||
bool encoding_successful;
|
||||
bool bitstream_match;
|
||||
};
|
||||
|
||||
template <typename DocType>
|
||||
EncodingResult encode_and_compare(const DocType&, const uint8_t* compare_data, std::size_t length);
|
||||
|
||||
template <typename DocType> struct DecodingResult {
|
||||
bool decoding_successful;
|
||||
DocType value;
|
||||
};
|
||||
|
||||
template <typename DocType> DecodingResult<DocType> decode(const uint8_t* raw_data, std::size_t length);
|
||||
|
||||
} // namespace test_utils
|
||||
Reference in New Issue
Block a user