Date: prev next · Thread: first prev next last
2013 Archives by date, by thread · List index


Bug 36960 was never fixed correctly (or rather, I suspect it was fixed, then 
broken when work was done to make the tests pass). The attached patch fixes 
the bug and adds new tests for cross-references to numbered paragraphs. The 
nature of the bug is that if you have numbered paragraphs like this:

   1. one
        (a) two
        (b) three
   2. four
        (a) five

a cross reference in paragraph 2(a), to paragraph 1(a), returns "1.(a)", which 
is not correct.
diff --git a/sw/qa/complex/writer/CheckCrossReferences.java 
b/sw/qa/complex/writer/CheckCrossReferences.java
index 541ea49..ced089f 100644
--- a/sw/qa/complex/writer/CheckCrossReferences.java
+++ b/sw/qa/complex/writer/CheckCrossReferences.java
@@ -38,28 +38,20 @@ public class CheckCrossReferences {
     public com.sun.star.text.XTextField getNextField()
         throws com.sun.star.uno.Exception
     {
-        if ( xPortionEnum != null ) {
-            while ( xPortionEnum.hasMoreElements() ) {
-                com.sun.star.beans.XPropertySet xPortionProps =
+        while (true) {
+            while (xPortionEnum == null) {
+                if (!xParaEnum.hasMoreElements())
+                    fail("Cannot retrieve next field.");
+
+                com.sun.star.container.XEnumerationAccess aPara =
                     UnoRuntime.queryInterface(
-                    com.sun.star.beans.XPropertySet.class , xPortionEnum.nextElement());
-                final String sPortionType =
-                    xPortionProps.getPropertyValue( "TextPortionType" ).toString();
-                if ( sPortionType.equals( "TextField") ) {
-                    com.sun.star.text.XTextField xField = UnoRuntime.queryInterface(
-                        com.sun.star.text.XTextField.class,
-                        xPortionProps.getPropertyValue( "TextField" ) );
-                    assertNotNull("Cannot retrieve next field.", xField);
-                    return xField;
-                }
+                    com.sun.star.container.XEnumerationAccess.class, xParaEnum.nextElement());
+                xPortionEnum = aPara.createEnumeration();
             }
-        }
 
-        while ( xParaEnum.hasMoreElements() ) {
-            com.sun.star.container.XEnumerationAccess aPara =
-                UnoRuntime.queryInterface(
-                com.sun.star.container.XEnumerationAccess.class, xParaEnum.nextElement());
-            xPortionEnum = aPara.createEnumeration();
+            if ( xPortionEnum == null )
+                break;
+
             while ( xPortionEnum.hasMoreElements() ) {
                 com.sun.star.beans.XPropertySet xPortionProps =
                     UnoRuntime.queryInterface(
@@ -74,9 +66,9 @@ public class CheckCrossReferences {
                     return xField;
                 }
             }
+           xPortionEnum = null;
         }
 
-        fail("Cannot retrieve next field.");
         return null; // unreachable
     }
 
@@ -135,6 +127,12 @@ public class CheckCrossReferences {
             final String FldResult4 = "1";
             final String FldResult5 = "1";
             final String FldResult6 = "A.1";
+            final String FldResult7 = "2(a)";
+            final String FldResult8 = "2(b)";
+            final String FldResult9 = "2";
+            final String FldResult10 = "1(a)";
+            final String FldResult11 = "(b)";
+            final String FldResult12 = "(a)";
 
             // variables for current field
             com.sun.star.text.XTextField xField = null;
@@ -175,6 +173,42 @@ public class CheckCrossReferences {
             checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER, FldResult6 );
             checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER_NO_CONTEXT, 
FldResult4 );
             checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER_FULL_CONTEXT, 
FldResult6 );
+
+            xField = getNextField();
+            xProps = getFieldProps( xField );
+            checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER, FldResult7 );
+            checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER_NO_CONTEXT, 
FldResult12 );
+            checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER_FULL_CONTEXT, 
FldResult7 );
+
+            xField = getNextField();
+            xProps = getFieldProps( xField );
+            checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER, FldResult8 );
+            checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER_NO_CONTEXT, 
FldResult11 );
+            checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER_FULL_CONTEXT, 
FldResult8 );
+
+            xField = getNextField();
+            xProps = getFieldProps( xField );
+            checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER, FldResult9 );
+            checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER_NO_CONTEXT, 
FldResult9 );
+            checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER_FULL_CONTEXT, 
FldResult9 );
+
+            xField = getNextField();
+            xProps = getFieldProps( xField );
+            checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER, FldResult4 );
+            checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER_NO_CONTEXT, 
FldResult4 );
+            checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER_FULL_CONTEXT, 
FldResult4 );
+
+            xField = getNextField();
+            xProps = getFieldProps( xField );
+            checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER, FldResult10 );
+            checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER_NO_CONTEXT, 
FldResult12 );
+            checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER_FULL_CONTEXT, 
FldResult10 );
+
+            xField = getNextField();
+            xProps = getFieldProps( xField );
+            checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER, FldResult12 );
+            checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER_NO_CONTEXT, 
FldResult12 );
+            checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER_FULL_CONTEXT, 
FldResult7 );
         }
 
         // insert a certain cross-reference bookmark and a reference field to this bookmark
diff --git a/sw/qa/complex/writer/testdocuments/CheckCrossReferences.odt 
b/sw/qa/complex/writer/testdocuments/CheckCrossReferences.odt
index d8102f0..d948442 100644
Binary files a/sw/qa/complex/writer/testdocuments/CheckCrossReferences.odt and 
b/sw/qa/complex/writer/testdocuments/CheckCrossReferences.odt differ
diff --git a/sw/source/core/doc/number.cxx b/sw/source/core/doc/number.cxx
index 27b2cb9..66be2d8e 100644
--- a/sw/source/core/doc/number.cxx
+++ b/sw/source/core/doc/number.cxx
@@ -739,7 +739,6 @@ String SwNumRule::MakeRefNumString( const SwNodeNum& rNodeNum,
     if ( rNodeNum.GetLevelInListTree() >= 0 )
     {
         bool bOldHadPrefix = true;
-        bool bFirstIteration = true;
         OUString sOldPrefix;
 
         const SwNodeNum* pWorkingNodeNum( &rNodeNum );
@@ -779,7 +778,7 @@ String SwNumRule::MakeRefNumString( const SwNodeNum& rNodeNum,
                     aExtremities.nPrefixChars -= nStrip;
                 }
 
-                if ((bFirstIteration || bOldHadPrefix) &&
+                if ((bOldHadPrefix) &&
                      aExtremities.nSuffixChars &&
                      !aExtremities.nPrefixChars
                    )
@@ -788,10 +787,6 @@ String SwNumRule::MakeRefNumString( const SwNodeNum& rNodeNum,
                     while (aPrevStr.Len() - nStrip2 < aExtremities.nSuffixChars)
                     {
                         char const cur = aPrevStr.GetChar(nStrip2);
-                        if  (!bFirstIteration && '\t' != cur && ' ' != cur)
-                        {
-                            break;
-                        }
                         --nStrip2;
                     }
                     if (nStrip2 < aPrevStr.Len())
@@ -799,7 +794,7 @@ String SwNumRule::MakeRefNumString( const SwNodeNum& rNodeNum,
                         aPrevStr.Erase(nStrip2, aPrevStr.Len() - nStrip2);
                     }
                 }
-                else if (sOldPrefix.getLength())
+                else if (!aExtremities.nSuffixChars && !bOldHadPrefix)
                 {
                     aRefNumStr.Insert(sOldPrefix, 0);
                 }
@@ -809,11 +804,6 @@ String SwNumRule::MakeRefNumString( const SwNodeNum& rNodeNum,
 
                 aRefNumStr.Insert( aPrevStr, 0 );
             }
-            else if ( aRefNumStr.Len() > 0 )
-            {
-                sOldPrefix += " ";
-                bOldHadPrefix = true;
-            }
 
             if ( bInclSuperiorNumLabels && pWorkingNodeNum->GetLevelInListTree() > 0 )
             {
@@ -830,7 +820,6 @@ String SwNumRule::MakeRefNumString( const SwNodeNum& rNodeNum,
             {
                 break;
             }
-            bFirstIteration = false;
         } while ( pWorkingNodeNum &&
                   pWorkingNodeNum->GetLevelInListTree() >= 0 &&
                   static_cast<sal_uInt8>(pWorkingNodeNum->GetLevelInListTree()) >= 
nRestrictInclToThisLevel );

Attachment: CheckCrossReferences.odt
Description: application/vnd.oasis.opendocument.text


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.