Skip to content

Commit

Permalink
registrar: fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rvlad-patrascu committed Apr 26, 2023
1 parent 1a753be commit 3767400
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions modules/registrar/test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,14 @@ static void test_lookup(void)
"mAq9Px0UY8YjVmo2LnmCocmFRBU0gPMV2ebheGGWCc");
str ct2 = str_init("sip:desk@127.0.0.2");
struct sip_msg msg;
struct lookup_flags flags;

memset(&flags, 0, sizeof flags);

ok(ul.register_udomain("location", &d) == 0, "get 'location' udomain");

mk_sip_req("INVITE", "sip:alice@localhost", &msg);
ok(reg_lookup(&msg, d, _str(""), NULL) == LOOKUP_NO_RESULTS, "lookup-1");
ok(reg_lookup(&msg, d, NULL, NULL) == LOOKUP_NO_RESULTS, "lookup-1");

ul.lock_udomain(d, &aor);
ok(ul.insert_urecord(d, &aor, &r, 0) == 0, "create AoR");
Expand All @@ -81,18 +84,21 @@ static void test_lookup(void)
ok(ul.insert_ucontact(r, &ct2, &ci, NULL, 1, &c) == 0, "insert Contact");
ul.unlock_udomain(d, &aor);

ok(reg_lookup(&msg, d, _str(""), NULL) == LOOKUP_OK, "lookup-2");
ok(reg_lookup(&msg, d, NULL, NULL) == LOOKUP_OK, "lookup-2");

set_ruri(&msg, &aor_ruri);
ok(reg_lookup(&msg, d, _str("m"), NULL) == LOOKUP_METHOD_UNSUP, "lookup-3");
flags.flags = REG_LOOKUP_METHODFILTER_FLAG;
ok(reg_lookup(&msg, d, &flags, NULL) == LOOKUP_METHOD_UNSUP,
"lookup-3");

c->methods = ALL_METHODS;

set_ruri(&msg, &aor_ruri);
ok(reg_lookup(&msg, d, _str(""), NULL) == LOOKUP_OK, "lookup-4");
ok(reg_lookup(&msg, d, NULL, NULL) == LOOKUP_OK, "lookup-4");

set_ruri(&msg, &aor_ruri);
ok(reg_lookup(&msg, d, _str("m"), NULL) == LOOKUP_OK, "lookup-5");
ok(reg_lookup(&msg, d, &flags, NULL) == LOOKUP_OK,
"lookup-5");

ok(ul.delete_ucontact(r, c, NULL, 0) == 0, "delete ucontact");

Expand All @@ -101,13 +107,13 @@ static void test_lookup(void)
ok(ul.insert_ucontact(r, &ct1, &ci, NULL, 1, &c) == 0, "insert ct1 (PN)");

set_ruri(&msg, &aor_ruri);
ok(reg_lookup(&msg, d, _str(""), NULL) == LOOKUP_PN_SENT, "lookup-6");
ok(reg_lookup(&msg, d, NULL, NULL) == LOOKUP_PN_SENT, "lookup-6");

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

set_ruri(&msg, &aor_ruri);
ok(reg_lookup(&msg, d, _str(""), NULL) == LOOKUP_OK, "lookup-7");
ok(reg_lookup(&msg, d, NULL, NULL) == LOOKUP_OK, "lookup-7");

/* the PN contact should just trigger a PN without becoming a branch */
ok(str_match(&msg.new_uri, &ct2), "lookup-7: R-URI is ct2");
Expand Down Expand Up @@ -135,7 +141,8 @@ static void test_lookup(void)
ok(append_branch(NULL, &ruri2, NULL, NULL, 1, 0, NULL) == 1, "append AoR-3");

set_ruri(&msg, &aor_ruri);
ok(reg_lookup(&msg, d, _str("r"), NULL) == LOOKUP_OK, "lookup-8");
flags.flags = REG_BRANCH_AOR_LOOKUP_FLAG;
ok(reg_lookup(&msg, d, &flags, NULL) == LOOKUP_OK, "lookup-8");
ok(get_nr_branches() == 1, "get-nr-branches");
}
}
Expand Down

0 comments on commit 3767400

Please sign in to comment.