Debian Codegraph @

Xpjproject/pjsip/src/test/msg_err_test.c

raw symbols SCIP
1 /*
2 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
3 * Copyright (C) 2003-2008 Benny Prijono <[email protected]>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 #include "test.h"
20 #include <pjsip.h>
21 #include <pjlib.h>
22
23 #define THIS_FILE "msg_err_test.c"
24
25
26 static pj_bool_t verify_success(pjsip_msg *msg,
27 pjsip_parser_err_report *err_list)
28 {
29 PJ_UNUSED_ARG(msg);
30 PJ_UNUSED_ARG(err_list);
31
32 return PJ_TRUE;
33 }
34
35 static struct test_entry
36 {
37 char msg[1024];
38 pj_bool_t (*verify)(pjsip_msg *msg,
39 pjsip_parser_err_report *err_list);
40
41 } test_entries[] =
42 {
43 /* Syntax error in status line */
44 {
45 "SIP/2.0 200\r\n"
46 "H-Name: H-Value\r\n"
47 "\r\n",
48 &verify_success
49 },
50
51 /* Syntax error in header */
52 {
53 "SIP/2.0 200 OK\r\n"
54 "Via: SIP/2.0\r\n"
55 "H-Name: H-Value\r\n"
56 "\r\n",
57 &verify_success
58 },
59
60 /* Multiple syntax errors in headers */
61 {
62 "SIP/2.0 200 OK\r\n"
63 "Via: SIP/2.0\r\n"
64 "H-Name: H-Value\r\n"
65 "Via: SIP/2.0\r\n"
66 "\r\n",
67 &verify_success
68 }
69 };
70
71
72 int msg_err_test(void)
73 {
74 pj_pool_t *pool;
75 unsigned i;
76
77 PJ_LOG(3,(THIS_FILE, "Testing parsing error"));
78
79 pool = pjsip_endpt_create_pool(endpt, "msgerrtest", 4000, 4000);
80
81 for (i=0; i<PJ_ARRAY_SIZE(test_entries); ++i) {
82 pjsip_parser_err_report err_list, *e;
83
84 PJ_LOG(3,(THIS_FILE, " Parsing msg %d", i));
85 pj_list_init(&err_list);
86 pjsip_parse_msg(pool, test_entries[i].msg,
87 strlen(test_entries[i].msg), &err_list);
88
89 e = err_list.next;
90 while (e != &err_list) {
91 PJ_LOG(3,(THIS_FILE,
92 " reported syntax error at line %d col %d for %.*s",
93 e->line, e->col,
94 (int)e->hname.slen,
95 e->hname.ptr));
96 e = e->next;
97 }
98 }
99
100 pj_pool_release(pool);
101 return 0;
102 }