2 The software in this package is distributed under the GNU General
3 Public License version 2 (with a special exception described below).
5 A copy of GNU General Public License (GPL) is included in this distribution,
6 in the file COPYING.GPL.
8 As a special exception, if other files instantiate templates or use macros
9 or inline functions from this file, or you compile this file and link it
10 with other works to produce a work based on this file, this file
11 does not by itself cause the resulting work to be covered
12 by the GNU General Public License.
14 However the source code for this file must still be made available
15 in accordance with section (3) of the GNU General Public License.
17 This exception does not invalidate any other reasons why a work based
18 on this file might be covered by the GNU General Public License.
21 #define BOOST_TEST_MAIN
22 #define BOOST_TEST_DYN_LINK
26 #include <boost/test/unit_test.hpp>
27 #include <boost/asio/io_service.hpp>
28 #include <boost/asio/ip/address.hpp>
30 #include "host/pingprotocol.h"
31 #include "dns/hostaddress.h"
32 #include "dns/dnsmaster.h"
33 #include "dns/dnscache.h"
34 #include "dns/resolverbase.h"
36 //------------------------------------------------------------------------------
38 //------------------------------------------------------------------------------
42 // TODO: try to run this only once for test suite
45 // only create if it does not exist yet
46 DnsMasterItem master = DnsMaster::get_instance();
49 boost::asio::ip::address name_server =
50 boost::asio::ip::address::from_string("127.0.0.1");
51 int resolved_ip_ttl_threshold = 3;
52 int max_address_resolution_attempts = 2;
53 std::string cache_file = DO_NOT_USE_CACHE_FILE;
54 IoServiceItem io_serv;
57 DnsMaster::create_master(io_serv,
59 resolved_ip_ttl_threshold,
60 max_address_resolution_attempts,
62 master = DnsMaster::get_instance();
65 BOOST_CHECK_EQUAL( master->get_resolved_ip_ttl_threshold(),
66 resolved_ip_ttl_threshold );
67 BOOST_CHECK_EQUAL( master->get_max_address_resolution_attempts(),
68 max_address_resolution_attempts );
72 //------------------------------------------------------------------------------
74 //------------------------------------------------------------------------------
76 BOOST_AUTO_TEST_SUITE( TestDns )
78 BOOST_AUTO_TEST_CASE( create_master )
83 BOOST_AUTO_TEST_CASE( create_v4 )
88 std::string hostname = "www.intra2net.com";
89 ResolverItem resolver = DnsMaster::get_instance()
90 ->get_resolver_for(hostname, PingProtocol_ICMP);
91 BOOST_CHECK_EQUAL( resolver->get_hostname(), hostname );
92 BOOST_CHECK( !resolver->is_resolving() );
94 // cancel should have no effect
95 resolver->cancel_resolve();
96 BOOST_CHECK( !resolver->is_resolving() );
98 // should not have any ips since cache did not load anything
99 BOOST_CHECK_EQUAL( resolver->get_resolved_ip_count(), 0 );
100 BOOST_CHECK( !resolver->have_up_to_date_ip() );
101 std::string no_ip = "0.0.0.0";
102 BOOST_CHECK_EQUAL( resolver->get_next_ip().get_ip().to_string(), no_ip );
105 BOOST_AUTO_TEST_SUITE_END()