From: JINMEI Tatuya Date: Fri, 2 Mar 2012 00:20:57 +0000 (-0800) Subject: [1607] test setup: created a test zone file, defined a param'ed test fixture. X-Git-Tag: trac2351_base~226^2~116^2~41^2~46^2~14 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ff863e03a8cbdb0c971a101af01b604dc13d1457;p=thirdparty%2Fkea.git [1607] test setup: created a test zone file, defined a param'ed test fixture. --- diff --git a/src/lib/datasrc/tests/Makefile.am b/src/lib/datasrc/tests/Makefile.am index 181664a6fe..c389f7a836 100644 --- a/src/lib/datasrc/tests/Makefile.am +++ b/src/lib/datasrc/tests/Makefile.am @@ -56,6 +56,7 @@ run_unittests_SOURCES += database_unittest.cc run_unittests_SOURCES += sqlite3_unittest.cc run_unittests_SOURCES += sqlite3_accessor_unittest.cc run_unittests_SOURCES += memory_datasrc_unittest.cc +run_unittests_SOURCES += zone_finder_context_unittest.cc # We need the actually module implementation in the tests (they are not part # of libdatasrc) @@ -106,3 +107,4 @@ EXTRA_DIST += testdata/test.sqlite3 EXTRA_DIST += testdata/test.sqlite3.nodiffs EXTRA_DIST += testdata/rwtest.sqlite3 EXTRA_DIST += testdata/diffs.sqlite3 +EXTRA_DIST += testdata/contexttest.zone diff --git a/src/lib/datasrc/tests/testdata/contexttest.zone b/src/lib/datasrc/tests/testdata/contexttest.zone new file mode 100644 index 0000000000..13b87651c7 --- /dev/null +++ b/src/lib/datasrc/tests/testdata/contexttest.zone @@ -0,0 +1,22 @@ +;; test zone file used for ZoneFinderContext tests. + +example.org. 3600 IN SOA ns1.example.org. bugs.x.w.example.org. 9 3600 300 3600000 3600 +example.org. 3600 IN NS ns1.example.org. +example.org. 3600 IN NS ns2.example.org. +example.org. 3600 IN MX 1 mx1.example.org. +example.org. 3600 IN MX 2 mx2.example.org. + +ns1.example.org. 3600 IN A 192.0.2.1 +ns1.example.org. 3600 IN AAAA 2001:db8::1 +ns2.example.org. 3600 IN A 192.0.2.2 + +mx1.example.org. 3600 IN A 192.0.2.10 +mx2.example.org. 3600 IN AAAA 2001:db8::10 + +;; delegation +a.example.org. 3600 IN NS ns1.a.example.org. +a.example.org. 3600 IN NS ns2.a.example.org. + +ns1.a.example.org. 3600 IN A 192.0.2.5 +ns2.a.example.org. 3600 IN A 192.0.2.6 +ns2.a.example.org. 3600 IN AAAA 2001:db8::6 diff --git a/src/lib/datasrc/tests/zone_finder_context_unittest.cc b/src/lib/datasrc/tests/zone_finder_context_unittest.cc new file mode 100644 index 0000000000..73f89defb9 --- /dev/null +++ b/src/lib/datasrc/tests/zone_finder_context_unittest.cc @@ -0,0 +1,122 @@ +// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC") +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#include +#include +#include + +#include +#include +#include +#include + +#include + +#include +#include + +#include + +using namespace std; +using namespace isc::dns; +using namespace isc::datasrc; +using boost::shared_ptr; + +namespace { + +// Commonly used test zone file. +const char* const TEST_ZONE_FILE = TEST_DATA_DIR "/contexttest.zone"; + +// Convenient shortcut +typedef shared_ptr DataSourceClientPtr; + +// This is the type used as the test parameter. Note that this is +// intentionally a plain old type (i.e. a function pointer), not a class; +// otherwise it could cause initialization fiasco at the instantiation time. +typedef DataSourceClientPtr (*ClientCreator)(RRClass, const Name&); + +// Creator for the in-memory client to be tested +DataSourceClientPtr +createInMemoryClient(RRClass zclass, const Name& zname) { + shared_ptr client(new InMemoryClient); + + shared_ptr finder( + new InMemoryZoneFinder(zclass, zname)); + finder->load(TEST_ZONE_FILE); + + client->addZone(finder); + + return (client); +} + +// Creator for the SQLite3 client to be tested. addRRset() is a helper +// subroutine. +void +addRRset(ZoneUpdaterPtr updater, ConstRRsetPtr rrset) { + updater->addRRset(*rrset); +} + +DataSourceClientPtr +createSQLite3Client(RRClass zclass, const Name& zname) { + // We always begin with an empty template SQLite3 DB file and install + // the zone data from the zone file to ensure both cases have the + // same test data. + + const char* const install_cmd = INSTALL_PROG " " TEST_DATA_DIR + "/rwtest.sqlite3 " TEST_DATA_BUILDDIR "/contexttest.sqlite3.copied"; + if (system(install_cmd) != 0) { + isc_throw(isc::Unexpected, + "Error setting up; command failed: " << install_cmd); + } + + shared_ptr accessor( + new SQLite3Accessor(TEST_DATA_BUILDDIR "/contexttest.sqlite3.copied", + zclass.toText())); + shared_ptr client(new DatabaseClient(zclass, accessor)); + + ZoneUpdaterPtr updater = client->getUpdater(zname, true); + masterLoad(TEST_ZONE_FILE, zname, zclass, boost::bind(addRRset, updater, + _1)); + updater->commit(); + + return (client); +} + +// The test class. Its parameterized so we can share the test scnearios +// for any concrete data source implementaitons. +class ZoneFinderContextTest : + public ::testing::TestWithParam +{ +protected: + ZoneFinderContextTest() : qclass_(RRClass::IN()), qzone_("example.org") { + client_ = (*GetParam())(qclass_, qzone_); + } + + const RRClass qclass_; + const Name qzone_; + DataSourceClientPtr client_; + ZoneFinderPtr finder_; +}; + +// We test the in-memory and SQLite3 data source implementations. +INSTANTIATE_TEST_CASE_P(, ZoneFinderContextTest, + ::testing::Values(createInMemoryClient, + createSQLite3Client)); + +TEST_P(ZoneFinderContextTest, getAdditional) { + finder_ = client_->findZone(Name("www.a.example.org")).zone_finder; + ASSERT_TRUE(finder_); +} + +}