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 1a8c472
Showing 1 changed file with 43 additions and 2 deletions.
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 1a8c472

Please sign in to comment.