added first DLE unit tests
This commit is contained in:
parent
026f7f00de
commit
57b13731e0
@ -41,7 +41,7 @@ ReturnValue_t DleEncoder::encode(const uint8_t* sourceStream,
|
|||||||
ReturnValue_t DleEncoder::encodeStreamEscaped(const uint8_t *sourceStream, size_t sourceLen,
|
ReturnValue_t DleEncoder::encodeStreamEscaped(const uint8_t *sourceStream, size_t sourceLen,
|
||||||
uint8_t *destStream, size_t maxDestLen, size_t *encodedLen,
|
uint8_t *destStream, size_t maxDestLen, size_t *encodedLen,
|
||||||
bool addStxEtx) {
|
bool addStxEtx) {
|
||||||
size_t encodedIndex = 2;
|
size_t encodedIndex = 1;
|
||||||
size_t sourceIndex = 0;
|
size_t sourceIndex = 0;
|
||||||
uint8_t nextByte = 0;
|
uint8_t nextByte = 0;
|
||||||
while (encodedIndex < maxDestLen and sourceIndex < sourceLen) {
|
while (encodedIndex < maxDestLen and sourceIndex < sourceLen) {
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
target_sources(${TARGET_NAME} PRIVATE
|
target_sources(${TARGET_NAME} PRIVATE
|
||||||
|
testDleEncoder.cpp
|
||||||
)
|
)
|
||||||
|
62
tests/src/fsfw_tests/unit/globalfunctions/testDleEncoder.cpp
Normal file
62
tests/src/fsfw_tests/unit/globalfunctions/testDleEncoder.cpp
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
#include "fsfw/globalfunctions/DleEncoder.h"
|
||||||
|
#include "fsfw_tests/unit/CatchDefinitions.h"
|
||||||
|
#include "catch2/catch_test_macros.hpp"
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
|
||||||
|
const std::array<uint8_t, 5> TEST_ARRAY_0 = { 0 };
|
||||||
|
const std::array<uint8_t, 3> TEST_ARRAY_1 = { 0, DleEncoder::DLE_CHAR, 5};
|
||||||
|
const std::array<uint8_t, 3> TEST_ARRAY_2 = { 0, DleEncoder::STX_CHAR, 5};
|
||||||
|
const std::array<uint8_t, 3> TEST_ARRAY_3 = { 0, DleEncoder::CARRIAGE_RETURN, DleEncoder::ETX_CHAR};
|
||||||
|
|
||||||
|
TEST_CASE("DleEncoder" , "[DleEncoder]") {
|
||||||
|
|
||||||
|
DleEncoder dleEncoder;
|
||||||
|
std::array<uint8_t, 32> buffer;
|
||||||
|
SECTION("Encoding") {
|
||||||
|
size_t encodedLen = 0;
|
||||||
|
ReturnValue_t result = dleEncoder.encode(TEST_ARRAY_0.data(), TEST_ARRAY_0.size(),
|
||||||
|
buffer.data(), buffer.size(), &encodedLen);
|
||||||
|
REQUIRE(result == retval::CATCH_OK);
|
||||||
|
std::vector<uint8_t> expected = {DleEncoder::STX_CHAR, 0, 0, 0, 0, 0,
|
||||||
|
DleEncoder::ETX_CHAR};
|
||||||
|
for(size_t idx = 0; idx < expected.size(); idx++) {
|
||||||
|
REQUIRE(buffer[idx] == expected[idx]);
|
||||||
|
}
|
||||||
|
REQUIRE(encodedLen == 7);
|
||||||
|
|
||||||
|
result = dleEncoder.encode(TEST_ARRAY_1.data(), TEST_ARRAY_1.size(),
|
||||||
|
buffer.data(), buffer.size(), &encodedLen);
|
||||||
|
REQUIRE(result == retval::CATCH_OK);
|
||||||
|
expected = std::vector<uint8_t>{DleEncoder::STX_CHAR, 0, DleEncoder::DLE_CHAR,
|
||||||
|
DleEncoder::DLE_CHAR, 5, DleEncoder::ETX_CHAR};
|
||||||
|
for(size_t idx = 0; idx < expected.size(); idx++) {
|
||||||
|
REQUIRE(buffer[idx] == expected[idx]);
|
||||||
|
}
|
||||||
|
REQUIRE(encodedLen == expected.size());
|
||||||
|
|
||||||
|
result = dleEncoder.encode(TEST_ARRAY_2.data(), TEST_ARRAY_2.size(),
|
||||||
|
buffer.data(), buffer.size(), &encodedLen);
|
||||||
|
REQUIRE(result == retval::CATCH_OK);
|
||||||
|
expected = std::vector<uint8_t>{DleEncoder::STX_CHAR, 0, DleEncoder::DLE_CHAR,
|
||||||
|
DleEncoder::STX_CHAR + 0x40, 5, DleEncoder::ETX_CHAR};
|
||||||
|
for(size_t idx = 0; idx < expected.size(); idx++) {
|
||||||
|
REQUIRE(buffer[idx] == expected[idx]);
|
||||||
|
}
|
||||||
|
REQUIRE(encodedLen == expected.size());
|
||||||
|
|
||||||
|
result = dleEncoder.encode(TEST_ARRAY_3.data(), TEST_ARRAY_3.size(),
|
||||||
|
buffer.data(), buffer.size(), &encodedLen);
|
||||||
|
REQUIRE(result == retval::CATCH_OK);
|
||||||
|
expected = std::vector<uint8_t>{DleEncoder::STX_CHAR, 0, DleEncoder::CARRIAGE_RETURN,
|
||||||
|
DleEncoder::DLE_CHAR, DleEncoder::ETX_CHAR + 0x40, DleEncoder::ETX_CHAR};
|
||||||
|
for(size_t idx = 0; idx < expected.size(); idx++) {
|
||||||
|
REQUIRE(buffer[idx] == expected[idx]);
|
||||||
|
}
|
||||||
|
REQUIRE(encodedLen == expected.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("Decoding") {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user