[svn] commit: r4012 - in /branches/trac448: ./ src/bin/auth/tests/ src/bin/recurse/tests/ src/lib/testutils/
BIND 10 source code commits
bind10-changes at lists.isc.org
Sun Dec 26 03:52:45 UTC 2010
Author: jinmei
Date: Sun Dec 26 03:52:45 2010
New Revision: 4012
Log:
made lib/testutils clang++-friendly:
- replaced the ugly macro with real methods the base class using the template method pattern. as a result srv_unittest.h is not needed anymore and removed.
- avoided the use of an unnamed namespace in srv_test.h (another bad practice anyway)
- avoided the use of 'using namespace' in srv_test.h (yet another bad practice anyway)
Added:
branches/trac448/src/lib/testutils/srv_test.cc
Removed:
branches/trac448/src/lib/testutils/srv_unittest.h
Modified:
branches/trac448/configure.ac
branches/trac448/src/bin/auth/tests/Makefile.am
branches/trac448/src/bin/auth/tests/auth_srv_unittest.cc
branches/trac448/src/bin/recurse/tests/Makefile.am
branches/trac448/src/bin/recurse/tests/recursor_config_unittest.cc
branches/trac448/src/bin/recurse/tests/recursor_unittest.cc
branches/trac448/src/lib/testutils/Makefile.am
branches/trac448/src/lib/testutils/README
branches/trac448/src/lib/testutils/srv_test.h
Modified: branches/trac448/configure.ac
==============================================================================
--- branches/trac448/configure.ac (original)
+++ branches/trac448/configure.ac Sun Dec 26 03:52:45 2010
@@ -577,6 +577,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: branches/trac448/src/bin/auth/tests/Makefile.am
==============================================================================
--- branches/trac448/src/bin/auth/tests/Makefile.am (original)
+++ branches/trac448/src/bin/auth/tests/Makefile.am Sun Dec 26 03:52:45 2010
@@ -38,6 +38,7 @@
run_unittests_LDADD += $(top_builddir)/src/lib/cc/libcc.la
run_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la
run_unittests_LDADD += $(top_builddir)/src/lib/xfr/libxfr.la
+run_unittests_LDADD += $(top_builddir)/src/lib/testutils/libtestutils.la
endif
noinst_PROGRAMS = $(TESTS)
Modified: branches/trac448/src/bin/auth/tests/auth_srv_unittest.cc
==============================================================================
--- branches/trac448/src/bin/auth/tests/auth_srv_unittest.cc (original)
+++ branches/trac448/src/bin/auth/tests/auth_srv_unittest.cc Sun Dec 26 03:52:45 2010
@@ -17,13 +17,16 @@
#include <config.h>
#include <datasrc/memory_datasrc.h>
#include <auth/auth_srv.h>
-#include <testutils/srv_unittest.h>
+
+#include <dns/tests/unittest_util.h>
+#include <testutils/srv_test.h>
using namespace isc::cc;
using namespace isc::dns;
using namespace isc::data;
using namespace isc::xfr;
using namespace asiolink;
+using namespace isc::testutils;
using isc::UnitTestUtil;
namespace {
@@ -39,6 +42,10 @@
AuthSrvTest() : server(true, xfrout), rrclass(RRClass::IN()) {
server.setXfrinSession(¬ify_session);
}
+ virtual void processMessage() {
+ server.processMessage(*io_message, parse_message, response_obuffer,
+ &dnsserv);
+ }
MockXfroutClient xfrout;
AuthSrv server;
const RRClass rrclass;
@@ -46,48 +53,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: branches/trac448/src/bin/recurse/tests/Makefile.am
==============================================================================
--- branches/trac448/src/bin/recurse/tests/Makefile.am (original)
+++ branches/trac448/src/bin/recurse/tests/Makefile.am Sun Dec 26 03:52:45 2010
@@ -33,6 +33,7 @@
run_unittests_LDADD += $(top_builddir)/src/lib/config/libcfgclient.la
run_unittests_LDADD += $(top_builddir)/src/lib/cc/libcc.la
run_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la
+run_unittests_LDADD += $(top_builddir)/src/lib/testutils/libtestutils.la
run_unittests_LDADD += $(top_builddir)/src/lib/xfr/libxfr.la
run_unittests_LDADD += $(top_builddir)/src/lib/log/liblog.la
endif
Modified: branches/trac448/src/bin/recurse/tests/recursor_config_unittest.cc
==============================================================================
--- branches/trac448/src/bin/recurse/tests/recursor_config_unittest.cc (original)
+++ branches/trac448/src/bin/recurse/tests/recursor_config_unittest.cc Sun Dec 26 03:52:45 2010
@@ -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: branches/trac448/src/bin/recurse/tests/recursor_unittest.cc
==============================================================================
--- branches/trac448/src/bin/recurse/tests/recursor_unittest.cc (original)
+++ branches/trac448/src/bin/recurse/tests/recursor_unittest.cc Sun Dec 26 03:52:45 2010
@@ -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: branches/trac448/src/lib/testutils/Makefile.am
==============================================================================
--- branches/trac448/src/lib/testutils/Makefile.am (original)
+++ branches/trac448/src/lib/testutils/Makefile.am Sun Dec 26 03:52:45 2010
@@ -1,5 +1,11 @@
-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)
+
+lib_LTLIBRARIES = libtestutils.la
+
+libtestutils_la_SOURCES = srv_test.h srv_test.cc
+libtestutils_la_SOURCES += srv_unittest.h
+libtestutils_la_SOURCES += mockups.h
Modified: branches/trac448/src/lib/testutils/README
==============================================================================
--- branches/trac448/src/lib/testutils/README (original)
+++ branches/trac448/src/lib/testutils/README Sun Dec 26 03:52:45 2010
@@ -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: branches/trac448/src/lib/testutils/srv_test.h
==============================================================================
--- branches/trac448/src/lib/testutils/srv_test.h (original)
+++ branches/trac448/src/lib/testutils/srv_test.h Sun Dec 26 03:52:45 2010
@@ -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