aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache/poi/hssf
diff options
context:
space:
mode:
authorEvgeniy Berlog <berlog@apache.org>2012-07-11 12:08:38 +0000
committerEvgeniy Berlog <berlog@apache.org>2012-07-11 12:08:38 +0000
commit8b027ef5cdef15ace8ba6585458a32209d9e6928 (patch)
treefe101f8beeb33413592b7557bce20fcfa7a01c0e /src/testcases/org/apache/poi/hssf
parent06df547a594c30a10d9d25eb82fcd107c2f42ae4 (diff)
downloadpoi-8b027ef5cdef15ace8ba6585458a32209d9e6928.tar.gz
poi-8b027ef5cdef15ace8ba6585458a32209d9e6928.zip
checked all examples, added several features
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/gsoc2012@1360132 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/hssf')
-rw-r--r--src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java15
-rw-r--r--src/testcases/org/apache/poi/hssf/model/TestHSSFAnchor.java34
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java2
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestComment.java3
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java61
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestPolygon.java4
6 files changed, 110 insertions, 9 deletions
diff --git a/src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java b/src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java
index e50aa47adf..06564e94c4 100644
--- a/src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java
+++ b/src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java
@@ -47,7 +47,8 @@ public class TestDrawingShapes extends TestCase {
}
public void testHSSFShapeCompatibility() {
- HSSFShape shape = new HSSFSimpleShape(null, new HSSFClientAnchor());
+ HSSFSimpleShape shape = new HSSFSimpleShape(null, new HSSFClientAnchor());
+ shape.setShapeType(HSSFSimpleShape.OBJECT_TYPE_LINE);
assertEquals(0x08000040, shape.getLineStyleColor());
assertEquals(0x08000009, shape.getFillColor());
assertEquals(HSSFShape.LINEWIDTH_DEFAULT, shape.getLineWidth());
@@ -80,7 +81,7 @@ public class TestDrawingShapes extends TestCase {
HSSFPicture picture = new HSSFPicture(null, new HSSFClientAnchor());
assertEquals(picture.getLineWidth(), HSSFShape.LINEWIDTH_DEFAULT);
assertEquals(picture.getFillColor(), HSSFShape.FILL__FILLCOLOR_DEFAULT);
- assertEquals(picture.getLineStyle(), HSSFShape.LINESTYLE_SOLID);
+ assertEquals(picture.getLineStyle(), HSSFShape.LINESTYLE_NONE);
assertEquals(picture.getLineStyleColor(), HSSFShape.LINESTYLE__COLOR_DEFAULT);
assertEquals(picture.isNoFill(), false);
assertEquals(picture.getPictureIndex(), -1);//not set yet
@@ -131,8 +132,10 @@ public class TestDrawingShapes extends TestCase {
assertEquals(10, rectangle.getLineStyle());
rectangle.setLineStyleColor(1111);
rectangle.setNoFill(true);
+ rectangle.setString(new HSSFRichTextString("teeeest"));
assertEquals(rectangle.getLineStyleColor(), 1111);
assertEquals(rectangle.isNoFill(), true);
+ assertEquals(rectangle.getString().getString(), "teeeest");
wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
sheet = wb.getSheetAt(0);
@@ -149,6 +152,7 @@ public class TestDrawingShapes extends TestCase {
assertEquals(rectangle2.getLineStyleColor(), 1111);
assertEquals(rectangle2.getFillColor(), 777);
assertEquals(rectangle2.isNoFill(), true);
+ assertEquals(rectangle2.getString().getString(), "teeeest");
rectangle2.setFillColor(3333);
rectangle2.setLineStyle(9);
@@ -159,6 +163,7 @@ public class TestDrawingShapes extends TestCase {
rectangle2.getAnchor().setDx2(3);
rectangle2.getAnchor().setDy1(4);
rectangle2.getAnchor().setDy2(5);
+ rectangle2.setString(new HSSFRichTextString("test22"));
wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
sheet = wb.getSheetAt(0);
@@ -175,6 +180,7 @@ public class TestDrawingShapes extends TestCase {
assertEquals(rectangle2.getAnchor().getDy1(), 4);
assertEquals(rectangle2.getAnchor().getDy2(), 5);
assertEquals(rectangle2.isNoFill(), false);
+ assertEquals(rectangle2.getString().getString(), "test22");
HSSFSimpleShape rect3 = drawing.createSimpleShape(new HSSFClientAnchor());
rect3.setShapeType(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE);
@@ -196,7 +202,7 @@ public class TestDrawingShapes extends TestCase {
assertEquals(picture.getFillColor(), 0x5DC943);
assertEquals(picture.getLineWidth(), HSSFShape.LINEWIDTH_DEFAULT);
assertEquals(picture.getLineStyle(), HSSFShape.LINESTYLE_DEFAULT);
- assertEquals(picture.isNoFill(), true);
+ assertEquals(picture.isNoFill(), false);
picture.setPictureIndex(2);
assertEquals(picture.getPictureIndex(), 2);
@@ -211,11 +217,12 @@ public class TestDrawingShapes extends TestCase {
assertEquals(1, drawing.getChildren().size());
HSSFSimpleShape shape = (HSSFSimpleShape) drawing.getChildren().get(0);
- assertEquals(shape.isNoFill(), true);
+ assertEquals(shape.isNoFill(), false);
assertEquals(shape.getLineStyle(), HSSFShape.LINESTYLE_DASHDOTGEL);
assertEquals(shape.getLineStyleColor(), 0x616161);
assertEquals(HexDump.toHex(shape.getFillColor()), shape.getFillColor(), 0x2CE03D);
assertEquals(shape.getLineWidth(), HSSFShape.LINEWIDTH_ONE_PT * 2);
+ assertEquals(shape.getString().getString(), "POItest");
}
public void testShapeIds() {
diff --git a/src/testcases/org/apache/poi/hssf/model/TestHSSFAnchor.java b/src/testcases/org/apache/poi/hssf/model/TestHSSFAnchor.java
index 248247266a..9134332834 100644
--- a/src/testcases/org/apache/poi/hssf/model/TestHSSFAnchor.java
+++ b/src/testcases/org/apache/poi/hssf/model/TestHSSFAnchor.java
@@ -375,4 +375,38 @@ public class TestHSSFAnchor extends TestCase {
childAnchor2.setDy2(3);
assertEquals(childAnchor1, childAnchor2);
}
+
+ public void testFlipped(){
+ HSSFChildAnchor child = new HSSFChildAnchor(2,2,1,1);
+ assertEquals(child.isHorizontallyFlipped(), true);
+ assertEquals(child.isVerticallyFlipped(), true);
+ assertEquals(child.getDx1(), 1);
+ assertEquals(child.getDx2(), 2);
+ assertEquals(child.getDy1(), 1);
+ assertEquals(child.getDy2(), 2);
+
+ child = new HSSFChildAnchor(3,3,4,4);
+ assertEquals(child.isHorizontallyFlipped(), false);
+ assertEquals(child.isVerticallyFlipped(), false);
+ assertEquals(child.getDx1(), 3);
+ assertEquals(child.getDx2(), 4);
+ assertEquals(child.getDy1(), 3);
+ assertEquals(child.getDy2(), 4);
+
+ HSSFClientAnchor client = new HSSFClientAnchor(1,1,1,1, (short)4,4,(short)3,3);
+ assertEquals(client.isVerticallyFlipped(), true);
+ assertEquals(client.isHorizontallyFlipped(), true);
+ assertEquals(client.getCol1(), 3);
+ assertEquals(client.getCol2(), 4);
+ assertEquals(client.getRow1(), 3);
+ assertEquals(client.getRow2(), 4);
+
+ client = new HSSFClientAnchor(1,1,1,1, (short)5,5,(short)6,6);
+ assertEquals(client.isVerticallyFlipped(), false);
+ assertEquals(client.isHorizontallyFlipped(), false);
+ assertEquals(client.getCol1(), 5);
+ assertEquals(client.getCol2(), 6);
+ assertEquals(client.getRow1(), 5);
+ assertEquals(client.getRow2(), 6);
+ }
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java b/src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java
index 3aafa04edd..d5606362c8 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java
@@ -83,7 +83,7 @@ public class HSSFTestHelper {
}
public static EscherOptRecord getOptRecord(HSSFShape shape){
- return shape._optRecord;
+ return shape.getOptRecord();
}
public static void convertHSSFGroup(HSSFShapeGroup shape, EscherContainerRecord escherParent, Map shapeToObj){
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestComment.java b/src/testcases/org/apache/poi/hssf/usermodel/TestComment.java
index 376edc32b1..b098c19737 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestComment.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestComment.java
@@ -212,8 +212,7 @@ public class TestComment extends TestCase {
HSSFSimpleShape shape = patriarch.createSimpleShape(new HSSFClientAnchor());
- //6 properties of HSSFShape + 8 of HSSFTextbox
- assertEquals(comment._optRecord.getEscherProperties().size(), 14);
+ assertEquals(comment.getOptRecord().getEscherProperties().size(), 10);
}
public void testShapeId(){
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java
index 6c08a167a1..234cddccfd 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java
@@ -17,8 +17,10 @@
package org.apache.poi.hssf.usermodel;
+import org.apache.poi.ddf.EscherBSERecord;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.HSSFITestDataProvider;
+import org.apache.poi.hssf.model.InternalSheet;
import org.apache.poi.ss.usermodel.BaseTestPicture;
import org.apache.poi.ss.usermodel.PictureData;
import org.apache.poi.ss.usermodel.Workbook;
@@ -149,4 +151,63 @@ public final class TestHSSFPicture extends BaseTestPicture {
assertTrue(Arrays.equals(data4, ((HSSFPicture)dr.getChildren().get(3)).getPictureData().getData()));
}
+ public void testBSEPictureRef(){
+ HSSFWorkbook wb = new HSSFWorkbook();
+
+ HSSFSheet sh = wb.createSheet("Pictures");
+ HSSFPatriarch dr = sh.createDrawingPatriarch();
+ HSSFClientAnchor anchor = new HSSFClientAnchor();
+
+ InternalSheet ish = HSSFTestHelper.getSheetForTest(sh);
+
+ //register a picture
+ byte[] data1 = new byte[]{1, 2, 3};
+ int idx1 = wb.addPicture(data1, Workbook.PICTURE_TYPE_JPEG);
+ assertEquals(1, idx1);
+ HSSFPicture p1 = dr.createPicture(anchor, idx1);
+
+ EscherBSERecord bse = wb.getWorkbook().getBSERecord(idx1);
+
+ assertEquals(bse.getRef(), 1);
+ dr.createPicture(new HSSFClientAnchor(), idx1);
+ assertEquals(bse.getRef(), 2);
+
+ HSSFShapeGroup gr = dr.createGroup(new HSSFClientAnchor());
+ gr.createPicture(new HSSFChildAnchor(), idx1);
+ assertEquals(bse.getRef(), 3);
+ }
+
+ public void testReadExistingImage(){
+ HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("drawings.xls");
+ HSSFSheet sheet = wb.getSheet("picture");
+ HSSFPatriarch drawing = sheet.getDrawingPatriarch();
+ assertEquals(1, drawing.getChildren().size());
+
+ HSSFPicture picture = (HSSFPicture) drawing.getChildren().get(0);
+ assertEquals(picture.getAdditionalData(), "test");
+ }
+
+ public void testSetGetProperties(){
+ HSSFWorkbook wb = new HSSFWorkbook();
+
+ HSSFSheet sh = wb.createSheet("Pictures");
+ HSSFPatriarch dr = sh.createDrawingPatriarch();
+ HSSFClientAnchor anchor = new HSSFClientAnchor();
+
+ //register a picture
+ byte[] data1 = new byte[]{1, 2, 3};
+ int idx1 = wb.addPicture(data1, Workbook.PICTURE_TYPE_JPEG);
+ HSSFPicture p1 = dr.createPicture(anchor, idx1);
+
+ assertEquals(p1.getAdditionalData(), "");
+ p1.setAdditionalData("aaa");
+ assertEquals(p1.getAdditionalData(), "aaa");
+
+ wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
+ sh = wb.getSheet("Pictures");
+ dr = sh.getDrawingPatriarch();
+
+ p1 = (HSSFPicture) dr.getChildren().get(0);
+ assertEquals(p1.getAdditionalData(), "aaa");
+ }
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestPolygon.java b/src/testcases/org/apache/poi/hssf/usermodel/TestPolygon.java
index 7c83a0d25f..3983c838b2 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestPolygon.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestPolygon.java
@@ -73,7 +73,7 @@ public class TestPolygon extends TestCase{
PolygonShape polygonShape = HSSFTestModelHelper.createPolygonShape(0, polygon);
- EscherArrayProperty verticesProp1 = polygon._optRecord.lookup(EscherProperties.GEOMETRY__VERTICES);
+ EscherArrayProperty verticesProp1 = polygon.getOptRecord().lookup(EscherProperties.GEOMETRY__VERTICES);
EscherArrayProperty verticesProp2 = ((EscherOptRecord)polygonShape.getSpContainer().getChildById(EscherOptRecord.RECORD_ID))
.lookup(EscherProperties.GEOMETRY__VERTICES);
@@ -85,7 +85,7 @@ public class TestPolygon extends TestCase{
assertTrue(Arrays.equals(polygon.getYPoints(), new int[]{4, 5, 6}));
polygonShape = HSSFTestModelHelper.createPolygonShape(0, polygon);
- verticesProp1 = polygon._optRecord.lookup(EscherProperties.GEOMETRY__VERTICES);
+ verticesProp1 = polygon.getOptRecord().lookup(EscherProperties.GEOMETRY__VERTICES);
verticesProp2 = ((EscherOptRecord)polygonShape.getSpContainer().getChildById(EscherOptRecord.RECORD_ID))
.lookup(EscherProperties.GEOMETRY__VERTICES);