rdata_nsec3param_unittest.cc 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. #include <string>
  15. #include <exceptions/exceptions.h>
  16. #include <util/encode/base32hex.h>
  17. #include <util/encode/hex.h>
  18. #include <util/buffer.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;
  30. using namespace isc::dns;
  31. using namespace isc::util;
  32. using namespace isc::util::encode;
  33. using namespace isc::dns::rdata;
  34. namespace {
  35. class Rdata_NSEC3PARAM_Test : public RdataTest {
  36. // there's nothing to specialize
  37. };
  38. string nsec3param_txt("1 0 1 D399EAAB");
  39. TEST_F(Rdata_NSEC3PARAM_Test, toText) {
  40. const generic::NSEC3PARAM rdata_nsec3param(nsec3param_txt);
  41. EXPECT_EQ(nsec3param_txt, rdata_nsec3param.toText());
  42. }
  43. TEST_F(Rdata_NSEC3PARAM_Test, badText) {
  44. EXPECT_THROW(generic::NSEC3PARAM("1 1 1 SPORK"), BadValue); // bad hex
  45. EXPECT_THROW(generic::NSEC3PARAM("100000 1 1 ADDAFEE"), InvalidRdataText);
  46. EXPECT_THROW(generic::NSEC3PARAM("1 100000 1 ADDAFEE"), InvalidRdataText);
  47. EXPECT_THROW(generic::NSEC3PARAM("1 1 100000 ADDAFEE"), InvalidRdataText);
  48. EXPECT_THROW(generic::NSEC3PARAM("1"), InvalidRdataText);
  49. }
  50. TEST_F(Rdata_NSEC3PARAM_Test, DISABLED_badText) {
  51. // this currently fails
  52. EXPECT_THROW(generic::NSEC3PARAM("1 0 1D399EAAB"), InvalidRdataText);
  53. }
  54. TEST_F(Rdata_NSEC3PARAM_Test, createFromWire) {
  55. const generic::NSEC3PARAM rdata_nsec3param(nsec3param_txt);
  56. EXPECT_EQ(0, rdata_nsec3param.compare(
  57. *rdataFactoryFromFile(RRType::NSEC3PARAM(), RRClass::IN(),
  58. "rdata_nsec3param_fromWire1")));
  59. }
  60. TEST_F(Rdata_NSEC3PARAM_Test, toWireRenderer) {
  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. const generic::NSEC3PARAM rdata_nsec3param(nsec3param_txt);
  72. rdata_nsec3param.toWire(obuffer);
  73. }
  74. TEST_F(Rdata_NSEC3PARAM_Test, assign) {
  75. generic::NSEC3PARAM rdata_nsec3param(nsec3param_txt);
  76. generic::NSEC3PARAM other_nsec3param = rdata_nsec3param;
  77. EXPECT_EQ(0, rdata_nsec3param.compare(other_nsec3param));
  78. }
  79. }