diff options
author | Mike Buland <eichlan@xagasoft.com> | 2006-05-26 14:36:57 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2006-05-26 14:36:57 +0000 |
commit | a820665eea71a64b40e74ed24afeaf07a7a99db4 (patch) | |
tree | 515af31ac2ed78aa92ce7e90e478bdb452e6e438 /src/xmlreader.cpp | |
parent | bd5bb1ca60a6a97b110cbf221b3625e6e6200141 (diff) | |
download | libbu++-a820665eea71a64b40e74ed24afeaf07a7a99db4.tar.gz libbu++-a820665eea71a64b40e74ed24afeaf07a7a99db4.tar.bz2 libbu++-a820665eea71a64b40e74ed24afeaf07a7a99db4.tar.xz libbu++-a820665eea71a64b40e74ed24afeaf07a7a99db4.zip |
Added the first of many unit tests. For now the unit tests are just built with
everything else in the all target of the makefile, which is fine, but relies on
CppTest, which can be found at http://cpptest.sf.net
Also fixed some things I've been meaning to get to for a while in the xml
system, including a few bugs that will make coping with malformed data not hang
other programs, and do the error reporting in a nice way.
Diffstat (limited to 'src/xmlreader.cpp')
-rw-r--r-- | src/xmlreader.cpp | 38 |
1 files changed, 11 insertions, 27 deletions
diff --git a/src/xmlreader.cpp b/src/xmlreader.cpp index bb24157..76c6258 100644 --- a/src/xmlreader.cpp +++ b/src/xmlreader.cpp | |||
@@ -1,10 +1,10 @@ | |||
1 | #include "xmlreader.h" | 1 | #include "xmlreader.h" |
2 | #include "xmlexception.h" | ||
2 | #include <string.h> | 3 | #include <string.h> |
3 | 4 | ||
4 | XmlReader::XmlReader( bool bStrip ) | 5 | XmlReader::XmlReader( bool bStrip ) : |
6 | bStrip( bStrip ) | ||
5 | { | 7 | { |
6 | nError = 0; | ||
7 | this->bStrip = bStrip; | ||
8 | } | 8 | } |
9 | 9 | ||
10 | XmlReader::~XmlReader() | 10 | XmlReader::~XmlReader() |
@@ -68,13 +68,12 @@ bool XmlReader::node() | |||
68 | } | 68 | } |
69 | else | 69 | else |
70 | { | 70 | { |
71 | reportError("Close node in singleNode malformed!"); | 71 | throw XmlException("Close node in singleNode malformed!"); |
72 | return false; | ||
73 | } | 72 | } |
74 | } | 73 | } |
75 | else | 74 | else |
76 | { | 75 | { |
77 | reportError("Close node expected, but not found."); | 76 | throw XmlException("Close node expected, but not found."); |
78 | return false; | 77 | return false; |
79 | } | 78 | } |
80 | 79 | ||
@@ -108,8 +107,7 @@ bool XmlReader::startNode() | |||
108 | } | 107 | } |
109 | else | 108 | else |
110 | { | 109 | { |
111 | reportError("Got a mismatched node close tag."); | 110 | throw XmlException("Got a mismatched node close tag."); |
112 | return false; | ||
113 | } | 111 | } |
114 | } | 112 | } |
115 | else | 113 | else |
@@ -127,8 +125,7 @@ bool XmlReader::startNode() | |||
127 | } | 125 | } |
128 | else | 126 | else |
129 | { | 127 | { |
130 | reportError("Got extra junk data instead of node close tag."); | 128 | throw XmlException("Got extra junk data instead of node close tag."); |
131 | return false; | ||
132 | } | 129 | } |
133 | } | 130 | } |
134 | else | 131 | else |
@@ -146,8 +143,7 @@ bool XmlReader::startNode() | |||
146 | } | 143 | } |
147 | else | 144 | else |
148 | { | 145 | { |
149 | reportError("Expected to find node opening char, '<'.\n"); | 146 | throw XmlException("Expected to find node opening char, '<'."); |
150 | return false; | ||
151 | } | 147 | } |
152 | 148 | ||
153 | return true; | 149 | return true; |
@@ -306,7 +302,7 @@ bool XmlReader::param() | |||
306 | } | 302 | } |
307 | else | 303 | else |
308 | { | 304 | { |
309 | reportError("Expected an equals to seperate the params."); | 305 | throw XmlException("Expected an equals to seperate the params."); |
310 | return false; | 306 | return false; |
311 | } | 307 | } |
312 | 308 | ||
@@ -352,8 +348,7 @@ bool XmlReader::content() | |||
352 | } | 348 | } |
353 | else | 349 | else |
354 | { | 350 | { |
355 | reportError("Mismatched close tag found."); | 351 | throw XmlException("Mismatched close tag found: <%s> to <%s>.", getCurrent()->getName(), fbName.getData() ); |
356 | return false; | ||
357 | } | 352 | } |
358 | } | 353 | } |
359 | else | 354 | else |
@@ -370,8 +365,7 @@ bool XmlReader::content() | |||
370 | } | 365 | } |
371 | else | 366 | else |
372 | { | 367 | { |
373 | reportError("Malformed close tag."); | 368 | throw XmlException("Malformed close tag."); |
374 | return false; | ||
375 | } | 369 | } |
376 | } | 370 | } |
377 | else | 371 | else |
@@ -400,13 +394,3 @@ bool XmlReader::content() | |||
400 | } | 394 | } |
401 | } | 395 | } |
402 | 396 | ||
403 | void XmlReader::reportError( const char *sError ) | ||
404 | { | ||
405 | printf("XmlReader error: %s\n", sError ); | ||
406 | } | ||
407 | |||
408 | int XmlReader::getError() | ||
409 | { | ||
410 | return nError; | ||
411 | } | ||
412 | |||