From a08b589d09d5197f9a76d549a189e4686bd2ca8c Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Sun, 13 Nov 2005 19:40:44 +0000 Subject: Applying license to pjproject git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@49 74dad513-b988-da41-8d7b-12977e46ad98 --- pjlib-util/src/pjlib-util-test/xml.c | 279 +++++++++++++++++++---------------- 1 file changed, 150 insertions(+), 129 deletions(-) (limited to 'pjlib-util/src/pjlib-util-test/xml.c') diff --git a/pjlib-util/src/pjlib-util-test/xml.c b/pjlib-util/src/pjlib-util-test/xml.c index d4e22746..440e0aef 100644 --- a/pjlib-util/src/pjlib-util-test/xml.c +++ b/pjlib-util/src/pjlib-util-test/xml.c @@ -1,129 +1,150 @@ -/* $Id$ - */ -#include "test.h" - - -#if INCLUDE_XML_TEST - -#include -#include - -#define THIS_FILE "xml_test" - -static const char *xml_doc[] = -{ -" \n" -" \n" -"\n" -" \n" -" \n" -" open\n" -" assistant\n" -" \n" -" \n" -" true\n" -" false\n" -" true\n" -" \n" -" tel:09012345678\n" -" \n" -"\n" -" \n" -" \n" -" open\n" -" \n" -" im:pep@example.com\n" -" \n" -"\n" -" \n" -" \n" -" closed\n" -" meeting\n" -" \n" -" http://example.com/~pep/\n" -" http://example.com/~pep/icon.gif\n" -" http://example.com/~pep/card.vcd\n" -" sip:pep@example.com\n" -" \n" -"\n" -" Full state presence document\n" -"\n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -"\n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -"\n" -" \n" -} -; - -static int xml_parse_print_test(const char *doc) -{ - pj_str_t msg; - pj_pool_t *pool; - pj_xml_node *root; - char *output; - int output_len; - - pool = pj_pool_create(mem, "xml", 4096, 1024, NULL); - pj_strdup2(pool, &msg, doc); - root = pj_xml_parse(pool, msg.ptr, msg.slen); - if (!root) { - PJ_LOG(1, (THIS_FILE, " Error: unable to parse XML")); - return -10; - } - - output = (char*)pj_pool_alloc(pool, msg.slen + 512); - pj_memset(output, 0, msg.slen+512); - output_len = pj_xml_print(root, output, msg.slen+512, PJ_TRUE); - if (output_len < 1) { - PJ_LOG(1, (THIS_FILE, " Error: buffer too small to print XML file")); - return -20; - } - output[output_len] = '\0'; - - - pj_pool_release(pool); - return 0; -} - -int xml_test() -{ - unsigned i; - for (i=0; i + * + * Author: + * Benny Prijono + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include "test.h" + + +#if INCLUDE_XML_TEST + +#include +#include + +#define THIS_FILE "xml_test" + +static const char *xml_doc[] = +{ +" \n" +" \n" +"\n" +" \n" +" \n" +" open\n" +" assistant\n" +" \n" +" \n" +" true\n" +" false\n" +" true\n" +" \n" +" tel:09012345678\n" +" \n" +"\n" +" \n" +" \n" +" open\n" +" \n" +" im:pep@example.com\n" +" \n" +"\n" +" \n" +" \n" +" closed\n" +" meeting\n" +" \n" +" http://example.com/~pep/\n" +" http://example.com/~pep/icon.gif\n" +" http://example.com/~pep/card.vcd\n" +" sip:pep@example.com\n" +" \n" +"\n" +" Full state presence document\n" +"\n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +"\n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +"\n" +" \n" +} +; + +static int xml_parse_print_test(const char *doc) +{ + pj_str_t msg; + pj_pool_t *pool; + pj_xml_node *root; + char *output; + int output_len; + + pool = pj_pool_create(mem, "xml", 4096, 1024, NULL); + pj_strdup2(pool, &msg, doc); + root = pj_xml_parse(pool, msg.ptr, msg.slen); + if (!root) { + PJ_LOG(1, (THIS_FILE, " Error: unable to parse XML")); + return -10; + } + + output = (char*)pj_pool_alloc(pool, msg.slen + 512); + pj_memset(output, 0, msg.slen+512); + output_len = pj_xml_print(root, output, msg.slen+512, PJ_TRUE); + if (output_len < 1) { + PJ_LOG(1, (THIS_FILE, " Error: buffer too small to print XML file")); + return -20; + } + output[output_len] = '\0'; + + + pj_pool_release(pool); + return 0; +} + +int xml_test() +{ + unsigned i; + for (i=0; i