Fixed pjsip-test and added msg_err_test.c for testing parsing errors

git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@547 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjsip/build/pjsip.dsw b/pjsip/build/pjsip.dsw
index e932108..06c45c2 100644
--- a/pjsip/build/pjsip.dsw
+++ b/pjsip/build/pjsip.dsw
@@ -105,45 +105,6 @@
 

 ###############################################################################

 

-Project: "pjsua"=.\pjsua.dsp - Package Owner=<4>

-

-Package=<5>

-{{{

-}}}

-

-Package=<4>

-{{{

-    Begin Project Dependency

-    Project_Dep_Name pjsip_core

-    End Project Dependency

-    Begin Project Dependency

-    Project_Dep_Name pjsip_ua

-    End Project Dependency

-    Begin Project Dependency

-    Project_Dep_Name pjlib

-    End Project Dependency

-    Begin Project Dependency

-    Project_Dep_Name pjmedia

-    End Project Dependency

-    Begin Project Dependency

-    Project_Dep_Name pjsdp

-    End Project Dependency

-    Begin Project Dependency

-    Project_Dep_Name pjmedia_codec

-    End Project Dependency

-    Begin Project Dependency

-    Project_Dep_Name pjlib_util

-    End Project Dependency

-    Begin Project Dependency

-    Project_Dep_Name pjsip_simple

-    End Project Dependency

-    Begin Project Dependency

-    Project_Dep_Name pjsua_lib

-    End Project Dependency

-}}}

-

-###############################################################################

-

 Project: "pjsua_lib"=.\pjsua_lib.dsp - Package Owner=<4>

 

 Package=<5>

@@ -170,6 +131,9 @@
     Begin Project Dependency

     Project_Dep_Name pjsip_core

     End Project Dependency

+    Begin Project Dependency

+    Project_Dep_Name pjlib_util

+    End Project Dependency

 }}}

 

 ###############################################################################

diff --git a/pjsip/build/test_pjsip.dsp b/pjsip/build/test_pjsip.dsp
index 213bad0..bdf1a72 100644
--- a/pjsip/build/test_pjsip.dsp
+++ b/pjsip/build/test_pjsip.dsp
@@ -97,6 +97,10 @@
 # End Source File

 # Begin Source File

 

+SOURCE="..\src\test-pjsip\msg_err_test.c"

+# End Source File

+# Begin Source File

+

 SOURCE="..\src\test-pjsip\msg_logger.c"

 # End Source File

 # Begin Source File

diff --git a/pjsip/src/test-pjsip/msg_err_test.c b/pjsip/src/test-pjsip/msg_err_test.c
new file mode 100644
index 0000000..c52c6eb
--- /dev/null
+++ b/pjsip/src/test-pjsip/msg_err_test.c
@@ -0,0 +1,100 @@
+/* $Id$ */
+/* 
+ * Copyright (C) 2003-2006 Benny Prijono <benny@prijono.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
+ */
+#include "test.h"
+#include <pjsip.h>
+#include <pjlib.h>
+
+#define THIS_FILE   "msg_err_test.c"
+
+
+static pj_bool_t verify_success(pjsip_msg *msg,
+				pjsip_parser_err_report *err_list)
+{
+    return PJ_TRUE;
+}
+
+static struct test_entry
+{
+    char	msg[1024];
+    pj_bool_t (*verify)(pjsip_msg *msg,
+		        pjsip_parser_err_report *err_list);
+
+} test_entries[] = 
+{
+    /* Syntax error in status line */
+    {
+	"SIP/2.0 200\r\n"
+	"H-Name: H-Value\r\n"
+	"\r\n",
+	&verify_success
+    },
+
+    /* Syntax error in header */
+    {
+	"SIP/2.0 200 OK\r\n"
+	"Via: SIP/2.0\r\n"
+	"H-Name: H-Value\r\n"
+	"\r\n",
+	&verify_success
+    },
+
+    /* Multiple syntax errors in headers */
+    {
+	"SIP/2.0 200 OK\r\n"
+	"Via: SIP/2.0\r\n"
+	"H-Name: H-Value\r\n"
+	"Via: SIP/2.0\r\n"
+	"\r\n",
+	&verify_success
+    }
+};
+
+
+int msg_err_test(void)
+{
+    pj_pool_t *pool;
+    unsigned i;
+
+    PJ_LOG(3,(THIS_FILE, "Testing parsing error"));
+
+    pool = pjsip_endpt_create_pool(endpt, "msgerrtest", 4000, 4000);
+
+    for (i=0; i<PJ_ARRAY_SIZE(test_entries); ++i) {
+	pjsip_parser_err_report err_list, *e;
+	pjsip_msg *msg;
+
+	PJ_LOG(3,(THIS_FILE, "  Parsing msg %d", i));
+	pj_list_init(&err_list);
+	msg = pjsip_parse_msg(pool, test_entries[i].msg,
+			      strlen(test_entries[i].msg), &err_list);
+
+	e = err_list.next;
+	while (e != &err_list) {
+	    PJ_LOG(3,(THIS_FILE, 
+		      "   reported syntax error at line %d col %d for %.*s",
+		      e->line, e->col,
+		      (int)e->hname.slen,
+		      e->hname.ptr));
+	    e = e->next;
+	}
+    }
+
+    pj_pool_release(pool);
+    return 0;
+}
diff --git a/pjsip/src/test-pjsip/msg_logger.c b/pjsip/src/test-pjsip/msg_logger.c
index 45a4cba..a4eac0d 100644
--- a/pjsip/src/test-pjsip/msg_logger.c
+++ b/pjsip/src/test-pjsip/msg_logger.c
@@ -63,7 +63,6 @@
     { "mod-msg-logger", 14},		/* Name.		*/
     -1,					/* Id			*/
     PJSIP_MOD_PRIORITY_TRANSPORT_LAYER-1,/* Priority		*/
-    NULL,				/* User data.		*/
     NULL,				/* load()		*/
     NULL,				/* start()		*/
     NULL,				/* stop()		*/
diff --git a/pjsip/src/test-pjsip/test.c b/pjsip/src/test-pjsip/test.c
index dd3453f..f3d4833 100644
--- a/pjsip/src/test-pjsip/test.c
+++ b/pjsip/src/test-pjsip/test.c
@@ -36,7 +36,7 @@
 
 
 pjsip_endpoint *endpt;
-int log_level = 5;
+int log_level = 3;
 
 void app_perror(const char *msg, pj_status_t rc)
 {
@@ -44,7 +44,7 @@
 
     PJ_CHECK_STACK();
 
-    pjsip_strerror(rc, errbuf, sizeof(errbuf));
+    pj_strerror(rc, errbuf, sizeof(errbuf));
     PJ_LOG(3,(THIS_FILE, "%s: [pj_status_t=%d] %s", msg, rc, errbuf));
 
 }
@@ -111,7 +111,7 @@
     msg_logger_set_enabled(1);
 
     /* Start transaction layer module. */
-    rc = pjsip_tsx_layer_init(endpt);
+    rc = pjsip_tsx_layer_init_module(endpt);
     if (rc != PJ_SUCCESS) {
 	app_perror("   Error initializing transaction module", rc);
 	goto on_return;
@@ -125,13 +125,14 @@
 	goto on_return;
     }
 
-    //DO_TEST(uri_test());
-    //DO_TEST(msg_test());
-    //DO_TEST(txdata_test());
-    //DO_TEST(transport_udp_test());
-    //DO_TEST(transport_loop_test());
-    //DO_TEST(tsx_basic_test());
-    //DO_TEST(tsx_uac_test());
+    DO_TEST(uri_test());
+    DO_TEST(msg_test());
+    DO_TEST(msg_err_test());
+    DO_TEST(txdata_test());
+    DO_TEST(transport_udp_test());
+    DO_TEST(transport_loop_test());
+    DO_TEST(tsx_basic_test());
+    DO_TEST(tsx_uac_test());
     DO_TEST(tsx_uas_test());
 
 on_return:
@@ -150,6 +151,6 @@
     else
 	PJ_LOG(3,(THIS_FILE, "Test completed with error(s)"));
 
-    return 0;
+    return rc;
 }
 
diff --git a/pjsip/src/test-pjsip/test.h b/pjsip/src/test-pjsip/test.h
index 7f74964..7c549a3 100644
--- a/pjsip/src/test-pjsip/test.h
+++ b/pjsip/src/test-pjsip/test.h
@@ -29,6 +29,7 @@
 /* The tests */
 int uri_test(void);
 int msg_test(void);
+int msg_err_test(void);
 int txdata_test(void);
 int transport_udp_test(void);
 int transport_loop_test(void);
diff --git a/pjsip/src/test-pjsip/transport_test.c b/pjsip/src/test-pjsip/transport_test.c
index df6f55e..0cd0d22 100644
--- a/pjsip/src/test-pjsip/transport_test.c
+++ b/pjsip/src/test-pjsip/transport_test.c
@@ -100,7 +100,6 @@
     { "Transport-Test", 14},		/* Name.		*/
     -1,					/* Id			*/
     PJSIP_MOD_PRIORITY_TSX_LAYER-1,	/* Priority		*/
-    NULL,				/* User data.		*/
     NULL,				/* load()		*/
     NULL,				/* start()		*/
     NULL,				/* stop()		*/
@@ -302,7 +301,6 @@
     { "Transport-RT-Test", 17},		/* Name.		*/
     -1,					/* Id			*/
     PJSIP_MOD_PRIORITY_TSX_LAYER-1,	/* Priority		*/
-    NULL,				/* User data.		*/
     NULL,				/* load()		*/
     NULL,				/* start()		*/
     NULL,				/* stop()		*/
diff --git a/pjsip/src/test-pjsip/tsx_uac_test.c b/pjsip/src/test-pjsip/tsx_uac_test.c
index c699bc5..262e5ce 100644
--- a/pjsip/src/test-pjsip/tsx_uac_test.c
+++ b/pjsip/src/test-pjsip/tsx_uac_test.c
@@ -102,7 +102,6 @@
     { "Tsx-UAC-User", 12},		/* Name.		*/
     -1,					/* Id			*/
     PJSIP_MOD_PRIORITY_APPLICATION-1,	/* Priority		*/
-    NULL,				/* User data.		*/
     NULL,				/* load()		*/
     NULL,				/* start()		*/
     NULL,				/* stop()		*/
@@ -121,7 +120,6 @@
     { "Msg-Receiver", 12},		/* Name.		*/
     -1,					/* Id			*/
     PJSIP_MOD_PRIORITY_APPLICATION-1,	/* Priority		*/
-    NULL,				/* User data.		*/
     NULL,				/* load()		*/
     NULL,				/* start()		*/
     NULL,				/* stop()		*/
diff --git a/pjsip/src/test-pjsip/tsx_uas_test.c b/pjsip/src/test-pjsip/tsx_uas_test.c
index 326f225..632950f 100644
--- a/pjsip/src/test-pjsip/tsx_uas_test.c
+++ b/pjsip/src/test-pjsip/tsx_uas_test.c
@@ -141,7 +141,6 @@
     { "Tsx-UAS-User", 12},		/* Name.		*/
     -1,					/* Id			*/
     PJSIP_MOD_PRIORITY_APPLICATION-1,	/* Priority		*/
-    NULL,				/* User data.		*/
     NULL,				/* load()		*/
     NULL,				/* start()		*/
     NULL,				/* stop()		*/
@@ -160,7 +159,6 @@
     { "Msg-Sender", 10},		/* Name.		*/
     -1,					/* Id			*/
     PJSIP_MOD_PRIORITY_APPLICATION-1,	/* Priority		*/
-    NULL,				/* User data.		*/
     NULL,				/* load()		*/
     NULL,				/* start()		*/
     NULL,				/* stop()		*/