Skip to content

Commit

Permalink
Implement new optional test to catch validate fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mikir committed Nov 26, 2024
1 parent ad609e1 commit 3ac93d6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/language/optional_members/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ add_custom_test(optional_members
optional_members_zs
SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/cpp/AutoOptionalTest.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cpp/OptionalComplexExpressionTest.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cpp/OptionalRecursionTest.cpp
GENERATED_SOURCES
${GENERATED_SOURCES}
Expand Down
2 changes: 2 additions & 0 deletions test/language/optional_members/ClangTidySuppressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ bugprone-exception-escape:gen/optional_members/optional_recursion/Block.cpp
bugprone-exception-escape:gen/optional_members/optional_recursion/Block.h

misc-no-recursion # reports also tested_release

google-explicit-constructor:gen/optional_members/optional_complex_expression/Permission.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "gtest/gtest.h"
#include "optional_members/optional_complex_expression/Container.h"
#include "test_utils/TestUtility.h"

namespace optional_members
{
namespace optional_complex_expression
{

class OptionalComplexExpressionTest : public ::testing::Test
{
protected:
static constexpr zserio::BitSize CONTAINER_WITHOUT_OPTIONAL_BIT_SIZE = 5;
static constexpr zserio::BitSize CONTAINER_WITH_OPTIONAL_BIT_SIZE = 9;
static constexpr zserio::UInt4 EXTRA_DATA_VALUE = 0x0F;
};

TEST_F(OptionalComplexExpressionTest, withoutOptional)
{
Container data{Permission::Values::READ, {}};
ASSERT_EQ(CONTAINER_WITHOUT_OPTIONAL_BIT_SIZE, zserio::detail::bitSizeOf(zserio::View<Container>(data)));

test_utils::writeReadTest(data);
}

TEST_F(OptionalComplexExpressionTest, withOptional)
{
Container data{Permission::Values::WRITE, EXTRA_DATA_VALUE};
ASSERT_EQ(CONTAINER_WITH_OPTIONAL_BIT_SIZE, zserio::detail::bitSizeOf(zserio::View<Container>(data)));

test_utils::writeReadTest(data);
}

} // namespace optional_complex_expression
} // namespace optional_members

0 comments on commit 3ac93d6

Please sign in to comment.