Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
ISC Open Source Projects
Kea
Commits
abd29c04
Commit
abd29c04
authored
Sep 06, 2013
by
Tomek Mrugalski
🛰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[3146] Test for LeaseMgr::getLease6() implemented.
parent
681def28
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
11 deletions
+63
-11
src/lib/dhcpsrv/tests/lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/lease_mgr_unittest.cc
+63
-11
No files found.
src/lib/dhcpsrv/tests/lease_mgr_unittest.cc
View file @
abd29c04
...
...
@@ -16,6 +16,8 @@
#include <asiolink/io_address.h>
#include <dhcpsrv/lease_mgr.h>
#include <dhcpsrv/memfile_lease_mgr.h>
#include <dhcpsrv/tests/test_utils.h>
#include <gtest/gtest.h>
...
...
@@ -28,6 +30,7 @@ using namespace std;
using
namespace
isc
;
using
namespace
isc
::
asiolink
;
using
namespace
isc
::
dhcp
;
using
namespace
isc
::
dhcp
::
test
;
// This is a concrete implementation of a Lease database. It does not do
// anything useful and is used for abstract LeaseMgr class testing.
...
...
@@ -135,25 +138,25 @@ public:
/// @brief Returns existing IPv6 lease for a given DUID+IA combination
///
/// @param duid
client DUID
/// @param iaid
IA identifier
/// @param duid
ignored
/// @param iaid
ignored
///
/// @return
collection of IPv6 leases
/// @return
whatever is set in leases6_ field
virtual
Lease6Collection
getLease6
(
Lease6
::
LeaseType
/* not used yet */
,
const
DUID
&
,
uint32_t
)
const
{
return
(
L
ease
6Collection
()
);
return
(
l
ease
s6_
);
}
/// @brief Returns existing IPv6 lease for a given DUID+IA combination
/// @brief Returns existing IPv6 lease for a given DUID+IA
+subnet-id
combination
///
/// @param duid
client DUID
/// @param iaid
IA identifier
/// @param subnet_id i
dentifier of the subnet the lease must belong to
/// @param duid
ignored
/// @param iaid
ignored
/// @param subnet_id i
gnored
///
/// @return
smart pointer to the lease (or NULL if a lease is not found)
/// @return
whatever is set in leases6_ field
virtual
Lease6Collection
getLeases6
(
Lease6
::
LeaseType
/* not used yet */
,
const
DUID
&
,
uint32_t
,
SubnetID
)
const
{
return
(
L
ease
6Collection
()
);
return
(
l
ease
s6_
);
}
/// @brief Updates IPv4 lease.
...
...
@@ -220,6 +223,17 @@ public:
/// @brief Rollback transactions
virtual
void
rollback
()
{
}
// We need to use it in ConcreteLeaseMgr
using
LeaseMgr
::
getLease6
;
Lease6Collection
leases6_
;
///< getLease6 methods return this as is
};
class
LeaseMgrTest
:
public
GenericLeaseMgrTest
{
public:
LeaseMgrTest
()
{
}
};
namespace
{
...
...
@@ -228,7 +242,7 @@ namespace {
///
/// This test checks if the LeaseMgr can be instantiated and that it
/// parses parameters string properly.
TEST
(
LeaseMgr
,
getParameter
)
{
TEST
_F
(
LeaseMgr
Test
,
getParameter
)
{
LeaseMgr
::
ParameterMap
pmap
;
pmap
[
std
::
string
(
"param1"
)]
=
std
::
string
(
"value1"
);
...
...
@@ -240,6 +254,44 @@ TEST(LeaseMgr, getParameter) {
EXPECT_THROW
(
leasemgr
.
getParameter
(
"param3"
),
BadValue
);
}
// This test checks if getLease6() method is working properly for 0 (NULL),
// 1 (return the lease) and more than 1 leases (throw).
TEST_F
(
LeaseMgrTest
,
getLease6
)
{
LeaseMgr
::
ParameterMap
pmap
;
boost
::
scoped_ptr
<
ConcreteLeaseMgr
>
mgr
(
new
ConcreteLeaseMgr
(
pmap
));
vector
<
Lease6Ptr
>
leases
=
createLeases6
();
mgr
->
leases6_
.
clear
();
// For no leases, the function should return NULL pointer
Lease6Ptr
lease
;
// the getLease6() is calling getLeases6(), which is a dummy. It returns
// whatever is there in leases6_ field.
EXPECT_NO_THROW
(
lease
=
mgr
->
getLease6
(
leasetype6_
[
1
],
*
leases
[
1
]
->
duid_
,
leases
[
1
]
->
iaid_
,
leases
[
1
]
->
subnet_id_
));
EXPECT_TRUE
(
Lease6Ptr
()
==
lease
);
// For a single lease, the function should return that lease
mgr
->
leases6_
.
push_back
(
leases
[
1
]);
EXPECT_NO_THROW
(
lease
=
mgr
->
getLease6
(
leasetype6_
[
1
],
*
leases
[
1
]
->
duid_
,
leases
[
1
]
->
iaid_
,
leases
[
1
]
->
subnet_id_
));
EXPECT_TRUE
(
lease
);
EXPECT_NO_THROW
(
detailCompareLease
(
lease
,
leases
[
1
]));
// Add one more lease. There are 2 now. It should throw
mgr
->
leases6_
.
push_back
(
leases
[
2
]);
EXPECT_THROW
(
lease
=
mgr
->
getLease6
(
leasetype6_
[
1
],
*
leases
[
1
]
->
duid_
,
leases
[
1
]
->
iaid_
,
leases
[
1
]
->
subnet_id_
),
MultipleRecords
);
}
// There's no point in calling any other methods in LeaseMgr, as they
// are purely virtual, so we would only call ConcreteLeaseMgr methods.
// Those methods are just stubs that do not return anything.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment