aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache/poi/hssf
diff options
context:
space:
mode:
authorEvgeniy Berlog <berlog@apache.org>2012-06-28 10:56:55 +0000
committerEvgeniy Berlog <berlog@apache.org>2012-06-28 10:56:55 +0000
commitfe51bb989b1e85d48d22a52974d40946eac325eb (patch)
tree98f84a6efa349559ca62e6632a7c8833ff789ae0 /src/testcases/org/apache/poi/hssf
parentb57fa5b4d0621d11b3f324387cebad89cd046eb8 (diff)
downloadpoi-fe51bb989b1e85d48d22a52974d40946eac325eb.tar.gz
poi-fe51bb989b1e85d48d22a52974d40946eac325eb.zip
implemented creating comments in existing files, bugfixes
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/gsoc2012@1354910 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/hssf')
-rw-r--r--src/testcases/org/apache/poi/hssf/model/HSSFTestModelHelper.java5
-rw-r--r--src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java92
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java5
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestComment.java241
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java2
5 files changed, 316 insertions, 29 deletions
diff --git a/src/testcases/org/apache/poi/hssf/model/HSSFTestModelHelper.java b/src/testcases/org/apache/poi/hssf/model/HSSFTestModelHelper.java
index cca8f2d635..507561e7e4 100644
--- a/src/testcases/org/apache/poi/hssf/model/HSSFTestModelHelper.java
+++ b/src/testcases/org/apache/poi/hssf/model/HSSFTestModelHelper.java
@@ -1,5 +1,6 @@
package org.apache.poi.hssf.model;
+import org.apache.poi.hssf.usermodel.HSSFComment;
import org.apache.poi.hssf.usermodel.HSSFTextbox;
/**
@@ -10,4 +11,8 @@ 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);
+ }
}
diff --git a/src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java b/src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java
index 1beeabe94b..4e120a7cb8 100644
--- a/src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java
+++ b/src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java
@@ -17,7 +17,7 @@ import static junit.framework.Assert.assertEquals;
* @author Evgeniy Berlog
* date: 12.06.12
*/
-public class TestDrawingShapes extends TestCase{
+public class TestDrawingShapes extends TestCase {
/**
* HSSFShape tree bust be built correctly
@@ -33,7 +33,7 @@ public class TestDrawingShapes extends TestCase{
* ----shape
* ----shape
*/
- public void testDrawingGroups(){
+ public void testDrawingGroups() {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("drawings.xls");
HSSFSheet sheet = wb.getSheet("groups");
HSSFPatriarch patriarch = sheet.getDrawingPatriarch();
@@ -47,7 +47,7 @@ public class TestDrawingShapes extends TestCase{
}
public void testHSSFShapeCompatibility() {
- HSSFShape shape = new HSSFSimpleShape(null, new HSSFClientAnchor());
+ HSSFShape shape = new HSSFSimpleShape(null, new HSSFClientAnchor());
assertEquals(0x08000040, shape.getLineStyleColor());
assertEquals(0x08000009, shape.getFillColor());
assertEquals(HSSFShape.LINEWIDTH_DEFAULT, shape.getLineWidth());
@@ -61,22 +61,22 @@ public class TestDrawingShapes extends TestCase{
assertEquals(7, opt.getEscherProperties().size());
assertEquals(true,
- ((EscherBoolProperty)opt.lookup(EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE)).isTrue());
+ ((EscherBoolProperty) opt.lookup(EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE)).isTrue());
assertEquals(0x00000004,
- ((EscherSimpleProperty)opt.lookup(EscherProperties.GEOMETRY__SHAPEPATH)).getPropertyValue());
+ ((EscherSimpleProperty) opt.lookup(EscherProperties.GEOMETRY__SHAPEPATH)).getPropertyValue());
assertEquals(0x08000009,
- ((EscherSimpleProperty)opt.lookup(EscherProperties.FILL__FILLCOLOR)).getPropertyValue());
+ ((EscherSimpleProperty) opt.lookup(EscherProperties.FILL__FILLCOLOR)).getPropertyValue());
assertEquals(true,
- ((EscherBoolProperty)opt.lookup(EscherProperties.FILL__NOFILLHITTEST)).isTrue());
+ ((EscherBoolProperty) opt.lookup(EscherProperties.FILL__NOFILLHITTEST)).isTrue());
assertEquals(0x08000040,
- ((EscherSimpleProperty)opt.lookup(EscherProperties.LINESTYLE__COLOR)).getPropertyValue());
+ ((EscherSimpleProperty) opt.lookup(EscherProperties.LINESTYLE__COLOR)).getPropertyValue());
assertEquals(true,
- ((EscherBoolProperty)opt.lookup(EscherProperties.LINESTYLE__NOLINEDRAWDASH)).isTrue());
+ ((EscherBoolProperty) opt.lookup(EscherProperties.LINESTYLE__NOLINEDRAWDASH)).isTrue());
assertEquals(true,
- ((EscherBoolProperty)opt.lookup(EscherProperties.GROUPSHAPE__PRINT)).isTrue());
+ ((EscherBoolProperty) opt.lookup(EscherProperties.GROUPSHAPE__PRINT)).isTrue());
}
- public void testDefaultPictureSettings(){
+ public void testDefaultPictureSettings() {
HSSFPicture picture = new HSSFPicture(null, new HSSFClientAnchor());
assertEquals(picture.getLineWidth(), HSSFShape.LINEWIDTH_DEFAULT);
assertEquals(picture.getFillColor(), HSSFShape.FILL__FILLCOLOR_DEFAULT);
@@ -89,7 +89,7 @@ public class TestDrawingShapes extends TestCase{
/**
* No NullPointerException should appear
*/
- public void testDefaultSettingsWithEmptyContainer(){
+ public void testDefaultSettingsWithEmptyContainer() {
EscherContainerRecord container = new EscherContainerRecord();
EscherOptRecord opt = new EscherOptRecord();
opt.setRecordId(EscherOptRecord.RECORD_ID);
@@ -107,6 +107,7 @@ public class TestDrawingShapes extends TestCase{
assertEquals(picture.isNoFill(), HSSFShape.NO_FILL_DEFAULT);
assertEquals(picture.getPictureIndex(), -1);//not set yet
}
+
/**
* create a rectangle, save the workbook, read back and verify that all shape properties are there
*/
@@ -116,7 +117,7 @@ public class TestDrawingShapes extends TestCase{
HSSFSheet sheet = wb.createSheet();
HSSFPatriarch drawing = sheet.createDrawingPatriarch();
- HSSFClientAnchor anchor = new HSSFClientAnchor(10, 10, 200, 200, (short)2, 2, (short)15, 15);
+ HSSFClientAnchor anchor = new HSSFClientAnchor(10, 10, 200, 200, (short) 2, 2, (short) 15, 15);
anchor.setAnchorType(2);
assertEquals(anchor.getAnchorType(), 2);
@@ -139,7 +140,7 @@ public class TestDrawingShapes extends TestCase{
assertEquals(1, drawing.getChildren().size());
HSSFSimpleShape rectangle2 =
- (HSSFSimpleShape)drawing.getChildren().get(0);
+ (HSSFSimpleShape) drawing.getChildren().get(0);
assertEquals(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE,
rectangle2.getShapeType());
assertEquals(10000, rectangle2.getLineWidth());
@@ -163,7 +164,7 @@ public class TestDrawingShapes extends TestCase{
sheet = wb.getSheetAt(0);
drawing = sheet.getDrawingPatriarch();
assertEquals(1, drawing.getChildren().size());
- rectangle2 = (HSSFSimpleShape)drawing.getChildren().get(0);
+ rectangle2 = (HSSFSimpleShape) drawing.getChildren().get(0);
assertEquals(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE, rectangle2.getShapeType());
assertEquals(77, rectangle2.getLineWidth());
assertEquals(9, rectangle2.getLineStyle());
@@ -183,7 +184,7 @@ public class TestDrawingShapes extends TestCase{
assertEquals(drawing.getChildren().size(), 2);
}
- public void testReadExistingImage(){
+ public void testReadExistingImage() {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("drawings.xls");
HSSFSheet sheet = wb.getSheet("pictures");
HSSFPatriarch drawing = sheet.getDrawingPatriarch();
@@ -196,6 +197,9 @@ public class TestDrawingShapes extends TestCase{
assertEquals(picture.getLineWidth(), HSSFShape.LINEWIDTH_DEFAULT);
assertEquals(picture.getLineStyle(), HSSFShape.LINESTYLE_DEFAULT);
assertEquals(picture.isNoFill(), true);
+
+ picture.setPictureIndex(2);
+ assertEquals(picture.getPictureIndex(), 2);
}
@@ -206,20 +210,19 @@ public class TestDrawingShapes extends TestCase{
HSSFPatriarch drawing = sheet.getDrawingPatriarch();
assertEquals(1, drawing.getChildren().size());
- for(HSSFShape shape : drawing.getChildren()){
- assertEquals(shape.isNoFill(), true);
- 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);
- }
+ HSSFSimpleShape shape = (HSSFSimpleShape) drawing.getChildren().get(0);
+ assertEquals(shape.isNoFill(), true);
+ 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);
}
public void testShapeIds() {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet();
HSSFPatriarch patriarch1 = sheet1.createDrawingPatriarch();
- for(int i = 0; i < 2; i++) {
+ for (int i = 0; i < 2; i++) {
patriarch1.createSimpleShape(new HSSFClientAnchor());
}
@@ -240,15 +243,15 @@ public class TestDrawingShapes extends TestCase{
assertEquals(3, spgrContainer.getChildRecords().size());
EscherSpRecord sp0 =
- ((EscherContainerRecord)spgrContainer.getChild(0)).getChildById(EscherSpRecord.RECORD_ID);
+ ((EscherContainerRecord) spgrContainer.getChild(0)).getChildById(EscherSpRecord.RECORD_ID);
assertEquals(1024, sp0.getShapeId());
EscherSpRecord sp1 =
- ((EscherContainerRecord)spgrContainer.getChild(1)).getChildById(EscherSpRecord.RECORD_ID);
+ ((EscherContainerRecord) spgrContainer.getChild(1)).getChildById(EscherSpRecord.RECORD_ID);
assertEquals(1025, sp1.getShapeId());
EscherSpRecord sp2 =
- ((EscherContainerRecord)spgrContainer.getChild(2)).getChildById(EscherSpRecord.RECORD_ID);
+ ((EscherContainerRecord) spgrContainer.getChild(2)).getChildById(EscherSpRecord.RECORD_ID);
assertEquals(1026, sp2.getShapeId());
}
@@ -256,7 +259,7 @@ public class TestDrawingShapes extends TestCase{
* Test get new id for shapes from existing file
* File already have for 1 shape on each sheet, because document must contain EscherDgRecord for each sheet
*/
- public void testAllocateNewIds(){
+ public void testAllocateNewIds() {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("empty.xls");
HSSFSheet sheet = wb.getSheetAt(0);
HSSFPatriarch patriarch = sheet.getDrawingPatriarch();
@@ -288,4 +291,37 @@ public class TestDrawingShapes extends TestCase{
assertEquals(HSSFTestHelper.allocateNewShapeId(patriarch), 1027);
assertEquals(HSSFTestHelper.allocateNewShapeId(patriarch), 1028);
}
+
+ public void testOpt() throws Exception {
+ HSSFWorkbook wb = new HSSFWorkbook();
+
+ // create a sheet with a text box
+ HSSFSheet sheet = wb.createSheet();
+ HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
+
+ HSSFTextbox textbox = patriarch.createTextbox(new HSSFClientAnchor());
+ EscherOptRecord opt1 = HSSFTestHelper.getOptRecord(textbox);
+ EscherOptRecord opt2 = textbox.getEscherContainer().getChildById(EscherOptRecord.RECORD_ID);
+ assertSame(opt1, opt2);
+ }
+
+ public void testCorrectOrderInOptRecord(){
+ HSSFWorkbook wb = new HSSFWorkbook();
+ HSSFSheet sheet = wb.createSheet();
+ HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
+
+ HSSFTextbox textbox = patriarch.createTextbox(new HSSFClientAnchor());
+ EscherOptRecord opt = HSSFTestHelper.getOptRecord(textbox);
+
+ String opt1Str = opt.toXml();
+
+ textbox.setFillColor(textbox.getFillColor());
+ assertEquals(opt1Str, textbox.getEscherContainer().getChildById(EscherOptRecord.RECORD_ID).toXml());
+ textbox.setLineStyle(textbox.getLineStyle());
+ assertEquals(opt1Str, textbox.getEscherContainer().getChildById(EscherOptRecord.RECORD_ID).toXml());
+ textbox.setLineWidth(textbox.getLineWidth());
+ assertEquals(opt1Str, textbox.getEscherContainer().getChildById(EscherOptRecord.RECORD_ID).toXml());
+ textbox.setLineStyleColor(textbox.getLineStyleColor());
+ assertEquals(opt1Str, textbox.getEscherContainer().getChildById(EscherOptRecord.RECORD_ID).toXml());
+ }
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java b/src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java
index 496139eaab..9b2273c590 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java
@@ -16,6 +16,7 @@
==================================================================== */
package org.apache.poi.hssf.usermodel;
+import org.apache.poi.ddf.EscherOptRecord;
import org.apache.poi.hssf.model.InternalSheet;
import org.apache.poi.hssf.model.InternalWorkbook;
import org.apache.poi.hssf.record.EscherAggregate;
@@ -47,4 +48,8 @@ public class HSSFTestHelper {
public static int allocateNewShapeId(HSSFPatriarch patriarch){
return patriarch.newShapeId();
}
+
+ public static EscherOptRecord getOptRecord(HSSFShape shape){
+ return shape._optRecord;
+ }
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestComment.java b/src/testcases/org/apache/poi/hssf/usermodel/TestComment.java
new file mode 100644
index 0000000000..91b1a7cb19
--- /dev/null
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestComment.java
@@ -0,0 +1,241 @@
+package org.apache.poi.hssf.usermodel;
+
+import junit.framework.TestCase;
+import org.apache.poi.ddf.EscherSpRecord;
+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.NoteRecord;
+import org.apache.poi.hssf.record.ObjRecord;
+import org.apache.poi.hssf.record.TextObjectRecord;
+
+import java.io.IOException;
+import java.util.Arrays;
+
+/**
+ * @author Evgeniy Berlog
+ * @date 26.06.12
+ */
+public class TestComment extends TestCase {
+
+ public void testResultEqualsToAbstractShape() {
+ HSSFWorkbook wb = new HSSFWorkbook();
+ HSSFSheet sh = wb.createSheet();
+ HSSFPatriarch patriarch = sh.createDrawingPatriarch();
+
+ HSSFComment comment = patriarch.createCellComment(new HSSFClientAnchor());
+ HSSFRow row = sh.createRow(0);
+ HSSFCell cell = row.createCell(0);
+ cell.setCellComment(comment);
+
+ CommentShape commentShape = HSSFTestModelHelper.createCommentShape(0, comment);
+
+ assertEquals(comment.getEscherContainer().getChildRecords().size(), 5);
+ assertEquals(commentShape.getSpContainer().getChildRecords().size(), 5);
+
+ //sp record
+ byte[] expected = commentShape.getSpContainer().getChild(0).serialize();
+ byte[] actual = comment.getEscherContainer().getChild(0).serialize();
+
+ assertEquals(expected.length, actual.length);
+ assertTrue(Arrays.equals(expected, actual));
+
+ expected = commentShape.getSpContainer().getChild(2).serialize();
+ actual = comment.getEscherContainer().getChild(2).serialize();
+
+ assertEquals(expected.length, actual.length);
+ assertTrue(Arrays.equals(expected, actual));
+
+ expected = commentShape.getSpContainer().getChild(3).serialize();
+ actual = comment.getEscherContainer().getChild(3).serialize();
+
+ assertEquals(expected.length, actual.length);
+ assertTrue(Arrays.equals(expected, actual));
+
+ expected = commentShape.getSpContainer().getChild(4).serialize();
+ actual = comment.getEscherContainer().getChild(4).serialize();
+
+ assertEquals(expected.length, actual.length);
+ assertTrue(Arrays.equals(expected, actual));
+
+ ObjRecord obj = comment.getObjRecord();
+ ObjRecord objShape = commentShape.getObjRecord();
+
+ expected = obj.serialize();
+ actual = objShape.serialize();
+
+ assertEquals(expected.length, actual.length);
+ assertTrue(Arrays.equals(expected, actual));
+
+ TextObjectRecord tor = comment.getTextObjectRecord();
+ TextObjectRecord torShape = commentShape.getTextObjectRecord();
+
+ expected = tor.serialize();
+ actual = torShape.serialize();
+
+ assertEquals(expected.length, actual.length);
+ assertTrue(Arrays.equals(expected, actual));
+
+ NoteRecord note = comment.getNoteRecord();
+ NoteRecord noteShape = commentShape.getNoteRecord();
+
+ expected = note.serialize();
+ actual = noteShape.serialize();
+
+ assertEquals(expected.length, actual.length);
+ assertTrue(Arrays.equals(expected, actual));
+ }
+
+ public void testAddToExistingFile() {
+ HSSFWorkbook wb = new HSSFWorkbook();
+ HSSFSheet sh = wb.createSheet();
+ HSSFPatriarch patriarch = sh.createDrawingPatriarch();
+
+ HSSFComment comment = patriarch.createCellComment(new HSSFClientAnchor());
+ comment.setString(new HSSFRichTextString("comment1"));
+ comment = patriarch.createCellComment(new HSSFClientAnchor());
+ comment.setString(new HSSFRichTextString("comment2"));
+
+ assertEquals(patriarch.getChildren().size(), 2);
+
+ wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
+ sh = wb.getSheetAt(0);
+ patriarch = sh.getDrawingPatriarch();
+
+ assertEquals(patriarch.getChildren().size(), 2);
+ comment = patriarch.createCellComment(new HSSFClientAnchor());
+ comment.setString(new HSSFRichTextString("comment3"));
+
+ assertEquals(patriarch.getChildren().size(), 3);
+ wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
+ sh = wb.getSheetAt(0);
+ patriarch = sh.getDrawingPatriarch();
+ assertEquals(patriarch.getChildren().size(), 3);
+ assertEquals(((HSSFComment) patriarch.getChildren().get(0)).getString().getString(), "comment1");
+ assertEquals(((HSSFComment) patriarch.getChildren().get(1)).getString().getString(), "comment2");
+ assertEquals(((HSSFComment) patriarch.getChildren().get(2)).getString().getString(), "comment3");
+ }
+
+ public void testSetGetProperties() throws IOException {
+ HSSFWorkbook wb = new HSSFWorkbook();
+ HSSFSheet sh = wb.createSheet();
+ HSSFPatriarch patriarch = sh.createDrawingPatriarch();
+
+ HSSFComment comment = patriarch.createCellComment(new HSSFClientAnchor());
+ comment.setString(new HSSFRichTextString("comment1"));
+ assertEquals(comment.getString().getString(), "comment1");
+
+ comment.setAuthor("poi");
+ assertEquals(comment.getAuthor(), "poi");
+
+ comment.setColumn(3);
+ assertEquals(comment.getColumn(), 3);
+
+ comment.setRow(4);
+ assertEquals(comment.getRow(), 4);
+
+ comment.setVisible(false);
+ assertEquals(comment.isVisible(), false);
+
+ wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
+ sh = wb.getSheetAt(0);
+ patriarch = sh.getDrawingPatriarch();
+
+ comment = (HSSFComment) patriarch.getChildren().get(0);
+
+ assertEquals(comment.getString().getString(), "comment1");
+ assertEquals("poi", comment.getAuthor());
+ assertEquals(comment.getColumn(), 3);
+ assertEquals(comment.getRow(), 4);
+ assertEquals(comment.isVisible(), false);
+
+ comment.setString(new HSSFRichTextString("comment12"));
+ comment.setAuthor("poi2");
+ comment.setColumn(32);
+ comment.setRow(42);
+ comment.setVisible(true);
+
+ wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
+ sh = wb.getSheetAt(0);
+ patriarch = sh.getDrawingPatriarch();
+ comment = (HSSFComment) patriarch.getChildren().get(0);
+
+ assertEquals(comment.getString().getString(), "comment12");
+ assertEquals("poi2", comment.getAuthor());
+ assertEquals(comment.getColumn(), 32);
+ assertEquals(comment.getRow(), 42);
+ assertEquals(comment.isVisible(), true);
+ }
+
+ public void testExistingFileWithComment(){
+ HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("drawings.xls");
+ HSSFSheet sheet = wb.getSheet("comments");
+ HSSFPatriarch drawing = sheet.getDrawingPatriarch();
+ assertEquals(1, drawing.getChildren().size());
+ HSSFComment comment = (HSSFComment) drawing.getChildren().get(0);
+ assertEquals(comment.getAuthor(), "evgeniy");
+ assertEquals(comment.getString().getString(), "evgeniy:\npoi test");
+ assertEquals(comment.getColumn(), 1);
+ assertEquals(comment.getRow(), 2);
+ }
+
+ public void testFindComments(){
+ HSSFWorkbook wb = new HSSFWorkbook();
+ HSSFSheet sh = wb.createSheet();
+ HSSFPatriarch patriarch = sh.createDrawingPatriarch();
+
+ HSSFComment comment = patriarch.createCellComment(new HSSFClientAnchor());
+ HSSFRow row = sh.createRow(5);
+ HSSFCell cell = row.createCell(4);
+ cell.setCellComment(comment);
+
+ HSSFTestModelHelper.createCommentShape(0, comment);
+
+ assertNotNull(sh.findCellComment(5, 4));
+ assertNull(sh.findCellComment(5, 5));
+
+ wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
+ sh = wb.getSheetAt(0);
+
+ assertNotNull(sh.findCellComment(5, 4));
+ assertNull(sh.findCellComment(5, 5));
+ }
+
+ public void testInitState(){
+ HSSFWorkbook wb = new HSSFWorkbook();
+ HSSFSheet sh = wb.createSheet();
+ HSSFPatriarch patriarch = sh.createDrawingPatriarch();
+
+ HSSFComment comment = patriarch.createCellComment(new HSSFClientAnchor());
+
+ HSSFSimpleShape shape = patriarch.createSimpleShape(new HSSFClientAnchor());
+
+ //5 properties of HSSFShape + 8 of HSSFTextbox
+ assertEquals(comment._optRecord.getEscherProperties().size(), 13);
+ }
+
+ public void testShapeId(){
+ HSSFWorkbook wb = new HSSFWorkbook();
+ HSSFSheet sh = wb.createSheet();
+ HSSFPatriarch patriarch = sh.createDrawingPatriarch();
+
+ HSSFComment comment = patriarch.createCellComment(new HSSFClientAnchor());
+
+ comment.setShapeId(2024);
+ /**
+ * SpRecord.id == shapeId
+ * 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(), 1000);
+ EscherSpRecord spRecord = (EscherSpRecord) comment.getEscherContainer().getChild(0);
+ assertEquals(spRecord.getShapeId(), 2024);
+ assertEquals(comment.getShapeId(), 2024);
+ assertEquals(comment.getNoteRecord().getShapeId(), 1000);
+ }
+}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java
index 7d04110b12..b49f725baa 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java
@@ -32,7 +32,7 @@ public final class TestHSSFComment extends BaseTestCellComment {
}
public void testDefaultShapeType() {
- HSSFComment comment = new HSSFComment((HSSFShape)null, (HSSFAnchor)null);
+ HSSFComment comment = new HSSFComment((HSSFShape)null, new HSSFClientAnchor());
assertEquals(HSSFSimpleShape.OBJECT_TYPE_COMMENT, comment.getShapeType());
}