Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Tor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sergi
Tor
Commits
9964c314
Commit
9964c314
authored
13 years ago
by
Nick Mathewson
Browse files
Options
Downloads
Patches
Plain Diff
fwd-port test_util_di_ops into tinytest format
parent
44ad7345
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/test/test_util.c
+54
-0
54 additions, 0 deletions
src/test/test_util.c
with
54 additions
and
0 deletions
src/test/test_util.c
+
54
−
0
View file @
9964c314
...
...
@@ -1209,6 +1209,59 @@ test_util_load_win_lib(void *ptr)
}
#endif
static
void
test_util_di_ops
(
void
)
{
#define LT -1
#define GT 1
#define EQ 0
const
struct
{
const
char
*
a
;
int
want_sign
;
const
char
*
b
;
}
examples
[]
=
{
{
"Foo"
,
EQ
,
"Foo"
},
{
"foo"
,
GT
,
"bar"
,
},
{
"foobar"
,
EQ
,
"foobar"
},
{
"foobar"
,
LT
,
"foobaw"
},
{
"foobar"
,
GT
,
"f00bar"
},
{
"foobar"
,
GT
,
"boobar"
},
{
""
,
EQ
,
""
},
{
NULL
,
0
,
NULL
},
};
int
i
;
for
(
i
=
0
;
examples
[
i
].
a
;
++
i
)
{
size_t
len
=
strlen
(
examples
[
i
].
a
);
int
eq1
,
eq2
,
neq1
,
neq2
,
cmp1
,
cmp2
;
test_eq
(
len
,
strlen
(
examples
[
i
].
b
));
/* We do all of the operations, with operands in both orders. */
eq1
=
tor_memeq
(
examples
[
i
].
a
,
examples
[
i
].
b
,
len
);
eq2
=
tor_memeq
(
examples
[
i
].
b
,
examples
[
i
].
a
,
len
);
neq1
=
tor_memneq
(
examples
[
i
].
a
,
examples
[
i
].
b
,
len
);
neq2
=
tor_memneq
(
examples
[
i
].
b
,
examples
[
i
].
a
,
len
);
cmp1
=
tor_memcmp
(
examples
[
i
].
a
,
examples
[
i
].
b
,
len
);
cmp2
=
tor_memcmp
(
examples
[
i
].
b
,
examples
[
i
].
a
,
len
);
/* Check for correctness of cmp1 */
if
(
cmp1
<
0
&&
examples
[
i
].
want_sign
!=
LT
)
test_fail
();
else
if
(
cmp1
>
0
&&
examples
[
i
].
want_sign
!=
GT
)
test_fail
();
else
if
(
cmp1
==
0
&&
examples
[
i
].
want_sign
!=
EQ
)
test_fail
();
/* Check for consistency of everything else with cmp1 */
test_eq
(
eq1
,
eq2
);
test_eq
(
neq1
,
neq2
);
test_eq
(
cmp1
,
-
cmp2
);
test_eq
(
eq1
,
cmp1
==
0
);
test_eq
(
neq1
,
!
eq1
);
}
done:
;
}
#define UTIL_LEGACY(name) \
{ #name, legacy_test_helper, 0, &legacy_setup, test_util_ ## name }
...
...
@@ -1229,6 +1282,7 @@ struct testcase_t util_tests[] = {
UTIL_LEGACY
(
threads
),
UTIL_LEGACY
(
sscanf
),
UTIL_LEGACY
(
strtok
),
UTIL_LEGACY
(
di_ops
),
UTIL_TEST
(
find_str_at_start_of_line
,
0
),
UTIL_TEST
(
asprintf
,
0
),
UTIL_TEST
(
listdir
,
0
),
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment