rdata_opt_unittest.cc 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 <util/buffer.h>
  15. #include <dns/messagerenderer.h>
  16. #include <dns/rdata.h>
  17. #include <dns/rdataclass.h>
  18. #include <dns/rrclass.h>
  19. #include <dns/rrtype.h>
  20. #include <gtest/gtest.h>
  21. #include <dns/tests/unittest_util.h>
  22. #include <dns/tests/rdata_unittest.h>
  23. using isc::UnitTestUtil;
  24. using namespace std;
  25. using namespace isc::dns;
  26. using namespace isc::util;
  27. using namespace isc::dns::rdata;
  28. namespace {
  29. class Rdata_OPT_Test : public RdataTest {
  30. // there's nothing to specialize
  31. };
  32. const generic::OPT rdata_opt;
  33. TEST_F(Rdata_OPT_Test, createFromText) {
  34. // OPT RR cannot be created from text.
  35. EXPECT_THROW(generic::OPT("this does not matter"), InvalidRdataText);
  36. }
  37. TEST_F(Rdata_OPT_Test, createFromWire) {
  38. // Valid cases: in the simple implementation with no supported options,
  39. // we can only check these don't throw.
  40. EXPECT_NO_THROW(rdataFactoryFromFile(RRType::OPT(), RRClass("CLASS4096"),
  41. "rdata_opt_fromWire"));
  42. EXPECT_NO_THROW(rdataFactoryFromFile(RRType::OPT(), RRClass::CH(),
  43. "rdata_opt_fromWire", 2));
  44. // short buffer case.
  45. EXPECT_THROW(rdataFactoryFromFile(RRType::OPT(), RRClass::IN(),
  46. "rdata_opt_fromWire", 11),
  47. InvalidRdataLength);
  48. }
  49. TEST_F(Rdata_OPT_Test, toWireBuffer) {
  50. rdata_opt.toWire(obuffer);
  51. EXPECT_EQ(0, obuffer.getLength());
  52. }
  53. TEST_F(Rdata_OPT_Test, toWireRenderer) {
  54. rdata_opt.toWire(renderer);
  55. EXPECT_EQ(0, obuffer.getLength());
  56. }
  57. TEST_F(Rdata_OPT_Test, toText) {
  58. EXPECT_EQ("", rdata_opt.toText());
  59. }
  60. TEST_F(Rdata_OPT_Test, compare) {
  61. // This simple implementation always returns "true"
  62. EXPECT_EQ(0, rdata_opt.compare(
  63. *rdataFactoryFromFile(RRType::OPT(), RRClass::CH(),
  64. "rdata_opt_fromWire", 2)));
  65. // comparison attempt between incompatible RR types should be rejected
  66. EXPECT_THROW(rdata_opt.compare(*RdataTest::rdata_nomatch), bad_cast);
  67. }
  68. }