poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From one...@apache.org
Subject svn commit: r1736126 - in /poi/trunk/src/ooxml: java/org/apache/poi/xwpf/usermodel/XWPFRun.java testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java
Date Tue, 22 Mar 2016 04:20:45 GMT
Author: onealj
Date: Tue Mar 22 04:20:45 2016
New Revision: 1736126

URL: http://svn.apache.org/viewvc?rev=1736126&view=rev
Log:
bug 59208: correctly understand val="1" for isBold, isItalic, etc

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java?rev=1736126&r1=1736125&r2=1736126&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java Tue Mar 22 04:20:45
2016
@@ -237,14 +237,15 @@ public class XWPFRun implements ISDTCont
     /**
      * For isBold, isItalic etc
      */
-    private boolean isCTOnOff(CTOnOff onoff) {
+    private static boolean isCTOnOff(CTOnOff onoff) {
         if (!onoff.isSetVal())
             return true;
-        if (onoff.getVal() == STOnOff.ON)
-            return true;
-        if (onoff.getVal() == STOnOff.TRUE)
-            return true;
-        return false;
+        final STOnOff.Enum val = onoff.getVal();
+        return (
+            (STOnOff.TRUE == val) ||
+            (STOnOff.X_1 == val) ||
+            (STOnOff.ON == val)
+        );
     }
 
     /**

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java?rev=1736126&r1=1736125&r2=1736126&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java Tue Mar 22
04:20:45 2016
@@ -66,6 +66,37 @@ public class TestXWPFRun extends TestCas
         //fail("Position wrong");
     }
 
+    /*
+     * bug 59208
+     * Purpose: test all valid boolean-like values
+     * exercise isCTOnOff(CTOnOff) through all valid permutations
+     */
+    public void testCTOnOff() {
+        CTRPr rpr = ctRun.addNewRPr();
+        CTOnOff bold = rpr.addNewB();        
+        XWPFRun run = new XWPFRun(ctRun, p);
+
+        // True values: "true", "1", "on"
+        bold.setVal(STOnOff.TRUE);
+        assertEquals(true, run.isBold());    
+
+        bold.setVal(STOnOff.X_1);
+        assertEquals(true, run.isBold());
+
+        bold.setVal(STOnOff.ON);
+        assertEquals(true, run.isBold());
+
+        // False values: "false", "0", "off"
+        bold.setVal(STOnOff.FALSE);
+        assertEquals(false, run.isBold());
+
+        bold.setVal(STOnOff.X_0);
+        assertEquals(false, run.isBold());
+
+        bold.setVal(STOnOff.OFF);
+        assertEquals(false, run.isBold());
+    }
+
     public void testSetGetBold() {
         CTRPr rpr = ctRun.addNewRPr();
         rpr.addNewB().setVal(STOnOff.TRUE);
@@ -74,6 +105,8 @@ public class TestXWPFRun extends TestCas
         assertEquals(true, run.isBold());
 
         run.setBold(false);
+        // Implementation detail: POI natively prefers <w:b w:val="false"/>,
+        // but should correctly read val="0" and val="off"
         assertEquals(STOnOff.FALSE, rpr.getB().getVal());
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message