diff options
| author | Baptiste Lepilleur <gaiacrtn@free.fr> | 2001-10-05 07:06:28 +0000 |
|---|---|---|
| committer | Baptiste Lepilleur <gaiacrtn@free.fr> | 2001-10-05 07:06:28 +0000 |
| commit | 6a1755ef0e36aeb1ac2df0a46e5dafe08a4699ee (patch) | |
| tree | ee4ef2f3f3b7dcacdbe71fe14bd6bb362a2351ad /examples/cppunittest/XmlUniformiser.cpp | |
| parent | c2ac2ac3bcfb30cb8ae4e95e531f1b630b8dd80e (diff) | |
| download | cppunit-6a1755ef0e36aeb1ac2df0a46e5dafe08a4699ee.tar.gz | |
NEWS : updated.
NEWS : updated.
* include/cppunit/Exception.h : added include Portability.h.
* include/cppunit/TestResult.* : changed TestFailures to a deque.
added tests().
* examples/cppunittest/CppUnitTest.dsp :
* examples/cppunittest/MakeFile.am :
* examples/msvc6/CppUnitTestApp/CppUnitTestApp.dsp : Added
XmlTestResultOutputterTest.*, XmlUniformiser.*, XmlUniformiserTest.*,
UnitTestToolSuite.h, OutputSuite.h.
* examples/msvc6/CppUnitTestApp/CppUnitTestApp.dsp : revised project
folders structure. Added missing NoteEqualExceptionTest.*.
* examples/cppunittest/CppUnitTestSuite.cpp : added 'Output' and
'UnitTestTool' suites.
* src/cppunit/cppunit.dsp: removed estring.h. Revised project folders
structure. Removed TestRegistry.*. Added TestSetUp.h,
XmlTestResultOutputter.*.
* src/cppunit/MakeFile.am: added XmlTestResultOutputter.*.
* src/testrunner/TestRunnerDlg.cpp: removed disabled code.
Diffstat (limited to 'examples/cppunittest/XmlUniformiser.cpp')
| -rw-r--r-- | examples/cppunittest/XmlUniformiser.cpp | 228 |
1 files changed, 228 insertions, 0 deletions
diff --git a/examples/cppunittest/XmlUniformiser.cpp b/examples/cppunittest/XmlUniformiser.cpp new file mode 100644 index 0000000..509cce5 --- /dev/null +++ b/examples/cppunittest/XmlUniformiser.cpp @@ -0,0 +1,228 @@ +#include "XmlUniformiser.h" + +namespace CppUnitTest +{ + + +/// Asserts that two XML string are equivalent. +void +checkXmlEqual( std::string expectedXml, + std::string actualXml ) +{ + std::string expected = XmlUniformiser( expectedXml ).stripped(); + std::string actual = XmlUniformiser( actualXml ).stripped(); + int index =0; + while ( index < actual.length() && + index < expected.length() ) + { + if ( actual[index] != expected[index] ) + { + CppUnit::OStringStream message; + message << "expected xml: " << expected << "\n" + << "actual xml : " << actual << "\n" + << "differ at column: " << index << "\n" + << "expected: " << expected.substr(index) << "\n" + << "but was : " << actual.substr( index ); + CPPUNIT_FAIL( message.str() ); + } + + ++index; + } + + if ( actual.length() != expected.length() ) + { + CppUnit::OStringStream message; + message << "expected: " << expected << "\n" + << "was : " << actual << "\n" + << "differ at column: " << index << "\n" + << "expected: " << expected.substr(index) << "\n" + << "but was : " << actual.substr( index ); + CPPUNIT_FAIL( message.str() ); + } +} + + + +XmlUniformiser::XmlUniformiser( const std::string &xml ) : + m_xml( xml ), + m_index( 0 ) +{ +} + + +std::string +XmlUniformiser::stripped() +{ + while ( isValidIndex() ) + { + skipSpaces(); + if ( startsWith( "<?" ) ) + skipProcessed(); + else if ( startsWith( "<!--" ) ) + skipComment(); + else if ( startsWith( "<" ) ) + copyElement(); + else + copyElementContent(); + } + return m_stripped; +} + + +void +XmlUniformiser::skipSpaces() +{ + while ( isSpace() ) + skipNext(); +} + + +bool +XmlUniformiser::isSpace( char c ) +{ + return c < 33; +} + + +bool +XmlUniformiser::isSpace() +{ + return isValidIndex() && isSpace( m_xml[m_index] ); +} + + +bool +XmlUniformiser::isValidIndex() +{ + return m_index < m_xml.length(); +} + + +void +XmlUniformiser::skipNext( int count ) +{ + while ( count-- > 0 ) + ++m_index; +} + + +void +XmlUniformiser::copyNext( int count ) +{ + while ( count-- > 0 && isValidIndex() ) + m_stripped += m_xml[ m_index++ ]; +} + + +bool +XmlUniformiser::startsWith( std::string expected ) +{ + std::string actual = m_xml.substr( m_index, expected.length() ); + return actual == expected; +} + + +void +XmlUniformiser::skipProcessed() +{ + while ( isValidIndex() && !startsWith( "?>" ) ) + skipNext(); + if ( isValidIndex() ) + skipNext( 2 ); +} + + +void +XmlUniformiser::skipComment() +{ + while ( isValidIndex() && !startsWith( "-->" ) ) + skipNext(); + if ( isValidIndex() ) + skipNext( 3 ); +} + + +void +XmlUniformiser::copyElement() +{ + copyElementName(); + copyElementAttributes(); +} + + +void +XmlUniformiser::copyElementName() +{ + while ( isValidIndex() && + !( isSpace() || startsWith( ">" ) ) ) + copyNext(); +} + + +void +XmlUniformiser::copyElementAttributes() +{ + do + { + skipSpaces(); + if ( startsWith( ">" ) ) + break; + m_stripped += ' '; + + copyAttributeName(); + skipSpaces(); + if ( startsWith( "=" ) ) + { + copyNext(); + copyAttributeValue(); + } + else // attribute should always be valued, ne ? + m_stripped += ' '; + } + while ( isValidIndex() ); + copyNext(); +} + + +void +XmlUniformiser::copyAttributeName() +{ + while ( isValidIndex() && !isEndOfAttributeName() ) + copyNext(); +} + + +bool +XmlUniformiser::isEndOfAttributeName() +{ + return isSpace() || startsWith( ">" ) || startsWith( "=" ); +} + + +void +XmlUniformiser::copyAttributeValue() +{ + skipSpaces(); + copyUntilDoubleQuote(); + copyUntilDoubleQuote(); +} + + +void +XmlUniformiser::copyUntilDoubleQuote() +{ + while ( isValidIndex() && !startsWith("\"") ) + copyNext(); + copyNext(); // '"' +} + + +void +XmlUniformiser::copyElementContent() +{ + while ( isValidIndex() && !startsWith( "<" ) ) + copyNext(); +} + + +} // namespace CppUnitTest |
