Fix check_xml that ignored attributes.
authorCarl Hetherington <cth@carlh.net>
Thu, 30 Apr 2015 14:31:14 +0000 (15:31 +0100)
committerCarl Hetherington <cth@carlh.net>
Thu, 30 Apr 2015 14:31:14 +0000 (15:31 +0100)
test/test.cc

index 67d6f2bd2f40b21c8f5c859c69cb9450696edc16..2620800bcc95354ce6e0fe0131d11dadabbc95ce 100644 (file)
@@ -225,15 +225,15 @@ check_xml (xmlpp::Element* ref, xmlpp::Element* test, list<string> ignore)
        if (find (ignore.begin(), ignore.end(), ref->get_name()) != ignore.end ()) {
                return;
        }
-           
+
        xmlpp::Element::NodeList ref_children = ref->get_children ();
        xmlpp::Element::NodeList test_children = test->get_children ();
        BOOST_CHECK_EQUAL (ref_children.size (), test_children.size ());
 
        xmlpp::Element::NodeList::iterator k = ref_children.begin ();
        xmlpp::Element::NodeList::iterator l = test_children.begin ();
-       while (k != ref_children.end () && l != test_children.end ()) {
-               
+       while (k != ref_children.end ()) {
+
                /* XXX: should be doing xmlpp::EntityReference, xmlpp::XIncludeEnd, xmlpp::XIncludeStart */
 
                xmlpp::Element* ref_el = dynamic_cast<xmlpp::Element*> (*k);
@@ -250,20 +250,23 @@ check_xml (xmlpp::Element* ref, xmlpp::Element* test, list<string> ignore)
                        BOOST_CHECK_EQUAL (ref_cn->get_content(), test_cn->get_content ());
                }
 
-               xmlpp::Attribute* ref_at = dynamic_cast<xmlpp::Attribute*> (*k);
-               xmlpp::Attribute* test_at = dynamic_cast<xmlpp::Attribute*> (*l);
-               BOOST_CHECK ((ref_at && test_at) || (!ref_at && !test_at));
-               if (ref_at && test_at) {
-                       BOOST_CHECK_EQUAL (ref_at->get_name(), test_at->get_name ());
-                       BOOST_CHECK_EQUAL (ref_at->get_value(), test_at->get_value ());
-               }
-
                ++k;
                ++l;
        }
 
-       BOOST_CHECK (k == ref_children.end ());
-       BOOST_CHECK (l == test_children.end ());
+       xmlpp::Element::AttributeList ref_attributes = ref->get_attributes ();
+       xmlpp::Element::AttributeList test_attributes = test->get_attributes ();
+       BOOST_CHECK_EQUAL (ref_attributes.size(), test_attributes.size ());
+
+       xmlpp::Element::AttributeList::const_iterator m = ref_attributes.begin();
+       xmlpp::Element::AttributeList::const_iterator n = test_attributes.begin();
+       while (m != ref_attributes.end ()) {
+               BOOST_CHECK_EQUAL ((*m)->get_name(), (*n)->get_name());
+               BOOST_CHECK_EQUAL ((*m)->get_value(), (*n)->get_value());
+
+               ++m;
+               ++n;
+       }
 }
 
 void