memfile_lease_mgr_unittest.cc 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. // Copyright (C) 2012-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 <config.h>
  15. #include <asiolink/io_address.h>
  16. #include <dhcp/duid.h>
  17. #include <dhcpsrv/lease_mgr.h>
  18. #include <dhcpsrv/memfile_lease_mgr.h>
  19. #include <dhcpsrv/tests/test_utils.h>
  20. #include <gtest/gtest.h>
  21. #include <iostream>
  22. #include <sstream>
  23. using namespace std;
  24. using namespace isc;
  25. using namespace isc::asiolink;
  26. using namespace isc::dhcp;
  27. using namespace isc::dhcp::test;
  28. namespace {
  29. // empty class for now, but may be extended once Addr6 becomes bigger
  30. class MemfileLeaseMgrTest : public GenericLeaseMgrTest {
  31. public:
  32. /// @brief memfile lease mgr test constructor
  33. ///
  34. /// Creates memfile and stores it in lmptr_ pointer
  35. MemfileLeaseMgrTest() {
  36. const LeaseMgr::ParameterMap pmap;
  37. lmptr_ = new Memfile_LeaseMgr(pmap);
  38. }
  39. virtual void reopen() {
  40. /// @todo: write lease to disk, flush, read file from disk
  41. }
  42. /// @brief destructor
  43. ///
  44. /// destroys lease manager backend.
  45. virtual ~MemfileLeaseMgrTest() {
  46. delete lmptr_;
  47. lmptr_ = 0;
  48. }
  49. };
  50. // This test checks if the LeaseMgr can be instantiated and that it
  51. // parses parameters string properly.
  52. TEST_F(MemfileLeaseMgrTest, constructor) {
  53. const LeaseMgr::ParameterMap pmap; // Empty parameter map
  54. boost::scoped_ptr<Memfile_LeaseMgr> lease_mgr;
  55. ASSERT_NO_THROW(lease_mgr.reset(new Memfile_LeaseMgr(pmap)));
  56. }
  57. // Checks if the getType() and getName() methods both return "memfile".
  58. TEST_F(MemfileLeaseMgrTest, getTypeAndName) {
  59. EXPECT_EQ(std::string("memfile"), lmptr_->getType());
  60. EXPECT_EQ(std::string("memory"), lmptr_->getName());
  61. }
  62. // Checks that adding/getting/deleting a Lease6 object works.
  63. TEST_F(MemfileLeaseMgrTest, addGetDelete6) {
  64. testAddGetDelete6(true);
  65. }
  66. /// @brief Basic Lease4 Checks
  67. ///
  68. /// Checks that the addLease, getLease4 (by address) and deleteLease (with an
  69. /// IPv4 address) works.
  70. TEST_F(MemfileLeaseMgrTest, basicLease4) {
  71. testBasicLease4();
  72. }
  73. /// @todo Write more memfile tests
  74. // Simple test about lease4 retrieval through client id method
  75. TEST_F(MemfileLeaseMgrTest, getLease4ClientId) {
  76. testGetLease4ClientId();
  77. }
  78. // Checks that lease4 retrieval client id is null is working
  79. TEST_F(MemfileLeaseMgrTest, getLease4NullClientId) {
  80. testGetLease4NullClientId();
  81. }
  82. // Checks lease4 retrieval through HWAddr
  83. TEST_F(MemfileLeaseMgrTest, getLease4HWAddr1) {
  84. testGetLease4HWAddr1();
  85. }
  86. /// @brief Check GetLease4 methods - access by Hardware Address
  87. ///
  88. /// Adds leases to the database and checks that they can be accessed via
  89. /// a combination of DUID and IAID.
  90. TEST_F(MemfileLeaseMgrTest, getLease4HWAddr2) {
  91. testGetLease4HWAddr2();
  92. }
  93. // Checks lease4 retrieval with clientId, HWAddr and subnet_id
  94. TEST_F(MemfileLeaseMgrTest, getLease4ClientIdHWAddrSubnetId) {
  95. testGetLease4ClientIdHWAddrSubnetId();
  96. }
  97. /// @brief Basic Lease4 Checks
  98. ///
  99. /// Checks that the addLease, getLease4(by address), getLease4(hwaddr,subnet_id),
  100. /// updateLease4() and deleteLease (IPv4 address) can handle NULL client-id.
  101. /// (client-id is optional and may not be present)
  102. TEST_F(MemfileLeaseMgrTest, DISABLED_lease4NullClientId) {
  103. /// @todo Test is disabled, because memfile does not support disk storage, so
  104. /// all leases are lost after reopen()
  105. testLease4NullClientId();
  106. }
  107. /// @brief Check GetLease4 methods - access by Hardware Address & Subnet ID
  108. ///
  109. /// Adds leases to the database and checks that they can be accessed via
  110. /// a combination of hardware address and subnet ID
  111. TEST_F(MemfileLeaseMgrTest, DISABLED_getLease4HwaddrSubnetId) {
  112. /// @todo: fails on memfile. It's probably a memfile bug.
  113. testGetLease4HWAddrSubnetId();
  114. }
  115. /// @brief Check GetLease4 methods - access by Client ID
  116. ///
  117. /// Adds leases to the database and checks that they can be accessed via
  118. /// the Client ID.
  119. TEST_F(MemfileLeaseMgrTest, getLease4ClientId2) {
  120. testGetLease4ClientId2();
  121. }
  122. // @brief Get Lease4 by client ID (2)
  123. //
  124. // Check that the system can cope with a client ID of any size.
  125. TEST_F(MemfileLeaseMgrTest, getLease4ClientIdSize) {
  126. testGetLease4ClientIdSize();
  127. }
  128. /// @brief Check GetLease4 methods - access by Client ID & Subnet ID
  129. ///
  130. /// Adds leases to the database and checks that they can be accessed via
  131. /// a combination of client and subnet IDs.
  132. TEST_F(MemfileLeaseMgrTest, getLease4ClientIdSubnetId) {
  133. testGetLease4ClientIdSubnetId();
  134. }
  135. // The following tests are not applicable for memfile. When adding
  136. // new tests to the list here, make sure to provide brief explanation
  137. // why they are not applicable:
  138. //
  139. // testGetLease4ClientIdSubnetId() - memfile just keeps Lease structure
  140. // and does not do any checks of HWAddr content
  141. // testGetLease4HWAddrSubnetIdSize() - memfile just keeps Lease structure
  142. // and does not do any checks of HWAddr content
  143. }; // end of anonymous namespace