/// <summary>
        /// Executes in two distinct scenarios.
        ///
        /// 1. If disposing is true, the method has been called directly
        /// or indirectly by a user's code via the Dispose method.
        /// Both managed and unmanaged resources can be disposed.
        ///
        /// 2. If disposing is false, the method has been called by the
        /// runtime from inside the finalizer and you should not reference (access)
        /// other managed objects, as they already have been garbage collected.
        /// Only unmanaged resources can be disposed.
        /// </summary>
        /// <param name="disposing"></param>
        /// <remarks>
        /// If any exceptions are thrown, that is fine.
        /// If the method is being done in a finalizer, it will be ignored.
        /// If it is thrown by client code calling Dispose,
        /// it needs to be handled by fixing the bug.
        ///
        /// If subclasses override this method, they should call the base implementation.
        /// </remarks>
        private void Dispose(bool disposing)
        {
            System.Diagnostics.Debug.WriteLineIf(!disposing, "****** Missing Dispose() call for " + GetType().Name + ". ****** ");
            // Must not be run more than once.
            if (m_isDisposed)
            {
                return;
            }

            if (disposing)
            {
                if (m_messages != null)
                {
                    while (m_messages.Count > 0)
                    {
                        m_messages.Remove();
                    }
                }
            }

            // Dispose unmanaged resources here, whether disposing is true or false.
            m_master   = null;
            m_receiver = null;
            m_messages = null;

            m_isDisposed = true;
        }
Beispiel #2
0
 void Fill(int start, int end, ref int count, SafeQueue queue)
 {
     for (int i = start; i < end; i++)
     {
         queue.Add(i);
         count++;
         Assert.AreEqual(count, queue.Count);
     }
 }
Beispiel #3
0
 void Check(int start, int end, ref int count, SafeQueue queue)
 {
     for (int i = start; i < end; i++)
     {
         int result = (int)queue.Remove();
         count--;
         Assert.AreEqual(i, result);
         Assert.AreEqual(count, queue.Count);
     }
 }
Beispiel #4
0
        public void QueueNormal()
        {
            SafeQueue queue = new SafeQueue();
            int       count = 0;

            // fill the first 49 of 100 inital slots. Just short of causing grow.
            Fill(0, 49, ref count, queue);

            // Remove the first 40.
            Check(0, 40, ref count, queue);
            Assert.AreEqual(9, count);

            // Add and remove another 40.
            Fill(49, 89, ref count, queue);
            Check(40, 80, ref count, queue);
            Assert.AreEqual(9, count);

            // And another group. This checks the situation where the queue is wrapped around during grow.
            Fill(89, 149, ref count, queue);
            Assert.AreEqual(69, count);

            Check(80, 149, ref count, queue);
            Assert.AreEqual(0, count);

            // Re-establishes a situation for an earlier group of tests.
            Fill(0, 50, ref count, queue);
            Check(0, 20, ref count, queue);

            // Add another 55; this will force a grow, we now have 200 slots
            Fill(500, 555, ref count, queue);
            // Remove the next 30. Down to 55.
            Check(20, 50, ref count, queue);

            // Remove 10 more. Down to 45.
            Check(500, 510, ref count, queue);

            // Add another 50
            Fill(600, 650, ref count, queue);

            // Remove the rest of the 500 series, just to check
            Check(510, 555, ref count, queue);
            // Remove the rest of the 600 series, just to check, and make sure we can be back to 0.
            Check(600, 650, ref count, queue);
            Assert.AreEqual(0, queue.Count);
        }
		public void QueueNormal()
		{
			SafeQueue queue = new SafeQueue();
			int count = 0;
			// fill the first 49 of 100 inital slots. Just short of causing grow.
			Fill(0, 49, ref count, queue);

			// Remove the first 40.
			Check(0, 40, ref count, queue);
			Assert.AreEqual(9, count);

			// Add and remove another 40.
			Fill(49, 89, ref count, queue);
			Check(40, 80, ref count, queue);
			Assert.AreEqual(9, count);

			// And another group. This checks the situation where the queue is wrapped around during grow.
			Fill(89, 149, ref count, queue);
			Assert.AreEqual(69, count);

			Check(80, 149, ref count, queue);
			Assert.AreEqual(0, count);

			// Re-establishes a situation for an earlier group of tests.
			Fill(0,50, ref count, queue);
			Check(0, 20, ref count, queue);

			// Add another 55; this will force a grow, we now have 200 slots
			Fill(500, 555, ref count, queue);
			// Remove the next 30. Down to 55.
			Check(20, 50, ref count, queue);

			// Remove 10 more. Down to 45.
			Check(500, 510, ref count, queue);

			// Add another 50
			Fill(600, 650, ref count, queue);

			// Remove the rest of the 500 series, just to check
			Check(510, 555, ref count, queue);
			// Remove the rest of the 600 series, just to check, and make sure we can be back to 0.
			Check(600, 650, ref count, queue);
			Assert.AreEqual(0, queue.Count);
		}
		void Check(int start, int end, ref int count, SafeQueue queue)
		{
			for (int i = start; i < end; i++)
			{
				int result = (int) queue.Remove();
				count--;
				Assert.AreEqual(i, result);
				Assert.AreEqual(count, queue.Count);
			}
		}
		void Fill(int start, int end, ref int count, SafeQueue queue)
		{
			for (int i = start; i < end; i++)
			{
				queue.Add(i);
				count++;
				Assert.AreEqual(count, queue.Count);
			}
		}
        /// <summary>
        /// Executes in two distinct scenarios.
        ///
        /// 1. If disposing is true, the method has been called directly
        /// or indirectly by a user's code via the Dispose method.
        /// Both managed and unmanaged resources can be disposed.
        ///
        /// 2. If disposing is false, the method has been called by the
        /// runtime from inside the finalizer and you should not reference (access)
        /// other managed objects, as they already have been garbage collected.
        /// Only unmanaged resources can be disposed.
        /// </summary>
        /// <param name="disposing"></param>
        /// <remarks>
        /// If any exceptions are thrown, that is fine.
        /// If the method is being done in a finalizer, it will be ignored.
        /// If it is thrown by client code calling Dispose,
        /// it needs to be handled by fixing the bug.
        ///
        /// If subclasses override this method, they should call the base implementation.
        /// </remarks>
        private void Dispose(bool disposing)
        {
            System.Diagnostics.Debug.WriteLineIf(!disposing, "****** Missing Dispose() call for " + GetType().Name + ". ****** ");
            // Must not be run more than once.
            if (m_isDisposed)
                return;

            if (disposing)
            {
                if (m_messages != null)
                {
                    while (m_messages.Count > 0)
                        m_messages.Remove();
                }
            }

            // Dispose unmanaged resources here, whether disposing is true or false.
            m_master = null;
            m_receiver = null;
            m_messages = null;

            m_isDisposed = true;
        }