1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- // Copyright (C) 2013 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/memory/rrset_collection.h>
- #include <datasrc/memory/zone_data_loader.h>
- #include <datasrc/memory/segment_object_holder.h>
- #include <dns/rrttl.h>
- #include <dns/rdataclass.h>
- #include <datasrc/tests/memory/memory_segment_mock.h>
- #include <gtest/gtest.h>
- #include <boost/scoped_ptr.hpp>
- using namespace isc::dns;
- using namespace isc::dns::rdata;
- using namespace std;
- using namespace isc::datasrc;
- using namespace isc::datasrc::memory;
- using namespace isc::datasrc::memory::detail;
- namespace {
- // Note: This class uses loadZoneData() to construct a ZoneData object,
- // which internally uses an RRsetCollection for validation. We assume
- // that loadZoneData() works at this point and test the RRsetCollection
- // around the ZoneData returned.
- class RRsetCollectionTest : public ::testing::Test {
- public:
- RRsetCollectionTest() :
- rrclass("IN"),
- origin("example.org"),
- zone_file(TEST_DATA_DIR "/rrset-collection.zone"),
- zone_data_holder(mem_sgmt, rrclass)
- {
- zone_data_holder.set(loadZoneData(mem_sgmt, rrclass, origin,
- zone_file));
- collection.reset(new RRsetCollection(*zone_data_holder.get(),
- rrclass));
- }
- const RRClass rrclass;
- const Name origin;
- std::string zone_file;
- test::MemorySegmentMock mem_sgmt;
- SegmentObjectHolder<ZoneData, RRClass> zone_data_holder;
- boost::scoped_ptr<RRsetCollection> collection;
- };
- TEST_F(RRsetCollectionTest, find) {
- const RRsetCollection& ccln = *collection;
- ConstRRsetPtr rrset = ccln.find(Name("www.example.org"), rrclass,
- RRType::A());
- EXPECT_TRUE(rrset);
- EXPECT_EQ(RRType::A(), rrset->getType());
- EXPECT_EQ(RRTTL(3600), rrset->getTTL());
- EXPECT_EQ(RRClass("IN"), rrset->getClass());
- EXPECT_EQ(Name("www.example.org"), rrset->getName());
- // foo.example.org doesn't exist
- rrset = ccln.find(Name("foo.example.org"), rrclass, RRType::A());
- EXPECT_FALSE(rrset);
- // www.example.org exists, but not with MX
- rrset = ccln.find(Name("www.example.org"), rrclass, RRType::MX());
- EXPECT_FALSE(rrset);
- // www.example.org exists, with AAAA
- rrset = ccln.find(Name("www.example.org"), rrclass, RRType::AAAA());
- EXPECT_TRUE(rrset);
- // www.example.org with AAAA does not exist in RRClass::CH()
- rrset = ccln.find(Name("www.example.org"), RRClass::CH(),
- RRType::AAAA());
- EXPECT_FALSE(rrset);
- }
- } // namespace
|