BIND 10 trac2376-callbacks, updated. d848160aede1dceacc9a2e45eb4ebb00fe51f102 [2376] Add missing test file
BIND 10 source code commits
bind10-changes at lists.isc.org
Sat Nov 17 13:08:19 UTC 2012
The branch, trac2376-callbacks has been updated
via d848160aede1dceacc9a2e45eb4ebb00fe51f102 (commit)
from 94b80d73b69ecbd781d449798a8e993bcd2f098a (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 d848160aede1dceacc9a2e45eb4ebb00fe51f102
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Sat Nov 17 14:08:11 2012 +0100
[2376] Add missing test file
-----------------------------------------------------------------------
Summary of changes:
src/lib/datasrc/tests/Makefile.am | 2 +-
src/lib/datasrc/tests/loader_callbacks_test.cc | 133 ++++++++++++++++++++++++
2 files changed, 134 insertions(+), 1 deletion(-)
create mode 100644 src/lib/datasrc/tests/loader_callbacks_test.cc
-----------------------------------------------------------------------
diff --git a/src/lib/datasrc/tests/Makefile.am b/src/lib/datasrc/tests/Makefile.am
index ed2723e..c265f2e 100644
--- a/src/lib/datasrc/tests/Makefile.am
+++ b/src/lib/datasrc/tests/Makefile.am
@@ -59,7 +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
+run_unittests_SOURCES += loader_callbacks_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_callbacks_test.cc b/src/lib/datasrc/tests/loader_callbacks_test.cc
new file mode 100644
index 0000000..2bacae6
--- /dev/null
+++ b/src/lib/datasrc/tests/loader_callbacks_test.cc
@@ -0,0 +1,133 @@
+// 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_callbacks.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 {
+protected:
+ LoaderContextTest() :
+ ok_(true),
+ callbacks_(createCallbacks(updater_, isc::dns::Name("example.org"),
+ isc::dns::RRClass::IN(), &ok_))
+ {}
+ // 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_;
+ // Is the loading OK?
+ bool ok_;
+ // The tested context
+ isc::dns::LoaderCallbacks callbacks_;
+};
+
+// Check it doesn't crash if we don't provide the OK
+TEST_F(LoaderContextTest, noOkProvided) {
+ createCallbacks(updater_, isc::dns::Name("example.org"),
+ isc::dns::RRClass::IN(), NULL).error("No source", 1,
+ "No reason");
+}
+
+// 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) {
+ EXPECT_NO_THROW(callbacks_.warning("No source", 1, "Just for fun"));
+ // The warning does not hurt the OK mode.
+ EXPECT_TRUE(ok_);
+ // Now the error
+ EXPECT_NO_THROW(callbacks_.error("No source", 2, "Some error"));
+ // The OK is turned off once there's at least one error
+ EXPECT_FALSE(ok_);
+
+ // Not being OK does not hurt that much, we can still call the callbacks
+ EXPECT_NO_THROW(callbacks_.warning("No source", 3, "Just for fun"));
+ // The OK is not reset back to true
+ EXPECT_FALSE(ok_);
+ EXPECT_NO_THROW(callbacks_.error("No source", 4, "Some error"));
+}
+
+// Try adding some RRsets.
+TEST_F(LoaderContextTest, addRRset) {
+ // Put some of them in.
+ EXPECT_NO_THROW(callbacks_.addRRset(generateRRset()));
+ EXPECT_NO_THROW(callbacks_.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.
+ callbacks_.error("No source", 1, "Just an error");
+ EXPECT_FALSE(ok_);
+
+ EXPECT_NO_THROW(callbacks_.addRRset(generateRRset()));
+ EXPECT_NO_THROW(callbacks_.addRRset(generateRRset()));
+ // They got through and the OK status didn't get reset
+ EXPECT_TRUE(updater_.expected_rrsets_.empty());
+ EXPECT_FALSE(ok_);
+}
+
+}
More information about the bind10-changes
mailing list