Exemplo n.º 1
0
        public void SaveCreateBufferRoundTrip()
        {
            RewindConfig config = new RewindConfig
            {
                BufferSize        = 1,
                TargetFrameLength = 10
            };
            var buff = new ZwinderBuffer(config);
            var ss   = new StateSource {
                PaddingData = new byte[500]
            };

            for (var frame = 0; frame < 2090; frame++)
            {
                ss.Frame = frame;
                buff.Capture(frame, (s) => ss.SaveStateBinary(new BinaryWriter(s)));
            }
            // states are 504 bytes large, buffer is 1048576 bytes large
            Assert.AreEqual(buff.Count, 2080);
            Assert.AreEqual(buff.GetState(0).Frame, 10);
            Assert.AreEqual(buff.GetState(2079).Frame, 2089);
            Assert.AreEqual(StateSource.GetFrameNumberInState(buff.GetState(0).GetReadStream()), 10);
            Assert.AreEqual(StateSource.GetFrameNumberInState(buff.GetState(2079).GetReadStream()), 2089);

            var ms = new MemoryStream();

            buff.SaveStateBinary(new BinaryWriter(ms));
            ms.Position = 0;
            var buff2 = ZwinderBuffer.Create(new BinaryReader(ms), config);

            Assert.AreEqual(buff.Size, buff2.Size);
            Assert.AreEqual(buff.Used, buff2.Used);
            Assert.AreEqual(buff2.Count, 2080);
            Assert.AreEqual(buff2.GetState(0).Frame, 10);
            Assert.AreEqual(buff2.GetState(2079).Frame, 2089);
            Assert.AreEqual(StateSource.GetFrameNumberInState(buff2.GetState(0).GetReadStream()), 10);
            Assert.AreEqual(StateSource.GetFrameNumberInState(buff2.GetState(2079).GetReadStream()), 2089);
        }
        public void WhatIfTheHeadStateWrapsAround()
        {
            var ss = new StateSource
            {
                PaddingData = new byte[400 * 1000]
            };

            using var zw = new ZwinderBuffer(new RewindConfig
            {
                BufferSize        = 1,
                TargetFrameLength = 1
            });

            // Need to get data in the zwinderbuffer so that the last state, and the last state in particular, wraps around
            ss.Frame = 1;
            zw.Capture(1, s => ss.SaveStateBinary(new BinaryWriter(s)), null, true);
            ss.Frame = 2;
            zw.Capture(2, s => ss.SaveStateBinary(new BinaryWriter(s)), null, true);
            ss.Frame = 3;
            zw.Capture(3, s => ss.SaveStateBinary(new BinaryWriter(s)), null, true);

            zw.SaveStateBinary(new BinaryWriter(new MemoryStream()));
        }