d2_zone_unittests.cc 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this
  5. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. #include <config.h>
  7. #include <d2/d2_zone.h>
  8. #include <gtest/gtest.h>
  9. using namespace std;
  10. using namespace isc;
  11. using namespace isc::d2;
  12. using namespace isc::dns;
  13. namespace {
  14. // This test verifies that Zone object is created and its constructor sets
  15. // appropriate values for its members.
  16. TEST(D2ZoneTest, constructor) {
  17. // Create first object.
  18. D2Zone zone1(Name("example.com"), RRClass::ANY());
  19. EXPECT_EQ("example.com.", zone1.getName().toText());
  20. EXPECT_EQ(RRClass::ANY().getCode(), zone1.getClass().getCode());
  21. // Create another object to make sure that constructor doesn't assign
  22. // fixed values, but they change when constructor's parameters change.
  23. D2Zone zone2(Name("foo.example.com"), RRClass::IN());
  24. EXPECT_EQ("foo.example.com.", zone2.getName().toText());
  25. EXPECT_EQ(RRClass::IN().getCode(), zone2.getClass().getCode());
  26. }
  27. // This test verifies that toText() function returns text representation of
  28. // of the zone in expected format.
  29. TEST(D2ZoneTest, toText) {
  30. // Create first object.
  31. D2Zone zone1(Name("example.com"), RRClass::ANY());
  32. EXPECT_EQ("example.com. ANY SOA\n", zone1.toText());
  33. // Create another object with different parameters to make sure that the
  34. // function's output changes accordingly.
  35. D2Zone zone2(Name("foo.example.com"), RRClass::IN());
  36. EXPECT_EQ("foo.example.com. IN SOA\n", zone2.toText());
  37. }
  38. // This test verifies that the equality and inequality operators behave as
  39. // expected.
  40. TEST(D2ZoneTest, compare) {
  41. const Name a("a"), b("b");
  42. const RRClass in(RRClass::IN()), any(RRClass::ANY());
  43. // Equality check
  44. EXPECT_TRUE(D2Zone(a, any) == D2Zone(a, any));
  45. EXPECT_FALSE(D2Zone(a, any) != D2Zone(a, any));
  46. // Inequality check, objects differ by class.
  47. EXPECT_FALSE(D2Zone(a, any) == D2Zone(a, in));
  48. EXPECT_TRUE(D2Zone(a, any) != D2Zone(a, in));
  49. // Inequality check, objects differ by name.
  50. EXPECT_FALSE(D2Zone(a, any) == D2Zone(b, any));
  51. EXPECT_TRUE(D2Zone(a, any) != D2Zone(b, any));
  52. // Inequality check, objects differ by name and class.
  53. EXPECT_FALSE(D2Zone(a, any) == D2Zone(b, in));
  54. EXPECT_TRUE(D2Zone(a, any) != D2Zone(b, in));
  55. }
  56. } // End of anonymous namespace