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
This commit is contained in:
Javen O'Neal 2016-03-22 04:20:45 +00:00
parent e89f19bef3
commit a61e242e86
2 changed files with 40 additions and 6 deletions

View File

@ -237,14 +237,15 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun {
/** /**
* For isBold, isItalic etc * For isBold, isItalic etc
*/ */
private boolean isCTOnOff(CTOnOff onoff) { private static boolean isCTOnOff(CTOnOff onoff) {
if (!onoff.isSetVal()) if (!onoff.isSetVal())
return true; return true;
if (onoff.getVal() == STOnOff.ON) final STOnOff.Enum val = onoff.getVal();
return true; return (
if (onoff.getVal() == STOnOff.TRUE) (STOnOff.TRUE == val) ||
return true; (STOnOff.X_1 == val) ||
return false; (STOnOff.ON == val)
);
} }
/** /**

View File

@ -66,6 +66,37 @@ public class TestXWPFRun extends TestCase {
//fail("Position wrong"); //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() { public void testSetGetBold() {
CTRPr rpr = ctRun.addNewRPr(); CTRPr rpr = ctRun.addNewRPr();
rpr.addNewB().setVal(STOnOff.TRUE); rpr.addNewB().setVal(STOnOff.TRUE);
@ -74,6 +105,8 @@ public class TestXWPFRun extends TestCase {
assertEquals(true, run.isBold()); assertEquals(true, run.isBold());
run.setBold(false); 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()); assertEquals(STOnOff.FALSE, rpr.getB().getVal());
} }