rdata_nsec_unittest.cc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 <string>
  16. #include <dns/buffer.h>
  17. #include <dns/messagerenderer.h>
  18. #include <dns/rdata.h>
  19. #include <dns/rdataclass.h>
  20. #include <dns/rrclass.h>
  21. #include <dns/rrtype.h>
  22. #include <gtest/gtest.h>
  23. #include "unittest_util.h"
  24. #include "rdata_unittest.h"
  25. using isc::UnitTestUtil;
  26. using namespace std;
  27. using namespace isc::dns;
  28. using namespace isc::dns::rdata;
  29. namespace {
  30. class Rdata_NSEC_Test : public RdataTest {
  31. // there's nothing to specialize
  32. };
  33. string nsec_txt("www2.isc.org. CNAME RRSIG NSEC");
  34. TEST_F(Rdata_NSEC_Test, toText_NSEC)
  35. {
  36. const generic::NSEC rdata_nsec(nsec_txt);
  37. EXPECT_EQ(nsec_txt, rdata_nsec.toText());
  38. }
  39. TEST_F(Rdata_NSEC_Test, badText_NSEC)
  40. {
  41. EXPECT_THROW(generic::NSEC rdata_nsec("www.isc.org. BIFF POW SPOON"),
  42. InvalidRRType);
  43. EXPECT_THROW(generic::NSEC rdata_nsec("www.isc.org."),
  44. InvalidRRType);
  45. }
  46. TEST_F(Rdata_NSEC_Test, createFromWire_NSEC)
  47. {
  48. const generic::NSEC rdata_nsec(nsec_txt);
  49. EXPECT_EQ(0, rdata_nsec.compare(
  50. *rdataFactoryFromFile(RRType("NSEC"), RRClass("IN"),
  51. "testdata/rdata_nsec_fromWire1")));
  52. // Too short RDLENGTH
  53. EXPECT_THROW(rdataFactoryFromFile(RRType("NSEC"), RRClass("IN"),
  54. "testdata/rdata_nsec_fromWire2"),
  55. InvalidRdataLength);
  56. }
  57. TEST_F(Rdata_NSEC_Test, toWireRenderer_NSEC)
  58. {
  59. renderer.skip(2);
  60. const generic::NSEC rdata_nsec(nsec_txt);
  61. rdata_nsec.toWire(renderer);
  62. vector<unsigned char> data;
  63. UnitTestUtil::readWireData("testdata/rdata_nsec_fromWire1", data);
  64. EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData,
  65. static_cast<const uint8_t *>(obuffer.getData()) + 2,
  66. obuffer.getLength() - 2, &data[2], data.size() - 2);
  67. }
  68. TEST_F(Rdata_NSEC_Test, toWireBuffer_NSEC)
  69. {
  70. const generic::NSEC rdata_nsec(nsec_txt);
  71. rdata_nsec.toWire(obuffer);
  72. }
  73. TEST_F(Rdata_NSEC_Test, assign)
  74. {
  75. generic::NSEC rdata_nsec(nsec_txt);
  76. generic::NSEC rdata_nsec2 = rdata_nsec;
  77. EXPECT_EQ(0, rdata_nsec.compare(rdata_nsec2));
  78. }
  79. }