Skip to content

Commit 293d7e7

Browse files
committed
PN Support: Add few unit tests for t_wait_for_new_branches()
(cherry picked from commit 5358eee)
1 parent d17fb7d commit 293d7e7

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

modules/registrar/test/test.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,36 @@
3232
#include "../lookup.h"
3333

3434

35+
static int (*saved_t_wait_for_new_branches)(struct sip_msg *msg,
36+
unsigned int num_br);
37+
static unsigned int pn_wait_branches;
38+
static int pn_wait_calls;
39+
40+
41+
static int test_t_wait_for_new_branches(struct sip_msg *msg,
42+
unsigned int num_br)
43+
{
44+
pn_wait_calls++;
45+
pn_wait_branches = num_br;
46+
return 1;
47+
}
48+
49+
50+
static void start_pn_wait_capture(void)
51+
{
52+
saved_t_wait_for_new_branches = tmb.t_wait_for_new_branches;
53+
tmb.t_wait_for_new_branches = test_t_wait_for_new_branches;
54+
pn_wait_calls = 0;
55+
pn_wait_branches = 0;
56+
}
57+
58+
59+
static void stop_pn_wait_capture(void)
60+
{
61+
tmb.t_wait_for_new_branches = saved_t_wait_for_new_branches;
62+
}
63+
64+
3565
static void fill_ucontact_info(ucontact_info_t *ci)
3666
{
3767
static char cid_buf[9];
@@ -59,6 +89,7 @@ static void test_lookup(void)
5989
ucontact_info_t ci;
6090
str aor = str_init("alice");
6191
str aor_ruri = str_init("sip:alice@localhost");
92+
str extra_branch_uri = str_init("sip:parallel@127.0.0.3");
6293
str ct1 = str_init("sip:cell@127.0.0.1:44444;"
6394
"pn-provider=apns;"
6495
"pn-prid=ZTY4ZDJlMzODE1NmUgKi0K;"
@@ -107,22 +138,49 @@ static void test_lookup(void)
107138
ok(ul.insert_ucontact(r, &ct1, &ci, NULL, 1, &c) == 0, "insert ct1 (PN)");
108139

109140
set_ruri(&msg, &aor_ruri);
141+
start_pn_wait_capture();
110142
ok(reg_lookup(&msg, d, NULL, NULL) == LOOKUP_PN_SENT, "lookup-6");
143+
ok(pn_wait_calls == 1 && pn_wait_branches == 1,
144+
"lookup-6: waits for PN branch");
145+
stop_pn_wait_capture();
111146

112147
fill_ucontact_info(&ci);
113148
ok(ul.insert_ucontact(r, &ct2, &ci, NULL, 1, &c) == 0, "insert ct2 (normal)");
114149

115150
set_ruri(&msg, &aor_ruri);
151+
start_pn_wait_capture();
116152
ok(reg_lookup(&msg, d, NULL, NULL) == LOOKUP_OK, "lookup-7");
153+
ok(pn_wait_calls == 1 && pn_wait_branches == 2,
154+
"lookup-7: waits for PN and regular branch");
155+
stop_pn_wait_capture();
117156

118157
/* the PN contact should just trigger a PN without becoming a branch */
119158
ok(str_match(&msg.new_uri, &ct2), "lookup-7: R-URI is ct2");
120159

160+
{
161+
struct msg_branch branch;
162+
163+
memset(&branch, 0, sizeof branch);
164+
branch.uri = extra_branch_uri;
165+
branch.q = Q_UNSPECIFIED;
166+
ok(append_msg_branch(&branch) == 1, "append extra branch");
167+
168+
set_ruri(&msg, &aor_ruri);
169+
start_pn_wait_capture();
170+
ok(reg_lookup(&msg, d, NULL, NULL) == LOOKUP_OK, "lookup-7b");
171+
ok(pn_wait_calls == 1 && pn_wait_branches == 3,
172+
"lookup-7b: waits for existing, regular and PN branches");
173+
stop_pn_wait_capture();
174+
clear_dset();
175+
}
176+
121177
/* test the "r" flag (branch lookup) */
122178
{
123179
str aor2 = str_init("bob"), aor3 = str_init("carol");
124180
struct msg_branch branch;
125181

182+
clear_dset();
183+
126184
ul.lock_udomain(d, &aor2);
127185
ok(ul.insert_urecord(d, &aor2, &r, 0) == 0, "create AoR 2");
128186
ul.unlock_udomain(d, &aor2);

0 commit comments

Comments
 (0)