-
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.
- Loading branch information
1 parent
636cd8e
commit 2e20c35
Showing
4 changed files
with
118 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
add_library(with_bit_position_zs STATIC zs/with_bit_position.zs) | ||
zserio_generate_cpp( | ||
TARGET with_bit_position_zs | ||
SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/zs | ||
GEN_DIR ${CMAKE_CURRENT_BINARY_DIR}/gen | ||
EXTRA_ARGS -withoutSourcesAmalgamation -withTypeInfoCode -withReflectionCode -withBitPosition ${ZSERIO_EXTRA_ARGS} | ||
GENERATED_SOURCES_VAR GENERATED_SOURCES | ||
OUTPUT_VAR ZSERIO_LOG | ||
ERROR_VAR ZSERIO_LOG | ||
) | ||
target_link_libraries(with_bit_position_zs PUBLIC ZserioCppRuntime) | ||
target_include_directories(with_bit_position_zs SYSTEM PRIVATE ${SQLITE_INCDIR}) | ||
if (ZSERIO_LOG) | ||
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/zserio_log.txt "${ZSERIO_LOG}") | ||
check_zserio_warnings("${ZSERIO_LOG}" 0) | ||
endif () | ||
|
||
add_custom_test(with_bit_position | ||
DEPENDS | ||
with_bit_position_zs | ||
SOURCES | ||
${CMAKE_CURRENT_SOURCE_DIR}/cpp/WithBitPositionTest.cpp | ||
GENERATED_SOURCES | ||
${GENERATED_SOURCES} | ||
) |
Empty file.
80 changes: 80 additions & 0 deletions
80
test/arguments/with_bit_position/cpp/WithBitPositionTest.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,80 @@ | ||
#include <vector> | ||
|
||
#include "gtest/gtest.h" | ||
#include "test_utils/Assertions.h" | ||
#include "with_bit_position/Item.h" | ||
#include "with_bit_position/ItemHolder.h" | ||
#include "zserio/BitStreamReader.h" | ||
#include "zserio/BitStreamWriter.h" | ||
|
||
namespace with_bit_position | ||
{ | ||
|
||
class WithBitPosition : public ::testing::Test | ||
{ | ||
protected: | ||
Item readItem() | ||
{ | ||
std::vector<uint8_t> buffer; | ||
buffer.resize(16); | ||
|
||
zserio::BitStreamWriter writer(buffer.data(), buffer.size()); | ||
|
||
Item tmp; | ||
tmp.write(writer); | ||
|
||
zserio::BitStreamReader reader(buffer.data(), buffer.size()); | ||
|
||
return Item(reader); | ||
} | ||
|
||
ItemHolder readItemHolder() | ||
{ | ||
std::vector<uint8_t> buffer; | ||
buffer.resize(32); | ||
|
||
zserio::BitStreamWriter writer(buffer.data(), buffer.size()); | ||
|
||
std::vector<Item> items; | ||
items.emplace_back(); | ||
items.emplace_back(); | ||
|
||
ItemHolder tmp; | ||
tmp.setSize(static_cast<decltype(tmp.getSize())>(items.size())); | ||
tmp.setItems(items); | ||
tmp.write(writer); | ||
|
||
zserio::BitStreamReader reader(buffer.data(), buffer.size()); | ||
|
||
return ItemHolder(reader); | ||
} | ||
}; | ||
|
||
static const char* const BLOB_NAME = "arguments/with_bit_position/with_bit_position.blob"; | ||
static const char* const PATH = "arguments/with_bit_position/gen/with_bit_position/"; | ||
|
||
TEST_F(WithBitPosition, checkItemTypeMethods) | ||
{ | ||
ASSERT_METHOD_PRESENT(PATH, "Item", "size_t bitPosition(", "size_t bitPosition("); | ||
ASSERT_METHOD_PRESENT(PATH, "ItemHolder", "size_t bitPosition(", "size_t bitPosition("); | ||
} | ||
|
||
TEST_F(WithBitPosition, readRootPosition) | ||
{ | ||
auto item = readItem(); | ||
|
||
ASSERT_EQ(item.bitPosition(), 0); | ||
} | ||
|
||
TEST_F(WithBitPosition, readChildPosition) | ||
{ | ||
auto holder = readItemHolder(); | ||
|
||
ASSERT_EQ(holder.bitPosition(), 0); | ||
|
||
size_t offset = 16; // The size field | ||
ASSERT_EQ(holder.getItems().at(0).bitPosition(), offset + 0); | ||
ASSERT_EQ(holder.getItems().at(1).bitPosition(), offset + holder.getItems().at(0).bitSizeOf()); | ||
} | ||
|
||
} // namespace with_bit_position |
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,13 @@ | ||
package with_bit_position; | ||
|
||
struct Item | ||
{ | ||
uint32 value; | ||
optional int8 opt; | ||
}; | ||
|
||
struct ItemHolder | ||
{ | ||
uint16 size; | ||
Item items[size]; | ||
}; |