Skip to content

Commit

Permalink
[#654] Improve without_writer_code test to catch bug in auto optionals
Browse files Browse the repository at this point in the history
  • Loading branch information
mikir committed Jul 26, 2024
1 parent 2864326 commit 33d6960
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 12 deletions.
19 changes: 17 additions & 2 deletions test/arguments/without_writer_code/cpp/WithoutWriterCodeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,9 @@ class WithoutWriterCode : public ::testing::Test
// Tile
writer.writeBits(VERSION_AVAILABILITY, 3);
writer.writeBits(VERSION, 8);
writer.writeBits(6, 32); // numElementsOffset
writer.writeBool(true);
writer.writeBits(OPTIONAL_VERSION_INFO, 8);
writer.writeBits(3 + 4, 32); // numElementsOffset
writer.alignTo(8);
writer.writeBits(NUM_ELEMENTS, 32);

Expand Down Expand Up @@ -339,8 +341,10 @@ class WithoutWriterCode : public ::testing::Test

void checkTile(const Tile& tile)
{
ASSERT_EQ(VERSION, tile.getVersion());
ASSERT_EQ(VERSION_AVAILABILITY, tile.getVersionAvailability().getValue());
ASSERT_EQ(VERSION, tile.getVersion());
ASSERT_EQ(OPTIONAL_VERSION_INFO, tile.getOptionalVersionInfo());

ASSERT_EQ(NUM_ELEMENTS, tile.getNumElements());

const auto& data = tile.getData();
Expand Down Expand Up @@ -377,6 +381,7 @@ class WithoutWriterCode : public ::testing::Test
static const int32_t TILE_ID_AMERICA;
static const uint8_t VERSION_AVAILABILITY;
static const uint8_t VERSION;
static const uint8_t OPTIONAL_VERSION_INFO;
static const uint32_t NUM_ELEMENTS;
static const uint16_t PARAMS0;
static const uint16_t PARAMS1;
Expand All @@ -391,6 +396,7 @@ const int32_t WithoutWriterCode::TILE_ID_EUROPE = 99;
const int32_t WithoutWriterCode::TILE_ID_AMERICA = 11;
const uint8_t WithoutWriterCode::VERSION_AVAILABILITY = 0x01;
const uint8_t WithoutWriterCode::VERSION = 8;
const uint8_t WithoutWriterCode::OPTIONAL_VERSION_INFO = 0xBA;
const uint32_t WithoutWriterCode::NUM_ELEMENTS = 2;
const uint16_t WithoutWriterCode::PARAMS0 = 13;
const uint16_t WithoutWriterCode::PARAMS1 = 21;
Expand Down Expand Up @@ -614,6 +620,11 @@ TEST_F(WithoutWriterCode, checkTileMethods)
ASSERT_METHOD_NOT_PRESENT(PATH, type, "void setVersionString(", "void Tile::setVersionString(");
ASSERT_METHOD_NOT_PRESENT(PATH, type, "bool isVersionStringSet(", "bool Tile::isVersionStringSet(");
ASSERT_METHOD_NOT_PRESENT(PATH, type, "void resetVersionString(", "void Tile::resetVersionString(");
ASSERT_METHOD_NOT_PRESENT(PATH, type, "void setOptionalVersionInfo(", "void Tile::setOptionalVersionInfo(");
ASSERT_METHOD_NOT_PRESENT(
PATH, type, "bool isOptionalVersionInfoSet(", "bool Tile::isOptionalVersionInfoSet(");
ASSERT_METHOD_NOT_PRESENT(
PATH, type, "void resetOptionalVersionInfo(", "void Tile::resetOptionalVersionInfo(");
ASSERT_METHOD_NOT_PRESENT(PATH, type, "void setNumElements(", "void Tile::setNumElements(");
ASSERT_METHOD_NOT_PRESENT(PATH, type, "void setData(", "void Tile::setData(");
ASSERT_METHOD_NOT_PRESENT(PATH, type, "size_t initializeOffsets(", "size_t Tile::initializeOffsets(");
Expand Down Expand Up @@ -644,6 +655,10 @@ TEST_F(WithoutWriterCode, checkTileMethods)
ASSERT_METHOD_PRESENT(PATH, type, MethodNames::GET_VERSION_STRING_DECLARATION,
MethodNames::GET_VERSION_STRING_DEFINITION);
ASSERT_METHOD_PRESENT(PATH, type, "bool isVersionStringUsed(", "bool Tile::isVersionStringUsed(");
ASSERT_METHOD_PRESENT(
PATH, type, "uint8_t getOptionalVersionInfo(", "uint8_t Tile::getOptionalVersionInfo(");
ASSERT_METHOD_PRESENT(
PATH, type, "bool isOptionalVersionInfoUsed(", "bool Tile::isOptionalVersionInfoUsed(");
ASSERT_METHOD_PRESENT(PATH, type, "uint32_t getNumElementsOffset(", "uint32_t Tile::getNumElementsOffset(");
ASSERT_METHOD_PRESENT(PATH, type, "uint32_t getNumElements(", "uint32_t Tile::getNumElements(");
ASSERT_METHOD_PRESENT(PATH, type, "& getOffsets() const", "& Tile::getOffsets() const");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ public void checkTile()
assertMethodNotPresent(Tile.class, "write(");
assertMethodNotPresent(Tile.class, "setVersion(");
assertMethodNotPresent(Tile.class, "isVersionSet(");
assertMethodNotPresent(Tile.class, "setVersionString(");
assertMethodNotPresent(Tile.class, "isVersionStringSet(");
assertMethodNotPresent(Tile.class, "setOptionalVersionInfo(");
assertMethodNotPresent(Tile.class, "isOptionalVersionInfoSet(");
assertMethodNotPresent(Tile.class, "setNumElementsOffset(");
assertMethodNotPresent(Tile.class, "setVersionString(");
assertMethodNotPresent(Tile.class, "isVersionStringSet(");
Expand All @@ -172,6 +176,8 @@ public void checkTile()
assertMethodPresent(Tile.class, "getNumElementsOffset()");
assertMethodPresent(Tile.class, "getNumElements()");
assertMethodPresent(Tile.class, "getVersion()");
assertMethodPresent(Tile.class, "getVersionString()");
assertMethodPresent(Tile.class, "getOptionalVersionInfo()");
assertMethodPresent(Tile.class, "read(zserio.runtime.io.BitStreamReader)");
}

Expand Down Expand Up @@ -319,7 +325,9 @@ private void writeTile(BitStreamWriter writer) throws IOException
// Tile
writer.writeBits(VERSION_AVAILABILITY, 3);
writer.writeBits((long)VERSION, 8);
writer.writeBits(6, 32); // numElementsOffset
writer.writeBool(true);
writer.writeBits((long)OPTIONAL_VERSION_INFO, 8);
writer.writeBits(3 + 4, 32); // numElementsOffset
writer.alignTo(8);
writer.writeBits(NUM_ELEMENTS, 32);

Expand Down Expand Up @@ -358,8 +366,9 @@ private void writeTile(BitStreamWriter writer) throws IOException

private void checkTile(Tile tile)
{
assertEquals(VERSION, tile.getVersion().shortValue());
assertEquals(VERSION_AVAILABILITY, tile.getVersionAvailability().getValue());
assertEquals(VERSION, tile.getVersion().shortValue());
assertEquals(OPTIONAL_VERSION_INFO, tile.getOptionalVersionInfo().shortValue());
assertEquals(NUM_ELEMENTS, tile.getNumElements());

final ItemChoiceHolder[] data = tile.getData();
Expand All @@ -385,8 +394,9 @@ private void checkTile(Tile tile)
private static final String BLOB_NAME = "without_writer_code.blob";
private static final int TILE_ID_EUROPE = 99;
private static final int TILE_ID_AMERICA = 11;
private static final short VERSION = 8;
private static final byte VERSION_AVAILABILITY = 1;
private static final short VERSION = 8;
private static final short OPTIONAL_VERSION_INFO = 0xBA;
private static final long NUM_ELEMENTS = 2;
private static final int PARAMS[] = {13, 21};
private static final long EXTRA_PARAM = 42;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ def testTileMethods(self):
assertMethodPresent(self, userType, "bitsizeof")

assertPropertyPresent(self, userType, "version", readOnly=True)
assertPropertyPresent(self, userType, "version_string", readOnly=True)
assertPropertyPresent(self, userType, "optional_version_info", readOnly=True)
assertPropertyPresent(self, userType, "num_elements_offset", readOnly=True)
assertPropertyPresent(self, userType, "num_elements", readOnly=True)
assertPropertyPresent(self, userType, "data", readOnly=True)
Expand Down Expand Up @@ -226,7 +228,9 @@ def _writeTile(self, writer):
# Tile
writer.write_bits(VERSION_AVAILABILITY, 3)
writer.write_bits(VERSION, 8)
writer.write_bits(6, 32) # numElementsOffset
writer.write_bool(True)
writer.write_bits(OPTIONAL_VERSION_INFO, 8)
writer.write_bits(3 + 4, 32) # numElementsOffset
writer.alignto(8)
writer.write_bits(NUM_ELEMENTS, 32)

Expand Down Expand Up @@ -258,6 +262,7 @@ def _writeTile(self, writer):
def _checkTile(self, tile):
self.assertEqual(VERSION, tile.version)
self.assertEqual(NUM_ELEMENTS, tile.num_elements)
self.assertEqual(OPTIONAL_VERSION_INFO, tile.optional_version_info)

data = tile.data
self.assertEqual(NUM_ELEMENTS, len(data))
Expand Down Expand Up @@ -285,6 +290,7 @@ def _checkTile(self, tile):
TILE_ID_AMERICA = 11
VERSION_AVAILABILITY = 1
VERSION = 8
OPTIONAL_VERSION_INFO = 0xBA
NUM_ELEMENTS = 2
PARAMS = [13, 21]
EXTRA_PARAM = 42
6 changes: 1 addition & 5 deletions test/arguments/without_writer_code/zs/without_writer_code.zs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ union ExtraParamUnion
uint32 value32;
};

struct ItemWithOptionalField
{
optional uint16 opt;
};

struct Item(ItemType itemType)
{
uint16 param;
Expand All @@ -49,6 +44,7 @@ struct Tile
VersionAvailability versionAvailability;
uint8 version if valueof(versionAvailability & VersionAvailability.VERSION_NUMBER) != 0;
string versionString if valueof(versionAvailability & VersionAvailability.VERSION_STRING) != 0;
optional uint8 optionalVersionInfo;

uint32 numElementsOffset;

Expand Down
2 changes: 1 addition & 1 deletion test/data

0 comments on commit 33d6960

Please sign in to comment.