summaryrefslogtreecommitdiff
path: root/sax/qa
diff options
context:
space:
mode:
authorMohammed Abdul Azeem <azeemmysore@gmail.com>2016-06-13 23:30:09 +0530
committerMichael Meeks <michael.meeks@collabora.com>2016-06-17 10:04:58 +0000
commit551a5066fcc8000850d34408d8c1bcdd5b599db3 (patch)
tree3db4333c535b828e61147d4a7c34bc02d27590d6 /sax/qa
parent4561119a8bab986df25a5ce2a544aa96394cbd5d (diff)
GSoC: Mapping legacy sax parser and XFastParser
This implements legacy parser interface using XFastParser, and unit test is also added. Change-Id: Ia2eb7d517d80a3f7ec0cf26ffa2e5747ad22b186 Reviewed-on: https://gerrit.libreoffice.org/26229 Reviewed-by: Michael Meeks <michael.meeks@collabora.com> Tested-by: Michael Meeks <michael.meeks@collabora.com>
Diffstat (limited to 'sax/qa')
-rw-r--r--sax/qa/cppunit/xmlimport.cxx53
1 files changed, 45 insertions, 8 deletions
diff --git a/sax/qa/cppunit/xmlimport.cxx b/sax/qa/cppunit/xmlimport.cxx
index c8bd21740b79..fe4af600022f 100644
--- a/sax/qa/cppunit/xmlimport.cxx
+++ b/sax/qa/cppunit/xmlimport.cxx
@@ -83,6 +83,7 @@ private:
public:
TestDocumentHandler() {}
const OUString& getString() { return m_aStr; }
+ void setString( const OUString aStr ) { m_aStr = aStr; }
// XDocumentHandler
virtual void SAL_CALL startDocument() throw (SAXException, RuntimeException, exception) override;
@@ -319,15 +320,43 @@ public:
}
};
+class TestLegacyDocumentHandler : public TestDocumentHandler
+{
+public:
+ virtual void SAL_CALL startElement( const OUString& aName, const Reference< XAttributeList >& xAttribs ) throw (SAXException, RuntimeException, exception) override;
+ virtual void SAL_CALL endElement( const OUString& aName ) throw (SAXException, RuntimeException, exception) override;
+};
+
+void SAL_CALL TestLegacyDocumentHandler::startElement( const OUString& aName, const Reference< XAttributeList >& xAttribs )
+ throw( SAXException, RuntimeException, exception )
+{
+ setString( getString() + aName );
+ sal_uInt16 len = xAttribs->getLength();
+ for (sal_uInt16 i = 0; i < len; i++)
+ {
+ OUString sAttrName = xAttribs->getNameByIndex(i);
+ OUString sAttrValue = xAttribs->getValueByIndex(i);
+ setString( getString() + sAttrName + sAttrValue );
+ }
+}
+
+
+void SAL_CALL TestLegacyDocumentHandler::endElement( const OUString& aName )
+ throw( SAXException, RuntimeException, exception )
+{
+ setString( getString() + aName );
+}
class XMLImportTest : public test::BootstrapFixture
{
private:
OUString m_sDirPath;
- rtl::Reference< TestDocumentHandler > m_xDocumentHandler;
- rtl::Reference< TestFastDocumentHandler > m_xFastDocumentHandler;
+ Reference< TestDocumentHandler > m_xDocumentHandler;
+ Reference< TestFastDocumentHandler > m_xFastDocumentHandler;
Reference< XParser > m_xParser;
Reference< XFastParser > m_xFastParser;
+ Reference< XParser > m_xLegacyFastParser;
+ Reference< TestLegacyDocumentHandler > m_xLegacyDocumentHandler;
Reference< XFastTokenHandler > m_xFastTokenHandler;
public:
@@ -345,16 +374,19 @@ public:
void XMLImportTest::setUp()
{
test::BootstrapFixture::setUp();
+ Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
m_xDocumentHandler.set( new TestDocumentHandler() );
m_xFastDocumentHandler.set( new TestFastDocumentHandler() );
+ m_xLegacyDocumentHandler.set( new TestLegacyDocumentHandler() );
m_xFastTokenHandler.set( new TestTokenHandler() );
- m_xParser = Parser::create(
- ::comphelper::getProcessComponentContext() );
- m_xFastParser = FastParser::create(
- ::comphelper::getProcessComponentContext() );
- m_xParser->setDocumentHandler( m_xDocumentHandler.get() );
- m_xFastParser->setFastDocumentHandler( m_xFastDocumentHandler.get() );
+ m_xParser = Parser::create( xContext );
+ m_xFastParser = FastParser::create( xContext );
+ m_xParser->setDocumentHandler( m_xDocumentHandler );
+ m_xFastParser->setFastDocumentHandler( m_xFastDocumentHandler );
m_xFastParser->setTokenHandler( m_xFastTokenHandler );
+ m_xLegacyFastParser.set( xContext->getServiceManager()->createInstanceWithContext
+ ( "com.sun.star.xml.sax.LegacyFastParser", xContext ), UNO_QUERY );
+ m_xLegacyFastParser->setDocumentHandler( m_xLegacyDocumentHandler );
m_sDirPath = m_directories.getPathFromSrc( "/sax/qa/data/" );
}
@@ -382,7 +414,12 @@ void XMLImportTest::parse()
m_xFastParser->parseStream(source);
const OUString& rFastParserStr = m_xFastDocumentHandler->getString();
+ source.aInputStream = createStreamFromFile( m_sDirPath + fileNames[i] );
+ m_xLegacyFastParser->parseStream(source);
+ const OUString& rLegacyFastParserStr = m_xLegacyDocumentHandler->getString();
+
CPPUNIT_ASSERT_EQUAL( rParserStr, rFastParserStr );
+ CPPUNIT_ASSERT_EQUAL( rFastParserStr, rLegacyFastParserStr );
// OString o = OUStringToOString( Str, RTL_TEXTENCODING_ASCII_US );
// CPPUNIT_ASSERT_MESSAGE( string(o.pData->buffer), false );
}