Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ISC Open Source Projects
Kea
Commits
92e23241
Commit
92e23241
authored
Dec 11, 2012
by
Marcin Siodelski
Browse files
[2526] Added unit tests for V4 option holding an array of integers.
parent
f54d04b8
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/lib/dhcp/option_int.h
View file @
92e23241
...
...
@@ -171,7 +171,7 @@ public:
/// @return length of this option
virtual
uint16_t
len
()
{
// Calculate the length of the header.
uint16_t
length
=
(
u
niverse
_
==
Option
::
V4
)
?
OPTION4_HDR_LEN
:
OPTION6_HDR_LEN
;
uint16_t
length
=
(
getU
niverse
()
==
Option
::
V4
)
?
OPTION4_HDR_LEN
:
OPTION6_HDR_LEN
;
// The data length is equal to size of T.
length
+=
sizeof
(
T
);;
// length of all suboptions
...
...
src/lib/dhcp/option_int_array.h
View file @
92e23241
...
...
@@ -116,8 +116,9 @@ public:
/// equal to 1, 2 or 4 bytes. The data type is not checked in this function
/// because it is checked in a constructor.
void
pack
(
isc
::
util
::
OutputBuffer
&
buf
)
{
buf
.
writeUint16
(
type_
);
buf
.
writeUint16
(
len
()
-
OPTION6_HDR_LEN
);
// Pack option header.
packHeader
(
buf
);
// Pack option data.
for
(
int
i
=
0
;
i
<
values_
.
size
();
++
i
)
{
// Depending on the data type length we use different utility functions
// writeUint16 or writeUint32 which write the data in the network byte
...
...
@@ -211,7 +212,8 @@ public:
///
/// @return length of this option
virtual
uint16_t
len
()
{
uint16_t
length
=
OPTION6_HDR_LEN
+
values_
.
size
()
*
sizeof
(
T
);
uint16_t
length
=
(
getUniverse
()
==
Option
::
V4
)
?
OPTION4_HDR_LEN
:
OPTION6_HDR_LEN
;
length
+=
values_
.
size
()
*
sizeof
(
T
);
// length of all suboptions
for
(
Option
::
OptionCollection
::
iterator
it
=
options_
.
begin
();
it
!=
options_
.
end
();
...
...
src/lib/dhcp/tests/option_int_array_unittest.cc
View file @
92e23241
...
...
@@ -75,7 +75,7 @@ public:
buf_
.
begin
()
+
opt_len
))
);
EXPECT_EQ
(
Option
::
V6
,
opt
->
getUniverse
());
EXPECT_EQ
(
u
,
opt
->
getUniverse
());
EXPECT_EQ
(
opt_code
,
opt
->
getType
());
// Option should return the collection of int8_t or uint8_t values that
// we can match with the buffer we used to create the option.
...
...
@@ -100,15 +100,26 @@ public:
// Data length is 10 bytes.
EXPECT_EQ
(
10
,
opt
->
len
()
-
opt
->
getHeaderLen
());
EXPECT_EQ
(
opt_code
,
opt
->
getType
());
// The total length is 10 bytes for data and 4 bytes for header.
ASSERT_EQ
(
14
,
out_buf_
.
getLength
());
// Check if pack worked properly:
InputBuffer
out
(
out_buf_
.
getData
(),
out_buf_
.
getLength
());
// if option type is correct
EXPECT_EQ
(
opt_code
,
out
.
readUint16
());
// if option length is correct
EXPECT_EQ
(
10
,
out
.
readUint16
());
if
(
u
==
Option
::
V4
)
{
// The total length is 10 bytes for data and 2 bytes for a header.
ASSERT_EQ
(
12
,
out_buf_
.
getLength
());
// if option type is correct
EXPECT_EQ
(
opt_code
,
out
.
readUint8
());
// if option length is correct
EXPECT_EQ
(
10
,
out
.
readUint8
());
}
else
{
// The total length is 10 bytes for data and 4 bytes for a header.
ASSERT_EQ
(
14
,
out_buf_
.
getLength
());
// if option type is correct
EXPECT_EQ
(
opt_code
,
out
.
readUint16
());
// if option length is correct
EXPECT_EQ
(
10
,
out
.
readUint16
());
}
// if data is correct
std
::
vector
<
uint8_t
>
out_data
;
ASSERT_NO_THROW
(
out
.
readVector
(
out_data
,
opt_len
));
...
...
@@ -172,15 +183,25 @@ public:
// Data length is 20 bytes.
EXPECT_EQ
(
20
,
opt
->
len
()
-
opt
->
getHeaderLen
());
EXPECT_EQ
(
opt_code
,
opt
->
getType
());
// The total length is 20 bytes for data and 4 bytes for header.
ASSERT_EQ
(
24
,
out_buf_
.
getLength
());
// Check if pack worked properly:
InputBuffer
out
(
out_buf_
.
getData
(),
out_buf_
.
getLength
());
// if option type is correct
EXPECT_EQ
(
opt_code
,
out
.
readUint16
());
// if option length is correct
EXPECT_EQ
(
20
,
out
.
readUint16
());
if
(
u
==
Option
::
V4
)
{
// The total length is 20 bytes for data and 2 bytes for a header.
ASSERT_EQ
(
22
,
out_buf_
.
getLength
());
// if option type is correct
EXPECT_EQ
(
opt_code
,
out
.
readUint8
());
// if option length is correct
EXPECT_EQ
(
20
,
out
.
readUint8
());
}
else
{
// The total length is 20 bytes for data and 4 bytes for a header.
ASSERT_EQ
(
24
,
out_buf_
.
getLength
());
// if option type is correct
EXPECT_EQ
(
opt_code
,
out
.
readUint16
());
// if option length is correct
EXPECT_EQ
(
20
,
out
.
readUint16
());
}
// if data is correct
std
::
vector
<
uint8_t
>
out_data
;
ASSERT_NO_THROW
(
out
.
readVector
(
out_data
,
opt_len
));
...
...
@@ -246,15 +267,26 @@ public:
// Data length is 40 bytes.
EXPECT_EQ
(
40
,
opt
->
len
()
-
opt
->
getHeaderLen
());
EXPECT_EQ
(
opt_code
,
opt
->
getType
());
// The total length is 40 bytes for data and 4 bytes for header.
ASSERT_EQ
(
44
,
out_buf_
.
getLength
());
// Check if pack worked properly:
InputBuffer
out
(
out_buf_
.
getData
(),
out_buf_
.
getLength
());
// if option type is correct
EXPECT_EQ
(
opt_code
,
out
.
readUint16
());
// if option length is correct
EXPECT_EQ
(
40
,
out
.
readUint16
());
if
(
u
==
Option
::
V4
)
{
// The total length is 40 bytes for data and 2 bytes for a header.
ASSERT_EQ
(
42
,
out_buf_
.
getLength
());
// if option type is correct
EXPECT_EQ
(
opt_code
,
out
.
readUint8
());
// if option length is correct
EXPECT_EQ
(
40
,
out
.
readUint8
());
}
else
{
// The total length is 40 bytes for data and 4 bytes for a header.
ASSERT_EQ
(
44
,
out_buf_
.
getLength
());
// if option type is correct
EXPECT_EQ
(
opt_code
,
out
.
readUint16
());
// if option length is correct
EXPECT_EQ
(
40
,
out
.
readUint16
());
}
// if data is correct
std
::
vector
<
uint8_t
>
out_data
;
ASSERT_NO_THROW
(
out
.
readVector
(
out_data
,
opt_len
));
...
...
@@ -290,26 +322,50 @@ TEST_F(OptionIntArrayTest, useInvalidType) {
}
TEST_F
(
OptionIntArrayTest
,
bufferToUint8V4
)
{
bufferToIntTest8
<
uint8_t
>
(
Option
::
V4
);
}
TEST_F
(
OptionIntArrayTest
,
bufferToUint8V6
)
{
bufferToIntTest8
<
uint8_t
>
(
Option
::
V6
);
}
TEST_F
(
OptionIntArrayTest
,
bufferToInt8V4
)
{
bufferToIntTest8
<
int8_t
>
(
Option
::
V4
);
}
TEST_F
(
OptionIntArrayTest
,
bufferToInt8V6
)
{
bufferToIntTest8
<
int8_t
>
(
Option
::
V6
);
}
TEST_F
(
OptionIntArrayTest
,
bufferToUint16V4
)
{
bufferToIntTest16
<
uint16_t
>
(
Option
::
V4
);
}
TEST_F
(
OptionIntArrayTest
,
bufferToUint16V6
)
{
bufferToIntTest16
<
uint16_t
>
(
Option
::
V6
);
}
TEST_F
(
OptionIntArrayTest
,
bufferToInt16V4
)
{
bufferToIntTest16
<
int16_t
>
(
Option
::
V4
);
}
TEST_F
(
OptionIntArrayTest
,
bufferToInt16V6
)
{
bufferToIntTest16
<
int16_t
>
(
Option
::
V6
);
}
TEST_F
(
OptionIntArrayTest
,
bufferToUint32V4
)
{
bufferToIntTest32
<
uint32_t
>
(
Option
::
V4
);
}
TEST_F
(
OptionIntArrayTest
,
bufferToUint32V6
)
{
bufferToIntTest32
<
uint32_t
>
(
Option
::
V6
);
}
TEST_F
(
OptionIntArrayTest
,
bufferToInt32V4
)
{
bufferToIntTest32
<
int32_t
>
(
Option
::
V4
);
}
TEST_F
(
OptionIntArrayTest
,
bufferToInt32V6
)
{
bufferToIntTest32
<
int32_t
>
(
Option
::
V6
);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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