cfg_rsoo_unittest.cc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Copyright (C) 2015 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 <dhcp/dhcp6.h>
  16. #include <dhcpsrv/cfg_rsoo.h>
  17. #include <gtest/gtest.h>
  18. using namespace isc;
  19. using namespace isc::dhcp;
  20. namespace {
  21. // This test verifies that the RSOO configuration holds the default
  22. // RSOO-enabled options.
  23. TEST(CfgRSOOTest, defaults) {
  24. CfgRSOO rsoo;
  25. EXPECT_TRUE(rsoo.enabled(D6O_ERP_LOCAL_DOMAIN_NAME));
  26. for (uint16_t code = 0; code < 200; ++code) {
  27. if (code != D6O_ERP_LOCAL_DOMAIN_NAME) {
  28. EXPECT_FALSE(rsoo.enabled(code))
  29. << "expected that the option with code "
  30. << code << " is by default RSOO-disabled, but"
  31. " it is enabled";
  32. }
  33. }
  34. // Now, let's see if we can remove the default options.
  35. ASSERT_NO_THROW(rsoo.clear());
  36. EXPECT_FALSE(rsoo.enabled(D6O_ERP_LOCAL_DOMAIN_NAME));
  37. // Make sure it can be added again.
  38. ASSERT_NO_THROW(rsoo.enable(D6O_ERP_LOCAL_DOMAIN_NAME));
  39. EXPECT_TRUE(rsoo.enabled(D6O_ERP_LOCAL_DOMAIN_NAME));
  40. }
  41. // This test verifies that it is possible to enable more RSOO options
  42. // and later remove all of them.
  43. TEST(CfgRSOOTest, enableAndClear) {
  44. CfgRSOO rsoo;
  45. EXPECT_TRUE(rsoo.enabled(D6O_ERP_LOCAL_DOMAIN_NAME));
  46. // Enable option 88.
  47. ASSERT_FALSE(rsoo.enabled(88));
  48. ASSERT_NO_THROW(rsoo.enable(88));
  49. EXPECT_TRUE(rsoo.enabled(88));
  50. // Enable option 89.
  51. ASSERT_FALSE(rsoo.enabled(89));
  52. ASSERT_NO_THROW(rsoo.enable(89));
  53. EXPECT_TRUE(rsoo.enabled(89));
  54. // Remove them and make sure they have been removed.
  55. ASSERT_NO_THROW(rsoo.clear());
  56. for (uint16_t code = 0; code < 200; ++code) {
  57. EXPECT_FALSE(rsoo.enabled(code))
  58. << "expected that the option with code "
  59. << code << " is RSOO-disabled after clearing"
  60. " the RSOO configuration, but it is not";
  61. }
  62. }
  63. // This test verfies that the same option may be specified
  64. // multiple times and that the code doesn't fail.
  65. TEST(CfgRSOOTest, enableTwice) {
  66. CfgRSOO rsoo;
  67. // By default there should be the default option enabled.
  68. // Let's try to enable it again. It should pass.
  69. ASSERT_NO_THROW(rsoo.enable(D6O_ERP_LOCAL_DOMAIN_NAME));
  70. EXPECT_TRUE(rsoo.enabled(D6O_ERP_LOCAL_DOMAIN_NAME));
  71. // Enable option 88.
  72. ASSERT_FALSE(rsoo.enabled(88));
  73. ASSERT_NO_THROW(rsoo.enable(88));
  74. EXPECT_TRUE(rsoo.enabled(88));
  75. // And enable it again.
  76. ASSERT_NO_THROW(rsoo.enabled(88));
  77. EXPECT_TRUE(rsoo.enabled(88));
  78. // Remove all.
  79. ASSERT_NO_THROW(rsoo.clear());
  80. ASSERT_FALSE(rsoo.enabled(D6O_ERP_LOCAL_DOMAIN_NAME));
  81. ASSERT_FALSE(rsoo.enabled(88));
  82. }
  83. } // end of anonymous namespace