Bug 61586: Add test which shows that it works as expected

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1811355 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2017-10-06 17:41:20 +00:00
parent 0e52f62a1e
commit c2d09c0217
2 changed files with 89 additions and 7 deletions

View File

@ -19,16 +19,18 @@ package org.apache.poi.hwpf.usermodel;
import java.io.IOException;
import junit.framework.TestCase;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.HWPFTestDataSamples;
import org.apache.poi.hwpf.model.Ffn;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* API for processing of symbols, see Bugzilla 49908
*/
public final class TestRangeSymbols extends TestCase {
public final class TestRangeSymbols {
@Test
public void test() throws IOException {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug49908.doc");
@ -36,13 +38,93 @@ public final class TestRangeSymbols extends TestCase {
assertTrue(range.numCharacterRuns() >= 2);
CharacterRun chr = range.getCharacterRun(0);
assertEquals(false, chr.isSymbol());
assertFalse(chr.isSymbol());
chr = range.getCharacterRun(1);
assertEquals(true, chr.isSymbol());
assertTrue(chr.isSymbol());
assertEquals("\u0028", chr.text());
assertEquals("Wingdings", chr.getSymbolFont().getMainFontName());
Ffn symbolFont = chr.getSymbolFont();
assertNotNull(symbolFont);
assertEquals("Wingdings", symbolFont.getMainFontName());
assertEquals(0xf028, chr.getSymbolCharacter());
}
@Test
public void test61586() throws IOException {
HWPFDocument document = HWPFTestDataSamples.openSampleFile("61586.doc");
assertEquals("\r" +
"\r" +
"TEST( \r" +
"111 (g.h/mL (AUC) and 15 (g/mL (Cmax). \r" +
"TEST( \r" +
"Greek mu(\r" +
"(\r\r", document.getText().toString());
Range range = document.getRange();
assertEquals(26, range.numCharacterRuns());
// newline
CharacterRun chr = range.getCharacterRun(0);
assertFalse(chr.isSymbol());
assertEquals("\r", chr.text());
// "TEST"
chr = range.getCharacterRun(2);
assertFalse(chr.isSymbol());
assertEquals("TEST", chr.text());
// "registered" symbol
chr = range.getCharacterRun(3);
assertTrue(chr.isSymbol());
assertEquals("\u0028", chr.text());
Ffn symbolFont = chr.getSymbolFont();
assertNotNull(symbolFont);
assertEquals("Symbol", symbolFont.getMainFontName());
assertEquals(0xf0e2, chr.getSymbolCharacter());
assertEquals("(", chr.text());
// Greek "mu" symbol
chr = range.getCharacterRun(8);
assertTrue(chr.isSymbol());
assertEquals("\u0028", chr.text());
symbolFont = chr.getSymbolFont();
assertNotNull(symbolFont);
assertEquals("Symbol", symbolFont.getMainFontName());
assertEquals(0xf06d, chr.getSymbolCharacter());
// Greek "mu" symbol
chr = range.getCharacterRun(12);
assertTrue(chr.isSymbol());
assertEquals("\u0028", chr.text());
symbolFont = chr.getSymbolFont();
assertNotNull(symbolFont);
assertEquals("Symbol", symbolFont.getMainFontName());
assertEquals(0xf06d, chr.getSymbolCharacter());
// "registered" symbol
chr = range.getCharacterRun(17);
assertTrue(chr.isSymbol());
assertEquals("\u0028", chr.text());
symbolFont = chr.getSymbolFont();
assertNotNull(symbolFont);
assertEquals("Symbol", symbolFont.getMainFontName());
assertEquals(0xf0e2, chr.getSymbolCharacter());
// Greek "mu" symbol
chr = range.getCharacterRun(21);
assertTrue(chr.isSymbol());
assertEquals("\u0028", chr.text());
symbolFont = chr.getSymbolFont();
assertNotNull(symbolFont);
assertEquals("Symbol", symbolFont.getMainFontName());
assertEquals(0xf06d, chr.getSymbolCharacter());
// normal bracket, not a symbol
chr = range.getCharacterRun(23);
assertFalse(chr.isSymbol());
assertEquals("\u0028", chr.text());
document.close();
}
}

Binary file not shown.