Skip to content

Commit

Permalink
registrar: Add some lookup() unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
liviuchircu committed Apr 27, 2020
1 parent b0d9c54 commit d761f15
Showing 1 changed file with 69 additions and 2 deletions.
71 changes: 69 additions & 2 deletions modules/registrar/test/test.c
Expand Up @@ -18,11 +18,78 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include <tap.h>

#include "../../../dprint.h"
#include "../../../test/unit_tests.h"
#include "../../../test/ut.h"
#include "../../../lib/reg/pn.h"
#include "../../../lib/reg/regtime.h"

#include "../../usrloc/usrloc.h"
#include "../reg_mod.h"
#include "../lookup.h"


ucontact_t *create_contact(const char *ct_uri, const struct ct_match *cmatch,
urecord_t *r)
{
ucontact_t *c;
ucontact_info_t ci;
char cid_buf[9];
str callid = {cid_buf, 0};
str no_ua = str_init("n/a");

update_act_time();

memset(&ci, 0, sizeof ci);

callid.len = sprintf(cid_buf, "%x", rand());
ci.callid = &callid;
ci.user_agent = &no_ua;
ci.q = Q_UNSPECIFIED;
ci.expires = get_act_time() + 120;

ok(ul.insert_ucontact(r, _str(ct_uri), &ci, &c, 0) == 0, "Insert Contact");
return c;
}


void test_lookup(void)
{
udomain_t *d;
urecord_t *r;
ucontact_t *c;
struct ct_match cmatch;
struct sip_msg msg;

ok(ul.register_udomain("location", &d) == 0, "get 'location' udomain");
ok(ul.insert_urecord(d, _str("alice"), &r, 0) == 0, "create AoR");

cmatch.mode = CT_MATCH_PARAMS;
cmatch.match_params = pn_ct_params;
ok((c = create_contact("sip:cell@127.0.0.1:44444;"
"pn-provider=apns;"
"pn-prid=ZTY4ZDJlMzODE1NmUgKi0K;"
"pn-param=ezenSQIywP8:APA91bHFH7p41WUFljaUPM2PPEjQUEslb6NtIqN6Pyc"
"gN5eDCyzuomQMyWboTVum0MY8YL_3E8vFIZUur_B71DHVgXQVD6UfZJ"
"mAq9Px0UY8YjVmo2LnmCocmFRBU0gPMV2ebheGGWCc", &cmatch, r))
!= NULL, "create Contact 1");

cmatch.mode = CT_MATCH_CONTACT_ONLY;
ok((c = create_contact("sip:desk@127.0.0.2", &cmatch, r)) != NULL, "create Contact 2");

mk_sip_req("INVITE", "sip:alice@localhost", &msg);

lookup(&msg, d, _str(""), NULL);

/* the PN contact should just trigger a PN without becoming a branch */
ok(str_match(&msg.new_uri, _str("sip:desk@127.0.0.2")), "lookup R-URI");
}


int mod_tests(void)
{
LM_INFO("Hello, World!\n");
test_lookup();

return 0;
}

0 comments on commit d761f15

Please sign in to comment.