mavtables  0.2.1
MAVLink router and firewall.
test_DNSLookupError.cpp
Go to the documentation of this file.
1 // MAVLink router and firewall.
2 // Copyright (C) 2017-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 "DNSLookupError.hpp"
24 
25 
26 [[noreturn]] static void throw_lookup_error(std::string hostname)
27 {
28  throw DNSLookupError(hostname);
29 }
30 
31 
32 TEST_CASE("DNSLookupError's can be thrown.", "[DNSLookupError]")
33 {
34  SECTION("And can be caught.")
35  {
36  REQUIRE_THROWS(throw_lookup_error("example.com"));
37  }
38  SECTION("And can be caught as DNSLookupError.")
39  {
40  REQUIRE_THROWS_AS(throw_lookup_error("example.com"), DNSLookupError);
41  }
42  SECTION("And can be caught as std::exception.")
43  {
44  REQUIRE_THROWS_AS(throw_lookup_error("example.com"), std::exception);
45  }
46 }
47 
48 
49 TEST_CASE("The 'what' method gives the unresolved hostname.",
50  "[DNSLookupError]")
51 {
52  REQUIRE_THROWS_WITH(
53  throw_lookup_error("example.com"),
54  "DNSLookupError: Could not find an IP address for \"example.com\"");
55 }
56 
57 
58 // Required for complete function coverage.
59 TEST_CASE("Run dynamic destructors (DNSLookupError).", "[DNSLookupError]")
60 {
61  DNSLookupError *dns = nullptr;
62  REQUIRE_NOTHROW(dns = new DNSLookupError("error"));
63  REQUIRE_NOTHROW(delete dns);
64 }
TEST_CASE("DNSLookupError's can be thrown.", "[DNSLookupError]")