[Libreoffice-commits] core.git: sw/qa

Tomaž Vajngerl tomaz.vajngerl at collabora.co.uk
Tue May 15 23:37:31 UTC 2018


 sw/qa/extras/globalfilter/globalfilter.cxx |  118 ++++++++++++++---------------
 1 file changed, 61 insertions(+), 57 deletions(-)

New commits:
commit 29cebedfbdc8a8d3bf47e9a8148dc081bf86eb10
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Tue May 15 22:25:46 2018 +0900

    sw: cleanup globalfilter test
    
    - use OUString for filter names
    - use modern iteration through filter names
    - no change to the tests
    
    Change-Id: Idab4183efe2b489b91b4f3c96e7cb1d639628766
    Reviewed-on: https://gerrit.libreoffice.org/54374
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/sw/qa/extras/globalfilter/globalfilter.cxx b/sw/qa/extras/globalfilter/globalfilter.cxx
index eab2037d697e..60b3d083a0c4 100644
--- a/sw/qa/extras/globalfilter/globalfilter.cxx
+++ b/sw/qa/extras/globalfilter/globalfilter.cxx
@@ -63,26 +63,27 @@ public:
 
 void Test::testEmbeddedGraphicRoundtrip()
 {
-    const char* aFilterNames[] = {
+    OUString aFilterNames[] = {
         "writer8",
         "Rich Text Format",
         "MS Word 97",
         "Office Open XML Text",
     };
 
-    for( size_t nFilter = 0; nFilter < SAL_N_ELEMENTS(aFilterNames); ++nFilter )
+    for (OUString const & rFilterName : aFilterNames)
     {
         // Check whether the export code swaps in the image which was swapped out before by auto mechanism
 
         if (mxComponent.is())
             mxComponent->dispose();
+
         mxComponent = loadFromDesktop(m_directories.getURLFromSrc("/sw/qa/extras/globalfilter/data/document_with_two_images.odt"), "com.sun.star.text.TextDocument");
 
         // Export the document and import again for a check
         uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
 
         utl::MediaDescriptor aMediaDescriptor;
-        aMediaDescriptor["FilterName"] <<= OUString::createFromAscii(aFilterNames[nFilter]);
+        aMediaDescriptor["FilterName"] <<= rFilterName;
 
         utl::TempFile aTempFile;
         aTempFile.EnableKillingFile();
@@ -95,7 +96,7 @@ void Test::testEmbeddedGraphicRoundtrip()
         uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
         uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY);
 
-        const OString sFailedMessage = OString("Failed on filter: ") + aFilterNames[nFilter];
+        const OString sFailedMessage = OString("Failed on filter: ") + rFilterName.toUtf8();
         CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(2), xDraws->getCount());
 
         // First image
@@ -134,28 +135,26 @@ void Test::testEmbeddedGraphicRoundtrip()
 
 void Test::testLinkedGraphicRT()
 {
-    const std::vector<OUString> aFilterNames = {
+    const OUString aFilterNames[] = {
         "writer8",
 //        "Rich Text Format",  Note: picture is there, but SwGrfNode is not found?
         "MS Word 97",
         "Office Open XML Text",
     };
 
-    for( size_t nFilter = 0; nFilter < aFilterNames.size(); ++nFilter )
+    for (OUString const & rFilterName : aFilterNames)
     {
         if (mxComponent.is())
             mxComponent->dispose();
         mxComponent = loadFromDesktop(m_directories.getURLFromSrc("/sw/qa/extras/globalfilter/data/document_with_linked_graphic.odt"), "com.sun.star.text.TextDocument");
 
-        const OString sFailedMessage = OString("Failed on filter: ")
-            + OUStringToOString(aFilterNames[nFilter], RTL_TEXTENCODING_ASCII_US);
-
+        const OString sFailedMessage = OString("Failed on filter: ") + rFilterName.toUtf8();
 
         // Export the document and import again for a check
         uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
 
         utl::MediaDescriptor aMediaDescriptor;
-        aMediaDescriptor["FilterName"] <<= aFilterNames[nFilter];
+        aMediaDescriptor["FilterName"] <<= rFilterName;
 
         utl::TempFile aTempFile;
         aTempFile.EnableKillingFile();
@@ -173,9 +172,9 @@ void Test::testLinkedGraphicRT()
         // Find the image
         bool bImageFound = false;
         Graphic aGraphic;
-        for( sal_uLong nIndex = 0; nIndex < aNodes.Count(); ++nIndex)
+        for (sal_uLong nIndex = 0; nIndex < aNodes.Count(); ++nIndex)
         {
-            if( aNodes[nIndex]->IsGrfNode() )
+            if (aNodes[nIndex]->IsGrfNode())
             {
                 SwGrfNode* pGrfNode = aNodes[nIndex]->GetGrfNode();
                 CPPUNIT_ASSERT(pGrfNode);
@@ -185,6 +184,7 @@ void Test::testLinkedGraphicRT()
                 bImageFound = true;
             }
         }
+
         CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), bImageFound);
 
         CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), GraphicType::Bitmap, aGraphic.GetType());
@@ -203,14 +203,14 @@ void Test::testImageWithSpecialID()
     // Check how LO handles when the imported graphic's ID is different from that one
     // which is generated by LO.
 
-    const char* aFilterNames[] = {
+    const OUString aFilterNames[] = {
         "writer8",
         "Rich Text Format",
         "MS Word 97",
         "Office Open XML Text",
     };
 
-    for( size_t nFilter = 0; nFilter < SAL_N_ELEMENTS(aFilterNames); ++nFilter )
+    for (OUString const & rFilterName : aFilterNames)
     {
         if (mxComponent.is())
             mxComponent->dispose();
@@ -220,7 +220,7 @@ void Test::testImageWithSpecialID()
         uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
 
         utl::MediaDescriptor aMediaDescriptor;
-        aMediaDescriptor["FilterName"] <<= OUString::createFromAscii(aFilterNames[nFilter]);
+        aMediaDescriptor["FilterName"] <<= rFilterName;
 
         utl::TempFile aTempFile;
         aTempFile.EnableKillingFile();
@@ -233,7 +233,7 @@ void Test::testImageWithSpecialID()
         uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
         uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY);
 
-        const OString sFailedMessage = OString("Failed on filter: ") + aFilterNames[nFilter];
+        const OString sFailedMessage = OString("Failed on filter: ") + rFilterName.toUtf8();
         CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(2), xDraws->getCount());
 
         uno::Reference<drawing::XShape> xImage = getShape(1);
@@ -250,8 +250,9 @@ void Test::testImageWithSpecialID()
             CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(610), xBitmap->getSize().Width);
             CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(381), xBitmap->getSize().Height);
         }
+
         // Second Image
-        xImage = getShape(2);
+        xImage.set(xDraws->getByIndex(1), uno::UNO_QUERY);
         XPropSet.set( xImage, uno::UNO_QUERY_THROW );
 
         // Check graphic, size
@@ -301,14 +302,14 @@ void Test::testGraphicShape()
     // There are two kind of images in Writer: 1) Writer specific handled by SwGrfNode and
     // 2) graphic shape handled by SdrGrafObj (e.g. after copy&paste from Impress).
 
-    const char* aFilterNames[] = {
+    const OUString aFilterNames[] = {
         "writer8",
         "Rich Text Format",
         "MS Word 97",
         "Office Open XML Text",
     };
 
-    for( size_t nFilter = 0; nFilter < SAL_N_ELEMENTS(aFilterNames); ++nFilter )
+    for (OUString const & rFilterName : aFilterNames)
     {
         if (mxComponent.is())
             mxComponent->dispose();
@@ -318,7 +319,7 @@ void Test::testGraphicShape()
         uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
 
         utl::MediaDescriptor aMediaDescriptor;
-        aMediaDescriptor["FilterName"] <<= OUString::createFromAscii(aFilterNames[nFilter]);
+        aMediaDescriptor["FilterName"] <<= rFilterName;
 
         utl::TempFile aTempFile;
         aTempFile.EnableKillingFile();
@@ -331,7 +332,7 @@ void Test::testGraphicShape()
         uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
         uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY);
 
-        const OString sFailedMessage = OString("Failed on filter: ") + aFilterNames[nFilter];
+        const OString sFailedMessage = OString("Failed on filter: ") + rFilterName.toUtf8();
         CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(2), xDraws->getCount());
 
         uno::Reference<drawing::XShape> xImage = lcl_getShape(mxComponent, true);
@@ -350,13 +351,13 @@ void Test::testGraphicShape()
         }
 
         // MS filters make this kind of linked images broken !?
-        if( OUString::createFromAscii(aFilterNames[nFilter]) != "writer8" )
+        if (rFilterName != "writer8")
             return;
 
         // Second image is a linked one
         xImage = lcl_getShape(mxComponent, false);
-        XPropSet.set( xImage, uno::UNO_QUERY );
-        const OString sFailedImageLoad = OString("Couldn't load the shape/image for ") + aFilterNames[nFilter];
+        XPropSet.set(xImage, uno::UNO_QUERY);
+        const OString sFailedImageLoad = OString("Couldn't load the shape/image for ") + rFilterName.toUtf8();
         CPPUNIT_ASSERT_MESSAGE(sFailedImageLoad.getStr(), xImage.is());
 
         // Check size
@@ -371,8 +372,8 @@ void Test::testGraphicShape()
 
             uno::Reference<awt::XBitmap> xBitmap(xGraphic, uno::UNO_QUERY);
             CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), xBitmap.is());
-            CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(620), xBitmap->getSize().Width );
-            CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(465), xBitmap->getSize().Height );
+            CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(620), xBitmap->getSize().Width);
+            CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(465), xBitmap->getSize().Height);
         }
     }
 }
@@ -382,27 +383,27 @@ void Test::testCharHighlightBody()
     // MS Word has two kind of character backgrounds called character shading and highlighting
     // MS filters handle these attributes separately, but ODF export merges them into one background attribute
 
-    const char* aFilterNames[] = {
+    const OUString aFilterNames[] = {
         "writer8",
         "Rich Text Format",
         "MS Word 97",
         "Office Open XML Text",
     };
 
-    for( size_t nFilter = 0; nFilter < SAL_N_ELEMENTS(aFilterNames); ++nFilter )
+    for (OUString const & rFilterName : aFilterNames)
     {
         if (mxComponent.is())
             mxComponent->dispose();
         mxComponent = loadFromDesktop(m_directories.getURLFromSrc("/sw/qa/extras/globalfilter/data/char_highlight.docx"),
                                       "com.sun.star.text.TextDocument");
 
-        const OString sFailedMessage = OString("Failed on filter: ") + aFilterNames[nFilter];
+        const OString sFailedMessage = OString("Failed on filter: ") + rFilterName.toUtf8();
 
         // Export the document and import again for a check
         uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
 
         utl::MediaDescriptor aMediaDescriptor;
-        aMediaDescriptor["FilterName"] <<= OUString::createFromAscii(aFilterNames[nFilter]);
+        aMediaDescriptor["FilterName"] <<= rFilterName;
 
         utl::TempFile aTempFile;
         aTempFile.EnableKillingFile();
@@ -438,7 +439,7 @@ void Test::testCharHighlightBody()
                 case 16: nHighlightColor = 0xC0C0C0; break; //light gray
             }
 
-            if( strcmp(aFilterNames[nFilter], "writer8") == 0 )
+            if (rFilterName == "writer8")
             {
                 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(COL_TRANSPARENT), getProperty<sal_Int32>(xRun,"CharHighlight"));
                 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), nHighlightColor, getProperty<sal_Int32>(xRun,"CharBackColor"));
@@ -453,7 +454,7 @@ void Test::testCharHighlightBody()
         // Only highlight
         {
             const uno::Reference<beans::XPropertySet> xRun(getRun(xPara,18), uno::UNO_QUERY);
-            if( strcmp(aFilterNames[nFilter], "writer8") == 0 )
+            if (rFilterName == "writer8")
             {
                 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(COL_TRANSPARENT), getProperty<sal_Int32>(xRun,"CharHighlight"));
                 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(0xff0000), getProperty<sal_Int32>(xRun,"CharBackColor"));
@@ -569,14 +570,14 @@ void Test::testMSCharBackgroundEditing()
     // Simulate the editing process of imported MSO character background attributes
     // and check how export behaves.
 
-    const char* aFilterNames[] = {
+    const OUString aFilterNames[] = {
         "writer8",
         "Rich Text Format",
         "MS Word 97",
         "Office Open XML Text",
     };
 
-    for( size_t nFilter = 0; nFilter < SAL_N_ELEMENTS(aFilterNames); ++nFilter )
+    for (OUString const & rFilterName : aFilterNames)
     {
         if (mxComponent.is())
             mxComponent->dispose();
@@ -584,7 +585,7 @@ void Test::testMSCharBackgroundEditing()
         mxComponent = loadFromDesktop(m_directories.getURLFromSrc("/sw/qa/extras/globalfilter/data/char_background_editing.docx"),
                                       "com.sun.star.text.TextDocument");
 
-        const OString sFailedMessage = OString("Failed on filter: ") + aFilterNames[nFilter];
+        const OString sFailedMessage = OString("Failed on filter: ") + rFilterName.toUtf8();
 
         // Check whether import was done on the right way
         uno::Reference< text::XTextRange > xPara = getParagraph(1);
@@ -643,7 +644,7 @@ void Test::testMSCharBackgroundEditing()
         uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
 
         utl::MediaDescriptor aMediaDescriptor;
-        aMediaDescriptor["FilterName"] <<= OUString::createFromAscii(aFilterNames[nFilter]);
+        aMediaDescriptor["FilterName"] <<= rFilterName;
 
         utl::TempFile aTempFile;
         aTempFile.EnableKillingFile();
@@ -665,7 +666,7 @@ void Test::testMSCharBackgroundEditing()
                 case 4: nBackColor = 0xff00ff; break; //magenta
             }
             const uno::Reference<beans::XPropertySet> xRun(getRun(xPara,i), uno::UNO_QUERY);
-            if( strcmp(aFilterNames[nFilter], "writer8") == 0 )
+            if (rFilterName == "writer8")
             {
                 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(COL_TRANSPARENT), getProperty<sal_Int32>(xRun,"CharHighlight"));
                 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), nBackColor, getProperty<sal_Int32>(xRun,"CharBackColor"));
@@ -684,20 +685,20 @@ void Test::testCharBackgroundToHighlighting()
     // MSO highlighting has less kind of values so let's see how LO character background is converted
     // to these values
 
-    const char* aFilterNames[] = {
+    const OUString aFilterNames[] = {
         "Rich Text Format",
         "MS Word 97",
         "Office Open XML Text",
     };
 
-    for( size_t nFilter = 0; nFilter < SAL_N_ELEMENTS(aFilterNames); ++nFilter )
+    for (OUString const & rFilterName : aFilterNames)
     {
         if (mxComponent.is())
             mxComponent->dispose();
         mxComponent = loadFromDesktop(m_directories.getURLFromSrc("/sw/qa/extras/globalfilter/data/char_background.odt"),
                                       "com.sun.star.text.TextDocument");
 
-        OString sFailedMessage = OString("Failed on filter: ") + aFilterNames[nFilter];
+        OString sFailedMessage = OString("Failed on filter: ") + rFilterName.toUtf8();
 
 
         SvtFilterOptions& rOpt = SvtFilterOptions::Get();
@@ -707,7 +708,7 @@ void Test::testCharBackgroundToHighlighting()
         uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
 
         utl::MediaDescriptor aMediaDescriptor;
-        aMediaDescriptor["FilterName"] <<= OUString::createFromAscii(aFilterNames[nFilter]);
+        aMediaDescriptor["FilterName"] <<= rFilterName;
 
         utl::TempFile aTempFile;
         aTempFile.EnableKillingFile();
@@ -756,17 +757,17 @@ void Test::testSkipImages()
     // Check how LO skips image loading (but not texts of textboxes and custom shapes)
     // during DOC and DOCX import, using the "SkipImages" FilterOptions.
 
-    const char* aFilterNames[][2] = {
-        { "/sw/qa/extras/globalfilter/data/skipimages.doc", nullptr },
+    std::pair<OUString, OUString> aFilterNames[] = {
+        { "/sw/qa/extras/globalfilter/data/skipimages.doc", "" },
         { "/sw/qa/extras/globalfilter/data/skipimages.doc", "SkipImages" },
-        { "/sw/qa/extras/globalfilter/data/skipimages.docx", nullptr },
+        { "/sw/qa/extras/globalfilter/data/skipimages.docx", "" },
         { "/sw/qa/extras/globalfilter/data/skipimages.docx", "SkipImages" }
     };
 
-    for( size_t nFilter = 0; nFilter < SAL_N_ELEMENTS(aFilterNames); ++nFilter )
+    for (auto const & rFilterNamePair : aFilterNames)
     {
-        bool bSkipImages = aFilterNames[nFilter][1] != nullptr;
-        OString sFailedMessage = OString("Failed on filter: ") + aFilterNames[nFilter][0];
+        bool bSkipImages = !rFilterNamePair.second.isEmpty();
+        OString sFailedMessage = OString("Failed on filter: ") + rFilterNamePair.first.toUtf8();
 
         if (mxComponent.is())
             mxComponent->dispose();
@@ -774,13 +775,16 @@ void Test::testSkipImages()
         if (bSkipImages)
         {
             // FilterOptions parameter
-            uno::Sequence<beans::PropertyValue> args( comphelper::InitPropertySequence({
-                    { "FilterOptions", uno::Any(OUString::createFromAscii(aFilterNames[nFilter][1])) }
+            uno::Sequence<beans::PropertyValue> args(comphelper::InitPropertySequence({
+                    { "FilterOptions", uno::Any(rFilterNamePair.second) }
             }));
-            mxComponent = loadFromDesktop(m_directories.getURLFromSrc(OUString::createFromAscii(aFilterNames[nFilter][0])), "com.sun.star.text.TextDocument", args);
-            sFailedMessage = sFailedMessage + " - " + aFilterNames[nFilter][1];
-        } else
-            mxComponent = loadFromDesktop(m_directories.getURLFromSrc(OUString::createFromAscii(aFilterNames[nFilter][0])), "com.sun.star.text.TextDocument");
+            mxComponent = loadFromDesktop(m_directories.getURLFromSrc(rFilterNamePair.first), "com.sun.star.text.TextDocument", args);
+            sFailedMessage = sFailedMessage + " - " + rFilterNamePair.second.toUtf8();
+        }
+        else
+        {
+            mxComponent = loadFromDesktop(m_directories.getURLFromSrc(rFilterNamePair.first), "com.sun.star.text.TextDocument");
+        }
 
         // Check shapes (images, textboxes, custom shapes)
         uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
@@ -828,7 +832,7 @@ void Test::testSkipImages()
 
 void Test::testRedlineFlags()
 {
-    const char* aFilterNames[] = {
+    const OUString aFilterNames[] = {
         "writer8",
         "Rich Text Format",
         "MS Word 97",
@@ -859,13 +863,13 @@ void Test::testRedlineFlags()
         rIDRA.GetRedlineFlags() & ~RedlineFlags::ShowDelete;
     rIDRA.SetRedlineFlags(nRedlineFlags);
 
-    for (size_t nFilter = 0; nFilter < SAL_N_ELEMENTS(aFilterNames); ++nFilter)
+    for (OUString const & rFilterName : aFilterNames)
     {
         // export the document
         uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
 
         utl::MediaDescriptor aMediaDescriptor;
-        aMediaDescriptor["FilterName"] <<= OUString::createFromAscii(aFilterNames[nFilter]);
+        aMediaDescriptor["FilterName"] <<= rFilterName;
         utl::TempFile aTempFile;
         aTempFile.EnableKillingFile();
         xStorable->storeToURL(aTempFile.GetURL(),
@@ -873,7 +877,7 @@ void Test::testRedlineFlags()
 
         // tdf#97103 check that redline mode is properly restored
         CPPUNIT_ASSERT_EQUAL_MESSAGE(
-            OString(OString("redline mode not restored in ") + aFilterNames[nFilter]).getStr(),
+            OString(OString("redline mode not restored in ") + rFilterName.toUtf8()).getStr(),
             static_cast<int>(nRedlineFlags), static_cast<int>(rIDRA.GetRedlineFlags()));
     }
 }


More information about the Libreoffice-commits mailing list