Exemple #1
0
    public void Items_cleared_out_of_buffer_cant_be_read()
    {
        var buffer = new CircularBuffer <int>(capacity: 1);

        buffer.Write(1);
        buffer.Clear();
        Assert.Throws <InvalidOperationException>(() => buffer.Read());
    }
Exemple #2
0
    public void Clear_does_nothing_on_empty_buffer()
    {
        var buffer = new CircularBuffer <int>(capacity: 1);

        buffer.Clear();
        buffer.Write(1);
        Assert.Equal(1, buffer.Read());
    }
 /// <summary>
 /// Executed after a Seek operation is performed on the parent MediaElement
 /// </summary>
 public void Seek()
 {
     lock (SyncLock)
     {
         AudioBuffer?.Clear();
         Array.Clear(ReadBuffer, 0, ReadBuffer.Length);
     }
 }
 public void Reclaim()
 {
     _availables.Clear();
     foreach (var item in _backup)
     {
         _availables.Enqueue(item);
     }
 }
    /// <summary>
    /// 将服务器发的的bytes进行解析
    /// </summary>
    private void AnalyticalNetworkMsg()
    {
        while (ringBuf.Size >= sizeof(uint))
        {
            byte[] lengthByte = new byte[sizeof(uint)];

            ringBuf.CopyTo(0, lengthByte, 0, lengthByte.Length);

            uint msgLength = BitConverter.ToUInt32(lengthByte, 0);

            msgLength = NetworkMsg.NetworkToHostOrder(msgLength);

            if (ringBuf.Size >= msgLength)
            {
                byte[] msgdata = new byte[msgLength];

                ringBuf.Get(msgdata);

                if (msgLength == 0)
                {
                    ringBuf.Clear();
                    return;
                }

                using (MemoryStream stream = new MemoryStream(msgdata))
                {
                    BinaryReader br = new BinaryReader(stream);

                    NetworkMsg Nmsg = new NetworkMsg();

                    try
                    {
                        Nmsg.length   = NetworkMsg.NetworkToHostOrder(br.ReadInt32());
                        Nmsg.msgId    = NetworkMsg.NetworkToHostOrder(br.ReadInt32());
                        Nmsg.sequence = (short)NetworkMsg.NetworkToHostOrder(br.ReadInt16());
                    }
                    catch (Exception)
                    {
                        throw;
                    }

                    // 10 is header length    length:4  msgId:4 sequence:2
                    byte[] data = br.ReadBytes((int)msgLength - 10);

                    Nmsg.data = data;

                    lock (objThread)
                    {
                        mMsgEvents.Enqueue(Nmsg);
                    }
                }
            }
            else
            {
                break;
            }
        }
    }
        public void ClearTest()
        {
            var target = new CircularBuffer<int>(3) { 1, 2, 3 };

            target.Clear();

            Assert.IsTrue(target.Capacity == 3);
            Assert.IsTrue(target.Count == 0);
        }
Exemple #7
0
        public void Clear_ItemsClearedCanNotBeRead()
        {
            var buffer = new CircularBuffer <int>(1);

            buffer.Write(1);
            buffer.Clear();

            Assert.Throws <InvalidOperationException>(() => buffer.Read());
        }
Exemple #8
0
        public void Clear_EmptyBuffer_DoesNothing()
        {
            var buffer = new CircularBuffer <int>(1);

            buffer.Clear();
            buffer.Write(1);

            Assert.AreEqual(1, buffer.Read());
        }
Exemple #9
0
 public void Clear()
 {
     _durationData.Clear();
     _totalSum    = default;
     _totalCount  = 0;
     _runningSum  = default;
     _toOverwrite = false;
     MarkDirty();
 }
Exemple #10
0
 private void SetStandardViewParams()
 {
     angleBuffer.Clear();
     sizeBuffer.Clear();
     transform.SetParent(null);
     player.transform.SetParent(null);
     CameraViews.SetActive(CameraView.CameraViewType.Standard);
     OnStandardViewSet?.Invoke();
 }
Exemple #11
0
    public void Clear_frees_up_capacity_for_another_write()
    {
        var buffer = new CircularBuffer <int>(capacity: 1);

        buffer.Write(1);
        buffer.Clear();
        buffer.Write(2);
        Assert.Equal(2, buffer.Read());
    }
        public void TestClear()
        {
            var buffer = new CircularBuffer <int>(3);

            Assert.IsTrue(buffer.IsEmpty);
            buffer.Add(100);
            Assert.IsFalse(buffer.IsEmpty);
            buffer.Clear();
            Assert.IsTrue(buffer.IsEmpty);
        }
        public void Should_Be_Empty_When_Clear()
        {
            var circularBuffer = new CircularBuffer <string>(2);

            circularBuffer.Add("One");

            circularBuffer.Clear();

            Assert.That(circularBuffer.ToList().Count, Is.EqualTo(0));
        }
Exemple #14
0
        public void Clear_FullBuffer_CanNowBeWrittenTo()
        {
            var buffer = new CircularBuffer <int>(1);

            buffer.Write(1);
            buffer.Clear();
            buffer.Write(2);

            Assert.AreEqual(2, buffer.Read());
        }
Exemple #15
0
        public void Clear_ClearsItems()
        {
            CircularBuffer <int> q = new CircularBuffer <int>(8)
            {
                1, 2, 3, 4, 5
            };

            q.Clear();
            Assert.AreEqual(0, q.Count, "CircularBuffer should remember its items");
        }
Exemple #16
0
    private byte[] CombineBuffer_Header_And_Packet <Packet>(Packet pPacket, Packet_Header pPacketHeader) where Packet : INetworkPacket
    {
        bool bIsGenerate = pPacketHeader != null;

        if (bIsGenerate == false)
        {
            OnGeneratePacketHeader(pPacket, out bIsGenerate, out pPacketHeader);
        }

        _pBufferSend.Clear();
        if (bIsGenerate)
        {
            pPacketHeader.INetworkPacketHeader_Set_Header(SCByteHelper.SizeOf <Packet>(), pPacket.INetworkPacket_Get_PacketID());
            _pBufferSend.Enqueue(SCByteHelper.ConvertByteArray(pPacketHeader));
        }
        _pBufferSend.Enqueue(SCByteHelper.ConvertByteArray(pPacket));

        return(_pBufferSend.Dequeue_OrNull(_pBufferSend.Count));
    }
Exemple #17
0
        public void Clear_should_reset_buffer_to_empty_state()
        {
            buffer.Add(1);
            buffer.Add(2);
            buffer.Add(3);
            buffer.Add(4);

            buffer.Clear();

            buffer.Should().BeEmpty();
        }
Exemple #18
0
        public void ClearTest()
        {
            var target = new CircularBuffer <int>(3)
            {
                1, 2, 3
            };

            target.Clear();

            Assert.IsTrue(target.Capacity == 3);
            Assert.IsTrue(target.Count == 0);
        }
        public void ClearTest()
        {
            var cb = new CircularBuffer <int>(2);

            cb.Enqueue(1);
            cb.Enqueue(2);
            Assert.That(cb.Count == 2);
            Assert.That(cb.Capacity == 2);
            cb.Clear();
            Assert.That(cb.Capacity == 2);
            Assert.That(cb.Count == 0);
        }
        /// <inheritdoc />
        public void Seek()
        {
            lock (SyncLock)
            {
                AudioBuffer?.Clear();

                // AudioDevice?.Clear(); // TODO: This causes crashes
                if (ReadBuffer != null)
                {
                    Array.Clear(ReadBuffer, 0, ReadBuffer.Length);
                }
            }
        }
        public void Clear()
        {
            var buffer = new CircularBuffer <int>(4);

            buffer.Write(3);
            buffer.Write(4);
            buffer.Write(5);
            buffer.Write(6);
            buffer.Write(7);
            buffer.Clear();

            Assert.IsTrue(buffer.IsEmpty);
        }
Exemple #22
0
    public void Clear()
    {
        SelectRow(null);

#if UNITY_EDITOR
        m_NextFakeIndex = 0;
#endif

        m_Messages.Clear();
        m_TouchId = -1;

        Refresh();
    }
Exemple #23
0
        public void _1_Clear_Should_clear_items()
        {
            CircularBuffer <char> collection = new CircularBuffer <char>(42);

            foreach (char c in "mindplugg")
            {
                collection.Add(c);
            }

            collection.Clear();

            Assert.Equal(string.Empty, new string(collection.ToArray()));
        }
Exemple #24
0
    public void Initial_clear_does_not_affect_wrapping_around()
    {
        var buffer = new CircularBuffer <int>(capacity: 2);

        buffer.Clear();
        buffer.Write(1);
        buffer.Write(2);
        buffer.Overwrite(3);
        buffer.Overwrite(4);
        Assert.Equal(3, buffer.Read());
        Assert.Equal(4, buffer.Read());
        Assert.Throws <InvalidOperationException>(() => buffer.Read());
    }
Exemple #25
0
    public void SwitchFrame()
    {
        Dictionary <Type, CircularBuffer <FrameData <object> > > temp = currentFrameData;

        currentFrameData = lastFrameData;
        lastFrameData    = temp;

        foreach (Type type in currentFrameData.Keys)
        {
            CircularBuffer <FrameData <object> > buffer = currentFrameData[type];
            buffer.Clear();
        }
    }
Exemple #26
0
        public void Disconnect()
        {
            if (_clientSocket == null || !IsRunning)
            {
                return;
            }

            IsRunning = false;
            InvokeDisconnected();

            try
            {
                _clientSocket.Shutdown(SocketShutdown.Both);
            }
            catch
            {
            }

            try
            {
                _clientSocket.Close();
            }
            catch
            {
            }

            // (_recvEventArgs?.UserToken as AsyncUserToken)?.Dispose();

            _clientSocket  = null;
            _sendEventArgs = null;
            _recvEventArgs = null;

            Protocol        = Protocol.Unknown;
            AccessLevel     = AccessLevel.Normal;
            ReceivedPackets = false;

            if (_dataBuffer != null)
            {
                _pool.AddFreeSegment(_dataBuffer);
            }
            _dataBuffer = null;
            _buffer.Clear();

            lock (_sendQueue)
            {
                if (!_sendQueue.IsEmpty)
                {
                    _sendQueue.Clear();
                }
            }
        }
Exemple #27
0
        public void CircularBufferTestClear()
        {
            var buffer = new CircularBuffer <long>(15);

            for (int i = 0; i < 5; i++)
            {
                buffer.PushFront(i);
            }
            buffer.Clear();
            Assert.ExceptionExpected(typeof(IndexOutOfRangeException), () => { buffer.PopBack(); });
            Assert.ExceptionExpected(typeof(IndexOutOfRangeException), () => { buffer.PopFront(); });
            Assert.AreEqual(0, buffer.Count);
            Assert.AreEqual(15, buffer.Capacity);
        }
Exemple #28
0
        public void _2_Add_Should_be_thread_safe()
        {
            CircularBuffer <char> collection = new CircularBuffer <char>(26);

            for (int i = 0; i < 100; ++i)
            {
                "azertyuiopqsdfghjklmwxcvbn".AsParallel().ForAll(collection.Add);
                "azertyuiopqsdfghjklmwxcvbn".AsParallel().ForAll(collection.Add);

                Assert.All(collection, c => Assert.Contains(c, "azertyuiopqsdfghjklmwxcvbn"));

                collection.Clear();
            }
        }
Exemple #29
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldEvictElementsWhenClearing()
        public virtual void ShouldEvictElementsWhenClearing()
        {
            // given
            CircularBuffer <int> buffer = new CircularBuffer <int>(3);

            int?[] evictions = new int?[3];
            buffer.Append(1);
            buffer.Append(2);

            // when
            buffer.Clear(evictions);

            // then
            assertEquals(0, buffer.Size());
            assertArrayEquals(evictions, new int?[] { 1, 2, null });
        }
Exemple #30
0
        protected override void OnStop()
        {
            ImportFileWorker.Default.StartStop();
            ExportFileWorker.Default.StartStop();
            CoverWorker.Default.StartStop();

            if (m_ServerHost != null)
            {
                m_ServerHost.Close();
                m_ServerHost = null;
            }

            m_HistiryBuffer.Clear();

            base.OnStop();
        }
        public void Dispose()
        {
            if (Mesh != null)
            {
                if (Application.isEditor)
                {
                    UnityEngine.Object.DestroyImmediate(Mesh, true);
                }
                else
                {
                    UnityEngine.Object.Destroy(Mesh);
                }
            }

            Points.Clear();
            Points = null;
        }
        public void UsageExample()
        {
            // Create a buffer with a capacity of 5 items.
            var buffer = new CircularBuffer<long>(5);

            // Add three.
            foreach (var i in Enumerable.Range(1, 3))
                buffer.Enqueue(i);
            Debug.WriteLine(buffer);
            // Capacity=5, Count=3, Buffer=[1,2,3]

            // Add three more.
            foreach (var i in Enumerable.Range(4, 3))
                buffer.Enqueue(i);
            Debug.WriteLine(buffer);
            // Capacity=5, Count=5, Buffer=[2,3,4,5,6]

            // Remove the third.
            var value = buffer[3];
            buffer.RemoveAt(3);
            Debug.WriteLine(buffer);
            // Capacity=5, Count=4, Buffer=[2,3,4,6]

            // Re-insert it.
            buffer.Insert(3, value);
            Debug.WriteLine(buffer);
            // Capacity=5, Count=5, Buffer=[2,3,4,5,6]

            // Dequeue.
            Debug.Print("Value = {0}", buffer.Dequeue());
            // Value = 2
            Debug.WriteLine(buffer);
            // Capacity=5, Count=4, Buffer=[3,4,5,6]

            // Increase the capacity.
            buffer.Capacity = 6;
            Debug.WriteLine(buffer);
            // Capacity=6, Count=4, Buffer=[3,4,5,6]

            // Add three more.
            foreach (var i in Enumerable.Range(7, 3))
                buffer.Enqueue(i);
            Debug.WriteLine(buffer);
            // Capacity=6, Count=6, Buffer=[4,5,6,7,8,9]

            // Reduce the capacity.
            buffer.Capacity = 4;
            Debug.WriteLine(buffer);
            // Capacity=4, Count=4, Buffer=[4,5,6,7]

            // Clear the buffer.
            buffer.Clear();
            Debug.WriteLine(buffer);
            // Capacity=4, Count=0, Buffer=[]
        }