From: Michal 'vorner' Vaner Date: Wed, 26 Sep 2012 11:48:59 +0000 (+0200) Subject: [2161] Remove the static_datasrc X-Git-Tag: trac2351_base~37^2~2^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e7d7b0180edf1cf28316bfb0b2e2ccb8e8593eb9;p=thirdparty%2Fkea.git [2161] Remove the static_datasrc The old implementation of static data source. Getting rid of tests and stray includes. --- diff --git a/src/bin/auth/auth_srv.cc b/src/bin/auth/auth_srv.cc index ddb7466fe3..d1109bc8f1 100644 --- a/src/bin/auth/auth_srv.cc +++ b/src/bin/auth/auth_srv.cc @@ -43,7 +43,6 @@ #include #include -#include #include #include diff --git a/src/lib/datasrc/Makefile.am b/src/lib/datasrc/Makefile.am index bd96838d16..213b98cf83 100644 --- a/src/lib/datasrc/Makefile.am +++ b/src/lib/datasrc/Makefile.am @@ -22,7 +22,6 @@ CLEANFILES += static.zone lib_LTLIBRARIES = libb10-datasrc.la libb10_datasrc_la_SOURCES = data_source.h data_source.cc -libb10_datasrc_la_SOURCES += static_datasrc.h static_datasrc.cc libb10_datasrc_la_SOURCES += sqlite3_datasrc.h sqlite3_datasrc.cc libb10_datasrc_la_SOURCES += query.h query.cc libb10_datasrc_la_SOURCES += cache.h cache.cc diff --git a/src/lib/datasrc/static_datasrc.cc b/src/lib/datasrc/static_datasrc.cc deleted file mode 100644 index 77d7a1d152..0000000000 --- a/src/lib/datasrc/static_datasrc.cc +++ /dev/null @@ -1,275 +0,0 @@ -// Copyright (C) 2010 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 -#include - -using namespace std; -using namespace isc::dns; -using namespace isc::dns::rdata; - -namespace isc { -namespace datasrc { - -// This class stores the "static" data for the built-in static data source. -// Since it's static, it could be literally static, i.e, defined as static -// objects. But to avoid the static initialization order fiasco, which would -// be unlikely to happen for this class in practice but is still possible, -// we took a safer approach. A downside of this approach is that redundant -// copies of exactly the same content of these objects can be created. -// In practice, however, there's normally at most one StaticDataSrc object, -// so this should be acceptable (if this turns out to be a real concern we -// might consider making this class a singleton). -// We use the "pimpl" idiom for this class. Operations for this class is -// not expected to be performance sensitive, so the overhead due to the pimpl -// should be okay, and it's more beneficial to hide details and minimize -// inter module dependencies in header files. -struct StaticDataSrcImpl { -public: - StaticDataSrcImpl(); - const Name authors_name; - const Name version_name; - // XXX: unfortunately these can't be ConstRRsetPtr because they'll be - // passed to RRsetList::addRRset(), which expect non const RRsetPtr. - // We should revisit this design later. - RRsetPtr authors; - RRsetPtr authors_ns; - RRsetPtr authors_soa; - RRsetPtr version; - RRsetPtr version_ns; - RRsetPtr version_soa; -}; - -StaticDataSrcImpl::StaticDataSrcImpl() : - authors_name("authors.bind"), version_name("version.bind") -{ - authors = RRsetPtr(new RRset(authors_name, RRClass::CH(), - RRType::TXT(), RRTTL(0))); - authors->addRdata(generic::TXT("Chen Zhengzhang")); // Jerry - authors->addRdata(generic::TXT("Dmitriy Volodin")); - authors->addRdata(generic::TXT("Evan Hunt")); - authors->addRdata(generic::TXT("Haidong Wang")); // Ocean - authors->addRdata(generic::TXT("Haikuo Zhang")); - authors->addRdata(generic::TXT("Han Feng")); - authors->addRdata(generic::TXT("Jelte Jansen")); - authors->addRdata(generic::TXT("Jeremy C. Reed")); - authors->addRdata(generic::TXT("Xie Jiagui")); // Kevin Tes - authors->addRdata(generic::TXT("Jin Jian")); - authors->addRdata(generic::TXT("JINMEI Tatuya")); - authors->addRdata(generic::TXT("Kazunori Fujiwara")); - authors->addRdata(generic::TXT("Michael Graff")); - authors->addRdata(generic::TXT("Michal Vaner")); - authors->addRdata(generic::TXT("Mukund Sivaraman")); - authors->addRdata(generic::TXT("Naoki Kambe")); - authors->addRdata(generic::TXT("Shane Kerr")); - authors->addRdata(generic::TXT("Shen Tingting")); - authors->addRdata(generic::TXT("Stephen Morris")); - authors->addRdata(generic::TXT("Yoshitaka Aharen")); - authors->addRdata(generic::TXT("Zhang Likun")); - - authors_ns = RRsetPtr(new RRset(authors_name, RRClass::CH(), - RRType::NS(), RRTTL(0))); - authors_ns->addRdata(generic::NS(authors_name)); - - authors_soa = RRsetPtr(new RRset(authors_name, RRClass::CH(), - RRType::SOA(), RRTTL(0))); - authors_soa->addRdata(generic::SOA( - "authors.bind. hostmaster.authors.bind. " - "0 28800 7200 604800 86400")); - - version = RRsetPtr(new RRset(version_name, RRClass::CH(), - RRType::TXT(), RRTTL(0))); - version->addRdata(generic::TXT(PACKAGE_STRING)); - - version_ns = RRsetPtr(new RRset(version_name, RRClass::CH(), - RRType::NS(), RRTTL(0))); - version_ns->addRdata(generic::NS(version_name)); - - version_soa = RRsetPtr(new RRset(version_name, RRClass::CH(), - RRType::SOA(), RRTTL(0))); - version_soa->addRdata(generic::SOA( - "version.bind. hostmaster.version.bind. " - "0 28800 7200 604800 86400")); -} - -StaticDataSrc::StaticDataSrc() { - LOG_DEBUG(logger, DBG_TRACE_BASIC, DATASRC_STATIC_CREATE); - setClass(RRClass::CH()); - impl_ = new StaticDataSrcImpl; -} - -StaticDataSrc::~StaticDataSrc() { - delete impl_; -} - -namespace { -bool -isSubdomain(const Name& qname, const Name& zone) { - const NameComparisonResult::NameRelation cmp = - qname.compare(zone).getRelation(); - return (cmp == NameComparisonResult::EQUAL || - cmp == NameComparisonResult::SUBDOMAIN); -} -} - -void -StaticDataSrc::findClosestEnclosure(DataSrcMatch& match) const { - const Name& qname = match.getName(); - - if (match.getClass() != getClass() && match.getClass() != RRClass::ANY()) { - return; - } - - if (isSubdomain(qname, impl_->version_name)) { - match.update(*this, impl_->version_name); - return; - } - - if (isSubdomain(qname, impl_->authors_name)) { - match.update(*this, impl_->authors_name); - return; - } -} - -DataSrc::Result -StaticDataSrc::findRRset(const Name& qname, - const RRClass& qclass, const RRType& qtype, - RRsetList& target, uint32_t& flags, - const Name* const zonename) const -{ - LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_STATIC_FIND).arg(qname). - arg(qtype); - flags = 0; - if (qclass != getClass() && qclass != RRClass::ANY()) { - LOG_ERROR(logger, DATASRC_STATIC_CLASS_NOT_CH); - return (ERROR); - } - - // Identify the appropriate zone. - bool is_versionname = false, is_authorsname = false; - if (zonename != NULL) { - if (*zonename == impl_->version_name && - isSubdomain(qname, impl_->version_name)) { - is_versionname = true; - } else if (*zonename == impl_->authors_name && - isSubdomain(qname, impl_->authors_name)) { - is_authorsname = true; - } else { - flags = NO_SUCH_ZONE; - return (SUCCESS); - } - } else { - if (isSubdomain(qname, impl_->version_name)) { - is_versionname = true; - } else if (isSubdomain(qname, impl_->authors_name)) { - is_authorsname = true; - } else { - flags = NO_SUCH_ZONE; - return (SUCCESS); - } - } - - const bool any = (qtype == RRType::ANY()); - - if (is_versionname) { - if (qname == impl_->version_name) { - if (qtype == RRType::TXT() || any) { - target.addRRset(impl_->version); - } - if (qtype == RRType::NS() || any) { - target.addRRset(impl_->version_ns); - } - if (qtype == RRType::SOA() || any) { - target.addRRset(impl_->version_soa); - } - if (target.size() == 0) { - flags = TYPE_NOT_FOUND; - } - } else { - flags = NAME_NOT_FOUND; - } - } else { - assert(is_authorsname); - if (qname == impl_->authors_name) { - if (qtype == RRType::TXT() || any) { - target.addRRset(impl_->authors); - } - if (qtype == RRType::NS() || any) { - target.addRRset(impl_->authors_ns); - } - if (qtype == RRType::SOA() || any) { - target.addRRset(impl_->authors_soa); - } - if (target.size() == 0 ) { - flags = TYPE_NOT_FOUND; - } - } else { - flags = NAME_NOT_FOUND; - } - } - - return (SUCCESS); -} - -DataSrc::Result -StaticDataSrc::findExactRRset(const Name& qname, - const RRClass& qclass, const RRType& qtype, - RRsetList& target, uint32_t& flags, - const Name* zonename) const -{ - return (findRRset(qname, qclass, qtype, target, flags, zonename)); -} - -DataSrc::Result -StaticDataSrc::findPreviousName(const Name&, Name&, const Name*) const { - return (NOT_IMPLEMENTED); -} - -DataSrc::Result -StaticDataSrc::findCoveringNSEC3(const Name&, string&, RRsetList&) const { - return (NOT_IMPLEMENTED); -} - -DataSrc::Result -StaticDataSrc::init() { - return (SUCCESS); -} - -// Static data source is "configuration less", so the \c config parameter -// is intentionally ignored. -DataSrc::Result -StaticDataSrc::init(isc::data::ConstElementPtr) { - return (init()); -} - -DataSrc::Result -StaticDataSrc::close() { - return (SUCCESS); -} - -} -} diff --git a/src/lib/datasrc/static_datasrc.h b/src/lib/datasrc/static_datasrc.h deleted file mode 100644 index 4d212fe075..0000000000 --- a/src/lib/datasrc/static_datasrc.h +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright (C) 2009 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. - -// -// Sample Datasource implementation; this datasource only returns -// static content for the queries -// CH TXT version.bind -// and -// CH TXT authors.bind -// - -#ifndef __STATIC_DATA_SOURCE_H -#define __STATIC_DATA_SOURCE_H - -#include - -namespace isc { - -namespace dns { -class Name; -class RRClass; -class RRType; -class RRType; -class RRsetList; -} - -namespace datasrc { - -struct StaticDataSrcImpl; - -class StaticDataSrc : public DataSrc { -private: - /// - /// \name Constructors, Assignment Operator and Destructor. - /// - /// Note: The copy constructor and the assignment operator are intentionally - /// defined as private. - //@{ - StaticDataSrc(const StaticDataSrc& source); - StaticDataSrc& operator=(const StaticDataSrc& source); -public: - StaticDataSrc(); - ~StaticDataSrc(); - //@} - - void findClosestEnclosure(DataSrcMatch& match) const; - - Result findRRset(const isc::dns::Name& qname, - const isc::dns::RRClass& qclass, - const isc::dns::RRType& qtype, - isc::dns::RRsetList& target, - uint32_t& flags, - const isc::dns::Name* zonename) const; - - Result findExactRRset(const isc::dns::Name& qname, - const isc::dns::RRClass& qclass, - const isc::dns::RRType& qtype, - isc::dns::RRsetList& target, - uint32_t& flags, - const isc::dns::Name* zonename) const; - - Result findPreviousName(const isc::dns::Name& qname, - isc::dns::Name& target, - const isc::dns::Name* zonename) const; - - Result findCoveringNSEC3(const isc::dns::Name& zonename, - std::string& hash, - isc::dns::RRsetList& target) const; - - Result init(); - Result init(isc::data::ConstElementPtr config); - Result close(); -private: - StaticDataSrcImpl* impl_; -}; - -} -} - -#endif - -// Local Variables: -// mode: c++ -// End: diff --git a/src/lib/datasrc/tests/Makefile.am b/src/lib/datasrc/tests/Makefile.am index b73a64a703..745c0d0fb6 100644 --- a/src/lib/datasrc/tests/Makefile.am +++ b/src/lib/datasrc/tests/Makefile.am @@ -50,7 +50,6 @@ run_unittests_SOURCES = $(common_sources) # Commented out by ticket #2165. If you re-enable these, please modify # EXTRA_DIST at the bottom of this file. #run_unittests_SOURCES += datasrc_unittest.cc -#run_unittests_SOURCES += static_unittest.cc #run_unittests_SOURCES += query_unittest.cc #run_unittests_SOURCES += cache_unittest.cc #run_unittests_SOURCES += sqlite3_unittest.cc @@ -127,7 +126,6 @@ EXTRA_DIST += testdata/static.zone # Added by ticket #2165 EXTRA_DIST += datasrc_unittest.cc -EXTRA_DIST += static_unittest.cc EXTRA_DIST += query_unittest.cc EXTRA_DIST += cache_unittest.cc EXTRA_DIST += sqlite3_unittest.cc diff --git a/src/lib/datasrc/tests/static_unittest.cc b/src/lib/datasrc/tests/static_unittest.cc deleted file mode 100644 index 2a19ecb23d..0000000000 --- a/src/lib/datasrc/tests/static_unittest.cc +++ /dev/null @@ -1,422 +0,0 @@ -// Copyright (C) 2010 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 -#include -#include - -#include -#include -#include - -using namespace std; -using namespace isc::dns; -using namespace isc::dns::rdata; -using namespace isc::datasrc; - -namespace { -class StaticDataSourceTest : public ::testing::Test { -protected: - StaticDataSourceTest() : version_name("version.bind"), - authors_name("authors.bind"), - nomatch_name("example.com"), - rrclass(RRClass::CH()), rrtype(RRType::TXT()), - rrttl(RRTTL(0)), find_flags(0), matched_rdata(0) - { - // version.bind is answered with package name+version - // (defined as PACKAGE_STRING in config.h) - version_data.push_back(PACKAGE_STRING); - - // NOTE: in addition, the order of the following items matter. - authors_data.push_back("Chen Zhengzhang"); - authors_data.push_back("Dmitriy Volodin"); - authors_data.push_back("Evan Hunt"); - authors_data.push_back("Haidong Wang"); - authors_data.push_back("Haikuo Zhang"); - authors_data.push_back("Han Feng"); - authors_data.push_back("Jelte Jansen"); - authors_data.push_back("Jeremy C. Reed"); - authors_data.push_back("Xie Jiagui"); - authors_data.push_back("Jin Jian"); - authors_data.push_back("JINMEI Tatuya"); - authors_data.push_back("Kazunori Fujiwara"); - authors_data.push_back("Michael Graff"); - authors_data.push_back("Michal Vaner"); - authors_data.push_back("Mukund Sivaraman"); - authors_data.push_back("Naoki Kambe"); - authors_data.push_back("Shane Kerr"); - authors_data.push_back("Shen Tingting"); - authors_data.push_back("Stephen Morris"); - authors_data.push_back("Yoshitaka Aharen"); - authors_data.push_back("Zhang Likun"); - - version_ns_data.push_back("version.bind."); - authors_ns_data.push_back("authors.bind."); - - version_soa_data.push_back("version.bind. hostmaster.version.bind. " - "0 28800 7200 604800 86400"); - authors_soa_data.push_back("authors.bind. hostmaster.authors.bind. " - "0 28800 7200 604800 86400"); - } - StaticDataSrc data_source; - const Name version_name; - const Name authors_name; - const Name nomatch_name; - const RRClass rrclass; - RRType rrtype; // we allow this to be modified in the test - RRTTL rrttl; - RRsetList result_sets; - uint32_t find_flags; - unsigned matched_rdata; - vector types; - vector ttls; - vector* > answers; - vector version_data; - vector authors_data; - vector version_ns_data; - vector authors_ns_data; - vector version_soa_data; - vector authors_soa_data; -}; - -void -checkRRset(ConstRRsetPtr rrset, const Name& expected_name, - const RRClass& expected_class, const RRType& expected_type, - const RRTTL& rrttl, const vector& expected_data) -{ - EXPECT_EQ(expected_name, rrset->getName()); - EXPECT_EQ(expected_class, rrset->getClass()); - EXPECT_EQ(expected_type, rrset->getType()); - EXPECT_EQ(rrttl, rrset->getTTL()); - - RdataIteratorPtr rdata_iterator = rrset->getRdataIterator(); - vector::const_iterator data_it = expected_data.begin(); - for (; data_it != expected_data.end(); ++data_it) { - EXPECT_FALSE(rdata_iterator->isLast()); - if (rdata_iterator->isLast()) { - // buggy case, should stop here - break; - } - EXPECT_EQ(0, (rdata_iterator->getCurrent()).compare( - *createRdata(expected_type, - expected_class, - *data_it))); - rdata_iterator->next(); - } - - EXPECT_TRUE(rdata_iterator->isLast()); -} - -void -checkFind(const DataSrc& data_source, - const Name& qname, const Name* zone_name, - const RRClass& qclass, const RRClass& expected_class, - const RRType& qtype, const vector& expected_ttls, - const uint32_t expected_flags, const vector& expected_types, - const vector* >& expected_answers) -{ - RRsetList result_sets; - uint32_t find_flags; - unsigned int rrset_matched = 0; - unsigned int rrset_count = 0; - - EXPECT_EQ(DataSrc::SUCCESS, - data_source.findRRset(qname, qclass, qtype, result_sets, - find_flags, zone_name)); - EXPECT_EQ(expected_flags, find_flags); - - if ((find_flags & (DataSrc::NO_SUCH_ZONE | DataSrc::NAME_NOT_FOUND | - DataSrc::TYPE_NOT_FOUND)) != 0) { - EXPECT_TRUE(result_sets.begin() == result_sets.end()); - return; - } - - RRsetList::iterator it = result_sets.begin(); - for (; it != result_sets.end(); ++it) { - vector::const_iterator found_type = - find(expected_types.begin(), expected_types.end(), - (*it)->getType()); - // there should be a match - EXPECT_TRUE(found_type != expected_types.end()); - if (found_type != expected_types.end()) { - unsigned int index = distance(expected_types.begin(), found_type); - checkRRset(*it, qname, expected_class, (*it)->getType(), - expected_ttls[index], *expected_answers[index]); - ++rrset_matched; - } - ++rrset_count; - } - EXPECT_EQ(expected_types.size(), rrset_count); - EXPECT_EQ(expected_types.size(), rrset_matched); -} - -void -checkFind(const DataSrc& data_source, - const Name& qname, const Name* zone_name, - const RRClass& qclass, const RRClass& expected_class, - const RRType& qtype, // == expected RRType - const RRTTL& expected_ttl, const uint32_t expected_flags, - const vector& expected_answers) -{ - vector types; - vector ttls; - vector* > answers; - - types.push_back(qtype); - ttls.push_back(expected_ttl); - answers.push_back(&expected_answers); - - checkFind(data_source, qname, zone_name, qclass, expected_class, qtype, - ttls, expected_flags, types, answers); -} - -TEST_F(StaticDataSourceTest, init) { - EXPECT_EQ(DataSrc::SUCCESS, data_source.init()); -} - -TEST_F(StaticDataSourceTest, close) { - EXPECT_EQ(DataSrc::SUCCESS, data_source.init()); -} - -TEST_F(StaticDataSourceTest, findClosestEnclosureForVersion) { - DataSrcMatch match(version_name, rrclass); - data_source.findClosestEnclosure(match); - EXPECT_EQ(version_name, *match.getEnclosingZone()); - EXPECT_EQ(&data_source, match.getDataSource()); -} - -// Class Any query should result in the same answer. -TEST_F(StaticDataSourceTest, findClosestEnclosureForVersionClassAny) { - DataSrcMatch match(version_name, RRClass::ANY()); - data_source.findClosestEnclosure(match); - EXPECT_EQ(version_name, *match.getEnclosingZone()); - EXPECT_EQ(&data_source, match.getDataSource()); -} - -// If class doesn't match the lookup should fail. -TEST_F(StaticDataSourceTest, findClosestEnclosureForVersionClassMismatch) { - DataSrcMatch match(version_name, RRClass::IN()); - data_source.findClosestEnclosure(match); - EXPECT_EQ(static_cast(NULL), match.getEnclosingZone()); - EXPECT_EQ(static_cast(NULL), match.getDataSource()); -} - -TEST_F(StaticDataSourceTest, findClosestEnclosureForVersionPartial) { - DataSrcMatch match(Name("foo").concatenate(version_name), rrclass); - data_source.findClosestEnclosure(match); - EXPECT_EQ(version_name, *match.getEnclosingZone()); - EXPECT_EQ(&data_source, match.getDataSource()); -} - -TEST_F(StaticDataSourceTest, findClosestEnclosureForAuthors) { - DataSrcMatch match(authors_name, rrclass); - data_source.findClosestEnclosure(match); - EXPECT_EQ(authors_name, *match.getEnclosingZone()); - EXPECT_EQ(&data_source, match.getDataSource()); -} - -TEST_F(StaticDataSourceTest, findClosestEnclosureForAuthorsPartial) { - DataSrcMatch match(Name("foo").concatenate(authors_name), rrclass); - data_source.findClosestEnclosure(match); - EXPECT_EQ(authors_name, *match.getEnclosingZone()); - EXPECT_EQ(&data_source, match.getDataSource()); -} - -TEST_F(StaticDataSourceTest, findClosestEnclosureNoMatch) { - DataSrcMatch match(nomatch_name, rrclass); - data_source.findClosestEnclosure(match); - EXPECT_EQ(static_cast(NULL), match.getEnclosingZone()); - EXPECT_EQ(static_cast(NULL), match.getDataSource()); -} - -TEST_F(StaticDataSourceTest, findRRsetVersionTXT) { - checkFind(data_source, version_name, NULL, rrclass, rrclass, - rrtype, rrttl, 0, version_data); - checkFind(data_source, version_name, &version_name, rrclass, rrclass, - rrtype, rrttl, 0, version_data); -} - -TEST_F(StaticDataSourceTest, findRRsetVersionNS) { - rrtype = RRType::NS(); - checkFind(data_source, version_name, NULL, rrclass, rrclass, - rrtype, rrttl, 0, version_ns_data); - checkFind(data_source, version_name, &version_name, rrclass, rrclass, - rrtype, rrttl, 0, version_ns_data); -} - -TEST_F(StaticDataSourceTest, findRRsetVersionSOA) { - rrtype = RRType::SOA(); - - checkFind(data_source, version_name, NULL, rrclass, rrclass, - rrtype, rrttl, 0, version_soa_data); - checkFind(data_source, version_name, &version_name, rrclass, rrclass, - rrtype, rrttl, 0, version_soa_data); -} - -TEST_F(StaticDataSourceTest, findRRsetVersionANY) { - rrtype = RRType::ANY(); - - types.push_back(RRType::TXT()); - types.push_back(RRType::NS()); - types.push_back(RRType::SOA()); - ttls.push_back(rrttl); - ttls.push_back(rrttl); - ttls.push_back(rrttl); - answers.push_back(&version_data); - answers.push_back(&version_ns_data); - answers.push_back(&version_soa_data); - - checkFind(data_source, version_name, NULL, rrclass, rrclass, rrtype, ttls, - 0, types, answers); - checkFind(data_source, version_name, &version_name, rrclass, rrclass, - rrtype, ttls, 0, types, answers); -} - -TEST_F(StaticDataSourceTest, findRRsetAuthorsTXT) { - checkFind(data_source, authors_name, NULL, rrclass, rrclass, - rrtype, rrttl, 0, authors_data); - checkFind(data_source, authors_name, &authors_name, rrclass, rrclass, - rrtype, rrttl, 0, authors_data); -} - -TEST_F(StaticDataSourceTest, findRRsetAuthorsNS) { - rrtype = RRType::NS(); - checkFind(data_source, authors_name, NULL, rrclass, rrclass, - rrtype, rrttl, 0, authors_ns_data); - checkFind(data_source, authors_name, &authors_name, rrclass, rrclass, - rrtype, rrttl, 0, authors_ns_data); -} - -TEST_F(StaticDataSourceTest, findRRsetAuthorsSOA) { - rrtype = RRType::SOA(); - checkFind(data_source, authors_name, NULL, rrclass, rrclass, - rrtype, rrttl, 0, authors_soa_data); - checkFind(data_source, authors_name, &authors_name, rrclass, rrclass, - rrtype, rrttl, 0, authors_soa_data); -} - -TEST_F(StaticDataSourceTest, findRRsetAuthorsANY) { - rrtype = RRType::ANY(); - - types.push_back(RRType::TXT()); - types.push_back(RRType::NS()); - types.push_back(RRType::SOA()); - ttls.push_back(rrttl); - ttls.push_back(rrttl); - ttls.push_back(rrttl); - answers.push_back(&authors_data); - answers.push_back(&authors_ns_data); - answers.push_back(&authors_soa_data); - - checkFind(data_source, authors_name, NULL, rrclass, rrclass, rrtype, ttls, - 0, types, answers); - checkFind(data_source, authors_name, &authors_name, rrclass, rrclass, - rrtype, ttls, 0, types, answers); -} -// Class ANY lookup should result in the same answer. -TEST_F(StaticDataSourceTest, findRRsetVersionClassAny) { - checkFind(data_source, version_name, NULL, RRClass::ANY(), rrclass, - rrtype, rrttl, 0, version_data); - checkFind(data_source, version_name, &version_name, RRClass::ANY(), rrclass, - rrtype, rrttl, 0, version_data); -} - -// If the class doesn't match, it should simply fail. -TEST_F(StaticDataSourceTest, findRRsetVersionClassMismatch) { - EXPECT_EQ(DataSrc::ERROR, - data_source.findRRset(version_name, RRClass::IN(), rrtype, - result_sets, find_flags, &version_name)); -} - -TEST_F(StaticDataSourceTest, findRRsetOutOfZone) { - // If the qname doesn't match any of the static zones, the result should - // be "no such zone", regardless of whether the zone is explicitly - // specified. Other "expected" result parameters will be ignored. - checkFind(data_source, nomatch_name, NULL, rrclass, rrclass, - rrtype, rrttl, DataSrc::NO_SUCH_ZONE, authors_ns_data); - checkFind(data_source, nomatch_name, &version_name, rrclass, rrclass, - rrtype, rrttl, DataSrc::NO_SUCH_ZONE, authors_ns_data); - checkFind(data_source, nomatch_name, &authors_name, rrclass, rrclass, - rrtype, rrttl, DataSrc::NO_SUCH_ZONE, authors_ns_data); -} - -// If a zone name is given but doesn't match any of the static zones, -// the result should be "no such zone" -TEST_F(StaticDataSourceTest, findRRsetZoneMismatch) { - const Name& short_zonename(Name("bind")); - checkFind(data_source, version_name, &short_zonename, rrclass, rrclass, - rrtype, rrttl, DataSrc::NO_SUCH_ZONE, authors_ns_data); - checkFind(data_source, authors_name, &short_zonename, rrclass, rrclass, - rrtype, rrttl, DataSrc::NO_SUCH_ZONE, authors_ns_data); -} - -// Zone matches, but name doesn't exist in the zone -TEST_F(StaticDataSourceTest, findRRsetNoName) { - checkFind(data_source, Name("foo").concatenate(version_name), NULL, rrclass, - rrclass, rrtype, rrttl, DataSrc::NAME_NOT_FOUND, authors_ns_data); - checkFind(data_source, Name("foo").concatenate(version_name), &version_name, - rrclass, rrclass, rrtype, rrttl, DataSrc::NAME_NOT_FOUND, - authors_ns_data); - checkFind(data_source, Name("foo").concatenate(authors_name), NULL, rrclass, - rrclass, rrtype, rrttl, DataSrc::NAME_NOT_FOUND, authors_ns_data); - checkFind(data_source, Name("foo").concatenate(authors_name), &authors_name, - rrclass, rrclass, rrtype, rrttl, DataSrc::NAME_NOT_FOUND, - authors_ns_data); -} - -// Zone matches and qname exists, but type doesn't exist for the name. -TEST_F(StaticDataSourceTest, findRRsetNoType) { - const RRType& nomatch_type = RRType::A(); - - checkFind(data_source, version_name, NULL, rrclass, - rrclass, nomatch_type, rrttl, DataSrc::TYPE_NOT_FOUND, - authors_ns_data); - checkFind(data_source, version_name, &version_name, rrclass, - rrclass, nomatch_type, rrttl, DataSrc::TYPE_NOT_FOUND, - authors_ns_data); - checkFind(data_source, authors_name, NULL, rrclass, - rrclass, nomatch_type, rrttl, DataSrc::TYPE_NOT_FOUND, - authors_ns_data); - checkFind(data_source, authors_name, &authors_name, rrclass, - rrclass, nomatch_type, rrttl, DataSrc::TYPE_NOT_FOUND, - authors_ns_data); -} - -// Simple tests for "unsupported" tests. -TEST_F(StaticDataSourceTest, notImplemented) { - Name target_name(version_name); - EXPECT_EQ(DataSrc::NOT_IMPLEMENTED, - data_source.findPreviousName(version_name, target_name, - &version_name)); - - string target_hash; - EXPECT_EQ(DataSrc::NOT_IMPLEMENTED, - data_source.findCoveringNSEC3(version_name, target_hash, - result_sets)); -} - -}