Beispiel #1
0
        public void TestCorruptExtRstDetection()
        {
            byte[] data = new byte[] {
                0x79, 0x79, 0x11, 0x11,
                0x22, 0x22, 0x33, 0x33,
            };
            Assert.AreEqual(8, data.Length);

            LittleEndianInputStream inp = new LittleEndianInputStream(
                new MemoryStream(data)
                );

            UnicodeString.ExtRst ext = new UnicodeString.ExtRst(inp, data.Length);

            // Will be empty
            Assert.AreEqual(ext, new UnicodeString.ExtRst());

            // If written, will be the usual size
            Assert.AreEqual(10, ext.DataSize); // Excludes 4 byte header

            // Is empty
            Assert.AreEqual(0, ext.NumberOfRuns);
            Assert.AreEqual(0, ext.FormattingOptions);
            Assert.AreEqual(0, ext.FormattingFontIndex);
            Assert.AreEqual("", ext.PhoneticText);
            Assert.AreEqual(0, ext.PhRuns.Length);
        }
Beispiel #2
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());
        }
Beispiel #3
0
        public void TestExtRstFromData()
        {
            byte[] data = new byte[] {
                01, 00, 0x0C, 00,
                00, 00, 0x37, 00,
                00, 00,
                00, 00, 00, 00,
                00, 00 // Cruft at the end, as found from real files
            };
            Assert.AreEqual(16, data.Length);

            LittleEndianInputStream inp = new LittleEndianInputStream(
                new MemoryStream(data)
                );

            UnicodeString.ExtRst ext = new UnicodeString.ExtRst(inp, data.Length);
            Assert.AreEqual(0x0c, ext.DataSize); // Excludes 4 byte header

            Assert.AreEqual(0, ext.NumberOfRuns);
            Assert.AreEqual(0x37, ext.FormattingOptions);
            Assert.AreEqual(0, ext.FormattingFontIndex);
            Assert.AreEqual("", ext.PhoneticText);
            Assert.AreEqual(0, ext.PhRuns.Length);
        }
        public void TestCorruptExtRstDetection()
        {
            byte[] data = new byte[] {
             0x79, 0x79, 0x11, 0x11, 
             0x22, 0x22, 0x33, 0x33, 
       };
            Assert.AreEqual(8, data.Length);

            LittleEndianInputStream inp = new LittleEndianInputStream(
                  new MemoryStream(data)
            );
            UnicodeString.ExtRst ext = new UnicodeString.ExtRst(inp, data.Length);

            // Will be empty
            Assert.AreEqual(ext, new UnicodeString.ExtRst());

            // If written, will be the usual size
            Assert.AreEqual(10, ext.DataSize); // Excludes 4 byte header

            // Is empty
            Assert.AreEqual(0, ext.NumberOfRuns);
            Assert.AreEqual(0, ext.FormattingOptions);
            Assert.AreEqual(0, ext.FormattingFontIndex);
            Assert.AreEqual("", ext.PhoneticText);
            Assert.AreEqual(0, ext.PhRuns.Length);
        }
        public void TestExtRstFromData()
        {
            byte[] data = new byte[] {
             01, 00, 0x0C, 00, 
             00, 00, 0x37, 00, 
             00, 00, 
             00, 00, 00, 00, 
             00, 00 // Cruft at the end, as found from real files
       };
            Assert.AreEqual(16, data.Length);

            LittleEndianInputStream inp = new LittleEndianInputStream(
                  new MemoryStream(data)
            );
            UnicodeString.ExtRst ext = new UnicodeString.ExtRst(inp, data.Length);
            Assert.AreEqual(0x0c, ext.DataSize); // Excludes 4 byte header

            Assert.AreEqual(0, ext.NumberOfRuns);
            Assert.AreEqual(0x37, ext.FormattingOptions);
            Assert.AreEqual(0, ext.FormattingFontIndex);
            Assert.AreEqual("", ext.PhoneticText);
            Assert.AreEqual(0, ext.PhRuns.Length);
        }
        public void TestExtRstFromEmpty()
        {
            UnicodeString.ExtRst ext = new UnicodeString.ExtRst();

            Assert.AreEqual(0, ext.NumberOfRuns);
            Assert.AreEqual(0, ext.FormattingFontIndex);
            Assert.AreEqual(0, ext.FormattingOptions);
            Assert.AreEqual("", ext.PhoneticText);
            Assert.AreEqual(0, ext.PhRuns.Length);
            Assert.AreEqual(10, ext.DataSize); // Excludes 4 byte header

            MemoryStream baos = new MemoryStream();
            LittleEndianOutputStream out1 = new LittleEndianOutputStream(baos);
            ContinuableRecordOutput cout = new ContinuableRecordOutput(out1, 0xffff);

            ext.Serialize(cout);
            cout.WriteContinue();

            byte[] b = baos.ToArray();
            Assert.AreEqual(20, b.Length);

            // First 4 bytes from the outputstream
            Assert.AreEqual(-1, (sbyte)b[0]);
            Assert.AreEqual(-1, (sbyte)b[1]);
            Assert.AreEqual(14, b[2]);
            Assert.AreEqual(00, b[3]);

            // Reserved
            Assert.AreEqual(1, b[4]);
            Assert.AreEqual(0, b[5]);
            // Data size
            Assert.AreEqual(10, b[6]);
            Assert.AreEqual(00, b[7]);
            // Font*2
            Assert.AreEqual(0, b[8]);
            Assert.AreEqual(0, b[9]);
            Assert.AreEqual(0, b[10]);
            Assert.AreEqual(0, b[11]);
            // 0 Runs
            Assert.AreEqual(0, b[12]);
            Assert.AreEqual(0, b[13]);
            // Size=0, *2
            Assert.AreEqual(0, b[14]);
            Assert.AreEqual(0, b[15]);
            Assert.AreEqual(0, b[16]);
            Assert.AreEqual(0, b[17]);

            // Last 2 bytes from the outputstream
            Assert.AreEqual(ContinueRecord.sid, b[18]);
            Assert.AreEqual(0, b[19]);


            // Load in again and re-test
            byte[] data = new byte[14];
            Array.Copy(b, 4, data, 0, data.Length);
            LittleEndianInputStream inp = new LittleEndianInputStream(
                  new MemoryStream(data)
            );
            ext = new UnicodeString.ExtRst(inp, data.Length);

            Assert.AreEqual(0, ext.NumberOfRuns);
            Assert.AreEqual(0, ext.FormattingFontIndex);
            Assert.AreEqual(0, ext.FormattingOptions);
            Assert.AreEqual("", ext.PhoneticText);
            Assert.AreEqual(0, ext.PhRuns.Length);
        }
Beispiel #7
0
        public void TestExtRstFromEmpty()
        {
            UnicodeString.ExtRst ext = new UnicodeString.ExtRst();

            Assert.AreEqual(0, ext.NumberOfRuns);
            Assert.AreEqual(0, ext.FormattingFontIndex);
            Assert.AreEqual(0, ext.FormattingOptions);
            Assert.AreEqual("", ext.PhoneticText);
            Assert.AreEqual(0, ext.PhRuns.Length);
            Assert.AreEqual(10, ext.DataSize); // Excludes 4 byte header

            MemoryStream             baos = new MemoryStream();
            LittleEndianOutputStream out1 = new LittleEndianOutputStream(baos);
            ContinuableRecordOutput  cout = new ContinuableRecordOutput(out1, 0xffff);

            ext.Serialize(cout);
            cout.WriteContinue();

            byte[] b = baos.ToArray();
            Assert.AreEqual(20, b.Length);

            // First 4 bytes from the outputstream
            Assert.AreEqual(-1, (sbyte)b[0]);
            Assert.AreEqual(-1, (sbyte)b[1]);
            Assert.AreEqual(14, b[2]);
            Assert.AreEqual(00, b[3]);

            // Reserved
            Assert.AreEqual(1, b[4]);
            Assert.AreEqual(0, b[5]);
            // Data size
            Assert.AreEqual(10, b[6]);
            Assert.AreEqual(00, b[7]);
            // Font*2
            Assert.AreEqual(0, b[8]);
            Assert.AreEqual(0, b[9]);
            Assert.AreEqual(0, b[10]);
            Assert.AreEqual(0, b[11]);
            // 0 Runs
            Assert.AreEqual(0, b[12]);
            Assert.AreEqual(0, b[13]);
            // Size=0, *2
            Assert.AreEqual(0, b[14]);
            Assert.AreEqual(0, b[15]);
            Assert.AreEqual(0, b[16]);
            Assert.AreEqual(0, b[17]);

            // Last 2 bytes from the outputstream
            Assert.AreEqual(ContinueRecord.sid, b[18]);
            Assert.AreEqual(0, b[19]);


            // Load in again and re-test
            byte[] data = new byte[14];
            Array.Copy(b, 4, data, 0, data.Length);
            LittleEndianInputStream inp = new LittleEndianInputStream(
                new MemoryStream(data)
                );

            ext = new UnicodeString.ExtRst(inp, data.Length);

            Assert.AreEqual(0, ext.NumberOfRuns);
            Assert.AreEqual(0, ext.FormattingFontIndex);
            Assert.AreEqual(0, ext.FormattingOptions);
            Assert.AreEqual("", ext.PhoneticText);
            Assert.AreEqual(0, ext.PhRuns.Length);
        }
Beispiel #8
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());
        }