From c6e27348f82bf01b5d3cac9e1d26f5bb4308637a Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Tue, 22 Mar 2016 04:20:45 +0000 Subject: [PATCH] bug 59208: correctly understand val="1" for isBold, isItalic, etc git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1736126 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/xwpf/usermodel/XWPFRun.java | 13 ++++---- .../poi/xwpf/usermodel/TestXWPFRun.java | 33 +++++++++++++++++++ 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java index 4cdb2401b3..3bbcac704f 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java @@ -237,14 +237,15 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun { /** * 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) + ); } /** diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java index 0b28c86d53..1e45014c05 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java @@ -66,6 +66,37 @@ public class TestXWPFRun extends TestCase { //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 TestCase { assertEquals(true, run.isBold()); run.setBold(false); + // Implementation detail: POI natively prefers , + // but should correctly read val="0" and val="off" assertEquals(STOnOff.FALSE, rpr.getB().getVal()); }