public void TestCreate() { EmbeddedObjectRefSubRecord record1 = new EmbeddedObjectRefSubRecord(); byte[] ser = record1.Serialize(); RecordInputStream in2 = new RecordInputStream(new MemoryStream(ser)); in2.NextRecord(); EmbeddedObjectRefSubRecord record2 = new EmbeddedObjectRefSubRecord(in2, ser.Length - 4); Assert.AreEqual(record1.OLEClassName, record2.OLEClassName); Assert.AreEqual(record1.StreamId, record2.StreamId); byte[] ser2 = record1.Serialize(); Assert.IsTrue(Arrays.Equals(ser, ser2)); }
public void TestStore() { byte[] src = HexRead.ReadFromString(data1); RecordInputStream in1 = TestcaseRecordInputStream.Create(EmbeddedObjectRefSubRecord.sid, src); EmbeddedObjectRefSubRecord record1 = new EmbeddedObjectRefSubRecord(in1, src.Length); byte[] ser = record1.Serialize(); RecordInputStream in2 = TestcaseRecordInputStream.Create(ser); EmbeddedObjectRefSubRecord record2 = new EmbeddedObjectRefSubRecord(in2, src.Length - 4); ConfirmData(src, ser); Assert.AreEqual(record1.OLEClassName, record2.OLEClassName); byte[] ser2 = record1.Serialize(); Assert.IsTrue(Arrays.Equals(ser, ser2)); }
public void TestCameraTool_bug45912() { /** * taken from ftPictFmla sub-record in attachment 22645 (offset 0x40AB). */ byte[] data45912 = hr( "12 00 0B 00 F8 02 88 04 3B 00 " + "00 00 00 01 00 00 00 01 " + "00 00"); RecordInputStream in1 = TestcaseRecordInputStream.Create(EORSR_SID, data45912); EmbeddedObjectRefSubRecord rec = new EmbeddedObjectRefSubRecord(in1, data45912.Length); byte[] ser2 = rec.Serialize(); ConfirmData(data45912, ser2); }
public void TestVisioDrawing_bug46199() { /** * taken from ftPictFmla sub-record in attachment 22860 (stream offset 0x768F).<br/> * Note that the since the string length is zero, there is no unicode flag byte */ byte[] data46199 = hr( "0E 00 " + "05 00 " + "28 25 A3 01 " + "02 6C D1 34 02 " + "03 00 00 " + "0F CB E8 00"); RecordInputStream in1 = TestcaseRecordInputStream.Create(EORSR_SID, data46199); EmbeddedObjectRefSubRecord rec; try { rec = new EmbeddedObjectRefSubRecord(in1, data46199.Length); } catch (RecordFormatException e) { if (e.Message.Equals("Not enough data (3) to read requested (4) bytes")) { throw new AssertionException("Identified bug 22860"); } throw e; } byte[] ser2 = rec.Serialize(); TestcaseRecordInputStream.ConfirmRecordEncoding(EORSR_SID, data46199, ser2); }
private static void ConfirmRead(byte[] data, int i) { RecordInputStream in1 = TestcaseRecordInputStream.Create(EORSR_SID, data); EmbeddedObjectRefSubRecord rec = new EmbeddedObjectRefSubRecord(in1, data.Length); byte[] ser2 = rec.Serialize(); TestcaseRecordInputStream.ConfirmRecordEncoding("Test record " + i, EORSR_SID, data, ser2); }
/** * Adds a new OLE Package Shape * * @param anchor the client anchor describes how this picture is * attached to the sheet. * @param storageId the storageId returned by {@Link HSSFWorkbook.AddOlePackage} * @param pictureIndex the index of the picture (used as preview image) in the * workbook collection of pictures. * * @return newly Created shape */ public HSSFObjectData CreateObjectData(HSSFClientAnchor anchor, int storageId, int pictureIndex) { ObjRecord obj = new ObjRecord(); CommonObjectDataSubRecord ftCmo = new CommonObjectDataSubRecord(); ftCmo.ObjectType = (/*setter*/CommonObjectType.Picture); // ftCmo.ObjectId=(/*setter*/oleShape.ShapeId); ... will be Set by onCreate(...) ftCmo.IsLocked = (/*setter*/true); ftCmo.IsPrintable = (/*setter*/true); ftCmo.IsAutoFill = (/*setter*/true); ftCmo.IsAutoline = (/*setter*/true); ftCmo.Reserved1 = (/*setter*/0); ftCmo.Reserved2 = (/*setter*/0); ftCmo.Reserved3 = (/*setter*/0); obj.AddSubRecord(ftCmo); // FtCf (pictFormat) FtCfSubRecord ftCf = new FtCfSubRecord(); HSSFPictureData pictData = Sheet.Workbook.GetAllPictures()[(pictureIndex - 1)] as HSSFPictureData; switch ((PictureType)pictData.Format) { case PictureType.WMF: case PictureType.EMF: // this needs patch #49658 to be applied to actually work ftCf.Flags = (/*setter*/FtCfSubRecord.METAFILE_BIT); break; case PictureType.DIB: case PictureType.PNG: case PictureType.JPEG: case PictureType.PICT: ftCf.Flags = (/*setter*/FtCfSubRecord.BITMAP_BIT); break; } obj.AddSubRecord(ftCf); // FtPioGrbit (pictFlags) FtPioGrbitSubRecord ftPioGrbit = new FtPioGrbitSubRecord(); ftPioGrbit.SetFlagByBit(FtPioGrbitSubRecord.AUTO_PICT_BIT, true); obj.AddSubRecord(ftPioGrbit); EmbeddedObjectRefSubRecord ftPictFmla = new EmbeddedObjectRefSubRecord(); ftPictFmla.SetUnknownFormulaData(new byte[] { 2, 0, 0, 0, 0 }); ftPictFmla.OLEClassName = (/*setter*/"Paket"); ftPictFmla.SetStorageId(storageId); obj.AddSubRecord(ftPictFmla); obj.AddSubRecord(new EndSubRecord()); String entryName = "MBD" + HexDump.ToHex(storageId); DirectoryEntry oleRoot; try { DirectoryNode dn = (_sheet.Workbook as HSSFWorkbook).RootDirectory; if (dn == null) throw new FileNotFoundException(); oleRoot = (DirectoryEntry)dn.GetEntry(entryName); } catch (FileNotFoundException e) { throw new InvalidOperationException("trying to add ole shape without actually Adding data first - use HSSFWorkbook.AddOlePackage first", e); } // create picture shape, which need to be minimal modified for oleshapes HSSFPicture shape = new HSSFPicture(null, anchor); shape.PictureIndex = (/*setter*/pictureIndex); EscherContainerRecord spContainer = shape.GetEscherContainer(); EscherSpRecord spRecord = spContainer.GetChildById(EscherSpRecord.RECORD_ID) as EscherSpRecord; spRecord.Flags = (/*setter*/spRecord.Flags | EscherSpRecord.FLAG_OLESHAPE); HSSFObjectData oleShape = new HSSFObjectData(spContainer, obj, oleRoot); AddShape(oleShape); OnCreate(oleShape); return oleShape; }