182 lines
6.4 KiB
C#
182 lines
6.4 KiB
C#
// The following code was generated by Microsoft Visual Studio 2005.
|
|
// The test owner should check each test for validity.
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
using System;
|
|
using System.Text;
|
|
using System.Collections.Generic;
|
|
using Virtuoso.Miranda.Plugins.Native;
|
|
using System.Diagnostics;
|
|
namespace Virtuoso.Miranda.Plugins.UnitTests
|
|
{
|
|
/// <summary>
|
|
///This is a test class for Virtuoso.Miranda.Plugins.Native.InteropBufferPool and is intended
|
|
///to contain all Virtuoso.Miranda.Plugins.Native.InteropBufferPool Unit Tests
|
|
///</summary>
|
|
[TestClass()]
|
|
public class InteropBufferPoolTest
|
|
{
|
|
private TestContext testContextInstance;
|
|
|
|
/// <summary>
|
|
///Gets or sets the test context which provides
|
|
///information about and functionality for the current test run.
|
|
///</summary>
|
|
public TestContext TestContext
|
|
{
|
|
get
|
|
{
|
|
return testContextInstance;
|
|
}
|
|
set
|
|
{
|
|
testContextInstance = value;
|
|
}
|
|
}
|
|
#region Additional test attributes
|
|
//
|
|
//You can use the following additional attributes as you write your tests:
|
|
//
|
|
//Use ClassInitialize to run code before running the first test in the class
|
|
//
|
|
//[ClassInitialize()]
|
|
//public static void MyClassInitialize(TestContext testContext)
|
|
//{
|
|
//}
|
|
//
|
|
//Use ClassCleanup to run code after all tests in a class have run
|
|
//
|
|
//[ClassCleanup()]
|
|
//public static void MyClassCleanup()
|
|
//{
|
|
//}
|
|
//
|
|
//Use TestInitialize to run code before running each test
|
|
//
|
|
//[TestInitialize()]
|
|
//public void MyTestInitialize()
|
|
//{
|
|
//}
|
|
//
|
|
//Use TestCleanup to run code after each test has run
|
|
//
|
|
//[TestCleanup()]
|
|
//public void MyTestCleanup()
|
|
//{
|
|
//}
|
|
//
|
|
#endregion
|
|
|
|
[TestInitialize]
|
|
public void TestInitializer()
|
|
{
|
|
InteropBufferPool_Accessor.Refresh();
|
|
}
|
|
|
|
/// <summary>
|
|
///A test for AcquireBuffer (int)
|
|
///</summary>
|
|
[TestMethod()]
|
|
public void AcquireBufferTest()
|
|
{
|
|
InteropBuffer buffer = null, buffer1 = null;
|
|
|
|
try
|
|
{
|
|
int prev = InteropBufferPool_Accessor.NextAvailableBufferIndex;
|
|
buffer = InteropBufferPool.AcquireBuffer();
|
|
|
|
Assert.AreEqual<int>(prev + 1, InteropBufferPool_Accessor.NextAvailableBufferIndex);
|
|
|
|
buffer1 = InteropBufferPool.AcquireBuffer(InteropBufferPool_Accessor.maximumAvailableBufferSize + 1);
|
|
Assert.IsTrue(Array.IndexOf<InteropBuffer>(InteropBufferPool_Accessor.Buffers, buffer1) == -1, "Acquired buffer is probably undersized.");
|
|
|
|
try
|
|
{
|
|
InteropBufferPool.AcquireBuffer(0);
|
|
Assert.Fail("Negative buffer size accepted.");
|
|
}
|
|
catch { }
|
|
}
|
|
finally
|
|
{
|
|
InteropBufferPool.ReleaseBuffer(buffer);
|
|
InteropBufferPool.ReleaseBuffer(buffer1);
|
|
}
|
|
}
|
|
|
|
[TestMethod()]
|
|
public void AcquireReleaseExpandedBufferTest()
|
|
{
|
|
InteropBuffer buffer = null, buffer1 = null, buffer2 = null;
|
|
int expandedSize = InteropBufferPool_Accessor.maximumAvailableBufferSize + 1;
|
|
|
|
try
|
|
{
|
|
buffer = buffer1 = InteropBufferPool.AcquireBuffer(expandedSize);
|
|
Assert.IsTrue(Array.IndexOf<InteropBuffer>(InteropBufferPool_Accessor.Buffers, buffer) == -1, "Acquired buffer is probably undersized.");
|
|
|
|
InteropBufferPool.ReleaseBuffer(buffer);
|
|
Assert.IsTrue(Array.IndexOf<InteropBuffer>(InteropBufferPool_Accessor.Buffers, buffer1) != -1, "Expanded buffer not assimilated.");
|
|
|
|
buffer = InteropBufferPool.AcquireBuffer(expandedSize);
|
|
Assert.IsTrue(buffer == buffer1, "Assimilated expanded buffer not used.");
|
|
Assert.IsTrue(buffer.Size >= expandedSize, "Undersized buffer acquired.");
|
|
InteropBufferPool.ReleaseBuffer(buffer);
|
|
|
|
buffer = InteropBufferPool.AcquireBuffer(expandedSize);
|
|
buffer1 = InteropBufferPool.AcquireBuffer(expandedSize);
|
|
Assert.IsTrue(buffer != buffer1, "Reserved buffer acquired.");
|
|
|
|
buffer2 = InteropBufferPool.AcquireBuffer(expandedSize);
|
|
Assert.IsTrue(buffer2 != buffer && buffer2 != buffer1, "Reserved buffer acquired.");
|
|
}
|
|
finally
|
|
{
|
|
InteropBufferPool.ReleaseBuffer(buffer);
|
|
InteropBufferPool.ReleaseBuffer(buffer1);
|
|
InteropBufferPool.ReleaseBuffer(buffer2);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///A test for ReleaseBuffer (InteropBuffer)
|
|
///</summary>
|
|
[TestMethod()]
|
|
public void ReleaseBufferTest()
|
|
{
|
|
int prev = InteropBufferPool_Accessor.NextAvailableBufferIndex;
|
|
InteropBuffer buffer = InteropBufferPool.AcquireBuffer();
|
|
InteropBuffer buffer1 = buffer;
|
|
|
|
try
|
|
{
|
|
buffer.Lock();
|
|
InteropBufferPool.ReleaseBuffer(buffer);
|
|
Assert.Fail("InteropBufferPool::ReleaseBuffer accepts locked buffers.");
|
|
}
|
|
catch { }
|
|
finally
|
|
{
|
|
buffer.Unlock();
|
|
InteropBufferPool.ReleaseBuffer(buffer);
|
|
}
|
|
|
|
try
|
|
{
|
|
InteropBufferPool.ReleaseBuffer(buffer1);
|
|
Assert.Fail("InteropBufferPool::ReleaseBuffer accepts already released buffers.");
|
|
}
|
|
catch { }
|
|
|
|
Assert.AreEqual<int>(prev, InteropBufferPool_Accessor.NextAvailableBufferIndex);
|
|
|
|
try
|
|
{
|
|
IntPtr ptr = buffer.IntPtr;
|
|
Assert.Fail("InteropBufferPool::ReleaseBuffer does not dispose released buffers.");
|
|
}
|
|
catch { }
|
|
}
|
|
}
|
|
}
|