mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Expanded tests and updated make lists
This commit is contained in:
parent
ed74f8bc54
commit
42d451dc79
@ -50,59 +50,18 @@ namespace etl
|
||||
{
|
||||
namespace private_byte_stream
|
||||
{
|
||||
class byte_stream_base
|
||||
class byte_stream_common
|
||||
{
|
||||
public:
|
||||
|
||||
typedef const char* const_iterator;
|
||||
|
||||
//***************************************************************************
|
||||
/// Sets the index back to the beginning of the stream.
|
||||
/// Sets the index back to the position in the stream. Default = 0.
|
||||
//***************************************************************************
|
||||
void restart()
|
||||
void restart(size_t n = 0U)
|
||||
{
|
||||
pcurrent = const_cast<char*>(pdata);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Returns <b>true</b> if the byte stream index has reached the end.
|
||||
//***************************************************************************
|
||||
bool full() const
|
||||
{
|
||||
return size() == capacity();
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Returns <b>true</b> if the byte stream is empty.
|
||||
//***************************************************************************
|
||||
bool empty() const
|
||||
{
|
||||
return size() == 0U;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Returns the number of bytes used in the stream.
|
||||
//***************************************************************************
|
||||
size_t size() const
|
||||
{
|
||||
return etl::distance(pdata, static_cast<char* const>(pcurrent));
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Returns the maximum number of bytes in the stream.
|
||||
//***************************************************************************
|
||||
size_t capacity() const
|
||||
{
|
||||
return length;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// The number of T left in the stream.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
size_t available() const
|
||||
{
|
||||
return (capacity() - size()) / sizeof(T);
|
||||
pcurrent = const_cast<char*>(pdata + n);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
@ -123,7 +82,7 @@ namespace etl
|
||||
|
||||
protected:
|
||||
|
||||
byte_stream_base(char* pdata_, size_t length_, etl::endian buffer_endianness_)
|
||||
byte_stream_common(char* pdata_, size_t length_, etl::endian buffer_endianness_)
|
||||
: pdata(pdata_)
|
||||
, pcurrent(pdata_)
|
||||
, length(length_)
|
||||
@ -155,7 +114,7 @@ namespace etl
|
||||
//***************************************************************************
|
||||
/// Encodes a byte stream.
|
||||
//***************************************************************************
|
||||
class byte_stream_writer : public private_byte_stream::byte_stream_base
|
||||
class byte_stream_writer : public private_byte_stream::byte_stream_common
|
||||
{
|
||||
public:
|
||||
|
||||
@ -163,7 +122,7 @@ namespace etl
|
||||
/// Construct from range.
|
||||
//***************************************************************************
|
||||
byte_stream_writer(char* begin_, char* end_, etl::endian buffer_endianness_ = etl::endian::big)
|
||||
: byte_stream_base(begin_, etl::distance(begin_, end_), buffer_endianness_)
|
||||
: byte_stream_common(begin_, etl::distance(begin_, end_), buffer_endianness_)
|
||||
{
|
||||
}
|
||||
|
||||
@ -171,7 +130,7 @@ namespace etl
|
||||
/// Construct from begin and length.
|
||||
//***************************************************************************
|
||||
byte_stream_writer(char* begin_, size_t length_, etl::endian buffer_endianness_ = etl::endian::big)
|
||||
: byte_stream_base(begin_, length_, buffer_endianness_)
|
||||
: byte_stream_common(begin_, length_, buffer_endianness_)
|
||||
{
|
||||
}
|
||||
|
||||
@ -210,19 +169,17 @@ namespace etl
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Write a range of value to the stream.
|
||||
/// Write a byte range to the stream.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, bool>::type
|
||||
typename etl::enable_if<sizeof(T) == 1U, bool>::type
|
||||
write(const etl::span<T>& range)
|
||||
{
|
||||
bool success = false;
|
||||
|
||||
size_t span_length = range.size();
|
||||
|
||||
if (available<T>() >= span_length)
|
||||
if (available<T>() >= range.size())
|
||||
{
|
||||
etl::span<int8_t>::const_iterator itr = range.begin();
|
||||
typename etl::span<T>::const_iterator itr = range.begin();
|
||||
|
||||
while (itr != range.end())
|
||||
{
|
||||
@ -235,6 +192,47 @@ namespace etl
|
||||
return success;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Returns <b>true</b> if the byte stream index has reached the end.
|
||||
//***************************************************************************
|
||||
bool full() const
|
||||
{
|
||||
return size_bytes() == capacity();
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Returns <b>true</b> if the byte stream is empty.
|
||||
//***************************************************************************
|
||||
bool empty() const
|
||||
{
|
||||
return size_bytes() == 0U;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Returns the number of bytes used in the stream.
|
||||
//***************************************************************************
|
||||
size_t size_bytes() const
|
||||
{
|
||||
return etl::distance(pdata, static_cast<char* const>(pcurrent));
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Returns the maximum number of bytes in the stream.
|
||||
//***************************************************************************
|
||||
size_t capacity() const
|
||||
{
|
||||
return length;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// The number of T left in the stream.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
size_t available() const
|
||||
{
|
||||
return (capacity() - size_bytes()) / sizeof(T);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
//***************************************************************************
|
||||
@ -262,7 +260,7 @@ namespace etl
|
||||
/// Decodes byte streams.
|
||||
/// Data must be stored in the stream in network order.
|
||||
//***************************************************************************
|
||||
class byte_stream_reader : public private_byte_stream::byte_stream_base
|
||||
class byte_stream_reader : public private_byte_stream::byte_stream_common
|
||||
{
|
||||
public:
|
||||
|
||||
@ -270,7 +268,7 @@ namespace etl
|
||||
/// Construct from range.
|
||||
//***************************************************************************
|
||||
byte_stream_reader(char* begin_, char* end_, etl::endian buffer_endianness_ = etl::endian::big)
|
||||
: byte_stream_base(begin_, etl::distance(begin_, end_), buffer_endianness_)
|
||||
: byte_stream_common(begin_, etl::distance(begin_, end_), buffer_endianness_)
|
||||
{
|
||||
}
|
||||
|
||||
@ -278,7 +276,7 @@ namespace etl
|
||||
/// Construct from begin and length.
|
||||
//***************************************************************************
|
||||
byte_stream_reader(char* begin_, size_t length_, etl::endian buffer_endianness_ = etl::endian::big)
|
||||
: byte_stream_base(begin_, length_, buffer_endianness_)
|
||||
: byte_stream_common(begin_, length_, buffer_endianness_)
|
||||
{
|
||||
}
|
||||
|
||||
@ -286,7 +284,7 @@ namespace etl
|
||||
/// Read a value from the stream.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, etl::optional<T>>::type
|
||||
typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, etl::optional<T> >::type
|
||||
read()
|
||||
{
|
||||
etl::optional<T> result;
|
||||
@ -301,28 +299,51 @@ namespace etl
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Read a range from the stream.
|
||||
/// Read a byte range from the stream.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, etl::span<T>>::type
|
||||
read(size_t length)
|
||||
typename etl::enable_if<sizeof(T) == 1U, etl::span<T> >::type
|
||||
read(size_t required_length)
|
||||
{
|
||||
etl::span<T> result;
|
||||
|
||||
const size_t buffer_length = length * sizeof(T);
|
||||
|
||||
// Do we have enough room?
|
||||
if (available<T>() >= buffer_length)
|
||||
if (available<T>() >= required_length)
|
||||
{
|
||||
const char* pend = pcurrent + buffer_length;
|
||||
char* pend = pcurrent + (required_length * sizeof(T));
|
||||
|
||||
result = etl::span<T>(reinterpret_cast<const T*>(pcurrent), reinterpret_cast<const T*>(pend));
|
||||
pcurrent += buffer_length;
|
||||
result = etl::span<T>(reinterpret_cast<T*>(pcurrent), reinterpret_cast<T*>(pend));
|
||||
pcurrent = pend;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Returns <b>true</b> if the byte stream is empty.
|
||||
//***************************************************************************
|
||||
bool empty() const
|
||||
{
|
||||
return available<char>() == 0U;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Returns the number of bytes used in the stream.
|
||||
//***************************************************************************
|
||||
size_t size_bytes() const
|
||||
{
|
||||
return length;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// The number of T left in the stream.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
size_t available() const
|
||||
{
|
||||
return (length - etl::distance(pdata, reinterpret_cast<char* const>(pcurrent))) / sizeof(T);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
//***************************************************************************
|
||||
|
||||
@ -44,8 +44,6 @@ SOFTWARE.
|
||||
/// A wrapper for arrays
|
||||
///\ingroup containers
|
||||
|
||||
#if ETL_CPP11_SUPPORTED
|
||||
|
||||
namespace etl
|
||||
{
|
||||
static ETL_CONSTANT size_t dynamic_extent = etl::integral_limits<size_t>::max;
|
||||
@ -282,6 +280,7 @@ namespace etl
|
||||
return etl::span<element_type, etl::dynamic_extent>(mend - count, mend);
|
||||
}
|
||||
|
||||
#if ETL_CPP11_SUPPORTED
|
||||
//*************************************************************************
|
||||
/// Obtains a span that is a view from OFFSET over the next COUNT elements of this span.
|
||||
/// Enabled for COUNT == etl::dynamic_extent
|
||||
@ -305,6 +304,31 @@ namespace etl
|
||||
{
|
||||
return etl::span<element_type, COUNT>(mbegin + OFFSET, mbegin + OFFSET + COUNT);
|
||||
}
|
||||
#else
|
||||
//*************************************************************************
|
||||
/// Obtains a span that is a view from OFFSET over the next COUNT elements of this span.
|
||||
/// Enabled for COUNT == etl::dynamic_extent
|
||||
//*************************************************************************
|
||||
template <const size_t OFFSET, const size_t COUNT>
|
||||
ETL_CONSTEXPR
|
||||
typename etl::enable_if<COUNT == etl::dynamic_extent, etl::span<element_type, ((EXTENT != etl::dynamic_extent) ? EXTENT - OFFSET : etl::dynamic_extent)> >::type
|
||||
subspan() const
|
||||
{
|
||||
return etl::span<element_type, ((EXTENT != etl::dynamic_extent) ? EXTENT - OFFSET : etl::dynamic_extent)>(mbegin + OFFSET, mend);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Obtains a span that is a view from OFFSET over the next COUNT elements of this span.
|
||||
/// Enabled for COUNT != etl::dynamic_extent
|
||||
//*************************************************************************
|
||||
template <const size_t OFFSET, const size_t COUNT>
|
||||
ETL_CONSTEXPR
|
||||
typename etl::enable_if<COUNT != etl::dynamic_extent, etl::span<element_type, COUNT> >::type
|
||||
subspan() const
|
||||
{
|
||||
return etl::span<element_type, COUNT>(mbegin + OFFSET, mbegin + OFFSET + COUNT);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
/// Obtains a span that is a view from 'offset' over the next 'count' elements of this span.
|
||||
@ -325,8 +349,8 @@ namespace etl
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
/// Template deduction guides.
|
||||
//*************************************************************************
|
||||
/// Template deduction guides.
|
||||
//*************************************************************************
|
||||
#if ETL_CPP17_SUPPORTED
|
||||
template <typename TArray>
|
||||
span(TArray& a)
|
||||
@ -360,5 +384,3 @@ namespace etl
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -50,6 +50,7 @@ set(TEST_SOURCE_FILES
|
||||
test_bip_buffer_spsc_atomic.cpp
|
||||
test_bitset.cpp
|
||||
test_bit_stream.cpp
|
||||
test_byte_stream.cpp
|
||||
test_bloom_filter.cpp
|
||||
test_bresenham_line.cpp
|
||||
test_bsd_checksum.cpp
|
||||
|
||||
29
test/sanity-check/byte_stream.h.t.cpp
Normal file
29
test/sanity-check/byte_stream.h.t.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2021 John Wellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#include <etl/byte_stream.h>
|
||||
@ -51,6 +51,7 @@ target_sources(t98 PRIVATE etl_profile.h
|
||||
../bip_buffer_spsc_atomic.h.t.cpp
|
||||
../bitset.h.t.cpp
|
||||
../bit_stream.h.t.cpp
|
||||
../byte_stream.h.t.cpp
|
||||
../bloom_filter.h.t.cpp
|
||||
../bresenham_line.h.t.cpp
|
||||
../buffer_descriptors.h.t.cpp
|
||||
|
||||
@ -51,6 +51,7 @@ target_sources(t11 PRIVATE etl_profile.h
|
||||
../bip_buffer_spsc_atomic.h.t.cpp
|
||||
../bitset.h.t.cpp
|
||||
../bit_stream.h.t.cpp
|
||||
../byte_stream.h.t.cpp
|
||||
../bloom_filter.h.t.cpp
|
||||
../bresenham_line.h.t.cpp
|
||||
../buffer_descriptors.h.t.cpp
|
||||
|
||||
@ -51,6 +51,7 @@ target_sources(t14 PRIVATE etl_profile.h
|
||||
../bip_buffer_spsc_atomic.h.t.cpp
|
||||
../bitset.h.t.cpp
|
||||
../bit_stream.h.t.cpp
|
||||
../byte_stream.h.t.cpp
|
||||
../bloom_filter.h.t.cpp
|
||||
../bresenham_line.h.t.cpp
|
||||
../buffer_descriptors.h.t.cpp
|
||||
|
||||
@ -51,6 +51,7 @@ target_sources(t17 PRIVATE etl_profile.h
|
||||
../bip_buffer_spsc_atomic.h.t.cpp
|
||||
../bitset.h.t.cpp
|
||||
../bit_stream.h.t.cpp
|
||||
../byte_stream.h.t.cpp
|
||||
../bloom_filter.h.t.cpp
|
||||
../bresenham_line.h.t.cpp
|
||||
../buffer_descriptors.h.t.cpp
|
||||
|
||||
@ -30,6 +30,7 @@ SOFTWARE.
|
||||
|
||||
#include "etl/byte_stream.h"
|
||||
#include "etl/optional.h"
|
||||
#include "etl/span.h"
|
||||
|
||||
#include <array>
|
||||
#include <numeric>
|
||||
@ -63,47 +64,21 @@ namespace etl
|
||||
//***********************************
|
||||
bool byte_stream_write(etl::byte_stream_writer& stream, const Object& object)
|
||||
{
|
||||
bool success = true;
|
||||
bool success_i = stream.write(object.i.value());
|
||||
bool success_d = stream.write(object.d.value());
|
||||
bool success_c = stream.write(object.c.value());
|
||||
|
||||
if (!stream.write(object.i.value()))
|
||||
{
|
||||
success = false;
|
||||
}
|
||||
|
||||
if (!stream.write(object.d.value()))
|
||||
{
|
||||
success = false;
|
||||
}
|
||||
|
||||
if (!stream.write(object.c.value()))
|
||||
{
|
||||
success = false;
|
||||
}
|
||||
|
||||
return success;
|
||||
return success_i && success_d && success_c;
|
||||
}
|
||||
|
||||
//***********************************
|
||||
bool byte_stream_read(etl::byte_stream_reader& stream, Object& object)
|
||||
{
|
||||
bool success = true;
|
||||
bool success_i = bool(object.i = stream.read<int16_t>());
|
||||
bool success_d = bool(object.d = stream.read<double>());
|
||||
bool success_c = bool(object.c = stream.read<uint8_t>());
|
||||
|
||||
if (object.i = stream.read<int16_t>())
|
||||
{
|
||||
success = false;
|
||||
}
|
||||
|
||||
if (object.d = stream.read<double>())
|
||||
{
|
||||
success = false;
|
||||
}
|
||||
|
||||
if (object.c = stream.read<uint8_t>())
|
||||
{
|
||||
success = false;
|
||||
}
|
||||
|
||||
return success;
|
||||
return success_i && success_d && success_c;
|
||||
}
|
||||
}
|
||||
|
||||
@ -111,6 +86,57 @@ namespace
|
||||
{
|
||||
SUITE(test_byte_stream)
|
||||
{
|
||||
//*************************************************************************
|
||||
TEST(byte_stream_default_properties)
|
||||
{
|
||||
char storage[7];
|
||||
|
||||
etl::byte_stream_writer writer(storage, std::size(storage));
|
||||
etl::byte_stream_reader reader(storage, writer.size_bytes()); // Capacity is zero.
|
||||
|
||||
CHECK(writer.empty());
|
||||
CHECK(reader.empty());
|
||||
|
||||
CHECK(!writer.full());
|
||||
|
||||
CHECK_EQUAL(0U, writer.size_bytes());
|
||||
CHECK_EQUAL(0U, reader.size_bytes());
|
||||
|
||||
CHECK_EQUAL(std::size(storage), writer.capacity());
|
||||
|
||||
CHECK_EQUAL(0U, reader.available<int8_t>());
|
||||
|
||||
CHECK_EQUAL(7U, writer.available<int8_t>());
|
||||
CHECK_EQUAL(3U, writer.available<int16_t>());
|
||||
CHECK_EQUAL(1U, writer.available<int32_t>());
|
||||
CHECK_EQUAL(0U, writer.available<int64_t>());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(byte_stream_properties)
|
||||
{
|
||||
char storage[8];
|
||||
|
||||
etl::byte_stream_writer writer(storage, std::size(storage));
|
||||
|
||||
CHECK(writer.write(uint8_t(0x12))); // 1 written.
|
||||
CHECK(writer.write(uint16_t(0x1234))); // 2 more written.
|
||||
CHECK(writer.write(uint32_t(0x12345678))); // 4 more written.
|
||||
CHECK(!writer.write(uint32_t(0x12345678))); // Can't write 4 more.
|
||||
|
||||
CHECK(!writer.empty());
|
||||
CHECK(!writer.full());
|
||||
CHECK_EQUAL(1U, writer.available<int8_t>());
|
||||
CHECK_EQUAL(7U, writer.size_bytes());
|
||||
CHECK_EQUAL(8U, writer.capacity());
|
||||
|
||||
etl::byte_stream_reader reader(storage, writer.size_bytes());
|
||||
|
||||
CHECK(!reader.empty());
|
||||
CHECK_EQUAL(7U, reader.available<int8_t>());
|
||||
CHECK_EQUAL(7U, reader.size_bytes());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(write_bool)
|
||||
{
|
||||
@ -353,20 +379,20 @@ namespace
|
||||
};
|
||||
|
||||
char storage[8];
|
||||
etl::byte_stream_writer byte_stream_w(storage, 8);
|
||||
etl::byte_stream_writer writer(storage, 8);
|
||||
|
||||
for (size_t i = 0; i < flags.size(); ++i)
|
||||
{
|
||||
byte_stream_w.write(flags[i]);
|
||||
writer.write(flags[i]);
|
||||
}
|
||||
|
||||
etl::byte_stream_reader byte_stream_r(storage, 8);
|
||||
etl::byte_stream_reader reader(storage, 8);
|
||||
|
||||
for (size_t i = 0; i < flags.size(); ++i)
|
||||
{
|
||||
etl::optional<bool> flag;
|
||||
|
||||
CHECK(flag = byte_stream_r.read<bool>());
|
||||
CHECK(flag = reader.read<bool>());
|
||||
CHECK_EQUAL(flags[i], flag.value());
|
||||
}
|
||||
}
|
||||
@ -378,26 +404,52 @@ namespace
|
||||
std::array<int8_t, 4> put_data = { int8_t(0x01), int8_t(0x5A), int8_t(0xA5), int8_t(0xFF) };
|
||||
std::array<etl::optional<int8_t>, 4> get_data = { int8_t(0x00), int8_t(0x00), int8_t(0x00), int8_t(0x00) };
|
||||
|
||||
etl::byte_stream_writer byte_stream_w(storage.data(), storage.size());
|
||||
etl::byte_stream_writer writer(storage.data(), storage.size());
|
||||
|
||||
// Insert into the stream
|
||||
byte_stream_w.write(put_data[0]);
|
||||
byte_stream_w.write(put_data[1]);
|
||||
byte_stream_w.write(put_data[2]);
|
||||
byte_stream_w.write(put_data[3]);
|
||||
CHECK(writer.empty());
|
||||
CHECK(!writer.full());
|
||||
CHECK_EQUAL(4U, writer.available<int8_t>());
|
||||
CHECK_EQUAL(0U, writer.size_bytes());
|
||||
|
||||
writer.write(put_data[0]);
|
||||
CHECK(!writer.empty());
|
||||
CHECK(!writer.full());
|
||||
CHECK_EQUAL(3U, writer.available<int8_t>());
|
||||
|
||||
writer.write(put_data[1]);
|
||||
CHECK(!writer.empty());
|
||||
CHECK(!writer.full());
|
||||
CHECK_EQUAL(2U, writer.available<int8_t>());
|
||||
|
||||
writer.write(put_data[2]);
|
||||
CHECK(!writer.empty());
|
||||
CHECK(!writer.full());
|
||||
CHECK_EQUAL(1U, writer.available<int8_t>());
|
||||
|
||||
writer.write(put_data[3]);
|
||||
CHECK(!writer.empty());
|
||||
CHECK(writer.full());
|
||||
CHECK_EQUAL(0U, writer.available<int8_t>());
|
||||
|
||||
etl::byte_stream_reader byte_stream_r(storage.data(), storage.size());
|
||||
etl::byte_stream_reader reader(storage.data(), writer.size_bytes());
|
||||
CHECK(!reader.empty());
|
||||
CHECK_EQUAL(4U, reader.available<int8_t>());
|
||||
|
||||
CHECK(get_data[0] = byte_stream_r.read<int8_t>());
|
||||
CHECK(get_data[0] = reader.read<int8_t>());
|
||||
CHECK_EQUAL(3U, reader.available<int8_t>());
|
||||
CHECK_EQUAL(put_data[0], int(get_data[0].value()));
|
||||
|
||||
CHECK(get_data[1] = byte_stream_r.read<int8_t>());
|
||||
CHECK(get_data[1] = reader.read<int8_t>());
|
||||
CHECK_EQUAL(2U, reader.available<int8_t>());
|
||||
CHECK_EQUAL(put_data[1], int(get_data[1].value()));
|
||||
|
||||
CHECK(get_data[2] = byte_stream_r.read<int8_t>());
|
||||
CHECK(get_data[2] = reader.read<int8_t>());
|
||||
CHECK_EQUAL(1U, reader.available<int8_t>());
|
||||
CHECK_EQUAL(put_data[2], int(get_data[2].value()));
|
||||
|
||||
CHECK(get_data[3] = byte_stream_r.read<int8_t>());
|
||||
CHECK(get_data[3] = reader.read<int8_t>());
|
||||
CHECK_EQUAL(0U, reader.available<int8_t>());
|
||||
CHECK_EQUAL(put_data[3], int(get_data[3].value()));
|
||||
}
|
||||
|
||||
@ -408,298 +460,502 @@ namespace
|
||||
std::array<uint8_t, 4> put_data = { uint8_t(0x01), uint8_t(0x5A), uint8_t(0xA5), uint8_t(0xFF) };
|
||||
std::array<etl::optional<uint8_t>, 4> get_data = { uint8_t(0x00), uint8_t(0x00), uint8_t(0x00), uint8_t(0x00) };
|
||||
|
||||
etl::byte_stream_writer byte_stream_w(storage.data(), storage.size());
|
||||
etl::byte_stream_writer writer(storage.data(), storage.size());
|
||||
|
||||
// Insert into the stream
|
||||
byte_stream_w.write(put_data[0]);
|
||||
byte_stream_w.write(put_data[1]);
|
||||
byte_stream_w.write(put_data[2]);
|
||||
byte_stream_w.write(put_data[3]);
|
||||
CHECK(writer.empty());
|
||||
CHECK(!writer.full());
|
||||
CHECK_EQUAL(4U, writer.available<uint8_t>());
|
||||
CHECK_EQUAL(0U, writer.size_bytes());
|
||||
|
||||
writer.write(put_data[0]);
|
||||
CHECK(!writer.empty());
|
||||
CHECK(!writer.full());
|
||||
CHECK_EQUAL(3U, writer.available<uint8_t>());
|
||||
|
||||
writer.write(put_data[1]);
|
||||
CHECK(!writer.empty());
|
||||
CHECK(!writer.full());
|
||||
CHECK_EQUAL(2U, writer.available<uint8_t>());
|
||||
|
||||
writer.write(put_data[2]);
|
||||
CHECK(!writer.empty());
|
||||
CHECK(!writer.full());
|
||||
CHECK_EQUAL(1U, writer.available<uint8_t>());
|
||||
|
||||
writer.write(put_data[3]);
|
||||
CHECK(!writer.empty());
|
||||
CHECK(writer.full());
|
||||
CHECK_EQUAL(0U, writer.available<uint8_t>());
|
||||
|
||||
etl::byte_stream_reader byte_stream_r(storage.data(), storage.size());
|
||||
etl::byte_stream_reader reader(storage.data(), writer.size_bytes());
|
||||
CHECK(!reader.empty());
|
||||
CHECK_EQUAL(4U, reader.available<uint8_t>());
|
||||
|
||||
CHECK(get_data[0] = byte_stream_r.read<uint8_t>());
|
||||
CHECK(get_data[0] = reader.read<uint8_t>());
|
||||
CHECK_EQUAL(3U, reader.available<uint8_t>());
|
||||
CHECK_EQUAL(put_data[0], int(get_data[0].value()));
|
||||
|
||||
CHECK(get_data[1] = byte_stream_r.read<uint8_t>());
|
||||
CHECK(get_data[1] = reader.read<uint8_t>());
|
||||
CHECK_EQUAL(2U, reader.available<uint8_t>());
|
||||
CHECK_EQUAL(put_data[1], int(get_data[1].value()));
|
||||
|
||||
CHECK(get_data[2] = byte_stream_r.read<uint8_t>());
|
||||
CHECK(get_data[2] = reader.read<uint8_t>());
|
||||
CHECK_EQUAL(1U, reader.available<uint8_t>());
|
||||
CHECK_EQUAL(put_data[2], int(get_data[2].value()));
|
||||
|
||||
CHECK(get_data[3] = byte_stream_r.read<uint8_t>());
|
||||
CHECK(get_data[3] = reader.read<uint8_t>());
|
||||
CHECK_EQUAL(0U, reader.available<uint8_t>());
|
||||
CHECK_EQUAL(put_data[3], int(get_data[3].value()));
|
||||
}
|
||||
|
||||
////*************************************************************************
|
||||
//TEST(put_get_int16_t)
|
||||
//{
|
||||
// std::array<char, 4 * sizeof(int16_t)> storage;
|
||||
// std::array<int16_t, 4> put_data = { int16_t(0x0001), int16_t(0xA55A), int16_t(0x5AA5), int16_t(0xFFFF) };
|
||||
// std::array<int16_t, 4> get_data = { int16_t(0x0000), int16_t(0x0000), int16_t(0x0000), int16_t(0x0000) };
|
||||
//*************************************************************************
|
||||
TEST(write_read_int16_t)
|
||||
{
|
||||
std::array<char, 4 * sizeof(int16_t)> storage;
|
||||
std::array<int16_t, 4> put_data = { int16_t(0x0001), int16_t(0xA55A), int16_t(0x5AA5), int16_t(0xFFFF) };
|
||||
std::array<etl::optional<int16_t>, 4> get_data = { int16_t(0x0000), int16_t(0x0000), int16_t(0x0000), int16_t(0x0000) };
|
||||
|
||||
etl::byte_stream_writer writer(storage.data(), storage.size());
|
||||
|
||||
// Insert into the stream
|
||||
CHECK(writer.empty());
|
||||
CHECK(!writer.full());
|
||||
CHECK_EQUAL(4U, writer.available<int16_t>());
|
||||
CHECK_EQUAL(0U, writer.size_bytes());
|
||||
|
||||
writer.write(put_data[0]);
|
||||
CHECK(!writer.empty());
|
||||
CHECK(!writer.full());
|
||||
CHECK_EQUAL(3U, writer.available<int16_t>());
|
||||
|
||||
writer.write(put_data[1]);
|
||||
CHECK(!writer.empty());
|
||||
CHECK(!writer.full());
|
||||
CHECK_EQUAL(2U, writer.available<int16_t>());
|
||||
|
||||
writer.write(put_data[2]);
|
||||
CHECK(!writer.empty());
|
||||
CHECK(!writer.full());
|
||||
CHECK_EQUAL(1U, writer.available<int16_t>());
|
||||
|
||||
writer.write(put_data[3]);
|
||||
CHECK(!writer.empty());
|
||||
CHECK(writer.full());
|
||||
CHECK_EQUAL(0U, writer.available<int16_t>());
|
||||
|
||||
etl::byte_stream_reader reader(storage.data(), writer.size_bytes());
|
||||
CHECK(!reader.empty());
|
||||
CHECK_EQUAL(4U, reader.available<int16_t>());
|
||||
|
||||
CHECK(get_data[0] = reader.read<int16_t>());
|
||||
CHECK_EQUAL(3U, reader.available<int16_t>());
|
||||
CHECK_EQUAL(put_data[0], get_data[0].value());
|
||||
|
||||
CHECK(get_data[1] = reader.read<int16_t>());
|
||||
CHECK_EQUAL(2U, reader.available<int16_t>());
|
||||
CHECK_EQUAL(put_data[1], get_data[1].value());
|
||||
|
||||
CHECK(get_data[2] = reader.read<int16_t>());
|
||||
CHECK_EQUAL(1U, reader.available<int16_t>());
|
||||
CHECK_EQUAL(put_data[2], get_data[2].value());
|
||||
|
||||
CHECK(get_data[3] = reader.read<int16_t>());
|
||||
CHECK_EQUAL(0U, reader.available<int16_t>());
|
||||
CHECK_EQUAL(put_data[3], get_data[3].value());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(write_read_uint16_t)
|
||||
{
|
||||
std::array<char, 4 * sizeof(uint16_t)> storage;
|
||||
std::array<uint16_t, 4> put_data = { uint16_t(0x0001), uint16_t(0xA55A), uint16_t(0x5AA5), uint16_t(0xFFFF) };
|
||||
std::array<etl::optional<uint16_t>, 4> get_data = { uint16_t(0x0000), uint16_t(0x0000), uint16_t(0x0000), uint16_t(0x0000) };
|
||||
|
||||
etl::byte_stream_writer writer(storage.data(), storage.size());
|
||||
|
||||
// Insert into the stream
|
||||
CHECK(writer.empty());
|
||||
CHECK(!writer.full());
|
||||
CHECK_EQUAL(4U, writer.available<uint16_t>());
|
||||
CHECK_EQUAL(0U, writer.size_bytes());
|
||||
|
||||
writer.write(put_data[0]);
|
||||
CHECK(!writer.empty());
|
||||
CHECK(!writer.full());
|
||||
CHECK_EQUAL(3U, writer.available<uint16_t>());
|
||||
|
||||
writer.write(put_data[1]);
|
||||
CHECK(!writer.empty());
|
||||
CHECK(!writer.full());
|
||||
CHECK_EQUAL(2U, writer.available<uint16_t>());
|
||||
|
||||
writer.write(put_data[2]);
|
||||
CHECK(!writer.empty());
|
||||
CHECK(!writer.full());
|
||||
CHECK_EQUAL(1U, writer.available<uint16_t>());
|
||||
|
||||
writer.write(put_data[3]);
|
||||
CHECK(!writer.empty());
|
||||
CHECK(writer.full());
|
||||
CHECK_EQUAL(0U, writer.available<uint16_t>());
|
||||
|
||||
etl::byte_stream_reader reader(storage.data(), writer.size_bytes());
|
||||
CHECK(!reader.empty());
|
||||
CHECK_EQUAL(4U, reader.available<uint16_t>());
|
||||
|
||||
CHECK(get_data[0] = reader.read<uint16_t>());
|
||||
CHECK_EQUAL(3U, reader.available<uint16_t>());
|
||||
CHECK_EQUAL(put_data[0], get_data[0].value());
|
||||
|
||||
CHECK(get_data[1] = reader.read<uint16_t>());
|
||||
CHECK_EQUAL(2U, reader.available<uint16_t>());
|
||||
CHECK_EQUAL(put_data[1], get_data[1].value());
|
||||
|
||||
CHECK(get_data[2] = reader.read<uint16_t>());
|
||||
CHECK_EQUAL(1U, reader.available<uint16_t>());
|
||||
CHECK_EQUAL(put_data[2], get_data[2].value());
|
||||
|
||||
CHECK(get_data[3] = reader.read<uint16_t>());
|
||||
CHECK_EQUAL(0U, reader.available<uint16_t>());
|
||||
CHECK_EQUAL(put_data[3], get_data[3].value());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(write_read_int32_t)
|
||||
{
|
||||
std::array<char, 4 * sizeof(int32_t)> storage;
|
||||
std::array<int32_t, 4> put_data = { int32_t(0x00000001), int32_t(0xA55AA55A), int32_t(0x5AA55AA5), int32_t(0xFFFFFFFF) };
|
||||
std::array<etl::optional<int32_t>, 4> get_data = { int32_t(0x00000000), int32_t(0x00000000), int32_t(0x00000000), int32_t(0x00000000) };
|
||||
|
||||
etl::byte_stream_writer writer(storage.data(), storage.size());
|
||||
|
||||
// Insert into the stream
|
||||
CHECK(writer.empty());
|
||||
CHECK(!writer.full());
|
||||
CHECK_EQUAL(4U, writer.available<int32_t>());
|
||||
CHECK_EQUAL(0U, writer.size_bytes());
|
||||
|
||||
writer.write(put_data[0]);
|
||||
CHECK(!writer.empty());
|
||||
CHECK(!writer.full());
|
||||
CHECK_EQUAL(3U, writer.available<int32_t>());
|
||||
|
||||
writer.write(put_data[1]);
|
||||
CHECK(!writer.empty());
|
||||
CHECK(!writer.full());
|
||||
CHECK_EQUAL(2U, writer.available<int32_t>());
|
||||
|
||||
writer.write(put_data[2]);
|
||||
CHECK(!writer.empty());
|
||||
CHECK(!writer.full());
|
||||
CHECK_EQUAL(1U, writer.available<int32_t>());
|
||||
|
||||
writer.write(put_data[3]);
|
||||
CHECK(!writer.empty());
|
||||
CHECK(writer.full());
|
||||
CHECK_EQUAL(0U, writer.available<int32_t>());
|
||||
|
||||
etl::byte_stream_reader reader(storage.data(), writer.size_bytes());
|
||||
CHECK(!reader.empty());
|
||||
CHECK_EQUAL(4U, reader.available<int32_t>());
|
||||
|
||||
CHECK(get_data[0] = reader.read<int32_t>());
|
||||
CHECK_EQUAL(3U, reader.available<int32_t>());
|
||||
CHECK_EQUAL(put_data[0], get_data[0].value());
|
||||
|
||||
CHECK(get_data[1] = reader.read<int32_t>());
|
||||
CHECK_EQUAL(2U, reader.available<int32_t>());
|
||||
CHECK_EQUAL(put_data[1], get_data[1].value());
|
||||
|
||||
CHECK(get_data[2] = reader.read<int32_t>());
|
||||
CHECK_EQUAL(1U, reader.available<int32_t>());
|
||||
CHECK_EQUAL(put_data[2], get_data[2].value());
|
||||
|
||||
CHECK(get_data[3] = reader.read<int32_t>());
|
||||
CHECK_EQUAL(0U, reader.available<int32_t>());
|
||||
CHECK_EQUAL(put_data[3], get_data[3].value());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(write_read_uint32_t)
|
||||
{
|
||||
std::array<char, 4 * sizeof(uint32_t)> storage;
|
||||
std::array<uint32_t, 4> put_data = { uint32_t(0x00000001), uint32_t(0xA55AA55A), uint32_t(0x5AA55AA5), uint32_t(0xFFFFFFFF) };
|
||||
std::array<etl::optional<uint32_t>, 4> get_data = { uint32_t(0x00000000), uint32_t(0x00000000), uint32_t(0x00000000), uint32_t(0x00000000) };
|
||||
|
||||
etl::byte_stream_writer writer(storage.data(), storage.size());
|
||||
|
||||
// Insert into the stream
|
||||
CHECK(writer.empty());
|
||||
CHECK(!writer.full());
|
||||
CHECK_EQUAL(4U, writer.available<uint32_t>());
|
||||
CHECK_EQUAL(0U, writer.size_bytes());
|
||||
|
||||
writer.write(put_data[0]);
|
||||
CHECK(!writer.empty());
|
||||
CHECK(!writer.full());
|
||||
CHECK_EQUAL(3U, writer.available<uint32_t>());
|
||||
|
||||
writer.write(put_data[1]);
|
||||
CHECK(!writer.empty());
|
||||
CHECK(!writer.full());
|
||||
CHECK_EQUAL(2U, writer.available<uint32_t>());
|
||||
|
||||
writer.write(put_data[2]);
|
||||
CHECK(!writer.empty());
|
||||
CHECK(!writer.full());
|
||||
CHECK_EQUAL(1U, writer.available<uint32_t>());
|
||||
|
||||
writer.write(put_data[3]);
|
||||
CHECK(!writer.empty());
|
||||
CHECK(writer.full());
|
||||
CHECK_EQUAL(0U, writer.available<uint32_t>());
|
||||
|
||||
etl::byte_stream_reader reader(storage.data(), writer.size_bytes());
|
||||
CHECK(!reader.empty());
|
||||
CHECK_EQUAL(4U, reader.available<uint32_t>());
|
||||
|
||||
CHECK(get_data[0] = reader.read<uint32_t>());
|
||||
CHECK_EQUAL(3U, reader.available<uint32_t>());
|
||||
CHECK_EQUAL(put_data[0], get_data[0].value());
|
||||
|
||||
CHECK(get_data[1] = reader.read<uint32_t>());
|
||||
CHECK_EQUAL(2U, reader.available<uint32_t>());
|
||||
CHECK_EQUAL(put_data[1], get_data[1].value());
|
||||
|
||||
CHECK(get_data[2] = reader.read<uint32_t>());
|
||||
CHECK_EQUAL(1U, reader.available<uint32_t>());
|
||||
CHECK_EQUAL(put_data[2], get_data[2].value());
|
||||
|
||||
CHECK(get_data[3] = reader.read<uint32_t>());
|
||||
CHECK_EQUAL(0U, reader.available<uint32_t>());
|
||||
CHECK_EQUAL(put_data[3], get_data[3].value());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(write_read_int64_t)
|
||||
{
|
||||
std::array<char, 4 * sizeof(int64_t)> storage;
|
||||
std::array<int64_t, 4> put_data = { int64_t(0x0000000000000001), int64_t(0xA55AA55AA55AA55A), int64_t(0x5AA55AA55AA55AA5), int64_t(0xFFFFFFFFFFFFFFFF) };
|
||||
std::array<int64_t, 4> expect_data = { int64_t(0x0000000000000001), int64_t(0xA55AA55AA55AA55A), int64_t(0x5AA55AA55AA55AA5), int64_t(0xFFFFFFFFFFFFFFFF) };
|
||||
std::array<etl::optional<int64_t>, 4> get_data = { int64_t(0x0000000000000000), int64_t(0x0000000000000000), int64_t(0x0000000000000000), int64_t(0x0000000000000000) };
|
||||
|
||||
etl::byte_stream_writer writer(storage.data(), storage.size());
|
||||
|
||||
// Insert into the stream
|
||||
CHECK(writer.empty());
|
||||
CHECK(!writer.full());
|
||||
CHECK_EQUAL(4U, writer.available<int64_t>());
|
||||
CHECK_EQUAL(0U, writer.size_bytes());
|
||||
|
||||
writer.write(put_data[0]);
|
||||
CHECK(!writer.empty());
|
||||
CHECK(!writer.full());
|
||||
CHECK_EQUAL(3U, writer.available<int64_t>());
|
||||
|
||||
writer.write(put_data[1]);
|
||||
CHECK(!writer.empty());
|
||||
CHECK(!writer.full());
|
||||
CHECK_EQUAL(2U, writer.available<int64_t>());
|
||||
|
||||
writer.write(put_data[2]);
|
||||
CHECK(!writer.empty());
|
||||
CHECK(!writer.full());
|
||||
CHECK_EQUAL(1U, writer.available<int64_t>());
|
||||
|
||||
writer.write(put_data[3]);
|
||||
CHECK(!writer.empty());
|
||||
CHECK(writer.full());
|
||||
CHECK_EQUAL(0U, writer.available<int64_t>());
|
||||
|
||||
etl::byte_stream_reader reader(storage.data(), writer.size_bytes());
|
||||
CHECK(!reader.empty());
|
||||
CHECK_EQUAL(4U, reader.available<int64_t>());
|
||||
|
||||
CHECK(get_data[0] = reader.read<int64_t>());
|
||||
CHECK_EQUAL(3U, reader.available<int64_t>());
|
||||
CHECK_EQUAL(put_data[0], get_data[0].value());
|
||||
|
||||
CHECK(get_data[1] = reader.read<int64_t>());
|
||||
CHECK_EQUAL(2U, reader.available<int64_t>());
|
||||
CHECK_EQUAL(put_data[1], get_data[1].value());
|
||||
|
||||
CHECK(get_data[2] = reader.read<int64_t>());
|
||||
CHECK_EQUAL(1U, reader.available<int64_t>());
|
||||
CHECK_EQUAL(put_data[2], get_data[2].value());
|
||||
|
||||
CHECK(get_data[3] = reader.read<int64_t>());
|
||||
CHECK_EQUAL(0U, reader.available<int64_t>());
|
||||
CHECK_EQUAL(put_data[3], get_data[3].value());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(write_read_uint64_t)
|
||||
{
|
||||
std::array<char, 4 * sizeof(uint64_t)> storage;
|
||||
std::array<uint64_t, 4> put_data = { uint64_t(0x0000000000000001), uint64_t(0xA55AA55AA55AA55A), uint64_t(0x5AA55AA55AA55AA5), uint64_t(0xFFFFFFFFFFFFFFFF) };
|
||||
std::array<uint64_t, 4> expect_data = { uint64_t(0x0000000000000001), uint64_t(0xA55AA55AA55AA55A), uint64_t(0x5AA55AA55AA55AA5), uint64_t(0xFFFFFFFFFFFFFFFF) };
|
||||
std::array<etl::optional<uint64_t>, 4> get_data = { uint64_t(0x0000000000000000), uint64_t(0x0000000000000000), uint64_t(0x0000000000000000), uint64_t(0x0000000000000000) };
|
||||
|
||||
etl::byte_stream_writer writer(storage.data(), storage.size());
|
||||
|
||||
// Insert into the stream
|
||||
CHECK(writer.empty());
|
||||
CHECK(!writer.full());
|
||||
CHECK_EQUAL(4U, writer.available<uint64_t>());
|
||||
CHECK_EQUAL(0U, writer.size_bytes());
|
||||
|
||||
writer.write(put_data[0]);
|
||||
CHECK(!writer.empty());
|
||||
CHECK(!writer.full());
|
||||
CHECK_EQUAL(3U, writer.available<uint64_t>());
|
||||
|
||||
writer.write(put_data[1]);
|
||||
CHECK(!writer.empty());
|
||||
CHECK(!writer.full());
|
||||
CHECK_EQUAL(2U, writer.available<uint64_t>());
|
||||
|
||||
writer.write(put_data[2]);
|
||||
CHECK(!writer.empty());
|
||||
CHECK(!writer.full());
|
||||
CHECK_EQUAL(1U, writer.available<uint64_t>());
|
||||
|
||||
writer.write(put_data[3]);
|
||||
CHECK(!writer.empty());
|
||||
CHECK(writer.full());
|
||||
CHECK_EQUAL(0U, writer.available<uint64_t>());
|
||||
|
||||
etl::byte_stream_reader reader(storage.data(), writer.size_bytes());
|
||||
CHECK(!reader.empty());
|
||||
CHECK_EQUAL(4U, reader.available<uint64_t>());
|
||||
|
||||
CHECK(get_data[0] = reader.read<uint64_t>());
|
||||
CHECK_EQUAL(3U, reader.available<uint64_t>());
|
||||
CHECK_EQUAL(put_data[0], get_data[0].value());
|
||||
|
||||
CHECK(get_data[1] = reader.read<uint64_t>());
|
||||
CHECK_EQUAL(2U, reader.available<uint64_t>());
|
||||
CHECK_EQUAL(put_data[1], get_data[1].value());
|
||||
|
||||
CHECK(get_data[2] = reader.read<uint64_t>());
|
||||
CHECK_EQUAL(1U, reader.available<uint64_t>());
|
||||
CHECK_EQUAL(put_data[2], get_data[2].value());
|
||||
|
||||
CHECK(get_data[3] = reader.read<uint64_t>());
|
||||
CHECK_EQUAL(0U, reader.available<uint64_t>());
|
||||
CHECK_EQUAL(put_data[3], get_data[3].value());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(write_read_char_range)
|
||||
{
|
||||
std::array<char, 4 * sizeof(char)> storage;
|
||||
std::array<char, 4> put_data = { char(0x01), char(0x5A), char(0xA5), char(0xFF) };
|
||||
|
||||
etl::span<char> input(put_data.begin(), put_data.end());
|
||||
|
||||
etl::byte_stream_writer writer(storage.data(), storage.size());
|
||||
CHECK(writer.write(input));
|
||||
|
||||
etl::byte_stream_reader reader(storage.data(), writer.size_bytes());
|
||||
|
||||
etl::span<char> output = reader.read<char>(4U);
|
||||
CHECK_EQUAL(4U, output.size());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(write_read_multiple)
|
||||
{
|
||||
char c1 = 90;
|
||||
char c2 = -91;
|
||||
unsigned short s1 = 23205;
|
||||
unsigned short s2 = 42330;
|
||||
int32_t i1 = 1520786085; // 0x5AA55AA5
|
||||
int32_t i2 = -1520786086; // 0xA55AA55A
|
||||
float f = 3.1415927f;
|
||||
double d = 3.1415927;
|
||||
|
||||
std::array<char, 100> storage;
|
||||
|
||||
etl::byte_stream_writer writer(storage.data(), storage.size());
|
||||
|
||||
// Insert into the stream.
|
||||
writer.write(c1);
|
||||
writer.write(s1);
|
||||
writer.write(i1);
|
||||
writer.write(f);
|
||||
writer.write(i2);
|
||||
writer.write(d);
|
||||
writer.write(s2);
|
||||
writer.write(c2);
|
||||
|
||||
etl::byte_stream_reader reader(storage.data(), writer.size_bytes());
|
||||
|
||||
etl::optional<char> rc1;
|
||||
etl::optional<char> rc2;
|
||||
etl::optional<unsigned short> rs1;
|
||||
etl::optional<unsigned short> rs2;
|
||||
etl::optional<int32_t> ri1;
|
||||
etl::optional<int32_t> ri2;
|
||||
etl::optional<float> rf;
|
||||
etl::optional<double> rd;
|
||||
|
||||
// Read them all back.
|
||||
CHECK(rc1 = reader.read<char>());
|
||||
CHECK_EQUAL(int(c1), int(rc1.value()));
|
||||
|
||||
CHECK(rs1 = reader.read<unsigned short>());
|
||||
CHECK_EQUAL(s1, rs1.value());
|
||||
|
||||
CHECK(ri1 = reader.read<int32_t>());
|
||||
CHECK_EQUAL(i1, ri1.value());
|
||||
|
||||
// etl::bit_stream bit_stream(storage.data(), storage.size());
|
||||
CHECK(rf = reader.read<float>());
|
||||
CHECK_CLOSE(f, rf.value(), 0.1f);
|
||||
|
||||
// // Insert into the stream
|
||||
// bit_stream.put(put_data[0]);
|
||||
// bit_stream.put(put_data[1]);
|
||||
// bit_stream.put(put_data[2]);
|
||||
// bit_stream.put(put_data[3]);
|
||||
CHECK(ri2 = reader.read<int32_t>());
|
||||
CHECK_EQUAL(i2, ri2.value());
|
||||
|
||||
CHECK(rd = reader.read<double>());
|
||||
CHECK_CLOSE(d, rd.value(), 0.1);
|
||||
|
||||
// bit_stream.restart();
|
||||
CHECK(rs2 = reader.read<unsigned short>());
|
||||
CHECK_EQUAL(s2, rs2.value());
|
||||
|
||||
// CHECK(bit_stream.get(get_data[0]));
|
||||
// CHECK_EQUAL(put_data[0], get_data[0]);
|
||||
CHECK(rc2 = reader.read<char>());
|
||||
CHECK_EQUAL(int(c2), int(rc2.value()));
|
||||
}
|
||||
|
||||
// CHECK(bit_stream.get(get_data[1]));
|
||||
// CHECK_EQUAL(put_data[1], get_data[1]);
|
||||
//*************************************************************************
|
||||
TEST(write_read_object_global)
|
||||
{
|
||||
std::array<char, 2 * sizeof(Object)> storage;
|
||||
|
||||
// CHECK(bit_stream.get(get_data[2]));
|
||||
// CHECK_EQUAL(put_data[2], get_data[2]);
|
||||
etl::byte_stream_writer writer(storage.data(), storage.size());
|
||||
|
||||
// CHECK(bit_stream.get(get_data[3]));
|
||||
// CHECK_EQUAL(put_data[3], get_data[3]);
|
||||
//}
|
||||
Object object1 = { -1234, 2.71578369, 250 };
|
||||
Object object2 = { 5678, 5.24685744, 126 };
|
||||
|
||||
////*************************************************************************
|
||||
//TEST(put_get_uint16_t)
|
||||
//{
|
||||
// std::array<char, 4 * sizeof(uint16_t)> storage;
|
||||
// std::array<uint16_t, 4> put_data = { uint16_t(0x0001), uint16_t(0xA55A), uint16_t(0x5AA5), uint16_t(0xFFFF) };
|
||||
// std::array<uint16_t, 4> get_data = { uint16_t(0x0000), uint16_t(0x0000), uint16_t(0x0000), uint16_t(0x0000) };
|
||||
CHECK(etl::byte_stream_write(writer, object1));
|
||||
CHECK(etl::byte_stream_write(writer, object2));
|
||||
|
||||
// etl::bit_stream bit_stream(storage.data(), storage.size());
|
||||
Object object1a;
|
||||
Object object2a;
|
||||
|
||||
// // Insert into the stream
|
||||
// bit_stream.put(put_data[0]);
|
||||
// bit_stream.put(put_data[1]);
|
||||
// bit_stream.put(put_data[2]);
|
||||
// bit_stream.put(put_data[3]);
|
||||
etl::byte_stream_reader reader(storage.data(), writer.size_bytes());
|
||||
|
||||
// bit_stream.restart();
|
||||
CHECK(etl::byte_stream_read(reader, object1a));
|
||||
CHECK(etl::byte_stream_read(reader, object2a));
|
||||
|
||||
// CHECK(bit_stream.get(get_data[0]));
|
||||
// CHECK_EQUAL(put_data[0], get_data[0]);
|
||||
CHECK_EQUAL(object1.i.value(), object1a.i.value());
|
||||
CHECK_EQUAL(object1.d.value(), object1a.d.value());
|
||||
CHECK_EQUAL(int(object1.c.value()), int(object1a.c.value()));
|
||||
|
||||
// CHECK(bit_stream.get(get_data[1]));
|
||||
// CHECK_EQUAL(put_data[1], get_data[1]);
|
||||
|
||||
// CHECK(bit_stream.get(get_data[2]));
|
||||
// CHECK_EQUAL(put_data[2], get_data[2]);
|
||||
|
||||
// CHECK(bit_stream.get(get_data[3]));
|
||||
// CHECK_EQUAL(put_data[3], get_data[3]);
|
||||
//}
|
||||
|
||||
////*************************************************************************
|
||||
//TEST(put_get_int32_t)
|
||||
//{
|
||||
// std::array<char, 4 * sizeof(int32_t)> storage;
|
||||
// std::array<int32_t, 4> put_data = { int32_t(0x00000001), int32_t(0xA55AA55A), int32_t(0x5AA55AA5), int32_t(0xFFFFFFFF) };
|
||||
// std::array<int32_t, 4> get_data = { int32_t(0x00000000), int32_t(0x00000000), int32_t(0x00000000), int32_t(0x00000000) };
|
||||
|
||||
// etl::bit_stream bit_stream(storage.data(), storage.size());
|
||||
|
||||
// // Insert into the stream
|
||||
// bit_stream.put(put_data[0]);
|
||||
// bit_stream.put(put_data[1]);
|
||||
// bit_stream.put(put_data[2]);
|
||||
// bit_stream.put(put_data[3]);
|
||||
|
||||
// bit_stream.restart();
|
||||
|
||||
// CHECK(bit_stream.get(get_data[0]));
|
||||
// CHECK_EQUAL(put_data[0], get_data[0]);
|
||||
|
||||
// CHECK(bit_stream.get(get_data[1]));
|
||||
// CHECK_EQUAL(put_data[1], get_data[1]);
|
||||
|
||||
// CHECK(bit_stream.get(get_data[2]));
|
||||
// CHECK_EQUAL(put_data[2], get_data[2]);
|
||||
|
||||
// CHECK(bit_stream.get(get_data[3]));
|
||||
// CHECK_EQUAL(put_data[3], get_data[3]);
|
||||
//}
|
||||
|
||||
////*************************************************************************
|
||||
//TEST(put_get_uint32_t)
|
||||
//{
|
||||
// std::array<char, 4 * sizeof(uint32_t)> storage;
|
||||
// std::array<uint32_t, 4> put_data = { uint32_t(0x00000001), uint32_t(0xA55AA55A), uint32_t(0x5AA55AA5), uint32_t(0xFFFFFFFF) };
|
||||
// std::array<uint32_t, 4> get_data = { uint32_t(0x00000000), uint32_t(0x00000000), uint32_t(0x00000000), uint32_t(0x00000000) };
|
||||
|
||||
// etl::bit_stream bit_stream(storage.data(), storage.size());
|
||||
|
||||
// // Insert into the stream
|
||||
// bit_stream.put(put_data[0]);
|
||||
// bit_stream.put(put_data[1]);
|
||||
// bit_stream.put(put_data[2]);
|
||||
// bit_stream.put(put_data[3]);
|
||||
|
||||
// bit_stream.restart();
|
||||
|
||||
// CHECK(bit_stream.get(get_data[0]));
|
||||
// CHECK_EQUAL(put_data[0], get_data[0]);
|
||||
|
||||
// CHECK(bit_stream.get(get_data[1]));
|
||||
// CHECK_EQUAL(put_data[1], get_data[1]);
|
||||
|
||||
// CHECK(bit_stream.get(get_data[2]));
|
||||
// CHECK_EQUAL(put_data[2], get_data[2]);
|
||||
|
||||
// CHECK(bit_stream.get(get_data[3]));
|
||||
// CHECK_EQUAL(put_data[3], get_data[3]);
|
||||
//}
|
||||
|
||||
////*************************************************************************
|
||||
//TEST(put_get_int64_t)
|
||||
//{
|
||||
// std::array<char, 4 * sizeof(int64_t)> storage;
|
||||
// std::array<int64_t, 4> put_data = { int64_t(0x0000000000000001), int64_t(0xA55AA55AA55AA55A), int64_t(0x5AA55AA55AA55AA5), int64_t(0xFFFFFFFFFFFFFFFF) };
|
||||
// std::array<int64_t, 4> expect_data = { int64_t(0x0000000000000001), int64_t(0xA55AA55AA55AA55A), int64_t(0x5AA55AA55AA55AA5), int64_t(0xFFFFFFFFFFFFFFFF) };
|
||||
// std::array<int64_t, 4> get_data = { int64_t(0x0000000000000000), int64_t(0x0000000000000000), int64_t(0x0000000000000000), int64_t(0x0000000000000000) };
|
||||
|
||||
// etl::bit_stream bit_stream(storage.data(), storage.size());
|
||||
|
||||
// // Insert into the stream
|
||||
// bit_stream.put(put_data[0]);
|
||||
// bit_stream.put(put_data[1]);
|
||||
// bit_stream.put(put_data[2]);
|
||||
// bit_stream.put(put_data[3]);
|
||||
|
||||
// bit_stream.restart();
|
||||
|
||||
// CHECK(bit_stream.get(get_data[0]));
|
||||
// CHECK_EQUAL(expect_data[0], get_data[0]);
|
||||
|
||||
// CHECK(bit_stream.get(get_data[1]));
|
||||
// CHECK_EQUAL(expect_data[1], get_data[1]);
|
||||
|
||||
// CHECK(bit_stream.get(get_data[2]));
|
||||
// CHECK_EQUAL(expect_data[2], get_data[2]);
|
||||
|
||||
// CHECK(bit_stream.get(get_data[3]));
|
||||
// CHECK_EQUAL(expect_data[3], get_data[3]);
|
||||
//}
|
||||
|
||||
////*************************************************************************
|
||||
//TEST(put_get_uint64_t)
|
||||
//{
|
||||
// std::array<char, 4 * sizeof(uint64_t)> storage;
|
||||
// std::array<uint64_t, 4> put_data = { uint64_t(0x0000000000000001), uint64_t(0xA55AA55AA55AA55A), uint64_t(0x5AA55AA55AA55AA5), uint64_t(0xFFFFFFFFFFFFFFFF) };
|
||||
// std::array<uint64_t, 4> expect_data = { uint64_t(0x0000000000000001), uint64_t(0xA55AA55AA55AA55A), uint64_t(0x5AA55AA55AA55AA5), uint64_t(0xFFFFFFFFFFFFFFFF) };
|
||||
// std::array<uint64_t, 4> get_data = { uint64_t(0x0000000000000000), uint64_t(0x0000000000000000), uint64_t(0x0000000000000000), uint64_t(0x0000000000000000) };
|
||||
|
||||
// etl::bit_stream bit_stream(storage.data(), storage.size());
|
||||
|
||||
// // Insert into the stream
|
||||
// bit_stream.put(put_data[0]);
|
||||
// bit_stream.put(put_data[1]);
|
||||
// bit_stream.put(put_data[2]);
|
||||
// bit_stream.put(put_data[3]);
|
||||
|
||||
// bit_stream.restart();
|
||||
|
||||
// CHECK(bit_stream.get(get_data[0]));
|
||||
// CHECK_EQUAL(expect_data[0], get_data[0]);
|
||||
|
||||
// CHECK(bit_stream.get(get_data[1]));
|
||||
// CHECK_EQUAL(expect_data[1], get_data[1]);
|
||||
|
||||
// CHECK(bit_stream.get(get_data[2]));
|
||||
// CHECK_EQUAL(expect_data[2], get_data[2]);
|
||||
|
||||
// CHECK(bit_stream.get(get_data[3]));
|
||||
// CHECK_EQUAL(expect_data[3], get_data[3]);
|
||||
//}
|
||||
|
||||
////*************************************************************************
|
||||
//TEST(put_get_multiple_full_size)
|
||||
//{
|
||||
// char c1 = 90;
|
||||
// char c2 = -91;
|
||||
// unsigned short s1 = 23205;
|
||||
// unsigned short s2 = 42330;
|
||||
// int32_t i1 = 1520786085; // 0x5AA55AA5
|
||||
// int32_t i2 = -1520786086; // 0xA55AA55A
|
||||
// float f = 3.1415927f;
|
||||
// double d = 3.1415927;
|
||||
|
||||
// std::array<char, 100> storage;
|
||||
|
||||
// etl::bit_stream bit_stream(storage.data(), storage.size());
|
||||
|
||||
// // Insert into the stream.
|
||||
// bit_stream.put(c1);
|
||||
// bit_stream.put(s1);
|
||||
// bit_stream.put(i1);
|
||||
// bit_stream.put(f);
|
||||
// bit_stream.put(i2);
|
||||
// bit_stream.put(d);
|
||||
// bit_stream.put(s2);
|
||||
// bit_stream.put(c2);
|
||||
|
||||
// bit_stream.restart();
|
||||
|
||||
// char rc1;
|
||||
// char rc2;
|
||||
// unsigned short rs1;
|
||||
// unsigned short rs2;
|
||||
// int32_t ri1;
|
||||
// int32_t ri2;
|
||||
// float rf;
|
||||
// double rd;
|
||||
|
||||
// // Read them all back.
|
||||
// CHECK(bit_stream.get(rc1));
|
||||
// CHECK_EQUAL(int(c1), int(rc1));
|
||||
|
||||
// CHECK(bit_stream.get(rs1));
|
||||
// CHECK_EQUAL(s1, rs1);
|
||||
|
||||
// CHECK(bit_stream.get(ri1));
|
||||
// CHECK_EQUAL(i1, ri1);
|
||||
|
||||
// CHECK(bit_stream.get(rf));
|
||||
// CHECK_CLOSE(f, rf, 0.1f);
|
||||
|
||||
// CHECK(bit_stream.get(ri2));
|
||||
// CHECK_EQUAL(i2, ri2);
|
||||
|
||||
// CHECK(bit_stream.get(rd));
|
||||
// CHECK_CLOSE(d, rd, 0.1);
|
||||
|
||||
// CHECK(bit_stream.get(rs2));
|
||||
// CHECK_EQUAL(s2, rs2);
|
||||
|
||||
// CHECK(bit_stream.get(rc2));
|
||||
// CHECK_EQUAL(int(c2), int(rc2));
|
||||
//}
|
||||
|
||||
////*************************************************************************
|
||||
//TEST(put_get_object_global)
|
||||
//{
|
||||
// std::array<char, 2 * sizeof(Object)> storage;
|
||||
|
||||
// etl::bit_stream bit_stream(storage.data(), storage.size());
|
||||
|
||||
// Object object1 = { -1234, 2.71578369, 250 };
|
||||
// Object object2 = { 5678, 5.24685744, 126 };
|
||||
|
||||
// CHECK(etl::bit_stream_put(bit_stream, object1));
|
||||
// CHECK(etl::bit_stream_put(bit_stream, object2));
|
||||
|
||||
// Object object1a;
|
||||
// Object object2a;
|
||||
|
||||
// bit_stream.restart();
|
||||
|
||||
// CHECK(etl::bit_stream_get(bit_stream, object1a));
|
||||
// CHECK(etl::bit_stream_get(bit_stream, object2a));
|
||||
|
||||
// CHECK_EQUAL(object1, object1a);
|
||||
// CHECK_EQUAL(object2, object2a);
|
||||
//}
|
||||
CHECK_EQUAL(object2.i.value(), object2a.i.value());
|
||||
CHECK_EQUAL(object2.d.value(), object2a.d.value());
|
||||
CHECK_EQUAL(int(object2.c.value()), int(object2a.c.value()));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(write_read_multiple_float)
|
||||
@ -710,20 +966,20 @@ namespace
|
||||
|
||||
std::array<char, 12> storage;
|
||||
|
||||
etl::byte_stream_writer byte_stream_w(storage.data(), storage.size());
|
||||
etl::byte_stream_writer writer(storage.data(), storage.size());
|
||||
|
||||
byte_stream_w.write(f);
|
||||
byte_stream_w.write(d);
|
||||
writer.write(f);
|
||||
writer.write(d);
|
||||
|
||||
etl::byte_stream_reader byte_stream_r(storage.data(), storage.size());
|
||||
etl::byte_stream_reader reader(storage.data(), storage.size());
|
||||
|
||||
etl::optional<float> rf;
|
||||
etl::optional<double> rd;
|
||||
|
||||
CHECK(rf = byte_stream_r.read<float>());
|
||||
CHECK(rf = reader.read<float>());
|
||||
CHECK_CLOSE(f, rf.value(), 0.1f);
|
||||
|
||||
CHECK(rd = byte_stream_r.read<double>());
|
||||
CHECK(rd = reader.read<double>());
|
||||
CHECK_CLOSE(d, rd.value(), 0.1);
|
||||
}
|
||||
};
|
||||
|
||||
@ -2445,6 +2445,26 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Clang|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='MSVC Debug - Appveyor|Win32'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\sanity-check\byte_stream.h.t.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC - Small Strings|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug - No STL|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='MSVC Debug - Appveyor|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='MSVC Debug - No STL - Appveyor|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug - No Unit Tests|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug LLVM|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC - No STL - Built-ins|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug LLVM - No STL|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug LLVM - No STL - Built-ins|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug64|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug - String Truncation Is Error|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Clang|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug - No STL - Force No Advanced|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC - Force cpp03|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC - No Checks|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC - Force C++03|Win32'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\sanity-check\callback.h.t.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC - No STL - Built-ins|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug LLVM|Win32'">true</ExcludedFromBuild>
|
||||
|
||||
@ -2993,15 +2993,18 @@
|
||||
<ClCompile Include="..\sanity-check\wstring_stream.h.t.cpp">
|
||||
<Filter>Source Files\Sanity Checks</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\sanity-check\bip_buffer_spsc_atomic.h.t.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test_bip_buffer_spsc_atomic.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test_byte_stream.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\sanity-check\bip_buffer_spsc_atomic.h.t.cpp">
|
||||
<Filter>Source Files\Sanity Checks</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\sanity-check\byte_stream.h.t.cpp">
|
||||
<Filter>Source Files\Sanity Checks</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\library.properties">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user