[Libreoffice-commits] .: 2 commits - sw/qa

Lubos Lunak llunak at kemper.freedesktop.org
Fri Jul 13 11:21:15 PDT 2012


 sw/qa/extras/README                      |   19 +++----
 sw/qa/extras/ooxmlexport/ooxmlexport.cxx |    4 -
 sw/qa/extras/ooxmlimport/ooxmlimport.cxx |   75 +++++--------------------------
 sw/qa/extras/swmodeltestbase.hxx         |   35 ++++++++++++++
 sw/qa/extras/ww8export/ww8export.cxx     |    3 -
 5 files changed, 61 insertions(+), 75 deletions(-)

New commits:
commit 76fd08ed822e791c812dd674265d977a4b3c59bb
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Fri Jul 13 20:18:52 2012 +0200

    getParagraph helper
    
    Change-Id: I8170f95e01b98db2fe79070dacfd7436e37019a2

diff --git a/sw/qa/extras/README b/sw/qa/extras/README
index b65a2b0..75d45bb 100644
--- a/sw/qa/extras/README
+++ b/sw/qa/extras/README
@@ -159,6 +159,11 @@ uno::Reference<container::XEnumeration> paraEnum = paraEnumAccess->createEnumera
 // get the 2nd paragraph
 uno::Reference<uno::XInterface> paragraph(paraEnum->nextElement(), uno::UNO_QUERY);
 
+Note that for paragraphs it's easier to use getParagraph(), which gets the given
+paragraph (counted from 1) and optionally checks the paragraph text.
+
+uno::Reference< text::XTextRange > paragraph = getParagraph( 2, "TEXT" )
+
 === XNamedAccess (e.g. get a bookmark named 'position1'):
 
 Basic:
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index fab93b1..cfbd45f 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -269,22 +269,10 @@ para = enum.NextElement
 xray para.String
 xray para.PageStyleName
 */
-    uno::Reference<text::XTextDocument> textDocument(mxComponent, uno::UNO_QUERY);
-    uno::Reference<container::XEnumerationAccess> paraEnumAccess(textDocument->getText(), uno::UNO_QUERY);
-    // list of paragraphs
-    uno::Reference<container::XEnumeration> paraEnum = paraEnumAccess->createEnumeration();
-    // go to 1st paragraph
-    (void) paraEnum->nextElement();
-    // get the 2nd paragraph
-    uno::Reference<uno::XInterface> paragraph(paraEnum->nextElement(), uno::UNO_QUERY);
-    // text of the paragraph
-    uno::Reference<text::XTextRange> text(paragraph, uno::UNO_QUERY);
-    CPPUNIT_ASSERT_EQUAL( OUString( "TEXT1" ), text->getString());
+    uno::Reference<uno::XInterface> paragraph = getParagraph( 2, "TEXT1" );
     // we want to test the paragraph is on the first page (it was put onto another page without the fix),
     // use a small trick and instead of checking the page layout, check the page style
-    uno::Reference<beans::XPropertySet> paragraphProperties(paragraph, uno::UNO_QUERY);
-    OUString pageStyle;
-    paragraphProperties->getPropertyValue( "PageStyleName" ) >>= pageStyle;
+    OUString pageStyle = getProperty< OUString >( paragraph, "PageStyleName" );
     CPPUNIT_ASSERT_EQUAL( OUString( "First Page" ), pageStyle );
 }
 
@@ -385,24 +373,11 @@ para2 = enum.nextElement
 xray para2.String
 xray para2.PageStyleName
 */
-    uno::Reference<text::XTextDocument> textDocument(mxComponent, uno::UNO_QUERY);
-    uno::Reference<container::XEnumerationAccess> paraEnumAccess(textDocument->getText(), uno::UNO_QUERY);
-    // list of paragraphs
-    uno::Reference<container::XEnumeration> paraEnum = paraEnumAccess->createEnumeration();
-    // go to 1st paragraph
-    (void) paraEnum->nextElement();
     // get the 2nd and 3rd paragraph
-    uno::Reference<uno::XInterface> paragraph1(paraEnum->nextElement(), uno::UNO_QUERY);
-    uno::Reference<uno::XInterface> paragraph2(paraEnum->nextElement(), uno::UNO_QUERY);
-    uno::Reference<text::XTextRange> text1(paragraph1, uno::UNO_QUERY);
-    uno::Reference<text::XTextRange> text2(paragraph2, uno::UNO_QUERY);
-    CPPUNIT_ASSERT_EQUAL( OUString( "one" ), text1->getString());
-    CPPUNIT_ASSERT_EQUAL( OUString( "two" ), text2->getString());
-    uno::Reference<beans::XPropertySet> paragraphProperties1(paragraph1, uno::UNO_QUERY);
-    uno::Reference<beans::XPropertySet> paragraphProperties2(paragraph2, uno::UNO_QUERY);
-    OUString pageStyle1, pageStyle2;
-    paragraphProperties1->getPropertyValue( "PageStyleName" ) >>= pageStyle1;
-    paragraphProperties2->getPropertyValue( "PageStyleName" ) >>= pageStyle2;
+    uno::Reference<uno::XInterface> paragraph1 = getParagraph( 2, "one" );
+    uno::Reference<uno::XInterface> paragraph2 = getParagraph( 3, "two" );
+    OUString pageStyle1 = getProperty< OUString >( paragraph1, "PageStyleName" );
+    OUString pageStyle2 = getProperty< OUString >( paragraph2, "PageStyleName" );
     CPPUNIT_ASSERT_EQUAL( OUString( "Converted1" ), pageStyle1 );
     CPPUNIT_ASSERT_EQUAL( OUString( "Converted2" ), pageStyle2 );
 
@@ -424,24 +399,11 @@ para2 = enum.nextElement
 xray para2.String
 xray para2.PageStyleName
 */
-    uno::Reference<text::XTextDocument> textDocument(mxComponent, uno::UNO_QUERY);
-    uno::Reference<container::XEnumerationAccess> paraEnumAccess(textDocument->getText(), uno::UNO_QUERY);
-    // list of paragraphs
-    uno::Reference<container::XEnumeration> paraEnum = paraEnumAccess->createEnumeration();
     // get the 2nd and 4th paragraph
-    (void) paraEnum->nextElement();
-    uno::Reference<uno::XInterface> paragraph1(paraEnum->nextElement(), uno::UNO_QUERY);
-    (void) paraEnum->nextElement();
-    uno::Reference<uno::XInterface> paragraph2(paraEnum->nextElement(), uno::UNO_QUERY);
-    uno::Reference<text::XTextRange> text1(paragraph1, uno::UNO_QUERY);
-    uno::Reference<text::XTextRange> text2(paragraph2, uno::UNO_QUERY);
-    CPPUNIT_ASSERT_EQUAL( OUString( "text1" ), text1->getString());
-    CPPUNIT_ASSERT_EQUAL( OUString( "text2" ), text2->getString());
-    uno::Reference<beans::XPropertySet> paragraphProperties1(paragraph1, uno::UNO_QUERY);
-    uno::Reference<beans::XPropertySet> paragraphProperties2(paragraph2, uno::UNO_QUERY);
-    OUString pageStyle1, pageStyle2;
-    paragraphProperties1->getPropertyValue( "PageStyleName" ) >>= pageStyle1;
-    paragraphProperties2->getPropertyValue( "PageStyleName" ) >>= pageStyle2;
+    uno::Reference<uno::XInterface> paragraph1 = getParagraph( 2, "text1" );
+    uno::Reference<uno::XInterface> paragraph2 = getParagraph( 4, "text2" );
+    OUString pageStyle1 = getProperty< OUString >( paragraph1, "PageStyleName" );
+    OUString pageStyle2 = getProperty< OUString >( paragraph2, "PageStyleName" );
     // "Standard" is the style for the first page (2nd is "Converted1").
     CPPUNIT_ASSERT_EQUAL( OUString( "Standard" ), pageStyle1 );
     CPPUNIT_ASSERT_EQUAL( OUString( "Standard" ), pageStyle2 );
@@ -693,16 +655,9 @@ numbering = numberingstyle.getByIndex(0)
 xray numbering(11)  - should be 4, arabic
 note that the indexes may get off as the implementation evolves, C++ code seaches in loops
 */
-    uno::Reference<text::XTextDocument> textDocument(mxComponent, uno::UNO_QUERY);
-    uno::Reference<container::XEnumerationAccess> paraEnumAccess(textDocument->getText(), uno::UNO_QUERY);
-    // list of paragraphs
-    uno::Reference<container::XEnumeration> paraEnum = paraEnumAccess->createEnumeration();
-    uno::Reference<uno::XInterface> paragraph(paraEnum->nextElement(), uno::UNO_QUERY);
-    uno::Reference<text::XTextRange> text(paragraph, uno::UNO_QUERY);
-    CPPUNIT_ASSERT_EQUAL( OUString( "Text1." ), text->getString());
-    uno::Reference<beans::XPropertySet> xPropertySet( paragraph, uno::UNO_QUERY );
-    OUString numberingStyleName;
-    xPropertySet->getPropertyValue( "NumberingStyleName" ) >>= numberingStyleName;
+    uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
+    uno::Reference< text::XTextRange > paragraph = getParagraph( 1, "Text1." );
+    OUString numberingStyleName = getProperty< OUString >( paragraph, "NumberingStyleName" );
     uno::Reference<text::XNumberingRulesSupplier> xNumberingRulesSupplier(mxComponent, uno::UNO_QUERY);
     uno::Reference<container::XIndexAccess> numberingRules(xNumberingRulesSupplier->getNumberingRules(), uno::UNO_QUERY);
     uno::Reference<container::XIndexAccess> numberingRule;
@@ -710,9 +665,7 @@ note that the indexes may get off as the implementation evolves, C++ code seache
          i < numberingRules->getCount();
          ++i )
     {
-        xPropertySet.set( numberingRules->getByIndex( i ), uno::UNO_QUERY );
-        OUString name;
-        xPropertySet->getPropertyValue( "Name" ) >>= name;
+        OUString name = getProperty< OUString >( numberingRules->getByIndex( i ), "Name" );
         if( name == numberingStyleName )
         {
             numberingRule.set( numberingRules->getByIndex( i ), uno::UNO_QUERY );
diff --git a/sw/qa/extras/swmodeltestbase.hxx b/sw/qa/extras/swmodeltestbase.hxx
index 72af401..8792eb3 100644
--- a/sw/qa/extras/swmodeltestbase.hxx
+++ b/sw/qa/extras/swmodeltestbase.hxx
@@ -27,6 +27,7 @@
 
 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
 #include <com/sun/star/text/XTextDocument.hpp>
+#include <com/sun/star/text/XTextRange.hpp>
 
 #include <test/bootstrapfixture.hxx>
 #include <unotest/macros_test.hxx>
@@ -160,6 +161,22 @@ protected:
         return data;
     }
 
+    // Get paragraph (counted from 1), optionally check it contains the given text.
+    uno::Reference< text::XTextRange > getParagraph( int number, rtl::OUString content ) const
+    {
+        uno::Reference<text::XTextDocument> textDocument(mxComponent, uno::UNO_QUERY);
+        uno::Reference<container::XEnumerationAccess> paraEnumAccess(textDocument->getText(), uno::UNO_QUERY);
+        uno::Reference<container::XEnumeration> paraEnum = paraEnumAccess->createEnumeration();
+        for( int i = 1;
+             i < number;
+             ++i )
+            paraEnum->nextElement();
+        uno::Reference< text::XTextRange > paragraph( paraEnum->nextElement(), uno::UNO_QUERY );
+        if( !content.isEmpty())
+            CPPUNIT_ASSERT_EQUAL( content, paragraph->getString());
+        return paragraph;
+    }
+
     uno::Reference<lang::XComponent> mxComponent;
     xmlBufferPtr mpXmlBuffer;
 };
commit 04495938d9598a1968fb6757b09caa768071bf8a
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Fri Jul 13 19:57:59 2012 +0200

    helper for XPropertySet
    
    Change-Id: Ia00cf37a4bc46c73047ecc4c57f11a4a3de3cb90

diff --git a/sw/qa/extras/README b/sw/qa/extras/README
index 57447fb..b65a2b0 100644
--- a/sw/qa/extras/README
+++ b/sw/qa/extras/README
@@ -120,11 +120,9 @@ prints the internal name of the object (e.g. 'SwXTextDocument' for 'xray ThisCom
 above the list of its properties. Inspect this class/interface in the code (that is,
 under offapi/, udkapi/, or wherever it is implemented) and search for a function named
 similarly to the property you want (getXYZ()). If there is none, it is most
-probably a property that can be read using XPropertySet:
+probably a property that can be read using XPropertySet or using the getProperty helper:
 
-uno::Reference<beans::XPropertySet> properties(textDocument, uno::UNO_QUERY);
-sal_Int32 val; // the right type for the property
-properties->getPropertyValue("CharacterCount") >>= val;
+sal_Int32 val = getProperty< sal_Int32 >( textDocument, "CharacterCount" );
 
 If there is a function to obtain the property, you need access it using the right interface.
 If the class itself is not the right interface, then it is one of the classes it inherits
@@ -215,9 +213,7 @@ uno::Reference<drawing::XDrawPageSupplier> drawPageSupplier(textDocument, uno::U
 uno::Reference<drawing::XDrawPage> drawPage = drawPageSupplier->getDrawPage();
 uno::Reference<drawing::XShape> image;
 drawPage->getByIndex(0) >>= image;
-uno::Reference<beans::XPropertySet> imageProperties(image, uno::UNO_QUERY);
-uno::Reference<graphic::XGraphic> graphic;
-imageProperties->getPropertyValue( "Graphic" ) >>= graphic;
+uno::Reference<graphic::XGraphic> graphic = getProperty< uno::Reference< graphic::XGraphic > >( image, "Graphic" );
 
 
 === Styles
@@ -238,6 +234,4 @@ uno::Reference<container::XNameAccess> pageStyles;
 styleFamilies->getByName("PageStyles") >>= pageStyles;
 uno::Reference<uno::XInterface> defaultStyle;
 pageStyles->getByName("Default") >>= defaultStyle;
-uno::Reference<beans::XPropertySet> styleProperties( defaultStyle, uno::UNO_QUERY );
-sal_Int32 width;
-styleProperties->getPropertyValue( "Width" ) >>= width;
+sal_Int32 width = getProperty< sal_Int32 >( defaultStyle, "Width" );
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index 96be2a7..16f9e31 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -86,8 +86,8 @@ void Test::defaultTabStopNotInStyles()
 // xray ThisComponent.StyleFamilies(1)(0).ParaTabStop
     uno::Reference< container::XNameAccess > paragraphStyles = getStyles( "ParagraphStyles" );
     uno::Reference< beans::XPropertySet > properties( paragraphStyles->getByName( "Standard" ), uno::UNO_QUERY );
-    uno::Sequence< style::TabStop > stops;
-    properties->getPropertyValue( "ParaTabStops" ) >>= stops;
+    uno::Sequence< style::TabStop > stops = getProperty< uno::Sequence< style::TabStop > >(
+        paragraphStyles->getByName( "Standard" ), "ParaTabStops" );
     CPPUNIT_ASSERT_EQUAL( 0, stops.getLength());
 }
 
diff --git a/sw/qa/extras/swmodeltestbase.hxx b/sw/qa/extras/swmodeltestbase.hxx
index 669e559..72af401 100644
--- a/sw/qa/extras/swmodeltestbase.hxx
+++ b/sw/qa/extras/swmodeltestbase.hxx
@@ -142,6 +142,24 @@ protected:
         return aRet;
     }
 
+    template< typename T >
+    T getProperty( uno::Any obj, const rtl::OUString& name ) const
+    {
+        uno::Reference< beans::XPropertySet > properties( obj, uno::UNO_QUERY );
+        T data;
+        properties->getPropertyValue( name ) >>= data;
+        return data;
+    }
+
+    template< typename T >
+    T getProperty( uno::Reference< uno::XInterface > obj, const rtl::OUString& name ) const
+    {
+        uno::Reference< beans::XPropertySet > properties( obj, uno::UNO_QUERY );
+        T data;
+        properties->getPropertyValue( name ) >>= data;
+        return data;
+    }
+
     uno::Reference<lang::XComponent> mxComponent;
     xmlBufferPtr mpXmlBuffer;
 };
diff --git a/sw/qa/extras/ww8export/ww8export.cxx b/sw/qa/extras/ww8export/ww8export.cxx
index f0587a7..4bf4a57 100644
--- a/sw/qa/extras/ww8export/ww8export.cxx
+++ b/sw/qa/extras/ww8export/ww8export.cxx
@@ -76,8 +76,7 @@ void Test::testN325936()
     uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
     uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY);
     uno::Reference<beans::XPropertySet> xPropertySet(xDraws->getByIndex(0), uno::UNO_QUERY);
-    sal_Int32 nValue = 0;
-    xPropertySet->getPropertyValue("BackColorTransparency") >>= nValue;
+    sal_Int32 nValue = getProperty< sal_Int32 >(xDraws->getByIndex(0), "BackColorTransparency");
     CPPUNIT_ASSERT_EQUAL(sal_Int32(100), nValue);
 }
 


More information about the Libreoffice-commits mailing list