-
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.
[#616] Fix java generator to check parameters in packed write
- Loading branch information
Showing
9 changed files
with
160 additions
and
12 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
47 changes: 47 additions & 0 deletions
47
test/language/parameterized_types/cpp/ParameterizedNestedInArrayTest.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,47 @@ | ||
#include "gtest/gtest.h" | ||
#include "parameterized_types/parameterized_nested_in_array/Holder.h" | ||
#include "zserio/BitStreamReader.h" | ||
#include "zserio/BitStreamWriter.h" | ||
#include "zserio/SerializeUtil.h" | ||
|
||
namespace parameterized_types | ||
{ | ||
namespace parameterized_nested_in_array | ||
{ | ||
|
||
class ParameterizedNestedInArrayTest : public ::testing::Test | ||
{ | ||
protected: | ||
zserio::BitBuffer bitBuffer = zserio::BitBuffer(1024); | ||
}; | ||
|
||
TEST_F(ParameterizedNestedInArrayTest, writeRead) | ||
{ | ||
Holder holder({{Element{Parameterized{6}}}}, {{Element{Parameterized{6}}}}); | ||
|
||
const auto bitBuffer = zserio::serialize(holder); | ||
const Holder readHolder = zserio::deserialize<Holder>(bitBuffer); | ||
|
||
ASSERT_EQ(holder, readHolder); | ||
} | ||
|
||
TEST_F(ParameterizedNestedInArrayTest, parameterCheckExceptionInArray) | ||
{ | ||
Holder holder({{Element{Parameterized{7}}}}, {{}}); | ||
holder.getElementArray().at(0).getParameterized().initialize(6); // wrong value | ||
|
||
zserio::BitStreamWriter writer(bitBuffer); | ||
ASSERT_THROW(holder.write(writer), zserio::CppRuntimeException); | ||
} | ||
|
||
TEST_F(ParameterizedNestedInArrayTest, parameterCheckExceptionInPackedArray) | ||
{ | ||
Holder holder({{}}, {{Element{Parameterized{7}}}}); | ||
holder.getElementPackedArray().at(0).getParameterized().initialize(6); // wrong value | ||
|
||
zserio::BitStreamWriter writer(bitBuffer); | ||
ASSERT_THROW(holder.write(writer), zserio::CppRuntimeException); | ||
} | ||
|
||
} // namespace parameterized_nested_in_array | ||
} // namespace parameterized_types |
48 changes: 48 additions & 0 deletions
48
...ava/parameterized_types/parameterized_nested_in_array/ParameterizedNestedInArrayTest.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,48 @@ | ||
package parameterized_types.parameterized_nested_in_array; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.io.IOException; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import zserio.runtime.ZserioError; | ||
import zserio.runtime.io.BitBuffer; | ||
import zserio.runtime.io.ByteArrayBitStreamWriter; | ||
import zserio.runtime.io.SerializeUtil; | ||
|
||
public class ParameterizedNestedInArrayTest | ||
{ | ||
@Test | ||
public void writeRead() | ||
{ | ||
final Holder holder = new Holder(new Element[] {new Element(new Parameterized((short)5, (long)6))}, | ||
new Element[] {new Element(new Parameterized((short)5, (long)6))}); | ||
|
||
final BitBuffer bitBuffer = SerializeUtil.serialize(holder); | ||
final Holder readHolder = SerializeUtil.deserialize(Holder.class, bitBuffer); | ||
assertEquals(holder, readHolder); | ||
} | ||
|
||
@Test | ||
public void parameterCheckExceptionInArray() throws IOException | ||
{ | ||
final Holder holder = | ||
new Holder(new Element[] {new Element(new Parameterized((short)6, (long)7))}, new Element[0]); | ||
|
||
final ByteArrayBitStreamWriter writer = new ByteArrayBitStreamWriter(); | ||
|
||
assertThrows(ZserioError.class, () -> holder.write(writer)); | ||
} | ||
|
||
@Test | ||
public void parameterCheckExceptionInPackedArray() throws IOException | ||
{ | ||
final Holder holder = | ||
new Holder(new Element[0], new Element[] {new Element(new Parameterized((short)6, (long)7))}); | ||
|
||
final ByteArrayBitStreamWriter writer = new ByteArrayBitStreamWriter(); | ||
|
||
assertThrows(ZserioError.class, () -> holder.write(writer)); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
test/language/parameterized_types/python/ParameterizedNestedInArrayTest.py
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,25 @@ | ||
import zserio | ||
|
||
import ParameterizedTypes | ||
|
||
|
||
class ParameterizedNestedInArrayTest(ParameterizedTypes.TestCase): | ||
def testWriteRead(self): | ||
holder = self.api.Holder( | ||
[self.api.Element(self.api.Parameterized(5, 6))], [self.api.Element(self.api.Parameterized(5, 6))] | ||
) | ||
bitBuffer = zserio.serialize(holder) | ||
readHolder = zserio.deserialize(self.api.Holder, bitBuffer) | ||
self.assertEqual(holder, readHolder) | ||
|
||
def testParameterCheckExceptionInArray(self): | ||
holder = self.api.Holder([self.api.Element(self.api.Parameterized(6, 7))], []) | ||
writer = zserio.BitStreamWriter() | ||
with self.assertRaises(zserio.PythonRuntimeException): | ||
holder.write(writer) | ||
|
||
def testParameterCheckExceptionInPackedArray(self): | ||
holder = self.api.Holder([], [self.api.Element(self.api.Parameterized(6, 7))]) | ||
writer = zserio.BitStreamWriter() | ||
with self.assertRaises(zserio.PythonRuntimeException): | ||
holder.write(writer) |
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
17 changes: 17 additions & 0 deletions
17
test/language/parameterized_types/zs/parameterized_types/parameterized_nested_in_array.zs
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,17 @@ | ||
package parameterized_types.parameterized_nested_in_array; | ||
|
||
struct Parameterized(uint8 param) | ||
{ | ||
uint32 field : field > param; | ||
}; | ||
|
||
struct Element | ||
{ | ||
Parameterized(5) parameterized; | ||
}; | ||
|
||
struct Holder | ||
{ | ||
Element elementArray[]; | ||
packed Element elementPackedArray[]; | ||
}; |