2 The oSIP library implements the Session Initiation Protocol (SIP -rfc2543-)
3 Copyright (C) 2001 Aymeric MOIZARD jack@atosc.org
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library 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 GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include <osipparser2/osip_parser.h>
29 #include <osip2/internal.h>
31 int test_message (char *msg, int verbose, int clone);
32 static void usage (void);
37 fprintf (stderr, "Usage: ./torture_test torture_file number [-v] [-c]\n");
42 main (int argc, char **argv)
45 int verbose = 0; /* 1: verbose, 0 (or nothing: not verbose) */
46 int clone = 0; /* 1: verbose, 0 (or nothing: not verbose) */
52 static int num_test = 0;
56 if (0 == strncmp (argv[3], "-v", 2))
58 else if (0 == strncmp (argv[3], "-c", 2))
66 if (0 == strncmp (argv[4], "-v", 2))
68 else if (0 == strncmp (argv[4], "-c", 2))
79 torture_file = fopen (argv[1], "r");
80 if (torture_file == NULL)
85 /* initialize parser */
89 tmp = (char *) osip_malloc (500);
90 marker = fgets (tmp, 500, torture_file); /* lines are under 500 */
91 while (marker != NULL && i < atoi (argv[2]))
93 if (0 == strncmp (tmp, "|", 1))
95 marker = fgets (tmp, 500, torture_file);
99 msg = (char *) osip_malloc (50000); /* msg are under 10000 */
102 fprintf (stderr, "Error! osip_malloc failed\n");
110 "Error! The message's number you specified does not exist\n");
111 exit (1); /* end of file detected! */
113 /* this part reads an entire message, separator is "|" */
114 /* (it is unlinkely that it will appear in messages!) */
115 while (marker != NULL && strncmp (tmp, "|", 1))
117 osip_strncpy (tmpmsg, tmp, strlen (tmp));
118 tmpmsg = tmpmsg + strlen (tmp);
119 marker = fgets (tmp, 500, torture_file);
124 fprintf (stdout, "test %s : ============================ \n", argv[2]);
125 fprintf (stdout, "%s", msg);
127 if (0 == test_message (msg, verbose, clone))
128 fprintf (stdout, "test %s : ============================ OK\n",
131 fprintf (stdout, "test %s : ============================ FAILED\n",
136 if (0 == test_message (msg, verbose, clone))
137 fprintf (stdout, "test %s : OK\n", argv[2]);
139 fprintf (stdout, "test %s : FAILED\n", argv[2]);
144 fclose (torture_file);
150 test_message (char *msg, int verbose, int clone)
161 "Trying %i sequentials calls to osip_message_init(), osip_message_parse() and osip_message_free()\n",
166 osip_message_init (&sip);
167 if (osip_message_parse (sip, msg) != 0)
169 fprintf (stdout, "ERROR: failed while parsing!\n");
170 osip_message_free (sip); /* try to free msg, even if it failed! */
173 osip_message_free (sip); /* try to free msg, even if it failed! */
176 osip_message_init (&sip);
177 if (osip_message_parse (sip, msg) != 0)
179 fprintf (stdout, "ERROR: failed while parsing!\n");
180 osip_message_free (sip); /* try to free msg, even if it failed! */
181 /* this seems dangerous..... */
188 i = osip_message_to_str (sip, &result);
191 fprintf (stdout, "ERROR: failed while printing message!\n");
192 osip_message_free (sip);
198 fprintf (stdout, "%s", result);
201 /* create a clone of message */
206 "Trying %i sequentials calls to osip_message_clone() and osip_message_free()\n",
210 osip_message_t *copy;
213 i = osip_message_clone (sip, ©);
217 "ERROR: failed while creating copy of message!\n");
223 osip_message_force_update (copy);
224 i = osip_message_to_str (copy, &tmp);
228 "ERROR: failed while printing message!\n");
232 if (0 == strcmp (result, tmp))
236 ("The osip_message_clone method works perfectly\n");
240 ("ERROR: The osip_message_clone method DOES NOT works\n");
242 printf ("Here is the copy: \n%s\n", tmp);
246 osip_message_free (copy);
249 fprintf (stdout, "sequentials calls: done\n");
253 osip_message_free (sip);