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
Container Registry
Model registry
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
The Tor Project
Core
Tor
Commits
28370fe7
Unverified
Commit
28370fe7
authored
9 years ago
by
Ola Bini
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for util_format
parent
a444b113
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/test/include.am
+1
-0
1 addition, 0 deletions
src/test/include.am
src/test/test.c
+2
-1
2 additions, 1 deletion
src/test/test.c
src/test/test_util_format.c
+197
-0
197 additions, 0 deletions
src/test/test_util_format.c
with
200 additions
and
1 deletion
src/test/include.am
+
1
−
0
View file @
28370fe7
...
...
@@ -96,6 +96,7 @@ src_test_test_SOURCES = \
src/test/test_status.c \
src/test/test_threads.c \
src/test/test_util.c \
src/test/test_util_format.c \
src/test/test_helpers.c \
src/test/test_dns.c \
src/test/testing_common.c \
...
...
This diff is collapsed.
Click to expand it.
src/test/test.c
+
2
−
1
View file @
28370fe7
...
...
@@ -1158,6 +1158,7 @@ extern struct testcase_t socks_tests[];
extern
struct
testcase_t
status_tests
[];
extern
struct
testcase_t
thread_tests
[];
extern
struct
testcase_t
util_tests
[];
extern
struct
testcase_t
util_format_tests
[];
extern
struct
testcase_t
dns_tests
[];
struct
testgroup_t
testgroups
[]
=
{
...
...
@@ -1203,9 +1204,9 @@ struct testgroup_t testgroups[] = {
{
"socks/"
,
socks_tests
},
{
"status/"
,
status_tests
},
{
"util/"
,
util_tests
},
{
"util/format/"
,
util_format_tests
},
{
"util/logging/"
,
logging_tests
},
{
"util/thread/"
,
thread_tests
},
{
"dns/"
,
dns_tests
},
END_OF_GROUPS
};
This diff is collapsed.
Click to expand it.
src/test/test_util_format.c
0 → 100644
+
197
−
0
View file @
28370fe7
/* Copyright (c) 2010-2015, The Tor Project, Inc. */
/* See LICENSE for licensing information */
#include
"orconfig.h"
#include
"or.h"
#include
"test.h"
#define UTIL_FORMAT_PRIVATE
#include
"util_format.h"
#define NS_MODULE util_format
static
void
test_util_format_base64_encode
(
void
*
ignored
)
{
(
void
)
ignored
;
int
res
;
int
i
;
char
*
src
;
char
*
dst
;
src
=
tor_malloc_zero
(
256
);
dst
=
tor_malloc_zero
(
1000
);
for
(
i
=
0
;
i
<
256
;
i
++
)
{
src
[
i
]
=
(
char
)
i
;
}
res
=
base64_encode
(
NULL
,
1
,
src
,
1
,
0
);
tt_int_op
(
res
,
OP_EQ
,
-
1
);
res
=
base64_encode
(
dst
,
1
,
NULL
,
1
,
0
);
tt_int_op
(
res
,
OP_EQ
,
-
1
);
res
=
base64_encode
(
dst
,
1
,
src
,
10
,
0
);
tt_int_op
(
res
,
OP_EQ
,
-
1
);
res
=
base64_encode
(
dst
,
SSIZE_MAX
-
1
,
src
,
1
,
0
);
tt_int_op
(
res
,
OP_EQ
,
-
1
);
res
=
base64_encode
(
dst
,
SSIZE_MAX
-
1
,
src
,
10
,
0
);
tt_int_op
(
res
,
OP_EQ
,
-
1
);
res
=
base64_encode
(
dst
,
1000
,
src
,
256
,
0
);
tt_int_op
(
res
,
OP_EQ
,
344
);
tt_str_op
(
dst
,
OP_EQ
,
"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w=="
);
res
=
base64_encode
(
dst
,
1000
,
src
,
256
,
BASE64_ENCODE_MULTILINE
);
tt_int_op
(
res
,
OP_EQ
,
350
);
tt_str_op
(
dst
,
OP_EQ
,
"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4v
\n
"
"MDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5f
\n
"
"YGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6P
\n
"
"kJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/
\n
"
"wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v
\n
"
"8PHy8/T19vf4+fr7/P3+/w==
\n
"
);
res
=
base64_encode
(
dst
,
1000
,
src
+
1
,
255
,
BASE64_ENCODE_MULTILINE
);
tt_int_op
(
res
,
OP_EQ
,
346
);
for
(
i
=
0
;
i
<
50
;
i
++
)
{
src
[
i
]
=
0
;
}
src
[
50
]
=
255
;
src
[
51
]
=
255
;
src
[
52
]
=
255
;
src
[
53
]
=
255
;
res
=
base64_encode
(
dst
,
1000
,
src
,
54
,
BASE64_ENCODE_MULTILINE
);
tt_int_op
(
res
,
OP_EQ
,
74
);
res
=
base64_encode
(
dst
,
1000
,
src
+
1
,
53
,
BASE64_ENCODE_MULTILINE
);
tt_int_op
(
res
,
OP_EQ
,
74
);
res
=
base64_encode
(
dst
,
1000
,
src
+
2
,
52
,
BASE64_ENCODE_MULTILINE
);
tt_int_op
(
res
,
OP_EQ
,
74
);
res
=
base64_encode
(
dst
,
1000
,
src
+
3
,
51
,
BASE64_ENCODE_MULTILINE
);
tt_int_op
(
res
,
OP_EQ
,
70
);
res
=
base64_encode
(
dst
,
1000
,
src
+
4
,
50
,
BASE64_ENCODE_MULTILINE
);
tt_int_op
(
res
,
OP_EQ
,
70
);
res
=
base64_encode
(
dst
,
1000
,
src
+
5
,
49
,
BASE64_ENCODE_MULTILINE
);
tt_int_op
(
res
,
OP_EQ
,
70
);
res
=
base64_encode
(
dst
,
1000
,
src
+
6
,
48
,
BASE64_ENCODE_MULTILINE
);
tt_int_op
(
res
,
OP_EQ
,
65
);
res
=
base64_encode
(
dst
,
1000
,
src
+
7
,
47
,
BASE64_ENCODE_MULTILINE
);
tt_int_op
(
res
,
OP_EQ
,
65
);
res
=
base64_encode
(
dst
,
1000
,
src
+
8
,
46
,
BASE64_ENCODE_MULTILINE
);
tt_int_op
(
res
,
OP_EQ
,
65
);
done:
tor_free
(
src
);
tor_free
(
dst
);
}
static
void
test_util_format_base64_decode_nopad
(
void
*
ignored
)
{
(
void
)
ignored
;
int
res
;
int
i
;
char
*
src
;
uint8_t
*
dst
;
src
=
tor_malloc_zero
(
256
);
dst
=
tor_malloc_zero
(
1000
);
for
(
i
=
0
;
i
<
256
;
i
++
)
{
src
[
i
]
=
(
char
)
i
;
}
res
=
base64_decode_nopad
(
dst
,
1
,
src
,
SIZE_T_CEILING
);
tt_int_op
(
res
,
OP_EQ
,
-
1
);
res
=
base64_decode_nopad
(
dst
,
1
,
src
,
5
);
tt_int_op
(
res
,
OP_EQ
,
-
1
);
done:
tor_free
(
src
);
tor_free
(
dst
);
}
static
void
test_util_format_base64_decode
(
void
*
ignored
)
{
(
void
)
ignored
;
int
res
;
int
i
;
char
*
src
;
char
*
dst
;
src
=
tor_malloc_zero
(
256
);
dst
=
tor_malloc_zero
(
1000
);
for
(
i
=
0
;
i
<
256
;
i
++
)
{
src
[
i
]
=
(
char
)
i
;
}
res
=
base64_decode
(
dst
,
1
,
src
,
SIZE_T_CEILING
);
tt_int_op
(
res
,
OP_EQ
,
-
1
);
res
=
base64_decode
(
dst
,
SIZE_T_CEILING
+
1
,
src
,
10
);
tt_int_op
(
res
,
OP_EQ
,
-
1
);
done:
tor_free
(
src
);
tor_free
(
dst
);
}
static
void
test_util_format_base16_decode
(
void
*
ignored
)
{
(
void
)
ignored
;
int
res
;
int
i
;
char
*
src
;
char
*
dst
;
src
=
tor_malloc_zero
(
256
);
dst
=
tor_malloc_zero
(
1000
);
for
(
i
=
0
;
i
<
256
;
i
++
)
{
src
[
i
]
=
(
char
)
i
;
}
res
=
base16_decode
(
dst
,
3
,
src
,
3
);
tt_int_op
(
res
,
OP_EQ
,
-
1
);
res
=
base16_decode
(
dst
,
1
,
src
,
10
);
tt_int_op
(
res
,
OP_EQ
,
-
1
);
res
=
base16_decode
(
dst
,
SIZE_T_CEILING
+
2
,
src
,
10
);
tt_int_op
(
res
,
OP_EQ
,
-
1
);
done:
tor_free
(
src
);
tor_free
(
dst
);
}
struct
testcase_t
util_format_tests
[]
=
{
{
"base64_encode"
,
test_util_format_base64_encode
,
0
,
NULL
,
NULL
},
{
"base64_decode_nopad"
,
test_util_format_base64_decode_nopad
,
0
,
NULL
,
NULL
},
{
"base64_decode"
,
test_util_format_base64_decode
,
0
,
NULL
,
NULL
},
{
"base16_decode"
,
test_util_format_base16_decode
,
0
,
NULL
,
NULL
},
END_OF_TESTCASES
};
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