local_zone_data_unittest.cc 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright (C) 2010 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. // $Id$
  15. #include <config.h>
  16. #include <string>
  17. #include <gtest/gtest.h>
  18. #include <cache/local_zone_data.h>
  19. #include <dns/rrset.h>
  20. #include <dns/rrttl.h>
  21. #include "cache_test_util.h"
  22. using namespace isc::cache;
  23. using namespace isc::dns;
  24. using namespace std;
  25. namespace {
  26. class LocalZoneDataTest: public testing::Test {
  27. protected:
  28. LocalZoneDataTest(): local_zone_data(1)
  29. {
  30. }
  31. LocalZoneData local_zone_data;
  32. };
  33. TEST_F(LocalZoneDataTest, updateAndLookup) {
  34. Message msg(Message::PARSE);
  35. messageFromFile(msg, "message_fromWire3");
  36. RRsetIterator rrset_iter = msg.beginSection(Message::SECTION_AUTHORITY);
  37. Name name = (*rrset_iter)->getName();
  38. RRType type = (*rrset_iter)->getType();
  39. EXPECT_FALSE(local_zone_data.lookup(name, type));
  40. local_zone_data.update((*(*rrset_iter).get()));
  41. EXPECT_TRUE(local_zone_data.lookup(name, type));
  42. // Test whether the old one is replaced
  43. uint32_t ttl = (*rrset_iter)->getTTL().getValue();
  44. // Make sure it is not zero
  45. ASSERT_NE(ttl / 2, ttl);
  46. RRsetPtr rrset_ptr = local_zone_data.lookup(name, type);
  47. EXPECT_EQ(ttl, rrset_ptr->getTTL().getValue());
  48. (*rrset_iter)->setTTL(RRTTL(ttl/2));
  49. local_zone_data.update((*(*rrset_iter).get()));
  50. rrset_ptr = local_zone_data.lookup(name, type);
  51. EXPECT_EQ(ttl/2, rrset_ptr->getTTL().getValue());
  52. }
  53. }