Updated test from Yegor, to also test creating text boxes with properties
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@395219 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
52f147ce5d
commit
4a27fd3c8a
@ -120,51 +120,47 @@ public class TestShapes extends TestCase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Verify that we can add TextBox shapes to a slide
|
* Verify that we can add TextBox shapes to a slide
|
||||||
* @throws Exception
|
* and set some of the style attributes
|
||||||
*/
|
*/
|
||||||
public void testTextBoxWrite() throws Exception {
|
public void testTextBoxWrite() throws Exception {
|
||||||
ppt = new SlideShow();
|
ppt = new SlideShow();
|
||||||
Slide sl = ppt.createSlide();
|
Slide sl = ppt.createSlide();
|
||||||
|
RichTextRun rt;
|
||||||
|
|
||||||
|
String val = "Hello, World!";
|
||||||
|
|
||||||
|
// Create a new textbox, and give it lots of properties
|
||||||
TextBox txtbox = new TextBox();
|
TextBox txtbox = new TextBox();
|
||||||
txtbox.setText("Hello, World!");
|
txtbox.setText(val);
|
||||||
txtbox.setFontSize(42);
|
txtbox.setFontSize(42);
|
||||||
txtbox.setBold(true);
|
txtbox.setBold(true);
|
||||||
txtbox.setItalic(true);
|
txtbox.setItalic(true);
|
||||||
|
txtbox.setUnderline(false);
|
||||||
sl.addShape(txtbox);
|
sl.addShape(txtbox);
|
||||||
|
|
||||||
txtbox = new TextBox();
|
// Check it before save
|
||||||
txtbox.setText("Plain text in default font");
|
rt = txtbox.getRichTextRuns()[0];
|
||||||
sl.addShape(txtbox);
|
assertEquals(val, rt.getText());
|
||||||
|
assertEquals(42, rt.getFontSize());
|
||||||
|
assertTrue(rt.isBold());
|
||||||
|
assertTrue(rt.isItalic());
|
||||||
|
assertFalse(rt.isUnderlined());
|
||||||
|
|
||||||
assertEquals(sl.getShapes().length, 2);
|
// Serialize and read again
|
||||||
|
|
||||||
//serialize and read again
|
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
ppt.write(out);
|
ppt.write(out);
|
||||||
out.close();
|
out.close();
|
||||||
|
|
||||||
ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
|
ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
|
||||||
sl = ppt.getSlides()[0];
|
|
||||||
assertEquals(sl.getShapes().length, 2);
|
|
||||||
|
|
||||||
Shape[] sh = sl.getShapes();
|
txtbox = (TextBox)sl.getShapes()[0];
|
||||||
for (int i = 0; i < sh.length; i++) {
|
rt = txtbox.getRichTextRuns()[0];
|
||||||
assertTrue(sh[i] instanceof TextBox);
|
|
||||||
txtbox = (TextBox)sh[i];
|
|
||||||
String text = txtbox.getText();
|
|
||||||
assertNotNull(text);
|
|
||||||
|
|
||||||
assertEquals(txtbox.getRichTextRuns().length, 1);
|
// Check after save
|
||||||
RichTextRun rt = txtbox.getRichTextRuns()[0];
|
assertEquals(val, rt.getText());
|
||||||
|
assertEquals(42, rt.getFontSize());
|
||||||
if (text.equals("Hello, World!")){
|
assertTrue(rt.isBold());
|
||||||
assertEquals(42, rt.getFontSize());
|
assertTrue(rt.isItalic());
|
||||||
assertTrue(rt.isBold());
|
assertFalse(rt.isUnderlined());
|
||||||
assertTrue(rt.isItalic());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user