-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#667] Fix choice tag clashing in packing context (Java & C++)
- Loading branch information
Showing
12 changed files
with
176 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
test/extensions/language/array_types/cpp/ChoiceTagClashTest.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#include "choice_tag_clash/ChoiceTagClash.h" | ||
#include "gtest/gtest.h" | ||
#include "zserio/SerializeUtil.h" | ||
|
||
namespace choice_tag_clash | ||
{ | ||
|
||
using allocator_type = ChoiceTagClash::allocator_type; | ||
template <typename T> | ||
using vector_type = zserio::vector<T, allocator_type>; | ||
using BitBuffer = zserio::BasicBitBuffer<zserio::RebindAlloc<allocator_type, uint8_t>>; | ||
|
||
class ChoiceTagClashTest : public ::testing::Test | ||
{ | ||
protected: | ||
ChoiceTagClash createChoiceTagClash() | ||
{ | ||
ChoiceTagClash choiceTagClash; | ||
fillChoices(choiceTagClash.getChoices()); | ||
fillUnions(choiceTagClash.getUnions()); | ||
return choiceTagClash; | ||
} | ||
|
||
static void fillChoices(vector_type<TestChoice>& choices) | ||
{ | ||
for (size_t i = 0; i < NUM_CHOICES; ++i) | ||
{ | ||
choices.emplace_back(); | ||
if (i % 2 == 0) | ||
{ | ||
choices.back().setChoiceTag(static_cast<uint32_t>(i)); | ||
} | ||
else | ||
{ | ||
choices.back().setStringField("text " + zserio::toString<allocator_type>(i)); | ||
} | ||
} | ||
} | ||
|
||
static void fillUnions(vector_type<TestUnion>& unions) | ||
{ | ||
for (size_t i = 0; i < NUM_UNIONS; ++i) | ||
{ | ||
unions.emplace_back(); | ||
if (i % 2 == 0) | ||
{ | ||
unions.back().setChoiceTag(static_cast<uint32_t>(i)); | ||
} | ||
else | ||
{ | ||
unions.back().setStringField("text " + zserio::toString<allocator_type>(i)); | ||
} | ||
} | ||
} | ||
|
||
private: | ||
static constexpr size_t NUM_CHOICES = 10; | ||
static constexpr size_t NUM_UNIONS = 13; | ||
}; | ||
|
||
constexpr size_t ChoiceTagClashTest::NUM_CHOICES; | ||
constexpr size_t ChoiceTagClashTest::NUM_UNIONS; | ||
|
||
TEST_F(ChoiceTagClashTest, writeRead) | ||
{ | ||
ChoiceTagClash choiceTagClash = createChoiceTagClash(); | ||
|
||
BitBuffer bitBuffer = zserio::serialize(choiceTagClash); | ||
ChoiceTagClash readChoiceTagClash = zserio::deserialize<ChoiceTagClash>(bitBuffer); | ||
|
||
ASSERT_EQ(choiceTagClash, readChoiceTagClash); | ||
} | ||
|
||
} // namespace choice_tag_clash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ZSERIO_ARGS=-withoutCrossExtensionCheck |
61 changes: 61 additions & 0 deletions
61
test/extensions/language/array_types/java/array_types/ChoiceTagClashTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package choice_tag_clash; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import zserio.runtime.io.BitBuffer; | ||
import zserio.runtime.io.SerializeUtil; | ||
|
||
public class ChoiceTagClashTest | ||
{ | ||
@Test | ||
public void writeRead() | ||
{ | ||
final ChoiceTagClash choiceTagClash = new ChoiceTagClash(createChoices(), createUnions()); | ||
|
||
final BitBuffer bitBuffer = SerializeUtil.serialize(choiceTagClash); | ||
final ChoiceTagClash readChoiceTagClash = SerializeUtil.deserialize(ChoiceTagClash.class, bitBuffer); | ||
|
||
assertEquals(choiceTagClash, readChoiceTagClash); | ||
} | ||
|
||
private TestChoice[] createChoices() | ||
{ | ||
final TestChoice[] choices = new TestChoice[NUM_CHOICES]; | ||
for (int i = 0; i < NUM_CHOICES; ++i) | ||
{ | ||
choices[i] = new TestChoice(i % 2 == 0); | ||
if (i % 2 == 0) | ||
{ | ||
choices[i].setChoiceTag(i); | ||
} | ||
else | ||
{ | ||
choices[i].setStringField("text " + i); | ||
} | ||
} | ||
return choices; | ||
} | ||
|
||
private TestUnion[] createUnions() | ||
{ | ||
final TestUnion[] unions = new TestUnion[NUM_UNIONS]; | ||
for (int i = 0; i < NUM_UNIONS; ++i) | ||
{ | ||
unions[i] = new TestUnion(); | ||
if (i % 2 == 0) | ||
{ | ||
unions[i].setChoiceTag(i); | ||
} | ||
else | ||
{ | ||
unions[i].setStringField("text " + i); | ||
} | ||
} | ||
return unions; | ||
} | ||
|
||
private static final int NUM_CHOICES = 10; | ||
private static final int NUM_UNIONS = 13; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ZSERIO_ARGS=-withoutCrossExtensionCheck |