int test_rtsp(void) { /* RTSP urls */ su_home_t home[1] = { SU_HOME_INIT(home) }; url_t rtsp[1] = { URL_INIT_AS(rtsp) }; url_t *u, url[1]; char *tst; char rtspurl[] = "rtsp://example.com:42/barfoo.rm"; char rtspuurl[] = "rtspu://example.com:42/barfoo.rm"; char rtsp2[sizeof(rtspurl) + 32]; BEGIN(); TEST_S(url_scheme(url_rtsp), "rtsp"); TEST_S(url_scheme(url_rtspu), "rtspu"); rtsp->url_root = 1; rtsp->url_host = "example.com"; rtsp->url_port = "42"; rtsp->url_path = "barfoo.rm"; TEST_1(tst = su_strdup(home, rtspurl)); TEST_1(url_d(url, tst) == 0); TEST_1(url_cmp(rtsp, url) == 0); TEST(url->url_type, url_rtsp); TEST_1(u = url_hdup(home, url)); TEST(u->url_type, url_rtsp); TEST_1(url_cmp(rtsp, u) == 0); TEST(url_e(rtsp2, sizeof(rtsp2), u), strlen(rtspurl)); TEST_1(strcmp(rtsp2, rtspurl) == 0); TEST_SIZE(snprintf(rtsp2, sizeof(rtsp2), URL_PRINT_FORMAT, URL_PRINT_ARGS(rtsp)), strlen(rtspurl)); TEST_1(strcmp(rtsp2, rtspurl) == 0); url_digest(hash1, sizeof(hash1), url, NULL); url_digest(hash2, sizeof(hash2), (url_t *)rtspurl, NULL); TEST(memcmp(hash1, hash2, sizeof(hash1)), 0); su_home_deinit(home); rtsp->url_type = url_rtspu, rtsp->url_scheme = "rtspu"; TEST_1(tst = su_strdup(home, rtspuurl)); TEST_1(url_d(url, tst) == 0); TEST_1(url_cmp(rtsp, url) == 0); TEST(url->url_type, url_rtspu); url_digest(hash1, sizeof(hash1), url, NULL); url_digest(hash2, sizeof(hash2), (url_t *)rtspuurl, NULL); TEST(memcmp(hash1, hash2, sizeof(hash1)), 0); su_home_deinit(home); END(); }
int test_tags(void) { url_t u0[1]; url_t *u1 = NULL; url_t const *u2 = (void *)-1; url_t const u3[1] = { URL_INIT_AS(sip) }; char c0[] = "http://www.nokia.com"; char const *c1 = "http://goodfeel.nokia.com"; char *c2 = "http://forum.nokia.com"; char const c3[] = "http://www.research.nokia.com"; url_string_t *us0 = NULL; tagi_t *lst, *dup; tag_value_t value; char *s; su_home_t home[1] = { SU_HOME_INIT(home) }; BEGIN(); TEST(t_scan(urltag_url, home, c0, &value), 0); TEST_S(s = url_as_string(home, (url_t *)value), c0); TEST(t_scan(urltag_url, home, c3, &value), 0); TEST_S(s = url_as_string(home, (url_t *)value), c3); TEST_1(url_d(u0, c0) == 0); lst = tl_list(URLTAG_URL(u0), URLTAG_URL(u1), URLTAG_URL(u2), URLTAG_URL(u3), URLTAG_URL(c0), URLTAG_URL(c1), URLTAG_URL(c2), URLTAG_URL(c3), URLTAG_URL(us0), TAG_NULL()); TEST_1(lst); dup = tl_adup(home, lst); tl_vfree(lst); su_free(home, dup); su_home_deinit(home); END(); }
static int test_strdupcat(void) { su_home_t home[1] = { SU_HOME_INIT(home) }; BEGIN(); TEST_S(su_strdup(home, "foo"), "foo"); TEST_S(su_strcat(home, "foo", "bar"), "foobar"); TEST_S(su_strndup(home, "foobar", 3), "foo"); TEST_S(su_strcat_all(home, NULL), ""); TEST_S(su_strcat_all(home, "a", "", "b", "", NULL), "ab"); su_home_deinit(home); END(); }
int test_ldap(void) { /* Test a LDAP url */ char ldapurl[] = "ldap://cn=Manager,o=nokia:secret@localhost:389/ou=devices,o=nokia"; url_t ldap[1] = { URL_INIT_AS(file) }; su_home_t home[1] = { SU_HOME_INIT(home) }; char *tst; url_t *u, url[1]; char buf1[sizeof(ldapurl) + 32]; char buf2[sizeof(ldapurl) + 32]; BEGIN(); ldap->url_type = url_unknown; ldap->url_scheme = "ldap"; /* TEST_S(url_scheme(url_ldap), "ldap"); */ TEST_1(tst = su_strdup(home, ldapurl)); TEST(url_d(url, tst), 0); TEST_S(url->url_user, "cn=Manager,o=nokia:secret"); /* TEST_S(url->url_password, "secret"); */ TEST_S(url->url_host, "localhost"); TEST_S(url->url_port, "389"); TEST_S(url->url_path, "ou=devices,o=nokia"); ldap->url_user = "******"; ldap->url_password = "******"; ldap->url_user = "******", ldap->url_password = NULL; ldap->url_host = "localhost"; ldap->url_port = "389"; ldap->url_path = "ou=devices,o=nokia"; TEST(url_cmp(ldap, url), 0); TEST(url->url_type, url_unknown); TEST_S(url->url_scheme, "ldap"); TEST_1(u = url_hdup(home, url)); TEST(u->url_type, url_unknown); TEST_S(u->url_scheme, "ldap"); TEST(url_cmp(ldap, u), 0); TEST_SIZE(url_e(buf1, sizeof(buf1), u), strlen(ldapurl)); TEST_S(buf1, ldapurl); TEST_SIZE(snprintf(buf2, sizeof(buf2), URL_PRINT_FORMAT, URL_PRINT_ARGS(u)), strlen(ldapurl)); TEST_S(buf2, ldapurl); url_digest(hash1, sizeof(hash1), url, NULL); url_digest(hash2, sizeof(hash2), (url_t *)ldapurl, NULL); TEST(memcmp(hash1, hash2, sizeof(hash1)), 0); su_home_deinit(home); END(); }
int main(void) { int i, j, k; char b[2000]; TEST(i, snprintf(0, 0, "%d", 123456), 6, "length returned %d != %d"); TEST(i, snprintf(0, 0, "%.4s", "hello"), 4, "length returned %d != %d"); TEST(i, snprintf(b, 0, "%.0s", "goodbye"), 0, "length returned %d != %d"); strcpy(b, "xxxxxxxx"); TEST(i, snprintf(b, 4, "%d", 123456), 6, "length returned %d != %d"); TEST_S(b, "123", "incorrect output"); TEST(i, b[5], 'x', "buffer overrun"); /* Perform ascii arithmetic to test printing tiny doubles */ TEST(i, snprintf(b, sizeof b, "%.1022f", 0x1p-1021), 1024, "%d != %d"); b[1] = '0'; for (i=0; i<1021; i++) { for (k=0, j=1023; j>0; j--) { if (b[j]<'5') b[j]+=b[j]-'0'+k, k=0; else b[j]+=b[j]-'0'-10+k, k=1; } } TEST(i, b[1], '1', "'%c' != '%c'"); for (j=2; b[j]=='0'; j++); TEST(i, j, 1024, "%d != %d"); #ifndef DISABLE_SLOW_TESTS errno = 0; TEST(i, snprintf(NULL, 0, "%.*u", 2147483647, 0), 2147483647, "cannot print max length %d"); TEST(i, snprintf(NULL, 0, "%.*u ", 2147483647, 0), -1, "integer overflow %d"); TEST(i, errno, EOVERFLOW, "after overflow: %d != %d"); #endif for (j=0; int_tests[j].fmt; j++) { i = snprintf(b, sizeof b, int_tests[j].fmt, int_tests[j].i); if (i != strlen(int_tests[j].expect)) { t_error("snprintf(b, sizeof b, \"%s\", %d) returned %d wanted %d\n", int_tests[j].fmt, int_tests[j].i, i, strlen(int_tests[j].expect)); } if (strcmp(b, int_tests[j].expect) != 0) t_error("bad integer conversion: got \"%s\", want \"%s\"\n", b, int_tests[j].expect); } for (j=0; fp_tests[j].fmt; j++) { i = snprintf(b, sizeof b, fp_tests[j].fmt, fp_tests[j].f); if (i != strlen(fp_tests[j].expect)) { t_error("snprintf(b, sizeof b, \"%s\", %f) returned %d wanted %d\n", fp_tests[j].fmt, fp_tests[j].f, i, strlen(fp_tests[j].expect)); } if (strcmp(b, fp_tests[j].expect) != 0) t_error("bad floating-point conversion: got \"%s\", want \"%s\"\n", b, fp_tests[j].expect); } TEST(i, snprintf(0, 0, "%.4a", 1.0), 11, "%d != %d"); return t_status; }
int test_wv(void) { /* wv urls */ su_home_t home[1] = { SU_HOME_INIT(home) }; url_t wv[1] = { URL_INIT_AS(wv) }; url_t *u, url[1]; char *tst; char wvurl[] = "wv:[email protected]"; char wv2[sizeof(wvurl) + 32]; BEGIN(); TEST_S(url_scheme(url_wv), "wv"); wv->url_user = "******"; wv->url_host = "imps.com"; TEST_1(tst = su_strdup(home, wvurl)); TEST_1(url_d(url, tst) == 0); TEST_1(url_cmp(wv, url) == 0); TEST_1(url_cmp(url_hdup(home, (void *)"wv:[email protected]"), url) == 0); TEST(url->url_type, url_wv); TEST_1(u = url_hdup(home, url)); TEST(u->url_type, url_wv); TEST_1(url_cmp(wv, u) == 0); TEST_SIZE(url_e(wv2, sizeof(wv2), u), strlen(wvurl)); TEST_1(strcmp(wv2, wvurl) == 0); TEST_SIZE(snprintf(wv2, sizeof(wv2), URL_PRINT_FORMAT, URL_PRINT_ARGS(wv)), strlen(wvurl)); TEST_1(strcmp(wv2, wvurl) == 0); url_digest(hash1, sizeof(hash1), url, NULL); url_digest(hash2, sizeof(hash2), (url_t *)wvurl, NULL); TEST(memcmp(hash1, hash2, sizeof(hash1)), 0); TEST_1(u = url_hdup(home, (void*)"wv:/[email protected]")); TEST_S(u->url_user, "/managers"); su_home_deinit(home); END(); }
int main(void) { int i, j; wchar_t b[500]; (void)( setlocale(LC_CTYPE, "en_US.UTF-8") || setlocale(LC_CTYPE, "en_GB.UTF-8") || setlocale(LC_CTYPE, "en.UTF-8") || setlocale(LC_CTYPE, "POSIX.UTF-8") || setlocale(LC_CTYPE, "C.UTF-8") || setlocale(LC_CTYPE, "UTF-8") || setlocale(LC_CTYPE, "") ); TEST(i, strcmp(nl_langinfo(CODESET), "UTF-8"), 0, "no UTF-8 locale; tests might fail"); TEST(i, swprintf(0, 0, L"%d", 123456)<0, 1, "%d != %d"); TEST(i, swprintf(b, 2, L"%lc", 0xc0), 1, "%d != %d"); TEST(i, b[0], 0xc0, "wrong character %x != %x"); TEST(i, swprintf(b, 2, L"%lc", 0x20ac), 1, "%d != %d"); TEST(i, b[0], 0x20ac, "wrong character %x != %x"); TEST(i, swprintf(b, 3, L"%s", "\xc3\x80!"), 2, "%d != %d"); TEST(i, b[0], 0xc0, "wrong character %x != %x"); TEST(i, swprintf(b, 2, L"%.1s", "\xc3\x80!"), 1, "%d != %d"); TEST(i, b[0], 0xc0, "wrong character %x != %x"); wcscpy(b, L"xxxxxxxx"); TEST(i, swprintf(b, 4, L"%d", 123456)<0, 1, "%d != %d"); TEST_S(b, L"123", "incorrect output"); TEST(i, b[5], 'x', "buffer overrun"); for (j=0; int_tests[j].fmt; j++) { i = swprintf(b, sizeof b, int_tests[j].fmt, int_tests[j].i); if (i != wcslen(int_tests[j].expect)) { t_error("swprintf(b, sizeof b, \"%ls\", %d) returned %d wanted %d\n", int_tests[j].fmt, int_tests[j].i, i, wcslen(int_tests[j].expect)); } if (wcscmp(b, int_tests[j].expect) != 0) t_error("bad integer conversion: got \"%ls\", want \"%ls\"\n", b, int_tests[j].expect); } for (j=0; fp_tests[j].fmt; j++) { i = swprintf(b, sizeof b, fp_tests[j].fmt, fp_tests[j].f); if (i != wcslen(fp_tests[j].expect)) { t_error("swprintf(b, sizeof b, \"%ls\", %f) returned %d wanted %d\n", fp_tests[j].fmt, fp_tests[j].f, i, wcslen(fp_tests[j].expect)); } if (wcscmp(b, fp_tests[j].expect) != 0) t_error("bad floating-point conversion: got \"%ls\", want \"%ls\"\n", b, fp_tests[j].expect); } return t_status; }
int test_tel(void) { /* tel urls: RFC 3906 */ su_home_t home[1] = { SU_HOME_INIT(home) }; url_t tel[1] = { URL_INIT_AS(tel) }; url_t *u, url[1]; char *tst; char telurl[] = "tel:+12345678" ";param=1;param=2" "?From=foo@bar&To=bar@baz#unf"; char tel2[sizeof(telurl) + 32]; url_t *a, *b; BEGIN(); TEST_S(url_scheme(url_tel), "tel"); tel->url_user = "******"; tel->url_params = "param=1;param=2"; tel->url_headers = "From=foo@bar&To=bar@baz"; tel->url_fragment = "unf"; TEST_1(tst = su_strdup(home, telurl)); TEST_1(url_d(url, tst) == 0); TEST_1(url_cmp(tel, url) == 0); TEST_1(url_cmp(url_hdup(home, (url_t const *)"tel:+12345678" ";param=1;param=2" "?From=foo@bar&To=bar@baz#unf"), url) == 0); TEST(url->url_type, url_tel); TEST_1(u = url_hdup(home, url)); TEST(u->url_type, url_tel); TEST_1(url_cmp(tel, u) == 0); TEST_SIZE(url_e(tel2, sizeof(tel2), u), strlen(telurl)); TEST_1(strcmp(tel2, telurl) == 0); TEST_SIZE(snprintf(tel2, sizeof(tel2), URL_PRINT_FORMAT, URL_PRINT_ARGS(tel)), strlen(telurl)); TEST_1(strcmp(tel2, telurl) == 0); url_digest(hash1, sizeof(hash1), url, NULL); url_digest(hash2, sizeof(hash2), (url_t *)telurl, NULL); TEST(memcmp(hash1, hash2, sizeof(hash1)), 0); a = url_hdup(home, (void *)"tel:+1.245.62357"); b = url_hdup(home, (void *)"tel:+(1).245.62357"); TEST_1(a); TEST_1(b); TEST_1(url_cmp(a, b) == 0); TEST_1(url_cmp_all(a, b) == 0); su_home_deinit(home); END(); }
int test_file(void) { /* Test a url with path like file:/foo/bar */ char fileurl[] = "file:///foo/bar"; url_t file[1] = { URL_INIT_AS(file) }; su_home_t home[1] = { SU_HOME_INIT(home) }; char *tst; url_t *u, url[1]; char buf1[sizeof(fileurl) + 32]; char buf2[sizeof(fileurl) + 32]; BEGIN(); TEST_S(url_scheme(url_file), "file"); TEST_1(tst = su_strdup(home, fileurl)); TEST(url_d(url, tst), 0); TEST_S(url->url_host, ""); file->url_root = '/'; file->url_host = ""; file->url_path = "foo/bar"; TEST(url_cmp(file, url), 0); TEST(url->url_type, url_file); TEST_1(u = url_hdup(home, url)); TEST(u->url_type, url_file); TEST(url_cmp(file, u), 0); TEST_SIZE(url_e(buf1, sizeof(buf1), u), strlen(fileurl)); TEST_S(buf1, fileurl); TEST_SIZE(snprintf(buf2, sizeof(buf2), URL_PRINT_FORMAT, URL_PRINT_ARGS(u)), strlen(fileurl)); TEST_S(buf2, fileurl); url_digest(hash1, sizeof(hash1), url, NULL); url_digest(hash2, sizeof(hash2), (url_t *)fileurl, NULL); TEST(memcmp(hash1, hash2, sizeof(hash1)), 0); su_home_deinit(home); END(); }
int strpool_test(void) { StrPool pool = {0}; char *p; int i; printf("testing strpool..."); TEST(!strpool_find(&pool,"abc")); p=strpool_add(&pool,"abc"); TEST(p); TEST(0==strcmp("abc",strpool_add(&pool,"abc"))); TEST(p == strpool_add(&pool,"abc")); for(i = 0; i < 100; ++i) { int j; char tmp[128]; sprintf(tmp,"%i",i); strpool_add(&pool,tmp); for(j = 0; j <= i; ++j) { sprintf(tmp,"%i",j); TEST(strpool_find(&pool,tmp)); } } strpool_cleanup(&pool); #define TEST_S(A,B) TEST(0==strcmp(A,B)) p = NULL; str_cat(&p,"a"); TEST_S(p,"a"); str_cat(&p,"b"); TEST_S(p,"ab"); str_catf(&p,"%i%s%i",1,"foo",2); TEST_S(p,"ab1foo2"); free(p); printf("done.\n"); return 0; }
static int test_sprintf(char const *fmt, ...) { BEGIN(); su_home_t home[1] = { SU_HOME_INIT(home) }; va_list va; TEST_S(su_sprintf(home, "foo%s", "bar"), "foobar"); va_start(va, fmt); TEST_S(su_vsprintf(home, fmt, va), "foo.bar"); TEST_S(su_sprintf(home, "foo%200s", "bar"), "foo " " " " " " bar"); su_home_deinit(home); END(); }
int test_sanitizing(void) { url_t url[1]; char www[] = "www.hut.fi"; char ftp[] = "ftp.hut.fi"; char www2[] = "iptel.hut.fi/humppa"; char sip[] = "test.host"; char buf[64]; BEGIN(); TEST_1(url_d(url, www) == 0); TEST_1(url_sanitize(url) == 0); TEST(url->url_type, url_http); snprintf(buf, sizeof(buf), URL_PRINT_FORMAT, URL_PRINT_ARGS(url)); TEST_S(buf, "http://www.hut.fi"); TEST_1(url_d(url, ftp) == 0); TEST_1(url_sanitize(url) == 0); TEST(url->url_type, url_ftp); snprintf(buf, sizeof(buf), URL_PRINT_FORMAT, URL_PRINT_ARGS(url)); TEST_S(buf, "ftp://ftp.hut.fi"); TEST_1(url_d(url, www2) == 0); TEST_1(url_sanitize(url) == 0); TEST(url->url_type, url_http); snprintf(buf, sizeof(buf), URL_PRINT_FORMAT, URL_PRINT_ARGS(url)); TEST_S(buf, "http://iptel.hut.fi/humppa"); TEST_1(url_d(url, sip) == 0); TEST_1(url_sanitize(url) == 0); TEST(url->url_type, url_sip); snprintf(buf, sizeof(buf), URL_PRINT_FORMAT, URL_PRINT_ARGS(url)); TEST_S(buf, "sip:test.host"); END(); }
int test_fax(void) { /* fax urls */ su_home_t home[1] = { SU_HOME_INIT(home) }; url_t fax[1] = { URL_INIT_AS(fax) }; url_t *u, url[1]; char *tst; char faxurl[] = "fax:+12345678" ";param=1;param=2" "?From=foo@bar&To=bar@baz#unf"; char fax2[sizeof(faxurl) + 32]; BEGIN(); TEST_S(url_scheme(url_fax), "fax"); fax->url_user = "******"; fax->url_params = "param=1;param=2"; fax->url_headers = "From=foo@bar&To=bar@baz"; fax->url_fragment = "unf"; TEST_1(tst = su_strdup(home, faxurl)); TEST_1(url_d(url, tst) == 0); TEST_1(url_cmp(fax, url) == 0); TEST(url->url_type, url_fax); TEST_1(u = url_hdup(home, url)); TEST(u->url_type, url_fax); TEST_1(url_cmp(fax, u) == 0); TEST_SIZE(url_e(fax2, sizeof(fax2), u), strlen(faxurl)); TEST_1(strcmp(fax2, faxurl) == 0); TEST_SIZE(snprintf(fax2, sizeof(fax2), URL_PRINT_FORMAT, URL_PRINT_ARGS(fax)), strlen(faxurl)); TEST_1(strcmp(fax2, faxurl) == 0); url_digest(hash1, sizeof(hash1), url, NULL); url_digest(hash2, sizeof(hash2), (url_t *)faxurl, NULL); TEST(memcmp(hash1, hash2, sizeof(hash1)), 0); su_home_deinit(home); END(); }
int test_modem(void) { /* modem urls */ su_home_t home[1] = { SU_HOME_INIT(home) }; url_t modem[1] = { URL_INIT_AS(modem) }; url_t *u, url[1]; char *tst; char modemurl[] = "modem:+12345678" ";param=1;param=2" "?From=foo@bar&To=bar@baz#unf"; char modem2[sizeof(modemurl) + 32]; BEGIN(); TEST_S(url_scheme(url_modem), "modem"); modem->url_user = "******"; modem->url_params = "param=1;param=2"; modem->url_headers = "From=foo@bar&To=bar@baz"; modem->url_fragment = "unf"; TEST_1(tst = su_strdup(home, modemurl)); TEST_1(url_d(url, tst) == 0); TEST_1(url_cmp(modem, url) == 0); TEST(url->url_type, url_modem); TEST_1(u = url_hdup(home, url)); TEST(u->url_type, url_modem); TEST_1(url_cmp(modem, u) == 0); TEST_SIZE(url_e(modem2, sizeof(modem2), u), strlen(modemurl)); TEST_1(strcmp(modem2, modemurl) == 0); TEST_SIZE(snprintf(modem2, sizeof(modem2), URL_PRINT_FORMAT, URL_PRINT_ARGS(modem)), strlen(modemurl)); TEST_1(strcmp(modem2, modemurl) == 0); url_digest(hash1, sizeof(hash1), url, NULL); url_digest(hash2, sizeof(hash2), (url_t *)modemurl, NULL); TEST(memcmp(hash1, hash2, sizeof(hash1)), 0); su_home_deinit(home); END(); }
int test_events(struct context *ctx) { BEGIN(); struct endpoint *a = &ctx->a, *b = &ctx->b; struct call *a_call = a->call, *b_call = b->call; struct event *e, *en, *es; sip_t const *sip; tagi_t const *t, *n_tags, *r_tags; url_t b_url[1]; enum nua_substate substate; nea_sub_t *sub = NULL; char const open[] = "<?xml version='1.0' encoding='UTF-8'?>\n" "<presence xmlns='urn:ietf:params:xml:ns:cpim-pidf' \n" " entity='pres:[email protected]'>\n" " <tuple id='ksac9udshce'>\n" " <status><basic>open</basic></status>\n" " <contact priority='1.0'>sip:[email protected]</contact>\n" " </tuple>\n" "</presence>\n"; char const closed[] = "<?xml version='1.0' encoding='UTF-8'?>\n" "<presence xmlns='urn:ietf:params:xml:ns:cpim-pidf' \n" " entity='pres:[email protected]'>\n" " <tuple id='ksac9udshce'>\n" " <status><basic>closed</basic></status>\n" " </tuple>\n" "</presence>\n"; /* SUBSCRIBE test A B |------SUBSCRIBE---->| |<--------405--------| | | */ if (print_headings) printf("TEST NUA-12.1: SUBSCRIBE without notifier\n"); nua_set_params(b->nua, SIPTAG_ALLOW_EVENTS(NULL), TAG_END()); run_b_until(ctx, nua_r_set_params, until_final_response); TEST_1(a_call->nh = nua_handle(a->nua, a_call, SIPTAG_TO(b->to), TAG_END())); SUBSCRIBE(a, a_call, a_call->nh, NUTAG_URL(b->contact->m_url), SIPTAG_EVENT_STR("presence"), TAG_END()); run_ab_until(ctx, -1, save_until_final_response, -1, NULL /* XXX save_until_received */); /* Client events: nua_subscribe(), nua_r_subscribe */ TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_r_subscribe); TEST(e->data->e_status, 489); TEST_1(!e->next); #if 0 /* XXX */ /* Server events: nua_i_subscribe */ TEST_1(e = b->events->head); TEST_E(e->data->e_event, nua_i_subscribe); TEST(e->data->e_status, 405); TEST_1(sip = sip_object(e->data->e_msg)); TEST_1(sip->sip_event); TEST_S(sip->sip_event->o_type, "presence"); TEST_1(!e->next); #endif free_events_in_list(ctx, a->events); free_events_in_list(ctx, b->events); nua_handle_destroy(b_call->nh), b_call->nh = NULL; if (print_headings) printf("TEST NUA-12.1: PASSED\n"); /* ---------------------------------------------------------------------- */ /* SUBSCRIBE test using notifier and establishing subscription A B | | |------SUBSCRIBE---->| |<--------202--------| |<------NOTIFY-------| |-------200 OK------>| | | */ if (print_headings) printf("TEST NUA-12.2: using notifier and establishing subscription\n"); TEST_1(b_call->nh = nua_handle(b->nua, b_call, TAG_END())); *b_url = *b->contact->m_url; NOTIFIER(b, b_call, b_call->nh, NUTAG_URL(b_url), SIPTAG_EVENT_STR("presence"), SIPTAG_CONTENT_TYPE_STR("application/pidf+xml"), SIPTAG_PAYLOAD_STR(closed), NEATAG_THROTTLE(1), TAG_END()); run_b_until(ctx, nua_r_notifier, until_final_response); SUBSCRIBE(a, a_call, a_call->nh, NUTAG_URL(b->contact->m_url), SIPTAG_EVENT_STR("presence"), SIPTAG_ACCEPT_STR("application/xpidf, application/pidf+xml"), TAG_END()); run_ab_until(ctx, -1, save_until_notified_and_responded, -1, save_until_received); /* Client events: nua_subscribe(), nua_i_notify/nua_r_subscribe */ TEST_1(en = event_by_type(a->events->head, nua_i_notify)); TEST_1(es = event_by_type(a->events->head, nua_r_subscribe)); TEST_1(e = es); TEST_E(e->data->e_event, nua_r_subscribe); r_tags = e->data->e_tags; TEST_1(tl_find(r_tags, nutag_substate)); if (es->next == en) { TEST_1(200 <= e->data->e_status && e->data->e_status < 300); TEST(tl_find(r_tags, nutag_substate)->t_value, nua_substate_embryonic); } else { TEST_1(200 <= e->data->e_status && e->data->e_status < 300); TEST(tl_find(r_tags, nutag_substate)->t_value, nua_substate_active); } TEST_1(e = en); TEST_E(e->data->e_event, nua_i_notify); TEST_1(sip = sip_object(e->data->e_msg)); n_tags = e->data->e_tags; TEST_1(sip->sip_event); TEST_S(sip->sip_event->o_type, "presence"); TEST_1(sip->sip_content_type); TEST_S(sip->sip_content_type->c_type, "application/pidf+xml"); TEST_1(sip->sip_subscription_state); TEST_S(sip->sip_subscription_state->ss_substate, "active"); TEST_1(sip->sip_subscription_state->ss_expires); TEST_1(tl_find(n_tags, nutag_substate)); TEST(tl_find(n_tags, nutag_substate)->t_value, nua_substate_active); TEST_1(!en->next || !es->next); free_events_in_list(ctx, a->events); /* XXX --- Do not check server side events */ free_events_in_list(ctx, b->events); if (print_headings) printf("TEST NUA-12.2: PASSED\n"); /* ---------------------------------------------------------------------- */ /* NOTIFY with updated content A B | | |<------NOTIFY-------| |-------200 OK------>| | | */ if (print_headings) printf("TEST NUA-12.3: update notifier\n"); /* Update presence data */ NOTIFIER(b, b_call, b_call->nh, SIPTAG_EVENT_STR("presence"), SIPTAG_CONTENT_TYPE_STR("application/pidf+xml"), SIPTAG_PAYLOAD_STR(open), TAG_END()); run_ab_until(ctx, -1, save_until_notified, -1, save_until_received); /* subscriber events: nua_i_notify */ TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_i_notify); TEST_1(sip = sip_object(e->data->e_msg)); TEST_1(sip->sip_event); TEST_S(sip->sip_event->o_type, "presence"); TEST_1(sip->sip_content_type); TEST_S(sip->sip_content_type->c_type, "application/pidf+xml"); TEST_1(sip->sip_subscription_state); TEST_S(sip->sip_subscription_state->ss_substate, "active"); TEST_1(sip->sip_subscription_state->ss_expires); n_tags = e->data->e_tags; TEST_1(tl_find(n_tags, nutag_substate)); TEST(tl_find(n_tags, nutag_substate)->t_value, nua_substate_active); TEST_1(!e->next); free_events_in_list(ctx, a->events); /* XXX --- Do not check server side events */ free_events_in_list(ctx, b->events); if (print_headings) printf("TEST NUA-12.3: PASSED\n"); /* ---------------------------------------------------------------------- */ /* un-SUBSCRIBE A B | | |------SUBSCRIBE---->| |<--------202--------| |<------NOTIFY-------| |-------200 OK------>| | | */ if (print_headings) printf("TEST NUA-12.5: un-SUBSCRIBE\n"); memset(&a->flags, 0, sizeof a->flags); UNSUBSCRIBE(a, a_call, a_call->nh, TAG_END()); run_ab_until(ctx, -1, save_until_notified_and_responded, -1, save_until_subscription); /* Client events: nua_unsubscribe(), nua_i_notify/nua_r_unsubscribe */ TEST_1(e = a->events->head); if (e->data->e_event == nua_i_notify) { TEST_E(e->data->e_event, nua_i_notify); TEST_1(sip = sip_object(e->data->e_msg)); n_tags = e->data->e_tags; TEST_1(sip->sip_event); TEST_1(sip->sip_subscription_state); TEST_S(sip->sip_subscription_state->ss_substate, "terminated"); TEST_1(!sip->sip_subscription_state->ss_expires); TEST_1(tl_find(n_tags, nutag_substate)); TEST(tl_find(n_tags, nutag_substate)->t_value, nua_substate_terminated); TEST_1(e = e->next); TEST_E(e->data->e_event, nua_r_unsubscribe); TEST_1(tl_find(e->data->e_tags, nutag_substate)); TEST(tl_find(e->data->e_tags, nutag_substate)->t_value, nua_substate_terminated); } else { TEST_E(e->data->e_event, nua_r_unsubscribe); TEST_1(tl_find(e->data->e_tags, nutag_substate)); /* NOTIFY is no more dropped after successful response to unsubscribe */ TEST(tl_find(e->data->e_tags, nutag_substate)->t_value, nua_substate_active); TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_notify); TEST_1(sip = sip_object(e->data->e_msg)); n_tags = e->data->e_tags; TEST_1(sip->sip_event); TEST_1(sip->sip_subscription_state); TEST_S(sip->sip_subscription_state->ss_substate, "terminated"); TEST_1(!sip->sip_subscription_state->ss_expires); TEST_1(tl_find(n_tags, nutag_substate)); TEST(tl_find(n_tags, nutag_substate)->t_value, nua_substate_terminated); } TEST_1(!e->next); free_events_in_list(ctx, a->events); /* Server events: nua_i_subscription with terminated status */ TEST_1(e = b->events->head); TEST_E(e->data->e_event, nua_i_subscription); TEST(tl_gets(e->data->e_tags, NEATAG_SUB_REF(sub), NUTAG_SUBSTATE_REF(substate), TAG_END()), 2); TEST_1(sub); TEST(substate, nua_substate_terminated); TEST_1(!e->next); free_events_in_list(ctx, b->events); if (print_headings) printf("TEST NUA-12.5: PASSED\n"); /* ---------------------------------------------------------------------- */ /* Fetch event, SUBSCRIBE with expires: 0 A B | | |------SUBSCRIBE---->| |<--------202--------| |<------NOTIFY-------| |-------200 OK------>| | | */ if (print_headings) printf("TEST NUA-12.5.1: event fetch\n"); SUBSCRIBE(a, a_call, a_call->nh, NUTAG_URL(b->contact->m_url), SIPTAG_EVENT_STR("presence"), SIPTAG_ACCEPT_STR("application/pidf+xml"), SIPTAG_EXPIRES_STR("0"), TAG_END()); run_ab_until(ctx, -1, save_until_notified_and_responded, -1, save_until_subscription); /* Client events: nua_subscribe(), nua_i_notify/nua_r_subscribe */ TEST_1(en = event_by_type(a->events->head, nua_i_notify)); TEST_1(es = event_by_type(a->events->head, nua_r_subscribe)); e = es; TEST_E(e->data->e_event, nua_r_subscribe); TEST_1(t = tl_find(e->data->e_tags, nutag_substate)); TEST_1(t->t_value == nua_substate_pending || t->t_value == nua_substate_terminated || t->t_value == nua_substate_embryonic); e = en; TEST_E(e->data->e_event, nua_i_notify); TEST_1(sip = sip_object(e->data->e_msg)); n_tags = e->data->e_tags; TEST_1(sip->sip_event); TEST_S(sip->sip_event->o_type, "presence"); TEST_1(sip->sip_content_type); TEST_S(sip->sip_content_type->c_type, "application/pidf+xml"); TEST_1(sip->sip_payload && sip->sip_payload->pl_data); TEST_1(sip->sip_subscription_state); TEST_S(sip->sip_subscription_state->ss_substate, "terminated"); TEST_1(tl_find(n_tags, nutag_substate)); TEST(tl_find(n_tags, nutag_substate)->t_value, nua_substate_terminated); TEST_1(!en->next || !es->next); free_events_in_list(ctx, a->events); /* Server events: nua_i_subscription */ TEST_1(e = b->events->head); TEST_E(e->data->e_event, nua_i_subscription); TEST(tl_gets(e->data->e_tags, NEATAG_SUB_REF(sub), TAG_END()), 1); TEST_1(sub); TEST_1(!e->next); free_events_in_list(ctx, b->events); if (print_headings) printf("TEST NUA-12.4.1: PASSED\n"); /* ---------------------------------------------------------------------- */ /* 2nd SUBSCRIBE with event id A B | | |------SUBSCRIBE---->| |<--------202--------| |<------NOTIFY-------| |-------200 OK------>| | | */ /* XXX - we should do this before unsubscribing first one */ if (print_headings) printf("TEST NUA-12.4.2: establishing 2nd subscription\n"); NOTIFIER(b, b_call, b_call->nh, SIPTAG_EVENT_STR("presence"), SIPTAG_CONTENT_TYPE_STR("application/xpidf+xml"), SIPTAG_PAYLOAD_STR(open), NEATAG_THROTTLE(1), NUTAG_SUBSTATE(nua_substate_pending), TAG_END()); run_b_until(ctx, nua_r_notifier, until_final_response); NOTIFIER(b, b_call, b_call->nh, SIPTAG_EVENT_STR("presence"), SIPTAG_CONTENT_TYPE_STR("application/xpidf+xml"), SIPTAG_PAYLOAD_STR(closed), NEATAG_THROTTLE(1), NEATAG_FAKE(1), NUTAG_SUBSTATE(nua_substate_pending), TAG_END()); run_b_until(ctx, nua_r_notifier, until_final_response); SUBSCRIBE(a, a_call, a_call->nh, NUTAG_URL(b->contact->m_url), SIPTAG_EVENT_STR("presence;id=1"), SIPTAG_ACCEPT_STR("application/xpidf+xml"), TAG_END()); run_ab_until(ctx, -1, save_until_notified_and_responded, -1, save_until_subscription); /* Client events: nua_subscribe(), nua_i_notify/nua_r_subscribe */ TEST_1(en = event_by_type(a->events->head, nua_i_notify)); TEST_1(es = event_by_type(a->events->head, nua_r_subscribe)); e = es; TEST_E(e->data->e_event, nua_r_subscribe); TEST_1(t = tl_find(e->data->e_tags, nutag_substate)); TEST_1(t->t_value == nua_substate_pending || t->t_value == nua_substate_embryonic); e = en; TEST_E(e->data->e_event, nua_i_notify); TEST_1(sip = sip_object(e->data->e_msg)); n_tags = e->data->e_tags; TEST_1(sip->sip_event); TEST_S(sip->sip_event->o_type, "presence"); TEST_S(sip->sip_event->o_id, "1"); TEST_1(sip->sip_content_type); TEST_S(sip->sip_content_type->c_type, "application/xpidf+xml"); TEST_1(sip->sip_payload && sip->sip_payload->pl_data); /* Check that we really got "fake" content */ TEST_1(memmem(sip->sip_payload->pl_data, sip->sip_payload->pl_len, "<basic>closed</basic>", strlen("<basic>closed</basic>"))); TEST_1(sip->sip_subscription_state); TEST_S(sip->sip_subscription_state->ss_substate, "pending"); TEST_1(sip->sip_subscription_state->ss_expires); TEST_1(tl_find(n_tags, nutag_substate)); TEST(tl_find(n_tags, nutag_substate)->t_value, nua_substate_pending); TEST_1(!en->next || !es->next); free_events_in_list(ctx, a->events); /* Server events: nua_i_subscription */ TEST_1(e = b->events->head); TEST_E(e->data->e_event, nua_i_subscription); TEST(tl_gets(e->data->e_tags, NEATAG_SUB_REF(sub), TAG_END()), 1); TEST_1(sub); TEST_1(!e->next); free_events_in_list(ctx, b->events); /* Authorize user A */ AUTHORIZE(b, b_call, b_call->nh, NUTAG_SUBSTATE(nua_substate_active), NEATAG_SUB(sub), NEATAG_FAKE(0), TAG_END()); run_ab_until(ctx, -1, save_until_notified, -1, save_until_final_response); /* subscriber events: nua_i_notify with NUTAG_SUBSTATE(nua_substate_active) */ TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_i_notify); TEST_1(sip = sip_object(e->data->e_msg)); TEST_1(sip->sip_event); TEST_S(sip->sip_event->o_type, "presence"); TEST_1(sip->sip_content_type); TEST_S(sip->sip_content_type->c_type, "application/xpidf+xml"); TEST_1(sip->sip_payload && sip->sip_payload->pl_data); /* Check that we really got real content */ TEST_1(memmem(sip->sip_payload->pl_data, sip->sip_payload->pl_len, "<basic>open</basic>", strlen("<basic>open</basic>"))); TEST_1(sip->sip_subscription_state); TEST_S(sip->sip_subscription_state->ss_substate, "active"); TEST_1(sip->sip_subscription_state->ss_expires); n_tags = e->data->e_tags; TEST_1(tl_find(n_tags, nutag_substate)); TEST(tl_find(n_tags, nutag_substate)->t_value, nua_substate_active); TEST_1(!e->next); free_events_in_list(ctx, a->events); /* Server events: nua_r_authorize */ TEST_1(e = b->events->head); TEST_E(e->data->e_event, nua_r_authorize); TEST_1(!e->next); free_events_in_list(ctx, b->events); if (print_headings) printf("TEST NUA-12.4: PASSED\n"); /* ---------------------------------------------------------------------- */ /* NOTIFY terminating subscription A B | | |<------NOTIFY-------| |-------200 OK------>| | | */ if (print_headings) printf("TEST NUA-12.6: terminate notifier\n"); TERMINATE(b, b_call, b_call->nh, TAG_END()); run_ab_until(ctx, -1, save_until_notified, -1, until_final_response); /* Client events: nua_i_notify */ TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_i_notify); TEST_1(sip = sip_object(e->data->e_msg)); TEST_1(sip->sip_event); TEST_S(sip->sip_event->o_type, "presence"); TEST_S(sip->sip_event->o_id, "1"); TEST_1(sip->sip_subscription_state); TEST_S(sip->sip_subscription_state->ss_substate, "terminated"); TEST_1(!sip->sip_subscription_state->ss_expires); n_tags = e->data->e_tags; TEST_1(tl_find(n_tags, nutag_substate)); TEST(tl_find(n_tags, nutag_substate)->t_value, nua_substate_terminated); TEST_1(!e->next); free_events_in_list(ctx, a->events); if (print_headings) printf("TEST NUA-12.6: PASSED\n"); /* ---------------------------------------------------------------------- */ nua_handle_destroy(a_call->nh), a_call->nh = NULL; nua_handle_destroy(b_call->nh), b_call->nh = NULL; END(); /* test_events */ }
static int test_vectors(void) { su_home_t home[1] = { SU_HOME_INIT(home) }; su_vector_t *v, *w; test_data_t *data1, *data2, *data3, *data4; char foo[] = "foo"; char bar[] = "bar"; char baz[] = "baz"; void **a; int i; BEGIN(); TEST_1(v = su_vector_create(home, NULL)); TEST_1(su_vector_is_empty(v)); TEST(su_vector_append(v, foo), 0); TEST(su_vector_append(v, bar), 0); TEST(su_vector_insert(v, 0, baz), 0); TEST_P(su_vector_item(v, 0), baz); TEST_P(su_vector_item(v, 1), foo); TEST_P(su_vector_item(v, 2), bar); TEST_P(su_vector_item(v, 3), NULL); TEST_P(su_vector_item(v, (unsigned)-1), NULL); TEST_1(!su_vector_is_empty(v)); su_vector_destroy(v); TEST_1(v = su_vector_create(home, NULL)); TEST(su_vector_insert(v, 0, "j"), 0); TEST(su_vector_insert(v, 0, "i"), 0); TEST(su_vector_insert(v, 0, "h"), 0); TEST(su_vector_insert(v, 0, "g"), 0); TEST(su_vector_insert(v, 0, "f"), 0); TEST(su_vector_insert(v, 0, "e"), 0); TEST(su_vector_insert(v, 0, "d"), 0); TEST(su_vector_insert(v, 0, "c"), 0); TEST(su_vector_insert(v, 0, "b"), 0); TEST(su_vector_insert(v, 0, "a"), 0); TEST_SIZE(su_vector_len(v), 10); TEST_1(a = su_vector_get_array(v)); for (i = 0; i < 10; i++) { TEST_S(su_vector_item(v, i), a[i]); } TEST_P(su_vector_item(v, 10), NULL); TEST_P(a[10], NULL); TEST_1(w = su_vector_create(home, NULL)); TEST(su_vector_append(w, "a"), 0); TEST(su_vector_append(w, "b"), 0); TEST(su_vector_append(w, "c"), 0); TEST(su_vector_append(w, "d"), 0); TEST(su_vector_append(w, "e"), 0); TEST(su_vector_append(w, "f"), 0); TEST(su_vector_append(w, "g"), 0); TEST(su_vector_append(w, "h"), 0); TEST(su_vector_append(w, "i"), 0); TEST(su_vector_append(w, "j"), 0); TEST_SIZE(su_vector_len(w), 10); for (i = 0; i < 10; i++) { TEST_S(su_vector_item(v, i), a[i]); } su_vector_empty(w); TEST_1(su_vector_is_empty(w)); su_vector_destroy(v); su_vector_destroy(w); TEST_1(v = su_vector_create(home, test_vector_free)); data1 = su_home_clone(home, sizeof(test_data_t)); data1->data = 1; data2 = su_home_clone(home, sizeof(test_data_t)); data2->data = 2; data3 = su_home_clone(home, sizeof(test_data_t)); data3->data = 3; data4 = su_home_clone(home, sizeof(test_data_t)); data4->data = 4; TEST(su_vector_append(v, data1), 0); TEST(su_vector_append(v, data2), 0); TEST(su_vector_append(v, data3), 0); TEST(su_vector_append(v, data4), 0); TEST_SIZE(su_vector_len(v), 4); TEST_P(su_vector_item(v, 0), data1); TEST_P(su_vector_item(v, 1), data2); TEST_P(su_vector_item(v, 2), data3); TEST_P(su_vector_item(v, 3), data4); TEST(data1->data, 1); TEST(data2->data, 2); TEST(data3->data, 3); TEST(data4->data, 4); TEST(su_vector_remove(v, 2), 0); TEST_SIZE(su_vector_len(v), 3); TEST_P(su_vector_item(v, 0), data1); TEST_P(su_vector_item(v, 1), data2); TEST_P(su_vector_item(v, 2), data4); TEST(data1->data, 1); TEST(data2->data, 2); TEST(data4->data, 4); su_vector_destroy(v); su_home_check(home); su_home_deinit(home); END(); }
static int test_strlst(void) { su_home_t home[1] = { SU_HOME_INIT(home) }; su_strlst_t *l, *l1, *l2; char *s; char foo[] = "foo"; char bar[] = "bar"; char baz[] = "baz"; su_home_stat_t parent[1], kids[2]; BEGIN(); parent->hs_size = (sizeof parent); kids[0].hs_size = (sizeof kids[0]); kids[1].hs_size = (sizeof kids[1]); su_home_init_stats(home); /* Test API for invalid arguments */ TEST_1(l = su_strlst_create(NULL)); TEST_1(l2 = su_strlst_dup(home, l)); TEST_VOID(su_strlst_destroy(l2)); TEST_1(!su_strlst_dup(home, NULL)); TEST_1(l1 = su_strlst_copy(home, l)); TEST_VOID(su_strlst_destroy(l1)); TEST_1(!su_strlst_copy(home, NULL)); TEST_VOID(su_strlst_destroy(NULL)); TEST_VOID(su_strlst_destroy(l)); TEST_1(!su_strlst_dup_append(NULL, "aa")); TEST_1(!su_strlst_append(NULL, "bee")); TEST_1(!su_strlst_item(NULL, 1)); TEST_1(!su_strlst_set_item(NULL, 1, "cee")); TEST_1(!su_strlst_remove(NULL, 1)); TEST_S(s = su_strlst_join(NULL, home, "a"), ""); TEST_VOID(su_free(home, s)); TEST_1(!su_strlst_split(home, NULL, ".")); TEST_1(s = su_strdup(home, "aaa")); TEST_1(l = su_strlst_split(home, s, NULL)); TEST_S(su_strlst_item(l, 0), "aaa"); TEST_VOID(su_strlst_destroy(l)); TEST_VOID(su_free(home, s)); TEST_1(!su_strlst_dup_split(home, NULL, ".")); TEST_1(l1 = su_strlst_dup_split(home, "aaa", "")); TEST_S(su_strlst_item(l1, 0), "aaa"); TEST_VOID(su_strlst_destroy(l1)); TEST_SIZE(su_strlst_len(NULL), 0); TEST_1(!su_strlst_get_array(NULL)); TEST_VOID(su_strlst_free_array(NULL, NULL)); TEST_1(l = su_strlst_create(home)); TEST_VOID(su_strlst_free_array(l, NULL)); TEST_S(su_strlst_dup_append(l, "oh"), "oh"); TEST_VOID(su_strlst_free_array(l, NULL)); TEST_VOID(su_strlst_destroy(l)); /* Test functionality */ TEST_1(l = su_strlst_create(home)); su_home_init_stats(su_strlst_home(l)); TEST_S(su_strlst_join(l, home, "bar"), ""); TEST_S(su_strlst_append(l, foo), "foo"); TEST_S(su_strlst_dup_append(l, bar), "bar"); TEST_S(su_strlst_append(l, baz), "baz"); TEST_S((s = su_strlst_join(l, home, "!")), "foo!bar!baz"); TEST_S(su_strlst_item(l, 0), foo); TEST_S(su_strlst_item(l, 1), bar); TEST_S(su_strlst_item(l, 2), baz); TEST_P(su_strlst_item(l, 3), NULL); TEST_P(su_strlst_item(l, (unsigned)-1), NULL); TEST_1(l1 = su_strlst_copy(su_strlst_home(l), l)); TEST_1(l2 = su_strlst_dup(su_strlst_home(l), l)); strcpy(foo, "hum"); strcpy(bar, "pah"); strcpy(baz, "hah"); TEST_S(su_strlst_dup_append(l1, "kuik"), "kuik"); TEST_S(su_strlst_dup_append(l2, "uik"), "uik"); TEST_S((s = su_strlst_join(l, home, ".")), "hum.bar.hah"); TEST_S((su_strlst_join(l1, home, ".")), "hum.bar.hah.kuik"); TEST_S((su_strlst_join(l2, home, ".")), "foo.bar.baz.uik"); su_strlst_destroy(l2); su_home_get_stats(su_strlst_home(l), 0, kids, sizeof kids); TEST_SIZE(kids->hs_clones, 2); TEST64(kids->hs_allocs.hsa_number, 3); TEST64(kids->hs_frees.hsf_number, 1); su_strlst_destroy(l); TEST_S(s, "hum.bar.hah"); TEST_1(l = su_strlst_create(home)); su_home_init_stats(su_strlst_home(l)); TEST_S(su_strlst_join(l, home, "bar"), ""); TEST_S(su_strlst_append(l, "a"), "a"); TEST_S(su_strlst_append(l, "b"), "b"); TEST_S(su_strlst_append(l, "c"), "c"); TEST_S(su_strlst_append(l, "d"), "d"); TEST_S(su_strlst_append(l, "e"), "e"); TEST_S(su_strlst_append(l, "f"), "f"); TEST_S(su_strlst_append(l, "g"), "g"); TEST_S(su_strlst_append(l, "h"), "h"); TEST_S(su_strlst_append(l, "i"), "i"); TEST_S(su_strlst_append(l, "j"), "j"); TEST_S((s = su_strlst_join(l, home, "")), "abcdefghij"); TEST_S(su_strlst_append(l, "a"), "a"); TEST_S(su_strlst_append(l, "b"), "b"); TEST_S(su_strlst_append(l, "c"), "c"); TEST_S(su_strlst_append(l, "d"), "d"); TEST_S(su_strlst_append(l, "e"), "e"); TEST_S(su_strlst_append(l, "f"), "f"); TEST_S(su_strlst_append(l, "g"), "g"); TEST_S(su_strlst_append(l, "h"), "h"); TEST_S(su_strlst_append(l, "i"), "i"); TEST_S(su_strlst_append(l, "j"), "j"); TEST_S((s = su_strlst_join(l, home, "")), "abcdefghijabcdefghij"); su_home_get_stats(su_strlst_home(l), 0, kids + 1, (sizeof kids[1])); su_home_stat_add(kids, kids + 1); su_strlst_destroy(l); su_home_get_stats(home, 1, parent, (sizeof parent)); su_home_check(home); su_home_deinit(home); su_home_init(home); { char s[] = "foo\nfaa\n"; TEST_1((l = su_strlst_split(home, s, "\n"))); TEST_SIZE(su_strlst_len(l), 3); TEST_1(su_strlst_append(l, "bar")); TEST_S(su_strlst_join(l, home, "\n"), "foo\nfaa\n\nbar"); } { char s[] = "foo"; TEST_1((l = su_strlst_split(home, s, "\n"))); TEST_SIZE(su_strlst_len(l), 1); } { char s[] = "\n\n"; TEST_1((l = su_strlst_split(home, s, "\n"))); TEST_SIZE(su_strlst_len(l), 3); } { char s[] = ""; TEST_1((l = su_strlst_split(home, s, "\n"))); TEST_SIZE(su_strlst_len(l), 1); } { int i; #define S \ "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\n" \ "n\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz\n" \ "A\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\n" \ "N\nO\nP\nQ\nR\nS\nT\nU\nV\nW\nX\nY\nZ\n" char s[] = S; TEST_1((l = su_strlst_split(home, s, "\n"))); TEST_SIZE(su_strlst_len(l), 53); TEST_1(su_strlst_append(l, "bar")); TEST_S(su_strlst_join(l, home, "\n"), S "\nbar"); TEST_1(!su_strlst_remove(l, 54)); for (i = 0; i < 54; i++) { TEST_1(su_strlst_remove(l, 0)); TEST_1(!su_strlst_remove(l, 53 - i)); TEST_SIZE(su_strlst_len(l), 53 - i); } TEST_1(!su_strlst_remove(l, 0)); TEST_SIZE(su_strlst_len(l), 0); } { char const *s0; TEST_1(l = su_strlst_create_with(NULL, s0 = "a", "b", NULL)); TEST_1(su_strlst_item(l, 0) == s0); TEST_S(su_strlst_item(l, 0), "a"); TEST_S(su_strlst_item(l, 1), "b"); TEST_1(su_strlst_item(l, 2) == NULL); TEST_S(su_slprintf(l, "1: %u", 1), "1: 1"); TEST_S(su_slprintf(l, "1.0: %g", 1.0), "1.0: 1"); TEST_1(su_strlst_append(l, "")); TEST_S(su_strlst_join(l, home, "\n"), "a\n" "b\n" "1: 1\n" "1.0: 1\n"); TEST_VOID(su_strlst_destroy(l)); TEST_1(l2 = su_strlst_create_with_dup(NULL, s0 = "0", "1", "2", "3", "4", "5", "6", "7", NULL)); TEST_1(su_strlst_item(l2, 0) != s0); TEST_S(su_strlst_item(l2, 0), "0"); TEST_S(su_strlst_item(l2, 1), "1"); TEST_S(su_strlst_item(l2, 2), "2"); TEST_S(su_strlst_item(l2, 3), "3"); TEST_S(su_strlst_item(l2, 4), "4"); TEST_S(su_strlst_item(l2, 5), "5"); TEST_S(su_strlst_item(l2, 6), "6"); TEST_S(su_strlst_item(l2, 7), "7"); TEST_1(su_strlst_item(l2, 8) == NULL); TEST_S(su_strlst_join(l2, home, ""), "01234567"); TEST_VOID(su_strlst_destroy(l2)); } su_home_check(home); su_home_deinit(home); END(); }
/* test unquoting and canonizing */ int test_quote(void) { su_home_t home[1] = { SU_HOME_INIT(home) }; url_t *u; char s[] = "%73ip:q%74est%01:%01%02%00@host%2enokia.com;%70aram=%01%02"; char c[] = "sip:qtest%01:%01%02%[email protected];param=%01%02"; char *d; #define RESERVED ";/?:@&=+$," #define DELIMS "<>#%\"" #define UNWISE "{}|\\^[]`" #define EXCLUDED RESERVED DELIMS UNWISE char escaped[1 + 3 * 23 + 1]; #define UNRESERVED "ABCDEFGHIJKLMNOPQRSTUVWXYZ" \ "abcdefghijklmnopqrstuvwxyz" \ "0123456789" \ "-_.!~*'()" char unreserved[26 + 26 + 10 + 9 + 1]; BEGIN(); d = url_as_string(home, (url_t *)"sip:[email protected]"); TEST_S(d, "sip:[email protected]"); TEST(strlen(EXCLUDED), 23); TEST(strlen(UNRESERVED), 71); TEST_1(!url_reserved_p("foo")); TEST_1(!url_reserved_p("")); TEST_1(url_reserved_p("foobar:bar")); TEST_SIZE(url_esclen("a" EXCLUDED, ""), 1 + strlen(RESERVED) + 3 * strlen(DELIMS UNWISE)); TEST_SIZE(url_esclen("a" EXCLUDED, DELIMS UNWISE), 1 + strlen(RESERVED) + 3 * strlen(DELIMS UNWISE)); TEST_SIZE(url_esclen("a" EXCLUDED, EXCLUDED), 1 + 3 * strlen(EXCLUDED)); TEST_SIZE(url_esclen("a" EXCLUDED, NULL), 1 + 3 * strlen(EXCLUDED)); TEST_S(url_escape(escaped, "a" EXCLUDED, NULL), "a%3B%2F%3F%3A%40%26%3D%2B%24%2C" "%3C%3E%23%25%22" "%7B%7D%7C%5C%5E%5B%5D%60"); TEST_S(url_unescape(escaped, escaped), "a" EXCLUDED); TEST_SIZE(url_esclen(UNRESERVED, NULL), strlen(UNRESERVED)); TEST_S(url_escape(unreserved, UNRESERVED, NULL), UNRESERVED); TEST_S(url_unescape(unreserved, UNRESERVED), UNRESERVED); d = "%53ip:%75@%48"; /* Sip:u@H */ u = url_hdup(home, (url_t *)d); TEST_1(u); url_digest(hash1, sizeof(hash1), u, NULL); url_digest(hash2, sizeof(hash2), (url_t const *)d, NULL); TEST(memcmp(hash1, hash2, sizeof(hash1)), 0); d = "sip:u@h"; u = url_hdup(home, (url_t *)d); TEST_1(u); url_digest(hash1, sizeof(hash1), u, NULL); TEST(memcmp(hash1, hash2, sizeof(hash1)), 0); url_digest(hash2, sizeof(hash2), (url_t const *)d, NULL); TEST(memcmp(hash1, hash2, sizeof(hash1)), 0); u = url_hdup(home, (url_t *)s); TEST_1(u); d = url_as_string(home, u); TEST_1(d); TEST_S(d, c); d = "sip:&=+$,;?/:&=+$,@[::1]:56001;param=+$,/:@&;another=@%40%2F" "?header=" RESERVED "&%3b%2f%3f%3a%40%26%3d%2b%24%2c"; u = url_hdup(home, (url_t *)d); TEST_1(u); TEST_S(u->url_user, "&=+$,;?/"); TEST_S(u->url_host, "[::1]"); TEST_S(u->url_params, "param=+$,/:@&;another=@%40/"); TEST_S(u->url_headers, "header=" RESERVED "&%3B%2F%3F%3A%40%26%3D%2B%24%2C"); url_digest(hash1, sizeof(hash1), u, NULL); url_digest(hash2, sizeof(hash2), (url_t const *)d, NULL); TEST(memcmp(hash1, hash2, sizeof(hash1)), 0); u = url_hdup(home, (url_t *)s); TEST_1(u); d = url_as_string(home, u); TEST_1(d); TEST_S(d, c); d = "http://&=+$,;:&=+$,;@host:8080/foo%2F%3B%3D" ";param=+$,%2f%3b%3d/bar;param=:@&;another=@" "?query=" RESERVED; u = url_hdup(home, (url_t *)d); TEST_1(u); TEST_S(u->url_user, "&=+$,;"); TEST_S(u->url_password, "&=+$,;"); TEST_S(u->url_path, "foo%2F%3B%3D;param=+$,%2F%3B%3D/bar;param=:@&;another=@"); url_digest(hash1, sizeof(hash1), u, NULL); url_digest(hash2, sizeof(hash2), (url_t const *)d, NULL); TEST(memcmp(hash1, hash2, sizeof(hash1)), 0); u = url_hdup(home, (url_t *)s); TEST_1(u); d = url_as_string(home, u); TEST_1(d); TEST_S(d, c); url_digest(hash1, sizeof(hash1), u, NULL); url_digest(hash2, sizeof(hash2), (url_t const *)s, NULL); TEST(memcmp(hash1, hash2, sizeof(hash1)), 0); url_digest(hash2, sizeof(hash2), (url_t const *)c, NULL); TEST(memcmp(hash1, hash2, sizeof(hash1)), 0); END(); }
int main(void) { int i, x, y; double u; char a[100], b[100]; FILE *f; TEST(i, !!(f=writetemp(" 42")), 1, "failed to make temp file"); if (f) { x=y=-1; TEST(i, fwscanf(f, L" %n%*d%n", &x, &y), 0, "%d != %d"); TEST(i, x, 6, "%d != %d"); TEST(i, y, 8, "%d != %d"); TEST(i, ftell(f), 8, "%d != %d"); TEST(i, !!feof(f), 1, "%d != %d"); fclose(f); } TEST(i, !!(f=writetemp("[abc123]....x")), 1, "failed to make temp file"); if (f) { x=y=-1; TEST(i, fwscanf(f, L"%10[^]]%n%10[].]%n", a, &x, b, &y), 2, "%d != %d"); TEST_S(a, "[abc123", "wrong result for %[^]]"); TEST_S(b, "]....", "wrong result for %[].]"); TEST(i, x, 7, "%d != %d"); TEST(i, y, 12, "%d != %d"); TEST(i, ftell(f), 12, "%d != %d"); TEST(i, feof(f), 0, "%d != %d"); TEST(i, fgetc(f), 'x', "%d != %d"); fclose(f); } TEST(i, !!(f=writetemp("0x1p 12")), 1, "failed to make temp file"); if (f) { x=y=-1; u=-1; TEST(i, fwscanf(f, L"%lf%n %d", &u, &x, &y), 0, "%d != %d"); TEST(u, u, -1.0, "%g != %g"); TEST(i, x, -1, "%d != %d"); TEST(i, y, -1, "%d != %d"); TEST(i, ftell(f), 4, "%d != %d"); TEST(i, feof(f), 0, "%d != %d"); TEST(i, fgetc(f), ' ', "%d != %d"); rewind(f); TEST(i, fgetc(f), '0', "%d != %d"); TEST(i, fgetc(f), 'x', "%d != %d"); TEST(i, fwscanf(f, L"%lf%n%c %d", &u, &x, a, &y), 3, "%d != %d"); TEST(u, u, 1.0, "%g != %g"); TEST(i, x, 1, "%d != %d"); TEST(i, a[0], 'p', "%d != %d"); TEST(i, y, 12, "%d != %d"); TEST(i, ftell(f), 7, "%d != %d"); TEST(i, !!feof(f), 1, "%d != %d"); fclose(f); } TEST(i, !!(f=writetemp("0x.1p4 012")), 1, "failed to make temp file"); if (f) { x=y=-1; u=-1; TEST(i, fwscanf(f, L"%lf%n %i", &u, &x, &y), 2, "%d != %d"); TEST(u, u, 1.0, "%g != %g"); TEST(i, x, 6, "%d != %d"); TEST(i, y, 10, "%d != %d"); TEST(i, ftell(f), 13, "%d != %d"); TEST(i, !!feof(f), 1, "%d != %d"); fclose(f); } TEST(i, !!(f=writetemp("0xx")), 1, "failed to make temp file"); if (f) { x=y=-1; TEST(i, fwscanf(f, L"%x%n", &x, &y), 0, "%d != %d"); TEST(i, x, -1, "%d != %d"); TEST(i, y, -1, "%d != %d"); TEST(i, ftell(f), 2, "%d != %d"); TEST(i, feof(f), 0, "%d != %d"); fclose(f); } return t_status; }
int test_md5(void) { BEGIN(); su_md5_t md5[1], md5i[1]; uint8_t digest[SU_MD5_DIGEST_SIZE]; char hexdigest[2 * SU_MD5_DIGEST_SIZE + 1]; struct { char *input; uint8_t digest[SU_MD5_DIGEST_SIZE]; } suite[] = { { (""), { 0xd4, 0x1d, 0x8c, 0xd9, 0x8f, 0x00, 0xb2, 0x04, 0xe9, 0x80, 0x09, 0x98, 0xec, 0xf8, 0x42, 0x7e } }, { ("a"), { 0x0c, 0xc1, 0x75, 0xb9, 0xc0, 0xf1, 0xb6, 0xa8, 0x31, 0xc3, 0x99, 0xe2, 0x69, 0x77, 0x26, 0x61 } }, { ("abc"), { 0x90, 0x01, 0x50, 0x98, 0x3c, 0xd2, 0x4f, 0xb0, 0xd6, 0x96, 0x3f, 0x7d, 0x28, 0xe1, 0x7f, 0x72 } }, { ("message digest"), { 0xf9, 0x6b, 0x69, 0x7d, 0x7c, 0xb7, 0x93, 0x8d, 0x52, 0x5a, 0x2f, 0x31, 0xaa, 0xf1, 0x61, 0xd0 } }, { ("abcdefghijklmnopqrstuvwxyz"), { 0xc3, 0xfc, 0xd3, 0xd7, 0x61, 0x92, 0xe4, 0x00, 0x7d, 0xfb, 0x49, 0x6c, 0xca, 0x67, 0xe1, 0x3b } }, { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", { 0xd1, 0x74, 0xab, 0x98, 0xd2, 0x77, 0xd9, 0xf5, 0xa5, 0x61, 0x1c, 0x2c, 0x9f, 0x41, 0x9d, 0x9f } }, { "1234567890123456789012345678901234567890" "1234567890123456789012345678901234567890", { 0x57, 0xed, 0xf4, 0xa2, 0x2b, 0xe3, 0xc9, 0x55, 0xac, 0x49, 0xda, 0x2e, 0x21, 0x07, 0xb6, 0x7a } }}; su_md5_init(md5); su_md5_update(md5, suite[0].input, 0); su_md5_digest(md5, digest); TEST_M(digest, suite[0].digest, SU_MD5_DIGEST_SIZE); su_md5_deinit(md5); su_md5_init(md5); su_md5_strupdate(md5, suite[1].input); su_md5_digest(md5, digest); TEST_M(digest, suite[1].digest, SU_MD5_DIGEST_SIZE); su_md5_deinit(md5); su_md5_init(md5); su_md5_iupdate(md5, suite[2].input, 3); su_md5_digest(md5, digest); TEST_M(digest, suite[2].digest, SU_MD5_DIGEST_SIZE); su_md5_deinit(md5); su_md5_init(md5); su_md5_striupdate(md5, suite[3].input); su_md5_digest(md5, digest); TEST_M(digest, suite[3].digest, SU_MD5_DIGEST_SIZE); su_md5_deinit(md5); su_md5_init(md5); su_md5_iupdate(md5, suite[4].input, 13); su_md5_striupdate(md5, suite[4].input + 13); su_md5_digest(md5, digest); TEST_M(digest, suite[4].digest, SU_MD5_DIGEST_SIZE); su_md5_deinit(md5); su_md5_init(md5); su_md5_update(md5, suite[5].input, 13); su_md5_strupdate(md5, suite[5].input + 13); su_md5_digest(md5, digest); TEST_M(digest, suite[5].digest, SU_MD5_DIGEST_SIZE); su_md5_deinit(md5); su_md5_init(md5); su_md5_update(md5, suite[6].input, 13); su_md5_strupdate(md5, suite[6].input + 13); su_md5_digest(md5, digest); TEST_M(digest, suite[6].digest, SU_MD5_DIGEST_SIZE); su_md5_deinit(md5); su_md5_init(md5); su_md5_str0update(md5, NULL); su_md5_hexdigest(md5, hexdigest); TEST_S(hexdigest, "93b885adfe0da089cdf634904fd59f71"); su_md5_deinit(md5); su_md5_init(md5); su_md5_stri0update(md5, NULL); su_md5_stri0update(md5, "ABBADABBADOO"); su_md5_hexdigest(md5, hexdigest); TEST_S(hexdigest, "101e6dd7cfabdb5c74f44b4c545c05cc"); su_md5_init(md5); su_md5_update(md5, "\0abbadabbadoo\0", 14); su_md5_hexdigest(md5, hexdigest); TEST_S(hexdigest, "101e6dd7cfabdb5c74f44b4c545c05cc"); su_md5_deinit(md5); /* Calculate md5 sum of 512 MB of zero */ if (getenv("EXPENSIVE_CHECKS")) { char zerokilo[1024] = { '\0' }; int i; su_md5_init(md5); su_md5_iupdate(md5, zerokilo, 19); for (i = 1; i < 512 * 1024; i++) su_md5_update(md5, zerokilo, 1024); *md5i = *md5; su_md5_update(md5, zerokilo, 1024 - 19); su_md5_hexdigest(md5, hexdigest); TEST_S(hexdigest, "aa559b4e3523a6c931f08f4df52d58f2"); su_md5_deinit(md5); su_md5_iupdate(md5i, zerokilo, 1024 - 19); su_md5_hexdigest(md5i, hexdigest); TEST_S(hexdigest, "aa559b4e3523a6c931f08f4df52d58f2"); } END(); }
int main(void) { char b[32]; char *s; int i; b[16]='a'; b[17]='b'; b[18]='c'; b[19]=0; TEST(s, strcpy(b, b+16), b, "wrong return %p != %p"); TEST_S(s, "abc", "strcpy gave incorrect string"); TEST(s, strcpy(b+1, b+16), b+1, "wrong return %p != %p"); TEST_S(s, "abc", "strcpy gave incorrect string"); TEST(s, strcpy(b+2, b+16), b+2, "wrong return %p != %p"); TEST_S(s, "abc", "strcpy gave incorrect string"); TEST(s, strcpy(b+3, b+16), b+3, "wrong return %p != %p"); TEST_S(s, "abc", "strcpy gave incorrect string"); TEST(s, strcpy(b+1, b+17), b+1, "wrong return %p != %p"); TEST_S(s, "bc", "strcpy gave incorrect string"); TEST(s, strcpy(b+2, b+18), b+2, "wrong return %p != %p"); TEST_S(s, "c", "strcpy gave incorrect string"); TEST(s, strcpy(b+3, b+19), b+3, "wrong return %p != %p"); TEST_S(s, "", "strcpy gave incorrect string"); TEST(s, memset(b, 'x', sizeof b), b, "wrong return %p != %p"); TEST(s, strncpy(b, "abc", sizeof b - 1), b, "wrong return %p != %p"); TEST(i, memcmp(b, "abc\0\0\0\0", 8), 0, "strncpy fails to zero-pad dest"); TEST(i, b[sizeof b - 1], 'x', "strncpy overruns buffer when n > strlen(src)"); b[3] = 'x'; b[4] = 0; strncpy(b, "abc", 3); TEST(i, b[2], 'c', "strncpy fails to copy last byte: %hhu != %hhu"); TEST(i, b[3], 'x', "strncpy overruns buffer to null-terminate: %hhu != %hhu"); TEST(i, !strncmp("abcd", "abce", 3), 1, "strncmp compares past n"); TEST(i, !!strncmp("abc", "abd", 3), 1, "strncmp fails to compare n-1st byte"); strcpy(b, "abc"); TEST(s, strncat(b, "123456", 3), b, "%p != %p"); TEST(i, b[6], 0, "strncat failed to null-terminate (%d)"); TEST_S(s, "abc123", "strncat gave incorrect string"); strcpy(b, "aaababccdd0001122223"); TEST(s, strchr(b, 'b'), b+3, "%p != %p"); TEST(s, strrchr(b, 'b'), b+5, "%p != %p"); TEST(i, strspn(b, "abcd"), 10, "%d != %d"); TEST(i, strcspn(b, "0123"), 10, "%d != %d"); TEST(s, strpbrk(b, "0123"), b+10, "%d != %d"); strcpy(b, "abc 123; xyz; foo"); TEST(s, strtok(b, " "), b, "%p != %p"); TEST_S(s, "abc", "strtok result"); TEST(s, strtok(NULL, ";"), b+4, "%p != %p"); TEST_S(s, " 123", "strtok result"); TEST(s, strtok(NULL, " ;"), b+11, "%p != %p"); TEST_S(s, "xyz", "strtok result"); TEST(s, strtok(NULL, " ;"), b+16, "%p != %p"); TEST_S(s, "foo", "strtok result"); memset(b, 'x', sizeof b); TEST(i, strlcpy(b, "abc", sizeof b - 1), 3, "length %d != %d"); TEST(i, b[3], 0, "strlcpy did not null-terminate short string (%d)"); TEST(i, b[4], 'x', "strlcpy wrote extra bytes (%d)"); memset(b, 'x', sizeof b); TEST(i, strlcpy(b, "abc", 2), 3, "length %d != %d"); TEST(i, b[0], 'a', "strlcpy did not copy character %d"); TEST(i, b[1], 0, "strlcpy did not null-terminate long string (%d)"); memset(b, 'x', sizeof b); TEST(i, strlcpy(b, "abc", 3), 3, "length %d != %d"); TEST(i, b[2], 0, "strlcpy did not null-terminate l-length string (%d)"); TEST(i, strlcpy(NULL, "abc", 0), 3, "length %d != %d"); memcpy(b, "abc\0\0\0x\0", 8); TEST(i, strlcat(b, "123", sizeof b), 6, "length %d != %d"); TEST_S(b, "abc123", "strlcat result"); memcpy(b, "abc\0\0\0x\0", 8); TEST(i, strlcat(b, "123", 6), 6, "length %d != %d"); TEST_S(b, "abc12", "strlcat result"); TEST(i, b[6], 'x', "strlcat wrote past string %d != %d"); memcpy(b, "abc\0\0\0x\0", 8); TEST(i, strlcat(b, "123", 4), 6, "length %d != %d"); TEST_S(b, "abc", "strlcat result"); memcpy(b, "abc\0\0\0x\0", 8); TEST(i, strlcat(b, "123", 3), 6, "length %d != %d"); TEST_S(b, "abc", "strlcat result"); return t_status; }
int test_sip(void) { /* sip urls */ su_home_t home[1] = { SU_HOME_INIT(home) }; url_t sip[1] = { URL_INIT_AS(sip) }; url_t *u, url[1]; char *tst, *s; char sipurl0[] = "sip:pekka%2Epessi@nokia%2Ecom;method=%4D%45%53%53%41%47%45" "?body=CANNED%20MSG"; char sipurl[] = "sip:user:pass@host:32;param=1" "?From=foo@bar&To=bar@baz#unf"; char sip2url[] = "sip:user/path;tel-param:pass@host:32;param=1%3d%3d1" "?From=foo@bar&body=CANNED%20MSG&To=bar@baz#unf"; char sip2[sizeof(sipurl) + 32]; char sipsurl[] = "sips:user:pass@host:32;param=1" "?From=foo@bar&To=bar@baz#unf"; size_t i, j; url_t *a, *b; BEGIN(); TEST_S(url_scheme(url_sip), "sip"); TEST_S(url_scheme(url_sips), "sips"); memset(url, 255, sizeof url); TEST(url_d(url, sipurl0), 0); TEST(url->url_type, url_sip); TEST(url->url_root, 0); TEST_S(url->url_scheme, "sip"); TEST_S(url->url_user, "pekka.pessi"); TEST_P(url->url_password, NULL); TEST_S(url->url_host, "nokia.com"); TEST_P(url->url_port, NULL); TEST_P(url->url_path, NULL); TEST_S(url->url_params, "method=MESSAGE"); TEST_S(url->url_headers, "body=CANNED%20MSG"); TEST_P(url->url_fragment, NULL); TEST_S(url_query_as_header_string(home, url->url_headers), "\n\nCANNED MSG"); sip->url_user = "******"; sip->url_password = "******"; sip->url_host = "host"; sip->url_port = "32"; sip->url_params = "param=1"; sip->url_headers = "From=foo@bar&To=bar@baz"; sip->url_fragment = "unf"; memset(url, 255, sizeof url); TEST_1(tst = su_strdup(home, sipurl)); TEST_1(url_d(url, tst) == 0); TEST_1(url_cmp(sip, url) == 0); TEST(url->url_type, url_sip); TEST_1(u = url_hdup(home, url)); TEST(u->url_type, url_sip); TEST_1(url_cmp(sip, u) == 0); TEST(url_e(sip2, sizeof(sip2), u), strlen(sipurl)); TEST_1(strcmp(sip2, sipurl) == 0); TEST_SIZE(snprintf(sip2, sizeof(sip2), URL_PRINT_FORMAT, URL_PRINT_ARGS(sip)), strlen(sipurl)); TEST_1(strcmp(sip2, sipurl) == 0); url_digest(hash1, sizeof(hash1), url, NULL); url_digest(hash2, sizeof(hash2), (url_t const *)sipurl, NULL); TEST(memcmp(hash1, hash2, sizeof(hash1)), 0); TEST_1(tst = su_strdup(home, sip2url)); TEST_1(url_d(url, tst) == 0); TEST_S(url->url_user, "user/path;tel-param"); TEST_S(url->url_params, "param=1%3D%3D1"); TEST_S(url_query_as_header_string(home, url->url_headers), "From:foo@bar\nTo:bar@baz\n\nCANNED MSG"); url_digest(hash1, sizeof(hash1), url, NULL); url_digest(hash2, sizeof(hash2), (url_t *)sip2url, NULL); TEST(memcmp(hash1, hash2, sizeof(hash1)), 0); sip->url_type = url_sips; sip->url_scheme = "sips"; TEST_1(tst = su_strdup(home, sipsurl)); TEST_1(url_d(url, tst) == 0); TEST_1(url_cmp(sip, url) == 0); TEST(url->url_type, url_sips); /* Test url_dup() */ for (i = 0; i <= sizeof(sipsurl); i++) { char buf[sizeof(sipsurl) + 1]; url_t dst[1]; buf[i] = '\377'; TEST_SIZE(url_dup(buf, i, dst, url), sizeof(sipsurl) - 1 - strlen("sips")); TEST(buf[i], '\377'); } url_digest(hash1, sizeof(hash1), url, NULL); url_digest(hash2, sizeof(hash2), (url_t *)sipsurl, NULL); TEST(memcmp(hash1, hash2, sizeof(hash1)), 0); u = url_hdup(home, (url_t*)"SIP:[email protected]:55"); TEST_1(u); TEST(u->url_type, url_sip); u = url_hdup(home, (url_t*)"SIP:[email protected]:"); TEST_1(u); TEST(u->url_type, url_sip); TEST_P(url_hdup(home, (url_t*)"sip:[email protected]::55"), NULL); TEST_P(url_hdup(home, (url_t*)"sip:[email protected]:55:"), NULL); TEST_P(url_hdup(home, (url_t*)"sip:[email protected]:sip"), NULL); u = url_hdup(home, (url_t*)"SIP:#**00**#;foo=/[email protected]"); TEST_1(u); TEST(u->url_type, url_sip); TEST_S(u->url_user, "#**00**#;foo=/bar"); TEST_1(!url_hdup(home, (url_t*)"SIP:#**00**#;foo=/bar@#127.0.0.1")); TEST_1(!url_hdup(home, (url_t*)"SIP:#**00**#;foo=/bar;127.0.0.1")); for (i = 32; i <= 256; i++) { char pu[512]; char param[512]; for (j = 0; j < i; j++) param[j] = 'x'; param[j] = '\0'; memcpy(param, "x=", 2); snprintf(pu, sizeof(pu), "sip:test@host;%s", param); u = url_hdup(home, (url_t*)pu); TEST_1(u); s = url_as_string(home, u); TEST_S(pu, s); } s = su_strdup(home, "ttl;transport=tcp;ttl=15;ttl=;method=INVITE;ttl"); TEST_1(s); s = url_strip_param_string(s, "ttl"); TEST_S(s, "transport=tcp;method=INVITE"); u = url_hdup(home, (void*)"sip:u:p@host:5060;maddr=127.0.0.1;transport=tcp"); TEST_1(u); TEST_1(url_have_transport(u)); TEST_1(url_strip_transport(u)); TEST_P(u->url_params, NULL); TEST_1(!url_have_transport(u)); u = url_hdup(home, (void*)"sip:u:p@host:5060;user=phone;ttl=1;isfocus"); TEST_1(u); TEST_1(url_have_transport(u)); TEST_1(url_strip_transport(u)); TEST_S(u->url_params, "user=phone;isfocus"); TEST_1(!url_have_transport(u)); u = url_hdup(home, (void*)"sip:u:p@host:5060;maddr=127.0.0.1;user=phone"); TEST_1(u); TEST_1(url_have_transport(u)); TEST_1(url_strip_transport(u)); TEST_S(u->url_params, "user=phone"); TEST_1(!url_have_transport(u)); u = url_hdup(home, (void*)"sip:u:p@host:5060;user=phone;transport=tcp"); TEST_1(u); TEST_1(url_have_transport(u)); TEST_1(url_strip_transport(u)); TEST_S(u->url_params, "user=phone"); TEST_1(!url_have_transport(u)); u = url_hdup(home, (void*)"sip:u:p@host;user=phone;;"); TEST_1(u); /* We don't have transport params */ TEST_1(!url_have_transport(u)); /* ...but we still strip empty params */ TEST_1(url_strip_transport(u)); TEST_S(u->url_params, "user=phone"); TEST_1(!url_have_transport(u)); u = url_hdup(home, (void*)"sip:u:p@host:5060;ttl=1;isfocus;transport=udp;"); TEST_1(u); TEST_1(url_have_transport(u)); TEST_1(url_strip_transport(u)); TEST_S(u->url_params, "isfocus"); TEST_1(!url_have_transport(u)); u = url_hdup(home, (void *)"sip:%22foo%[email protected]:5060"); TEST_1(u); TEST_S(u->url_user, "%22foo%22"); a = url_hdup(home, (void *)"sip:172.21.55.55:5060"); b = url_hdup(home, (void *)"sip:172.21.55.55"); TEST_1(a); TEST_1(b); TEST_1(url_cmp(a, b) == 0); TEST(url_cmp_all(a, b), 0); a = url_hdup(home, (void *)"sips:172.21.55.55:5060"); b = url_hdup(home, (void *)"sips:172.21.55.55"); TEST_1(a); TEST_1(b); TEST_1(url_cmp(a, b) != 0); TEST_1(url_cmp_all(a, b) < 0); a = url_hdup(home, (void *)"sips:172.21.55.55:5061"); b = url_hdup(home, (void *)"sips:172.21.55.55"); TEST_1(a); TEST_1(b); TEST_1(url_cmp(a, b) == 0); TEST(url_cmp_all(a, b), 0); a = url_hdup(home, (void *)"sip:my.domain:5060"); b = url_hdup(home, (void *)"sip:my.domain"); TEST_1(a); TEST_1(b); TEST_1(url_cmp(a, b) > 0); TEST_1(url_cmp_all(a, b) > 0); a = url_hdup(home, (void *)"sips:my.domain:5061"); b = url_hdup(home, (void *)"sips:my.domain"); TEST_1(a); TEST_1(b); TEST_1(url_cmp(a, b) > 0); TEST_1(url_cmp_all(a, b) > 0); a = url_hdup(home, (void *)"sip:my.domain"); b = url_hdup(home, (void *)"SIP:MY.DOMAIN"); TEST_1(a); TEST_1(b); TEST_1(url_cmp(a, b) == 0); TEST_1(url_cmp_all(a, b) == 0); su_home_deinit(home); END(); }
int test_http(void) { /* http urls */ su_home_t home[1] = { SU_HOME_INIT(home) }; url_t http[1] = { URL_INIT_AS(http) }; url_t *u, url[1]; char *tst; char httpurl[] = "http://*****:*****@host:32/foo;param=1/bar;param=3" "?From=foo@bar&To=bar@baz#unf"; char http2[sizeof(httpurl) + 32]; char queryonly[] = "http://some.host?query"; BEGIN(); TEST_S(url_scheme(url_http), "http"); TEST_S(url_scheme(url_https), "https"); http->url_root = '/'; http->url_user = "******"; http->url_password = "******"; http->url_host = "host"; http->url_port = "32"; http->url_path = "foo;param=1/bar;param=3"; http->url_headers = "From=foo@bar&To=bar@baz"; http->url_fragment = "unf"; TEST_1(tst = su_strdup(home, httpurl)); TEST_1(url_d(url, tst) == 0); TEST_1(url_cmp(http, url) == 0); TEST(url->url_type, url_http); TEST_1(u = url_hdup(home, url)); TEST(u->url_type, url_http); TEST_1(url_cmp(http, u) == 0); TEST_SIZE(url_e(http2, sizeof(http2), u), strlen(httpurl)); TEST_1(strcmp(http2, httpurl) == 0); TEST_SIZE(snprintf(http2, sizeof(http2), URL_PRINT_FORMAT, URL_PRINT_ARGS(http)), strlen(httpurl)); TEST_1(strcmp(http2, httpurl) == 0); url_digest(hash1, sizeof(hash1), http, NULL); url_digest(hash2, sizeof(hash2), (url_t *)httpurl, NULL); TEST(memcmp(hash1, hash2, sizeof(hash1)), 0); memset(url, 0, sizeof url); TEST_1(tst = su_strdup(home, queryonly)); TEST(url_d(url, tst), 0); TEST_S(url->url_host, "some.host"); TEST_S(url->url_headers, "query"); TEST_S(url->url_params, NULL); TEST_1(u = url_hdup(home, (void *)"http://[::1]/test;ing?here")); TEST_S(u->url_host, "[::1]"); TEST_S(u->url_path, "test;ing"); TEST_S(u->url_headers, "here"); url_digest(hash1, sizeof(hash1), u, NULL); url_digest(hash2, sizeof(hash2), (url_t *)"http://[::1]/test;ing?here", NULL); TEST(memcmp(hash1, hash2, sizeof(hash1)), 0); su_home_deinit(home); END(); }
int test_strcasestr(void) { BEGIN(); { char const hs[] = "A case-folding string searching test consisting of a Long String"; char const *s; s = su_strcasestr(hs, "sting"); TEST_S(s, hs + 42); s = su_strcasestr(hs, "String"); TEST_S(s, hs + 15); s = su_strcasestr(hs, "S"); TEST_S(s, hs + 4); s = su_strcasestr(hs, "L"); TEST_S(s, hs + 9); s = su_strcasestr(hs, "trings"); TEST_1(s == NULL); s = su_strcasestr(hs, "String"); TEST_S(s, hs + 15); s = su_strcasestr(hs, "StRiNg"); TEST_S(s, hs + 15); s = su_strcasestr(hs, "OnG"); TEST_S(s, hs + 54); /* Special cases */ TEST_1(su_strcasestr(hs, "") == hs); TEST_1(su_strcasestr("", "ong") == NULL); TEST_1(su_strcasestr("", "OnG") == NULL); TEST_1(su_strcasestr("ong", hs) == NULL); TEST_1(su_strcasestr("OnG", hs) == NULL); TEST_1(su_strcasestr(hs, "Z") == NULL); TEST_1(su_strcasestr(hs, "z") == NULL); TEST_S(su_strcasestr("foobar", "OB"), "obar"); TEST_S(su_strcasestr("FOOBAR", "ob"), "OBAR"); } { char const hs[] = "A case-folding string searching test consisting of a Very Long String\n" "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Integer felis. " "Suspendisse potenti. Morbi malesuada erat eget enim. Sed dui lorem, aliquam " "eu, lobortis eget, dapibus vitae, velit. Cras non purus. Suspendisse massa. " "Curabitur gravida condimentum massa. Donec nunc magna, lacinia non, " "pellentesque ac, laoreet vel, eros. Praesent lectus leo, vestibulum eu, " "tempus eu, ullamcorper tristique, mi. Duis fringilla ultricies lacus. Ut " "non pede. Donec id libero. Cum sociis natoque penatibus et magnis dis " "parturient montes, nascetur ridiculus mus. Phasellus bibendum.\n" "Vestibulum turpis. Nunc euismod. Maecenas venenatis, purus at pharetra " "ultrices, orci orci blandit nisl, eget vulputate enim tortor sed nunc. " "Proin sit amet elit. Donec ut justo. In quis nisi. Praesent posuere. " "Maecenas porta. Curabitur pharetra. Class aptent taciti sociosqu ad litora " "torquent per conubia nostra, per inceptos hymenaeos. Donec suscipit ligula. " "Quisque facilisis ante eget mi. Nunc ac est.\n" "Quisque in sapien eget justo aliquam laoreet. Nullam ultricies est id dolor. " "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse ante " "velit, eleifend at, ullamcorper ut, rutrum et, ipsum. Mauris luctus, tellus " "non elementum convallis, nunc ipsum hendrerit lectus, ut lacinia elit nulla " "ac tellus. In sit amet velit. Maecenas non dolor. Sed commodo diam a pede. " "Ut non pede. Vestibulum condimentum turpis vel lacus consectetuer dictum. " "Nulla ullamcorper mi eu pede. Donec mauris tortor, facilisis vitae, " "hendrerit nec, lobortis nec, eros. Nam sit amet mi. Ut pharetra, orci nec " "porta convallis, lacus velit blandit sapien, luctus nonummy lacus dolor vel " "sapien. Suspendisse placerat. Donec ante turpis, volutpat eu, hendrerit " "vel, eleifend ac, arcu. Nulla facilisi. Sed faucibus facilisis lectus. " "Aliquam congue justo nec dui.\n" "Donec dapibus dui sed nisl. Proin congue. Curabitur placerat diam id eros. " "Pellentesque vitae nulla. Quisque at lorem et dolor auctor consequat. Sed " "sed tellus non nibh imperdiet venenatis. Integer ultrices dapibus nisi. " "Aenean vehicula malesuada risus. Fusce egestas malesuada leo. In " "ullamcorper pretium lorem. Vestibulum ante ipsum primis in faucibus orci " "luctus et ultrices posuere cubilia Curae;\n" "Phasellus congue. Morbi lectus arcu, mattis non, pulvinar et, condimentum " "non, mi. Suspendisse vestibulum nunc eu neque. Sed rutrum felis aliquam " "urna. Ut tincidunt orci vitae ipsum. Nullam eros. Quisque augue. Quisque " "lacinia. Nunc ligula diam, nonummy a, porta in, tristique quis, leo. " "Phasellus nunc nulla, fringilla vel, lacinia et, suscipit a, turpis. " "Integer a est. Curabitur mauris lacus, vehicula sit amet, sodales vel, " "iaculis vitae, massa. Nam diam est, ultrices vitae, varius et, tempor a, " "leo. Class aptent taciti sociosqu ad litora torquent per conubia nostra, " "per inceptos hymenaeos. Fusce felis nibh, ullamcorper non, malesuada eget, " "facilisis vel, purus.\n"; char const needle[] = "Proin congue. Curabitur placerat diam id eros. " "Pellentesque vitae nulla. Quisque at lorem et dolor auctor consequat. Sed " "sed tellus non nibh imperdiet venenatis. Integer ultrices dapibus nisi. " "Aenean vehicula malesuada risus. Fusce egestas malesuada leo. In " "ullamcorper pretium lorem. Vestibulum ante ipsum primis in faucibus orci " "luctus et ultrices posuere cubilia Curae;\n"; char const Needle[] = "PROIN CONGUE. CURABITUR PLACERAT DIAM ID EROS. " "PELLENTESQUE VITAE NULLA. QUISQUE AT LOREM ET DOLOR AUCTOR CONSEQUAT. SED " "SED TELLUS NON NIBH IMPERDIET VENENATIS. INTEGER ULTRICES DAPIBUS NISI. " "AENEAN VEHICULA MALESUADA RISUS. FUSCE EGESTAS MALESUADA LEO. IN " "ULLAMCORPER PRETIUM LOREM. VESTIBULUM ANTE IPSUM PRIMIS IN FAUCIBUS ORCI " "LUCTUS ET ULTRICES POSUERE CUBILIA CURAE;\n"; char const *s; s = su_strcasestr(hs, needle); TEST_S(s, hs + 1920); s = su_strcasestr(hs, Needle); TEST_S(s, hs + 1920); } END(); }
int test_any(void) { /* Test any (*) urls */ url_t any[1] = { URL_INIT_AS(any) }; su_home_t home[1] = { SU_HOME_INIT(home) }; url_t *u, url[1]; char *tst; BEGIN(); TEST_S(url_scheme(url_any), "*"); TEST_S(url_scheme(url_mailto), "mailto"); TEST_S(url_scheme(url_im), "im"); TEST_S(url_scheme(url_cid), "cid"); TEST_S(url_scheme(url_msrp), "msrp"); TEST_S(url_scheme(url_msrps), "msrps"); TEST_1(tst = su_strdup(home, "*")); TEST(url_d(url, tst), 0); TEST(url_cmp(any, url), 0); TEST(url->url_type, url_any); TEST_1(u = url_hdup(home, url)); TEST(u->url_type, url_any); TEST(url_cmp(any, u), 0); url_digest(hash1, sizeof(hash1), url, NULL); url_digest(hash2, sizeof(hash2), (url_t *)"*", NULL); TEST(memcmp(hash1, hash2, sizeof(hash1)), 0); { char buf[6]; TEST_1(u = url_hdup(home, (void *)"error")); TEST_SIZE(url_xtra(u), 6); TEST_SIZE(url_dup(buf, 6, url, u), 6); TEST_S(buf, "error"); } { TEST_1(u = url_hdup(home, (void *)"scheme:test")); TEST(u->url_type, url_unknown); } { TEST_1(u = url_hdup(home, (void *)"*;param=foo?query=bar")); TEST(u->url_type, url_unknown); TEST_S(u->url_host, "*"); TEST_S(u->url_params, "param=foo"); TEST_S(u->url_headers, "query=bar"); } { TEST_1(u = url_hdup(home, (void *)"#foo")); TEST(u->url_type, url_unknown); TEST_S(u->url_fragment, "foo"); } { url_t u[1]; char b2[6] = ""; memset(u, 0xff, sizeof u); TEST(url_d(u, b2), 0); TEST(u->url_type, url_unknown); } su_home_deinit(home); END(); }