|
32 | 32 | #include "../lookup.h" |
33 | 33 |
|
34 | 34 |
|
| 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 | + |
35 | 65 | static void fill_ucontact_info(ucontact_info_t *ci) |
36 | 66 | { |
37 | 67 | static char cid_buf[9]; |
@@ -59,6 +89,7 @@ static void test_lookup(void) |
59 | 89 | ucontact_info_t ci; |
60 | 90 | str aor = str_init("alice"); |
61 | 91 | str aor_ruri = str_init("sip:alice@localhost"); |
| 92 | + str extra_branch_uri = str_init("sip:parallel@127.0.0.3"); |
62 | 93 | str ct1 = str_init("sip:cell@127.0.0.1:44444;" |
63 | 94 | "pn-provider=apns;" |
64 | 95 | "pn-prid=ZTY4ZDJlMzODE1NmUgKi0K;" |
@@ -107,22 +138,49 @@ static void test_lookup(void) |
107 | 138 | ok(ul.insert_ucontact(r, &ct1, &ci, NULL, 1, &c) == 0, "insert ct1 (PN)"); |
108 | 139 |
|
109 | 140 | set_ruri(&msg, &aor_ruri); |
| 141 | + start_pn_wait_capture(); |
110 | 142 | 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(); |
111 | 146 |
|
112 | 147 | fill_ucontact_info(&ci); |
113 | 148 | ok(ul.insert_ucontact(r, &ct2, &ci, NULL, 1, &c) == 0, "insert ct2 (normal)"); |
114 | 149 |
|
115 | 150 | set_ruri(&msg, &aor_ruri); |
| 151 | + start_pn_wait_capture(); |
116 | 152 | 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(); |
117 | 156 |
|
118 | 157 | /* the PN contact should just trigger a PN without becoming a branch */ |
119 | 158 | ok(str_match(&msg.new_uri, &ct2), "lookup-7: R-URI is ct2"); |
120 | 159 |
|
| 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 | + |
121 | 177 | /* test the "r" flag (branch lookup) */ |
122 | 178 | { |
123 | 179 | str aor2 = str_init("bob"), aor3 = str_init("carol"); |
124 | 180 | struct msg_branch branch; |
125 | 181 |
|
| 182 | + clear_dset(); |
| 183 | + |
126 | 184 | ul.lock_udomain(d, &aor2); |
127 | 185 | ok(ul.insert_urecord(d, &aor2, &r, 0) == 0, "create AoR 2"); |
128 | 186 | ul.unlock_udomain(d, &aor2); |
|
0 commit comments