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. // $Id$
  15. #include <string>
  16. #include <exceptions/exceptions.h>
  17. #include <dns/util/base32hex.h>
  18. #include <dns/buffer.h>
  19. #include <dns/util/hex.h>
  20. #include <dns/messagerenderer.h>
  21. #include <dns/rdata.h>
  22. #include <dns/rdataclass.h>
  23. #include <dns/rrclass.h>
  24. #include <dns/rrtype.h>
  25. #include <gtest/gtest.h>
  26. #include <dns/tests/unittest_util.h>
  27. #include <dns/tests/rdata_unittest.h>
  28. using isc::UnitTestUtil;
  29. using namespace std;
  30. using namespace isc;
  31. using namespace isc::dns;
  32. using namespace isc::dns::rdata;
  33. namespace {
  34. class Rdata_NSEC3PARAM_Test : public RdataTest {
  35. // there's nothing to specialize
  36. };
  37. string nsec3param_txt("1 0 1 D399EAAB");
  38. TEST_F(Rdata_NSEC3PARAM_Test, toText) {
  39. const generic::NSEC3PARAM rdata_nsec3param(nsec3param_txt);
  40. EXPECT_EQ(nsec3param_txt, rdata_nsec3param.toText());
  41. }
  42. TEST_F(Rdata_NSEC3PARAM_Test, badText) {
  43. EXPECT_THROW(generic::NSEC3PARAM("1 1 1 SPORK"), BadValue); // bad hex
  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. }
  49. TEST_F(Rdata_NSEC3PARAM_Test, DISABLED_badText) {
  50. // this currently fails
  51. EXPECT_THROW(generic::NSEC3PARAM("1 0 1D399EAAB"), InvalidRdataText);
  52. }
  53. TEST_F(Rdata_NSEC3PARAM_Test, createFromWire) {
  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. renderer.skip(2);
  61. const generic::NSEC3PARAM rdata_nsec3param(nsec3param_txt);
  62. rdata_nsec3param.toWire(renderer);
  63. vector<unsigned char> data;
  64. UnitTestUtil::readWireData("rdata_nsec3param_fromWire1", data);
  65. EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData,
  66. static_cast<const uint8_t *>(obuffer.getData()) + 2,
  67. obuffer.getLength() - 2, &data[2], data.size() - 2);
  68. }
  69. TEST_F(Rdata_NSEC3PARAM_Test, toWireBuffer) {
  70. const generic::NSEC3PARAM rdata_nsec3param(nsec3param_txt);
  71. rdata_nsec3param.toWire(obuffer);
  72. }
  73. TEST_F(Rdata_NSEC3PARAM_Test, assign) {
  74. generic::NSEC3PARAM rdata_nsec3param(nsec3param_txt);
  75. generic::NSEC3PARAM other_nsec3param = rdata_nsec3param;
  76. EXPECT_EQ(0, rdata_nsec3param.compare(other_nsec3param));
  77. }
  78. }