From: <vac...@us...> - 2010-04-10 08:39:45
|
Revision: 180 http://xmlwrapp.svn.sourceforge.net/xmlwrapp/?rev=180&view=rev Author: vaclavslavik Date: 2010-04-10 08:39:38 +0000 (Sat, 10 Apr 2010) Log Message: ----------- Fix error handling in tree_parser without exceptions. If libxml2 returned NULL document without errors (e.g. because a missing file is just a warning in it), pimpl_->okay_ was left as true. This was not only clearly wrong, but also inconsistent with exceptions handling: if exceptions were allowed, an exception _would_ be thrown in this situation. Modified Paths: -------------- trunk/src/libxml/tree_parser.cxx trunk/tests/tree/test_tree.cxx Modified: trunk/src/libxml/tree_parser.cxx =================================================================== --- trunk/src/libxml/tree_parser.cxx 2010-04-10 08:39:16 UTC (rev 179) +++ trunk/src/libxml/tree_parser.cxx 2010-04-10 08:39:38 UTC (rev 180) @@ -160,6 +160,8 @@ if (tmpdoc) xmlFreeDoc(tmpdoc); + pimpl_->okay_ = false; + if (allow_exceptions) throw xml::exception(pimpl_->last_error_); } @@ -192,6 +194,7 @@ ctxt->myDoc = 0; ctxt->sax = 0; xmlFreeParserCtxt(ctxt); + pimpl_->okay_ = false; if (allow_exceptions) Modified: trunk/tests/tree/test_tree.cxx =================================================================== --- trunk/tests/tree/test_tree.cxx 2010-04-10 08:39:16 UTC (rev 179) +++ trunk/tests/tree/test_tree.cxx 2010-04-10 08:39:38 UTC (rev 180) @@ -140,6 +140,23 @@ } +// test reporting of nonexistent files +BOOST_AUTO_TEST_CASE( nonexistent_file ) +{ + xml::tree_parser parser("doesnt_exist.xml", false); + BOOST_CHECK( !parser ); // failed +} + +BOOST_AUTO_TEST_CASE( nonexistent_file_throw ) +{ + BOOST_CHECK_THROW + ( + xml::tree_parser parser("doesnt_exist.xml"), + xml::exception + ); +} + + /* * this test should print out an outline of the input xml doc */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |