rrset_collection_unittest.cc 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #include <datasrc/memory/rrset_collection.h>
  15. #include <datasrc/memory/zone_data_loader.h>
  16. #include <datasrc/memory/segment_object_holder.h>
  17. #include <dns/rrttl.h>
  18. #include <dns/rdataclass.h>
  19. #include <datasrc/tests/memory/memory_segment_mock.h>
  20. #include <gtest/gtest.h>
  21. #include <boost/scoped_ptr.hpp>
  22. using namespace isc::dns;
  23. using namespace isc::dns::rdata;
  24. using namespace std;
  25. using namespace isc::datasrc;
  26. using namespace isc::datasrc::memory;
  27. using namespace isc::datasrc::memory::detail;
  28. namespace {
  29. // Note: This class uses loadZoneData() to construct a ZoneData object,
  30. // which internally uses an RRsetCollection for validation. We assume
  31. // that loadZoneData() works at this point and test the RRsetCollection
  32. // around the ZoneData returned.
  33. class RRsetCollectionTest : public ::testing::Test {
  34. public:
  35. RRsetCollectionTest() :
  36. rrclass("IN"),
  37. origin("example.org"),
  38. zone_file(TEST_DATA_DIR "/rrset-collection.zone"),
  39. zone_data_holder(mem_sgmt, rrclass)
  40. {
  41. zone_data_holder.set(loadZoneData(mem_sgmt, rrclass, origin,
  42. zone_file));
  43. collection.reset(new RRsetCollection(*zone_data_holder.get(),
  44. rrclass));
  45. }
  46. const RRClass rrclass;
  47. const Name origin;
  48. std::string zone_file;
  49. test::MemorySegmentMock mem_sgmt;
  50. SegmentObjectHolder<ZoneData, RRClass> zone_data_holder;
  51. boost::scoped_ptr<RRsetCollection> collection;
  52. };
  53. TEST_F(RRsetCollectionTest, find) {
  54. const RRsetCollection& ccln = *collection;
  55. ConstRRsetPtr rrset = ccln.find(Name("www.example.org"), rrclass,
  56. RRType::A());
  57. EXPECT_TRUE(rrset);
  58. EXPECT_EQ(RRType::A(), rrset->getType());
  59. EXPECT_EQ(RRTTL(3600), rrset->getTTL());
  60. EXPECT_EQ(RRClass("IN"), rrset->getClass());
  61. EXPECT_EQ(Name("www.example.org"), rrset->getName());
  62. // foo.example.org doesn't exist
  63. rrset = ccln.find(Name("foo.example.org"), rrclass, RRType::A());
  64. EXPECT_FALSE(rrset);
  65. // www.example.org exists, but not with MX
  66. rrset = ccln.find(Name("www.example.org"), rrclass, RRType::MX());
  67. EXPECT_FALSE(rrset);
  68. // www.example.org exists, with AAAA
  69. rrset = ccln.find(Name("www.example.org"), rrclass, RRType::AAAA());
  70. EXPECT_TRUE(rrset);
  71. // www.example.org with AAAA does not exist in RRClass::CH()
  72. rrset = ccln.find(Name("www.example.org"), RRClass::CH(),
  73. RRType::AAAA());
  74. EXPECT_FALSE(rrset);
  75. }
  76. } // namespace