Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
mikir committed May 29, 2024
1 parent 56f0301 commit 0b7dba2
Showing 1 changed file with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,49 @@
namespace zserio
{

struct Blob
{
struct View
{
explicit View(Blob& storage) :
m_storage(storage)
{
std::cout << "Size = " << m_storage.m_field.size() << std::endl;
}

const std::string& getField() const
{
return m_storage.m_field;
}

Blob& m_storage;
};

std::string m_field;
};

template <typename T>
struct StorageView : public T::View
{
using Base = typename T::View;

StorageView() :
Base(m_storage)
{}

explicit StorageView(T& storage) :
Base(m_storage),
m_storage(storage)
{}

explicit StorageView(T&& storage) :
Base(m_storage),
m_storage(std::move(storage))
{}

T m_storage;
};

TEST(BitPositionUtilTest, alignTo)
{
const size_t bitPosition = 5;
Expand All @@ -17,6 +60,15 @@ TEST(BitPositionUtilTest, alignTo)
EXPECT_EQ(6, alignTo(6, bitPosition));
EXPECT_EQ(7, alignTo(7, bitPosition));
EXPECT_EQ(8, alignTo(8, bitPosition));

Blob b{"this is a test with some long string to check allocation"};

std::cout << b.m_field << std::endl << std::hex << static_cast<const void*>(b.m_field.data()) << std::endl;

StorageView<Blob> blob(b);

std::cout << blob.getField() << std::endl
<< std::hex << static_cast<const void*>(blob.getField().data()) << std::endl;
}

} // namespace zserio

0 comments on commit 0b7dba2

Please sign in to comment.