1
/* $Id: xml.c 3553 2011-05-05 06:14:19Z nanang $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
#include <pjlib-util/xml.h>
28
#define THIS_FILE "xml_test"
30
static const char *xml_doc[] =
32
" <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
33
" <p:pidf-full xmlns=\"urn:ietf:params:xml:ns:pidf\"\n"
34
" xmlns:p=\"urn:ietf:params:xml:ns:pidf-diff\"\n"
35
" xmlns:r=\"urn:ietf:params:xml:ns:pidf:rpid\"\n"
36
" xmlns:c=\"urn:ietf:params:xml:ns:pidf:caps\"\n"
37
" entity=\"pres:someone@example.com\"\n"
40
" <tuple id=\"sg89ae\">\n"
42
" <basic>open</basic>\n"
43
" <r:relationship>assistant</r:relationship>\n"
46
" <c:audio>true</c:audio>\n"
47
" <c:video>false</c:video>\n"
48
" <c:message>true</c:message>\n"
50
" <contact priority=\"0.8\">tel:09012345678</contact>\n"
53
" <tuple id=\"cg231jcr\">\n"
55
" <basic>open</basic>\n"
57
" <contact priority=\"1.0\">im:pep@example.com</contact>\n"
60
" <tuple id=\"r1230d\">\n"
62
" <basic>closed</basic>\n"
63
" <r:activity>meeting</r:activity>\n"
65
" <r:homepage>http://example.com/~pep/</r:homepage>\n"
66
" <r:icon>http://example.com/~pep/icon.gif</r:icon>\n"
67
" <r:card>http://example.com/~pep/card.vcd</r:card>\n"
68
" <contact priority=\"0.9\">sip:pep@example.com</contact>\n"
71
" <note xml:lang=\"en\">Full state presence document</note>\n"
76
" <r:on-the-phone/>\n"
82
" <r:device id=\"urn:esn:600b40c7\">\n"
98
static int xml_parse_print_test(const char *doc)
106
pool = pj_pool_create(mem, "xml", 4096, 1024, NULL);
107
pj_strdup2(pool, &msg, doc);
108
root = pj_xml_parse(pool, msg.ptr, msg.slen);
110
PJ_LOG(1, (THIS_FILE, " Error: unable to parse XML"));
114
output = (char*)pj_pool_zalloc(pool, msg.slen + 512);
115
output_len = pj_xml_print(root, output, msg.slen+512, PJ_TRUE);
116
if (output_len < 1) {
117
PJ_LOG(1, (THIS_FILE, " Error: buffer too small to print XML file"));
120
output[output_len] = '\0';
123
pj_pool_release(pool);
130
for (i=0; i<sizeof(xml_doc)/sizeof(xml_doc[0]); ++i) {
132
if ((status=xml_parse_print_test(xml_doc[i])) != 0)
139
/* To prevent warning about "translation unit is empty"
140
* when this test is disabled.
143
#endif /* INCLUDE_XML_TEST */