public void TestStore() { StringRecord record = new StringRecord(); record.String = (/*setter*/"Fahrzeugtyp"); byte[] recordBytes = record.Serialize(); Assert.AreEqual(recordBytes.Length - 4, data.Length); for (int i = 0; i < data.Length; i++) Assert.AreEqual(data[i], recordBytes[i + 4], "At offset " + i); }
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); }