query_unittest.cc 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 <gtest/gtest.h>
  16. #include <dns/buffer.h>
  17. #include <dns/message.h>
  18. #include <dns/name.h>
  19. #include <dns/opcode.h>
  20. #include <dns/rrtype.h>
  21. #include <dns/rrclass.h>
  22. #include <datasrc/query.h>
  23. #include <dns/tests/unittest_util.h>
  24. using isc::UnitTestUtil;
  25. using namespace isc::dns;
  26. using namespace isc::datasrc;
  27. namespace {
  28. void
  29. createQuery(Message& m, const Name& qname, const RRClass& qclass,
  30. const RRType& qtype)
  31. {
  32. m.setOpcode(Opcode::QUERY());
  33. m.setHeaderFlag(MessageFlag::RD());
  34. m.addQuestion(Question(qname, qclass, qtype));
  35. }
  36. QueryTaskPtr
  37. createTask(Message& m, const Name& name, const RRType& rrtype0, HotCache& c) {
  38. RRType rrtype(rrtype0);
  39. Query q(m, c, true);
  40. return (QueryTaskPtr(new QueryTask(q, name, rrtype,
  41. QueryTask::SIMPLE_QUERY)));
  42. }
  43. // Check the QueryTask created using a temporary RRType object will remain
  44. // valid.
  45. TEST(QueryTest, constructWithTemporary) {
  46. HotCache cache;
  47. Message m1(Message::RENDER);
  48. createQuery(m1, Name("www.wild.example.com"), RRClass::IN(), RRType::A());
  49. QueryTaskPtr task_a = createTask(m1, Name("www.wild.example.com"),
  50. RRType::A(), cache);
  51. EXPECT_EQ(RRType::A(), task_a->qtype);
  52. Message m2(Message::RENDER);
  53. createQuery(m2, Name("www.wild.example.com"), RRClass::IN(),
  54. RRType::AAAA());
  55. QueryTaskPtr task_aaaa = createTask(m2, Name("www.wild.example.com"),
  56. RRType::AAAA(), cache);
  57. EXPECT_EQ(RRType::AAAA(), task_aaaa->qtype);
  58. }
  59. }