msg_err_test.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
  3. * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
  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. #define THIS_FILE "msg_err_test.c"
  23. static pj_bool_t verify_success(pjsip_msg *msg,
  24. pjsip_parser_err_report *err_list)
  25. {
  26. PJ_UNUSED_ARG(msg);
  27. PJ_UNUSED_ARG(err_list);
  28. return PJ_TRUE;
  29. }
  30. static struct test_entry
  31. {
  32. char msg[1024];
  33. pj_bool_t (*verify)(pjsip_msg *msg,
  34. pjsip_parser_err_report *err_list);
  35. } test_entries[] =
  36. {
  37. /* Syntax error in status line */
  38. {
  39. "SIP/2.0 200\r\n"
  40. "H-Name: H-Value\r\n"
  41. "\r\n",
  42. &verify_success
  43. },
  44. /* Syntax error in header */
  45. {
  46. "SIP/2.0 200 OK\r\n"
  47. "Via: SIP/2.0\r\n"
  48. "H-Name: H-Value\r\n"
  49. "\r\n",
  50. &verify_success
  51. },
  52. /* Multiple syntax errors in headers */
  53. {
  54. "SIP/2.0 200 OK\r\n"
  55. "Via: SIP/2.0\r\n"
  56. "H-Name: H-Value\r\n"
  57. "Via: SIP/2.0\r\n"
  58. "\r\n",
  59. &verify_success
  60. }
  61. };
  62. int msg_err_test(void)
  63. {
  64. pj_pool_t *pool;
  65. unsigned i;
  66. PJ_LOG(3,(THIS_FILE, "Testing parsing error"));
  67. pool = pjsip_endpt_create_pool(endpt, "msgerrtest", 4000, 4000);
  68. for (i=0; i<PJ_ARRAY_SIZE(test_entries); ++i) {
  69. pjsip_parser_err_report err_list, *e;
  70. PJ_LOG(3,(THIS_FILE, " Parsing msg %d", i));
  71. pj_list_init(&err_list);
  72. pjsip_parse_msg(pool, test_entries[i].msg,
  73. strlen(test_entries[i].msg), &err_list);
  74. e = err_list.next;
  75. while (e != &err_list) {
  76. PJ_LOG(3,(THIS_FILE,
  77. " reported syntax error at line %d col %d for %.*s",
  78. e->line, e->col,
  79. (int)e->hname.slen,
  80. e->hname.ptr));
  81. e = e->next;
  82. }
  83. }
  84. pj_pool_release(pool);
  85. return 0;
  86. }