aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache/poi
diff options
context:
space:
mode:
authorEvgeniy Berlog <berlog@apache.org>2012-07-19 19:02:43 +0000
committerEvgeniy Berlog <berlog@apache.org>2012-07-19 19:02:43 +0000
commit4e646a718235a622fde308eab8e66698204f923d (patch)
treedaad2a2396cb5712ac981bd733d5da36ca722e43 /src/testcases/org/apache/poi
parent47dd4545797ec8e0e789445931d3897a98cf384c (diff)
downloadpoi-4e646a718235a622fde308eab8e66698204f923d.tar.gz
poi-4e646a718235a622fde308eab8e66698204f923d.zip
implemented cloning of shapes
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/gsoc2012@1363479 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi')
-rw-r--r--src/testcases/org/apache/poi/hssf/model/TestDrawingAggregate.java40
-rw-r--r--src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java6
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java15
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestCloneSheet.java76
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestComment.java11
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestShapeGroup.java23
7 files changed, 87 insertions, 88 deletions
diff --git a/src/testcases/org/apache/poi/hssf/model/TestDrawingAggregate.java b/src/testcases/org/apache/poi/hssf/model/TestDrawingAggregate.java
index b497212518..9de806cfc7 100644
--- a/src/testcases/org/apache/poi/hssf/model/TestDrawingAggregate.java
+++ b/src/testcases/org/apache/poi/hssf/model/TestDrawingAggregate.java
@@ -194,46 +194,6 @@ public class TestDrawingAggregate extends TestCase {
}
}
- public void testBuildBaseTree(){
- HSSFWorkbook wb = new HSSFWorkbook();
- HSSFSheet sheet = wb.createSheet();
- HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
- EscherAggregate agg = HSSFTestHelper.getEscherAggregate(patriarch);
- EscherAggregate agg1 = new EscherAggregate(new HSSFTestHelper.MockDrawingManager());
- EscherSpgrRecord spgr = new EscherSpgrRecord();
- spgr.setRectY1(0);
- spgr.setRectY2(255);
- spgr.setRectX1(0);
- spgr.setRectX2(1023);
- EscherContainerRecord spContainer = new EscherContainerRecord();
- spContainer.addChildRecord(spgr);
- EscherContainerRecord spgrContainer = new EscherContainerRecord();
- spgrContainer.addChildRecord(spContainer);
- EscherContainerRecord dgContainer = new EscherContainerRecord();
- dgContainer.addChildRecord(spgrContainer);
- agg1.addEscherRecord(dgContainer);
- agg1.setPatriarch(HSSFTestHelper.createTestPatriarch(sheet, agg1));
- agg1.clear();
- HSSFTestHelper.callConvertPatriarch(agg1);
- agg1.setPatriarch(null);
-
- agg.setPatriarch(null);
-//
- EscherSpRecord sp = (EscherSpRecord) agg.getEscherContainer().getChildContainers().get(0).getChild(0).getChild(1);
- sp.setShapeId(1025);
- EscherDgRecord dg = (EscherDgRecord) agg.getEscherContainer().getChild(0);
- dg.setNumShapes(1);
- dg.setOptions((short) (1 << 4));
-
- byte[] aggS = agg.serialize();
- byte []agg1S = agg1.serialize();
-
- assertEquals(aggS.length, agg1S.length);
- assertTrue(Arrays.equals(aggS, agg1S));
- }
-
-
-
/**
* when reading incomplete data ensure that the serialized bytes
match the source
diff --git a/src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java b/src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java
index dd8882764f..e57a1b4372 100644
--- a/src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java
+++ b/src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java
@@ -352,8 +352,7 @@ public class TestDrawingShapes extends TestCase {
shape.setShapeType(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE);
EscherAggregate agg = HSSFTestHelper.getEscherAggregate(patriarch);
- assertNull(shape.getEscherContainer().getChildById(EscherTextboxRecord.RECORD_ID));
- assertEquals(agg.getShapeToObjMapping().size(), 1);
+ assertEquals(agg.getShapeToObjMapping().size(), 2);
wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
sheet = wb.getSheetAt(0);
@@ -362,8 +361,7 @@ public class TestDrawingShapes extends TestCase {
shape = (HSSFSimpleShape) patriarch.getChildren().get(0);
agg = HSSFTestHelper.getEscherAggregate(patriarch);
- assertNull(shape.getEscherContainer().getChildById(EscherTextboxRecord.RECORD_ID));
- assertEquals(agg.getShapeToObjMapping().size(), 1);
+ assertEquals(agg.getShapeToObjMapping().size(), 2);
shape.setString(new HSSFRichTextString("string1"));
assertEquals(shape.getString().getString(), "string1");
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java b/src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java
index 50ff1dc50c..465f7746b0 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java
@@ -101,21 +101,6 @@ public class HSSFTestHelper {
}
}
- public static void callConvertPatriarch(EscherAggregate agg) {
- Method method = null;
- try {
- method = agg.getClass().getDeclaredMethod("convertPatriarch", HSSFPatriarch.class);
- method.setAccessible(true);
- method.invoke(agg, agg.getPatriarch());
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- } catch (NoSuchMethodException e) {
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- e.printStackTrace();
- }
- }
-
public static void setShapeId(HSSFShape shape, int id){
shape.setShapeId(id);
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestCloneSheet.java b/src/testcases/org/apache/poi/hssf/usermodel/TestCloneSheet.java
index 1f276b7765..10acaa5e9f 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestCloneSheet.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestCloneSheet.java
@@ -19,8 +19,14 @@ package org.apache.poi.hssf.usermodel;
import junit.framework.TestCase;
+import org.apache.poi.ddf.EscherDgRecord;
+import org.apache.poi.ddf.EscherSpRecord;
+import org.apache.poi.hssf.record.EscherAggregate;
import org.apache.poi.ss.util.CellRangeAddress;
+import java.io.IOException;
+import java.util.Arrays;
+
/**
* Test the ability to clone a sheet.
* If adding new records that belong to a sheet (as opposed to a book)
@@ -55,4 +61,74 @@ public final class TestCloneSheet extends TestCase {
assertTrue("Row 3 still should be broken", clone.isRowBroken(3));
}
+
+ public void testCloneSheetWithoutDrawings(){
+ HSSFWorkbook b = new HSSFWorkbook();
+ HSSFSheet s = b.createSheet("Test");
+ HSSFSheet s2 = s.cloneSheet(b);
+
+ assertNull(s.getDrawingPatriarch());
+ assertNull(s2.getDrawingPatriarch());
+ assertEquals(HSSFTestHelper.getSheetForTest(s).getRecords().size(), HSSFTestHelper.getSheetForTest(s2).getRecords().size());
+ }
+
+ public void testCloneSheetWithEmptyDrawingAggregate(){
+ HSSFWorkbook b = new HSSFWorkbook();
+ HSSFSheet s = b.createSheet("Test");
+ HSSFPatriarch patriarch = s.createDrawingPatriarch();
+
+ EscherAggregate agg1 = patriarch._getBoundAggregate();
+
+ HSSFSheet s2 = s.cloneSheet(b);
+
+ patriarch = s2.getDrawingPatriarch();
+
+ EscherAggregate agg2 = patriarch._getBoundAggregate();
+
+ EscherSpRecord sp1 = (EscherSpRecord) agg1.getEscherContainer().getChild(1).getChild(0).getChild(1);
+ EscherSpRecord sp2 = (EscherSpRecord) agg2.getEscherContainer().getChild(1).getChild(0).getChild(1);
+
+ assertEquals(sp1.getShapeId(), 1024);
+ assertEquals(sp2.getShapeId(), 2048);
+
+ EscherDgRecord dg = (EscherDgRecord) agg2.getEscherContainer().getChild(0);
+
+ assertEquals(dg.getLastMSOSPID(), 2048);
+ assertEquals(dg.getInstance(), 0x2);
+
+ //everything except id and DgRecord.lastMSOSPID and DgRecord.Instance must be the same
+
+ sp2.setShapeId(1024);
+ dg.setLastMSOSPID(1024);
+ dg.setInstance((short) 0x1);
+
+ assertEquals(agg1.serialize().length, agg2.serialize().length);
+ assertEquals(agg1.toXml(""), agg2.toXml(""));
+ assertTrue(Arrays.equals(agg1.serialize(), agg2.serialize()));
+ }
+
+ public void testCloneComment() throws IOException {
+ HSSFWorkbook wb = new HSSFWorkbook();
+ HSSFSheet sh = wb.createSheet();
+ HSSFPatriarch p = sh.createDrawingPatriarch();
+ HSSFComment c = p.createComment(new HSSFClientAnchor(0,0,100,100, (short) 0,0,(short)5,5));
+ c.setColumn(1);
+ c.setRow(2);
+ c.setString(new HSSFRichTextString("qwertyuio"));
+
+ HSSFSheet sh2 = wb.cloneSheet(0);
+ HSSFPatriarch p2 = sh2.getDrawingPatriarch();
+ HSSFComment c2 = (HSSFComment) p2.getChildren().get(0);
+
+ assertTrue(Arrays.equals(c2.getTextObjectRecord().serialize(), c.getTextObjectRecord().serialize()));
+ assertTrue(Arrays.equals(c2.getObjRecord().serialize(), c.getObjRecord().serialize()));
+ assertTrue(Arrays.equals(c2.getNoteRecord().serialize(), c.getNoteRecord().serialize()));
+
+
+ //everything except spRecord.shapeId must be the same
+ assertFalse(Arrays.equals(c2.getEscherContainer().serialize(), c.getEscherContainer().serialize()));
+ EscherSpRecord sp = (EscherSpRecord) c2.getEscherContainer().getChild(0);
+ sp.setShapeId(1025);
+ assertTrue(Arrays.equals(c2.getEscherContainer().serialize(), c.getEscherContainer().serialize()));
+ }
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestComment.java b/src/testcases/org/apache/poi/hssf/usermodel/TestComment.java
index b098c19737..cbf49bb5e3 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestComment.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestComment.java
@@ -58,6 +58,8 @@ public class TestComment extends TestCase {
ObjRecord obj = comment.getObjRecord();
ObjRecord objShape = commentShape.getObjRecord();
+ /**shapeId = 1025 % 1024**/
+ ((CommonObjectDataSubRecord)objShape.getSubRecords().get(0)).setObjectId(1);
expected = obj.serialize();
actual = objShape.serialize();
@@ -76,6 +78,7 @@ public class TestComment extends TestCase {
NoteRecord note = comment.getNoteRecord();
NoteRecord noteShape = commentShape.getNoteRecord();
+ noteShape.setShapeId(1);
expected = note.serialize();
actual = noteShape.serialize();
@@ -225,17 +228,17 @@ public class TestComment extends TestCase {
comment.setShapeId(2024);
/**
* SpRecord.id == shapeId
- * ObjRecord.id == shapeId - 1024
- * NoteRecord.id == ObjectRecord.id == shapeId - 1024
+ * ObjRecord.id == shapeId % 1024
+ * NoteRecord.id == ObjectRecord.id == shapeId % 1024
*/
assertEquals(comment.getShapeId(), 2024);
CommonObjectDataSubRecord cod = (CommonObjectDataSubRecord) comment.getObjRecord().getSubRecords().get(0);
- assertEquals(cod.getObjectId(), 2024);
+ assertEquals(cod.getObjectId(), 1000);
EscherSpRecord spRecord = (EscherSpRecord) comment.getEscherContainer().getChild(0);
assertEquals(spRecord.getShapeId(), 2024);
assertEquals(comment.getShapeId(), 2024);
- assertEquals(comment.getNoteRecord().getShapeId(), 2024);
+ assertEquals(comment.getNoteRecord().getShapeId(), 1000);
}
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
index 1abf1026ed..d05f048771 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
@@ -808,8 +808,8 @@ public final class TestHSSFSheet extends BaseTestSheet {
HSSFSheet sheet2 = wb2.getSheetAt(1);
//check that id of the drawing group was updated
- EscherDgRecord dg1 = (EscherDgRecord)sheet1.getDrawingEscherAggregate().findFirstWithId(EscherDgRecord.RECORD_ID);
- EscherDgRecord dg2 = (EscherDgRecord)sheet2.getDrawingEscherAggregate().findFirstWithId(EscherDgRecord.RECORD_ID);
+ EscherDgRecord dg1 = (EscherDgRecord)sheet1.getDrawingPatriarch()._getBoundAggregate().findFirstWithId(EscherDgRecord.RECORD_ID);
+ EscherDgRecord dg2 = (EscherDgRecord)sheet2.getDrawingPatriarch()._getBoundAggregate().findFirstWithId(EscherDgRecord.RECORD_ID);
int dg_id_1 = dg1.getOptions() >> 4;
int dg_id_2 = dg2.getOptions() >> 4;
assertEquals(dg_id_1 + 1, dg_id_2);
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestShapeGroup.java b/src/testcases/org/apache/poi/hssf/usermodel/TestShapeGroup.java
index 5eb93f6e3e..f0ce3f2801 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestShapeGroup.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestShapeGroup.java
@@ -17,29 +17,6 @@ import java.util.Map;
*/
public class TestShapeGroup extends TestCase{
- public void testResultEqualsToAbstractShape() {
- HSSFWorkbook wb = new HSSFWorkbook();
- HSSFSheet sheet = wb.createSheet();
- HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
- HSSFShapeGroup group = patriarch.createGroup(new HSSFClientAnchor());
-
- EscherContainerRecord container = new EscherContainerRecord();
- Map shapeToObj = new HashMap();
- HSSFTestHelper.convertHSSFGroup(group, container, shapeToObj);
-
- byte [] actual = group.getEscherContainer().serialize();
- byte [] expected = container.getChild(0).serialize();
-
- assertEquals(actual.length, expected.length);
- assertTrue(Arrays.equals(actual, expected));
-
- actual = group.getObjRecord().serialize();
- expected = ((ObjRecord)shapeToObj.values().toArray()[0]).serialize();
-
- assertEquals(actual.length, expected.length);
- assertTrue(Arrays.equals(actual, expected));
- }
-
public void testSetGetCoordinates(){
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sh = wb.createSheet();