separate unittest folder
This commit is contained in:
5
unittests/serialize/CMakeLists.txt
Normal file
5
unittests/serialize/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
||||
target_sources(${FSFW_TEST_TGT} PRIVATE
|
||||
TestSerialBufferAdapter.cpp
|
||||
TestSerialization.cpp
|
||||
TestSerialLinkedPacket.cpp
|
||||
)
|
134
unittests/serialize/TestSerialBufferAdapter.cpp
Normal file
134
unittests/serialize/TestSerialBufferAdapter.cpp
Normal file
@ -0,0 +1,134 @@
|
||||
#include <fsfw/serialize/SerialBufferAdapter.h>
|
||||
|
||||
#include <array>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "fsfw_tests/unit/CatchDefinitions.h"
|
||||
|
||||
static bool test_value_bool = true;
|
||||
static uint16_t tv_uint16{283};
|
||||
static std::array<uint8_t, 512> testArray;
|
||||
|
||||
TEST_CASE("Serial Buffer Adapter", "[single-file]") {
|
||||
size_t serialized_size = 0;
|
||||
test_value_bool = true;
|
||||
uint8_t* arrayPtr = testArray.data();
|
||||
std::array<uint8_t, 5> test_serial_buffer{5, 4, 3, 2, 1};
|
||||
SerialBufferAdapter<uint8_t> tv_serial_buffer_adapter =
|
||||
SerialBufferAdapter<uint8_t>(test_serial_buffer.data(), test_serial_buffer.size(), false);
|
||||
tv_uint16 = 16;
|
||||
|
||||
SECTION("Serialize without size field") {
|
||||
SerializeAdapter::serialize(&test_value_bool, &arrayPtr, &serialized_size, testArray.size(),
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tv_serial_buffer_adapter, &arrayPtr, &serialized_size,
|
||||
testArray.size(), SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tv_uint16, &arrayPtr, &serialized_size, testArray.size(),
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
|
||||
REQUIRE(serialized_size == 8);
|
||||
REQUIRE(testArray[0] == true);
|
||||
REQUIRE(testArray[1] == 5);
|
||||
REQUIRE(testArray[2] == 4);
|
||||
REQUIRE(testArray[3] == 3);
|
||||
REQUIRE(testArray[4] == 2);
|
||||
REQUIRE(testArray[5] == 1);
|
||||
memcpy(&tv_uint16, testArray.data() + 6, sizeof(tv_uint16));
|
||||
REQUIRE(tv_uint16 == 16);
|
||||
}
|
||||
|
||||
SECTION("Serialize with size field") {
|
||||
SerialBufferAdapter<uint8_t> tv_serial_buffer_adapter_loc =
|
||||
SerialBufferAdapter<uint8_t>(test_serial_buffer.data(), test_serial_buffer.size(), true);
|
||||
serialized_size = 0;
|
||||
arrayPtr = testArray.data();
|
||||
SerializeAdapter::serialize(&test_value_bool, &arrayPtr, &serialized_size, testArray.size(),
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tv_serial_buffer_adapter_loc, &arrayPtr, &serialized_size,
|
||||
testArray.size(), SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tv_uint16, &arrayPtr, &serialized_size, testArray.size(),
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
|
||||
REQUIRE(serialized_size == 9);
|
||||
REQUIRE(testArray[0] == true);
|
||||
REQUIRE(testArray[1] == 5);
|
||||
REQUIRE(testArray[2] == 5);
|
||||
REQUIRE(testArray[3] == 4);
|
||||
REQUIRE(testArray[4] == 3);
|
||||
REQUIRE(testArray[5] == 2);
|
||||
REQUIRE(testArray[6] == 1);
|
||||
memcpy(&tv_uint16, testArray.data() + 7, sizeof(tv_uint16));
|
||||
REQUIRE(tv_uint16 == 16);
|
||||
}
|
||||
|
||||
SECTION("Test set buffer function") {
|
||||
SerialBufferAdapter<uint8_t> tv_serial_buffer_adapter_loc =
|
||||
SerialBufferAdapter<uint8_t>((uint8_t*)nullptr, 0, true);
|
||||
tv_serial_buffer_adapter_loc.setBuffer(test_serial_buffer.data(), test_serial_buffer.size());
|
||||
serialized_size = 0;
|
||||
arrayPtr = testArray.data();
|
||||
SerializeAdapter::serialize(&test_value_bool, &arrayPtr, &serialized_size, testArray.size(),
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tv_serial_buffer_adapter_loc, &arrayPtr, &serialized_size,
|
||||
testArray.size(), SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tv_uint16, &arrayPtr, &serialized_size, testArray.size(),
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
REQUIRE(serialized_size == 9);
|
||||
REQUIRE(testArray[0] == true);
|
||||
REQUIRE(testArray[1] == 5);
|
||||
REQUIRE(testArray[2] == 5);
|
||||
REQUIRE(testArray[3] == 4);
|
||||
REQUIRE(testArray[4] == 3);
|
||||
REQUIRE(testArray[5] == 2);
|
||||
REQUIRE(testArray[6] == 1);
|
||||
memcpy(&tv_uint16, testArray.data() + 7, sizeof(tv_uint16));
|
||||
REQUIRE(tv_uint16 == 16);
|
||||
}
|
||||
|
||||
SECTION("Deserialization with size field") {
|
||||
size_t buffer_size = 4;
|
||||
memcpy(testArray.data(), &buffer_size, sizeof(uint16_t));
|
||||
testArray[2] = 1;
|
||||
testArray[3] = 1;
|
||||
testArray[4] = 1;
|
||||
testArray[5] = 0;
|
||||
std::array<uint8_t, 4> test_recv_array;
|
||||
arrayPtr = testArray.data();
|
||||
// copy testArray[1] to testArray[4] into receive buffer, skip
|
||||
// size field (testArray[0]) for deSerialization.
|
||||
SerialBufferAdapter<uint16_t> tv_serial_buffer_adapter3 =
|
||||
SerialBufferAdapter<uint16_t>(test_recv_array.data(), 4, true);
|
||||
// Deserialization
|
||||
size_t size = 6;
|
||||
auto result = tv_serial_buffer_adapter3.deSerialize(const_cast<const uint8_t**>(&arrayPtr),
|
||||
&size, SerializeIF::Endianness::MACHINE);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
CHECK(test_recv_array[0] == 1);
|
||||
CHECK(test_recv_array[1] == 1);
|
||||
CHECK(test_recv_array[2] == 1);
|
||||
CHECK(test_recv_array[3] == 0);
|
||||
}
|
||||
|
||||
SECTION("Deserialization without size field") {
|
||||
size_t buffer_size = 4;
|
||||
memcpy(testArray.data(), &buffer_size, sizeof(uint16_t));
|
||||
testArray[2] = 1;
|
||||
testArray[3] = 1;
|
||||
testArray[4] = 1;
|
||||
testArray[5] = 0;
|
||||
std::array<uint8_t, 4> test_recv_array;
|
||||
arrayPtr = testArray.data() + 2;
|
||||
// copy testArray[1] to testArray[4] into receive buffer, skip
|
||||
// size field (testArray[0])
|
||||
SerialBufferAdapter<uint16_t> tv_serial_buffer_adapter3 =
|
||||
SerialBufferAdapter<uint16_t>(test_recv_array.data(), 4, false);
|
||||
// Deserialization
|
||||
size_t size = 4;
|
||||
tv_serial_buffer_adapter3.deSerialize(const_cast<const uint8_t**>(&arrayPtr), &size,
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
CHECK(test_recv_array[0] == 1);
|
||||
CHECK(test_recv_array[1] == 1);
|
||||
CHECK(test_recv_array[2] == 1);
|
||||
CHECK(test_recv_array[3] == 0);
|
||||
}
|
||||
}
|
73
unittests/serialize/TestSerialLinkedPacket.cpp
Normal file
73
unittests/serialize/TestSerialLinkedPacket.cpp
Normal file
@ -0,0 +1,73 @@
|
||||
#include "TestSerialLinkedPacket.h"
|
||||
|
||||
#include <fsfw/globalfunctions/arrayprinter.h>
|
||||
|
||||
#include <array>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "fsfw_tests/unit/CatchDefinitions.h"
|
||||
|
||||
TEST_CASE("Serial Linked Packet", "[SerLinkPacket]") {
|
||||
// perform set-up here
|
||||
uint32_t header = 42;
|
||||
std::array<uint8_t, 3> testArray{1, 2, 3};
|
||||
uint32_t tail = 96;
|
||||
size_t packetMaxSize = 256;
|
||||
uint8_t packet[packetMaxSize] = {};
|
||||
size_t packetLen = 0;
|
||||
|
||||
SECTION("Test Deserialization with Serial Buffer Adapter.") {
|
||||
// This is a serialization of a packet, made "manually".
|
||||
// We generate a packet which store data big-endian by swapping some
|
||||
// values. (like coming from ground).
|
||||
header = EndianConverter::convertBigEndian(header);
|
||||
std::memcpy(packet, &header, sizeof(header));
|
||||
packetLen += sizeof(header);
|
||||
|
||||
std::copy(testArray.data(), testArray.data() + testArray.size(), packet + packetLen);
|
||||
packetLen += testArray.size();
|
||||
|
||||
tail = EndianConverter::convertBigEndian(tail);
|
||||
std::memcpy(packet + packetLen, &tail, sizeof(tail));
|
||||
packetLen += sizeof(tail);
|
||||
|
||||
// arrayprinter::print(packet, packetLen, OutputType::DEC);
|
||||
|
||||
// This is the buffer which will be filled when testClass.deSerialize
|
||||
// is called.
|
||||
std::array<uint8_t, 3> bufferAdaptee = {};
|
||||
TestPacket testClass(packet, packetLen, bufferAdaptee.data(), bufferAdaptee.size());
|
||||
const uint8_t* readOnlyPointer = packet;
|
||||
// Deserialize big endian packet by setting bigEndian to true.
|
||||
ReturnValue_t result =
|
||||
testClass.deSerialize(&readOnlyPointer, &packetLen, SerializeIF::Endianness::BIG);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
CHECK(testClass.getHeader() == 42);
|
||||
// Equivalent check.
|
||||
// CHECK(testClass.getBuffer()[0] == 1);
|
||||
CHECK(bufferAdaptee[0] == 1);
|
||||
CHECK(bufferAdaptee[1] == 2);
|
||||
CHECK(bufferAdaptee[2] == 3);
|
||||
CHECK(testClass.getTail() == 96);
|
||||
}
|
||||
|
||||
SECTION("Test Serialization") {
|
||||
// Same process as performed in setup, this time using the class
|
||||
// instead of doing it manually.
|
||||
TestPacket testClass(header, tail, testArray.data(), testArray.size());
|
||||
size_t serializedSize = 0;
|
||||
uint8_t* packetPointer = packet;
|
||||
// serialize for ground: bigEndian = true.
|
||||
ReturnValue_t result = testClass.serialize(&packetPointer, &serializedSize, packetMaxSize,
|
||||
SerializeIF::Endianness::BIG);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
// Result should be big endian now.
|
||||
CHECK(packet[3] == 42);
|
||||
CHECK(packet[4] == 1);
|
||||
CHECK(packet[5] == 2);
|
||||
CHECK(packet[6] == 3);
|
||||
CHECK(packet[10] == 96);
|
||||
}
|
||||
|
||||
// perform tear-down here
|
||||
}
|
50
unittests/serialize/TestSerialLinkedPacket.h
Normal file
50
unittests/serialize/TestSerialLinkedPacket.h
Normal file
@ -0,0 +1,50 @@
|
||||
#ifndef UNITTEST_HOSTED_TESTSERIALLINKEDPACKET_H_
|
||||
#define UNITTEST_HOSTED_TESTSERIALLINKEDPACKET_H_
|
||||
|
||||
#include <fsfw/objectmanager/SystemObjectIF.h>
|
||||
#include <fsfw/parameters/HasParametersIF.h>
|
||||
#include <fsfw/serialize/SerialBufferAdapter.h>
|
||||
#include <fsfw/serialize/SerialLinkedListAdapter.h>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
class TestPacket : public SerialLinkedListAdapter<SerializeIF> {
|
||||
public:
|
||||
/**
|
||||
* For Deserialization
|
||||
*/
|
||||
TestPacket(const uint8_t* somePacket, size_t size, uint8_t* storePointer, size_t storeSize)
|
||||
: buffer(storePointer, storeSize) {
|
||||
setLinks();
|
||||
}
|
||||
|
||||
/**
|
||||
* For Serialization
|
||||
*/
|
||||
TestPacket(uint32_t header, uint32_t tail, const uint8_t* parameters, size_t paramSize)
|
||||
: header(header), buffer(parameters, paramSize), tail(tail) {
|
||||
setLinks();
|
||||
}
|
||||
|
||||
uint32_t getHeader() const { return header.entry; }
|
||||
|
||||
const uint8_t* getBuffer() { return buffer.entry.getConstBuffer(); }
|
||||
|
||||
size_t getBufferLength() { return buffer.getSerializedSize(); }
|
||||
|
||||
uint16_t getTail() const { return tail.entry; }
|
||||
|
||||
private:
|
||||
void setLinks() {
|
||||
setStart(&header);
|
||||
header.setNext(&buffer);
|
||||
buffer.setNext(&tail);
|
||||
tail.setEnd();
|
||||
}
|
||||
|
||||
SerializeElement<uint32_t> header = 0;
|
||||
SerializeElement<SerialBufferAdapter<uint8_t>> buffer;
|
||||
SerializeElement<uint32_t> tail = 0;
|
||||
};
|
||||
|
||||
#endif /* UNITTEST_TESTFW_NEWTESTS_TESTTEMPLATE_H_ */
|
202
unittests/serialize/TestSerialization.cpp
Normal file
202
unittests/serialize/TestSerialization.cpp
Normal file
@ -0,0 +1,202 @@
|
||||
#include <fsfw/serialize/SerialBufferAdapter.h>
|
||||
#include <fsfw/serialize/SerializeAdapter.h>
|
||||
|
||||
#include <array>
|
||||
#include <catch2/catch_approx.hpp>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "fsfw_tests/unit/CatchDefinitions.h"
|
||||
|
||||
static bool testBool = true;
|
||||
static uint8_t tvUint8{5};
|
||||
static uint16_t tvUint16{283};
|
||||
static uint32_t tvUint32{929221};
|
||||
static uint64_t tvUint64{2929329429};
|
||||
|
||||
static int8_t tvInt8{-16};
|
||||
static int16_t tvInt16{-829};
|
||||
static int32_t tvInt32{-2312};
|
||||
|
||||
static float tvFloat{8.2149214};
|
||||
static float tvSfloat = {-922.2321321};
|
||||
static double tvDouble{9.2132142141e8};
|
||||
static double tvSdouble{-2.2421e19};
|
||||
|
||||
static std::array<uint8_t, 512> TEST_ARRAY;
|
||||
|
||||
TEST_CASE("Serialization size tests", "[SerSizeTest]") {
|
||||
// REQUIRE(unitTestClass.test_autoserialization() == 0);
|
||||
REQUIRE(SerializeAdapter::getSerializedSize(&testBool) == sizeof(testBool));
|
||||
REQUIRE(SerializeAdapter::getSerializedSize(&tvUint8) == sizeof(tvUint8));
|
||||
REQUIRE(SerializeAdapter::getSerializedSize(&tvUint16) == sizeof(tvUint16));
|
||||
REQUIRE(SerializeAdapter::getSerializedSize(&tvUint32) == sizeof(tvUint32));
|
||||
REQUIRE(SerializeAdapter::getSerializedSize(&tvUint64) == sizeof(tvUint64));
|
||||
REQUIRE(SerializeAdapter::getSerializedSize(&tvInt8) == sizeof(tvInt8));
|
||||
REQUIRE(SerializeAdapter::getSerializedSize(&tvInt16) == sizeof(tvInt16));
|
||||
REQUIRE(SerializeAdapter::getSerializedSize(&tvInt32) == sizeof(tvInt32));
|
||||
REQUIRE(SerializeAdapter::getSerializedSize(&tvFloat) == sizeof(tvFloat));
|
||||
REQUIRE(SerializeAdapter::getSerializedSize(&tvSfloat) == sizeof(tvSfloat));
|
||||
REQUIRE(SerializeAdapter::getSerializedSize(&tvDouble) == sizeof(tvDouble));
|
||||
REQUIRE(SerializeAdapter::getSerializedSize(&tvSdouble) == sizeof(tvSdouble));
|
||||
}
|
||||
|
||||
TEST_CASE("Auto Serialize Adapter", "[SerAdapter]") {
|
||||
size_t serializedSize = 0;
|
||||
uint8_t* pArray = TEST_ARRAY.data();
|
||||
|
||||
SECTION("SerDe") {
|
||||
size_t deserSize = 0;
|
||||
SerializeAdapter::serialize(&testBool, TEST_ARRAY.data(), &deserSize, TEST_ARRAY.size(),
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
REQUIRE(deserSize == 1);
|
||||
REQUIRE(TEST_ARRAY[0] == true);
|
||||
bool readBack = false;
|
||||
SerializeAdapter::deSerialize(&readBack, TEST_ARRAY.data(), &deserSize,
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
REQUIRE(deserSize == 1);
|
||||
REQUIRE(readBack == true);
|
||||
SerializeAdapter::serialize(&tvUint8, TEST_ARRAY.data(), &deserSize, TEST_ARRAY.size(),
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
REQUIRE(deserSize == 1);
|
||||
REQUIRE(TEST_ARRAY[0] == 5);
|
||||
uint8_t readBackUint8 = 0;
|
||||
uint8_t* const testPtr = TEST_ARRAY.data();
|
||||
uint8_t* const shouldStayConst = testPtr;
|
||||
SerializeAdapter::deSerialize(&readBackUint8, testPtr, &deserSize,
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
REQUIRE(testPtr == shouldStayConst);
|
||||
REQUIRE(deserSize == 1);
|
||||
REQUIRE(readBackUint8 == 5);
|
||||
SerializeAdapter::serialize(&tvUint16, TEST_ARRAY.data(), &deserSize, TEST_ARRAY.size(),
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
REQUIRE(deserSize == 2);
|
||||
deserSize = 0;
|
||||
uint16_t readBackUint16 = 0;
|
||||
SerializeAdapter::deSerialize(&readBackUint16, TEST_ARRAY.data(), &deserSize,
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
REQUIRE(deserSize == 2);
|
||||
REQUIRE(readBackUint16 == 283);
|
||||
|
||||
SerializeAdapter::serialize(&tvUint32, TEST_ARRAY.data(), &deserSize, TEST_ARRAY.size(),
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
REQUIRE(deserSize == 4);
|
||||
uint32_t readBackUint32 = 0;
|
||||
deserSize = 0;
|
||||
SerializeAdapter::deSerialize(&readBackUint32, TEST_ARRAY.data(), &deserSize,
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
REQUIRE(deserSize == 4);
|
||||
REQUIRE(readBackUint32 == 929221);
|
||||
|
||||
SerializeAdapter::serialize(&tvInt16, TEST_ARRAY.data(), &deserSize, TEST_ARRAY.size(),
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
REQUIRE(deserSize == 2);
|
||||
int16_t readBackInt16 = 0;
|
||||
SerializeAdapter::deSerialize(&readBackInt16, TEST_ARRAY.data(), &deserSize,
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
REQUIRE(readBackInt16 == -829);
|
||||
REQUIRE(deserSize == 2);
|
||||
|
||||
SerializeAdapter::serialize(&tvFloat, TEST_ARRAY.data(), &deserSize, TEST_ARRAY.size(),
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
float readBackFloat = 0.0;
|
||||
SerializeAdapter::deSerialize(&readBackFloat, TEST_ARRAY.data(), &deserSize,
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
REQUIRE(readBackFloat == Catch::Approx(8.214921));
|
||||
|
||||
SerializeAdapter::serialize(&tvSdouble, TEST_ARRAY.data(), &deserSize, TEST_ARRAY.size(),
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
double readBackSignedDouble = 0.0;
|
||||
SerializeAdapter::deSerialize(&readBackSignedDouble, TEST_ARRAY.data(), &deserSize,
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
REQUIRE(readBackSignedDouble == Catch::Approx(-2.2421e19));
|
||||
|
||||
uint8_t testBuf[4] = {1, 2, 3, 4};
|
||||
SerialBufferAdapter<uint8_t> bufferAdapter(testBuf, sizeof(testBuf));
|
||||
SerializeAdapter::serialize(&bufferAdapter, TEST_ARRAY.data(), &deserSize, TEST_ARRAY.size(),
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
REQUIRE(deserSize == 4);
|
||||
for (uint8_t idx = 0; idx < 4; idx++) {
|
||||
REQUIRE(TEST_ARRAY[idx] == idx + 1);
|
||||
}
|
||||
deserSize = 0;
|
||||
testBuf[0] = 0;
|
||||
testBuf[1] = 12;
|
||||
SerializeAdapter::deSerialize(&bufferAdapter, TEST_ARRAY.data(), &deserSize,
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
REQUIRE(deserSize == 4);
|
||||
for (uint8_t idx = 0; idx < 4; idx++) {
|
||||
REQUIRE(testBuf[idx] == idx + 1);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Serialize incrementing") {
|
||||
SerializeAdapter::serialize(&testBool, &pArray, &serializedSize, TEST_ARRAY.size(),
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tvUint8, &pArray, &serializedSize, TEST_ARRAY.size(),
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tvUint16, &pArray, &serializedSize, TEST_ARRAY.size(),
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tvUint32, &pArray, &serializedSize, TEST_ARRAY.size(),
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tvInt8, &pArray, &serializedSize, TEST_ARRAY.size(),
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tvInt16, &pArray, &serializedSize, TEST_ARRAY.size(),
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tvInt32, &pArray, &serializedSize, TEST_ARRAY.size(),
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tvUint64, &pArray, &serializedSize, TEST_ARRAY.size(),
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tvFloat, &pArray, &serializedSize, TEST_ARRAY.size(),
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tvDouble, &pArray, &serializedSize, TEST_ARRAY.size(),
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tvSfloat, &pArray, &serializedSize, TEST_ARRAY.size(),
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tvSdouble, &pArray, &serializedSize, TEST_ARRAY.size(),
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
REQUIRE(serializedSize == 47);
|
||||
}
|
||||
|
||||
SECTION("Deserialize decrementing") {
|
||||
pArray = TEST_ARRAY.data();
|
||||
size_t remaining_size = serializedSize;
|
||||
SerializeAdapter::deSerialize(&testBool, const_cast<const uint8_t**>(&pArray), &remaining_size,
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::deSerialize(&tvUint8, const_cast<const uint8_t**>(&pArray), &remaining_size,
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::deSerialize(&tvUint16, const_cast<const uint8_t**>(&pArray), &remaining_size,
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::deSerialize(&tvUint32, const_cast<const uint8_t**>(&pArray), &remaining_size,
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::deSerialize(&tvInt8, const_cast<const uint8_t**>(&pArray), &remaining_size,
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::deSerialize(&tvInt16, const_cast<const uint8_t**>(&pArray), &remaining_size,
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::deSerialize(&tvInt32, const_cast<const uint8_t**>(&pArray), &remaining_size,
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::deSerialize(&tvUint64, const_cast<const uint8_t**>(&pArray), &remaining_size,
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::deSerialize(&tvFloat, const_cast<const uint8_t**>(&pArray), &remaining_size,
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::deSerialize(&tvDouble, const_cast<const uint8_t**>(&pArray), &remaining_size,
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::deSerialize(&tvSfloat, const_cast<const uint8_t**>(&pArray), &remaining_size,
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::deSerialize(&tvSdouble, const_cast<const uint8_t**>(&pArray), &remaining_size,
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
|
||||
REQUIRE(testBool == true);
|
||||
REQUIRE(tvUint8 == 5);
|
||||
REQUIRE(tvUint16 == 283);
|
||||
REQUIRE(tvUint32 == 929221);
|
||||
REQUIRE(tvUint64 == 2929329429);
|
||||
REQUIRE(tvInt8 == -16);
|
||||
REQUIRE(tvInt16 == -829);
|
||||
REQUIRE(tvInt32 == -2312);
|
||||
|
||||
REQUIRE(tvFloat == Catch::Approx(8.214921));
|
||||
REQUIRE(tvDouble == Catch::Approx(9.2132142141e8));
|
||||
REQUIRE(tvSfloat == Catch::Approx(-922.2321321));
|
||||
REQUIRE(tvSdouble == Catch::Approx(-2.2421e19));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user