Skip to content

Commit

Permalink
Implemented tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mikir committed Jan 14, 2025
1 parent d6ea959 commit 5a7c1ac
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 0 deletions.
56 changes: 56 additions & 0 deletions test/language/choice_types/cpp/UInt64ParamChoiceTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,62 @@ TEST_F(UInt64ParamChoiceTest, constructors)
}
}

TEST_F(UInt64ParamChoiceTest, copyConstructor)
{
UInt64ParamChoice data;
const VariantA value = 99;
data.emplace<ChoiceTag::CHOICE_valueA>(value);
UInt64ParamChoice dataCopy(data);
ASSERT_EQ(dataCopy, data);

zserio::View view(data, VARIANT_A_SELECTOR);
zserio::View viewCopy(view);
ASSERT_EQ(viewCopy, view);
}

TEST_F(UInt64ParamChoiceTest, assignmentOperator)
{
UInt64ParamChoice data;
const VariantA value = 99;
data.emplace<ChoiceTag::CHOICE_valueA>(value);
UInt64ParamChoice dataCopy;
dataCopy = data;
ASSERT_EQ(dataCopy, data);

zserio::View view(data, VARIANT_A_SELECTOR);
zserio::View viewCopy(UInt64ParamChoice{}, VARIANT_B_SELECTOR);
viewCopy = view;
ASSERT_EQ(viewCopy, view);
}

TEST_F(UInt64ParamChoiceTest, moveConstructor)
{
UInt64ParamChoice data;
const VariantA value = 99;
data.emplace<ChoiceTag::CHOICE_valueA>(value);
UInt64ParamChoice dataMoved(std::move(data));
ASSERT_EQ(value, zserio::get<ChoiceTag::CHOICE_valueA>(dataMoved));

zserio::View view(data, VARIANT_A_SELECTOR);
zserio::View viewMoved(std::move(view));
ASSERT_EQ(value, viewMoved.valueA());
}

TEST_F(UInt64ParamChoiceTest, moveAssignmentOperator)
{
UInt64ParamChoice data;
const VariantA value = 99;
data.emplace<ChoiceTag::CHOICE_valueA>(value);
UInt64ParamChoice dataMoved;
dataMoved = std::move(data);
ASSERT_EQ(value, zserio::get<ChoiceTag::CHOICE_valueA>(dataMoved));

zserio::View view(data, VARIANT_A_SELECTOR);
zserio::View viewMoved(UInt64ParamChoice{}, VARIANT_B_SELECTOR);
viewMoved = std::move(view);
ASSERT_EQ(value, viewMoved.valueA());
}

TEST_F(UInt64ParamChoiceTest, selector)
{
UInt64ParamChoice data;
Expand Down
12 changes: 12 additions & 0 deletions test/language/structure_types/cpp/SimpleStructureTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,18 @@ TEST_F(SimpleStructureDataTest, stdHash)
ASSERT_EQ(hasher(simpleStructure1), hasher(simpleStructure2));
}

TEST_F(SimpleStructureViewTest, assignmentOperator)
{
const uint8_t numberA = 0x07;
const uint8_t numberB = 0xFF;
const uint8_t numberC = 0x7F;
SimpleStructure simpleStructure(numberA, numberB, numberC);
zserio::View view(simpleStructure);
zserio::View viewCopy(SimpleStructure{0, 0, 0});
viewCopy = view;
ASSERT_EQ(viewCopy, view);
}

TEST_F(SimpleStructureViewTest, operatorEquality)
{
SimpleStructure simpleStructure1;
Expand Down
52 changes: 52 additions & 0 deletions test/language/union_types/cpp/SimpleUnionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,58 @@ TEST_F(SimpleUnionTest, constructors)
}
}

TEST_F(SimpleUnionTest, copyConstructor)
{
SimpleUnion data;
data.emplace<ChoiceTag::CHOICE_case1Field>(CASE1_FIELD);
SimpleUnion dataCopy(data);
ASSERT_EQ(dataCopy, data);

zserio::View view(data);
zserio::View viewCopy(view);
ASSERT_EQ(viewCopy, view);
}

TEST_F(SimpleUnionTest, assignmentOperator)
{
SimpleUnion data;
data.emplace<ChoiceTag::CHOICE_case1Field>(CASE1_FIELD);
SimpleUnion dataCopy;
dataCopy = data;
ASSERT_EQ(dataCopy, data);

zserio::View view(data);
zserio::View viewCopy(SimpleUnion{});
viewCopy = view;
ASSERT_EQ(viewCopy, view);
}

TEST_F(SimpleUnionTest, moveConstructor)
{
SimpleUnion data;
data.emplace<ChoiceTag::CHOICE_case1Field>(CASE1_FIELD);
SimpleUnion dataMoved(std::move(data));
ASSERT_EQ(CASE1_FIELD, zserio::get<ChoiceTag::CHOICE_case1Field>(dataMoved));

zserio::View view(data);
zserio::View viewMoved(std::move(view));
ASSERT_EQ(CASE1_FIELD, viewMoved.case1Field());
}

TEST_F(SimpleUnionTest, moveAssignmentOperator)
{
SimpleUnion data;
data.emplace<ChoiceTag::CHOICE_case1Field>(CASE1_FIELD);
SimpleUnion dataMoved;
dataMoved = std::move(data);
ASSERT_EQ(CASE1_FIELD, zserio::get<ChoiceTag::CHOICE_case1Field>(dataMoved));

zserio::View view(data);
zserio::View viewMoved(SimpleUnion{});
viewMoved = std::move(view);
ASSERT_EQ(CASE1_FIELD, viewMoved.case1Field());
}

TEST_F(SimpleUnionTest, zserioChoiceTag)
{
{
Expand Down

0 comments on commit 5a7c1ac

Please sign in to comment.