summaryrefslogtreecommitdiff
path: root/pjsip/src/test-pjsip
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2007-12-02 15:40:52 +0000
committerBenny Prijono <bennylp@teluu.com>2007-12-02 15:40:52 +0000
commit085b6a1482c3241345b79c3f29ad9f4d64f4805f (patch)
tree9645ab7e0d3ff2b9bf845977f28b3d296f077f24 /pjsip/src/test-pjsip
parenta379832fa79e4ca211c85783b68eac1f070622f2 (diff)
More ticket #421: fixed SIP messaging components to support IPv6 format
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@1610 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip/src/test-pjsip')
-rw-r--r--pjsip/src/test-pjsip/msg_test.c109
-rw-r--r--pjsip/src/test-pjsip/test.h2
-rw-r--r--pjsip/src/test-pjsip/uri_test.c46
3 files changed, 147 insertions, 10 deletions
diff --git a/pjsip/src/test-pjsip/msg_test.c b/pjsip/src/test-pjsip/msg_test.c
index ce6c372f..c271aab8 100644
--- a/pjsip/src/test-pjsip/msg_test.c
+++ b/pjsip/src/test-pjsip/msg_test.c
@@ -700,6 +700,7 @@ static pj_status_t simple_test(void)
}
+#if INCLUDE_BENCHMARKS
static int msg_benchmark(unsigned *p_detect, unsigned *p_parse,
unsigned *p_print)
{
@@ -775,6 +776,7 @@ static int msg_benchmark(unsigned *p_detect, unsigned *p_parse,
*p_print = (unsigned)avg_print;
return status;
}
+#endif /* INCLUDE_BENCHMARKS */
/*****************************************************************************/
/* Test various header parsing and production */
@@ -795,12 +797,14 @@ static int hdr_test_record_route(pjsip_hdr *h);
static int hdr_test_supported(pjsip_hdr *h);
static int hdr_test_to(pjsip_hdr *h);
static int hdr_test_via(pjsip_hdr *h);
-
+static int hdr_test_via_ipv6_1(pjsip_hdr *h);
+static int hdr_test_via_ipv6_2(pjsip_hdr *h);
+static int hdr_test_via_ipv6_3(pjsip_hdr *h);
#define GENERIC_PARAM "p0=a;p1=\"ab:;cd\";p2=ab%3acd;p3"
#define GENERIC_PARAM_PARSED "p0=a;p1=\"ab:;cd\";p2=ab:cd;p3"
-#define PARAM_CHAR "[]/:&+$"
+#define PARAM_CHAR "][/:&+$"
#define SIMPLE_ADDR_SPEC "sip:host"
#define ADDR_SPEC SIMPLE_ADDR_SPEC ";"PARAM_CHAR"="PARAM_CHAR ";p1=\";\""
#define NAME_ADDR "<" ADDR_SPEC ">"
@@ -947,6 +951,27 @@ struct hdr_test_t
"Via", "v",
"SIP/2.0/XYZ host" ";" GENERIC_PARAM,
&hdr_test_via
+ },
+
+ {
+ /* Via with IPv6 */
+ "Via", "v",
+ "SIP/2.0/UDP [::1]",
+ &hdr_test_via_ipv6_1
+ },
+
+ {
+ /* Via with IPv6 */
+ "Via", "v",
+ "SIP/2.0/UDP [::1]:5061",
+ &hdr_test_via_ipv6_2
+ },
+
+ {
+ /* Via with IPv6 */
+ "Via", "v",
+ "SIP/2.0/UDP [::1];rport=5061;received=::2",
+ &hdr_test_via_ipv6_3
}
};
@@ -1111,7 +1136,7 @@ static int test_simple_addr_spec(pjsip_uri *uri)
}
/*
-#define PARAM_CHAR "[]/:&+$"
+#define PARAM_CHAR "][/:&+$"
#define SIMPLE_ADDR_SPEC "sip:host"
#define ADDR_SPEC SIMPLE_ADDR_SPEC ";"PARAM_CHAR"="PARAM_CHAR ";p1=\";\""
#define NAME_ADDR "<" ADDR_SPEC ">"
@@ -1433,6 +1458,74 @@ static int hdr_test_via(pjsip_hdr *h)
}
+/*
+ "SIP/2.0/UDP [::1]"
+ */
+static int hdr_test_via_ipv6_1(pjsip_hdr *h)
+{
+ pjsip_via_hdr *hdr = (pjsip_via_hdr*)h;
+
+ if (h->type != PJSIP_H_VIA)
+ return -2610;
+
+ if (pj_strcmp2(&hdr->transport, "UDP"))
+ return -2615;
+
+ if (pj_strcmp2(&hdr->sent_by.host, "::1"))
+ return -2620;
+
+ if (hdr->sent_by.port != 0)
+ return -2630;
+
+ return 0;
+}
+
+/* "SIP/2.0/UDP [::1]:5061" */
+static int hdr_test_via_ipv6_2(pjsip_hdr *h)
+{
+ pjsip_via_hdr *hdr = (pjsip_via_hdr*)h;
+
+ if (h->type != PJSIP_H_VIA)
+ return -2710;
+
+ if (pj_strcmp2(&hdr->transport, "UDP"))
+ return -2715;
+
+ if (pj_strcmp2(&hdr->sent_by.host, "::1"))
+ return -2720;
+
+ if (hdr->sent_by.port != 5061)
+ return -2730;
+
+ return 0;
+}
+
+/* "SIP/2.0/UDP [::1];rport=5061;received=::2" */
+static int hdr_test_via_ipv6_3(pjsip_hdr *h)
+{
+ pjsip_via_hdr *hdr = (pjsip_via_hdr*)h;
+
+ if (h->type != PJSIP_H_VIA)
+ return -2810;
+
+ if (pj_strcmp2(&hdr->transport, "UDP"))
+ return -2815;
+
+ if (pj_strcmp2(&hdr->sent_by.host, "::1"))
+ return -2820;
+
+ if (hdr->sent_by.port != 0)
+ return -2830;
+
+ if (pj_strcmp2(&hdr->recvd_param, "::2"))
+ return -2840;
+
+ if (hdr->rport_param != 5061)
+ return -2850;
+
+ return 0;
+}
+
static int hdr_test(void)
{
unsigned i;
@@ -1533,14 +1626,15 @@ int msg_test(void)
char desc[250];
pj_status_t status;
- status = simple_test();
- if (status != PJ_SUCCESS)
- return status;
-
status = hdr_test();
if (status != 0)
return status;
+ status = simple_test();
+ if (status != PJ_SUCCESS)
+ return status;
+
+#if INCLUDE_BENCHMARKS
for (i=0; i<COUNT; ++i) {
PJ_LOG(3,(THIS_FILE, " benchmarking (%d of %d)..", i+1, COUNT));
status = msg_benchmark(&run[i].detect, &run[i].parse, &run[i].print);
@@ -1608,6 +1702,7 @@ int msg_test(void)
"SIP messages printed per second). "
"The value is derived from msg-print-per-sec above.");
+#endif /* INCLUDE_BENCHMARKS */
return PJ_SUCCESS;
}
diff --git a/pjsip/src/test-pjsip/test.h b/pjsip/src/test-pjsip/test.h
index b2566510..1234cebc 100644
--- a/pjsip/src/test-pjsip/test.h
+++ b/pjsip/src/test-pjsip/test.h
@@ -41,6 +41,8 @@ extern pjsip_endpoint *endpt;
#define INCLUDE_TSX_GROUP 1
#define INCLUDE_INV_GROUP 1
+#define INCLUDE_BENCHMARKS 1
+
/*
* Include tests that normally would fail under certain gcc
* optimization levels.
diff --git a/pjsip/src/test-pjsip/uri_test.c b/pjsip/src/test-pjsip/uri_test.c
index 413c6fed..612a8410 100644
--- a/pjsip/src/test-pjsip/uri_test.c
+++ b/pjsip/src/test-pjsip/uri_test.c
@@ -76,7 +76,8 @@ static pjsip_uri *create_uri31( pj_pool_t *pool );
static pjsip_uri *create_uri32( pj_pool_t *pool );
static pjsip_uri *create_uri33( pj_pool_t *pool );
static pjsip_uri *create_uri34( pj_pool_t *pool );
-//static pjsip_uri *create_uri35( pj_pool_t *pool );
+static pjsip_uri *create_uri35( pj_pool_t *pool );
+static pjsip_uri *create_uri36( pj_pool_t *pool );
static pjsip_uri *create_dummy( pj_pool_t *pool );
#define ERR_NOT_EQUAL -1001
@@ -318,7 +319,21 @@ struct uri_test
&create_uri34,
"tel:911;p1=p1;p2=p2"
},
-
+ {
+ /* 35: IPv6 in host and maddr parameter */
+ PJ_SUCCESS,
+ "sip:user@[::1];maddr=[::01]",
+ &create_uri35,
+ "sip:user@[::1];maddr=[::01]"
+ },
+ {
+ /* 36: IPv6 in host and maddr, without username */
+ PJ_SUCCESS,
+ "sip:[::1];maddr=[::01]",
+ &create_uri36,
+ "sip:[::1];maddr=[::01]"
+ }
+
};
static pjsip_uri *create_uri0(pj_pool_t *pool)
@@ -669,6 +684,27 @@ static pjsip_uri *create_uri34(pj_pool_t *pool)
return (pjsip_uri*)uri;
}
+/* "sip:user@[::1];maddr=[::01]" */
+static pjsip_uri *create_uri35( pj_pool_t *pool )
+{
+ pjsip_sip_uri *url;
+ url = pjsip_sip_uri_create(pool, 0);
+ url->user = pj_str("user");
+ url->host = pj_str("::1");
+ url->maddr_param = pj_str("::01");
+ return (pjsip_uri*)url;
+}
+
+/* "sip:[::1];maddr=[::01]" */
+static pjsip_uri *create_uri36( pj_pool_t *pool )
+{
+ pjsip_sip_uri *url;
+ url = pjsip_sip_uri_create(pool, 0);
+ url->host = pj_str("::1");
+ url->maddr_param = pj_str("::01");
+ return (pjsip_uri*)url;
+
+}
static pjsip_uri *create_dummy(pj_pool_t *pool)
{
@@ -824,6 +860,7 @@ static int simple_uri_test(void)
return 0;
}
+#if INCLUDE_BENCHMARKS
static int uri_benchmark(unsigned *p_parse, unsigned *p_print, unsigned *p_cmp)
{
unsigned i, loop;
@@ -909,7 +946,7 @@ static int uri_benchmark(unsigned *p_parse, unsigned *p_print, unsigned *p_cmp)
on_return:
return status;
}
-
+#endif /* INCLUDE_BENCHMARKS */
/*****************************************************************************/
@@ -929,6 +966,7 @@ int uri_test(void)
if (status != PJ_SUCCESS)
return status;
+#if INCLUDE_BENCHMARKS
for (i=0; i<COUNT; ++i) {
PJ_LOG(3,(THIS_FILE, " benchmarking (%d of %d)...", i+1, COUNT));
status = uri_benchmark(&run[i].parse, &run[i].print, &run[i].cmp);
@@ -993,6 +1031,8 @@ int uri_test(void)
report_ival("uri-cmp-per-sec", max, "URI/sec", desc);
+#endif /* INCLUDE_BENCHMARKS */
+
return PJ_SUCCESS;
}