diff options
author | Evgeniy Berlog <berlog@apache.org> | 2012-06-26 11:21:13 +0000 |
---|---|---|
committer | Evgeniy Berlog <berlog@apache.org> | 2012-06-26 11:21:13 +0000 |
commit | b57fa5b4d0621d11b3f324387cebad89cd046eb8 (patch) | |
tree | 524b19e1706364f051f084db7c0158847b39eeec /src/testcases/org/apache/poi/hssf/usermodel/TestText.java | |
parent | 7efc80c3e8945546bb7fa4fa019e9f6449e5b55b (diff) | |
download | poi-b57fa5b4d0621d11b3f324387cebad89cd046eb8.tar.gz poi-b57fa5b4d0621d11b3f324387cebad89cd046eb8.zip |
implemented creating shapes in existing files
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/gsoc2012@1353960 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/hssf/usermodel/TestText.java')
-rw-r--r-- | src/testcases/org/apache/poi/hssf/usermodel/TestText.java | 186 |
1 files changed, 186 insertions, 0 deletions
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestText.java b/src/testcases/org/apache/poi/hssf/usermodel/TestText.java new file mode 100644 index 0000000000..213c5be674 --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestText.java @@ -0,0 +1,186 @@ +package org.apache.poi.hssf.usermodel;
+
+import junit.framework.TestCase;
+import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.hssf.model.HSSFTestModelHelper;
+import org.apache.poi.hssf.model.TextboxShape;
+import org.apache.poi.hssf.record.CommonObjectDataSubRecord;
+import org.apache.poi.hssf.record.ObjRecord;
+import org.apache.poi.hssf.record.TextObjectRecord;
+
+import java.util.Arrays;
+
+/**
+ * @author Evgeniy Berlog
+ * @date 25.06.12
+ */
+public class TestText extends TestCase {
+
+ public void testResultEqualsToAbstractShape() {
+ HSSFWorkbook wb = new HSSFWorkbook();
+ HSSFSheet sh = wb.createSheet();
+ HSSFPatriarch patriarch = sh.createDrawingPatriarch();
+ HSSFTextbox textbox = patriarch.createTextbox(new HSSFClientAnchor());
+ TextboxShape textboxShape = HSSFTestModelHelper.createTextboxShape(0, textbox);
+
+ assertEquals(textbox.getEscherContainer().getChildRecords().size(), 5);
+ assertEquals(textboxShape.getSpContainer().getChildRecords().size(), 5);
+
+ //sp record
+ byte[] expected = textboxShape.getSpContainer().getChild(0).serialize();
+ byte[] actual = textbox.getEscherContainer().getChild(0).serialize();
+
+ assertEquals(expected.length, actual.length);
+ assertTrue(Arrays.equals(expected, actual));
+
+ expected = textboxShape.getSpContainer().getChild(2).serialize();
+ actual = textbox.getEscherContainer().getChild(2).serialize();
+
+ assertEquals(expected.length, actual.length);
+ assertTrue(Arrays.equals(expected, actual));
+
+ expected = textboxShape.getSpContainer().getChild(3).serialize();
+ actual = textbox.getEscherContainer().getChild(3).serialize();
+
+ assertEquals(expected.length, actual.length);
+ assertTrue(Arrays.equals(expected, actual));
+
+ expected = textboxShape.getSpContainer().getChild(4).serialize();
+ actual = textbox.getEscherContainer().getChild(4).serialize();
+
+ assertEquals(expected.length, actual.length);
+ assertTrue(Arrays.equals(expected, actual));
+
+ ObjRecord obj = textbox.getObjRecord();
+ ((CommonObjectDataSubRecord) obj.getSubRecords().get(0)).setObjectId(-1024);
+ ObjRecord objShape = textboxShape.getObjRecord();
+
+ expected = obj.serialize();
+ actual = objShape.serialize();
+
+ assertEquals(expected.length, actual.length);
+ assertTrue(Arrays.equals(expected, actual));
+
+ TextObjectRecord tor = textbox.getTextObjectRecord();
+ TextObjectRecord torShape = textboxShape.getTextObjectRecord();
+
+ expected = tor.serialize();
+ actual = torShape.serialize();
+
+ assertEquals(expected.length, actual.length);
+ assertTrue(Arrays.equals(expected, actual));
+ }
+
+ public void testAddTextToExistingFile() {
+ HSSFWorkbook wb = new HSSFWorkbook();
+ HSSFSheet sh = wb.createSheet();
+ HSSFPatriarch patriarch = sh.createDrawingPatriarch();
+ HSSFTextbox textbox = patriarch.createTextbox(new HSSFClientAnchor());
+ textbox.setString(new HSSFRichTextString("just for test"));
+ HSSFTextbox textbox2 = patriarch.createTextbox(new HSSFClientAnchor());
+ textbox2.setString(new HSSFRichTextString("just for test2"));
+
+ assertEquals(patriarch.getChildren().size(), 2);
+
+ wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
+ sh = wb.getSheetAt(0);
+ patriarch = sh.getDrawingPatriarch();
+
+ assertEquals(patriarch.getChildren().size(), 2);
+ HSSFTextbox text3 = patriarch.createTextbox(new HSSFClientAnchor());
+ text3.setString(new HSSFRichTextString("text3"));
+ assertEquals(patriarch.getChildren().size(), 3);
+
+ wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
+ sh = wb.getSheetAt(0);
+ patriarch = sh.getDrawingPatriarch();
+
+ assertEquals(patriarch.getChildren().size(), 3);
+ assertEquals(((HSSFTextbox) patriarch.getChildren().get(0)).getString().getString(), "just for test");
+ assertEquals(((HSSFTextbox) patriarch.getChildren().get(1)).getString().getString(), "just for test2");
+ assertEquals(((HSSFTextbox) patriarch.getChildren().get(2)).getString().getString(), "text3");
+ }
+
+ public void testSetGetProperties() {
+ HSSFWorkbook wb = new HSSFWorkbook();
+ HSSFSheet sh = wb.createSheet();
+ HSSFPatriarch patriarch = sh.createDrawingPatriarch();
+ HSSFTextbox textbox = patriarch.createTextbox(new HSSFClientAnchor());
+ textbox.setString(new HSSFRichTextString("test"));
+ assertEquals(textbox.getString().getString(), "test");
+
+ textbox.setHorizontalAlignment((short) 5);
+ assertEquals(textbox.getHorizontalAlignment(), 5);
+
+ textbox.setVerticalAlignment((short) 6);
+ assertEquals(textbox.getVerticalAlignment(), (short) 6);
+
+ textbox.setMarginBottom(7);
+ assertEquals(textbox.getMarginBottom(), 7);
+
+ textbox.setMarginLeft(8);
+ assertEquals(textbox.getMarginLeft(), 8);
+
+ textbox.setMarginRight(9);
+ assertEquals(textbox.getMarginRight(), 9);
+
+ textbox.setMarginTop(10);
+ assertEquals(textbox.getMarginTop(), 10);
+
+ wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
+ sh = wb.getSheetAt(0);
+ patriarch = sh.getDrawingPatriarch();
+ textbox = (HSSFTextbox) patriarch.getChildren().get(0);
+ assertEquals(textbox.getString().getString(), "test");
+ assertEquals(textbox.getHorizontalAlignment(), 5);
+ assertEquals(textbox.getVerticalAlignment(), (short) 6);
+ assertEquals(textbox.getMarginBottom(), 7);
+ assertEquals(textbox.getMarginLeft(), 8);
+ assertEquals(textbox.getMarginRight(), 9);
+ assertEquals(textbox.getMarginTop(), 10);
+
+ textbox.setString(new HSSFRichTextString("test1"));
+ textbox.setHorizontalAlignment(HSSFTextbox.HORIZONTAL_ALIGNMENT_CENTERED);
+ textbox.setVerticalAlignment(HSSFTextbox.VERTICAL_ALIGNMENT_TOP);
+ textbox.setMarginBottom(71);
+ textbox.setMarginLeft(81);
+ textbox.setMarginRight(91);
+ textbox.setMarginTop(101);
+
+ assertEquals(textbox.getString().getString(), "test1");
+ assertEquals(textbox.getHorizontalAlignment(), HSSFTextbox.HORIZONTAL_ALIGNMENT_CENTERED);
+ assertEquals(textbox.getVerticalAlignment(), HSSFTextbox.VERTICAL_ALIGNMENT_TOP);
+ assertEquals(textbox.getMarginBottom(), 71);
+ assertEquals(textbox.getMarginLeft(), 81);
+ assertEquals(textbox.getMarginRight(), 91);
+ assertEquals(textbox.getMarginTop(), 101);
+
+ wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
+ sh = wb.getSheetAt(0);
+ patriarch = sh.getDrawingPatriarch();
+ textbox = (HSSFTextbox) patriarch.getChildren().get(0);
+
+ assertEquals(textbox.getString().getString(), "test1");
+ assertEquals(textbox.getHorizontalAlignment(), HSSFTextbox.HORIZONTAL_ALIGNMENT_CENTERED);
+ assertEquals(textbox.getVerticalAlignment(), HSSFTextbox.VERTICAL_ALIGNMENT_TOP);
+ assertEquals(textbox.getMarginBottom(), 71);
+ assertEquals(textbox.getMarginLeft(), 81);
+ assertEquals(textbox.getMarginRight(), 91);
+ assertEquals(textbox.getMarginTop(), 101);
+ }
+
+ public void testExistingFileWithText(){
+ HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("drawings.xls");
+ HSSFSheet sheet = wb.getSheet("text");
+ HSSFPatriarch drawing = sheet.getDrawingPatriarch();
+ assertEquals(1, drawing.getChildren().size());
+ HSSFTextbox textbox = (HSSFTextbox) drawing.getChildren().get(0);
+ assertEquals(textbox.getHorizontalAlignment(), HSSFTextbox.HORIZONTAL_ALIGNMENT_LEFT);
+ assertEquals(textbox.getVerticalAlignment(), HSSFTextbox.VERTICAL_ALIGNMENT_TOP);
+ assertEquals(textbox.getMarginTop(), 0);
+ assertEquals(textbox.getMarginBottom(), 3600000);
+ assertEquals(textbox.getMarginLeft(), 3600000);
+ assertEquals(textbox.getMarginRight(), 0);
+ assertEquals(textbox.getString().getString(), "teeeeesssstttt");
+ }
+}
|