using System;
using NUnit.Framework;
using NCover;
namespace NCoverCheckTests.AcceptenceTests.Vb{
/// <summary>
/// Summary description for IfTest.
/// </summary>
[TestFixture]
public class IfTest
{
[SetUp]
public void SetUp()
{
NCoverCheck.ResetForTests();
}
[Test]
public void CorrectCoverageOfTrueIf()
{
const string COVER_TRUE_IF = @"
Public Class A
Public Shared Function B() As Boolean()
If System.Environment.TickCount > 0 Then '4
Return NCover.NCoverCheck.covered 'todo
End If
Return NCover.NCoverCheck.covered 'todo
End Function
End Class";
string instrumentedCode;
TestUtilities.AssertVbCompiles(new string[] { COVER_TRUE_IF }, "A");
CoveragePoint[] points = new VbInstrumenter( 0, COVER_TRUE_IF, "").Do(out instrumentedCode, null);
Assert.AreEqual(1, points.Length);
bool[] results = (bool[]) TestUtilities.AssertVbCompiles(new string[] { instrumentedCode }, "A");
Assert.AreEqual(1, results.Length);
Assert.IsTrue(TestUtilities.WasHit(points, results, 4));
//Assert.IsTrue(TestUtilities.WasHit(points, results, 5));
//Assert.IsFalse(TestUtilities.WasHit(points, results, 8));
}
[Test]
public void CorrectCoverageOfFalseIf()
{
const string COVER_TRUE_IF = @"
Public Class A
Public Shared Function B() As Boolean()
If System.Environment.TickCount < 0 Then '4
Return NCover.NCoverCheck.covered 'todo
End If
Return NCover.NCoverCheck.covered 'todo
End Function
End Class";
string instrumentedCode;
TestUtilities.AssertVbCompiles(new string[] { COVER_TRUE_IF }, "A");
CoveragePoint[] points = new VbInstrumenter( 0, COVER_TRUE_IF, "").Do(out instrumentedCode, null);
Assert.AreEqual(1, points.Length);
bool[] results = (bool[]) TestUtilities.AssertVbCompiles(new string[] { instrumentedCode }, "A");
Assert.AreEqual(0, results.Length);
Assert.IsFalse(TestUtilities.WasHit(points, results, 4));
//Assert.IsTrue(TestUtilities.WasHit(points, results, 5));
//Assert.IsFalse(TestUtilities.WasHit(points, results, 8));
}
[Test]
public void CorrectCoverageOfTrueSingleLineIf()
{
const string COVER_TRUE_IF = @"
Public Class A
Public Shared Function B() As Boolean()
If System.Environment.TickCount > 0 Then Return NCover.NCoverCheck.covered 'todo line 4
Return NCover.NCoverCheck.covered 'todo
End Function
End Class";
string instrumentedCode;
TestUtilities.AssertVbCompiles(new string[] { COVER_TRUE_IF }, "A");
CoveragePoint[] points = new VbInstrumenter( 0, COVER_TRUE_IF, "").Do(out instrumentedCode, null);
Assert.AreEqual(1, points.Length);
bool[] results = (bool[]) TestUtilities.AssertVbCompiles(new string[] { instrumentedCode }, "A");
Assert.AreEqual(1, results.Length);
Assert.IsTrue(TestUtilities.WasHit(points, results, 4));
//Assert.IsTrue(TestUtilities.WasHit(points, results, 5));
//Assert.IsFalse(TestUtilities.WasHit(points, results, 8));
}
[Test]
public void CorrectCoverageOfSingleLineFalseIf()
{
const string COVER_TRUE_IF = @"
Public Class A
Public Shared Function B() As Boolean()
If System.Environment.TickCount < 0 Then Return NCover.NCoverCheck.covered 'todo
Return NCover.NCoverCheck.covered 'todo
End Function
End Class";
string instrumentedCode;
TestUtilities.AssertVbCompiles(new string[] { COVER_TRUE_IF }, "A");
CoveragePoint[] points = new VbInstrumenter( 0, COVER_TRUE_IF, "").Do(out instrumentedCode, null);
Assert.AreEqual(1, points.Length);
bool[] results = (bool[]) TestUtilities.AssertVbCompiles(new string[] { instrumentedCode }, "A");
Assert.AreEqual(0, results.Length);
Assert.IsFalse(TestUtilities.WasHit(points, results, 4));
//Assert.IsTrue(TestUtilities.WasHit(points, results, 5));
//Assert.IsFalse(TestUtilities.WasHit(points, results, 8));
}
[Test]
public void CorrectCoverageOfTrueElseIf()
{
const string COVER_TRUE_IF = @"
Public Class A
Public Shared Function B() As Boolean()
If System.Environment.TickCount < 0 Then '4
ElseIf System.Environment.TickCount > 0 Then '5
Return NCover.NCoverCheck.covered 'todo
End If
Return NCover.NCoverCheck.covered 'todo
End Function
End Class";
string instrumentedCode;
TestUtilities.AssertVbCompiles(new string[] { COVER_TRUE_IF }, "A");
CoveragePoint[] points = new VbInstrumenter( 0, COVER_TRUE_IF, "").Do(out instrumentedCode, null);
Assert.AreEqual(2, points.Length);
bool[] results = (bool[]) TestUtilities.AssertVbCompiles(new string[] { instrumentedCode }, "A");
Assert.AreEqual(2, results.Length);
Assert.IsTrue(TestUtilities.WasHit(points, results, 5));
//Assert.IsTrue(TestUtilities.WasHit(points, results, 5));
//Assert.IsFalse(TestUtilities.WasHit(points, results, 8));
}
[Test]
public void DontInstumentPreProcessorStatements()
{
const string CODE = @"
#if DEBUG
#else
#endif
";
string instrumentedCode;
CoveragePoint[] points = new VbInstrumenter( 0, CODE, "").Do(out instrumentedCode, null);
Assert.AreEqual(0, points.Length);
}
}
}
|