Skip to content

Commit

Permalink
MessageSet: add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasDebrunner committed Mar 14, 2024
1 parent a6d7af9 commit 18c7f65
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
1 change: 1 addition & 0 deletions gcovr.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
exclude-throw-branches = yes
exclude-unreachable-branches = yes
filter = include/mav
exclude = include/mav/rapidxml/*
exclude = include/mav/picosha2/*
2 changes: 1 addition & 1 deletion include/mav/MessageSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ namespace mav {
}


static bool _isPrefix(std::string_view prefix, std::string_view full) {
static bool _isPrefix(std::string_view prefix, std::string_view full) noexcept {
return prefix == full.substr(0, prefix.size());
}

Expand Down
45 changes: 43 additions & 2 deletions tests/MessageSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ TEST_CASE("Enum value encoding") {
CHECK_THROWS_AS(message_set.addFromXMLString(empty_value), mav::ParseError);
}

SUBCASE("Enum with invalid value") {
SUBCASE("Enum with invalid value 1") {
std::string invalid_value = R""""(
<mavlink>
<enums>
Expand All @@ -209,6 +209,35 @@ TEST_CASE("Enum value encoding") {
CHECK_THROWS_AS(message_set.addFromXMLString(invalid_value), mav::ParseError);
}

SUBCASE("Enum with invalid value 2") {
std::string invalid_value = R""""(
<mavlink>
<enums>
<enum name="MY_ENUM_INVALID_VALUE">
<entry value="thisiswrong" name="INVALID" />
</enum>
</enums>
</mavlink>
)"""";

MessageSet message_set;
CHECK_THROWS_AS(message_set.addFromXMLString(invalid_value), mav::ParseError);
}

SUBCASE("Enum with invalid value 3") {
std::string invalid_value = R""""(
<mavlink>
<enums>
<enum name="MY_ENUM_INVALID_VALUE">
<entry value="128thereismorecontent" name="INVALID" />
</enum>
</enums>
</mavlink>
)"""";

MessageSet message_set;
CHECK_THROWS_AS(message_set.addFromXMLString(invalid_value), mav::ParseError);
}

SUBCASE("Enum with overflow value") {
std::string invalid_value = R""""(
Expand All @@ -225,8 +254,20 @@ TEST_CASE("Enum value encoding") {
CHECK_THROWS_AS(message_set.addFromXMLString(invalid_value), mav::ParseError);
}

SUBCASE("Enum with non-base-2 exponential value") {
std::string invalid_value = R""""(
<mavlink>
<enums>
<enum name="MY_ENUM_INVALID_VALUE">
<entry value="3**3" name="INVALID" />
</enum>
</enums>
</mavlink>
)"""";


MessageSet message_set;
CHECK_THROWS_AS(message_set.addFromXMLString(invalid_value), mav::ParseError);
}

}

0 comments on commit 18c7f65

Please sign in to comment.