diff options
author | Noel Grandin <noel@peralex.com> | 2015-07-13 16:17:00 +0200 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2015-08-03 06:37:16 +0000 |
commit | 2660d24a07866e083c5135ea263030f3e3a2e729 (patch) | |
tree | 0089d6018d4fc33a7fde955e585e77191cdd258b /sax | |
parent | baba1d14766282bd2c592bffd79ed69f9078cfe1 (diff) |
new loplugin: refcounting
This was a feature requested by mmeeks, as a result of
tdf#92611.
It validates that things that extend XInterface are not
directly heap/stack-allocated, but have their lifecycle managed
via css::uno::Reference or rtl::Reference.
Change-Id: I28e3b8b236f6a4a56d0a6d6f26ad54e44b36e692
Reviewed-on: https://gerrit.libreoffice.org/16924
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Tested-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'sax')
-rw-r--r-- | sax/qa/cppunit/attributes.cxx | 42 | ||||
-rw-r--r-- | sax/qa/cppunit/parser.cxx | 9 |
2 files changed, 26 insertions, 25 deletions
diff --git a/sax/qa/cppunit/attributes.cxx b/sax/qa/cppunit/attributes.cxx index a573f9ddb4b6..c76fd6556bf4 100644 --- a/sax/qa/cppunit/attributes.cxx +++ b/sax/qa/cppunit/attributes.cxx @@ -34,44 +34,44 @@ public: void AttributesTest::test() { - sax_fastparser::FastAttributeList aAttributeList( NULL ); - aAttributeList.add(1, "1"); - aAttributeList.add(2, OString("2")); + uno::Reference<sax_fastparser::FastAttributeList> xAttributeList( new sax_fastparser::FastAttributeList(NULL) ); + xAttributeList->add(1, "1"); + xAttributeList->add(2, OString("2")); // We can't test getValueToken() and getOptionalValueToken() // without XFastTokenHandler :-( // Uncomment to get segmantation fault: - // aAttributeList.getOptionalValueToken(1, 0); - // aAttributeList.getValueToken(2); + // xAttributeList->getOptionalValueToken(1, 0); + // xAttributeList->getValueToken(2); - CPPUNIT_ASSERT( aAttributeList.hasAttribute(1) ); - CPPUNIT_ASSERT( !aAttributeList.hasAttribute(3) ); + CPPUNIT_ASSERT( xAttributeList->hasAttribute(1) ); + CPPUNIT_ASSERT( !xAttributeList->hasAttribute(3) ); - CPPUNIT_ASSERT_EQUAL( aAttributeList.getOptionalValue(2), OUString("2") ); - CPPUNIT_ASSERT_EQUAL( aAttributeList.getOptionalValue(3), OUString() ); + CPPUNIT_ASSERT_EQUAL( xAttributeList->getOptionalValue(2), OUString("2") ); + CPPUNIT_ASSERT_EQUAL( xAttributeList->getOptionalValue(3), OUString() ); - CPPUNIT_ASSERT_EQUAL( aAttributeList.getValue(1), OUString("1") ); + CPPUNIT_ASSERT_EQUAL( xAttributeList->getValue(1), OUString("1") ); mbException = false; - try { aAttributeList.getValue(3); } + try { xAttributeList->getValue(3); } catch (const sax::SAXException& ) { mbException = true; } CPPUNIT_ASSERT( mbException ); - aAttributeList.addUnknown("a", "a"); - aAttributeList.addUnknown("b", "b", "b"); - aAttributeList.addUnknown("c", "c"); - CPPUNIT_ASSERT_EQUAL( (sal_Int32) 3, aAttributeList.getUnknownAttributes().getLength() ); + xAttributeList->addUnknown("a", "a"); + xAttributeList->addUnknown("b", "b", "b"); + xAttributeList->addUnknown("c", "c"); + CPPUNIT_ASSERT_EQUAL( (sal_Int32) 3, xAttributeList->getUnknownAttributes().getLength() ); - CPPUNIT_ASSERT_EQUAL( (sal_Int32) 2, aAttributeList.getFastAttributes().getLength() ); + CPPUNIT_ASSERT_EQUAL( (sal_Int32) 2, xAttributeList->getFastAttributes().getLength() ); - aAttributeList.clear(); - CPPUNIT_ASSERT( !aAttributeList.hasAttribute(1) ); - CPPUNIT_ASSERT_EQUAL( (sal_Int32) 0, aAttributeList.getFastAttributes().getLength() ); - aAttributeList.addUnknown("c", "c"); - CPPUNIT_ASSERT_EQUAL( (sal_Int32) 1, aAttributeList.getUnknownAttributes().getLength() ); + xAttributeList->clear(); + CPPUNIT_ASSERT( !xAttributeList->hasAttribute(1) ); + CPPUNIT_ASSERT_EQUAL( (sal_Int32) 0, xAttributeList->getFastAttributes().getLength() ); + xAttributeList->addUnknown("c", "c"); + CPPUNIT_ASSERT_EQUAL( (sal_Int32) 1, xAttributeList->getUnknownAttributes().getLength() ); } CPPUNIT_TEST_SUITE_REGISTRATION( AttributesTest ); diff --git a/sax/qa/cppunit/parser.cxx b/sax/qa/cppunit/parser.cxx index 824d5ecd7078..b781d9e1a6e1 100644 --- a/sax/qa/cppunit/parser.cxx +++ b/sax/qa/cppunit/parser.cxx @@ -45,7 +45,7 @@ public: class ParserTest: public test::BootstrapFixture { InputSource maInput; - sax_fastparser::FastSaxParser maParser; + uno::Reference< sax_fastparser::FastSaxParser > mxParser; uno::Reference< XFastDocumentHandler > mxDocumentHandler; uno::Reference< DummyTokenHandler > mxTokenHandler; @@ -67,7 +67,8 @@ void ParserTest::setUp() { test::BootstrapFixture::setUp(); mxTokenHandler.set( new DummyTokenHandler() ); - maParser.setTokenHandler( mxTokenHandler ); + mxParser.set( new sax_fastparser::FastSaxParser() ); + mxParser->setTokenHandler( mxTokenHandler.get() ); } void ParserTest::tearDown() @@ -89,13 +90,13 @@ uno::Reference< io::XInputStream > ParserTest::createStream(const OString& sInpu void ParserTest::parse() { maInput.aInputStream = createStream("<a>...<b />..</a>"); - maParser.parseStream( maInput ); + mxParser->parseStream( maInput ); maInput.aInputStream = createStream("<b></a>"); bool bException = false; try { - maParser.parseStream( maInput ); + mxParser->parseStream( maInput ); } catch (const SAXParseException &) { |