1 #ifndef CPPUNITTEST_XMLUNIFORMISER_H
2 #define CPPUNITTEST_XMLUNIFORMISER_H
3 
4 #include <cppunit/SourceLine.h>
5 #include <cppunit/TestAssert.h>
6 #include <string>
7 
8 
9 /*! Uniformise an XML string.
10  *
11  * Strips spaces between attribut in Element.
12  * \warning Attribute values must be double-quoted (att="value").
13  * No support for embedded DTD declaration
14  */
15 class XmlUniformiser
16 {
17 public:
18   XmlUniformiser( const std::string &xml );
19   std::string stripped();
20 
21 private:
22   void skipSpaces();
23   bool isValidIndex();
24   void skipNext( int count =1 );
25   void copyNext( int count =1 );
26   void skipProcessed();
27   void skipComment();
28   void copyElement();
29   void copyElementContent();
30   bool isSpace( char c );
31   bool isSpace();
32   bool startsWith( std::string expected );
33   void copyElementName();
34   void copyElementAttributes();
35   void copyAttributeName();
36   bool isEndOfAttributeName();
37   void copyAttributeValue();
38   void copyUntilDoubleQuote();
39   void removeTrailingSpaces();
40 
41 private:
42   unsigned int m_index;
43   std::string m_xml;
44   std::string m_stripped;
45 };
46 
47 
48 
49 
50 void
51 checkXmlEqual( std::string expectedXml,
52                std::string actualXml,
53                CPPUNIT_NS::SourceLine sourceLine );
54 
55 
56 /// Asserts that two XML strings are equivalent.
57 #define CPPUNITTEST_ASSERT_XML_EQUAL( expected, actual ) \
58     ::checkXmlEqual( expected, actual,      \
59                      CPPUNIT_SOURCELINE() )
60 
61 
62 
63 #endif  // XMLUNIFORMISER_H
64