1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
#ifndef BOOST_TEST_DYN_LINK
#define BOOST_TEST_DYN_LINK
#endif
#define BOOST_TEST_NO_MAIN
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <boost/test/unit_test.hpp>
#include "test-common.hh"
#include "secpoll.hh"
BOOST_AUTO_TEST_SUITE(test_secpoll_cc)
static bool checkBasicMessage1(const PDNSException& ex)
{
BOOST_CHECK_EQUAL(ex.reason, "Had empty answer on NOERROR RCODE");
return true;
}
static bool checkBasicMessage2(const PDNSException& ex)
{
BOOST_CHECK_EQUAL(ex.reason, "RCODE was " + RCode::to_s(1));
return true;
}
static bool checkBasicMessage3(const PDNSException& ex)
{
BOOST_CHECK_EQUAL(ex.reason, "No TXT record found in response");
return true;
}
static bool checkBasicMessage4(const PDNSException& ex)
{
BOOST_CHECK(ex.reason.find("Could not parse status number: stoi") == 0);
return true;
}
static bool checkBasicMessage5(const PDNSException& ex)
{
BOOST_CHECK(ex.reason.find("Could not parse status number: stoi") == 0);
return true;
}
BOOST_AUTO_TEST_CASE(test_secpoll_basic)
{
BOOST_CHECK(!isReleaseVersion(""));
BOOST_CHECK(isReleaseVersion(".."));
BOOST_CHECK(!isReleaseVersion("..."));
int status = 0;
std::string message;
BOOST_CHECK_EXCEPTION(processSecPoll(0, std::vector<DNSRecord>(), status, message), PDNSException, checkBasicMessage1);
BOOST_CHECK_EXCEPTION(processSecPoll(1, std::vector<DNSRecord>(), status, message), PDNSException, checkBasicMessage2);
std::vector<DNSRecord> v;
addRecordToList(v, DNSName("aname"), QType::A, "1.2.3.4");
BOOST_CHECK_EXCEPTION(processSecPoll(0, v, status, message), PDNSException, checkBasicMessage3);
v.clear();
addRecordToList(v, DNSName("aname"), QType::TXT, "");
BOOST_CHECK_EXCEPTION(processSecPoll(0, v, status, message), PDNSException, checkBasicMessage4);
v.clear();
addRecordToList(v, DNSName("aname"), QType::TXT, "1NOQUOTES");
processSecPoll(0, v, status, message);
BOOST_CHECK_EQUAL(status, 1);
BOOST_CHECK_EQUAL(message, "");
v.clear();
addRecordToList(v, DNSName("aname"), QType::TXT, "\"1OK\"");
processSecPoll(0, v, status, message);
BOOST_CHECK_EQUAL(status, 1);
BOOST_CHECK_EQUAL(message, "");
v.clear();
addRecordToList(v, DNSName("aname"), QType::TXT, "\"1 OK\"");
processSecPoll(0, v, status, message);
BOOST_CHECK_EQUAL(status, 1);
BOOST_CHECK_EQUAL(message, "OK");
v.clear();
addRecordToList(v, DNSName("aname"), QType::TXT, "\"X OK\"");
BOOST_CHECK_EXCEPTION(processSecPoll(0, v, status, message), PDNSException, checkBasicMessage5);
}
BOOST_AUTO_TEST_SUITE_END();
|