Skip to content

Commit

Permalink
cpp-rt: Add bitPosition unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
johannes-wolf committed Jul 18, 2024
1 parent 636cd8e commit e21ccb6
Show file tree
Hide file tree
Showing 127 changed files with 4,181 additions and 794 deletions.
9 changes: 9 additions & 0 deletions compiler/extensions/cpp/runtime/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ set(TEST_OBJECT_SRCS
test_object/polymorphic_allocator/ArrayObject.h
test_object/polymorphic_allocator/ArrayParamObject.cpp
test_object/polymorphic_allocator/ArrayParamObject.h
test_object/polymorphic_allocator/BitPositionObject.cpp
test_object/polymorphic_allocator/BitPositionObject.h
test_object/polymorphic_allocator/BitPositionSubObject.h
test_object/polymorphic_allocator/BitPositionSubObject.cpp
test_object/polymorphic_allocator/CreatorBitmask.cpp
test_object/polymorphic_allocator/CreatorBitmask.h
test_object/polymorphic_allocator/CreatorEnum.cpp
Expand Down Expand Up @@ -87,6 +91,10 @@ set(TEST_OBJECT_SRCS
test_object/std_allocator/ArrayObject.h
test_object/std_allocator/ArrayParamObject.cpp
test_object/std_allocator/ArrayParamObject.h
test_object/std_allocator/BitPositionObject.cpp
test_object/std_allocator/BitPositionObject.h
test_object/std_allocator/BitPositionSubObject.cpp
test_object/std_allocator/BitPositionSubObject.h
test_object/std_allocator/CreatorBitmask.cpp
test_object/std_allocator/CreatorBitmask.h
test_object/std_allocator/CreatorEnum.cpp
Expand Down Expand Up @@ -187,6 +195,7 @@ set(ZSERIO_CPP_RUNTIME_TEST_SRCS
zserio/SizeConvertUtilTest.cpp
zserio/WalkerTest.cpp
zserio/ZserioTreeCreatorTest.cpp
zserio/BitPositionTest.cpp
)

set(ZSERIO_CPP_RUNTIME_TEST_HEADERS
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Automatically generated by Zserio C++ generator version 1.0.2 using Zserio core 2.14.1.
* Generator setup: writerCode, pubsubCode, serviceCode, sqlCode, typeInfoCode, reflectionCode, polymorphicAllocator.
* Generator setup: writerCode, pubsubCode, serviceCode, sqlCode, typeInfoCode, reflectionCode, bitPosition, polymorphicAllocator.
*/

#include <zserio/HashCodeUtil.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
/**
* Automatically generated by Zserio C++ generator version 1.0.2 using Zserio core 2.14.1.
* Generator setup: writerCode, pubsubCode, serviceCode, sqlCode, typeInfoCode, reflectionCode, polymorphicAllocator.
* Generator setup: writerCode, pubsubCode, serviceCode, sqlCode, typeInfoCode, reflectionCode, bitPosition, polymorphicAllocator.
*/

#ifndef TEST_OBJECT_POLYMORPHIC_ALLOCATOR_ARRAY_BITMASK_H
#define TEST_OBJECT_POLYMORPHIC_ALLOCATOR_ARRAY_BITMASK_H

#include <zserio/CppRuntimeVersion.h>
#if CPP_EXTENSION_RUNTIME_VERSION_NUMBER != 1000002
#error Version mismatch between Zserio runtime library and Zserio C++ generator!
#error Please update your Zserio runtime library to the version 1.0.2.
#endif

#include <zserio/BitStreamReader.h>
#include <zserio/BitStreamWriter.h>
#include <zserio/DeltaContext.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Automatically generated by Zserio C++ generator version 1.0.2 using Zserio core 2.14.1.
* Generator setup: writerCode, pubsubCode, serviceCode, sqlCode, typeInfoCode, reflectionCode, polymorphicAllocator.
* Generator setup: writerCode, pubsubCode, serviceCode, sqlCode, typeInfoCode, reflectionCode, bitPosition, polymorphicAllocator.
*/

#include <zserio/StringConvertUtil.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
/**
* Automatically generated by Zserio C++ generator version 1.0.2 using Zserio core 2.14.1.
* Generator setup: writerCode, pubsubCode, serviceCode, sqlCode, typeInfoCode, reflectionCode, polymorphicAllocator.
* Generator setup: writerCode, pubsubCode, serviceCode, sqlCode, typeInfoCode, reflectionCode, bitPosition, polymorphicAllocator.
*/

#ifndef TEST_OBJECT_POLYMORPHIC_ALLOCATOR_ARRAY_ENUM_H
#define TEST_OBJECT_POLYMORPHIC_ALLOCATOR_ARRAY_ENUM_H

#include <zserio/CppRuntimeVersion.h>
#if CPP_EXTENSION_RUNTIME_VERSION_NUMBER != 1000002
#error Version mismatch between Zserio runtime library and Zserio C++ generator!
#error Please update your Zserio runtime library to the version 1.0.2.
#endif

#include <array>

#include <zserio/Enums.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Automatically generated by Zserio C++ generator version 1.0.2 using Zserio core 2.14.1.
* Generator setup: writerCode, pubsubCode, serviceCode, sqlCode, typeInfoCode, reflectionCode, polymorphicAllocator.
* Generator setup: writerCode, pubsubCode, serviceCode, sqlCode, typeInfoCode, reflectionCode, bitPosition, polymorphicAllocator.
*/

#include <zserio/StringConvertUtil.h>
Expand All @@ -21,28 +21,30 @@ namespace polymorphic_allocator
{

ArrayHolder::ArrayHolder(const allocator_type& allocator) noexcept :
m_areChildrenInitialized(false),
m_enumArray_(allocator),
m_bitmaskArray_(allocator),
m_packedArray_(allocator),
m_packedParamArray_(allocator)
m_areChildrenInitialized(false),
m_enumArray_(allocator),
m_bitmaskArray_(allocator),
m_packedArray_(allocator),
m_packedParamArray_(allocator)
{
}

ArrayHolder::ArrayHolder(::zserio::BitStreamReader& in, const allocator_type& allocator) :
m_areChildrenInitialized(true),
m_enumArray_(readEnumArray(in, allocator)),
m_bitmaskArray_(readBitmaskArray(in, allocator)),
m_packedArray_(readPackedArray(in, allocator)),
m_packedParamArray_(readPackedParamArray(in, allocator))
m_bitPosition(in.getBitPosition()),
m_areChildrenInitialized(true),
m_enumArray_(readEnumArray(in, allocator)),
m_bitmaskArray_(readBitmaskArray(in, allocator)),
m_packedArray_(readPackedArray(in, allocator)),
m_packedParamArray_(readPackedParamArray(in, allocator))
{
}

ArrayHolder::ArrayHolder(const ArrayHolder& other) :
m_enumArray_(other.m_enumArray_),
m_bitmaskArray_(other.m_bitmaskArray_),
m_packedArray_(other.m_packedArray_),
m_packedParamArray_(::zserio::NoInit, other.m_packedParamArray_)
m_bitPosition(other.m_bitPosition),
m_enumArray_(other.m_enumArray_),
m_bitmaskArray_(other.m_bitmaskArray_),
m_packedArray_(other.m_packedArray_),
m_packedParamArray_(::zserio::NoInit, other.m_packedParamArray_)
{
if (other.m_areChildrenInitialized)
{
Expand Down Expand Up @@ -73,10 +75,11 @@ ArrayHolder& ArrayHolder::operator=(const ArrayHolder& other)
}

ArrayHolder::ArrayHolder(ArrayHolder&& other) :
m_enumArray_(::std::move(other.m_enumArray_)),
m_bitmaskArray_(::std::move(other.m_bitmaskArray_)),
m_packedArray_(::std::move(other.m_packedArray_)),
m_packedParamArray_(::zserio::NoInit, ::std::move(other.m_packedParamArray_))
m_bitPosition(::std::move(other.m_bitPosition)),
m_enumArray_(::std::move(other.m_enumArray_)),
m_bitmaskArray_(::std::move(other.m_bitmaskArray_)),
m_packedArray_(::std::move(other.m_packedArray_)),
m_packedParamArray_(::zserio::NoInit, ::std::move(other.m_packedParamArray_))
{
if (other.m_areChildrenInitialized)
{
Expand All @@ -90,6 +93,7 @@ ArrayHolder::ArrayHolder(ArrayHolder&& other) :

ArrayHolder& ArrayHolder::operator=(ArrayHolder&& other)
{
m_bitPosition = ::std::move(other.m_bitPosition);
m_enumArray_ = ::std::move(other.m_enumArray_);
m_bitmaskArray_ = ::std::move(other.m_bitmaskArray_);
m_packedArray_ = ::std::move(other.m_packedArray_);
Expand All @@ -107,11 +111,13 @@ ArrayHolder& ArrayHolder::operator=(ArrayHolder&& other)
}

ArrayHolder::ArrayHolder(::zserio::PropagateAllocatorT,
const ArrayHolder& other, const allocator_type& allocator) :
m_enumArray_(::zserio::allocatorPropagatingCopy(other.m_enumArray_, allocator)),
m_bitmaskArray_(::zserio::allocatorPropagatingCopy(other.m_bitmaskArray_, allocator)),
m_packedArray_(::zserio::allocatorPropagatingCopy(other.m_packedArray_, allocator)),
m_packedParamArray_(::zserio::NoInit, ::zserio::allocatorPropagatingCopy(::zserio::NoInit, other.m_packedParamArray_, allocator))
const ArrayHolder& other,
const allocator_type& allocator) :
m_bitPosition(other.m_bitPosition),
m_enumArray_(::zserio::allocatorPropagatingCopy(other.m_enumArray_, allocator)),
m_bitmaskArray_(::zserio::allocatorPropagatingCopy(other.m_bitmaskArray_, allocator)),
m_packedArray_(::zserio::allocatorPropagatingCopy(other.m_packedArray_, allocator)),
m_packedParamArray_(::zserio::NoInit, ::zserio::allocatorPropagatingCopy(::zserio::NoInit, other.m_packedParamArray_, allocator))
{
if (other.m_areChildrenInitialized)
{
Expand All @@ -121,6 +127,7 @@ ArrayHolder::ArrayHolder(::zserio::PropagateAllocatorT,
{
m_areChildrenInitialized = false;
}
(void)other;
}

const ::zserio::pmr::ITypeInfo& ArrayHolder::typeInfo()
Expand Down Expand Up @@ -266,6 +273,11 @@ ::zserio::pmr::IReflectableConstPtr ArrayHolder::reflectable(const allocator_typ
return ::zserio::pmr::AnyHolder(::std::cref(m_object), alloc);
}

size_t bitPosition() const override
{
return m_object.bitPosition();
}

private:
const ::test_object::polymorphic_allocator::ArrayHolder& m_object;
};
Expand Down Expand Up @@ -406,6 +418,11 @@ ::zserio::pmr::IReflectablePtr ArrayHolder::reflectable(const allocator_type& al
return ::zserio::pmr::AnyHolder(::std::ref(m_object), alloc);
}

size_t bitPosition() const override
{
return m_object.bitPosition();
}

private:
::test_object::polymorphic_allocator::ArrayHolder& m_object;
};
Expand Down Expand Up @@ -598,6 +615,10 @@ void ArrayHolder::write(::zserio::BitStreamWriter& out) const
m_packedArray_.writePacked(*this, out);
m_packedParamArray_.writePacked(*this, out);
}
size_t ArrayHolder::bitPosition() const
{
return m_bitPosition;
}

void ArrayHolder::ZserioElementFactory_packedArray::create(ArrayHolder&,
::zserio::pmr::vector<::test_object::polymorphic_allocator::ArrayObject>& array,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
/**
* Automatically generated by Zserio C++ generator version 1.0.2 using Zserio core 2.14.1.
* Generator setup: writerCode, pubsubCode, serviceCode, sqlCode, typeInfoCode, reflectionCode, polymorphicAllocator.
* Generator setup: writerCode, pubsubCode, serviceCode, sqlCode, typeInfoCode, reflectionCode, bitPosition, polymorphicAllocator.
*/

#ifndef TEST_OBJECT_POLYMORPHIC_ALLOCATOR_ARRAY_HOLDER_H
#define TEST_OBJECT_POLYMORPHIC_ALLOCATOR_ARRAY_HOLDER_H

#include <zserio/CppRuntimeVersion.h>
#if CPP_EXTENSION_RUNTIME_VERSION_NUMBER != 1000002
#error Version mismatch between Zserio runtime library and Zserio C++ generator!
#error Please update your Zserio runtime library to the version 1.0.2.
#endif

#include <zserio/Traits.h>
#include <zserio/BitStreamReader.h>
#include <zserio/BitStreamWriter.h>
Expand Down Expand Up @@ -108,6 +114,14 @@ class ArrayHolder

void write(::zserio::BitStreamWriter& out) const;

/**
* Get the source offset and size of the structure in bits.
* For objects not loaded from a blob, the offest is 0.
*
* \return Tuple of the objects offset and size in bits.
*/
size_t bitPosition() const;

private:
class ZserioElementFactory_packedArray
{
Expand Down Expand Up @@ -162,6 +176,7 @@ class ArrayHolder
ZserioArrayType_packedParamArray readPackedParamArray(::zserio::BitStreamReader& in,
const allocator_type& allocator);

size_t m_bitPosition = 0;
bool m_areChildrenInitialized;
ZserioArrayType_enumArray m_enumArray_;
ZserioArrayType_bitmaskArray m_bitmaskArray_;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Automatically generated by Zserio C++ generator version 1.0.2 using Zserio core 2.14.1.
* Generator setup: writerCode, pubsubCode, serviceCode, sqlCode, typeInfoCode, reflectionCode, polymorphicAllocator.
* Generator setup: writerCode, pubsubCode, serviceCode, sqlCode, typeInfoCode, reflectionCode, bitPosition, polymorphicAllocator.
*/

#include <zserio/StringConvertUtil.h>
Expand All @@ -21,24 +21,29 @@ namespace polymorphic_allocator
{

ArrayObject::ArrayObject(const allocator_type&) noexcept :
m_value_(uint32_t())
m_value_(uint32_t())
{
}

ArrayObject::ArrayObject(::zserio::BitStreamReader& in, const allocator_type&) :
m_value_(readValue(in))
m_bitPosition(in.getBitPosition()),
m_value_(readValue(in))
{
}

ArrayObject::ArrayObject(ArrayObject::ZserioPackingContext& context, ::zserio::BitStreamReader& in, const allocator_type&) :
m_value_(readValue(context, in))
m_bitPosition(in.getBitPosition()),
m_value_(readValue(context, in))
{
}

ArrayObject::ArrayObject(::zserio::PropagateAllocatorT,
const ArrayObject& other, const allocator_type& allocator) :
m_value_(::zserio::allocatorPropagatingCopy(other.m_value_, allocator))
const ArrayObject& other,
const allocator_type& allocator) :
m_bitPosition(other.m_bitPosition),
m_value_(::zserio::allocatorPropagatingCopy(other.m_value_, allocator))
{
(void)other;
}

const ::zserio::pmr::ITypeInfo& ArrayObject::typeInfo()
Expand Down Expand Up @@ -121,6 +126,11 @@ ::zserio::pmr::IReflectableConstPtr ArrayObject::reflectable(const allocator_typ
return ::zserio::pmr::AnyHolder(::std::cref(m_object), alloc);
}

size_t bitPosition() const override
{
return m_object.bitPosition();
}

private:
const ::test_object::polymorphic_allocator::ArrayObject& m_object;
};
Expand Down Expand Up @@ -206,6 +216,11 @@ ::zserio::pmr::IReflectablePtr ArrayObject::reflectable(const allocator_type& al
return ::zserio::pmr::AnyHolder(::std::ref(m_object), alloc);
}

size_t bitPosition() const override
{
return m_object.bitPosition();
}

private:
::test_object::polymorphic_allocator::ArrayObject& m_object;
};
Expand Down Expand Up @@ -307,6 +322,10 @@ void ArrayObject::write(ArrayObject::ZserioPackingContext& context, ::zserio::Bi
{
context.getValue().write<::zserio::BitFieldArrayTraits<uint32_t, UINT8_C(31)>>(out, m_value_);
}
size_t ArrayObject::bitPosition() const
{
return m_bitPosition;
}

uint32_t ArrayObject::readValue(::zserio::BitStreamReader& in)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
/**
* Automatically generated by Zserio C++ generator version 1.0.2 using Zserio core 2.14.1.
* Generator setup: writerCode, pubsubCode, serviceCode, sqlCode, typeInfoCode, reflectionCode, polymorphicAllocator.
* Generator setup: writerCode, pubsubCode, serviceCode, sqlCode, typeInfoCode, reflectionCode, bitPosition, polymorphicAllocator.
*/

#ifndef TEST_OBJECT_POLYMORPHIC_ALLOCATOR_ARRAY_OBJECT_H
#define TEST_OBJECT_POLYMORPHIC_ALLOCATOR_ARRAY_OBJECT_H

#include <zserio/CppRuntimeVersion.h>
#if CPP_EXTENSION_RUNTIME_VERSION_NUMBER != 1000002
#error Version mismatch between Zserio runtime library and Zserio C++ generator!
#error Please update your Zserio runtime library to the version 1.0.2.
#endif

#include <zserio/Traits.h>
#include <zserio/BitStreamReader.h>
#include <zserio/BitStreamWriter.h>
Expand Down Expand Up @@ -92,11 +98,20 @@ class ArrayObject
void write(::zserio::BitStreamWriter& out) const;
void write(ZserioPackingContext& context, ::zserio::BitStreamWriter& out) const;

/**
* Get the source offset and size of the structure in bits.
* For objects not loaded from a blob, the offest is 0.
*
* \return Tuple of the objects offset and size in bits.
*/
size_t bitPosition() const;

private:
uint32_t readValue(::zserio::BitStreamReader& in);
uint32_t readValue(ZserioPackingContext& context,
::zserio::BitStreamReader& in);

size_t m_bitPosition = 0;
uint32_t m_value_;
};

Expand Down
Loading

0 comments on commit e21ccb6

Please sign in to comment.