mavtables  0.2.1
MAVLink router and firewall.
test_mavlink.cpp
Go to the documentation of this file.
1 // MAVLink router and firewall.
2 // Copyright (C) 2018 Michael R. Shannon <mrshannon.aerospace@gmail.com>
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 
18 #include <catch.hpp>
19 
20 #include "mavlink.hpp"
21 
22 
23 TEST_CASE("'message_info' returns the message info structure.", "[mavlink]")
24 {
25  SECTION("When given a numeric message ID.")
26  {
27  REQUIRE(mavlink::name(0) == "HEARTBEAT");
28  REQUIRE(mavlink::name(4) == "PING");
29  REQUIRE(mavlink::name(11) == "SET_MODE");
30  REQUIRE(mavlink::name(41) == "MISSION_SET_CURRENT");
31  REQUIRE(mavlink::name(131) == "ENCAPSULATED_DATA");
32  REQUIRE(mavlink::name(321) == "PARAM_EXT_REQUEST_LIST");
33  }
34  SECTION("Throws and error when given an invalid message ID.")
35  {
36  // Currently #255 and #5000 are not valid message ID's.
37  REQUIRE_THROWS_AS(mavlink::name(255), std::invalid_argument);
38  REQUIRE_THROWS_WITH(mavlink::name(255), "Invalid packet ID (#255).");
39  REQUIRE_THROWS_AS(mavlink::name(5000), std::invalid_argument);
40  REQUIRE_THROWS_WITH(mavlink::name(5000), "Invalid packet ID (#5000).");
41  }
42  SECTION("When given a message name.")
43  {
44  REQUIRE(mavlink::id("HEARTBEAT") == 0);
45  REQUIRE(mavlink::id("PING") == 4);
46  REQUIRE(mavlink::id("SET_MODE") == 11);
47  REQUIRE(mavlink::id("MISSION_SET_CURRENT") == 41);
48  REQUIRE(mavlink::id("ENCAPSULATED_DATA") == 131);
49  REQUIRE(mavlink::id("PARAM_EXT_REQUEST_LIST") == 321);
50  }
51  SECTION("Throws and error when given an invalid message name.")
52  {
53  REQUIRE_THROWS_AS(
54  mavlink::id("CRAZY_MESSAGE_ID"), std::invalid_argument);
55  REQUIRE_THROWS_WITH(
56  mavlink::id("CRAZY_MESSAGE_ID"),
57  "Invalid packet name (\"CRAZY_MESSAGE_ID\").");
58  }
59 }