-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
structure data initializer, fix optionals
- Loading branch information
Showing
9 changed files
with
219 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
add_library(default_values_zs STATIC ${TEST_ZS_ROOT}/default_values.zs) | ||
zserio_generate_cpp( | ||
TARGET default_values_zs | ||
SRC_DIR ${TEST_ZS_ROOT} | ||
GEN_DIR ${CMAKE_CURRENT_BINARY_DIR}/gen | ||
EXTRA_ARGS ${ZSERIO_EXTRA_ARGS} | ||
GENERATED_SOURCES_VAR GENERATED_SOURCES | ||
OUTPUT_VAR ZSERIO_LOG | ||
ERROR_VAR ZSERIO_LOG | ||
) | ||
target_link_libraries(default_values_zs PUBLIC ZserioCpp17Runtime) | ||
if (ZSERIO_LOG) | ||
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/zserio_log.txt "${ZSERIO_LOG}") | ||
check_zserio_warnings("${ZSERIO_LOG}" 0) | ||
endif () | ||
|
||
add_custom_test(default_values | ||
DEPENDS | ||
default_values_zs | ||
SOURCES | ||
${CMAKE_CURRENT_SOURCE_DIR}/cpp/StructureDefaultValuesTest.cpp | ||
GENERATED_SOURCES | ||
${GENERATED_SOURCES} | ||
) |
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,9 @@ | ||
google-explicit-constructor:gen/default_values/structure_default_values/Permission.h | ||
|
||
#hicpp-signed-bitwise:gen/default_values/structure_default_values/Permission.h | ||
|
||
#readability-make-member-function-const:gen/default_values/structure_default_values/StructureDefaultValues.cpp | ||
|
||
readability-uppercase-literal-suffix:gen/default_values/structure_default_values/StructureDefaultValues.cpp | ||
|
||
readability-simplify-boolean-expr:gen/default_values/structure_default_values/StructureDefaultValues.cpp |
98 changes: 98 additions & 0 deletions
98
test/language/default_values/cpp/StructureDefaultValuesTest.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,98 @@ | ||
#include "default_values/structure_default_values/BasicColor.h" | ||
#include "default_values/structure_default_values/Permission.h" | ||
#include "default_values/structure_default_values/StructureDefaultValues.h" | ||
#include "gtest/gtest.h" | ||
#include "zserio/BitStreamReader.h" | ||
#include "zserio/CppRuntimeException.h" | ||
|
||
namespace default_values | ||
{ | ||
namespace structure_default_values | ||
{ | ||
|
||
TEST(StructureDefaultValuesDataTest, checkDefaultBoolValue) | ||
{ | ||
StructureDefaultValues structureDefaultValues; | ||
ASSERT_EQ(true, structureDefaultValues.boolValue); | ||
} | ||
|
||
TEST(StructureDefaultValuesDataTest, checkDefaultBit4Value) | ||
{ | ||
StructureDefaultValues structureDefaultValues; | ||
ASSERT_EQ(0x0F, structureDefaultValues.bit4Value); | ||
} | ||
|
||
TEST(StructureDefaultValuesDataTest, checkDefaultInt16Value) | ||
{ | ||
StructureDefaultValues structureDefaultValues; | ||
ASSERT_EQ(0x0BEE, structureDefaultValues.int16Value); | ||
} | ||
|
||
TEST(StructureDefaultValuesDataTest, checkDefaultFloat16Value) | ||
{ | ||
StructureDefaultValues structureDefaultValues; | ||
float diff = 1.23F - structureDefaultValues.float16Value; | ||
if (diff < 0.0F) | ||
{ | ||
diff = -diff; | ||
} | ||
ASSERT_TRUE(diff <= std::numeric_limits<float>::epsilon()); | ||
} | ||
|
||
TEST(StructureDefaultValuesDataTest, checkDefaultFloat32Value) | ||
{ | ||
StructureDefaultValues structureDefaultValues; | ||
float diff = 1.234F - structureDefaultValues.float32Value; | ||
if (diff < 0.0F) | ||
{ | ||
diff = -diff; | ||
} | ||
ASSERT_TRUE(diff <= std::numeric_limits<float>::epsilon()); | ||
} | ||
|
||
TEST(StructureDefaultValuesDataTest, checkDefaultFloat64Value) | ||
{ | ||
StructureDefaultValues structureDefaultValues; | ||
double diff = 1.2345 - structureDefaultValues.float64Value; | ||
if (diff < 0.0) | ||
{ | ||
diff = -diff; | ||
} | ||
ASSERT_TRUE(diff <= std::numeric_limits<double>::epsilon()); | ||
} | ||
|
||
TEST(StructureDefaultValuesDataTest, checkDefaultStringValue) | ||
{ | ||
StructureDefaultValues structureDefaultValues; | ||
ASSERT_EQ("string", structureDefaultValues.stringValue); | ||
} | ||
|
||
TEST(StructureDefaultValuesDataTest, checkDefaultEnumValue) | ||
{ | ||
StructureDefaultValues structureDefaultValues; | ||
ASSERT_EQ(BasicColor::BLACK, structureDefaultValues.enumValue); | ||
} | ||
|
||
TEST(StructureDefaultValuesDataTest, checkDefaultBitmaskValue) | ||
{ | ||
StructureDefaultValues structureDefaultValues; | ||
ASSERT_EQ(Permission::Values::READ_WRITE, structureDefaultValues.bitmaskValue); | ||
} | ||
|
||
TEST(StructureDefaultValuesDataTest, operatorEquality) | ||
{ | ||
StructureDefaultValues structureDefaultValues1; | ||
StructureDefaultValues structureDefaultValues2; | ||
ASSERT_EQ(structureDefaultValues1, structureDefaultValues2); | ||
} | ||
|
||
TEST(StructureDefaultValuesDataTest, operatorLessThan) | ||
{ | ||
StructureDefaultValues structureDefaultValues1; | ||
StructureDefaultValues structureDefaultValues2; | ||
ASSERT_FALSE(structureDefaultValues1 < structureDefaultValues2); | ||
ASSERT_FALSE(structureDefaultValues2 < structureDefaultValues1); | ||
} | ||
|
||
} // namespace structure_default_values | ||
} // namespace default_values |