Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
3d5bac92
Commit
3d5bac92
authored
Sep 06, 2016
by
Christian Brauner
Committed by
Stéphane Graber
Nov 21, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests: add unit tests for lxc_safe_uint()
Signed-off-by:
Christian Brauner
<
christian.brauner@canonical.com
>
parent
d7cfb1de
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
0 deletions
+30
-0
lxc-test-utils.c
src/tests/lxc-test-utils.c
+30
-0
No files found.
src/tests/lxc-test-utils.c
View file @
3d5bac92
...
...
@@ -25,6 +25,7 @@
#include <errno.h>
#include <fcntl.h>
#include <sched.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
...
...
@@ -220,6 +221,34 @@ non_test_error:
if
(
fret
==
EXIT_SUCCESS
)
return
;
exit
(
fret
);
void
test_lxc_safe_uint
(
void
)
{
int
ret
;
unsigned
int
n
;
size_t
len
=
/* 2^64 = 21 - 1 */
21
;
char
uint_max
[
len
];
ret
=
snprintf
(
uint_max
,
len
,
"%lu"
,
(
unsigned
long
)
UINT_MAX
+
1
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
len
)
{
lxc_error
(
"%s
\n
"
,
"Failed to create string via snprintf()."
);
exit
(
EXIT_FAILURE
);
}
lxc_test_assert_abort
((
0
==
lxc_safe_uint
(
"1234345"
,
&
n
))
&&
n
==
1234345
);
lxc_test_assert_abort
((
0
==
lxc_safe_uint
(
" 345"
,
&
n
))
&&
n
==
345
);
lxc_test_assert_abort
((
-
EINVAL
==
lxc_safe_uint
(
" g345"
,
&
n
)));
lxc_test_assert_abort
((
-
EINVAL
==
lxc_safe_uint
(
" 3g45"
,
&
n
)));
lxc_test_assert_abort
((
-
EINVAL
==
lxc_safe_uint
(
" 345g"
,
&
n
)));
lxc_test_assert_abort
((
-
EINVAL
==
lxc_safe_uint
(
"g345"
,
&
n
)));
lxc_test_assert_abort
((
-
EINVAL
==
lxc_safe_uint
(
"3g45"
,
&
n
)));
lxc_test_assert_abort
((
-
EINVAL
==
lxc_safe_uint
(
"345g"
,
&
n
)));
lxc_test_assert_abort
((
-
EINVAL
==
lxc_safe_uint
(
"g345 "
,
&
n
)));
lxc_test_assert_abort
((
-
EINVAL
==
lxc_safe_uint
(
"3g45 "
,
&
n
)));
lxc_test_assert_abort
((
-
EINVAL
==
lxc_safe_uint
(
"345g "
,
&
n
)));
lxc_test_assert_abort
((
-
EINVAL
==
lxc_safe_uint
(
"g"
,
&
n
)));
lxc_test_assert_abort
((
-
EINVAL
==
lxc_safe_uint
(
" g345"
,
&
n
)));
lxc_test_assert_abort
((
-
ERANGE
==
lxc_safe_uint
(
uint_max
,
&
n
)));
}
void
test_lxc_string_replace
(
void
)
...
...
@@ -280,6 +309,7 @@ int main(int argc, char *argv[])
test_lxc_string_in_array
();
test_lxc_deslashify
();
test_detect_ramfs_rootfs
();
test_lxc_safe_uint
();
exit
(
EXIT_SUCCESS
);
}
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