public void TestReading() { int pointCount = 0; var reading = new TsscDecoder(); reading.SetBuffer(new byte[10], 5, 0); ushort id; long timestamp; uint quality; float value; while (reading.TryGetMeasurement(out id, out timestamp, out quality, out value)) { throw new ArgumentOutOfRangeException(); } System.Console.WriteLine(pointCount); }
public void TestReading1() { //Just adds metadata var r = new Randomizer(3); byte[] buffer = new byte[65536]; int endPosition; { var comp = new TsscEncoder(); comp.SetBuffer(buffer, 0, 65530); for (int x = 0; x < 1000; x++) { if (!comp.TryAddMeasurement(r.GetUInt16(), r.GetDate(), r.GetUInt16(), r.GetUInt16())) { throw new Exception(); } } endPosition = comp.FinishBlock(); } r.Reset(); { ushort id; long timestamp; uint quality; float value; var reading = new TsscDecoder(); reading.SetBuffer(buffer, 0, endPosition); for (int x = 0; x < 1000; x++) { if (!reading.TryGetMeasurement(out id, out timestamp, out quality, out value)) { throw new ArgumentOutOfRangeException(); } if (id != r.GetUInt16()) { throw new Exception(); } if (timestamp != r.GetDate()) { throw new Exception(); } if (quality != r.GetUInt16()) { throw new Exception(); } if (value != r.GetUInt16()) { throw new Exception(); } } if (reading.TryGetMeasurement(out id, out timestamp, out quality, out value)) { throw new ArgumentOutOfRangeException(); } if (reading.TryGetMeasurement(out id, out timestamp, out quality, out value)) { throw new ArgumentOutOfRangeException(); } } }
private static void TestEncoding(TsscEncoder encoder, TsscDecoder decoder, TsscEncoder encoder2, byte[] writeBuffer, byte randomValue, OrigReader reader2, ushort idOld, long timestampOld, uint qualityOld, float valueOld) { ushort id2; long timestamp2; uint quality2; float value2; ushort id3 = 0; long timestamp3 = 0; uint quality3 = 0; float value3 = 0; int flushPosition; flushPosition = encoder.FinishBlock(); Array.Clear(writeBuffer, flushPosition, writeBuffer.Length - flushPosition); byte[] writeBuffer2 = new byte[writeBuffer.Length]; encoder2.SetBuffer(writeBuffer2, randomValue, writeBuffer2.Length - randomValue); decoder.SetBuffer(writeBuffer, randomValue, flushPosition - randomValue); while (decoder.TryGetMeasurement(out id2, out timestamp2, out quality2, out value2)) { if (!encoder2.TryAddMeasurement(id2, timestamp2, quality2, value2)) { throw new Exception(); } if (!reader2.ReadNextMeasurement(out id3, out timestamp3, out quality3, out value3)) { throw new Exception(); } if (id2 != id3) { throw new Exception(); } if (timestamp2 != timestamp3) { throw new Exception(); } if (quality2 != quality3) { throw new Exception(); } if (value2 != value3) { throw new Exception(); } } if (idOld != id3) { throw new Exception(); } if (timestampOld != timestamp3) { throw new Exception(); } if (qualityOld != quality3) { throw new Exception(); } if (valueOld != value3) { throw new Exception(); } if (flushPosition != encoder2.FinishBlock()) { throw new Exception(); } for (int x = 0; x < writeBuffer.Length; x++) { if (writeBuffer[x] != writeBuffer2[x]) { throw new Exception(); } } }