1 #include "fct.h"
2
3 #include "log.h"
4
5 #include "AmSipHeaders.h"
6 #include "AmSipMsg.h"
7 #include "AmUtils.h"
8 #include "AmUriParser.h"
9
FCTMF_SUITE_BGN(test_uriparser)10 FCTMF_SUITE_BGN(test_uriparser) {
11
12 FCT_TEST_BGN(uriparser_simple) {
13 AmUriParser p;
14 size_t end;
15 fct_chk( p.parse_contact("sip:u@d", 0, end) );
16 fct_chk( p.uri_user=="u");
17 fct_chk( p.uri_host=="d");
18 } FCT_TEST_END();
19
20 FCT_TEST_BGN(uriparser_angle) {
21 AmUriParser p;
22 size_t end;
23 fct_chk( p.parse_contact("<sip:u@d>", 0, end) );
24 fct_chk( p.uri_user=="u");
25 fct_chk( p.uri_host=="d");
26 } FCT_TEST_END();
27
28 FCT_TEST_BGN(uriparser_angle_param) {
29 AmUriParser p;
30 size_t end;
31 fct_chk( p.parse_contact("<sip:u@d>;tag=123", 0, end) );
32 fct_chk( p.uri_user=="u");
33 fct_chk( p.uri_host=="d");
34 fct_chk( p.params["tag"]=="123");
35 } FCT_TEST_END();
36
37 FCT_TEST_BGN(uriparser_uri_param) {
38 AmUriParser p;
39 size_t end;
40 fct_chk( p.parse_contact("<sip:u@d;tag=123>", 0, end) );
41 fct_chk( p.uri_user=="u");
42 fct_chk( p.uri_host=="d");
43 fct_chk( p.uri_param=="tag=123");
44 } FCT_TEST_END();
45
46 FCT_TEST_BGN(uriparser_params_nobracket) {
47 AmUriParser p;
48 size_t end;
49 fct_chk( p.parse_contact("sip:u@d;tag=123", 0, end) );
50 fct_chk( p.uri_user=="u");
51 fct_chk( p.uri_host=="d");
52 fct_chk( p.params["tag"]=="123");
53 } FCT_TEST_END();
54
55 FCT_TEST_BGN(uriparser_params_dname) {
56 AmUriParser p;
57 size_t end;
58 fct_chk( p.parse_contact("hu <sip:u@d;tag=123>", 0, end) );
59 // DBG("DN:: '%s'\n", p.display_name.c_str());
60 fct_chk( p.display_name=="hu");
61 fct_chk( p.uri_user=="u");
62 fct_chk( p.uri_host=="d");
63 } FCT_TEST_END();
64
65 FCT_TEST_BGN(uriparser_params_dname2) {
66 AmUriParser p;
67 size_t end;
68 fct_chk( p.parse_contact(" hu bar <sip:u@d;tag=123>", 0, end) );
69 // DBG("DN:: '%s'\n", p.display_name.c_str());
70
71 fct_chk( p.display_name=="hu bar");
72 fct_chk( p.uri_user=="u");
73 fct_chk( p.uri_host=="d");
74 } FCT_TEST_END();
75
76 FCT_TEST_BGN(uriparser_params_dname3) {
77 AmUriParser p;
78 size_t end;
79 fct_chk( p.parse_contact(" \"hu bar\" <sip:u@d;tag=123>", 0, end) );
80 fct_chk( p.display_name=="hu bar");
81 fct_chk( p.uri_user=="u");
82 fct_chk( p.uri_host=="d");
83 } FCT_TEST_END();
84
85 FCT_TEST_BGN(uriparser_params_dname4) {
86 AmUriParser p;
87 size_t end;
88 fct_chk( p.parse_contact(" \"hu bar\\\\ \" <sip:u@d;tag=123>", 0, end) );
89 // fct_chk( p.parse_contact(" \"hu bar\\\\\" <sip:u@d;tag=123>", 0, end) );
90 fct_chk( p.display_name=="hu bar\\\\ ");
91 fct_chk( p.uri_user=="u");
92 fct_chk( p.uri_host=="d");
93 } FCT_TEST_END();
94
95 FCT_TEST_BGN(uriparser_params_dname4) {
96 AmUriParser p;
97 size_t end;
98 fct_chk(p.parse_contact("\"Mr. Watson\" <mailto:watson@bell-telephone.com> ;q=0.1", 0, end));
99 fct_chk( p.display_name=="Mr. Watson");
100 fct_chk( p.uri_user=="watson");
101 fct_chk( p.uri_host=="bell-telephone.com");
102 } FCT_TEST_END();
103
104 FCT_TEST_BGN(uriparser_headers) {
105 AmUriParser p;
106 size_t end;
107 fct_chk(p.parse_contact("\"Mr. Watson\" <mailto:watson@bell-telephone.com?Replaces:%20lkancskjd%3Bto-tag=3123141ab%3Bfrom-tag=kjhkjcsd> ;q=0.1", 0, end));
108 fct_chk( p.display_name=="Mr. Watson");
109 fct_chk( p.uri_user=="watson");
110 fct_chk( p.uri_host=="bell-telephone.com");
111 fct_chk( p.uri_headers=="Replaces:\%20lkancskjd%3Bto-tag=3123141ab%3Bfrom-tag=kjhkjcsd");
112 } FCT_TEST_END();
113
114 FCT_TEST_BGN(uriparser_headers_str) {
115 AmUriParser p;
116 string orig_str = "\"Mr. Watson\" <sip:watson@bell-telephone.com?Replaces:%20lkancskjd%3Bto-tag=3123141ab%3Bfrom-tag=kjhkjcsd>;q=0.1";
117 fct_chk(p.parse_nameaddr(orig_str));
118 fct_chk( p.display_name=="Mr. Watson");
119 fct_chk( p.uri_user=="watson");
120 fct_chk( p.uri_host=="bell-telephone.com");
121 fct_chk( p.uri_headers=="Replaces:\%20lkancskjd%3Bto-tag=3123141ab%3Bfrom-tag=kjhkjcsd");
122 string a_str = p.nameaddr_str();
123 // DBG(" >>%s<< => >>%s<<\n", orig_str.c_str(), a_str.c_str());
124 fct_chk(orig_str == a_str);
125 } FCT_TEST_END();
126
127 FCT_TEST_BGN(uriparser_url_escape) {
128 string src = "Replaces: CSADFSD;from-tag=31241231abc;to-tag=235123";
129 string dst = "Replaces%3A%20CSADFSD%3Bfrom-tag%3D31241231abc%3Bto-tag%3D235123";
130 fct_chk ( URL_decode(dst)==src );
131 fct_chk ( URL_encode(src)==dst );
132 fct_chk ( URL_decode(URL_encode(src))==src );
133 } FCT_TEST_END();
134
135 FCT_TEST_BGN(uriparser_params_dname5) {
136 AmUriParser p;
137 size_t end;
138 fct_chk(p.parse_contact("<sip:alice@atlanta.com>;q=\"0.1\";param", 0, end));
139 fct_chk( p.params.size()==2);
140 } FCT_TEST_END();
141
142 FCT_TEST_BGN(uriparser_params_dname6) {
143 AmUriParser p;
144 size_t end;
145 fct_chk(p.parse_contact("<sip:alice@atlanta.com>;+g.3gpp.icsi-ref=\"urn%3Aurn-7%3A3gpp-service.ims.icsi.mmtel\";video;mobility=\"mobile\"", 0, end));
146 fct_chk( p.params.size()==3);
147 } FCT_TEST_END();
148 } FCTMF_SUITE_END();
149