示例#1
0
        public void TestExtRstEqualsAndHashCode()
        {
            byte[] buf = new byte[200];
            LittleEndianByteArrayOutputStream bos = new LittleEndianByteArrayOutputStream(buf, 0);
            String str = "\u1d02\u1d12\u1d22";

            bos.WriteShort(1);
            bos.WriteShort(5 * LittleEndianConsts.SHORT_SIZE + str.Length * 2 + 3 * LittleEndianConsts.SHORT_SIZE + 2); // data size
            bos.WriteShort(0x4711);
            bos.WriteShort(0x0815);
            bos.WriteShort(1);
            bos.WriteShort(str.Length);
            bos.WriteShort(str.Length);
            StringUtil.PutUnicodeLE(str, bos);
            bos.WriteShort(1);
            bos.WriteShort(1);
            bos.WriteShort(3);
            bos.WriteShort(42);

            LittleEndianByteArrayInputStream in1 = new LittleEndianByteArrayInputStream(buf, 0, bos.WriteIndex);

            UnicodeString.ExtRst extRst1 = new UnicodeString.ExtRst(in1, bos.WriteIndex);
            in1 = new LittleEndianByteArrayInputStream(buf, 0, bos.WriteIndex);
            UnicodeString.ExtRst extRst2 = new UnicodeString.ExtRst(in1, bos.WriteIndex);

            Assert.AreEqual(extRst1, extRst2);
            Assert.AreEqual(extRst1.GetHashCode(), extRst2.GetHashCode());
        }
示例#2
0
        private static Ptg ReadRefPtg(byte[] formulaRawBytes)
        {
            LittleEndianInput in1 = new LittleEndianByteArrayInputStream(formulaRawBytes);
            byte ptgSid           = (byte)in1.ReadByte();

            switch (ptgSid)
            {
            case AreaPtg.sid: return(new AreaPtg(in1));

            case Area3DPtg.sid: return(new Area3DPtg(in1));

            case RefPtg.sid: return(new RefPtg(in1));

            case Ref3DPtg.sid: return(new Ref3DPtg(in1));
            }
            return(null);
        }
示例#3
0
文件: NameRecord.cs 项目: zzy092/npoi
        /**
         * Constructs a Name record and Sets its fields appropriately.
         *
         * @param in the RecordInputstream to Read the record from
         */
        public NameRecord(RecordInputStream ris)
        {
            byte[]             remainder = ris.ReadAllContinuedRemainder();
            ILittleEndianInput in1       = new LittleEndianByteArrayInputStream(remainder);

            field_1_option_flag       = in1.ReadShort();
            field_2_keyboard_shortcut = (byte)in1.ReadByte();
            int field_3_length_name_text       = in1.ReadByte();
            int field_4_length_name_definition = in1.ReadShort();

            field_5_externSheetIndex_plus1 = in1.ReadShort();
            field_6_sheetNumber            = in1.ReadUShort();
            int field_7_length_custom_menu      = in1.ReadUByte();
            int field_8_length_description_text = in1.ReadUByte();
            int field_9_length_help_topic_text  = in1.ReadUByte();
            int field_10_length_status_bar_text = in1.ReadUByte();

            //store the name in byte form if it's a built-in name
            field_11_nameIsMultibyte = (in1.ReadByte() != 0);
            if (IsBuiltInName)
            {
                field_12_built_in_code = (byte)in1.ReadByte();
            }
            else
            {
                if (field_11_nameIsMultibyte)
                {
                    field_12_name_text = StringUtil.ReadUnicodeLE(in1, field_3_length_name_text);
                }
                else
                {
                    field_12_name_text = StringUtil.ReadCompressedUnicode(in1, field_3_length_name_text);
                }
            }
            int nBytesAvailable = in1.Available() - (field_7_length_custom_menu
                                                     + field_8_length_description_text + field_9_length_help_topic_text + field_10_length_status_bar_text);

            field_13_name_definition = SSFormula.Formula.Read(field_4_length_name_definition, in1, nBytesAvailable);

            //Who says that this can only ever be compressed unicode???
            field_14_custom_menu_text = StringUtil.ReadCompressedUnicode(in1, field_7_length_custom_menu);
            field_15_description_text = StringUtil.ReadCompressedUnicode(in1, field_8_length_description_text);
            field_16_help_topic_text  = StringUtil.ReadCompressedUnicode(in1, field_9_length_help_topic_text);
            field_17_status_bar_text  = StringUtil.ReadCompressedUnicode(in1, field_10_length_status_bar_text);
        }
        public void TestContinue()
        {
            int           MAX_BIFF_DATA = RecordInputStream.MAX_RECORD_DATA_SIZE;
            int           TEXT_LEN      = MAX_BIFF_DATA + 1000; // deliberately over-size
            string        textChunk     = "ABCDEGGHIJKLMNOP";   // 16 chars
            StringBuilder sb            = new StringBuilder(16384);

            while (sb.Length < TEXT_LEN)
            {
                sb.Append(textChunk);
            }
            sb.Length = (/*setter*/ TEXT_LEN);

            StringRecord sr = new StringRecord();

            sr.String = (/*setter*/ sb.ToString());
            byte[] ser = sr.Serialize();
            Assert.AreEqual(StringRecord.sid, LittleEndian.GetUShort(ser, 0));
            if (LittleEndian.GetUShort(ser, 2) > MAX_BIFF_DATA)
            {
                throw new AssertionException(
                          "StringRecord should have been split with a continue record");
            }
            // Confirm expected size of first record, and ushort strLen.
            Assert.AreEqual(MAX_BIFF_DATA, LittleEndian.GetUShort(ser, 2));
            Assert.AreEqual(TEXT_LEN, LittleEndian.GetUShort(ser, 4));

            // Confirm first few bytes of ContinueRecord
            ILittleEndianInput crIn = new LittleEndianByteArrayInputStream(ser, (MAX_BIFF_DATA + 4));
            int nCharsInFirstRec    = MAX_BIFF_DATA - (2 + 1); // strLen, optionFlags
            int nCharsInSecondRec   = TEXT_LEN - nCharsInFirstRec;

            Assert.AreEqual(ContinueRecord.sid, crIn.ReadUShort());
            Assert.AreEqual(1 + nCharsInSecondRec, crIn.ReadUShort());
            Assert.AreEqual(0, crIn.ReadUByte());
            Assert.AreEqual('N', crIn.ReadUByte());
            Assert.AreEqual('O', crIn.ReadUByte());

            // re-read and make sure string value is the same
            RecordInputStream in1 = TestcaseRecordInputStream.Create(ser);
            StringRecord      sr2 = new StringRecord(in1);

            Assert.AreEqual(sb.ToString(), sr2.String);
        }
        public void TestReadFully()
        {
            byte[]             srcBuf = HexRead.ReadFromString("99 88 77 66 55 44 33");
            ILittleEndianInput lei    = new LittleEndianByteArrayInputStream(srcBuf);

            // do Initial read to increment the read index beyond zero
            Assert.AreEqual(0x8899, lei.ReadUShort());

            byte[] actBuf = new byte[4];
            lei.ReadFully(actBuf);

            if (actBuf[0] == 0x00 && srcBuf[0] == 0x77 && srcBuf[3] == 0x44)
            {
                throw new AssertionException("Identified bug in ReadFully() - source buffer was modified");
            }

            byte[] expBuf = HexRead.ReadFromString("77 66 55 44");
            Assert.IsTrue(Arrays.Equals(actBuf, expBuf));
            Assert.AreEqual(0x33, lei.ReadUByte());
            Assert.AreEqual(0, lei.Available());
        }
示例#6
0
 private static Ptg ReadRefPtg(byte[] formulaRawBytes)
 {
     LittleEndianInput in1 = new LittleEndianByteArrayInputStream(formulaRawBytes);
     byte ptgSid = (byte)in1.ReadByte();
     switch (ptgSid)
     {
         case AreaPtg.sid: return new AreaPtg(in1);
         case Area3DPtg.sid: return new Area3DPtg(in1);
         case RefPtg.sid: return new RefPtg(in1);
         case Ref3DPtg.sid: return new Ref3DPtg(in1);
     }
     return null;
 }