public void TestSimpleConstructor() { SSTRecord record = new SSTRecord(); Assert.AreEqual(0, record.NumStrings); Assert.AreEqual(0, record.NumUniqueStrings); Assert.AreEqual(0, record.CountStrings); byte[] output = record.Serialize(); byte[] expected = { (byte) record.Sid, (byte) ( record.Sid >> 8 ), (byte) 8, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0 }; Assert.AreEqual(expected.Length, output.Length); for (int k = 0; k < expected.Length; k++) { Assert.AreEqual(expected[k], output[k], k.ToString()); } }
public void TestHugeStrings() { SSTRecord record = new SSTRecord(); byte[][] bstrings = { new byte[9000], new byte[7433], new byte[9002], new byte[16998] }; UnicodeString[] strings = new UnicodeString[bstrings.Length]; int total_length = 0; for (int k = 0; k < bstrings.Length; k++) { Arrays.Fill(bstrings[k], (byte)('a' + k)); strings[k] = new UnicodeString(new String(ConvertByteToChar(bstrings[k]))); record.AddString(strings[k]); total_length += 3 + bstrings[k].Length; } // add overhead of SST record total_length += 8; // add overhead of broken strings total_length += 4; // add overhead of six records total_length += (6 * 4); byte[] content = new byte[record.RecordSize]; record.Serialize(0, content); Assert.AreEqual(total_length, content.Length); //Deserialize the record. RecordInputStream recStream = new RecordInputStream(new MemoryStream(content)); recStream.NextRecord(); record = new SSTRecord(recStream); Assert.AreEqual(strings.Length, record.NumStrings); Assert.AreEqual(strings.Length, record.NumUniqueStrings); Assert.AreEqual(strings.Length, record.CountStrings); for (int k = 0; k < strings.Length; k++) { Assert.AreEqual(strings[k], record.GetString(k)); } record = new SSTRecord(); bstrings[1] = new byte[bstrings[1].Length - 1]; for (int k = 0; k < bstrings.Length; k++) { if ((bstrings[k].Length % 2) == 1) { Arrays.Fill(bstrings[k], (byte)('a' + k)); strings[k] = new UnicodeString(new String(ConvertByteToChar(bstrings[k]))); } else { char[] data = new char[bstrings[k].Length / 2]; Arrays.Fill(data, (char)('\u2122' + k)); strings[k] = new UnicodeString(new String(data)); } record.AddString(strings[k]); } content = new byte[record.RecordSize]; record.Serialize(0, content); total_length--; Assert.AreEqual(total_length, content.Length); recStream = new RecordInputStream(new MemoryStream(content)); recStream.NextRecord(); record = new SSTRecord(recStream); Assert.AreEqual(strings.Length, record.NumStrings); Assert.AreEqual(strings.Length, record.NumUniqueStrings); Assert.AreEqual(strings.Length, record.CountStrings); for (int k = 0; k < strings.Length; k++) { Assert.AreEqual(strings[k], record.GetString(k)); } }
public void TestSSTRecordBug() { // create an SSTRecord and write a certain pattern of strings // to it ... then serialize it and verify the content SSTRecord record = new SSTRecord(); // the record will start with two integers, then this string // ... that will eat up 16 of the 8224 bytes that the record // can hold record.AddString(new UnicodeString("Hello")); // now we have an Additional 8208 bytes, which is an exact // multiple of 16 bytes long Testvalue = 1000000000000L; for (int k = 0; k < 2000; k++) { record.AddString(new UnicodeString((Testvalue + k).ToString())); } byte[] content = new byte[record.RecordSize]; record.Serialize(0, content); Assert.AreEqual(8224, LittleEndian.GetShort(content, 2)); Assert.AreEqual(ContinueRecord.sid, LittleEndian.GetShort(content, 8228)); Assert.AreEqual(8224, LittleEndian.GetShort(content, 8228 + 2)); Assert.AreEqual((byte)13, content[4 + 8228]); Assert.AreEqual(ContinueRecord.sid, LittleEndian.GetShort(content, 2 * 8228)); Assert.AreEqual(8224, LittleEndian.GetShort(content, 8228 * 2 + 2)); Assert.AreEqual((byte)13, content[4 + 8228 * 2]); Assert.AreEqual(ContinueRecord.sid, LittleEndian.GetShort(content, 3 * 8228)); Assert.AreEqual((byte)13, content[4 + 8228 * 3]); }
public void Test50779_2() { byte[] bytes = HexRead.ReadFromString(data_50779_2); RecordInputStream in1 = TestcaseRecordInputStream.Create(bytes); Assert.AreEqual(SSTRecord.sid, in1.Sid); SSTRecord src = new SSTRecord(in1); Assert.AreEqual(81, src.NumStrings); byte[] Serialized = src.Serialize(); in1 = TestcaseRecordInputStream.Create(Serialized); Assert.AreEqual(SSTRecord.sid, in1.Sid); SSTRecord dst = new SSTRecord(in1); Assert.AreEqual(81, dst.NumStrings); AssertAreEqual(src, dst); }