Commit 009d45df authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

[trac1067] Tests for in-memory iteration

parent f1d52ff7
......@@ -25,6 +25,7 @@
namespace isc {
namespace datasrc {
// The iterator.h is not included on purpose, most application won't need it
class ZoneIterator;
typedef boost::shared_ptr<ZoneIterator> ZoneIteratorPtr;
......
......@@ -29,6 +29,8 @@
#include <dns/masterload.h>
#include <datasrc/memory_datasrc.h>
#include <datasrc/data_source.h>
#include <datasrc/iterator.h>
#include <gtest/gtest.h>
......@@ -138,6 +140,43 @@ TEST_F(InMemoryClientTest, add_find_Zone) {
getOrigin());
}
TEST_F(InMemoryClientTest, iterator) {
// Just some preparations of data
boost::shared_ptr<InMemoryZoneFinder>
zone(new InMemoryZoneFinder(RRClass::IN(), Name("a")));
RRsetPtr aRRsetA(new RRset(Name("a"), RRClass::IN(), RRType::A(),
RRTTL(300)));
aRRsetA->addRdata(rdata::in::A("192.0.2.1"));
RRsetPtr aRRsetAAAA(new RRset(Name("a"), RRClass::IN(), RRType::AAAA(),
RRTTL(300)));
aRRsetAAAA->addRdata(rdata::in::AAAA("2001:db8::1"));
aRRsetAAAA->addRdata(rdata::in::AAAA("2001:db8::2"));
RRsetPtr subRRsetA(new RRset(Name("sub.x.a"), RRClass::IN(), RRType::A(),
RRTTL(300)));
subRRsetA->addRdata(rdata::in::A("192.0.2.2"));
EXPECT_EQ(result::SUCCESS, memory_client.addZone(
ZoneFinderPtr(new InMemoryZoneFinder(RRClass::IN(),
Name("a")))));
// First, the zone is not there, so it should throw
EXPECT_THROW(memory_client.getIterator(Name("b")), DataSourceError);
// Now, an empty zone
ZoneIteratorPtr iterator(memory_client.getIterator(Name("a")));
EXPECT_EQ(ConstRRsetPtr(), iterator->getNextRRset());
// It throws Unexpected when we are past the end
EXPECT_THROW(iterator->getNextRRset(), isc::Unexpected);
EXPECT_EQ(result::SUCCESS, zone->add(aRRsetA));
EXPECT_EQ(result::SUCCESS, zone->add(aRRsetAAAA));
EXPECT_EQ(result::SUCCESS, zone->add(subRRsetA));
// Check it with full zone, one by one.
// It should be in ascending order in case of InMemory data source
// (isn't guaranteed in general)
iterator = memory_client.getIterator(Name("a"));
EXPECT_EQ(aRRsetA, iterator->getNextRRset());
EXPECT_EQ(aRRsetAAAA, iterator->getNextRRset());
EXPECT_EQ(subRRsetA, iterator->getNextRRset());
EXPECT_EQ(ConstRRsetPtr(), iterator->getNextRRset());
}
TEST_F(InMemoryClientTest, getZoneCount) {
EXPECT_EQ(0, memory_client.getZoneCount());
memory_client.addZone(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment