public void TestConstruct() { ObjRecord record = new ObjRecord(); CommonObjectDataSubRecord ftCmo = new CommonObjectDataSubRecord(); ftCmo.ObjectType = (CommonObjectType.Comment); ftCmo.ObjectId = ((short)1024); ftCmo.IsLocked = (true); ftCmo.IsPrintable = (true); ftCmo.IsAutoFill = (true); ftCmo.IsAutoline = (true); record.AddSubRecord(ftCmo); EndSubRecord ftEnd = new EndSubRecord(); record.AddSubRecord(ftEnd); //Serialize and Read again byte[] recordBytes = record.Serialize(); //cut off the record header byte[] bytes = new byte[recordBytes.Length - 4]; System.Array.Copy(recordBytes, 4, bytes, 0, bytes.Length); record = new ObjRecord(TestcaseRecordInputStream.Create(ObjRecord.sid, bytes)); IList subrecords = record.SubRecords; Assert.AreEqual(2, subrecords.Count); Assert.IsTrue(subrecords[0] is CommonObjectDataSubRecord); Assert.IsTrue(subrecords[1] is EndSubRecord); }
public void Test_47701() { byte[] data = HexRead.ReadFromString( "15, 00, 12, 00, 12, 00, 02, 00, 11, 20, " + "00, 00, 00, 00, 80, 3D, 03, 05, 00, 00, " + "00, 00, 0C, 00, 14, 00, 00, 00, 00, 00, " + "00, 00, 00, 00, 00, 00, 01, 00, 0A, 00, " + "00, 00, 10, 00, 01, 00, 13, 00, EE, 1F, " + "10, 00, 09, 00, 40, 9F, 74, 01, 25, 09, " + "00, 0C, 00, 07, 00, 07, 00, 07, 04, 00, " + "00, 00, 08, 00, 00, 00"); RecordInputStream in1 = TestcaseRecordInputStream.Create(ObjRecord.sid, data); // check read OK ObjRecord record = new ObjRecord(in1); Assert.AreEqual(3, record.SubRecords.Count); SubRecord sr = record.SubRecords[(2)]; Assert.IsTrue(sr is LbsDataSubRecord); LbsDataSubRecord lbs = (LbsDataSubRecord)sr; Assert.AreEqual(4, lbs.NumberOfItems); Assert.IsTrue(lbs.Formula is AreaPtg); AreaPtg ptg = (AreaPtg)lbs.Formula; CellRangeAddress range = new CellRangeAddress( ptg.FirstRow, ptg.LastRow, ptg.FirstColumn, ptg.LastColumn); Assert.AreEqual("H10:H13", range.FormatAsString()); // check that it re-Serializes to the same data byte[] ser = record.Serialize(); TestcaseRecordInputStream.ConfirmRecordEncoding(ObjRecord.sid, data, ser); }
public void Test_45778() { byte[] data = HexRead.ReadFromString( "15, 00, 12, 00, 14, 00, 01, 00, 01, 00, " + "01, 21, 00, 00, 3C, 13, F4, 03, 00, 00, " + "00, 00, 0C, 00, 14, 00, 00, 00, 00, 00, " + "00, 00, 00, 00, 00, 00, 01, 00, 08, 00, 00, " + "00, 10, 00, 00, 00, " + "13, 00, EE, 1F, " + "00, 00, " + "08, 00, " + //number of items "08, 00, " + //selected item "01, 03, " + //flags "00, 00, " + //objId //LbsDropData "0A, 00, " + //flags "14, 00, " + //the number of lines to be displayed in the dropdown "6C, 00, " + //the smallest width in pixels allowed for the dropdown window "00, 00, " + //num chars "00, 00"); RecordInputStream in1 = TestcaseRecordInputStream.Create(ObjRecord.sid, data); // check read OK ObjRecord record = new ObjRecord(in1); SubRecord sr = record.SubRecords[(2)]; Assert.IsTrue(sr is LbsDataSubRecord); LbsDataSubRecord lbs = (LbsDataSubRecord)sr; Assert.AreEqual(8, lbs.NumberOfItems); Assert.IsNull(lbs.Formula); // check that it re-Serializes to the same data byte[] ser = record.Serialize(); TestcaseRecordInputStream.ConfirmRecordEncoding(ObjRecord.sid, data, ser); }
public void TestReadManualComboWithFormula() { byte[] data = HexRead.ReadFromString("" + "5D 00 66 00 " + "15 00 12 00 14 00 02 00 11 20 00 00 00 00 " + "20 44 C6 04 00 00 00 00 0C 00 14 00 04 F0 C6 04 " + "00 00 00 00 00 00 01 00 06 00 00 00 10 00 00 00 " + "0E 00 0C 00 05 00 80 44 C6 04 24 09 00 02 00 02 " + "13 00 DE 1F 10 00 09 00 80 44 C6 04 25 0A 00 0F " + "00 02 00 02 00 02 06 00 03 00 08 00 00 00 00 00 " + "08 00 00 00 00 00 00 00 " // TODO sometimes last byte is non-zero ); RecordInputStream in1 = TestcaseRecordInputStream.Create(data); ObjRecord or = new ObjRecord(in1); byte[] data2 = or.Serialize(); if (data2.Length == 8228) { throw new AssertionException("Identified bug 45778"); } Assert.AreEqual(data.Length, data2.Length, "Encoded length"); for (int i = 0; i < data.Length; i++) { if (data[i] != data2[i]) { throw new AssertionException("Encoded data differs at index " + i); } } Assert.IsTrue(Arrays.Equals(data, data2)); }
public void Test_Remove_padding() { byte[] data = HexRead.ReadFromString( "5D, 00, 4C, 00, " + "15, 00, 12, 00, 12, 00, 01, 00, 11, 00, " + "00, 00, 00, 00, 00, 00, 00, 00, 00, 00, " + "00, 00, 0C, 00, 14, 00, 00, 00, 00, 00, " + "00, 00, 00, 00, 00, 00, 01, 00, 09, 00, " + "00, 00, 0F, 00, 01, 00, " + "13, 00, 1B, 00, " + "10, 00, " + //next 16 bytes is a ptg aray "09, 00, 00, 00, 00, 00, 25, 09, 00, 0C, 00, 07, 00, 07, 00, 00, " + "01, 00, " + //num lines "00, 00, " + //selected "08, 00, " + "00, 00, " + "00, 00, 00, 00, 00"); //pAdding bytes RecordInputStream in1 = TestcaseRecordInputStream.Create(data); // check read OK ObjRecord record = new ObjRecord(in1); // check that it re-Serializes to the same data byte[] ser = record.Serialize(); Assert.AreEqual(data.Length - 5, ser.Length); for (int i = 0; i < ser.Length; i++) Assert.AreEqual(data[i], ser[i]); //check we can read the Trimmed record RecordInputStream in2 = TestcaseRecordInputStream.Create(ser); ObjRecord record2 = new ObjRecord(in2); byte[] ser2 = record2.Serialize(); Assert.IsTrue(Arrays.Equals(ser, ser2)); }
public void TestStore() { ObjRecord record = new ObjRecord(TestcaseRecordInputStream.Create(ObjRecord.sid, recdata)); byte[] recordBytes = record.Serialize(); Assert.AreEqual(26, recordBytes.Length - 4); byte[] subData = new byte[recdata.Length]; System.Array.Copy(recordBytes, 4, subData, 0, subData.Length); Assert.IsTrue(Npoi.Core.Util.Arrays.Equals(recdata, subData)); }
public void TestReadAll_bug45778() { RecordInputStream in1 = TestcaseRecordInputStream.Create(dataAutoFilter); ObjRecord or = new ObjRecord(in1); byte[] data2 = or.Serialize(); if (data2.Length == 8228) { throw new AssertionException("Identified bug 45778"); } Assert.AreEqual(74, data2.Length); Assert.IsTrue(Arrays.Equals(dataAutoFilter, data2)); }
public void TestResultEqualsToAbstractShape() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sh = wb.CreateSheet() as HSSFSheet; HSSFPatriarch patriarch = sh.CreateDrawingPatriarch() as HSSFPatriarch; HSSFTextbox textbox = patriarch.CreateTextbox(new HSSFClientAnchor()) as HSSFTextbox; TextboxShape textboxShape = HSSFTestModelHelper.CreateTextboxShape(1025, textbox); Assert.AreEqual(textbox.GetEscherContainer().ChildRecords.Count, 5); Assert.AreEqual(textboxShape.SpContainer.ChildRecords.Count, 5); //sp record byte[] expected = textboxShape.SpContainer.GetChild(0).Serialize(); byte[] actual = textbox.GetEscherContainer().GetChild(0).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); expected = textboxShape.SpContainer.GetChild(2).Serialize(); actual = textbox.GetEscherContainer().GetChild(2).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); expected = textboxShape.SpContainer.GetChild(3).Serialize(); actual = textbox.GetEscherContainer().GetChild(3).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); expected = textboxShape.SpContainer.GetChild(4).Serialize(); actual = textbox.GetEscherContainer().GetChild(4).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); ObjRecord obj = textbox.GetObjRecord(); ObjRecord objShape = textboxShape.ObjRecord; expected = obj.Serialize(); actual = objShape.Serialize(); TextObjectRecord tor = textbox.GetTextObjectRecord(); TextObjectRecord torShape = textboxShape.TextObjectRecord; expected = tor.Serialize(); actual = torShape.Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); }
public void Test4BytePadding() { // actual data from file saved by Excel 2007 byte[] data = HexRead.ReadFromString("" + "15 00 12 00 1E 00 01 00 11 60 B4 6D 3C 01 C4 06 " + "49 06 00 00 00 00 00 00 00 00 00 00"); // this data seems to have 2 extra bytes of padding more than usual // the total may have been padded to the nearest quad-byte length RecordInputStream in1 = TestcaseRecordInputStream.Create(ObjRecord.sid, data); // check read OK ObjRecord record = new ObjRecord(in1); // check that it re-serializes to the same data byte[] ser = record.Serialize(); TestcaseRecordInputStream.ConfirmRecordEncoding(ObjRecord.sid, data, ser); }
public void TestResultEqualsToAbstractShape() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sh = wb.CreateSheet() as HSSFSheet; HSSFPatriarch patriarch = sh.CreateDrawingPatriarch() as HSSFPatriarch; 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.ShapeId = (1024); Assert.AreEqual(polygon.GetEscherContainer().ChildRecords.Count, 4); Assert.AreEqual(polygonShape.SpContainer.ChildRecords.Count, 4); //sp record byte[] expected = polygonShape.SpContainer.GetChild(0).Serialize(); byte[] actual = polygon.GetEscherContainer().GetChild(0).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); expected = polygonShape.SpContainer.GetChild(2).Serialize(); actual = polygon.GetEscherContainer().GetChild(2).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); expected = polygonShape.SpContainer.GetChild(3).Serialize(); actual = polygon.GetEscherContainer().GetChild(3).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); ObjRecord obj = polygon.GetObjRecord(); ObjRecord objShape = polygonShape.ObjRecord; expected = obj.Serialize(); actual = objShape.Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); }
public void TestResultEqualsToAbstractShape() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sh = wb.CreateSheet() as HSSFSheet; HSSFPatriarch patriarch = sh.CreateDrawingPatriarch() as HSSFPatriarch; HSSFPolygon polygon = patriarch.CreatePolygon(new HSSFClientAnchor()); polygon.SetPolygonDrawArea(100, 100); polygon.SetPoints(new int[] { 0, 90, 50 }, new int[] { 5, 5, 44 }); polygon.ShapeId = (1024); Assert.AreEqual(polygon.GetEscherContainer().ChildRecords.Count, 4); //sp record byte[] expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAGNi4PrAwQAELEDMxcAAAAU6ZlwQAAAA"); byte[] actual = polygon.GetEscherContainer().GetChild(0).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAGNgEPggxIANAABK4+laGgAAAA=="); actual = polygon.GetEscherContainer().GetChild(2).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAGNgEPzAAAQACl6c5QgAAAA="); actual = polygon.GetEscherContainer().GetChild(3).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); ObjRecord obj = polygon.GetObjRecord(); expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAItlkGIQZRBikGNgYBBMYEADAOAV/ZkeAAAA"); actual = obj.Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); wb.Close(); }
public void TestWayTooMuchPAdding_bug46545() { byte[] data = HexRead.ReadFromString("" + "15 00 12 00 14 00 13 00 01 21 00 00 00" + "00 98 0B 5B 09 00 00 00 00 0C 00 14 00 00 00 00 00 00 00 00" + "00 00 00 01 00 01 00 00 00 10 00 00 00 " // ftLbs + "13 00 EE 1F 00 00 " + "01 00 00 00 01 06 00 00 02 00 08 00 75 00 " // ftEnd + "00 00 00 00" ); int LBS_START_POS = 0x002E; int WRONG_LBS_SIZE = 0x1FEE; Assert.AreEqual(0x0013, LittleEndian.GetShort(data, LBS_START_POS + 0)); Assert.AreEqual(WRONG_LBS_SIZE, LittleEndian.GetShort(data, LBS_START_POS + 2)); int wrongTotalSize = LBS_START_POS + 4 + WRONG_LBS_SIZE; byte[] wrongData = new byte[wrongTotalSize]; Array.Copy(data, 0, wrongData, 0, data.Length); // wrongData has the ObjRecord data as would have been written by v3.1 RecordInputStream in1 = TestcaseRecordInputStream.Create(ObjRecord.sid, wrongData); ObjRecord or; try { or = new ObjRecord(in1); } catch (RecordFormatException e) { if (e.Message.StartsWith("Leftover 8154 bytes in subrecord data")) { throw new AssertionException("Identified bug 46545"); } throw e; } // make sure POI properly tRuncates the ObjRecord data byte[] data2 = or.Serialize(); TestcaseRecordInputStream.ConfirmRecordEncoding(ObjRecord.sid, data, data2); }
public void TestResultEqualsToNonExistingAbstractShape() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sh = wb.CreateSheet() as HSSFSheet; HSSFPatriarch patriarch = sh.CreateDrawingPatriarch() as HSSFPatriarch; HSSFTextbox textbox = patriarch.CreateTextbox(new HSSFClientAnchor()) as HSSFTextbox; Assert.AreEqual(textbox.GetEscherContainer().ChildRecords.Count, 5); //sp record byte[] expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAFvEw/WBg4GBgZEFSHAxMAAA9gX7nhAAAAA="); byte[] actual = textbox.GetEscherContainer().GetChild(0).Serialize(); Assert.AreEqual(expected.Length, actual.Length); //assertArrayEquals(expected, actual) CollectionAssert.AreEqual(expected, actual); expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAGNgEPggxIANAABK4+laGgAAAA=="); actual = textbox.GetEscherContainer().GetChild(2).Serialize(); Assert.AreEqual(expected.Length, actual.Length); CollectionAssert.AreEqual(expected, actual); expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAGNgEPzAAAQACl6c5QgAAAA="); actual = textbox.GetEscherContainer().GetChild(3).Serialize(); Assert.AreEqual(expected.Length, actual.Length); CollectionAssert.AreEqual(expected, actual); expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAGNg4P3AAAQA6pyIkQgAAAA="); actual = textbox.GetEscherContainer().GetChild(4).Serialize(); Assert.AreEqual(expected.Length, actual.Length); CollectionAssert.AreEqual(expected, actual); ObjRecord obj = textbox.GetObjRecord(); expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAItlkGIQZRBiYGNgZBBMYEADAOdCLuweAAAA"); actual = obj.Serialize(); Assert.AreEqual(expected.Length, actual.Length); CollectionAssert.AreEqual(expected, actual); TextObjectRecord tor = textbox.GetTextObjectRecord(); expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAANvGKMQgxMSABgBGi8T+FgAAAA=="); actual = tor.Serialize(); Assert.AreEqual(expected.Length, actual.Length); CollectionAssert.AreEqual(expected, actual); wb.Close(); }
public void TestResultEqualsToAbstractShape() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sh = wb.CreateSheet() as HSSFSheet; HSSFPatriarch patriarch = sh.CreateDrawingPatriarch() as HSSFPatriarch; HSSFComment comment = patriarch.CreateCellComment(new HSSFClientAnchor()) as HSSFComment; HSSFRow row = sh.CreateRow(0) as HSSFRow; HSSFCell cell = row.CreateCell(0) as HSSFCell; cell.CellComment = (comment); CommentShape commentShape = HSSFTestModelHelper.CreateCommentShape(1025, comment); Assert.AreEqual(comment.GetEscherContainer().ChildRecords.Count, 5); Assert.AreEqual(commentShape.SpContainer.ChildRecords.Count, 5); //sp record byte[] expected = commentShape.SpContainer.GetChild(0).Serialize(); byte[] actual = comment.GetEscherContainer().GetChild(0).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); expected = commentShape.SpContainer.GetChild(2).Serialize(); actual = comment.GetEscherContainer().GetChild(2).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); expected = commentShape.SpContainer.GetChild(3).Serialize(); actual = comment.GetEscherContainer().GetChild(3).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); expected = commentShape.SpContainer.GetChild(4).Serialize(); actual = comment.GetEscherContainer().GetChild(4).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); ObjRecord obj = comment.GetObjRecord(); ObjRecord objShape = commentShape.ObjRecord; expected = obj.Serialize(); actual = objShape.Serialize(); Assert.AreEqual(expected.Length, actual.Length); //assertArrayEquals(expected, actual); TextObjectRecord tor = comment.GetTextObjectRecord(); TextObjectRecord torShape = commentShape.TextObjectRecord; expected = tor.Serialize(); actual = torShape.Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); NoteRecord note = comment.NoteRecord; NoteRecord noteShape = commentShape.NoteRecord; expected = note.Serialize(); actual = noteShape.Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); wb.Close(); }
public void ResultEqualsToNonExistingAbstractShape() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sh = wb.CreateSheet() as HSSFSheet; HSSFPatriarch patriarch = sh.CreateDrawingPatriarch() as HSSFPatriarch; HSSFComment comment = patriarch.CreateCellComment(new HSSFClientAnchor()) as HSSFComment; HSSFRow row = sh.CreateRow(0) as HSSFRow; HSSFCell cell = row.CreateCell(0) as HSSFCell; cell.CellComment = (comment); Assert.AreEqual(comment.GetEscherContainer().ChildRecords.Count, 5); //sp record byte[] expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAFvEw/WBg4GBgZEFSHAxMAAA9gX7nhAAAAA="); byte[] actual = comment.GetEscherContainer().GetChild(0).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAGNgEPggxIANAABK4+laGgAAAA=="); actual = comment.GetEscherContainer().GetChild(2).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAGNgEPzAAAQACl6c5QgAAAA="); actual = comment.GetEscherContainer().GetChild(3).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAGNg4P3AAAQA6pyIkQgAAAA="); actual = comment.GetEscherContainer().GetChild(4).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); ObjRecord obj = comment.GetObjRecord(); expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAItlMGEQZRBikGRgZBF0YEACvAxiDLgBAJZsuoU4AAAA"); actual = obj.Serialize(); Assert.AreEqual(expected.Length, actual.Length); //assertArrayEquals(expected, actual); TextObjectRecord tor = comment.GetTextObjectRecord(); expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAANvGKMQgxMSABgBGi8T+FgAAAA=="); actual = tor.Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); NoteRecord note = comment.NoteRecord; expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAJNh4GGAAEYWEAkAS0KXuRAAAAA="); actual = note.Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); wb.Close(); }