rdata_nsec3param_unittest.cc 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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/base32.h>
  17. #include <dns/buffer.h>
  18. #include <dns/hex.h>
  19. #include <dns/messagerenderer.h>
  20. #include <dns/rdata.h>
  21. #include <dns/rdataclass.h>
  22. #include <dns/rrclass.h>
  23. #include <dns/rrtype.h>
  24. #include <gtest/gtest.h>
  25. #include <dns/tests/unittest_util.h>
  26. #include <dns/tests/rdata_unittest.h>
  27. using isc::UnitTestUtil;
  28. using namespace std;
  29. using namespace isc::dns;
  30. using namespace isc::dns::rdata;
  31. namespace {
  32. class Rdata_NSEC3PARAM_Test : public RdataTest {
  33. // there's nothing to specialize
  34. };
  35. string nsec3param_txt("1 0 1 D399EAAB");
  36. TEST_F(Rdata_NSEC3PARAM_Test, toText)
  37. {
  38. const generic::NSEC3PARAM rdata_nsec3param(nsec3param_txt);
  39. EXPECT_EQ(nsec3param_txt, rdata_nsec3param.toText());
  40. }
  41. TEST_F(Rdata_NSEC3PARAM_Test, badText)
  42. {
  43. EXPECT_THROW(generic::NSEC3PARAM("1 1 1 SPORK"), BadHexString);
  44. EXPECT_THROW(generic::NSEC3PARAM("100000 1 1 ADDAFEE"), InvalidRdataText);
  45. EXPECT_THROW(generic::NSEC3PARAM("1 100000 1 ADDAFEE"), InvalidRdataText);
  46. EXPECT_THROW(generic::NSEC3PARAM("1 1 100000 ADDAFEE"), InvalidRdataText);
  47. EXPECT_THROW(generic::NSEC3PARAM("1"), InvalidRdataText);
  48. #if 0 // this currently fails
  49. EXPECT_THROW(generic::NSEC3PARAM("1 0 1D399EAAB"), InvalidRdataText);
  50. #endif
  51. }
  52. TEST_F(Rdata_NSEC3PARAM_Test, createFromWire)
  53. {
  54. const generic::NSEC3PARAM rdata_nsec3param(nsec3param_txt);
  55. EXPECT_EQ(0, rdata_nsec3param.compare(
  56. *rdataFactoryFromFile(RRType::NSEC3PARAM(), RRClass::IN(),
  57. "rdata_nsec3param_fromWire1")));
  58. }
  59. TEST_F(Rdata_NSEC3PARAM_Test, toWireRenderer)
  60. {
  61. renderer.skip(2);
  62. const generic::NSEC3PARAM rdata_nsec3param(nsec3param_txt);
  63. rdata_nsec3param.toWire(renderer);
  64. vector<unsigned char> data;
  65. UnitTestUtil::readWireData("rdata_nsec3param_fromWire1", data);
  66. EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData,
  67. static_cast<const uint8_t *>(obuffer.getData()) + 2,
  68. obuffer.getLength() - 2, &data[2], data.size() - 2);
  69. }
  70. TEST_F(Rdata_NSEC3PARAM_Test, toWireBuffer)
  71. {
  72. const generic::NSEC3PARAM rdata_nsec3param(nsec3param_txt);
  73. rdata_nsec3param.toWire(obuffer);
  74. }
  75. TEST_F(Rdata_NSEC3PARAM_Test, assign)
  76. {
  77. generic::NSEC3PARAM rdata_nsec3param(nsec3param_txt);
  78. generic::NSEC3PARAM other_nsec3param = rdata_nsec3param;
  79. EXPECT_EQ(0, rdata_nsec3param.compare(other_nsec3param));
  80. }
  81. }