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
882d33a8
Commit
882d33a8
authored
9 years ago
by
rl1987
Browse files
Options
Downloads
Patches
Plain Diff
Using namespace macros for mock functions in test_dns.c
parent
2f5d0ea1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/test/test_dns.c
+25
-20
25 additions, 20 deletions
src/test/test_dns.c
with
25 additions
and
20 deletions
src/test/test_dns.c
+
25
−
20
View file @
882d33a8
...
...
@@ -55,6 +55,11 @@ static cached_resolve_t *cache_entry = NULL;
static
int
n_fake_impl
=
0
;
NS_DECL
(
int
,
dns_resolve_impl
,
(
edge_connection_t
*
exitconn
,
int
is_resolve
,
or_circuit_t
*
oncirc
,
char
**
hostname_out
,
int
*
made_connection_pending_out
,
cached_resolve_t
**
resolve_out
));
/** This will be our configurable substitute for <b>dns_resolve_impl</b> in
* dns.c. It will return <b>resolve_retval</b>,
* and set <b>resolve_made_conn_pending</b> to
...
...
@@ -64,10 +69,10 @@ static int n_fake_impl = 0;
* 1.
*/
static
int
dns_resolve_
fake_
impl
(
edge_connection_t
*
exitconn
,
int
is_resolve
,
or_circuit_t
*
oncirc
,
char
**
hostname_out
,
int
*
made_connection_pending_out
,
cached_resolve_t
**
resolve_out
)
NS
(
dns_resolve_impl
)
(
edge_connection_t
*
exitconn
,
int
is_resolve
,
or_circuit_t
*
oncirc
,
char
**
hostname_out
,
int
*
made_connection_pending_out
,
cached_resolve_t
**
resolve_out
)
{
(
void
)
oncirc
;
(
void
)
exitconn
;
...
...
@@ -94,8 +99,8 @@ static uint8_t last_answer_type = 0;
static
cached_resolve_t
*
last_resolved
;
static
void
send_resolved_cell
_replacement
(
edge_connection_t
*
conn
,
uint8_t
answer_type
,
const
cached_resolve_t
*
resolved
)
NS
(
send_resolved_cell
)
(
edge_connection_t
*
conn
,
uint8_t
answer_type
,
const
cached_resolve_t
*
resolved
)
{
conn_for_resolved_cell
=
conn
;
...
...
@@ -110,8 +115,8 @@ static int n_send_resolved_hostname_cell_replacement = 0;
static
char
*
last_resolved_hostname
=
NULL
;
static
void
send_resolved_hostname_cell
_replacement
(
edge_connection_t
*
conn
,
const
char
*
hostname
)
NS
(
send_resolved_hostname_cell
)
(
edge_connection_t
*
conn
,
const
char
*
hostname
)
{
conn_for_resolved_cell
=
conn
;
...
...
@@ -124,7 +129,7 @@ send_resolved_hostname_cell_replacement(edge_connection_t *conn,
static
int
n_dns_cancel_pending_resolve_replacement
=
0
;
static
void
dns_cancel_pending_resolve
_replacement
(
const
char
*
address
)
NS
(
dns_cancel_pending_resolve
)
(
const
char
*
address
)
{
(
void
)
address
;
n_dns_cancel_pending_resolve_replacement
++
;
...
...
@@ -134,7 +139,7 @@ static int n_connection_free = 0;
static
connection_t
*
last_freed_conn
=
NULL
;
static
void
connection_free
_replacement
(
connection_t
*
conn
)
NS
(
connection_free
)
(
connection_t
*
conn
)
{
n_connection_free
++
;
...
...
@@ -161,9 +166,9 @@ NS(test_main)(void *arg)
memset
(
exitconn
,
0
,
sizeof
(
edge_connection_t
));
memset
(
nextconn
,
0
,
sizeof
(
edge_connection_t
));
MOCK
(
dns_resolve_impl
,
dns_resolve_fake_impl
);
MOCK
(
send_resolved_cell
,
send_resolved_cell_replacement
);
MOCK
(
send_resolved_hostname_cell
,
send_resolved_hostname_cell_replacement
);
NS_
MOCK
(
dns_resolve_impl
);
NS_
MOCK
(
send_resolved_cell
);
NS_
MOCK
(
send_resolved_hostname_cell
);
/*
* CASE 1: dns_resolve_impl returns 1 and sets a hostname. purpose is
...
...
@@ -276,8 +281,8 @@ NS(test_main)(void *arg)
* on exitconn with type being RESOLVED_TYPE_ERROR.
*/
MOCK
(
dns_cancel_pending_resolve
,
dns_cancel_pending_resolve_replacement
);
MOCK
(
connection_free
,
connection_free_replacement
);
NS_
MOCK
(
dns_cancel_pending_resolve
);
NS_
MOCK
(
connection_free
);
exitconn
->
on_circuit
=
&
(
on_circuit
->
base_
);
exitconn
->
base_
.
purpose
=
EXIT_PURPOSE_RESOLVE
;
...
...
@@ -300,11 +305,11 @@ NS(test_main)(void *arg)
tt_assert
(
last_freed_conn
==
TO_CONN
(
exitconn
));
done:
UNMOCK
(
dns_resolve_impl
);
UNMOCK
(
send_resolved_cell
);
UNMOCK
(
send_resolved_hostname_cell
);
UNMOCK
(
dns_cancel_pending_resolve
);
UNMOCK
(
connection_free
);
NS_
UNMOCK
(
dns_resolve_impl
);
NS_
UNMOCK
(
send_resolved_cell
);
NS_
UNMOCK
(
send_resolved_hostname_cell
);
NS_
UNMOCK
(
dns_cancel_pending_resolve
);
NS_
UNMOCK
(
connection_free
);
tor_free
(
on_circuit
);
tor_free
(
exitconn
);
tor_free
(
nextconn
);
...
...
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