[svn] commit: r4133 - in /trunk: ./ src/bin/auth/tests/ src/bin/auth/tests/testdata/ src/bin/bind10/ src/bin/recurse/tests/ src/lib/asiolink/ src/lib/asiolink/internal/ src/lib/asiolink/internal/tests/ src/lib/asiolink/tests/ src/lib/log/ src/lib/python/isc/utils/ src/lib/testutils/
BIND 10 source code commits
bind10-changes at lists.isc.org
Mon Jan 3 19:38:45 UTC 2011
Author: jinmei
Date: Mon Jan 3 19:38:45 2011
New Revision: 4133
Log:
merged trac #448 (regression fix for clang++ build)
Added:
trunk/src/lib/asiolink/internal/Makefile.am
- copied unchanged from r4131, branches/trac448/src/lib/asiolink/internal/Makefile.am
trunk/src/lib/asiolink/internal/tests/
- copied from r4131, branches/trac448/src/lib/asiolink/internal/tests/
trunk/src/lib/testutils/srv_test.cc
- copied unchanged from r4131, branches/trac448/src/lib/testutils/srv_test.cc
Removed:
trunk/src/lib/asiolink/tests/udpdns_unittest.cc
trunk/src/lib/testutils/srv_unittest.h
Modified:
trunk/ (props changed)
trunk/configure.ac
trunk/src/bin/auth/tests/Makefile.am
trunk/src/bin/auth/tests/auth_srv_unittest.cc
trunk/src/bin/auth/tests/testdata/ (props changed)
trunk/src/bin/bind10/bind10.py.in (props changed)
trunk/src/bin/recurse/tests/ (props changed)
trunk/src/bin/recurse/tests/Makefile.am
trunk/src/bin/recurse/tests/recursor_config_unittest.cc
trunk/src/bin/recurse/tests/recursor_unittest.cc
trunk/src/lib/asiolink/ (props changed)
trunk/src/lib/asiolink/Makefile.am
trunk/src/lib/asiolink/tests/Makefile.am
trunk/src/lib/asiolink/tests/asiolink_unittest.cc
trunk/src/lib/log/ (props changed)
trunk/src/lib/python/isc/utils/ (props changed)
trunk/src/lib/testutils/ (props changed)
trunk/src/lib/testutils/Makefile.am
trunk/src/lib/testutils/README
trunk/src/lib/testutils/srv_test.h
Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac (original)
+++ trunk/configure.ac Mon Jan 3 19:38:45 2011
@@ -597,6 +597,8 @@
src/lib/Makefile
src/lib/asiolink/Makefile
src/lib/asiolink/tests/Makefile
+ src/lib/asiolink/internal/Makefile
+ src/lib/asiolink/internal/tests/Makefile
src/lib/bench/Makefile
src/lib/bench/example/Makefile
src/lib/bench/tests/Makefile
Modified: trunk/src/bin/auth/tests/Makefile.am
==============================================================================
--- trunk/src/bin/auth/tests/Makefile.am (original)
+++ trunk/src/bin/auth/tests/Makefile.am Mon Jan 3 19:38:45 2011
@@ -33,6 +33,7 @@
run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
run_unittests_LDADD = $(GTEST_LDADD)
run_unittests_LDADD += $(SQLITE_LIBS)
+run_unittests_LDADD += $(top_builddir)/src/lib/testutils/libtestutils.la
run_unittests_LDADD += $(top_builddir)/src/lib/datasrc/libdatasrc.la
run_unittests_LDADD += $(top_builddir)/src/lib/dns/libdns++.la
run_unittests_LDADD += $(top_builddir)/src/lib/asiolink/libasiolink.la
Modified: trunk/src/bin/auth/tests/auth_srv_unittest.cc
==============================================================================
--- trunk/src/bin/auth/tests/auth_srv_unittest.cc (original)
+++ trunk/src/bin/auth/tests/auth_srv_unittest.cc Mon Jan 3 19:38:45 2011
@@ -30,15 +30,19 @@
#include <datasrc/memory_datasrc.h>
#include <auth/auth_srv.h>
-#include <testutils/srv_unittest.h>
#include <auth/statistics.h>
+#include <dns/tests/unittest_util.h>
+#include <testutils/srv_test.h>
+
+using namespace std;
using namespace isc::cc;
using namespace isc::dns;
using namespace isc::dns::rdata;
using namespace isc::data;
using namespace isc::xfr;
using namespace asiolink;
+using namespace isc::testutils;
using isc::UnitTestUtil;
namespace {
@@ -54,6 +58,10 @@
AuthSrvTest() : server(true, xfrout), rrclass(RRClass::IN()) {
server.setXfrinSession(¬ify_session);
server.setStatisticsSession(&statistics_session);
+ }
+ virtual void processMessage() {
+ server.processMessage(*io_message, parse_message, response_obuffer,
+ &dnsserv);
}
MockSession statistics_session;
MockXfroutClient xfrout;
@@ -159,48 +167,52 @@
// Unsupported requests. Should result in NOTIMP.
TEST_F(AuthSrvTest, unsupportedRequest) {
- UNSUPPORTED_REQUEST_TEST;
+ unsupportedRequest();
}
// Simple API check
TEST_F(AuthSrvTest, verbose) {
- VERBOSE_TEST;
+ EXPECT_FALSE(server.getVerbose());
+ server.setVerbose(true);
+ EXPECT_TRUE(server.getVerbose());
+ server.setVerbose(false);
+ EXPECT_FALSE(server.getVerbose());
}
// Multiple questions. Should result in FORMERR.
TEST_F(AuthSrvTest, multiQuestion) {
- MULTI_QUESTION_TEST;
+ multiQuestion();
}
// Incoming data doesn't even contain the complete header. Must be silently
// dropped.
TEST_F(AuthSrvTest, shortMessage) {
- SHORT_MESSAGE_TEST;
+ shortMessage();
}
// Response messages. Must be silently dropped, whether it's a valid response
// or malformed or could otherwise cause a protocol error.
TEST_F(AuthSrvTest, response) {
- RESPONSE_TEST;
+ response();
}
// Query with a broken question
TEST_F(AuthSrvTest, shortQuestion) {
- SHORT_QUESTION_TEST;
+ shortQuestion();
}
// Query with a broken answer section
TEST_F(AuthSrvTest, shortAnswer) {
- SHORT_ANSWER_TEST;
+ shortAnswer();
}
// Query with unsupported version of EDNS.
TEST_F(AuthSrvTest, ednsBadVers) {
- EDNS_BADVERS_TEST;
+ ednsBadVers();
}
TEST_F(AuthSrvTest, AXFROverUDP) {
- AXFR_OVER_UDP_TEST;
+ axfrOverUDP();
}
TEST_F(AuthSrvTest, AXFRSuccess) {
Modified: trunk/src/bin/recurse/tests/Makefile.am
==============================================================================
--- trunk/src/bin/recurse/tests/Makefile.am (original)
+++ trunk/src/bin/recurse/tests/Makefile.am Mon Jan 3 19:38:45 2011
@@ -27,6 +27,7 @@
run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
run_unittests_LDADD = $(GTEST_LDADD)
run_unittests_LDADD += $(SQLITE_LIBS)
+run_unittests_LDADD += $(top_builddir)/src/lib/testutils/libtestutils.la
run_unittests_LDADD += $(top_builddir)/src/lib/datasrc/libdatasrc.la
run_unittests_LDADD += $(top_builddir)/src/lib/dns/libdns++.la
run_unittests_LDADD += $(top_builddir)/src/lib/asiolink/libasiolink.la
Modified: trunk/src/bin/recurse/tests/recursor_config_unittest.cc
==============================================================================
--- trunk/src/bin/recurse/tests/recursor_config_unittest.cc (original)
+++ trunk/src/bin/recurse/tests/recursor_config_unittest.cc Mon Jan 3 19:38:45 2011
@@ -12,10 +12,24 @@
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
-// $Id$
+#include <string>
+
+#include <gtest/gtest.h>
+
+#include <cc/data.h>
+
+#include <asiolink/asiolink.h>
#include <recurse/recursor.h>
-#include <testutils/srv_unittest.h>
+
+#include <dns/tests/unittest_util.h>
+#include <testutils/srv_test.h>
+
+using namespace std;
+using namespace isc::data;
+using namespace isc::testutils;
+using namespace asiolink;
+using isc::UnitTestUtil;
namespace {
class RecursorConfig : public ::testing::Test {
Modified: trunk/src/bin/recurse/tests/recursor_unittest.cc
==============================================================================
--- trunk/src/bin/recurse/tests/recursor_unittest.cc (original)
+++ trunk/src/bin/recurse/tests/recursor_unittest.cc Mon Jan 3 19:38:45 2011
@@ -12,10 +12,15 @@
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
-// $Id$
+#include <dns/name.h>
#include <recurse/recursor.h>
-#include <testutils/srv_unittest.h>
+#include <dns/tests/unittest_util.h>
+#include <testutils/srv_test.h>
+
+using namespace isc::dns;
+using namespace isc::testutils;
+using isc::UnitTestUtil;
namespace {
const char* const TEST_PORT = "53535";
@@ -23,48 +28,52 @@
class RecursorTest : public SrvTestBase{
protected:
RecursorTest() : server(){}
+ virtual void processMessage() {
+ server.processMessage(*io_message, parse_message, response_obuffer,
+ &dnsserv);
+ }
Recursor server;
};
// Unsupported requests. Should result in NOTIMP.
TEST_F(RecursorTest, unsupportedRequest) {
- UNSUPPORTED_REQUEST_TEST;
+ unsupportedRequest();
}
// Multiple questions. Should result in FORMERR.
TEST_F(RecursorTest, multiQuestion) {
- MULTI_QUESTION_TEST;
+ multiQuestion();
}
// Incoming data doesn't even contain the complete header. Must be silently
// dropped.
TEST_F(RecursorTest, shortMessage) {
- SHORT_MESSAGE_TEST;
+ shortMessage();
}
// Response messages. Must be silently dropped, whether it's a valid response
// or malformed or could otherwise cause a protocol error.
TEST_F(RecursorTest, response) {
- RESPONSE_TEST;
+ response();
}
// Query with a broken question
TEST_F(RecursorTest, shortQuestion) {
- SHORT_QUESTION_TEST;
+ shortQuestion();
}
// Query with a broken answer section
TEST_F(RecursorTest, shortAnswer) {
- SHORT_ANSWER_TEST;
+ shortAnswer();
}
// Query with unsupported version of EDNS.
TEST_F(RecursorTest, ednsBadVers) {
- EDNS_BADVERS_TEST;
+ ednsBadVers();
}
TEST_F(RecursorTest, AXFROverUDP) {
- AXFR_OVER_UDP_TEST;
+ axfrOverUDP();
}
TEST_F(RecursorTest, AXFRFail) {
Modified: trunk/src/lib/asiolink/Makefile.am
==============================================================================
--- trunk/src/lib/asiolink/Makefile.am (original)
+++ trunk/src/lib/asiolink/Makefile.am Mon Jan 3 19:38:45 2011
@@ -1,4 +1,4 @@
-SUBDIRS = . tests
+SUBDIRS = . tests internal
AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
AM_CPPFLAGS += $(BOOST_INCLUDES)
Modified: trunk/src/lib/asiolink/tests/Makefile.am
==============================================================================
--- trunk/src/lib/asiolink/tests/Makefile.am (original)
+++ trunk/src/lib/asiolink/tests/Makefile.am Mon Jan 3 19:38:45 2011
@@ -18,7 +18,6 @@
run_unittests_SOURCES = $(top_srcdir)/src/lib/dns/tests/unittest_util.h
run_unittests_SOURCES += $(top_srcdir)/src/lib/dns/tests/unittest_util.cc
run_unittests_SOURCES += asiolink_unittest.cc
-run_unittests_SOURCES += udpdns_unittest.cc
run_unittests_SOURCES += run_unittests.cc
run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
Modified: trunk/src/lib/asiolink/tests/asiolink_unittest.cc
==============================================================================
--- trunk/src/lib/asiolink/tests/asiolink_unittest.cc (original)
+++ trunk/src/lib/asiolink/tests/asiolink_unittest.cc Mon Jan 3 19:38:45 2011
@@ -17,6 +17,9 @@
#include <config.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+
#include <string.h>
#include <boost/lexical_cast.hpp>
@@ -32,19 +35,21 @@
#include <dns/buffer.h>
#include <dns/message.h>
+// IMPORTANT: We shouldn't directly use ASIO definitions in this test.
+// In particular, we must not include asio.hpp in this file.
+// The asiolink module is primarily intended to be a wrapper that hide the
+// details of the underlying implementations. We need to test the wrapper
+// level behaviors. In addition, some compilers reject to compile this file
+// if we include asio.hpp unless we specify a special compiler option.
+// If we need to test something at the level of underlying ASIO and need
+// their definition, that test should go to asiolink/internal/tests.
#include <asiolink/asiolink.h>
#include <asiolink/iosocket.h>
-#include <asiolink/internal/tcpdns.h>
-#include <asiolink/internal/udpdns.h>
-
-#include <asio.hpp>
using isc::UnitTestUtil;
using namespace std;
using namespace asiolink;
using namespace isc::dns;
-using namespace asio;
-using asio::ip::udp;
namespace {
const char* const TEST_SERVER_PORT = "53535";
@@ -330,10 +335,30 @@
// ... and this one will block until the send has completed
io_service_->run_one();
- // Now we attempt to recv() whatever was sent
- const int ret = recv(sock_, buffer, size, MSG_DONTWAIT);
+ // Now we attempt to recv() whatever was sent.
+ // XXX: there's no guarantee the receiving socket can immediately get
+ // the packet. Normally we can perform blocking recv to wait for it,
+ // but in theory it's even possible that the packet is lost.
+ // In order to prevent the test from hanging in such a worst case
+ // we add an ad hoc timeout.
+ const struct timeval timeo = { 10, 0 };
+ int recv_options = 0;
+ if (setsockopt(sock_, SOL_SOCKET, SO_RCVTIMEO, &timeo,
+ sizeof(timeo))) {
+ if (errno == ENOPROTOOPT) {
+ // Workaround for Solaris: it doesn't accept SO_RCVTIMEO
+ // with the error of ENOPROTOOPT. Since this is a workaround
+ // for rare error cases anyway, we simply switch to the
+ // "don't wait" mode. If we still find an error in recv()
+ // can happen often we'll consider a more complete solution.
+ recv_options = MSG_DONTWAIT;
+ } else {
+ isc_throw(IOError, "set RCVTIMEO failed: " << strerror(errno));
+ }
+ }
+ const int ret = recv(sock_, buffer, size, recv_options);
if (ret < 0) {
- isc_throw(IOError, "recvfrom failed");
+ isc_throw(IOError, "recvfrom failed: " << strerror(errno));
}
// Pass the message size back via the size parameter
@@ -411,8 +436,7 @@
// has completed.
class MockServer : public DNSServer {
public:
- explicit MockServer(asio::io_service& io_service,
- const asio::ip::address& addr, const uint16_t port,
+ explicit MockServer(IOService& io_service,
SimpleCallback* checkin = NULL,
DNSLookup* lookup = NULL,
DNSAnswer* answer = NULL) :
@@ -426,9 +450,7 @@
size_t length = 0)
{}
- void resume(const bool done) {
- done_ = done;
- io_.post(*this);
+ void resume(const bool) { // in our test this shouldn't be called
}
DNSServer* clone() {
@@ -443,7 +465,7 @@
}
protected:
- asio::io_service& io_;
+ IOService& io_;
bool done_;
private:
@@ -462,8 +484,8 @@
// This version of mock server just stops the io_service when it is resumed
class MockServerStop : public MockServer {
public:
- explicit MockServerStop(asio::io_service& io_service, bool* done) :
- MockServer(io_service, asio::ip::address(), 0),
+ explicit MockServerStop(IOService& io_service, bool* done) :
+ MockServer(io_service),
done_(done)
{}
@@ -511,7 +533,6 @@
string callback_address_;
vector<uint8_t> callback_data_;
int sock_;
-private:
struct addrinfo* res_;
};
@@ -640,14 +661,12 @@
// full code coverage including error cases.
TEST_F(ASIOLinkTest, recursiveSend) {
setDNSService(true, false);
- asio::io_service& io = io_service_->get_io_service();
// Note: We use the test prot plus one to ensure we aren't binding
// to the same port as the actual server
uint16_t port = boost::lexical_cast<uint16_t>(TEST_CLIENT_PORT);
- asio::ip::address addr = asio::ip::address::from_string(TEST_IPV4_ADDR);
-
- MockServer server(io, addr, port, NULL, NULL, NULL);
+
+ MockServer server(*io_service_);
RecursiveQuery rq(*dns_service_, singleAddress(TEST_IPV4_ADDR, port));
Question q(Name("example.com"), RRClass::IN(), RRType::TXT());
@@ -656,7 +675,7 @@
char data[4096];
size_t size = sizeof(data);
- EXPECT_NO_THROW(recvUDP(AF_INET, data, size));
+ ASSERT_NO_THROW(recvUDP(AF_INET, data, size));
Message m(Message::PARSE);
InputBuffer ibuf(data, size);
@@ -672,34 +691,27 @@
EXPECT_EQ(q.getClass(), q2->getClass());
}
-void
-receive_and_inc(udp::socket* socket, int* num) {
- (*num) ++;
- static char inbuff[512];
- socket->async_receive(asio::buffer(inbuff, 512),
- boost::bind(receive_and_inc, socket, num));
-}
-
// Test it tries the correct amount of times before giving up
TEST_F(ASIOLinkTest, recursiveTimeout) {
// Prepare the service (we do not use the common setup, we do not answer
setDNSService();
- asio::io_service& service = io_service_->get_io_service();
// Prepare the socket
- uint16_t port = boost::lexical_cast<uint16_t>(TEST_CLIENT_PORT);
- udp::socket socket(service, udp::v4());
- socket.set_option(socket_base::reuse_address(true));
- socket.bind(udp::endpoint(ip::address::from_string(TEST_IPV4_ADDR), port));
- // And count the answers
- int num = -1; // One is counted before the receipt of the first one
- receive_and_inc(&socket, &num);
+ res_ = resolveAddress(AF_INET, IPPROTO_UDP, true);
+ sock_ = socket(res_->ai_family, res_->ai_socktype, res_->ai_protocol);
+ if (sock_ < 0) {
+ isc_throw(IOError, "failed to open test socket");
+ }
+ if (bind(sock_, res_->ai_addr, res_->ai_addrlen) < 0) {
+ isc_throw(IOError, "failed to bind test socket");
+ }
// Prepare the server
bool done(true);
- MockServerStop server(service, &done);
+ MockServerStop server(*io_service_, &done);
// Do the answer
+ const uint16_t port = boost::lexical_cast<uint16_t>(TEST_CLIENT_PORT);
RecursiveQuery query(*dns_service_, singleAddress(TEST_IPV4_ADDR, port),
10, 2);
Question question(Name("example.net"), RRClass::IN(), RRType::A());
@@ -707,7 +719,27 @@
query.sendQuery(question, buffer, &server);
// Run the test
- service.run();
+ io_service_->run();
+
+ // Read up to 3 packets. Use some ad hoc timeout to prevent an infinite
+ // block (see also recvUDP()).
+ const struct timeval timeo = { 10, 0 };
+ int recv_options = 0;
+ if (setsockopt(sock_, SOL_SOCKET, SO_RCVTIMEO, &timeo, sizeof(timeo))) {
+ if (errno == ENOPROTOOPT) { // see ASIOLinkTest::recvUDP()
+ recv_options = MSG_DONTWAIT;
+ } else {
+ isc_throw(IOError, "set RCVTIMEO failed: " << strerror(errno));
+ }
+ }
+ int num = 0;
+ do {
+ char inbuff[512];
+ if (recv(sock_, inbuff, sizeof(inbuff), recv_options) < 0) {
+ num = -1;
+ break;
+ }
+ } while (++num < 3);
// The query should fail
EXPECT_FALSE(done);
Modified: trunk/src/lib/testutils/Makefile.am
==============================================================================
--- trunk/src/lib/testutils/Makefile.am (original)
+++ trunk/src/lib/testutils/Makefile.am Mon Jan 3 19:38:45 2011
@@ -1,5 +1,14 @@
-SUBDIRS = testdata
+SUBDIRS = . testdata
-EXTRA_DIST = srv_test.h
-EXTRA_DIST += srv_unittest.h
-EXTRA_DIST += mockups.h
+AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
+AM_CPPFLAGS += $(BOOST_INCLUDES)
+AM_CXXFLAGS=$(B10_CXXFLAGS)
+
+if HAVE_GTEST
+lib_LTLIBRARIES = libtestutils.la
+
+libtestutils_la_SOURCES = srv_test.h srv_test.cc
+libtestutils_la_SOURCES += srv_unittest.h
+libtestutils_la_SOURCES += mockups.h
+libtestutils_la_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
+endif
Modified: trunk/src/lib/testutils/README
==============================================================================
--- trunk/src/lib/testutils/README (original)
+++ trunk/src/lib/testutils/README Mon Jan 3 19:38:45 2011
@@ -1,4 +1,2 @@
Here is some code used by more than one test. No code is used for bind10
itself, only for testing.
-
-As it contains headers only currently, it does not compile here.
Modified: trunk/src/lib/testutils/srv_test.h
==============================================================================
--- trunk/src/lib/testutils/srv_test.h (original)
+++ trunk/src/lib/testutils/srv_test.h Mon Jan 3 19:38:45 2011
@@ -12,10 +12,6 @@
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
-// $Id: auth_srv_unittest.cc 3310 2010-10-21 23:10:24Z each $
-
-#include <config.h>
-
#include <gtest/gtest.h>
#include <dns/buffer.h>
@@ -27,139 +23,99 @@
#include <dns/rrclass.h>
#include <dns/rrtype.h>
-#include <cc/data.h>
-#include <cc/session.h>
-
-#include <xfr/xfrout_client.h>
-
-#include <auth/auth_srv.h>
-#include <asiolink/asiolink.h>
-
-#include <dns/tests/unittest_util.h>
#include "mockups.h"
-using namespace std;
-using namespace isc::cc;
-using namespace isc::dns;
-using namespace isc::data;
-using namespace isc::xfr;
-using namespace asiolink;
-using isc::UnitTestUtil;
+namespace asiolink {
+class IOSocket;
+class IOMessage;
+class IOEndpoint;
+}
-namespace {
-const char* const DEFAULT_REMOTE_ADDRESS = "192.0.2.1";
+namespace isc {
+namespace testutils {
+extern const char* const DEFAULT_REMOTE_ADDRESS;
+
+// These are flags to indicate whether the corresponding flag bit of the
+// DNS header is to be set in the test cases. (The flag values
+// is irrelevant to their wire-format values)
+extern const unsigned int QR_FLAG;
+extern const unsigned int AA_FLAG;
+extern const unsigned int TC_FLAG;
+extern const unsigned int RD_FLAG;
+extern const unsigned int RA_FLAG;
+extern const unsigned int AD_FLAG;
+extern const unsigned int CD_FLAG;
+
+void
+headerCheck(const isc::dns::Message& message, const isc::dns::qid_t qid,
+ const isc::dns::Rcode& rcode,
+ const uint16_t opcodeval, const unsigned int flags,
+ const unsigned int qdcount,
+ const unsigned int ancount, const unsigned int nscount,
+ const unsigned int arcount);
// The base class for Auth and Recurse test case
class SrvTestBase : public ::testing::Test {
protected:
- SrvTestBase() : request_message(Message::RENDER),
- parse_message(new Message(Message::PARSE)),
- default_qid(0x1035), opcode(Opcode(Opcode::QUERY())),
- qname("www.example.com"), qclass(RRClass::IN()),
- qtype(RRType::A()), io_sock(NULL),
- io_message(NULL), endpoint(NULL),
- request_obuffer(0), request_renderer(request_obuffer),
- response_obuffer(new OutputBuffer(0))
- {}
- ~SrvTestBase() {
- delete io_message;
- delete endpoint;
- }
+ SrvTestBase();
+ virtual ~SrvTestBase();
+
+ /// Let the server process a DNS message.
+ ///
+ /// The derived class implementation is expected to pass \c io_message,
+ /// \c parse_message, \c response_obuffer, and \c dnsserv to the server
+ /// implementation it is testing.
+ virtual void processMessage() = 0;
+
+ /// The following methods implement server independent test logic using
+ /// the template method pattern. Each test calls \c processMessage()
+ /// to delegate the server-dependent behavior to the actual implementation
+ /// classes.
+ void unsupportedRequest();
+ void multiQuestion();
+ void shortMessage();
+ void response();
+ void shortQuestion();
+ void shortAnswer();
+ void ednsBadVers();
+ void axfrOverUDP();
+
+ /// Create DNS packet data from a file.
+ ///
+ /// It constructs wire-format DNS packet data from \c datafile in the
+ /// form of \c IOMessage in \c io_message.
+ /// The existing content of \c io_message, if any, will be deleted.
+ void createDataFromFile(const char* const datafile,
+ int protocol = IPPROTO_UDP);
+
+ /// Create DNS packet data from a message.
+ ///
+ /// It constructs wire-format DNS packet data from \c message in the
+ /// form of \c IOMessage in \c io_message.
+ /// The existing content of \c io_message, if any, will be deleted.
+ void createRequestPacket(isc::dns::Message& message,
+ const int protocol = IPPROTO_UDP);
+
MockSession notify_session;
MockServer dnsserv;
- Message request_message;
- MessagePtr parse_message;
- const qid_t default_qid;
- const Opcode opcode;
- const Name qname;
- const RRClass qclass;
- const RRType qtype;
- IOSocket* io_sock;
- IOMessage* io_message;
- const IOEndpoint* endpoint;
- OutputBuffer request_obuffer;
- MessageRenderer request_renderer;
- OutputBufferPtr response_obuffer;
- vector<uint8_t> data;
+ isc::dns::Message request_message;
+ isc::dns::MessagePtr parse_message;
+ const isc::dns::qid_t default_qid;
+ const isc::dns::Opcode opcode;
+ const isc::dns::Name qname;
+ const isc::dns::RRClass qclass;
+ const isc::dns::RRType qtype;
+ asiolink::IOSocket* io_sock;
+ asiolink::IOMessage* io_message;
+ const asiolink::IOEndpoint* endpoint;
+ isc::dns::OutputBuffer request_obuffer;
+ isc::dns::MessageRenderer request_renderer;
+ isc::dns::OutputBufferPtr response_obuffer;
+ std::vector<uint8_t> data;
+};
+} // end of namespace testutils
+} // end of namespace isc
- void createDataFromFile(const char* const datafile, int protocol);
- void createRequestPacket(Message& message, const int protocol);
-};
-
-void
-SrvTestBase::createDataFromFile(const char* const datafile,
- const int protocol = IPPROTO_UDP)
-{
- delete io_message;
- data.clear();
-
- delete endpoint;
-
- endpoint = IOEndpoint::create(protocol,
- IOAddress(DEFAULT_REMOTE_ADDRESS), 5300);
- UnitTestUtil::readWireData(datafile, data);
- io_sock = (protocol == IPPROTO_UDP) ? &IOSocket::getDummyUDPSocket() :
- &IOSocket::getDummyTCPSocket();
- io_message = new IOMessage(&data[0], data.size(), *io_sock, *endpoint);
-}
-
-void
-SrvTestBase::createRequestPacket(Message& message,
- const int protocol = IPPROTO_UDP)
-{
- message.toWire(request_renderer);
-
- delete io_message;
-
- endpoint = IOEndpoint::create(protocol,
- IOAddress(DEFAULT_REMOTE_ADDRESS), 5300);
- io_sock = (protocol == IPPROTO_UDP) ? &IOSocket::getDummyUDPSocket() :
- &IOSocket::getDummyTCPSocket();
- io_message = new IOMessage(request_renderer.getData(),
- request_renderer.getLength(),
- *io_sock, *endpoint);
-}
-
-// These are flags to indicate whether the corresponding flag bit of the
-// DNS header is to be set in the test cases. (Note that the flag values
-// is irrelevant to their wire-format values)
-const unsigned int QR_FLAG = 0x1;
-const unsigned int AA_FLAG = 0x2;
-const unsigned int TC_FLAG = 0x4;
-const unsigned int RD_FLAG = 0x8;
-const unsigned int RA_FLAG = 0x10;
-const unsigned int AD_FLAG = 0x20;
-const unsigned int CD_FLAG = 0x40;
-
-void
-headerCheck(const Message& message, const qid_t qid, const Rcode& rcode,
- const uint16_t opcodeval, const unsigned int flags,
- const unsigned int qdcount,
- const unsigned int ancount, const unsigned int nscount,
- const unsigned int arcount)
-{
- EXPECT_EQ(qid, message.getQid());
- EXPECT_EQ(rcode, message.getRcode());
- EXPECT_EQ(opcodeval, message.getOpcode().getCode());
- EXPECT_EQ((flags & QR_FLAG) != 0,
- message.getHeaderFlag(Message::HEADERFLAG_QR));
- EXPECT_EQ((flags & AA_FLAG) != 0,
- message.getHeaderFlag(Message::HEADERFLAG_AA));
- EXPECT_EQ((flags & TC_FLAG) != 0,
- message.getHeaderFlag(Message::HEADERFLAG_TC));
- EXPECT_EQ((flags & RA_FLAG) != 0,
- message.getHeaderFlag(Message::HEADERFLAG_RA));
- EXPECT_EQ((flags & RD_FLAG) != 0,
- message.getHeaderFlag(Message::HEADERFLAG_RD));
- EXPECT_EQ((flags & AD_FLAG) != 0,
- message.getHeaderFlag(Message::HEADERFLAG_AD));
- EXPECT_EQ((flags & CD_FLAG) != 0,
- message.getHeaderFlag(Message::HEADERFLAG_CD));
-
- EXPECT_EQ(qdcount, message.getRRCount(Message::SECTION_QUESTION));
- EXPECT_EQ(ancount, message.getRRCount(Message::SECTION_ANSWER));
- EXPECT_EQ(nscount, message.getRRCount(Message::SECTION_AUTHORITY));
- EXPECT_EQ(arcount, message.getRRCount(Message::SECTION_ADDITIONAL));
-}
-
-}
+// Local Variables:
+// mode: c++
+// End:
More information about the bind10-changes
mailing list