Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
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
a0cf3955
Commit
a0cf3955
authored
Oct 18, 2011
by
Tomek Mrugalski
🛰
Browse files
[1313] Tests implemented for readUint32,writeUint32
parent
1032195d
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/lib/util/tests/io_utilities_unittest.cc
View file @
a0cf3955
...
@@ -19,6 +19,7 @@
...
@@ -19,6 +19,7 @@
#include <cstddef>
#include <cstddef>
#include <arpa/inet.h>
#include <gtest/gtest.h>
#include <gtest/gtest.h>
#include <util/buffer.h>
#include <util/buffer.h>
...
@@ -71,3 +72,48 @@ TEST(asioutil, writeUint16) {
...
@@ -71,3 +72,48 @@ TEST(asioutil, writeUint16) {
EXPECT_EQ
(
ref
[
1
],
test
[
1
]);
EXPECT_EQ
(
ref
[
1
],
test
[
1
]);
}
}
}
}
// test data shared amount readUint32 and writeUint32 tests
const
static
uint32_t
test32
[]
=
{
0
,
1
,
2000
,
0x80000000
,
0xffffffff
};
TEST
(
asioutil
,
readUint32
)
{
uint8_t
data
[
8
];
// make sure that we can read data, regardless of
// the memory alignment. That' why we need to repeat
// it 4 times.
for
(
int
offset
=
0
;
offset
<
4
;
offset
++
)
{
for
(
int
i
=
0
;
i
<
sizeof
(
test32
);
i
++
)
{
uint32_t
tmp
=
htonl
(
test32
[
i
]);
memcpy
(
&
data
[
offset
],
&
tmp
,
sizeof
(
uint32_t
)
);
EXPECT_EQ
(
test32
[
i
],
readUint32
(
&
data
[
offset
])
);
}
}
}
TEST
(
asioutil
,
writeUint32
)
{
uint8_t
data
[
8
];
// make sure that we can write data, regardless of
// the memory alignment. That's why we need to repeat
// it 4 times.
for
(
int
offset
=
0
;
offset
<
4
;
offset
++
)
{
for
(
int
i
=
0
;
i
<
sizeof
(
test32
);
i
++
)
{
uint8_t
*
ptr
=
writeUint32
(
test32
[
i
],
&
data
[
offset
]);
EXPECT_EQ
(
&
data
[
offset
]
+
sizeof
(
uint32_t
),
ptr
);
uint32_t
tmp
=
htonl
(
test32
[
i
]);
EXPECT_FALSE
(
memcmp
(
&
tmp
,
&
data
[
offset
],
sizeof
(
uint32_t
)
)
);
}
}
}
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