BIND 10 trac2376, updated. 15bd8b64fbd62d313b6d91ae5b70ff548a7cce2b [2376] Test adding RRsets
BIND 10 source code commits
bind10-changes at lists.isc.org
Wed Nov 7 12:27:51 UTC 2012
The branch, trac2376 has been updated
via 15bd8b64fbd62d313b6d91ae5b70ff548a7cce2b (commit)
via 4505781583df99c90346180f083019c04a968fcd (commit)
via 488d8709a1ef79eac0e994aa3d19e400694cdd0a (commit)
via 97a61b4085a815d92ce5dfcbfc0192da7dd74509 (commit)
via 8a0720804168493dce74510e46673b74aefede8b (commit)
from 5a110df6b6634a161c391d37abcf12fddb26ae16 (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 15bd8b64fbd62d313b6d91ae5b70ff548a7cce2b
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Wed Nov 7 13:25:14 2012 +0100
[2376] Test adding RRsets
commit 4505781583df99c90346180f083019c04a968fcd
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Wed Nov 7 13:02:38 2012 +0100
[2376] Test the callbacks
commit 488d8709a1ef79eac0e994aa3d19e400694cdd0a
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Wed Nov 7 12:57:08 2012 +0100
[2376] Test newly-created context acts sanely
commit 97a61b4085a815d92ce5dfcbfc0192da7dd74509
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Wed Nov 7 12:42:16 2012 +0100
[2376] Skeleton of the tests
This includes the test fixture and a mock updater to test against. No
real tests are present yet.
It does not compile, since there are no methods in the LoaderContext.
commit 8a0720804168493dce74510e46673b74aefede8b
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Wed Nov 7 12:01:02 2012 +0100
[2376] Fix includes
It should be possible to include any header alone. This one was missing
some definition.
-----------------------------------------------------------------------
Summary of changes:
src/lib/datasrc/tests/Makefile.am | 1 +
src/lib/datasrc/tests/loader_context_test.cc | 135 ++++++++++++++++++++++++++
src/lib/datasrc/tests/test_client.cc | 5 +-
src/lib/datasrc/tests/test_client.h | 2 +
src/lib/dns/master_loader.h | 4 +-
5 files changed, 142 insertions(+), 5 deletions(-)
create mode 100644 src/lib/datasrc/tests/loader_context_test.cc
-----------------------------------------------------------------------
diff --git a/src/lib/datasrc/tests/Makefile.am b/src/lib/datasrc/tests/Makefile.am
index d2049f1..ed2723e 100644
--- a/src/lib/datasrc/tests/Makefile.am
+++ b/src/lib/datasrc/tests/Makefile.am
@@ -59,6 +59,7 @@ run_unittests_SOURCES += zonetable_unittest.cc
run_unittests_SOURCES += zone_finder_context_unittest.cc
run_unittests_SOURCES += faked_nsec3.h faked_nsec3.cc
run_unittests_SOURCES += client_list_unittest.cc
+run_unittests_SOURCES += loader_context_test.cc
# We need the actual module implementation in the tests (they are not part
# of libdatasrc)
diff --git a/src/lib/datasrc/tests/loader_context_test.cc b/src/lib/datasrc/tests/loader_context_test.cc
new file mode 100644
index 0000000..4ef9b24
--- /dev/null
+++ b/src/lib/datasrc/tests/loader_context_test.cc
@@ -0,0 +1,135 @@
+// 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/loader_context.h>
+#include <datasrc/zone.h>
+
+#include <dns/rrset.h>
+#include <dns/rrclass.h>
+#include <dns/rrttl.h>
+
+#include <exceptions/exceptions.h>
+
+#include <gtest/gtest.h>
+
+#include <boost/lexical_cast.hpp>
+
+#include <list>
+#include <string>
+
+using namespace isc::datasrc;
+
+namespace {
+
+// An updater for the tests. Most of the virtual methods throw
+// NotImplemented, as they are not used in the tests.
+class MockUpdater : public ZoneUpdater {
+public:
+ // We do the adding in this test. We currently only check these are
+ // the correct ones, according to a predefined set in a list.
+ virtual void addRRset(const isc::dns::AbstractRRset& rrset) {
+ ASSERT_FALSE(expected_rrsets_.empty());
+ // In our tests, pointer equality is enough.
+ EXPECT_EQ(expected_rrsets_.front().get(), &rrset);
+ // And remove this RRset, as it has been used.
+ expected_rrsets_.pop_front();
+ }
+ // The unused but required methods
+ virtual ZoneFinder& getFinder() {
+ isc_throw(isc::NotImplemented, "Not to be called in this test");
+ }
+ virtual void deleteRRset(const isc::dns::AbstractRRset&) {
+ isc_throw(isc::NotImplemented, "Not to be called in this test");
+ }
+ virtual void commit() {
+ isc_throw(isc::NotImplemented, "Not to be called in this test");
+ }
+ // The RRsets that are expected to appear through addRRset.
+ std::list<isc::dns::RRsetPtr> expected_rrsets_;
+};
+
+class LoaderContextTest : public ::testing::Test {
+public:
+ LoaderContextTest() :
+ context_(updater_)
+ {}
+protected:
+ // Generate a new RRset, put it to the updater and return it.
+ isc::dns::RRsetPtr generateRRset() {
+ const isc::dns::RRsetPtr
+ result(new isc::dns::RRset(isc::dns::Name("example.org"),
+ isc::dns::RRClass::IN(),
+ isc::dns::RRType::A(),
+ isc::dns::RRTTL(3600)));
+ updater_.expected_rrsets_.push_back(result);
+ return (result);
+ }
+ // An updater to be passed to the context
+ MockUpdater updater_;
+ // The tested context
+ LoaderContext context_;
+};
+
+// Check the context can be created and has the correct default values.
+// The construction happens within the constructor of the test fixture.
+TEST_F(LoaderContextTest, constructor) {
+ // The status is OK, nothing broke yet
+ EXPECT_TRUE(context_.ok());
+ // Get the callbacks and check both are non-empty
+ const isc::dns::LoaderCallbacks& callbacks(context_.getCallbacks());
+ EXPECT_FALSE(callbacks.warning.empty());
+ EXPECT_FALSE(callbacks.error.empty());
+}
+
+// Check the callbacks can be called, don't crash and the error one switches
+// to non-OK mode. This, however, does not stop anybody from calling more
+// callbacks.
+TEST_F(LoaderContextTest, callbacks) {
+ const isc::dns::LoaderCallbacks& callbacks(context_.getCallbacks());
+ EXPECT_NO_THROW(callbacks.warning("No source", 1, 1, "Just for fun"));
+ // The warning does not hurt the OK mode.
+ EXPECT_TRUE(context_.ok());
+ // Now the error
+ EXPECT_NO_THROW(callbacks.error("No source", 2, 4, "Some error"));
+ // The OK is turned off once there's at least one error
+ EXPECT_FALSE(context_.ok());
+
+ // Not being OK does not hurt that much, we can still call the callbacks
+ EXPECT_NO_THROW(callbacks.warning("No source", 3, 5, "Just for fun"));
+ // The OK is not reset back to true
+ EXPECT_FALSE(context_.ok());
+ EXPECT_NO_THROW(callbacks.error("No source", 4, 7, "Some error"));
+}
+
+// Try adding some RRsets.
+TEST_F(LoaderContextTest, addRRset) {
+ // Put some of them in.
+ EXPECT_NO_THROW(context_.addRRset(generateRRset()));
+ EXPECT_NO_THROW(context_.addRRset(generateRRset()));
+ // They all get pushed there right away, so there are none in the queue
+ EXPECT_TRUE(updater_.expected_rrsets_.empty());
+
+ // Making the status not OK by an error does not stop the RRsets to get
+ // through.
+ context_.getCallbacks().error("No source", 1, 1, "Just an error");
+ EXPECT_FALSE(context_.ok());
+
+ EXPECT_NO_THROW(context_.addRRset(generateRRset()));
+ EXPECT_NO_THROW(context_.addRRset(generateRRset()));
+ // They got through and the OK status didn't get reset
+ EXPECT_TRUE(updater_.expected_rrsets_.empty());
+ EXPECT_FALSE(context_.ok());
+}
+
+}
diff --git a/src/lib/datasrc/tests/test_client.cc b/src/lib/datasrc/tests/test_client.cc
index c7854ed..92bfc1b 100644
--- a/src/lib/datasrc/tests/test_client.cc
+++ b/src/lib/datasrc/tests/test_client.cc
@@ -12,18 +12,17 @@
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
+#include "test_client.h"
+
#include <exceptions/exceptions.h>
#include <dns/masterload.h>
#include <dns/name.h>
#include <dns/rrclass.h>
-#include <datasrc/client.h>
#include <datasrc/zone.h>
#include <datasrc/sqlite3_accessor.h>
-#include "test_client.h"
-
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
diff --git a/src/lib/datasrc/tests/test_client.h b/src/lib/datasrc/tests/test_client.h
index 1e35cd3..e03bdff 100644
--- a/src/lib/datasrc/tests/test_client.h
+++ b/src/lib/datasrc/tests/test_client.h
@@ -15,6 +15,8 @@
#ifndef TEST_DATA_SOURCE_CLIENT_H
#define TEST_DATA_SOURCE_CLIENT_H 1
+#include <datasrc/client.h>
+
#include <dns/name.h>
#include <dns/rrclass.h>
diff --git a/src/lib/dns/master_loader.h b/src/lib/dns/master_loader.h
index 6845f15..bd9ba6d 100644
--- a/src/lib/dns/master_loader.h
+++ b/src/lib/dns/master_loader.h
@@ -15,14 +15,14 @@
#ifndef MASTER_LOADER_H
#define MASTER_LOADER_H
+#include <dns/rrset.h>
+
#include <string>
#include <boost/function.hpp>
namespace isc {
namespace dns {
-class RRsetPtr;
-
/// \brief Set of callbacks for a loader.
///
/// This holds a set of callbacks by which a loader (such as MasterLoader)
More information about the bind10-changes
mailing list