/[resiprocate]/main/rutil/test/testXMLCursor.cxx
ViewVC logotype

Contents of /main/rutil/test/testXMLCursor.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9392 - (show annotations) (download)
Fri Feb 10 18:19:59 2012 UTC (7 years, 9 months ago) by sgodin
File MIME type: text/plain
File size: 13336 byte(s)
-merged work from b-repro-enh-20120205 branch

-added a new Command interface/server to repro that operates over a TCP socket and uses
 XML formatted messaging
-implemented the following commands:
  - GetStackInfo
  - GetStackStats
  - ResetStackStats
  - LogDnsCache
  - ClearDnsCache
  - GetDnsCache
  - GetCongestionStats
  - SetCongestionTolerance
  - Shutdown
  - GetProxyConfig
-added new reprocmd executable that connects to repro via new command socket server and sends commands
 base on command line arguments
-moved XMLCursor class from resip/stack to rutil

-added operator<< for Statistics Payload
-added ability to encode Congestion stats to a stream 
-modified GeneralCongestionManager::updateFifoTolerance to allow updating
 all fifos by specifying fifoDescription as an empty string
-added current fifo behaviour and tolerance settings to congestion stats output
-renamed configuration setting XmlRpcPort to RegSyncPort to differentiate it with new Command Port setting
-add new TCP server (CommandServer) to repro that accepts commands via XML formatted messages
-allow SipStack statistics to be reset/zero'd out
-modified GetStackStats command to be able to retrieve statistics that are accurate at the time of the request, 
 instead of just returning the statistics as of the last statistics interval
-added operator<< to ConfigParse

1 #include "rutil/XMLCursor.hxx"
2 #include "rutil/DataStream.hxx"
3 #include "rutil/Inserter.hxx"
4 #include "rutil/Logger.hxx"
5
6 #include <iostream>
7
8 #include <cassert>
9
10 using namespace resip;
11 using namespace std;
12
13 /*
14 <foo/>
15 <foo></foo>
16 <foo>some contents</foo>
17 <foo><echild/><child>first</child><child>second</child></foo>
18 <foo bar="baz" qwerty = "quux"/>
19 <foo bar="baz" qwerty = "quux">contents</foo>
20 */
21
22 void traverse(XMLCursor& c)
23 {
24 if (c.firstChild())
25 {
26 traverse(c);
27 c.parent();
28 }
29
30 // process(c);
31 std::cerr << c.getTag() << std::endl;
32
33 if (c.nextSibling())
34 {
35 traverse(c);
36 }
37 }
38
39 int
40 main()
41 {
42 Log::initialize(Log::Cout, Log::Stack, "testXMLCursor");
43
44 {
45 const Data test(
46 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
47 "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\"\r\n"
48 " xmlns:ep=\"urn:ietf:params:xml:ns:pidf:rpid:rpid-person\"\r\n"
49 " xmlns:pp=\"urn:ietf:params:xml:ns:pidf:person\"\r\n"
50 " entity=\"sip:chris@xxx.xx.xxx.xx\">\r\n"
51 " <pp:person>\r\n"
52 " <status>\r\n"
53 " <ep:activities>\r\n"
54 " <ep:activity>away</ep:activity>\r\n"
55 " </ep:activities>\r\n"
56 " </status>\r\n"
57 " </pp:person>\r\n"
58 " <tuple id=\"9b6yhF2Gk37o4\" >\r\n"
59 " <status><basic>open</basic></status>\r\n"
60 " </tuple>\r\n"
61 "</presence>");
62
63 try
64 {
65 XMLCursor xmlc(ParseBuffer(test.data(), test.size()));
66
67 assert(xmlc.getTag() == "presence");
68 traverse(xmlc);
69 }
70 catch (ParseException& e)
71 {
72 cerr << e << endl;
73 assert(false);
74 }
75 }
76
77 // Tests for XML comment handling
78 {
79 const Data test(
80 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
81 "<!--Comment1-->\r\n"
82 "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\"\r\n"
83 " xmlns:ep=\"urn:ietf:params:xml:ns:pidf:rpid:rpid-person\"\r\n"
84 " xmlns:pp=\"urn:ietf:params:xml:ns:pidf:person\"\r\n"
85 " entity=\"sip:chris@xxx.xx.xxx.xx\">\r\n"
86 "<!--Comment2-->\r\n"
87 " <pp:person>\r\n"
88 " <status>\r\n"
89 " <!--Comment3-->\r\n"
90 " <ep:activities>\r\n"
91 " <ep:activity>away</ep:activity>\r\n"
92 " </ep:activities>\r\n"
93 " </status>\r\n"
94 " </pp:person>\r\n"
95 " <tuple id=\"9b6yhF2Gk37o4\" >\r\n"
96 " <status><basic>open</basic></status>\r\n"
97 "<!--Comment4-->\r\n"
98 " </tuple>\r\n"
99 "<!--Comment5-->\r\n"
100 "</presence>"
101 "<!--Comment6-->\r\n");
102
103 try
104 {
105 XMLCursor xmlc(ParseBuffer(test.data(), test.size()));
106
107 assert(xmlc.getTag() == "presence");
108 traverse(xmlc);
109 }
110 catch (ParseException& e)
111 {
112 cerr << e << endl;
113 assert(false);
114 }
115 }
116
117 // test assume that whitespace is not significant
118 // may eventually be controlled by the document/element
119 // see http://www.w3.org/TR/1998/REC-xml-19980210#sec-white-space
120 assert(!XMLCursor::WhitespaceSignificant);
121
122 {
123 cerr << "test attributes in self-terminating tag" << endl;
124 Data contents("<?xml version=\"1.0\"?><root><foo attr=\"true\"/></root>");
125 try
126 {
127 XMLCursor xmlc(ParseBuffer(contents.data(), contents.size()));
128
129 assert(xmlc.getTag() == "root");
130 assert(xmlc.getValue().empty());
131 assert(xmlc.getAttributes().empty());
132 assert(xmlc.atRoot());
133 assert(!xmlc.atLeaf());
134 assert(!xmlc.parent());
135 assert(xmlc.firstChild());
136 assert(xmlc.getValue().empty());
137 assert(!xmlc.getAttributes().empty());
138 assert(!xmlc.nextSibling());
139 }
140 catch (ParseException& e)
141 {
142 cerr << e << endl;
143 assert(false);
144 }
145 }
146
147 {
148 cerr << "test empty root" << endl;
149 Data contents("<?xml version=\"1.0\"?><foo/>");
150 try
151 {
152 XMLCursor xmlc(ParseBuffer(contents.data(), contents.size()));
153
154 assert(xmlc.getTag() == "foo");
155 assert(xmlc.getValue().empty());
156 assert(xmlc.getAttributes().empty());
157 assert(xmlc.atRoot());
158 assert(!xmlc.atLeaf());
159 assert(!xmlc.parent());
160 assert(!xmlc.firstChild());
161 xmlc.reset();
162 assert(!xmlc.nextSibling());
163 assert(false);
164 }
165 catch (ParseException& e)
166 {
167 }
168 }
169
170 {
171 cerr << "test childless root" << endl;
172 Data contents("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
173 "<foo> </foo>");
174 XMLCursor xmlc(ParseBuffer(contents.data(), contents.size()));
175
176 assert(xmlc.getTag() == "foo");
177 cerr << "value: |" << xmlc.getValue() << "|" << endl;
178 assert(xmlc.getValue().empty());
179 assert(xmlc.getAttributes().empty());
180 assert(xmlc.atRoot());
181 assert(!xmlc.atLeaf());
182 assert(!xmlc.parent());
183 assert(!xmlc.firstChild());
184 xmlc.reset();
185 assert(!xmlc.nextSibling());
186 }
187
188 {
189 cerr << "test childless root with attributes" << endl;
190 Data contents("<?xml version=\"1.0\"?><foo bar=\"baz\" attribute = 'value' ></foo>");
191 XMLCursor xmlc(ParseBuffer(contents.data(), contents.size()));
192
193 assert(xmlc.getTag() == "foo");
194 assert(xmlc.getValue().empty());
195 resipCerr << Inserter(xmlc.getAttributes()) << endl;
196 assert(xmlc.getAttributes().size() == 2);
197 assert(xmlc.getAttributes().find("bar") != xmlc.getAttributes().end());
198 assert(xmlc.atRoot());
199 assert(!xmlc.atLeaf());
200 assert(!xmlc.parent());
201 assert(!xmlc.firstChild());
202 xmlc.reset();
203 assert(!xmlc.nextSibling());
204 }
205
206 {
207 cerr << "test empty child" << endl;
208 Data contents("<?xml version=\"1.0\"?><foo><child/></foo>");
209 XMLCursor xmlc(ParseBuffer(contents.data(), contents.size()));
210
211 assert(xmlc.getTag() == "foo");
212 assert(xmlc.getValue().empty());
213 assert(xmlc.getAttributes().size() == 0);
214 assert(xmlc.atRoot());
215 assert(!xmlc.atLeaf());
216 assert(!xmlc.parent());
217
218 assert(xmlc.firstChild());
219 assert(xmlc.getTag() == "child");
220 assert(!xmlc.firstChild());
221 assert(!xmlc.nextSibling());
222 assert(xmlc.parent());
223 assert(xmlc.getTag() == "foo");
224 assert(xmlc.firstChild());
225
226 xmlc.reset();
227 assert(xmlc.getTag() == "foo");
228 assert(!xmlc.nextSibling());
229 }
230
231 {
232 cerr << "test contentless child" << endl;
233 Data contents("<?xml version=\"1.0\"?> <foo><child></child></foo>");
234 XMLCursor xmlc(ParseBuffer(contents.data(), contents.size()));
235
236 assert(xmlc.getTag() == "foo");
237 assert(xmlc.getValue().empty());
238 assert(xmlc.getAttributes().size() == 0);
239 assert(xmlc.atRoot());
240 assert(!xmlc.atLeaf());
241 assert(!xmlc.parent());
242
243 assert(xmlc.firstChild());
244 assert(xmlc.getTag() == "child");
245 assert(!xmlc.firstChild());
246 assert(!xmlc.nextSibling());
247 assert(xmlc.parent());
248 assert(xmlc.getTag() == "foo");
249 assert(xmlc.firstChild());
250 assert(xmlc.parent());
251 assert(xmlc.getTag() == "foo");
252 assert(xmlc.firstChild());
253
254 xmlc.reset();
255 assert(xmlc.getTag() == "foo");
256 assert(!xmlc.nextSibling());
257 }
258
259 {
260 cerr << "test tree" << endl;
261 Data contents("<?xml version=\"1.0\"?> \n"
262 "<root>\n"
263 " <P1>\n"
264 " <A1></A1>\n"
265 " <A2></A2>\n"
266 " </P1>\n"
267 " <P2>\n"
268 " <B1></B1>\n"
269 " <B2></B2>\n"
270 " </P2>\n"
271 " </root> ");
272
273 XMLCursor tree(ParseBuffer(contents.data(), contents.size()));
274
275 assert(tree.atRoot());
276 assert(tree.firstChild());
277 assert(tree.getTag() == "P1");
278 assert(tree.firstChild());
279 assert(tree.getTag() == "A1");
280
281 assert(tree.parent());
282 assert(tree.getTag() == "P1");
283 assert(tree.firstChild());
284
285 assert(tree.nextSibling());
286 assert(tree.getTag() == "A2");
287 assert(tree.parent());
288 assert(!tree.atRoot());
289 assert(tree.nextSibling());
290 assert(tree.getTag() == "P2");
291 assert(tree.firstChild());
292 assert(tree.getTag() == "B1");
293 assert(tree.nextSibling());
294 assert(tree.getTag() == "B2");
295 assert(!tree.nextSibling());
296 assert(tree.parent());
297 assert(!tree.nextSibling());
298 }
299
300 {
301 cerr << "test leafy tree" << endl;
302 Data contents("<?xml version=\"1.0\"?> <root>Pie<P1 attribute = \"value\">I<A1>wish</A1>I<A2>could</A2>recollect</P1>pi"
303 "<P2>eureka<B1>cried</B1>the<B2>great</B2>professor</P2>christmas</root> ");
304 XMLCursor tree(ParseBuffer(contents.data(), contents.size()));
305
306 assert(tree.firstChild());
307 assert(tree.atLeaf());
308 assert(tree.getTag().empty());
309 assert(tree.getValue() == "Pie");
310 assert(tree.nextSibling());
311 assert(tree.getTag() == "P1");
312 assert(tree.getAttributes().size() == 1);
313 assert(tree.nextSibling());
314 assert(tree.getTag().empty());
315 assert(tree.getValue() == "pi");
316 assert(tree.nextSibling());
317 assert(tree.getTag() == "P2");
318 assert(tree.nextSibling());
319 assert(tree.getTag().empty());
320 assert(tree.getValue() == "christmas");
321 assert(!tree.nextSibling());
322 }
323
324 {
325 cerr << "test CRLF canonicalization" << endl;
326
327 Data contents("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
328 "<list xmlns=\"urn:ietf:params:xml:ns:rmli\"\r\n"
329 " uri=\"sip:adam-friends@pres.example.com\" version=\"2\"\r\n"
330 " name=\"Buddy List at COM\" fullState=\"false\">\r\n"
331 " <resource uri=\"sip:ed@example.net\" name=\"Ed at NET\">\r\n"
332 " <instance id=\"sdlkmeopdf\" state=\"pending\"/>\r\n"
333 " </resource>\r\n"
334 " <resource uri=\"sip:adam-friends@example.org\"\r\n"
335 " name=\"My Friends at ORG\">\r\n"
336 " <instance id=\"cmpqweitlp\" state=\"active\"\r\n"
337 " cid=\"1KQhyE@pres.example.com\"/>\r\n"
338 " </resource>\r\n"
339 "</list>");
340
341 XMLCursor tree(ParseBuffer(contents.data(), contents.size()));
342
343 cerr << "root tag = |" << tree.getTag() << "|" << endl;
344 assert(tree.getTag() == "list");
345 tree.firstChild();
346 do
347 {
348 cerr << tree.getTag() << endl;
349 }
350 while (tree.nextSibling());
351
352
353 assert(tree.getTag() == "resource");
354 }
355
356 cerr << "All OK" << endl;
357
358 return 0;
359 }
360 /* ====================================================================
361 * The Vovida Software License, Version 1.0
362 *
363 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
364 *
365 * Redistribution and use in source and binary forms, with or without
366 * modification, are permitted provided that the following conditions
367 * are met:
368 *
369 * 1. Redistributions of source code must retain the above copyright
370 * notice, this list of conditions and the following disclaimer.
371 *
372 * 2. Redistributions in binary form must reproduce the above copyright
373 * notice, this list of conditions and the following disclaimer in
374 * the documentation and/or other materials provided with the
375 * distribution.
376 *
377 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
378 * and "Vovida Open Communication Application Library (VOCAL)" must
379 * not be used to endorse or promote products derived from this
380 * software without prior written permission. For written
381 * permission, please contact vocal@vovida.org.
382 *
383 * 4. Products derived from this software may not be called "VOCAL", nor
384 * may "VOCAL" appear in their name, without prior written
385 * permission of Vovida Networks, Inc.
386 *
387 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
388 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
389 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
390 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
391 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
392 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
393 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
394 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
395 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
396 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
397 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
398 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
399 * DAMAGE.
400 *
401 * ====================================================================
402 *
403 * This software consists of voluntary contributions made by Vovida
404 * Networks, Inc. and many individuals on behalf of Vovida Networks,
405 * Inc. For more information on Vovida Networks, Inc., please see
406 * <http://www.vovida.org/>.
407 *
408 */

Properties

Name Value
svn:eol-style native
svn:mime-type text/plain

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27