Skip to content

Commit 054ce77

Browse files
committed
[#1415] Check done flag for permutation
As suggested in the review comment, the unit test is now checking if the done flag returned by the IP range permutation is set to false when the permutation is not done returning addresses.
1 parent a6b7858 commit 054ce77

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

src/lib/dhcpsrv/tests/ip_range_permutation_unittest.cc

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,24 @@ TEST(IPRangePermutationTest, ipv4) {
4141
std::set<IOAddress> addrs;
4242
bool done = false;
4343

44-
// Call the next() function 95 tims. The first 91 calls should return non-zero
44+
// Call the next() function 95 times. The first 91 calls should return non-zero
4545
// IP addresses.
4646
for (auto i = 0; i < 95; ++i) {
4747
auto next = perm.next(done);
4848
if (!next.isV4Zero()) {
4949
// Make sure the returned address is within the range.
5050
EXPECT_LE(range.start_, next);
5151
EXPECT_LE(next, range.end_);
52-
} else {
53-
// The IPv4 zero address marks the end of the permutation. In this case
54-
// the done flag should be set.
52+
}
53+
// If we went over all addresses in the range, the flags indicating that
54+
// the permutation is exhausted should be set to true.
55+
if (i >= 90) {
5556
EXPECT_TRUE(done);
5657
EXPECT_TRUE(perm.exhausted());
58+
} else {
59+
// We're not done yet, so these flag should still be false.
60+
EXPECT_FALSE(done);
61+
EXPECT_FALSE(perm.exhausted());
5762
}
5863
// Insert the address returned to the set.
5964
addrs.insert(next);
@@ -68,21 +73,27 @@ TEST(IPRangePermutationTest, ipv4) {
6873
// be generated.
6974
TEST(IPRangePermutationTest, ipv6) {
7075
AddressRange range(IOAddress("2001:db8:1::1:fea0"),
71-
IOAddress("2001:db8:1::2:abcd"));
76+
IOAddress("2001:db8:1::2:abcd"));
7277
IPRangePermutation perm(range);
7378

7479
std::set<IOAddress> addrs;
7580
bool done = false;
7681
for (auto i = 0; i < 44335; ++i) {
7782
auto next = perm.next(done);
7883
if (!next.isV6Zero()) {
79-
// The IPv6 zero address marks the end of the permutation. In this case
80-
// the done flag should be set.
84+
// Make sure that the address is within the range.
8185
EXPECT_LE(range.start_, next);
8286
EXPECT_LE(next, range.end_);
83-
} else {
87+
}
88+
// If we went over all addresses in the range, the flags indicating that
89+
// the permutation is exhausted should be set to true.
90+
if (i >= 44333) {
8491
EXPECT_TRUE(done);
8592
EXPECT_TRUE(perm.exhausted());
93+
} else {
94+
// We're not done yet, so these flag should still be false.
95+
EXPECT_FALSE(done);
96+
EXPECT_FALSE(perm.exhausted());
8697
}
8798
// Insert the address returned to the set.
8899
addrs.insert(next);
@@ -103,15 +114,21 @@ TEST(IPRangePermutationTest, pd) {
103114
for (auto i = 0; i < 257; ++i) {
104115
auto next = perm.next(done);
105116
if (!next.isV6Zero()) {
106-
// The IPv6 zero address marks the end of the permutation. In this case
107-
// the done flag should be set.
117+
// Make sure the prefix is within the range.
108118
EXPECT_LE(range.start_, next);
109119
EXPECT_LE(next, range.end_);
110-
} else {
120+
}
121+
// If we went over all delegated prefixes in the range, the flags indicating
122+
// that the permutation is exhausted should be set to true.
123+
if (i >= 255) {
111124
EXPECT_TRUE(done);
112125
EXPECT_TRUE(perm.exhausted());
126+
} else {
127+
// We're not done yet, so these flag should still be false.
128+
EXPECT_FALSE(done);
129+
EXPECT_FALSE(perm.exhausted());
113130
}
114-
// Insert the address returned to the set.
131+
// Insert the prefix returned to the set.
115132
addrs.insert(next);
116133
}
117134

0 commit comments

Comments
 (0)