Skip to content
This repository was archived by the owner on Nov 15, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,6 @@ public string GetLine ( int LineNo ) {
if ( LineNo > 0 && LineNo <= lines.Length ) {
lineInfo lineInfo = lines[LineNo-1];
retString = textSource.Substring(lineInfo.Offset, lineInfo.Length);
} else {
//Debug.Fail( "Line number out of range" );
}

return retString;
Expand Down
87 changes: 87 additions & 0 deletions main/OpenCover.Test/Framework/Manager/MemoryManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,93 @@

namespace OpenCover.Test.Framework.Manager
{
[TestFixture]
public class MemoryManagerTests_Full_Coverage
{
[Test]
public void AllocateMemoryBuffer_WhenManagerNotInitialised_Ignored_OK()
{
using (var _manager = new MemoryManager()) {
// not initialised

// arrange
uint bufferId;
_manager.AllocateMemoryBuffer(100, out bufferId);
Assert.AreEqual(0, _manager.GetBlocks.Count);

// act
_manager.DeactivateMemoryBuffer(bufferId);

// assert
Assert.AreEqual(0, _manager.GetBlocks.Count);
}
}

[Test]
public void AllocateMemoryBuffer_WhenManagerInitialisedTwice_Ignored_OK()
{
using (var _manager = new MemoryManager()) {
_manager.Initialise("Local", "C#", new String[0]);
_manager.Initialise("Local", "C#", new String[0]);

// arrange
uint bufferId;
_manager.AllocateMemoryBuffer(100, out bufferId);
Assert.AreEqual(1, _manager.GetBlocks.Count);

// act
_manager.DeactivateMemoryBuffer(bufferId);

// assert
Assert.IsFalse(_manager.GetBlocks.First().Active);
}
}

[Test]
public void AllocateMemoryBuffer_Twice_ThisIsPotentialMemoryLeak_FAIL()
{
// setup
using (var _manager = new MemoryManager()) {
_manager.Initialise("Local", "C#", new String[0]);

// arrange
uint bufferId;
_manager.AllocateMemoryBuffer(100, out bufferId);
_manager.AllocateMemoryBuffer(100, out bufferId);
Assert.AreEqual(2, _manager.GetBlocks.Count);
Assert.IsTrue(_manager.GetBlocks.First().Active);

// act
_manager.DeactivateMemoryBuffer(bufferId);

// assert is WRONG
Assert.IsTrue(_manager.GetBlocks.First().Active);
}
}

[Test]
public void DeactivateMemoryBufferTwice_Ignored_OK()
{
using (var _manager = new MemoryManager()) {
_manager.Initialise("Local", "C#", new String[0]);

// arrange
uint bufferId;
_manager.AllocateMemoryBuffer(100, out bufferId);
Assert.AreEqual(1, _manager.GetBlocks.Count);
Assert.IsTrue(_manager.GetBlocks.First().Active);

// act
_manager.DeactivateMemoryBuffer(bufferId);
_manager.DeactivateMemoryBuffer(bufferId);

// assert
Assert.IsFalse(_manager.GetBlocks.First().Active);
}
}

}

[TestFixture]
public class MemoryManagerTests
{
Expand Down