dns_exceptions_unittest.cc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright (C) 2014 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 <dns/exceptions.h>
  15. #include <gtest/gtest.h>
  16. namespace { // begin unnamed namespace
  17. TEST(DNSExceptionsTest, checkExceptionsHierarchy) {
  18. EXPECT_NO_THROW({
  19. const isc::dns::Exception exception("", 0, "");
  20. const isc::Exception& exception_cast =
  21. dynamic_cast<const isc::Exception&>(exception);
  22. // to avoid compiler warning
  23. exception_cast.what();
  24. });
  25. EXPECT_NO_THROW({
  26. const isc::dns::DNSTextError exception("", 0, "");
  27. const isc::dns::Exception& exception_cast =
  28. dynamic_cast<const isc::dns::Exception&>(exception);
  29. // to avoid compiler warning
  30. exception_cast.what();
  31. });
  32. EXPECT_NO_THROW({
  33. const isc::dns::NameParserException exception("", 0, "");
  34. const isc::dns::DNSTextError& exception_cast =
  35. dynamic_cast<const isc::dns::DNSTextError&>(exception);
  36. // to avoid compiler warning
  37. exception_cast.what();
  38. });
  39. EXPECT_NO_THROW({
  40. const isc::dns::DNSMessageFORMERR exception("", 0, "");
  41. const isc::dns::DNSProtocolError& exception_cast =
  42. dynamic_cast<const isc::dns::DNSProtocolError&>(exception);
  43. const isc::dns::Exception& exception_cast2 =
  44. dynamic_cast<const isc::dns::Exception&>(exception);
  45. // to avoid compiler warning
  46. exception_cast.what();
  47. exception_cast2.what();
  48. });
  49. EXPECT_NO_THROW({
  50. const isc::dns::DNSMessageBADVERS exception("", 0, "");
  51. const isc::dns::DNSProtocolError& exception_cast =
  52. dynamic_cast<const isc::dns::DNSProtocolError&>(exception);
  53. const isc::dns::Exception& exception_cast2 =
  54. dynamic_cast<const isc::dns::Exception&>(exception);
  55. // to avoid compiler warning
  56. exception_cast.what();
  57. exception_cast2.what();
  58. });
  59. }
  60. } // end unnamed namespace