d2_zone_unittests.cc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright (C) 2013 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 <config.h>
  15. #include <d2/d2_zone.h>
  16. #include <gtest/gtest.h>
  17. using namespace std;
  18. using namespace isc;
  19. using namespace isc::d2;
  20. using namespace isc::dns;
  21. namespace {
  22. // This test verifies that Zone object is created and its constructor sets
  23. // appropriate values for its members.
  24. TEST(D2ZoneTest, constructor) {
  25. // Create first object.
  26. D2Zone zone1(Name("example.com"), RRClass::ANY());
  27. EXPECT_EQ("example.com.", zone1.getName().toText());
  28. EXPECT_EQ(RRClass::ANY().getCode(), zone1.getClass().getCode());
  29. // Create another object to make sure that constructor doesn't assign
  30. // fixed values, but they change when constructor's parameters change.
  31. D2Zone zone2(Name("foo.example.com"), RRClass::IN());
  32. EXPECT_EQ("foo.example.com.", zone2.getName().toText());
  33. EXPECT_EQ(RRClass::IN().getCode(), zone2.getClass().getCode());
  34. }
  35. // This test verifies that toText() function returns text representation of
  36. // of the zone in expected format.
  37. TEST(D2ZoneTest, toText) {
  38. // Create first object.
  39. D2Zone zone1(Name("example.com"), RRClass::ANY());
  40. EXPECT_EQ("example.com. ANY SOA\n", zone1.toText());
  41. // Create another object with different parameters to make sure that the
  42. // function's output changes accordingly.
  43. D2Zone zone2(Name("foo.example.com"), RRClass::IN());
  44. EXPECT_EQ("foo.example.com. IN SOA\n", zone2.toText());
  45. }
  46. // This test verifies that the equality and inequality operators behave as
  47. // expected.
  48. TEST(D2ZoneTest, compare) {
  49. const Name a("a"), b("b");
  50. const RRClass in(RRClass::IN()), any(RRClass::ANY());
  51. // Equality check
  52. EXPECT_TRUE(D2Zone(a, any) == D2Zone(a, any));
  53. EXPECT_FALSE(D2Zone(a, any) != D2Zone(a, any));
  54. // Inequality check, objects differ by class.
  55. EXPECT_FALSE(D2Zone(a, any) == D2Zone(a, in));
  56. EXPECT_TRUE(D2Zone(a, any) != D2Zone(a, in));
  57. // Inequality check, objects differ by name.
  58. EXPECT_FALSE(D2Zone(a, any) == D2Zone(b, any));
  59. EXPECT_TRUE(D2Zone(a, any) != D2Zone(b, any));
  60. // Inequality check, objects differ by name and class.
  61. EXPECT_FALSE(D2Zone(a, any) == D2Zone(b, in));
  62. EXPECT_TRUE(D2Zone(a, any) != D2Zone(b, in));
  63. }
  64. } // End of anonymous namespace