sw/qa/extras/odfimport/odfimport.cxx       |   10 ++--------
 sw/qa/extras/ooxmlexport/ooxmlexport13.cxx |   29 +++++++++++++----------------
 sw/qa/extras/ooxmlexport/ooxmlexport2.cxx  |   11 +----------
 sw/qa/extras/rtfexport/rtfexport2.cxx      |   10 +---------
 sw/qa/extras/rtfexport/rtfexport5.cxx      |   11 +----------
 sw/qa/extras/rtfimport/rtfimport.cxx       |   10 +---------
 6 files changed, 19 insertions(+), 62 deletions(-)

New commits:
commit 38a475fbfb346234bcd9976fadf4067c7ea9da29
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Wed Apr 27 10:06:14 2022 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Wed Apr 27 16:27:24 2022 +0200

    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 <xiscofa...@libreoffice.org>

diff --git a/sw/qa/extras/odfimport/odfimport.cxx 
b/sw/qa/extras/odfimport/odfimport.cxx
index 0238ffc96a9b..e79ce4df1da1 100644
--- a/sw/qa/extras/odfimport/odfimport.cxx
+++ b/sw/qa/extras/odfimport/odfimport.cxx
@@ -643,15 +643,12 @@ static void lcl_CheckShape(
 CPPUNIT_TEST_FIXTURE(Test, testFdo68839)
 {
     load(mpTestDocumentPath, "fdo68839.odt");
+    CPPUNIT_ASSERT_EQUAL(4, getShapes());
     // check names
     lcl_CheckShape(getShape(1), "FrameXXX");
     lcl_CheckShape(getShape(2), "ObjectXXX");
     lcl_CheckShape(getShape(3), "FrameY");
     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
     uno::Reference<beans::XPropertySet> xFrame1(getShape(1), 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)
 {
     load(mpTestDocumentPath, "fdo82165.odt");
+    CPPUNIT_ASSERT_EQUAL(1, getShapes());
     // there was a duplicate shape in the left header
     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)
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
index 9f02523807c0..48f65a6a0793 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
@@ -754,26 +754,23 @@ CPPUNIT_TEST_FIXTURE(Test, testTextInput)
 DECLARE_OOXMLEXPORT_TEST(testTdf123460, "tdf123460.docx")
 {
     // check paragraph mark deletion at terminating moveFrom
-    CPPUNIT_ASSERT_EQUAL(true,getParagraph( 2 
)->getString().startsWith("Nunc"));
-    CPPUNIT_ASSERT_EQUAL( OUString( "" ), getRun( getParagraph( 2 ), 1 
)->getString());
-    CPPUNIT_ASSERT(hasProperty(getRun(getParagraph(2), 2), "RedlineType"));
-    
CPPUNIT_ASSERT_EQUAL(OUString("Delete"),getProperty<OUString>(getRun(getParagraph(2),
 2), "RedlineType"));
-    CPPUNIT_ASSERT_EQUAL(true, getRun( getParagraph( 2 ), 3 
)->getString().endsWith("tellus."));
-    CPPUNIT_ASSERT(hasProperty(getRun(getParagraph(2), 4), "Bookmark"));
+    CPPUNIT_ASSERT(getParagraph( 2 )->getString().startsWith("Nunc"));
+    uno::Reference<container::XEnumerationAccess> xRunEnumAccess(getParagraph( 
2 ), uno::UNO_QUERY);
+    uno::Reference<container::XEnumeration> xRunEnum = 
xRunEnumAccess->createEnumeration();
+    uno::Reference<text::XTextRange> xRun(xRunEnum->nextElement(), 
uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL( OUString( "" ), xRun->getString());
+    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
     if (mbExported)
     {
         // there is no run after the MoveBookmark
-        bool bCaught = false;
-        try
-        {
-            getRun( getParagraph( 2 ), 5 );
-        }
-        catch (container::NoSuchElementException&)
-        {
-            bCaught = true;
-        }
-        CPPUNIT_ASSERT_EQUAL(true, bCaught);
+        CPPUNIT_ASSERT(!xRunEnum->hasMoreElements());
     }
 }
 
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx
index 4af48b2feb15..48cec2f2cca2 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx
@@ -253,16 +253,7 @@ DECLARE_OOXMLEXPORT_TEST(testFdo38244, "fdo38244.docx")
     xParaEnumAccess = getProperty< 
uno::Reference<container::XEnumerationAccess> >(xPropertySet, "TextRange");
     xParaEnum = xParaEnumAccess->createEnumeration();
     xParaEnum->nextElement();
-    bool bCaught = false;
-    try
-    {
-        xParaEnum->nextElement();
-    }
-    catch (container::NoSuchElementException&)
-    {
-        bCaught = true;
-    }
-    CPPUNIT_ASSERT_EQUAL(true, bCaught);
+    CPPUNIT_ASSERT(!xParaEnum->hasMoreElements());
 }
 
 CPPUNIT_TEST_FIXTURE(Test, testCommentsNested)
diff --git a/sw/qa/extras/rtfexport/rtfexport2.cxx 
b/sw/qa/extras/rtfexport/rtfexport2.cxx
index fac1ba0f762b..38d3550436da 100644
--- a/sw/qa/extras/rtfexport/rtfexport2.cxx
+++ b/sw/qa/extras/rtfexport/rtfexport2.cxx
@@ -451,18 +451,10 @@ DECLARE_RTFEXPORT_TEST(testFdo46966, "fdo46966.rtf")
 DECLARE_RTFEXPORT_TEST(testFdo76633, "fdo76633.rtf")
 {
     // 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);
     CPPUNIT_ASSERT(xShape.is());
     
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")
diff --git a/sw/qa/extras/rtfexport/rtfexport5.cxx 
b/sw/qa/extras/rtfexport/rtfexport5.cxx
index 684ae9b249ed..39bcf7135ddf 100644
--- a/sw/qa/extras/rtfexport/rtfexport5.cxx
+++ b/sw/qa/extras/rtfexport/rtfexport5.cxx
@@ -440,16 +440,7 @@ DECLARE_RTFEXPORT_TEST(testTdf107413, "tdf107413.rtf")
 DECLARE_RTFEXPORT_TEST(testCp1000016, "hello.rtf")
 {
     // The single-line document had a second fake empty para on Windows.
-    bool bFound = true;
-    try
-    {
-        getParagraph(2);
-    }
-    catch (const container::NoSuchElementException&)
-    {
-        bFound = false;
-    }
-    CPPUNIT_ASSERT_EQUAL(false, bFound);
+    CPPUNIT_ASSERT_EQUAL(1, getParagraphs());
 }
 
 DECLARE_RTFEXPORT_TEST(testFdo65090, "fdo65090.rtf")
diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx 
b/sw/qa/extras/rtfimport/rtfimport.cxx
index 60301446c35a..9e1e71003b4a 100644
--- a/sw/qa/extras/rtfimport/rtfimport.cxx
+++ b/sw/qa/extras/rtfimport/rtfimport.cxx
@@ -1160,15 +1160,7 @@ CPPUNIT_TEST_FIXTURE(Test, testFdo49893_3)
 {
     load(mpTestDocumentPath, "fdo49893-3.rtf");
     // No artifacts (black lines in left top corner) as shape #3 are expected
-    try
-    {
-        getShape(3);
-        CPPUNIT_FAIL("exception expected: no shape #3 in document");
-    }
-    catch (lang::IndexOutOfBoundsException const&)
-    {
-        /* expected */
-    }
+    CPPUNIT_ASSERT_EQUAL(2, getShapes());
 
     // Correct wrapping for shape
     CPPUNIT_ASSERT_EQUAL(text::WrapTextMode_THROUGH,

Reply via email to