public void TestSparseSampleByteStream() { const int sliverSize = 2 * 2 * 4; // uncompressed 2x2 RGBA image... worst case const int bufferSlivers = 10; BufferAllocator<byte> allocator = new BufferAllocator<byte>(sliverSize * bufferSlivers, 1, sizeof(float)); byte[] appendBuffer = new byte[sliverSize]; for (int i = 0; i < sliverSize; i++) { appendBuffer[i] = (byte)i; } SparseSampleByteStream stream = new SparseSampleByteStream(10, allocator, sliverSize); stream.Append(11, new Slice<Frame, byte>(new Buf<byte>(-9, appendBuffer), sliverSize)); // now let's get it back out Slice<Frame, byte> slice = stream.GetClosestSliver(11); HoloDebug.Assert(slice.Duration == 1); HoloDebug.Assert(slice.SliverSize == sliverSize); for (int i = 0; i < sliverSize; i++) { HoloDebug.Assert(slice[0, i] == (byte)i); } // now let's copy it to intptr byte[] target = new byte[sliverSize]; unsafe { fixed (byte* p = target) { IntPtr pp = new IntPtr(p); stream.CopyTo(11, pp); } } for (int i = 0; i < sliverSize; i++) { HoloDebug.Assert(target[i] == (byte)i); } SparseSampleByteStream stream2 = new SparseSampleByteStream(10, allocator, sliverSize); unsafe { fixed (byte* p = target) { IntPtr pp = new IntPtr(p); stream2.Append(11, pp); } } Slice<Frame, byte> slice2 = stream2.GetClosestSliver(12); HoloDebug.Assert(slice2.Duration == 1); HoloDebug.Assert(slice2.SliverSize == sliverSize); for (int i = 0; i < sliverSize; i++) { HoloDebug.Assert(slice2[0, i] == (byte)i); } // now verify looping and shutting work as expected for (int i = 0; i < appendBuffer.Length; i++) { appendBuffer[i] += (byte)appendBuffer.Length; } stream2.Append(21, new Slice<Frame, byte>(new Buf<byte>(-10, appendBuffer), sliverSize)); Slice<Frame, byte> slice3 = stream2.GetClosestSliver(12); HoloDebug.Assert(slice3.Duration == 1); HoloDebug.Assert(slice3.SliverSize == sliverSize); HoloDebug.Assert(slice3[0, 0] == (byte)0); Slice<Frame, byte> slice4 = stream2.GetClosestSliver(22); HoloDebug.Assert(slice4.Duration == 1); HoloDebug.Assert(slice4.SliverSize == sliverSize); HoloDebug.Assert(slice4[0, 0] == (byte)sliverSize); stream2.Shut((ContinuousDuration)20); // now the closest sliver to 32 should be the first sliver Slice<Frame, byte> slice5 = stream2.GetClosestSliver(32); HoloDebug.Assert(slice5.Duration == 1); HoloDebug.Assert(slice5.SliverSize == sliverSize); HoloDebug.Assert(slice5[0, 0] == (byte)0); // and 42, the second Slice<Frame, byte> slice6 = stream2.GetClosestSliver(42); HoloDebug.Assert(slice6.Duration == 1); HoloDebug.Assert(slice6.SliverSize == sliverSize); HoloDebug.Assert(slice6[0, 0] == (byte)sliverSize); }