Exemplo n.º 1
0
        public void TestSerialize()
        {
            // Check under max record size
            DrawingGroupRecord r = new DrawingGroupRecord();

            byte[] rawData = new byte[100];
            rawData[0]  = 100;
            rawData[99] = (byte)200;
            r.RawData   = (rawData);
            byte[] buffer = new byte[r.RecordSize];
            int    size   = r.Serialize(0, buffer);

            Assert.AreEqual(104, size);
            Assert.AreEqual("[EB, 00, 64, 00, 64, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, C8]", HexDump.ToHex(buffer));

            // check at max record size
            rawData   = new byte[MAX_DATA_SIZE];
            r.RawData = (rawData);
            buffer    = new byte[r.RecordSize];
            size      = r.Serialize(0, buffer);
            Assert.AreEqual(MAX_RECORD_SIZE, size);

            // check over max record size
            rawData = new byte[MAX_DATA_SIZE + 1];
            rawData[rawData.Length - 1] = (byte)255;
            r.RawData = (rawData);
            buffer    = new byte[r.RecordSize];
            size      = r.Serialize(0, buffer);
            Assert.AreEqual(MAX_RECORD_SIZE + 5, size);
            Assert.AreEqual("[EB, 00, 20, 20]", HexDump.ToHex(cut(buffer, 0, 4)));
            Assert.AreEqual("[00, EB, 00, 01, 00, FF]", HexDump.ToHex(cut(buffer, MAX_RECORD_SIZE - 1, MAX_RECORD_SIZE + 5)));

            // check continue record
            rawData = new byte[MAX_DATA_SIZE * 2 + 1];
            rawData[rawData.Length - 1] = (byte)255;
            r.RawData = (rawData);
            buffer    = new byte[r.RecordSize];
            size      = r.Serialize(0, buffer);
            Assert.AreEqual(MAX_RECORD_SIZE * 2 + 5, size);
            Assert.AreEqual(MAX_RECORD_SIZE * 2 + 5, r.RecordSize);
            Assert.AreEqual("[EB, 00, 20, 20]", HexDump.ToHex(cut(buffer, 0, 4)));
            Assert.AreEqual("[EB, 00, 20, 20]", HexDump.ToHex(cut(buffer, MAX_RECORD_SIZE, MAX_RECORD_SIZE + 4)));
            Assert.AreEqual("[3C, 00, 01, 00, FF]", HexDump.ToHex(cut(buffer, MAX_RECORD_SIZE * 2, MAX_RECORD_SIZE * 2 + 5)));

            // check continue record
            rawData   = new byte[664532];
            r.RawData = (rawData);
            buffer    = new byte[r.RecordSize];
            size      = r.Serialize(0, buffer);
            Assert.AreEqual(664856, size);
            Assert.AreEqual(664856, r.RecordSize);
        }
Exemplo n.º 2
0
        public RecordTreeNode(Record record)
        {
            if (record is ObjRecord)
            {
                ObjRecord or      = (ObjRecord)record;
                IList     subrecs = or.SubRecords;
                foreach (SubRecord sr in subrecs)
                {
                    this.Nodes.Add(new SubRecordTreeNode(sr));
                }
                this.ImageKey         = "Folder";
                this.SelectedImageKey = "Folder";
            }
            else if (record is SSTRecord)
            {
                IEnumerator strings = ((SSTRecord)record).GetStrings();

                this.ImageKey         = "Folder";
                this.SelectedImageKey = "Folder";

                while (strings.MoveNext())
                {
                    this.Nodes.Add(new UnicodeStringTreeNode((UnicodeString)strings.Current));
                }
            }
            else if (record is DrawingGroupRecord)
            {
                this.ImageKey         = "Folder";
                this.SelectedImageKey = "Folder";

                DrawingGroupRecord dgr = (DrawingGroupRecord)record;

                for (int i = 0; i < dgr.EscherRecords.Count; i++)
                {
                    this.Nodes.Add(new EscherRecordTreeNode((NPOI.DDF.EscherRecord)dgr.EscherRecords[i]));
                }
            }
            else
            {
                this.ImageKey = "Binary";
            }
            if (record is UnknownRecord)
            {
                this.Text = UnknownRecord.GetBiffName(record.Sid) + "*";
            }
            else
            {
                this.Text = record.GetType().Name;
            }
            this.Record = record;
        }
Exemplo n.º 3
0
        public void TestGrossSizeFromDataSize()
        {
            for (int i = 0; i < MAX_RECORD_SIZE * 4; i += 11)
            {
                //System.out.print( "data size = " + i + ", gross size = " + DrawingGroupRecord.GrossSizeFromDataSize( i ) );
                //System.out.println( "  Diff: " + (DrawingGroupRecord.GrossSizeFromDataSize( i ) - i) );
            }

            Assert.AreEqual(4, DrawingGroupRecord.GrossSizeFromDataSize(0));
            Assert.AreEqual(5, DrawingGroupRecord.GrossSizeFromDataSize(1));
            Assert.AreEqual(MAX_RECORD_SIZE, DrawingGroupRecord.GrossSizeFromDataSize(MAX_DATA_SIZE));
            Assert.AreEqual(MAX_RECORD_SIZE + 5, DrawingGroupRecord.GrossSizeFromDataSize(MAX_DATA_SIZE + 1));
            Assert.AreEqual(MAX_RECORD_SIZE * 2, DrawingGroupRecord.GrossSizeFromDataSize(MAX_DATA_SIZE * 2));
            Assert.AreEqual(MAX_RECORD_SIZE * 2 + 5, DrawingGroupRecord.GrossSizeFromDataSize(MAX_DATA_SIZE * 2 + 1));
        }
Exemplo n.º 4
0
        public void TestRecordSize()
        {
            DrawingGroupRecord r = new DrawingGroupRecord();

            Assert.AreEqual(4, r.RecordSize);

            EscherSpRecord sp = new EscherSpRecord();

            sp.RecordId = (EscherSpRecord.RECORD_ID);
            sp.Options  = ((short)0x1111);
            sp.Flags    = (-1);
            sp.ShapeId  = (-1);
            EscherContainerRecord dggContainer = new EscherContainerRecord();

            dggContainer.Options  = ((short)0x000F);
            dggContainer.RecordId = unchecked ((short)0xF000);
            dggContainer.AddChildRecord(sp);

            r.AddEscherRecord(dggContainer);
            Assert.AreEqual(28, r.RecordSize);

            byte[] data = new byte[28];
            int    size = r.Serialize(0, data);

            Assert.AreEqual("[EB, 00, 18, 00, 0F, 00, 00, F0, 10, 00, 00, 00, 11, 11, 0A, F0, 08, 00, 00, 00, FF, FF, FF, FF, FF, FF, FF, FF]", HexDump.ToHex(data));
            Assert.AreEqual(28, size);

            Assert.AreEqual(24, dggContainer.RecordSize);


            r         = new DrawingGroupRecord();
            r.RawData = (new byte[MAX_DATA_SIZE]);
            Assert.AreEqual(MAX_RECORD_SIZE, r.RecordSize);
            r.RawData = (new byte[MAX_DATA_SIZE + 1]);
            Assert.AreEqual(MAX_RECORD_SIZE + 5, r.RecordSize);
            r.RawData = (new byte[MAX_DATA_SIZE * 2]);
            Assert.AreEqual(MAX_RECORD_SIZE * 2, r.RecordSize);
            r.RawData = (new byte[MAX_DATA_SIZE * 2 + 1]);
            Assert.AreEqual(MAX_RECORD_SIZE * 2 + 5, r.RecordSize);
        }