More rich text related tests

git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353801 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2005-11-29 22:23:28 +00:00
parent b8e7d71490
commit ababb95a88
1 changed files with 166 additions and 5 deletions

View File

@ -26,6 +26,8 @@ import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.hslf.record.TextBytesAtom;
import org.apache.poi.hslf.record.TextCharsAtom;
import org.apache.poi.hslf.record.TextHeaderAtom;
import org.apache.poi.hslf.record.StyleTextPropAtom.TextPropCollection;
import org.apache.poi.hslf.usermodel.RichTextRun;
import org.apache.poi.hslf.usermodel.SlideShow;
/**
@ -36,13 +38,22 @@ import org.apache.poi.hslf.usermodel.SlideShow;
public class TestTextRun extends TestCase {
// SlideShow primed on the test data
private SlideShow ss;
private SlideShow ssRich;
private HSLFSlideShow hss;
private HSLFSlideShow hssRich;
public TestTextRun() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path");
// Basic (non rich) test file
String filename = dirname + "/basic_test_ppt_file.ppt";
HSLFSlideShow hss = new HSLFSlideShow(filename);
hss = new HSLFSlideShow(filename);
ss = new SlideShow(hss);
// Rich test file
filename = dirname + "/Single_Coloured_Page.ppt";
hssRich = new HSLFSlideShow(filename);
ssRich = new SlideShow(hssRich);
}
/**
@ -61,6 +72,17 @@ public class TestTextRun extends TestCase {
// Raw text has \r instead
assertEquals("This is a test title", textRuns[0].getRawText());
assertEquals("This is a test subtitle\rThis is on page 1", textRuns[1].getRawText());
// Now check on a rich text run
Slide slideOneR = ssRich.getSlides()[0];
TextRun[] textRunsR = slideOneR.getTextRuns();
assertEquals(2, textRunsR.length);
assertEquals("This is a title, it\u2019s in black", textRunsR[0].getText());
assertEquals("This is the subtitle, in bold\nThis bit is blue and italic\nThis bit is red (normal)", textRunsR[1].getText());
assertEquals("This is a title, it\u2019s in black", textRunsR[0].getRawText());
assertEquals("This is the subtitle, in bold\rThis bit is blue and italic\rThis bit is red (normal)", textRunsR[1].getRawText());
}
/**
@ -150,14 +172,96 @@ public class TestTextRun extends TestCase {
* set up for it
*/
public void testGetRichTextNonRich() throws Exception {
// TODO
Slide slideOne = ss.getSlides()[0];
TextRun[] textRuns = slideOne.getTextRuns();
assertEquals(2, textRuns.length);
TextRun trA = textRuns[0];
TextRun trB = textRuns[1];
assertEquals(1, trA.getRichTextRuns().length);
assertEquals(1, trB.getRichTextRuns().length);
RichTextRun rtrA = trA.getRichTextRuns()[0];
RichTextRun rtrB = trB.getRichTextRuns()[0];
assertEquals(trA.getText(), rtrA.getText());
assertEquals(trB.getText(), rtrB.getText());
assertNull(rtrA._getRawCharacterStyle());
assertNull(rtrA._getRawParagraphStyle());
assertNull(rtrB._getRawCharacterStyle());
assertNull(rtrB._getRawParagraphStyle());
}
/**
* Tests to ensure that the rich text runs are built up correctly
*/
public void testGetRichText() throws Exception {
// TODO
Slide slideOne = ssRich.getSlides()[0];
TextRun[] textRuns = slideOne.getTextRuns();
assertEquals(2, textRuns.length);
TextRun trA = textRuns[0];
TextRun trB = textRuns[1];
assertEquals(1, trA.getRichTextRuns().length);
assertEquals(3, trB.getRichTextRuns().length);
RichTextRun rtrA = trA.getRichTextRuns()[0];
RichTextRun rtrB = trB.getRichTextRuns()[0];
RichTextRun rtrC = trB.getRichTextRuns()[1];
RichTextRun rtrD = trB.getRichTextRuns()[2];
assertEquals(trA.getText(), rtrA.getText());
assertEquals(trB.getText().substring(0, 30), rtrB.getText());
assertEquals(trB.getText().substring(30,58), rtrC.getText());
assertEquals(trB.getText().substring(58,82), rtrD.getText());
assertNull(rtrA._getRawCharacterStyle());
assertNull(rtrA._getRawParagraphStyle());
assertNotNull(rtrB._getRawCharacterStyle());
assertNotNull(rtrB._getRawParagraphStyle());
assertNotNull(rtrC._getRawCharacterStyle());
assertNotNull(rtrC._getRawParagraphStyle());
assertNotNull(rtrD._getRawCharacterStyle());
assertNotNull(rtrD._getRawParagraphStyle());
// Same paragraph styles
assertEquals(rtrB._getRawParagraphStyle(), rtrC._getRawParagraphStyle());
assertEquals(rtrB._getRawParagraphStyle(), rtrD._getRawParagraphStyle());
// Different char styles
assertFalse( rtrB._getRawCharacterStyle().equals( rtrC._getRawCharacterStyle() ));
assertFalse( rtrB._getRawCharacterStyle().equals( rtrD._getRawCharacterStyle() ));
assertFalse( rtrC._getRawCharacterStyle().equals( rtrD._getRawCharacterStyle() ));
}
/**
* Tests to ensure that setting the text where the text isn't rich,
* ensuring that everything stays with the same default styling
*/
public void testSetTextWhereNotRich() throws Exception {
Slide slideOne = ss.getSlides()[0];
TextRun[] textRuns = slideOne.getTextRuns();
TextRun trB = textRuns[1];
assertEquals(1, trB.getRichTextRuns().length);
RichTextRun rtrB = trB.getRichTextRuns()[0];
assertEquals(trB.getText(), rtrB.getText());
assertNull(rtrB._getRawCharacterStyle());
assertNull(rtrB._getRawParagraphStyle());
// Change text via normal
trB.setText("Test Foo Test");
rtrB = trB.getRichTextRuns()[0];
assertEquals("Test Foo Test", trB.getText());
assertEquals("Test Foo Test", rtrB.getText());
assertNull(rtrB._getRawCharacterStyle());
assertNull(rtrB._getRawParagraphStyle());
}
/**
@ -165,7 +269,47 @@ public class TestTextRun extends TestCase {
* sets everything to the same styling
*/
public void testSetTextWhereRich() throws Exception {
// TODO
Slide slideOne = ssRich.getSlides()[0];
TextRun[] textRuns = slideOne.getTextRuns();
TextRun trB = textRuns[1];
assertEquals(3, trB.getRichTextRuns().length);
RichTextRun rtrB = trB.getRichTextRuns()[0];
RichTextRun rtrC = trB.getRichTextRuns()[1];
RichTextRun rtrD = trB.getRichTextRuns()[2];
TextPropCollection tpBP = rtrB._getRawParagraphStyle();
TextPropCollection tpBC = rtrB._getRawCharacterStyle();
TextPropCollection tpCP = rtrC._getRawParagraphStyle();
TextPropCollection tpCC = rtrC._getRawCharacterStyle();
TextPropCollection tpDP = rtrD._getRawParagraphStyle();
TextPropCollection tpDC = rtrD._getRawCharacterStyle();
assertEquals(trB.getText().substring(0, 30), rtrB.getText());
assertNotNull(tpBP);
assertNotNull(tpBC);
assertNotNull(tpCP);
assertNotNull(tpCC);
assertNotNull(tpDP);
assertNotNull(tpDC);
assertTrue(tpBP.equals(tpCP));
assertTrue(tpBP.equals(tpDP));
assertTrue(tpCP.equals(tpDP));
assertFalse(tpBC.equals(tpCC));
assertFalse(tpBC.equals(tpDC));
assertFalse(tpCC.equals(tpDC));
// Change text via normal
trB.setText("Test Foo Test");
// Ensure now have first style
assertEquals(1, trB.getRichTextRuns().length);
rtrB = trB.getRichTextRuns()[0];
assertEquals("Test Foo Test", trB.getText());
assertEquals("Test Foo Test", rtrB.getText());
assertNotNull(rtrB._getRawCharacterStyle());
assertNotNull(rtrB._getRawParagraphStyle());
assertEquals( tpBP, rtrB._getRawParagraphStyle() );
assertEquals( tpBC, rtrB._getRawCharacterStyle() );
}
/**
@ -173,7 +317,24 @@ public class TestTextRun extends TestCase {
* in a rich text run, that doesn't happen to actually be rich
*/
public void testChangeTextInRichTextRunNonRich() throws Exception {
// TODO
Slide slideOne = ss.getSlides()[0];
TextRun[] textRuns = slideOne.getTextRuns();
TextRun trB = textRuns[1];
assertEquals(1, trB.getRichTextRuns().length);
RichTextRun rtrB = trB.getRichTextRuns()[0];
assertEquals(trB.getText(), rtrB.getText());
assertNull(rtrB._getRawCharacterStyle());
assertNull(rtrB._getRawParagraphStyle());
// Change text via rich
rtrB.setText("Test Test Test");
assertEquals("Test Test Test", trB.getText());
assertEquals("Test Test Test", rtrB.getText());
// Will now have dummy props
assertNotNull(rtrB._getRawCharacterStyle());
assertNotNull(rtrB._getRawParagraphStyle());
}
/**