public void TestStore() { CellRangeAddress cref = new CellRangeAddress(0, 0, 0, 0); byte[] recordBytes; //ByteArrayOutputStream baos = new ByteArrayOutputStream(); MemoryStream baos = new MemoryStream(); LittleEndianOutputStream output = new LittleEndianOutputStream(baos); try { // With nothing set cref.Serialize(output); recordBytes = baos.ToArray(); Assert.AreEqual(recordBytes.Length, data.Length); for (int i = 0; i < data.Length; i++) { Assert.AreEqual(0, recordBytes[i], "At offset " + i); } // Now set the flags cref.FirstRow = ((short)2); cref.LastRow = ((short)4); cref.FirstColumn = ((short)0); cref.LastColumn = ((short)3); // Re-test //baos.reset(); baos.Seek(0, SeekOrigin.Begin); cref.Serialize(output); recordBytes = baos.ToArray(); Assert.AreEqual(recordBytes.Length, data.Length); for (int i = 0; i < data.Length; i++) { Assert.AreEqual(data[i], recordBytes[i], "At offset " + i); } } finally { //output.Close(); } }
public void TestRead() { MemoryStream baos = new MemoryStream(); ILittleEndianOutput leo = new LittleEndianOutputStream(baos); leo.WriteInt(12345678); leo.WriteShort(12345); leo.WriteByte(123); leo.WriteShort(40000); leo.WriteByte(200); leo.WriteLong(1234567890123456789L); leo.WriteDouble(123.456); ILittleEndianInput lei = new LittleEndianInputStream(new MemoryStream(baos.ToArray())); Assert.AreEqual(12345678, lei.ReadInt()); Assert.AreEqual(12345, lei.ReadShort()); Assert.AreEqual(123, lei.ReadByte()); Assert.AreEqual(40000, lei.ReadUShort()); Assert.AreEqual(200, lei.ReadUByte()); Assert.AreEqual(1234567890123456789L, lei.ReadLong()); Assert.AreEqual(123.456, lei.ReadDouble(), 0.0); }
/** * Have the contents printer out into an OutputStream, used when writing a * file back out to disk (Normally, atom classes will keep their bytes * around, but non atom classes will just request the bytes from their * children, then chuck on their header and return) */ public void WriteOut(Stream out1) { byte[] intbuf = new byte[LittleEndianConsts.INT_SIZE]; byte[] shortbuf = new byte[LittleEndianConsts.SHORT_SIZE]; byte[] zerobuf = { 0, 0, 0, 0 }; LittleEndianOutputStream leosOut = new LittleEndianOutputStream(out1); switch (mode) { case EncodingMode.parsed: { MemoryStream bos = new MemoryStream(); LittleEndianOutputStream leos = new LittleEndianOutputStream(bos); // total size, will be determined later .. leos.WriteShort(Flags1); leos.Write(Encoding.GetEncoding(ISO1).GetBytes(Label)); leos.WriteByte(0); leos.Write(Encoding.GetEncoding(ISO1).GetBytes(FileName)); leos.WriteByte(0); leos.WriteShort(Flags2); leos.WriteShort(Unknown1); leos.WriteInt(Command.Length + 1); leos.Write(Encoding.GetEncoding(ISO1).GetBytes(Command)); leos.WriteByte(0); leos.WriteInt(DataSize); leos.Write(DataBuffer); leos.WriteShort(Flags3); //leos.Close(); // satisfy compiler ... leosOut.WriteInt((int)bos.Length); // total size bos.WriteTo(out1); break; } case EncodingMode.compact: leosOut.WriteInt(DataSize + LittleEndianConsts.SHORT_SIZE); leosOut.WriteShort(Flags1); out1.Write(DataBuffer, 0, DataBuffer.Length); break; default: case EncodingMode.unparsed: leosOut.WriteInt(DataSize); out1.Write(DataBuffer, 0, DataBuffer.Length); break; } }
private void TestReadWrite(byte[] data, String message) { RecordInputStream is1 = TestcaseRecordInputStream.Create(81, data); DConRefRecord d = new DConRefRecord(is1); MemoryStream bos = new MemoryStream(data.Length); LittleEndianOutputStream o = new LittleEndianOutputStream(bos); d.Serialize(o); o.Flush(); Assert.IsTrue(Arrays.Equals(data, bos.ToArray()), message); }
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); }
public void TestFormatRun() { UnicodeString.FormatRun fr = new UnicodeString.FormatRun((short)4, (short)0x15c); Assert.AreEqual(4, fr.CharacterPos); Assert.AreEqual(0x15c, fr.FontIndex); MemoryStream baos = new MemoryStream(); LittleEndianOutputStream out1 = new LittleEndianOutputStream(baos); fr.Serialize(out1); byte[] b = baos.ToArray(); Assert.AreEqual(4, b.Length); Assert.AreEqual(4, b[0]); Assert.AreEqual(0, b[1]); Assert.AreEqual(0x5c, b[2]); Assert.AreEqual(0x01, b[3]); LittleEndianInputStream inp = new LittleEndianInputStream( new MemoryStream(b) ); fr = new UnicodeString.FormatRun(inp); Assert.AreEqual(4, fr.CharacterPos); Assert.AreEqual(0x15c, fr.FontIndex); }