BIND 10 trac1975, updated. f1af1f3ba715af99d1fbade8eea193deabb405a5 [1975] The test data source now returns

BIND 10 source code commits bind10-changes at lists.isc.org
Mon Jun 4 15:18:05 UTC 2012


The branch, trac1975 has been updated
       via  f1af1f3ba715af99d1fbade8eea193deabb405a5 (commit)
       via  d95ff3f155636aa484dbba780ed5264335387905 (commit)
       via  15a17147855caf469e55b6fc3d3827f496bd0025 (commit)
      from  170c72d67a741e958611e7267826679b0629286a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit f1af1f3ba715af99d1fbade8eea193deabb405a5
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Mon Jun 4 17:17:50 2012 +0200

    [1975] The test data source now returns

commit d95ff3f155636aa484dbba780ed5264335387905
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Mon Jun 4 16:36:51 2012 +0200

    [1975] Tests for container of one data source
    
    Checks it can find zones if there's only one data source inside. Caches
    are not considered yet at all. The fake data source needs some
    implementation.

commit 15a17147855caf469e55b6fc3d3827f496bd0025
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Mon Jun 4 16:00:37 2012 +0200

    [1975] Start writing some tests for the container
    
    This time, only tests for the empty data source container.

-----------------------------------------------------------------------

Summary of changes:
 src/lib/datasrc/container.cc                |   20 +++
 src/lib/datasrc/container.h                 |   33 +++++
 src/lib/datasrc/tests/Makefile.am           |    1 +
 src/lib/datasrc/tests/container_unittest.cc |  197 +++++++++++++++++++++++++++
 4 files changed, 251 insertions(+)
 create mode 100644 src/lib/datasrc/tests/container_unittest.cc

-----------------------------------------------------------------------
diff --git a/src/lib/datasrc/container.cc b/src/lib/datasrc/container.cc
index c568827..71ec75b 100644
--- a/src/lib/datasrc/container.cc
+++ b/src/lib/datasrc/container.cc
@@ -13,3 +13,23 @@
 // PERFORMANCE OF THIS SOFTWARE.
 
 #include "container.h"
+
+using namespace isc::data;
+
+namespace isc {
+namespace datasrc {
+
+ConfigurableContainer::ConfigurableContainer(const ConstElementPtr&, bool,
+                                             const ConstContainerPtr&)
+{
+    // TODO: Implement
+}
+
+Container::SearchResult
+ConfigurableContainer::search(const dns::Name& , bool , bool ) const {
+    // TODO: Implement
+    isc_throw(NotImplemented, "A virtual unimplemented method, just to make it compile for now");
+}
+
+}
+}
diff --git a/src/lib/datasrc/container.h b/src/lib/datasrc/container.h
index 5a42646..d612e1f 100644
--- a/src/lib/datasrc/container.h
+++ b/src/lib/datasrc/container.h
@@ -19,6 +19,7 @@
 #include <cc/data.h>
 #include <exceptions/exceptions.h>
 
+#include <vector>
 #include <boost/shared_ptr.hpp>
 #include <boost/noncopyable.hpp>
 
@@ -74,6 +75,16 @@ public:
             matched_labels_(0),
             exact_match_(false)
         { }
+        /// \brief Comparison operator.
+        ///
+        /// It is needed for tests and it might be of some use elsewhere
+        /// too.
+        bool operator ==(const SearchResult& other) const {
+            return (datasrc_ == other.datasrc_ &&
+                    finder_ == other.finder_ &&
+                    matched_labels_ == other.matched_labels_ &&
+                    exact_match_ == other.exact_match_);
+        }
         /// \brief The found data source.
         ///
         /// The data source containing the best matching zone. If no such
@@ -193,6 +204,28 @@ public:
     virtual SearchResult search(const dns::Name& zone,
                                 bool want_exact_match = false,
                                 bool want_finder = true) const;
+
+    /// \brief This holds one data source and corresponding information.
+    ///
+    /// \todo The content yet to be defined.
+    struct DataSourceInfo {
+        DataSourceClientPtr data_src_;
+    };
+    /// \brief The collection of data sources.
+    typedef std::vector<DataSourceInfo> DataSources;
+protected:
+    /// \brief The data sources held here.
+    ///
+    /// All our data sources are stored here. It is protected to let the
+    /// tests in.
+    DataSources data_sources_;
+public:
+    /// \brief Access to the data sources.
+    ///
+    /// It can be used to examine the loaded list of data sources directly.
+    /// It is not known if it is of any use other than testing, but it might
+    /// be, so it is just made public.
+    const DataSources& dataSources() const { return (data_sources_); }
 };
 
 } // namespace datasrc
diff --git a/src/lib/datasrc/tests/Makefile.am b/src/lib/datasrc/tests/Makefile.am
index 6c4a937..63ef55b 100644
--- a/src/lib/datasrc/tests/Makefile.am
+++ b/src/lib/datasrc/tests/Makefile.am
@@ -59,6 +59,7 @@ run_unittests_SOURCES += memory_datasrc_unittest.cc
 run_unittests_SOURCES += rbnode_rrset_unittest.cc
 run_unittests_SOURCES += zone_finder_context_unittest.cc
 run_unittests_SOURCES += faked_nsec3.h faked_nsec3.cc
+run_unittests_SOURCES += container_unittest.cc
 
 # We need the actual module implementation in the tests (they are not part
 # of libdatasrc)
diff --git a/src/lib/datasrc/tests/container_unittest.cc b/src/lib/datasrc/tests/container_unittest.cc
new file mode 100644
index 0000000..0d6bb0c
--- /dev/null
+++ b/src/lib/datasrc/tests/container_unittest.cc
@@ -0,0 +1,197 @@
+// 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 <datasrc/container.h>
+#include <datasrc/client.h>
+
+#include <dns/rrclass.h>
+
+#include <gtest/gtest.h>
+
+#include <set>
+
+using namespace isc::datasrc;
+using namespace isc::data;
+using namespace isc::dns;
+using namespace boost;
+using namespace std;
+
+namespace {
+
+// The test version is the same as the normal version. We, however, add
+// some methods to dig directly in the internals, for the tests.
+class TestedContainer : public ConfigurableContainer {
+public:
+    TestedContainer(const ConstElementPtr& configuration,
+                    bool allow_cache) :
+        ConfigurableContainer(configuration, allow_cache)
+    { }
+    DataSources& dataSources() { return (data_sources_); }
+};
+
+// A test data source. It pretends it has some zones.
+class TestDS : public DataSourceClient {
+public:
+    class Finder : public ZoneFinder {
+    public:
+        Finder(const Name& origin) :
+            origin_(origin)
+        { }
+        Name getOrigin() const { return (origin_); }
+        // The rest is not to be called, so just have them
+        RRClass getClass() const {
+            isc_throw(isc::NotImplemented, "Not implemented");
+        }
+        shared_ptr<Context> find(const Name&, const RRType&,
+                                 const FindOptions)
+        {
+            isc_throw(isc::NotImplemented, "Not implemented");
+        }
+        shared_ptr<Context> findAll(const Name&,
+                                    vector<ConstRRsetPtr>&,
+                                    const FindOptions)
+        {
+            isc_throw(isc::NotImplemented, "Not implemented");
+        }
+        FindNSEC3Result findNSEC3(const Name&, bool) {
+            isc_throw(isc::NotImplemented, "Not implemented");
+        }
+        Name findPreviousName(const Name&) const {
+            isc_throw(isc::NotImplemented, "Not implemented");
+        }
+    private:
+        Name origin_;
+    };
+    TestDS(const char* zone_names[]) {
+        for (const char** zone(zone_names); *zone; ++ zone) {
+            zones.insert(Name(*zone));
+        }
+    }
+    virtual FindResult findZone(const Name& name) const {
+        set<Name>::const_iterator it(zones.lower_bound(name));
+        if (it == zones.end()) {
+            return (FindResult(result::NOTFOUND, ZoneFinderPtr()));
+        } else {
+            NameComparisonResult compar(it->compare(name));
+            const ZoneFinderPtr finder(new Finder(*it));
+            switch (compar.getRelation()) {
+                case NameComparisonResult::EQUAL:
+                    return (FindResult(result::SUCCESS, finder));
+                case NameComparisonResult::SUPERDOMAIN:
+                    return (FindResult(result::PARTIALMATCH, finder));
+                default:
+                    return (FindResult(result::NOTFOUND, ZoneFinderPtr()));
+            }
+        }
+    }
+    // These methods are not used. They just need to be there to have
+    // complete vtable.
+    virtual ZoneUpdaterPtr getUpdater(const Name&, bool, bool) const {
+        isc_throw(isc::NotImplemented, "Not implemented");
+    }
+    virtual pair<ZoneJournalReader::Result, ZoneJournalReaderPtr>
+        getJournalReader(const Name&, uint32_t, uint32_t) const
+    {
+        isc_throw(isc::NotImplemented, "Not implemented");
+    }
+private:
+    set<Name> zones;
+};
+
+const char* ds1_zones[] = {
+    "example.org.",
+    "example.com."
+};
+
+class ContainerTest : public ::testing::Test {
+public:
+    ContainerTest() :
+        // The empty list corresponds to a container with no elements inside
+        container_(new TestedContainer(ConstElementPtr(new ListElement()),
+                                       true)),
+        ds1_(new TestDS(ds1_zones))
+    {
+        ds1_info_.data_src_ = ds1_;
+    }
+    shared_ptr<TestedContainer> container_;
+    const Container::SearchResult negativeResult_;
+    shared_ptr<TestDS> ds1_;
+    ConfigurableContainer::DataSourceInfo ds1_info_;
+};
+
+// Test the container we create with empty configuration is, in fact, empty
+TEST_F(ContainerTest, emptyContainer) {
+    EXPECT_TRUE(container_->dataSources().empty());
+}
+
+// Check the values returned by a search on an empty container. It should be
+// a negative answer (nothing found) no matter if we want an exact or inexact
+// match.
+TEST_F(ContainerTest, emptySearch) {
+    // No matter what we try, we don't get an answer.
+    EXPECT_EQ(negativeResult_, container_->search(Name("example.org"), false,
+                                                 false));
+    EXPECT_EQ(negativeResult_, container_->search(Name("example.org"), false,
+                                                 true));
+    EXPECT_EQ(negativeResult_, container_->search(Name("example.org"), true,
+                                                 false));
+    EXPECT_EQ(negativeResult_, container_->search(Name("example.org"), true,
+                                                 true));
+}
+
+// Put a single data source inside the container and check it can find an
+// exact match if there's one.
+TEST_F(ContainerTest, singleDSExactMatch) {
+    container_->dataSources().push_back(ds1_info_);
+    // This zone is not there
+    EXPECT_EQ(negativeResult_, container_->search(Name("org."), true));
+    // But this one is, so check it.
+    const Container::SearchResult
+        result(container_->search(Name("example.org"), true));
+    EXPECT_EQ(ds1_, result.datasrc_);
+    ASSERT_NE(ZoneFinderPtr(), result.finder_);
+    EXPECT_EQ(Name("example.org"), result.finder_->getOrigin());
+    EXPECT_EQ(2, result.matched_labels_);
+    EXPECT_TRUE(result.exact_match_);
+    // When asking for a sub zone of a zone there, we get nothing
+    // (we want exact match, this would be partial one)
+    EXPECT_EQ(negativeResult_, container_->search(Name("sub.example.org."),
+                                                  true));
+}
+
+// When asking for a partial match, we get all that the exact one, but more.
+TEST_F(ContainerTest, singleDSBestMatch) {
+    container_->dataSources().push_back(ds1_info_);
+    // This zone is not there
+    EXPECT_EQ(negativeResult_, container_->search(Name("org.")));
+    // But this one is, so check it.
+    const Container::SearchResult
+        result(container_->search(Name("example.org")));
+    EXPECT_EQ(ds1_, result.datasrc_);
+    ASSERT_NE(ZoneFinderPtr(), result.finder_);
+    EXPECT_EQ(Name("example.org"), result.finder_->getOrigin());
+    EXPECT_EQ(2, result.matched_labels_);
+    EXPECT_TRUE(result.exact_match_);
+    // When asking for a sub zone of a zone there, we get nothing
+    // (we want exact match, this would be partial one)
+    const Container::SearchResult
+        partialResult(container_->search(Name("sub.example.org.")));
+    EXPECT_EQ(ds1_, partialResult.datasrc_);
+    ASSERT_NE(ZoneFinderPtr(), partialResult.finder_);
+    EXPECT_EQ(Name("example.org"), partialResult.finder_->getOrigin());
+    EXPECT_EQ(2, partialResult.matched_labels_);
+    EXPECT_FALSE(partialResult.exact_match_);
+}
+
+}



More information about the bind10-changes mailing list