Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
David Goulet
Tor
Commits
de8110fb
Commit
de8110fb
authored
Jan 03, 2016
by
Nick Mathewson
👁
Browse files
Explicitly test our get/set_uint{8,16,32,64}.
parent
a8749ea9
Changes
2
Hide whitespace changes
Inline
Side-by-side
configure.ac
View file @
de8110fb
...
...
@@ -391,6 +391,7 @@ AC_CHECK_FUNCS(
getrlimit \
gettimeofday \
gmtime_r \
htonll \
inet_aton \
ioctl \
issetugid \
...
...
src/test/test_util_format.c
View file @
de8110fb
...
...
@@ -11,6 +11,44 @@
#define NS_MODULE util_format
#if !defined(HAVE_HTONLL) && !defined(htonll)
#ifdef WORDS_BIGENDIAN
#define htonll(x) (x)
#else
static
uint64_t
htonll
(
uint64_t
a
)
{
return
htonl
((
uint32_t
)(
a
>>
32
))
|
(((
uint64_t
)
htonl
((
uint32_t
)
a
))
<<
32
);
}
#endif
#endif
static
void
test_util_format_unaligned_accessors
(
void
*
ignored
)
{
(
void
)
ignored
;
char
buf
[
9
]
=
"onionsoup"
;
// 6f6e696f6e736f7570
tt_u64_op
(
get_uint64
(
buf
+
1
),
OP_EQ
,
htonll
(
U64_LITERAL
(
0x6e696f6e736f7570
)));
tt_uint_op
(
get_uint32
(
buf
+
1
),
OP_EQ
,
htonl
(
0x6e696f6e
));
tt_uint_op
(
get_uint16
(
buf
+
1
),
OP_EQ
,
htons
(
0x6e69
));
tt_uint_op
(
get_uint8
(
buf
+
1
),
OP_EQ
,
0x6e
);
set_uint8
(
buf
+
7
,
0x61
);
tt_mem_op
(
buf
,
OP_EQ
,
"onionsoap"
,
9
);
set_uint16
(
buf
+
6
,
htons
(
0x746f
));
tt_mem_op
(
buf
,
OP_EQ
,
"onionstop"
,
9
);
set_uint32
(
buf
+
1
,
htonl
(
0x78696465
));
tt_mem_op
(
buf
,
OP_EQ
,
"oxidestop"
,
9
);
set_uint64
(
buf
+
1
,
htonll
(
U64_LITERAL
(
0x6266757363617465
)));
tt_mem_op
(
buf
,
OP_EQ
,
"obfuscate"
,
9
);
done:
;
}
static
void
test_util_format_base64_encode
(
void
*
ignored
)
{
...
...
@@ -252,6 +290,8 @@ test_util_format_base16_decode(void *ignored)
}
struct
testcase_t
util_format_tests
[]
=
{
{
"unaligned_accessors"
,
test_util_format_unaligned_accessors
,
0
,
NULL
,
NULL
},
{
"base64_encode"
,
test_util_format_base64_encode
,
0
,
NULL
,
NULL
},
{
"base64_decode_nopad"
,
test_util_format_base64_decode_nopad
,
0
,
NULL
,
NULL
},
...
...
Write
Preview
Supports
Markdown
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