Browse Source

[1975] Start writing some tests for the container

This time, only tests for the empty data source container.
Michal 'vorner' Vaner 13 years ago
parent
commit
15a1714785

+ 20 - 0
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");
+}
+
+}
+}

+ 31 - 0
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,26 @@ 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 {};
+    /// \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

+ 1 - 0
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)

+ 67 - 0
src/lib/datasrc/tests/container_unittest.cc

@@ -0,0 +1,67 @@
+// 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 <gtest/gtest.h>
+
+using namespace isc::datasrc;
+using namespace isc::data;
+using namespace isc::dns;
+using namespace boost;
+
+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)
+    { }
+};
+
+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))
+    { }
+    shared_ptr<TestedContainer> container_;
+};
+
+// 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) {
+    Container::SearchResult negativeResult;
+    // 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));
+}
+
+}