Skip to content

Commit

Permalink
DO-NOT-MERGE: test truncation fail
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasDebrunner committed Nov 21, 2023
1 parent 7b1e517 commit a3940b6
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion tests/Message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,22 @@ TEST_CASE("Message set creation") {
<field type="float[3]" name="float_arr_field">description</field>
<field type="int32_t[3]" name="int32_arr_field">description</field>
</message>
<message id="77" name="COMMAND_ACK">
<description>Report status of a command. Includes feedback whether the command was executed. The command microservice is documented at https://mavlink.io/en/services/command.html</description>
<field type="uint16_t" name="command" enum="MAV_CMD">Command ID (of acknowledged command).</field>
<field type="uint8_t" name="result" enum="MAV_RESULT">Result of command.</field>
<extensions/>
<field type="uint8_t" name="progress" invalid="UINT8_MAX" units="%">The progress percentage when result is MAV_RESULT_IN_PROGRESS. Values: [0-100], or UINT8_MAX if the progress is unknown.</field>
<field type="int32_t" name="result_param2">Additional result information. Can be set with a command-specific enum containing command-specific error reasons for why the command might be denied. If used, the associated enum must be documented in the corresponding MAV_CMD (this enum should have a 0 value to indicate "unused" or "unknown").</field>
<field type="uint8_t" name="target_system">System ID of the target recipient. This is the ID of the system that sent the command for which this COMMAND_ACK is an acknowledgement.</field>
<field type="uint8_t" name="target_component">Component ID of the target recipient. This is the ID of the system that sent the command for which this COMMAND_ACK is an acknowledgement.</field>
</message>
</messages>
</mavlink>
)"""");

REQUIRE(message_set.contains("BIG_MESSAGE"));
REQUIRE_EQ(message_set.size(), 1);
REQUIRE_EQ(message_set.size(), 2);

auto message = message_set.create("BIG_MESSAGE");
CHECK_EQ(message.id(), message_set.idForMessage("BIG_MESSAGE"));
Expand Down Expand Up @@ -236,4 +246,34 @@ TEST_CASE("Message set creation") {
message.set("char_arr_field", "Hello Worldo!");
CHECK_EQ(message.get<std::string>("char_arr_field"), "Hello Worldo!");
}

SUBCASE("Zero elision works") {
auto ack_message = message_set.create("COMMAND_ACK")({
{"command", 211},
{"result", 0},
{"progress", 0},
{"result_param2", 0},
{"target_system", 0},
{"target_component", 0}
});

int wire_size = ack_message.finalize(1, {2,3});
CHECK_EQ(wire_size, 13);

std::array<uint8_t, MessageDefinition::MAX_MESSAGE_SIZE> buffer{};
std::copy(ack_message.data(), ack_message.data() + wire_size, buffer.begin());

auto parsed_ack_message = ack_message._instantiateFromMemory(
ack_message.type(), ConnectionPartner{}, 11, std::move(buffer));

CHECK_EQ(parsed_ack_message.get<uint16_t>("command"), 211);
CHECK_EQ(parsed_ack_message.get<uint8_t>("result"), 0);
CHECK_EQ(parsed_ack_message.get<uint8_t>("progress"), 0);
CHECK_EQ(parsed_ack_message.get<int32_t>("result_param2"), 0);
CHECK_EQ(parsed_ack_message.get<uint8_t>("target_system"), 0);
CHECK_EQ(parsed_ack_message.get<uint8_t>("target_component"), 0);
}



}

0 comments on commit a3940b6

Please sign in to comment.