mavtables  0.2.1
MAVLink router and firewall.
test_PartialSendError.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 <exception>
19 #include <string>
20 
21 #include <catch.hpp>
22 
23 #include "PartialSendError.hpp"
24 
25 
26 [[noreturn]] static void throw_partial_send_error(
27  unsigned long bytes_sent, unsigned long total_bytes)
28 {
29  throw PartialSendError(bytes_sent, total_bytes);
30 }
31 
32 
33 TEST_CASE("PartialSendError's can be thrown.", "[PartialSendError]")
34 {
35  SECTION("And can be caught.")
36  {
37  REQUIRE_THROWS(throw_partial_send_error(50, 100));
38  }
39  SECTION("And can be caught as PartialSendError.")
40  {
41  REQUIRE_THROWS_AS(throw_partial_send_error(50, 100), PartialSendError);
42  }
43  SECTION("And can be caught as std::exception.")
44  {
45  REQUIRE_THROWS_AS(throw_partial_send_error(50, 100), std::exception);
46  }
47 }
48 
49 
50 TEST_CASE("PartialSendError's have a message.", "[PartialSendError]")
51 {
52  REQUIRE_THROWS_WITH(
53  throw_partial_send_error(10, 100), "Could only write 10 of 100 bytes.");
54  REQUIRE_THROWS_WITH(
55  throw_partial_send_error(20, 100), "Could only write 20 of 100 bytes.");
56  REQUIRE_THROWS_WITH(
57  throw_partial_send_error(30, 100), "Could only write 30 of 100 bytes.");
58  REQUIRE_THROWS_WITH(
59  throw_partial_send_error(40, 100), "Could only write 40 of 100 bytes.");
60  REQUIRE_THROWS_WITH(
61  throw_partial_send_error(50, 100), "Could only write 50 of 100 bytes.");
62  REQUIRE_THROWS_WITH(
63  throw_partial_send_error(60, 100), "Could only write 60 of 100 bytes.");
64  REQUIRE_THROWS_WITH(
65  throw_partial_send_error(70, 100), "Could only write 70 of 100 bytes.");
66  REQUIRE_THROWS_WITH(
67  throw_partial_send_error(80, 100), "Could only write 80 of 100 bytes.");
68  REQUIRE_THROWS_WITH(
69  throw_partial_send_error(90, 100), "Could only write 90 of 100 bytes.");
70 }
71 
72 
73 // Required for complete function coverage.
74 TEST_CASE("Run dynamic destructors (PartialSendError).", "[PartialSendError]")
75 {
76  PartialSendError *partial_send = nullptr;
77  REQUIRE_NOTHROW(partial_send = new PartialSendError(50, 100));
78  REQUIRE_NOTHROW(delete partial_send);
79 }
TEST_CASE("PartialSendError's can be thrown.", "[PartialSendError]")