mavtables  0.2.1
MAVLink router and firewall.
test_RecursionError.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 "RecursionError.hpp"
24 
25 
26 [[noreturn]] static void throw_recursion_error(std::string message)
27 {
28  throw RecursionError(message);
29 }
30 
31 
32 TEST_CASE("RecursionError's can be thrown.", "[RecursionError]")
33 {
34  SECTION("And can be caught.")
35  {
36  REQUIRE_THROWS(throw_recursion_error("example"));
37  }
38  SECTION("And can be caught as DNSLookupError.")
39  {
40  REQUIRE_THROWS_AS(throw_recursion_error("example"), RecursionError);
41  }
42  SECTION("And can be caught as std::exception.")
43  {
44  REQUIRE_THROWS_AS(throw_recursion_error("example"), std::exception);
45  }
46 }
47 
48 
49 TEST_CASE("RecursionError's have a message.", "[RecursionError]")
50 {
51  REQUIRE_THROWS_WITH(throw_recursion_error("example"), "example");
52 }
53 
54 
55 // Required for complete function coverage.
56 TEST_CASE("Run dynamic destructors (RecursionError).", "[RecursionError]")
57 {
58  RecursionError *recursion = nullptr;
59  REQUIRE_NOTHROW(recursion = new RecursionError("error"));
60  REQUIRE_NOTHROW(delete recursion);
61 }
TEST_CASE("RecursionError's can be thrown.", "[RecursionError]")