hello-dns/tdns/tests.cc

55 lines
1.3 KiB
C++
Raw Normal View History

2018-04-13 16:03:07 +07:00
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include "catch.hpp"
2018-04-15 05:38:20 +07:00
#include "dnsmessages.hh"
2018-04-13 16:03:07 +07:00
#include "dns-storage.hh"
using namespace std;
TEST_CASE("DNSLabel equality", "[dnslabel]") {
DNSLabel a("www"), b("WWW");
REQUIRE(a==b);
REQUIRE(!(a<b));
REQUIRE(!(b<a));
}
TEST_CASE( "DNSName escaping", "[escapes]" ) {
DNSName test({"powerdns", "com."});
ostringstream str;
str<<test;
REQUIRE(str.str() == "powerdns.com\\..");
str=ostringstream();
const char zero[]="p\x0werdns";
DNSName test2({std::string(zero, sizeof(zero)-1), "com"});
str<<test2;
REQUIRE(str.str() == "p\\000werdns.com.");
};
2018-04-14 02:25:59 +07:00
TEST_CASE("DNSName operations", "[dnsname]") {
DNSName test({"www", "powerdns", "org"}), test2;
test2 = test;
REQUIRE(test2 == test);
test.pop_back();
REQUIRE(test == DNSName({"www", "powerdns"}));
REQUIRE(test2.makeRelative({"org"}));
REQUIRE(test2 == DNSName({"www", "powerdns"}));
}
2018-04-15 05:38:20 +07:00
TEST_CASE("DNS Messages", "[dnsmessage]") {
DNSName qname({"www", "powerdns", "com"}), rname;
DNSType rtype;
DNSMessageWriter dmw(qname, DNSType::SOA);
std::string ser = dmw.serialize();
DNSMessageReader dmr(ser);
dmr.getQuestion(rname, rtype);
REQUIRE(rname == qname);
REQUIRE(rtype == DNSType::SOA);
}