diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-07-18 14:57:37 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-07-23 13:51:18 +0200 |
commit | c4bce5dafdfcb97586fab4bc3834daa6a27fec4c (patch) | |
tree | b7143868f8ba67936fdf2e7227883789b210faaf /sw/qa/extras/rtfimport | |
parent | 413956ae4c1e833d7ecb6e3695bcdec92533c2ce (diff) |
resurrect and improve loplugin:referencecasting
Improve the plugin to avoid generating false+ with the special case of
querying XInterface (what the code calls normalisation).
Also ignore places where the querying is dealing with ambiguous base
classes.
Change-Id: I23b2b2fa6618328fafc4707b94c26582a462ea87
Reviewed-on: https://gerrit.libreoffice.org/74993
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sw/qa/extras/rtfimport')
-rw-r--r-- | sw/qa/extras/rtfimport/rtfimport.cxx | 61 |
1 files changed, 25 insertions, 36 deletions
diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx index 45a54092454e..316cfc06f7d5 100644 --- a/sw/qa/extras/rtfimport/rtfimport.cxx +++ b/sw/qa/extras/rtfimport/rtfimport.cxx @@ -71,8 +71,7 @@ DECLARE_RTFIMPORT_TEST(testN695479, "n695479.rtf") getProperty<sal_Int32>(xPropertySet, "Height")); uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), - uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xDraws = xDrawPageSupplier->getDrawPage(); bool bFrameFound = false, bDrawFound = false; for (int i = 0; i < xDraws->getCount(); ++i) { @@ -82,8 +81,8 @@ DECLARE_RTFIMPORT_TEST(testN695479, "n695479.rtf") // Both frames should be anchored to the first paragraph. bFrameFound = true; uno::Reference<text::XTextContent> xTextContent(xServiceInfo, uno::UNO_QUERY); - uno::Reference<text::XTextRange> xRange(xTextContent->getAnchor(), uno::UNO_QUERY); - uno::Reference<text::XText> xText(xRange->getText(), uno::UNO_QUERY); + uno::Reference<text::XTextRange> xRange = xTextContent->getAnchor(); + uno::Reference<text::XText> xText = xRange->getText(); CPPUNIT_ASSERT_EQUAL(OUString("plain"), xText->getString()); if (i == 0) @@ -191,8 +190,7 @@ DECLARE_RTFIMPORT_TEST(testTdf108951, "tdf108951.rtf") DECLARE_RTFIMPORT_TEST(testFdo47036, "fdo47036.rtf") { uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), - uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xDraws = xDrawPageSupplier->getDrawPage(); int nAtCharacter = 0; for (int i = 0; i < xDraws->getCount(); ++i) { @@ -213,8 +211,7 @@ DECLARE_RTFIMPORT_TEST(testFdo47036, "fdo47036.rtf") DECLARE_RTFIMPORT_TEST(testFdo45182, "fdo45182.rtf") { uno::Reference<text::XFootnotesSupplier> xFootnotesSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference<container::XIndexAccess> xFootnotes(xFootnotesSupplier->getFootnotes(), - uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xFootnotes = xFootnotesSupplier->getFootnotes(); uno::Reference<text::XTextRange> xTextRange(xFootnotes->getByIndex(0), uno::UNO_QUERY); // Encoding in the footnote was wrong. OUString aExpected(u"\u017Eivnost\u00ED" SAL_NEWLINE_STRING); @@ -331,7 +328,7 @@ DECLARE_RTFIMPORT_TEST(testFdo52066, "fdo52066.rtf") * * xray ThisComponent.DrawPage(0).Size.Height */ - uno::Reference<drawing::XShape> xShape(getShape(1), uno::UNO_QUERY); + uno::Reference<drawing::XShape> xShape = getShape(1); CPPUNIT_ASSERT_EQUAL(sal_Int32(convertTwipToMm100(19)), xShape->getSize().Height); } @@ -354,8 +351,7 @@ DECLARE_RTFIMPORT_TEST(testTdf122430, "tdf122430.rtf") DECLARE_RTFIMPORT_TEST(testFdo49892, "fdo49892.rtf") { uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), - uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xDraws = xDrawPageSupplier->getDrawPage(); for (int i = 0; i < xDraws->getCount(); ++i) { OUString aDescription = getProperty<OUString>(xDraws->getByIndex(i), "Description"); @@ -422,7 +418,7 @@ DECLARE_RTFIMPORT_TEST(testInk, "ink.rtf") DECLARE_RTFIMPORT_TEST(testFdo79319, "fdo79319.rtf") { // the thin horizontal rule was imported as a big fat rectangle - uno::Reference<drawing::XShape> xShape(getShape(1), uno::UNO_QUERY); + uno::Reference<drawing::XShape> xShape = getShape(1); CPPUNIT_ASSERT_EQUAL(sal_Int16(100), getProperty<sal_Int16>(xShape, "RelativeWidth")); CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(15238), xShape->getSize().Width, 10); CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(53), xShape->getSize().Height, 10); @@ -449,7 +445,7 @@ DECLARE_RTFIMPORT_TEST(testFdo55525, "fdo55525.rtf") // Negative left margin was ~missing, -191 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1877), getProperty<sal_Int32>(xTable, "LeftMargin")); // Cell width of A1 was 3332 (e.g. not set, 30% percent of total width) - uno::Reference<table::XTableRows> xTableRows(xTable->getRows(), uno::UNO_QUERY); + uno::Reference<table::XTableRows> xTableRows = xTable->getRows(); CPPUNIT_ASSERT_EQUAL(sal_Int16(896), getProperty<uno::Sequence<text::TableColumnSeparator>>( xTableRows->getByIndex(0), "TableColumnSeparators")[0] .Position); @@ -460,8 +456,7 @@ DECLARE_RTFIMPORT_TEST(testFdo57708, "fdo57708.rtf") // There were two issues: the doc was of 2 pages and the picture was missing. CPPUNIT_ASSERT_EQUAL(1, getPages()); uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), - uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xDraws = xDrawPageSupplier->getDrawPage(); // Two objects: a picture and a textframe. CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xDraws->getCount()); } @@ -486,7 +481,7 @@ DECLARE_RTFIMPORT_TEST(testFdo59953, "fdo59953.rtf") uno::UNO_QUERY); uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY); // Cell width of A1 was 4998 (e.g. not set / not wide enough, ~50% of total width) - uno::Reference<table::XTableRows> xTableRows(xTable->getRows(), uno::UNO_QUERY); + uno::Reference<table::XTableRows> xTableRows = xTable->getRows(); CPPUNIT_ASSERT_EQUAL(sal_Int16(7649), getProperty<uno::Sequence<text::TableColumnSeparator>>( xTableRows->getByIndex(0), "TableColumnSeparators")[0] .Position); @@ -624,8 +619,7 @@ DECLARE_RTFIMPORT_TEST(testN823675, "n823675.rtf") DECLARE_RTFIMPORT_TEST(testGroupshape, "groupshape.rtf") { uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), - uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xDraws = xDrawPageSupplier->getDrawPage(); // There should be a single groupshape with 2 children. CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xDraws->getCount()); uno::Reference<drawing::XShapes> xGroupshape(xDraws->getByIndex(0), uno::UNO_QUERY); @@ -635,8 +629,7 @@ DECLARE_RTFIMPORT_TEST(testGroupshape, "groupshape.rtf") DECLARE_RTFIMPORT_TEST(testGroupshape_notext, "groupshape-notext.rtf") { uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), - uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xDraws = xDrawPageSupplier->getDrawPage(); // There should be a single groupshape with 2 children. CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xDraws->getCount()); uno::Reference<drawing::XShapes> xGroupshape(xDraws->getByIndex(0), uno::UNO_QUERY); @@ -680,7 +673,7 @@ DECLARE_RTFIMPORT_TEST(testFdo66565, "fdo66565.rtf") uno::UNO_QUERY); uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY); // Cell width of A2 was 554, should be 453/14846*10000 - uno::Reference<table::XTableRows> xTableRows(xTable->getRows(), uno::UNO_QUERY); + uno::Reference<table::XTableRows> xTableRows = xTable->getRows(); CPPUNIT_ASSERT_EQUAL(sal_Int16(304), getProperty<uno::Sequence<text::TableColumnSeparator>>( xTableRows->getByIndex(1), "TableColumnSeparators")[0] .Position); @@ -750,7 +743,7 @@ DECLARE_RTFIMPORT_TEST(testTdf115153, "tdf115153.rtf") DECLARE_RTFIMPORT_TEST(testFdo68291, "fdo68291.odt") { uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); - uno::Reference<text::XTextRange> xText(xTextDocument->getText(), uno::UNO_QUERY); + uno::Reference<text::XTextRange> xText = xTextDocument->getText(); uno::Reference<text::XTextRange> xEnd = xText->getEnd(); paste("rtfimport/data/fdo68291-paste.rtf", xEnd); @@ -818,7 +811,7 @@ DECLARE_RTFIMPORT_TEST(testFdo74823, "fdo74823.rtf") uno::UNO_QUERY); uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY); // Cell width of C2 was too large / column separator being 3749 too small (e.g. not set, around 3/7 of total width) - uno::Reference<table::XTableRows> xTableRows(xTable->getRows(), uno::UNO_QUERY); + uno::Reference<table::XTableRows> xTableRows = xTable->getRows(); CPPUNIT_ASSERT_EQUAL(sal_Int16(5391), getProperty<uno::Sequence<text::TableColumnSeparator>>( xTableRows->getByIndex(1), "TableColumnSeparators")[2] .Position); @@ -1069,8 +1062,7 @@ DECLARE_RTFIMPORT_TEST(testTdf90046, "tdf90046.rtf") { // this was crashing on importing the footnote uno::Reference<text::XFootnotesSupplier> xFootnotesSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference<container::XIndexAccess> xFootnotes(xFootnotesSupplier->getFootnotes(), - uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xFootnotes = xFootnotesSupplier->getFootnotes(); uno::Reference<text::XTextRange> xTextRange(xFootnotes->getByIndex(0), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(OUString("Ma"), xTextRange->getString()); } @@ -1078,7 +1070,7 @@ DECLARE_RTFIMPORT_TEST(testTdf90046, "tdf90046.rtf") DECLARE_RTFIMPORT_TEST(testFdo49893, "fdo49893.rtf") { // Image from shape was not loaded, invalid size of image after load - uno::Reference<drawing::XShape> xShape(getShape(2), uno::UNO_QUERY); + uno::Reference<drawing::XShape> xShape = getShape(2); CPPUNIT_ASSERT(xShape.is()); CPPUNIT_ASSERT_EQUAL(sal_Int32(convertTwipToMm100(432)), xShape->getSize().Height); CPPUNIT_ASSERT_EQUAL(sal_Int32(convertTwipToMm100(1296)), xShape->getSize().Width); @@ -1089,7 +1081,7 @@ DECLARE_RTFIMPORT_TEST(testFdo49893_3, "fdo49893-3.rtf") // No artifacts (black lines in left top corner) as shape #3 are expected try { - uno::Reference<drawing::XShape> xShape2(getShape(3), uno::UNO_QUERY); + uno::Reference<drawing::XShape> xShape2 = getShape(3); CPPUNIT_FAIL("exception expected: no shape #3 in document"); } catch (lang::IndexOutOfBoundsException const&) @@ -1131,7 +1123,7 @@ DECLARE_RTFIMPORT_TEST(testWrapDistance, "wrap-distance.rtf") DECLARE_RTFIMPORT_TEST(testTdf90260Par, "hello.rtf") { uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); - uno::Reference<text::XTextRange> xText(xTextDocument->getText(), uno::UNO_QUERY); + uno::Reference<text::XTextRange> xText = xTextDocument->getText(); uno::Reference<text::XTextRange> xEnd = xText->getEnd(); paste("rtfimport/data/tdf90260-par.rtf", xEnd); CPPUNIT_ASSERT_EQUAL(2, getParagraphs()); @@ -1233,7 +1225,7 @@ DECLARE_RTFIMPORT_TEST(testTdf99498, "tdf99498.rtf") DECLARE_RTFIMPORT_TEST(testClassificatonPaste, "hello.rtf") { uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); - uno::Reference<text::XTextRange> xText(xTextDocument->getText(), uno::UNO_QUERY); + uno::Reference<text::XTextRange> xText = xTextDocument->getText(); uno::Reference<text::XTextRange> xEnd = xText->getEnd(); // Not classified source, not classified destination: OK. @@ -1334,18 +1326,15 @@ DECLARE_RTFIMPORT_TEST(testImportHeaderFooter, "tdf108055.rtf") // Check if any Header or Footer text snuck into the TextBody uno::Reference<text::XTextRange> paragraph = getParagraph(1); - uno::Reference<text::XTextRange> text(paragraph, uno::UNO_QUERY); - OUString value = text->getString(); + OUString value = paragraph->getString(); CPPUNIT_ASSERT_EQUAL(OUString("First Page"), value); paragraph = getParagraph(4); - uno::Reference<text::XTextRange> text2(paragraph, uno::UNO_QUERY); - value = text2->getString(); + value = paragraph->getString(); CPPUNIT_ASSERT_EQUAL(OUString("Second Page"), value); paragraph = getParagraph(7); - uno::Reference<text::XTextRange> text3(paragraph, uno::UNO_QUERY); - value = text3->getString(); + value = paragraph->getString(); CPPUNIT_ASSERT_EQUAL(OUString("Third Page"), value); //Check if Headers/Footers only contain what they should in this document @@ -1403,7 +1392,7 @@ DECLARE_RTFIMPORT_TEST(testTdf108947, "tdf108947.rtf") DECLARE_RTFIMPORT_TEST(testWatermark, "watermark.rtf") { Size aExpectedSize(14965, 7482); - uno::Reference<drawing::XShape> xShape(getShape(1), uno::UNO_QUERY); + uno::Reference<drawing::XShape> xShape = getShape(1); awt::Size aActualSize(xShape->getSize()); CPPUNIT_ASSERT_EQUAL(sal_Int32(aExpectedSize.Width()), aActualSize.Width); |