aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/testcases/org')
-rw-r--r--src/testcases/org/apache/poi/hssf/model/HSSFTestModelHelper.java40
-rw-r--r--src/testcases/org/apache/poi/hssf/model/TestDrawingAggregate.java36
-rw-r--r--src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java20
-rw-r--r--src/testcases/org/apache/poi/hssf/model/TestShapes.java60
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java26
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java40
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestPolygon.java130
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestText.java31
8 files changed, 172 insertions, 211 deletions
diff --git a/src/testcases/org/apache/poi/hssf/model/HSSFTestModelHelper.java b/src/testcases/org/apache/poi/hssf/model/HSSFTestModelHelper.java
deleted file mode 100644
index 10acb70e73..0000000000
--- a/src/testcases/org/apache/poi/hssf/model/HSSFTestModelHelper.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.hssf.model;
-
-import org.apache.poi.hssf.usermodel.HSSFComment;
-import org.apache.poi.hssf.usermodel.HSSFPolygon;
-import org.apache.poi.hssf.usermodel.HSSFTextbox;
-
-/**
- * @author Evgeniy Berlog
- * @date 25.06.12
- */
-public class HSSFTestModelHelper {
- public static TextboxShape createTextboxShape(int shapeId, HSSFTextbox textbox){
- return new TextboxShape(textbox, shapeId);
- }
-
- public static CommentShape createCommentShape(int shapeId, HSSFComment comment){
- return new CommentShape(comment, shapeId);
- }
-
- public static PolygonShape createPolygonShape(int shapeId, HSSFPolygon polygon){
- return new PolygonShape(polygon, shapeId);
- }
-}
diff --git a/src/testcases/org/apache/poi/hssf/model/TestDrawingAggregate.java b/src/testcases/org/apache/poi/hssf/model/TestDrawingAggregate.java
index df03e33fa3..70e7c7db63 100644
--- a/src/testcases/org/apache/poi/hssf/model/TestDrawingAggregate.java
+++ b/src/testcases/org/apache/poi/hssf/model/TestDrawingAggregate.java
@@ -224,8 +224,7 @@ public class TestDrawingAggregate {
"H4sIAAAAAAAAAGWOOw7CQAxE32YTsSRIWSgQJSUloqSm5g4ICURBg+iBK3APGi6wBWeh9xGYbEps2WON"+
"P+OWwpYeIsECMFC8S2jxNvMdlrYQ5xha5N8K6ryHdir6+avwOer5l3hq2NPYWuWN0n1dIsgfbgshuSj1"+
"+2eqbvLdxQ0ndhy5KJ/lc1ZZK9okY5X/gSbrHZTH1vE/ozagTcwAAAA=";
- byte[] base64Bytes = DatatypeConverter.parseBase64Binary(data);
- byte[] dgBytes = IOUtils.toByteArray(new GZIPInputStream(new ByteArrayInputStream(base64Bytes)));
+ byte[] dgBytes = decompress(data);
List<EscherRecord> records = new ArrayList<EscherRecord>();
EscherRecordFactory recordFactory = new DefaultEscherRecordFactory();
@@ -725,8 +724,7 @@ public class TestDrawingAggregate {
"IppKQdVys+cLtUY6Un0+hI2Z0wMzAxO8Lr0LbaILk8WtNsxpaFYMrTjC22723OH5GFkUi+ux8An2Hi0F"+
"fvcr1v8aFU6POn+OCqfj4ffS/e+pcOEMKhABrCdUAAPhwB+pQHYGFcT/BBUEz6LC/wGpc+eRNSkAAA==";
- byte[] base64Bytes = DatatypeConverter.parseBase64Binary(data);
- byte[] dgBytes = IOUtils.toByteArray(new GZIPInputStream(new ByteArrayInputStream(base64Bytes)));
+ byte[] dgBytes = decompress(data);
List<Record> dgRecords = RecordFactory.createRecords(new ByteArrayInputStream(dgBytes));
assertEquals(20, dgRecords.size());
@@ -904,8 +902,7 @@ public class TestDrawingAggregate {
"p9IQmzVDjm0LdSLqeHM8ILiJRsdoNYS93WyEhi7IOdKXZLTCvCLifxTMEi+snNzAtfevk8DpkejvSeB0"+
"BPza/oPKABD5z4SARKQEELP1WQsFMc+QwP8ATkmhK404AAA=";
- byte[] base64Bytes = DatatypeConverter.parseBase64Binary(data);
- byte[] dgBytes = IOUtils.toByteArray(new GZIPInputStream(new ByteArrayInputStream(base64Bytes)));
+ byte[] dgBytes = decompress(data);
List<Record> dgRecords = RecordFactory.createRecords(new ByteArrayInputStream(dgBytes));
assertEquals(14, dgRecords.size());
@@ -950,4 +947,31 @@ public class TestDrawingAggregate {
assertTrue("drawing data brefpore and after save is different", Arrays.equals(dgBytes, dgBytesAfterSave));
}
+
+ /**
+ * Decompress previously gziped/base64ed data
+ *
+ * @param data the gziped/base64ed data
+ * @return the raw bytes
+ * @throws IOException if you copy and pasted the data wrong
+ */
+ public static byte[] decompress(String data) throws IOException {
+ byte[] base64Bytes = DatatypeConverter.parseBase64Binary(data);
+ return IOUtils.toByteArray(new GZIPInputStream(new ByteArrayInputStream(base64Bytes)));
+ }
+
+ /**
+ * Compress raw data for test runs - usually called while debugging :)
+ *
+ * @param data the raw data
+ * @return the gziped/base64ed data as String
+ * @throws IOException usually not ...
+ */
+ public static String compress(byte[] data) throws IOException {
+ java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
+ java.util.zip.GZIPOutputStream gz = new java.util.zip.GZIPOutputStream(bos);
+ gz.write(data);
+ gz.finish();
+ return DatatypeConverter.printBase64Binary(bos.toByteArray());
+ }
}
diff --git a/src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java b/src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java
index b21806a57c..7c81783331 100644
--- a/src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java
+++ b/src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java
@@ -20,6 +20,7 @@ package org.apache.poi.hssf.model;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
@@ -103,23 +104,14 @@ public class TestDrawingShapes {
assertEquals(HSSFShape.LINEWIDTH_DEFAULT, shape.getLineWidth());
assertEquals(HSSFShape.LINESTYLE_SOLID, shape.getLineStyle());
assertFalse(shape.isNoFill());
-
- AbstractShape sp = AbstractShape.createShape(shape, 1);
- EscherContainerRecord spContainer = sp.getSpContainer();
- EscherOptRecord opt =
- spContainer.getChildById(EscherOptRecord.RECORD_ID);
+
+ EscherOptRecord opt = shape.getOptRecord();
assertEquals(7, opt.getEscherProperties().size());
- assertTrue(((EscherBoolProperty) opt.lookup(EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE)).isTrue());
- assertEquals(0x00000004,
- ((EscherSimpleProperty) opt.lookup(EscherProperties.GEOMETRY__SHAPEPATH)).getPropertyValue());
- assertEquals(0x08000009,
- ((EscherSimpleProperty) opt.lookup(EscherProperties.FILL__FILLCOLOR)).getPropertyValue());
- assertTrue(((EscherBoolProperty) opt.lookup(EscherProperties.FILL__NOFILLHITTEST)).isTrue());
- assertEquals(0x08000040,
- ((EscherSimpleProperty) opt.lookup(EscherProperties.LINESTYLE__COLOR)).getPropertyValue());
- assertTrue(((EscherBoolProperty) opt.lookup(EscherProperties.LINESTYLE__NOLINEDRAWDASH)).isTrue());
assertTrue(((EscherBoolProperty) opt.lookup(EscherProperties.GROUPSHAPE__PRINT)).isTrue());
+ assertTrue(((EscherBoolProperty) opt.lookup(EscherProperties.LINESTYLE__NOLINEDRAWDASH)).isTrue());
+ assertEquals(0x00000004, ((EscherSimpleProperty) opt.lookup(EscherProperties.GEOMETRY__SHAPEPATH)).getPropertyValue());
+ assertNull(opt.lookup(EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE));
}
@Test
diff --git a/src/testcases/org/apache/poi/hssf/model/TestShapes.java b/src/testcases/org/apache/poi/hssf/model/TestShapes.java
deleted file mode 100644
index beed4a1d38..0000000000
--- a/src/testcases/org/apache/poi/hssf/model/TestShapes.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ====================================================================
- */
-
-package org.apache.poi.hssf.model;
-
-import junit.framework.TestCase;
-
-import org.apache.poi.hssf.record.CommonObjectDataSubRecord;
-import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
-import org.apache.poi.hssf.usermodel.HSSFComment;
-import org.apache.poi.hssf.usermodel.HSSFPicture;
-import org.apache.poi.hssf.usermodel.HSSFTextbox;
-
-/**
- *
- * @author Yegor Kozlov
- */
-public final class TestShapes extends TestCase {
-
- /**
- * Test generator of ids for the CommonObjectDataSubRecord record.
- *
- * See Bug 51332
- */
- @SuppressWarnings("deprecation")
- public void testShapeId(){
-
- HSSFClientAnchor anchor = new HSSFClientAnchor();
- AbstractShape shape;
- CommonObjectDataSubRecord cmo;
-
- shape = new TextboxShape(new HSSFTextbox(null, anchor), 1025);
- cmo = (CommonObjectDataSubRecord)shape.getObjRecord().getSubRecords().get(0);
- assertEquals(1, cmo.getObjectId());
-
- shape = new PictureShape(new HSSFPicture(null, anchor), 1026);
- cmo = (CommonObjectDataSubRecord)shape.getObjRecord().getSubRecords().get(0);
- assertEquals(2, cmo.getObjectId());
-
- shape = new CommentShape(new HSSFComment(null, anchor), 1027);
- cmo = (CommonObjectDataSubRecord)shape.getObjRecord().getSubRecords().get(0);
- assertEquals(1027, cmo.getObjectId());
- }
-}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
index 7ccae676bd..a65721151b 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
@@ -51,6 +51,7 @@ import org.apache.poi.hssf.extractor.ExcelExtractor;
import org.apache.poi.hssf.model.InternalSheet;
import org.apache.poi.hssf.model.InternalWorkbook;
import org.apache.poi.hssf.record.CellValueRecordInterface;
+import org.apache.poi.hssf.record.CommonObjectDataSubRecord;
import org.apache.poi.hssf.record.EmbeddedObjectRefSubRecord;
import org.apache.poi.hssf.record.NameRecord;
import org.apache.poi.hssf.record.Record;
@@ -3009,4 +3010,29 @@ public final class TestBugs extends BaseTestBugzillaIssues {
assertNotNull(newSheet);
wb.close();
}
+
+ /**
+ * Test generator of ids for the CommonObjectDataSubRecord record.
+ */
+ @Test
+ public void test51332() {
+ HSSFClientAnchor anchor = new HSSFClientAnchor();
+ HSSFSimpleShape shape;
+ CommonObjectDataSubRecord cmo;
+
+ shape = new HSSFTextbox(null, anchor);
+ shape.setShapeId(1025);
+ cmo = (CommonObjectDataSubRecord)shape.getObjRecord().getSubRecords().get(0);
+ assertEquals(1, cmo.getObjectId());
+
+ shape = new HSSFPicture(null, anchor);
+ shape.setShapeId(1026);
+ cmo = (CommonObjectDataSubRecord)shape.getObjRecord().getSubRecords().get(0);
+ assertEquals(2, cmo.getObjectId());
+
+ shape = new HSSFComment(null, anchor);
+ shape.setShapeId(1027);
+ cmo = (CommonObjectDataSubRecord)shape.getObjRecord().getSubRecords().get(0);
+ assertEquals(1027, cmo.getObjectId());
+ }
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java
index ac65070340..9e40695b4b 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java
@@ -16,6 +16,7 @@
==================================================================== */
package org.apache.poi.hssf.usermodel;
+import static org.apache.poi.hssf.model.TestDrawingAggregate.decompress;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -26,8 +27,6 @@ import java.io.IOException;
import org.apache.poi.ddf.EscherSpRecord;
import org.apache.poi.hssf.HSSFITestDataProvider;
import org.apache.poi.hssf.HSSFTestDataSamples;
-import org.apache.poi.hssf.model.CommentShape;
-import org.apache.poi.hssf.model.HSSFTestModelHelper;
import org.apache.poi.hssf.record.CommonObjectDataSubRecord;
import org.apache.poi.hssf.record.EscherAggregate;
import org.apache.poi.hssf.record.NoteRecord;
@@ -66,7 +65,7 @@ public final class TestHSSFComment extends BaseTestCellComment {
* when matching cells and their cell comments. The correct algorithm is to map
*/
@Test
- public void bug47924() {
+ public void bug47924() throws IOException {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("47924.xls");
HSSFSheet sheet = wb.getSheetAt(0);
HSSFCell cell;
@@ -95,6 +94,8 @@ public final class TestHSSFComment extends BaseTestCellComment {
cell = sheet.getRow(5).getCell(2);
comment = cell.getCellComment();
assertEquals("c6", comment.getString().getString());
+
+ wb.close();
}
@Test
@@ -202,7 +203,7 @@ public final class TestHSSFComment extends BaseTestCellComment {
}
@Test
- public void resultEqualsToAbstractShape() throws IOException {
+ public void resultEqualsToNonExistingAbstractShape() throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sh = wb.createSheet();
HSSFPatriarch patriarch = sh.createDrawingPatriarch();
@@ -212,59 +213,53 @@ public final class TestHSSFComment extends BaseTestCellComment {
HSSFCell cell = row.createCell(0);
cell.setCellComment(comment);
- CommentShape commentShape = HSSFTestModelHelper.createCommentShape(1025, comment);
-
assertEquals(comment.getEscherContainer().getChildRecords().size(), 5);
- assertEquals(commentShape.getSpContainer().getChildRecords().size(), 5);
//sp record
- byte[] expected = commentShape.getSpContainer().getChild(0).serialize();
+ byte[] expected = decompress("H4sIAAAAAAAAAFvEw/WBg4GBgZEFSHAxMAAA9gX7nhAAAAA=");
byte[] actual = comment.getEscherContainer().getChild(0).serialize();
assertEquals(expected.length, actual.length);
assertArrayEquals(expected, actual);
- expected = commentShape.getSpContainer().getChild(2).serialize();
+ expected = decompress("H4sIAAAAAAAAAGNgEPggxIANAABK4+laGgAAAA==");
actual = comment.getEscherContainer().getChild(2).serialize();
assertEquals(expected.length, actual.length);
assertArrayEquals(expected, actual);
- expected = commentShape.getSpContainer().getChild(3).serialize();
+ expected = decompress("H4sIAAAAAAAAAGNgEPzAAAQACl6c5QgAAAA=");
actual = comment.getEscherContainer().getChild(3).serialize();
assertEquals(expected.length, actual.length);
assertArrayEquals(expected, actual);
- expected = commentShape.getSpContainer().getChild(4).serialize();
+ expected = decompress("H4sIAAAAAAAAAGNg4P3AAAQA6pyIkQgAAAA=");
actual = comment.getEscherContainer().getChild(4).serialize();
assertEquals(expected.length, actual.length);
assertArrayEquals(expected, actual);
ObjRecord obj = comment.getObjRecord();
- ObjRecord objShape = commentShape.getObjRecord();
- expected = obj.serialize();
- actual = objShape.serialize();
+ expected = decompress("H4sIAAAAAAAAAItlMGEQZRBikGRgZBF0YEACvAxiDLgBAJZsuoU4AAAA");
+ actual = obj.serialize();
assertEquals(expected.length, actual.length);
//assertArrayEquals(expected, actual);
TextObjectRecord tor = comment.getTextObjectRecord();
- TextObjectRecord torShape = commentShape.getTextObjectRecord();
- expected = tor.serialize();
- actual = torShape.serialize();
+ expected = decompress("H4sIAAAAAAAAANvGKMQgxMSABgBGi8T+FgAAAA==");
+ actual = tor.serialize();
assertEquals(expected.length, actual.length);
assertArrayEquals(expected, actual);
NoteRecord note = comment.getNoteRecord();
- NoteRecord noteShape = commentShape.getNoteRecord();
- expected = note.serialize();
- actual = noteShape.serialize();
+ expected = decompress("H4sIAAAAAAAAAJNh4GGAAEYWEAkAS0KXuRAAAAA=");
+ actual = note.serialize();
assertEquals(expected.length, actual.length);
assertArrayEquals(expected, actual);
@@ -376,7 +371,7 @@ public final class TestHSSFComment extends BaseTestCellComment {
}
@Test
- public void existingFileWithComment(){
+ public void existingFileWithComment() throws IOException {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("drawings.xls");
HSSFSheet sheet = wb.getSheet("comments");
HSSFPatriarch drawing = sheet.getDrawingPatriarch();
@@ -386,6 +381,7 @@ public final class TestHSSFComment extends BaseTestCellComment {
assertEquals(comment.getString().getString(), "evgeniy:\npoi test");
assertEquals(comment.getColumn(), 1);
assertEquals(comment.getRow(), 2);
+ wb.close();
}
@Test
@@ -399,8 +395,6 @@ public final class TestHSSFComment extends BaseTestCellComment {
HSSFCell cell = row.createCell(4);
cell.setCellComment(comment);
- HSSFTestModelHelper.createCommentShape(0, comment);
-
assertNotNull(sh.findCellComment(5, 4));
assertNull(sh.findCellComment(5, 5));
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestPolygon.java b/src/testcases/org/apache/poi/hssf/usermodel/TestPolygon.java
index bcaf477493..6174a5ff30 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestPolygon.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestPolygon.java
@@ -17,27 +17,22 @@
package org.apache.poi.hssf.usermodel;
+import static org.apache.poi.hssf.model.TestDrawingAggregate.decompress;
import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import java.io.IOException;
-import junit.framework.TestCase;
-
import org.apache.poi.ddf.EscherArrayProperty;
-import org.apache.poi.ddf.EscherOptRecord;
import org.apache.poi.ddf.EscherProperties;
import org.apache.poi.ddf.EscherSpRecord;
import org.apache.poi.hssf.HSSFTestDataSamples;
-import org.apache.poi.hssf.model.HSSFTestModelHelper;
-import org.apache.poi.hssf.model.PolygonShape;
import org.apache.poi.hssf.record.ObjRecord;
+import org.junit.Test;
-/**
- * @author Evgeniy Berlog
- * @date 28.06.12
- */
-public class TestPolygon extends TestCase{
-
+public class TestPolygon {
+ @Test
public void testResultEqualsToAbstractShape() throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sh = wb.createSheet();
@@ -46,42 +41,42 @@ public class TestPolygon extends TestCase{
HSSFPolygon polygon = patriarch.createPolygon(new HSSFClientAnchor());
polygon.setPolygonDrawArea( 100, 100 );
polygon.setPoints( new int[]{0, 90, 50}, new int[]{5, 5, 44} );
- PolygonShape polygonShape = HSSFTestModelHelper.createPolygonShape(1024, polygon);
polygon.setShapeId(1024);
assertEquals(polygon.getEscherContainer().getChildRecords().size(), 4);
- assertEquals(polygonShape.getSpContainer().getChildRecords().size(), 4);
//sp record
- byte[] expected = polygonShape.getSpContainer().getChild(0).serialize();
+ byte[] expected = decompress("H4sIAAAAAAAAAGNi4PrAwQAELEDMxcAAAAU6ZlwQAAAA");
byte[] actual = polygon.getEscherContainer().getChild(0).serialize();
assertEquals(expected.length, actual.length);
assertArrayEquals(expected, actual);
- expected = polygonShape.getSpContainer().getChild(2).serialize();
+ expected = decompress("H4sIAAAAAAAAAGNgEPggxIANAABK4+laGgAAAA==");
actual = polygon.getEscherContainer().getChild(2).serialize();
assertEquals(expected.length, actual.length);
assertArrayEquals(expected, actual);
- expected = polygonShape.getSpContainer().getChild(3).serialize();
+ expected = decompress("H4sIAAAAAAAAAGNgEPzAAAQACl6c5QgAAAA=");
actual = polygon.getEscherContainer().getChild(3).serialize();
assertEquals(expected.length, actual.length);
assertArrayEquals(expected, actual);
ObjRecord obj = polygon.getObjRecord();
- ObjRecord objShape = polygonShape.getObjRecord();
- expected = obj.serialize();
- actual = objShape.serialize();
+ expected = decompress("H4sIAAAAAAAAAItlkGIQZRBikGNgYBBMYEADAOAV/ZkeAAAA");
+ actual = obj.serialize();
assertEquals(expected.length, actual.length);
assertArrayEquals(expected, actual);
+
+ wb.close();
}
- public void testPolygonPoints(){
+ @Test
+ public void testPolygonPoints() throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sh = wb.createSheet();
HSSFPatriarch patriarch = sh.createDrawingPatriarch();
@@ -90,31 +85,46 @@ public class TestPolygon extends TestCase{
polygon.setPolygonDrawArea( 100, 100 );
polygon.setPoints( new int[]{0, 90, 50, 90}, new int[]{5, 5, 44, 88} );
- PolygonShape polygonShape = HSSFTestModelHelper.createPolygonShape(0, polygon);
-
EscherArrayProperty verticesProp1 = polygon.getOptRecord().lookup(EscherProperties.GEOMETRY__VERTICES);
- EscherArrayProperty verticesProp2 = ((EscherOptRecord)polygonShape.getSpContainer().getChildById(EscherOptRecord.RECORD_ID))
- .lookup(EscherProperties.GEOMETRY__VERTICES);
- assertEquals(verticesProp1.getNumberOfElementsInArray(), verticesProp2.getNumberOfElementsInArray());
- assertEquals(verticesProp1.toXml(""), verticesProp2.toXml(""));
+ String expected =
+ "<EscherArrayProperty id=\"0x8145\" name=\"geometry.vertices\" blipId=\"false\">"+
+ "<Element>[00, 00, 05, 00]</Element>"+
+ "<Element>[5A, 00, 05, 00]</Element>"+
+ "<Element>[32, 00, 2C, 00]</Element>"+
+ "<Element>[5A, 00, 58, 00]</Element>"+
+ "<Element>[00, 00, 05, 00]</Element>"+
+ "</EscherArrayProperty>";
+ String actual = verticesProp1.toXml("").replaceAll("[\r\n\t]","");
+
+ assertEquals(verticesProp1.getNumberOfElementsInArray(), 5);
+ assertEquals(expected, actual);
polygon.setPoints(new int[]{1,2,3}, new int[] {4,5,6});
assertArrayEquals(polygon.getXPoints(), new int[]{1, 2, 3});
assertArrayEquals(polygon.getYPoints(), new int[]{4, 5, 6});
- polygonShape = HSSFTestModelHelper.createPolygonShape(0, polygon);
verticesProp1 = polygon.getOptRecord().lookup(EscherProperties.GEOMETRY__VERTICES);
- verticesProp2 = ((EscherOptRecord)polygonShape.getSpContainer().getChildById(EscherOptRecord.RECORD_ID))
- .lookup(EscherProperties.GEOMETRY__VERTICES);
- assertEquals(verticesProp1.getNumberOfElementsInArray(), verticesProp2.getNumberOfElementsInArray());
- assertEquals(verticesProp1.toXml(""), verticesProp2.toXml(""));
+ expected =
+ "<EscherArrayProperty id=\"0x8145\" name=\"geometry.vertices\" blipId=\"false\">" +
+ "<Element>[01, 00, 04, 00]</Element>" +
+ "<Element>[02, 00, 05, 00]</Element>" +
+ "<Element>[03, 00, 06, 00]</Element>" +
+ "<Element>[01, 00, 04, 00]</Element>" +
+ "</EscherArrayProperty>";
+ actual = verticesProp1.toXml("").replaceAll("[\r\n\t]","");
+
+ assertEquals(verticesProp1.getNumberOfElementsInArray(), 4);
+ assertEquals(expected, actual);
+
+ wb.close();
}
- public void testSetGetProperties(){
- HSSFWorkbook wb = new HSSFWorkbook();
- HSSFSheet sh = wb.createSheet();
+ @Test
+ public void testSetGetProperties() throws IOException {
+ HSSFWorkbook wb1 = new HSSFWorkbook();
+ HSSFSheet sh = wb1.createSheet();
HSSFPatriarch patriarch = sh.createDrawingPatriarch();
HSSFPolygon polygon = patriarch.createPolygon(new HSSFClientAnchor());
@@ -126,8 +136,9 @@ public class TestPolygon extends TestCase{
assertEquals(polygon.getDrawAreaHeight(), 101);
assertEquals(polygon.getDrawAreaWidth(), 102);
- wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
- sh = wb.getSheetAt(0);
+ HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
+ wb1.close();
+ sh = wb2.getSheetAt(0);
patriarch = sh.getDrawingPatriarch();
polygon = (HSSFPolygon) patriarch.getChildren().get(0);
@@ -144,8 +155,9 @@ public class TestPolygon extends TestCase{
assertEquals(polygon.getDrawAreaHeight(), 1011);
assertEquals(polygon.getDrawAreaWidth(), 1021);
- wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
- sh = wb.getSheetAt(0);
+ HSSFWorkbook wb3 = HSSFTestDataSamples.writeOutAndReadBack(wb2);
+ wb2.close();
+ sh = wb3.getSheetAt(0);
patriarch = sh.getDrawingPatriarch();
polygon = (HSSFPolygon) patriarch.getChildren().get(0);
@@ -154,11 +166,14 @@ public class TestPolygon extends TestCase{
assertArrayEquals(polygon.getYPoints(), new int[]{41, 51, 61});
assertEquals(polygon.getDrawAreaHeight(), 1011);
assertEquals(polygon.getDrawAreaWidth(), 1021);
+
+ wb3.close();
}
- public void testAddToExistingFile(){
- HSSFWorkbook wb = new HSSFWorkbook();
- HSSFSheet sh = wb.createSheet();
+ @Test
+ public void testAddToExistingFile() throws IOException {
+ HSSFWorkbook wb1 = new HSSFWorkbook();
+ HSSFSheet sh = wb1.createSheet();
HSSFPatriarch patriarch = sh.createDrawingPatriarch();
HSSFPolygon polygon = patriarch.createPolygon(new HSSFClientAnchor());
@@ -169,8 +184,9 @@ public class TestPolygon extends TestCase{
polygon1.setPolygonDrawArea( 103, 104 );
polygon1.setPoints( new int[]{11,12,13}, new int[]{14,15,16} );
- wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
- sh = wb.getSheetAt(0);
+ HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
+ wb1.close();
+ sh = wb2.getSheetAt(0);
patriarch = sh.getDrawingPatriarch();
assertEquals(patriarch.getChildren().size(), 2);
@@ -179,8 +195,9 @@ public class TestPolygon extends TestCase{
polygon2.setPolygonDrawArea( 203, 204 );
polygon2.setPoints( new int[]{21,22,23}, new int[]{24,25,26} );
- wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
- sh = wb.getSheetAt(0);
+ HSSFWorkbook wb3 = HSSFTestDataSamples.writeOutAndReadBack(wb2);
+ wb2.close();
+ sh = wb3.getSheetAt(0);
patriarch = sh.getDrawingPatriarch();
assertEquals(patriarch.getChildren().size(), 3);
@@ -203,8 +220,11 @@ public class TestPolygon extends TestCase{
assertArrayEquals(polygon2.getYPoints(), new int[]{24,25,26});
assertEquals(polygon2.getDrawAreaHeight(), 204);
assertEquals(polygon2.getDrawAreaWidth(), 203);
+
+ wb3.close();
}
+ @Test
public void testExistingFile() throws IOException {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("drawings.xls");
HSSFSheet sheet = wb.getSheet("polygon");
@@ -216,19 +236,23 @@ public class TestPolygon extends TestCase{
assertEquals(polygon.getDrawAreaWidth(), 3686175);
assertArrayEquals(polygon.getXPoints(), new int[]{0, 0, 31479, 16159, 19676, 20502});
assertArrayEquals(polygon.getYPoints(), new int[]{0, 0, 36, 56, 34, 18});
+
+ wb.close();
}
- public void testPolygonType(){
- HSSFWorkbook wb = new HSSFWorkbook();
- HSSFSheet sh = wb.createSheet();
+ @Test
+ public void testPolygonType() throws IOException {
+ HSSFWorkbook wb1 = new HSSFWorkbook();
+ HSSFSheet sh = wb1.createSheet();
HSSFPatriarch patriarch = sh.createDrawingPatriarch();
HSSFPolygon polygon = patriarch.createPolygon(new HSSFClientAnchor());
polygon.setPolygonDrawArea( 102, 101 );
polygon.setPoints( new int[]{1,2,3}, new int[]{4,5,6} );
- wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
- sh = wb.getSheetAt(0);
+ HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
+ wb1.close();
+ sh = wb2.getSheetAt(0);
patriarch = sh.getDrawingPatriarch();
HSSFPolygon polygon1 = patriarch.createPolygon(new HSSFClientAnchor());
@@ -239,12 +263,14 @@ public class TestPolygon extends TestCase{
spRecord.setShapeType((short)77/**RANDOM**/);
- wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
- sh = wb.getSheetAt(0);
+ HSSFWorkbook wb3 = HSSFTestDataSamples.writeOutAndReadBack(wb2);
+ wb2.close();
+ sh = wb3.getSheetAt(0);
patriarch = sh.getDrawingPatriarch();
assertEquals(patriarch.getChildren().size(), 2);
assertTrue(patriarch.getChildren().get(0) instanceof HSSFPolygon);
assertTrue(patriarch.getChildren().get(1) instanceof HSSFPolygon);
+ wb3.close();
}
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestText.java b/src/testcases/org/apache/poi/hssf/usermodel/TestText.java
index 51eede08f0..c8203d8d49 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestText.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestText.java
@@ -17,12 +17,13 @@
package org.apache.poi.hssf.usermodel;
+import static org.apache.poi.hssf.model.TestDrawingAggregate.decompress;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
+import java.io.IOException;
+
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.ObjRecord;
import org.apache.poi.hssf.record.TextObjectRecord;
import org.junit.Test;
@@ -31,56 +32,54 @@ import org.junit.Test;
* @author Evgeniy Berlog
* @date 25.06.12
*/
-@SuppressWarnings("deprecation")
public class TestText {
@Test
- public void testResultEqualsToAbstractShape() throws Exception {
+ public void testResultEqualsToNonExistingAbstractShape() throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sh = wb.createSheet();
HSSFPatriarch patriarch = sh.createDrawingPatriarch();
HSSFTextbox textbox = patriarch.createTextbox(new HSSFClientAnchor());
- TextboxShape textboxShape = HSSFTestModelHelper.createTextboxShape(1025, textbox);
assertEquals(textbox.getEscherContainer().getChildRecords().size(), 5);
- assertEquals(textboxShape.getSpContainer().getChildRecords().size(), 5);
//sp record
- byte[] expected = textboxShape.getSpContainer().getChild(0).serialize();
+ byte[] expected = decompress("H4sIAAAAAAAAAFvEw/WBg4GBgZEFSHAxMAAA9gX7nhAAAAA=");
byte[] actual = textbox.getEscherContainer().getChild(0).serialize();
assertEquals(expected.length, actual.length);
assertArrayEquals(expected, actual);
- expected = textboxShape.getSpContainer().getChild(2).serialize();
+ expected = decompress("H4sIAAAAAAAAAGNgEPggxIANAABK4+laGgAAAA==");
actual = textbox.getEscherContainer().getChild(2).serialize();
assertEquals(expected.length, actual.length);
assertArrayEquals(expected, actual);
- expected = textboxShape.getSpContainer().getChild(3).serialize();
+ expected = decompress("H4sIAAAAAAAAAGNgEPzAAAQACl6c5QgAAAA=");
actual = textbox.getEscherContainer().getChild(3).serialize();
assertEquals(expected.length, actual.length);
assertArrayEquals(expected, actual);
- expected = textboxShape.getSpContainer().getChild(4).serialize();
+ expected = decompress("H4sIAAAAAAAAAGNg4P3AAAQA6pyIkQgAAAA=");
actual = textbox.getEscherContainer().getChild(4).serialize();
assertEquals(expected.length, actual.length);
assertArrayEquals(expected, actual);
ObjRecord obj = textbox.getObjRecord();
- ObjRecord objShape = textboxShape.getObjRecord();
- expected = obj.serialize();
- actual = objShape.serialize();
+ expected = decompress("H4sIAAAAAAAAAItlkGIQZRBiYGNgZBBMYEADAOdCLuweAAAA");
+ actual = obj.serialize();
+ assertEquals(expected.length, actual.length);
+ assertArrayEquals(expected, actual);
+
TextObjectRecord tor = textbox.getTextObjectRecord();
- TextObjectRecord torShape = textboxShape.getTextObjectRecord();
- expected = tor.serialize();
- actual = torShape.serialize();
+ expected = decompress("H4sIAAAAAAAAANvGKMQgxMSABgBGi8T+FgAAAA==");
+ actual = tor.serialize();
assertEquals(expected.length, actual.length);
assertArrayEquals(expected, actual);