]> git.mxchange.org Git - simgear.git/blob - simgear/io/test_DNS.cxx
Initial commit for a DNS service resolver
[simgear.git] / simgear / io / test_DNS.cxx
1 #include <cstdlib>
2
3 #include <iostream>
4 #include <map>
5 #include <sstream>
6 #include <errno.h>
7
8 #include <boost/algorithm/string/case_conv.hpp>
9
10 #include <simgear/simgear_config.h>
11
12 #include "DNSClient.hxx"
13
14 #include "test_DNS.hxx"
15
16 #include <simgear/debug/logstream.hxx>
17
18 using std::cout;
19 using std::cerr;
20 using std::endl;
21
22 using namespace simgear;
23
24 #define COMPARE(a, b) \
25     if ((a) != (b))  { \
26         cerr << "failed:" << #a << " != " << #b << endl; \
27         cerr << "\tgot:'" << a << "'" << endl; \
28         exit(1); \
29     }
30
31
32 int main(int argc, char* argv[])
33 {
34     sglog().setLogLevels( SG_ALL, SG_DEBUG );
35
36     DNS::Client cl;
37
38     // test existing NAPTR
39     // fgtest.t3r.de.           600     IN      NAPTR   999 99 "U" "test" "!^.*$!http://dnstest.flightgear.org/!" .
40     {
41         DNS::NAPTRRequest * naptrRequest = new DNS::NAPTRRequest("fgtest.t3r.de");
42         DNS::Request_ptr r(naptrRequest);
43         cl.makeRequest(r);
44         while( !r->complete() )
45                 cl.update(0);
46
47         COMPARE(naptrRequest->entries.size(), 1 );
48         COMPARE(naptrRequest->entries[0]->order, 999 );
49         COMPARE(naptrRequest->entries[0]->preference, 99 );
50         COMPARE(naptrRequest->entries[0]->service, "test" );
51         COMPARE(naptrRequest->entries[0]->regexp, "!^.*$!http://dnstest.flightgear.org/!" );
52         COMPARE(naptrRequest->entries[0]->replacement, "" );
53     }
54
55     // test non-existing NAPTR
56     {
57         DNS::NAPTRRequest * naptrRequest = new DNS::NAPTRRequest("jurkxkqdiufqzpfvzqok.prozhqrlcaavbxifkkhf");
58         DNS::Request_ptr r(naptrRequest);
59         cl.makeRequest(r);
60         while( !r->complete() )
61                 cl.update(0);
62
63         COMPARE(naptrRequest->entries.size(), 0 );
64     }
65
66     cout << "all tests passed ok" << endl;
67     return EXIT_SUCCESS;
68 }