sw: qa: don't use try/catch in unittests

Change-Id: Ib1d6ea6b5e8e7f3e985014210c16725ee7645f7d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133471
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
This commit is contained in:
Xisco Fauli 2022-04-27 10:06:14 +02:00
parent 0a6ca96436
commit 38a475fbfb
6 changed files with 19 additions and 62 deletions

View File

@ -643,15 +643,12 @@ static void lcl_CheckShape(
CPPUNIT_TEST_FIXTURE(Test, testFdo68839) CPPUNIT_TEST_FIXTURE(Test, testFdo68839)
{ {
load(mpTestDocumentPath, "fdo68839.odt"); load(mpTestDocumentPath, "fdo68839.odt");
CPPUNIT_ASSERT_EQUAL(4, getShapes());
// check names // check names
lcl_CheckShape(getShape(1), "FrameXXX"); lcl_CheckShape(getShape(1), "FrameXXX");
lcl_CheckShape(getShape(2), "ObjectXXX"); lcl_CheckShape(getShape(2), "ObjectXXX");
lcl_CheckShape(getShape(3), "FrameY"); lcl_CheckShape(getShape(3), "FrameY");
lcl_CheckShape(getShape(4), "graphicsXXX"); lcl_CheckShape(getShape(4), "graphicsXXX");
try {
uno::Reference<drawing::XShape> xShape = getShape(5);
CPPUNIT_FAIL("IndexOutOfBoundsException expected");
} catch (lang::IndexOutOfBoundsException const&) { }
// check prev/next chain // check prev/next chain
uno::Reference<beans::XPropertySet> xFrame1(getShape(1), uno::UNO_QUERY); uno::Reference<beans::XPropertySet> xFrame1(getShape(1), uno::UNO_QUERY);
uno::Reference<beans::XPropertySet> xFrame2(getShape(3), uno::UNO_QUERY); uno::Reference<beans::XPropertySet> xFrame2(getShape(3), uno::UNO_QUERY);
@ -668,12 +665,9 @@ CPPUNIT_TEST_FIXTURE(Test, testFdo68839)
CPPUNIT_TEST_FIXTURE(Test, testFdo82165) CPPUNIT_TEST_FIXTURE(Test, testFdo82165)
{ {
load(mpTestDocumentPath, "fdo82165.odt"); load(mpTestDocumentPath, "fdo82165.odt");
CPPUNIT_ASSERT_EQUAL(1, getShapes());
// there was a duplicate shape in the left header // there was a duplicate shape in the left header
lcl_CheckShape(getShape(1), "Picture 9"); lcl_CheckShape(getShape(1), "Picture 9");
try {
uno::Reference<drawing::XShape> xShape = getShape(2);
CPPUNIT_FAIL("IndexOutOfBoundsException expected");
} catch (lang::IndexOutOfBoundsException const&) { }
} }
CPPUNIT_TEST_FIXTURE(Test, testTdf89802) CPPUNIT_TEST_FIXTURE(Test, testTdf89802)

View File

@ -754,26 +754,23 @@ CPPUNIT_TEST_FIXTURE(Test, testTextInput)
DECLARE_OOXMLEXPORT_TEST(testTdf123460, "tdf123460.docx") DECLARE_OOXMLEXPORT_TEST(testTdf123460, "tdf123460.docx")
{ {
// check paragraph mark deletion at terminating moveFrom // check paragraph mark deletion at terminating moveFrom
CPPUNIT_ASSERT_EQUAL(true,getParagraph( 2 )->getString().startsWith("Nunc")); CPPUNIT_ASSERT(getParagraph( 2 )->getString().startsWith("Nunc"));
CPPUNIT_ASSERT_EQUAL( OUString( "" ), getRun( getParagraph( 2 ), 1 )->getString()); uno::Reference<container::XEnumerationAccess> xRunEnumAccess(getParagraph( 2 ), uno::UNO_QUERY);
CPPUNIT_ASSERT(hasProperty(getRun(getParagraph(2), 2), "RedlineType")); uno::Reference<container::XEnumeration> xRunEnum = xRunEnumAccess->createEnumeration();
CPPUNIT_ASSERT_EQUAL(OUString("Delete"),getProperty<OUString>(getRun(getParagraph(2), 2), "RedlineType")); uno::Reference<text::XTextRange> xRun(xRunEnum->nextElement(), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(true, getRun( getParagraph( 2 ), 3 )->getString().endsWith("tellus.")); CPPUNIT_ASSERT_EQUAL( OUString( "" ), xRun->getString());
CPPUNIT_ASSERT(hasProperty(getRun(getParagraph(2), 4), "Bookmark")); xRun.set(xRunEnum->nextElement(), uno::UNO_QUERY);
CPPUNIT_ASSERT(hasProperty(xRun, "RedlineType"));
CPPUNIT_ASSERT_EQUAL(OUString("Delete"),getProperty<OUString>(xRun, "RedlineType"));
xRun.set(xRunEnum->nextElement(), uno::UNO_QUERY);
CPPUNIT_ASSERT(xRun->getString().endsWith("tellus."));
xRun.set(xRunEnum->nextElement(), uno::UNO_QUERY);
CPPUNIT_ASSERT(hasProperty(xRun, "Bookmark"));
// deleted paragraph mark at the end of the second paragraph // deleted paragraph mark at the end of the second paragraph
if (mbExported) if (mbExported)
{ {
// there is no run after the MoveBookmark // there is no run after the MoveBookmark
bool bCaught = false; CPPUNIT_ASSERT(!xRunEnum->hasMoreElements());
try
{
getRun( getParagraph( 2 ), 5 );
}
catch (container::NoSuchElementException&)
{
bCaught = true;
}
CPPUNIT_ASSERT_EQUAL(true, bCaught);
} }
} }

View File

@ -253,16 +253,7 @@ DECLARE_OOXMLEXPORT_TEST(testFdo38244, "fdo38244.docx")
xParaEnumAccess = getProperty< uno::Reference<container::XEnumerationAccess> >(xPropertySet, "TextRange"); xParaEnumAccess = getProperty< uno::Reference<container::XEnumerationAccess> >(xPropertySet, "TextRange");
xParaEnum = xParaEnumAccess->createEnumeration(); xParaEnum = xParaEnumAccess->createEnumeration();
xParaEnum->nextElement(); xParaEnum->nextElement();
bool bCaught = false; CPPUNIT_ASSERT(!xParaEnum->hasMoreElements());
try
{
xParaEnum->nextElement();
}
catch (container::NoSuchElementException&)
{
bCaught = true;
}
CPPUNIT_ASSERT_EQUAL(true, bCaught);
} }
CPPUNIT_TEST_FIXTURE(Test, testCommentsNested) CPPUNIT_TEST_FIXTURE(Test, testCommentsNested)

View File

@ -451,18 +451,10 @@ DECLARE_RTFEXPORT_TEST(testFdo46966, "fdo46966.rtf")
DECLARE_RTFEXPORT_TEST(testFdo76633, "fdo76633.rtf") DECLARE_RTFEXPORT_TEST(testFdo76633, "fdo76633.rtf")
{ {
// check that there is only a graphic object, not an additional rectangle // check that there is only a graphic object, not an additional rectangle
CPPUNIT_ASSERT_EQUAL(1, getShapes());
uno::Reference<lang::XServiceInfo> xShape(getShape(1), uno::UNO_QUERY); uno::Reference<lang::XServiceInfo> xShape(getShape(1), uno::UNO_QUERY);
CPPUNIT_ASSERT(xShape.is()); CPPUNIT_ASSERT(xShape.is());
CPPUNIT_ASSERT(xShape->supportsService("com.sun.star.text.TextGraphicObject")); CPPUNIT_ASSERT(xShape->supportsService("com.sun.star.text.TextGraphicObject"));
try
{
getShape(2);
CPPUNIT_FAIL("exception expected");
}
catch (lang::IndexOutOfBoundsException const&)
{
/* expected */
}
} }
DECLARE_RTFEXPORT_TEST(testFdo48033, "fdo48033.rtf") DECLARE_RTFEXPORT_TEST(testFdo48033, "fdo48033.rtf")

View File

@ -440,16 +440,7 @@ DECLARE_RTFEXPORT_TEST(testTdf107413, "tdf107413.rtf")
DECLARE_RTFEXPORT_TEST(testCp1000016, "hello.rtf") DECLARE_RTFEXPORT_TEST(testCp1000016, "hello.rtf")
{ {
// The single-line document had a second fake empty para on Windows. // The single-line document had a second fake empty para on Windows.
bool bFound = true; CPPUNIT_ASSERT_EQUAL(1, getParagraphs());
try
{
getParagraph(2);
}
catch (const container::NoSuchElementException&)
{
bFound = false;
}
CPPUNIT_ASSERT_EQUAL(false, bFound);
} }
DECLARE_RTFEXPORT_TEST(testFdo65090, "fdo65090.rtf") DECLARE_RTFEXPORT_TEST(testFdo65090, "fdo65090.rtf")

View File

@ -1160,15 +1160,7 @@ CPPUNIT_TEST_FIXTURE(Test, testFdo49893_3)
{ {
load(mpTestDocumentPath, "fdo49893-3.rtf"); load(mpTestDocumentPath, "fdo49893-3.rtf");
// No artifacts (black lines in left top corner) as shape #3 are expected // No artifacts (black lines in left top corner) as shape #3 are expected
try CPPUNIT_ASSERT_EQUAL(2, getShapes());
{
getShape(3);
CPPUNIT_FAIL("exception expected: no shape #3 in document");
}
catch (lang::IndexOutOfBoundsException const&)
{
/* expected */
}
// Correct wrapping for shape // Correct wrapping for shape
CPPUNIT_ASSERT_EQUAL(text::WrapTextMode_THROUGH, CPPUNIT_ASSERT_EQUAL(text::WrapTextMode_THROUGH,