Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

Commit

Permalink
Fixed all test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
lextm committed Jul 28, 2012
1 parent 3230d1d commit 98c93a3
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 51 deletions.
26 changes: 14 additions & 12 deletions src/AddIns/Analysis/CodeCoverage/Project/Src/CodeCoverageMethod.cs
Expand Up @@ -44,6 +44,18 @@ public CodeCoverageMethod(string className, XElement reader)
: this(GetMethodName(reader), className, GetMethodAttributes(reader))
{
ReadMethodBodySize(reader);
XAttribute isGetter = reader.Attribute("isGetter");
XAttribute isSetter = reader.Attribute("isSetter");
if (isGetter != null && isSetter != null && IsPropertyMethodName()) {
try {
IsProperty = Convert.ToBoolean(isGetter.Value) || Convert.ToBoolean(isSetter.Value);
} catch (FormatException) {
IsProperty = false;
}
}
else {
IsProperty = false;
}
}

static string GetMethodName(XElement reader)
Expand All @@ -53,12 +65,6 @@ static string GetMethodName(XElement reader)

static MethodAttributes GetMethodAttributes(XElement reader)
{
//string flags = reader.GetAttribute("flags");
//if (flags != null) {
// try {
// return (MethodAttributes)Enum.Parse(typeof(MethodAttributes), flags);
// } catch (ArgumentException) { }
//}
return MethodAttributes.Public;
}

Expand All @@ -73,11 +79,7 @@ void ReadMethodBodySize(XElement reader)
/// <summary>
/// Returns true if the method is a getter or setter method for a property.
/// </summary>
public bool IsProperty {
get {
return IsSpecialMethodName() && IsPropertyMethodName();
}
}
public bool IsProperty { get; private set; }

bool IsSpecialMethodName()
{
Expand All @@ -86,7 +88,7 @@ bool IsSpecialMethodName()

bool IsPropertyMethodName()
{
return name.StartsWith("get_") || name.StartsWith("set_");
return name.Contains("::get_") || name.Contains("::set_");
}

public string Name {
Expand Down
Expand Up @@ -32,7 +32,11 @@ public void SetUpFixture()
"\t\t\t\t\t\t<Method visited=\"true\" cyclomaticComplexity=\"1\" sequenceCoverage=\"100\" branchCoverage=\"100\" isConstructor=\"false\" isStatic=\"false\" isGetter=\"false\" isSetter=\"false\">\r\n" +
"\t\t\t\t\t\t\t<MetadataToken>100663297</MetadataToken>\r\n" +
"\t\t\t\t\t\t\t<Name>System.Boolean NUnit.Framework.NotEqualAsserter::Fail()</Name>\r\n" +
"\t\t\t\t\t\t\t<SequencePoints />\r\n" +
"\t\t\t\t\t\t\t<SequencePoints>\r\n" +
"\t\t\t\t\t\t\t\t<SequencePoint vc=\"1\" sl=\"21\" sc=\"3\" el=\"21\" ec=\"4\" />\r\n" +
"\t\t\t\t\t\t\t\t<SequencePoint vc=\"0\" sl=\"20\" sc=\"3\" el=\"20\" ec=\"4\" />\r\n" +
"\t\t\t\t\t\t\t\t<SequencePoint vc=\"0\" sl=\"19\" sc=\"3\" el=\"19\" ec=\"18\" />\r\n" +
"\t\t\t\t\t\t\t</SequencePoints>\r\n" +
"\t\t\t\t\t\t</Method>\r\n" +
"\t\t\t\t\t</Methods>\r\n" +
"\t\t\t\t</Class>\r\n" +
Expand Down
Expand Up @@ -19,45 +19,83 @@ public class CodeCoverageResultsPropertyFlagsTestFixture : CodeCoverageResultsTe
public void SetUpFixture()
{
string xml =
"<PartCoverReport ver=\"1.0.2796.35184\">\r\n" +
" <File id=\"1\" url=\"d:\\Projects\\test\\TestFixture1.cs\" />\r\n" +
" <Assembly id=\"1\" name=\"MyTests\" module=\"C:\\Projects\\Test\\MyTests\\bin\\MyTests.DLL\" domain=\"test-domain-MyTests.dll\" domainIdx=\"1\" />\r\n" +
" <Type asmref=\"1\" name=\"MyTests.Class1\" flags=\"2606412\">\r\n" +
" <Method name=\"set_Count\" sig=\"void (int)\" flags=\"2182\" iflags=\"0\">\r\n" +
" <pt visit=\"0\" pos=\"9\" len=\"1\" fid=\"1\" sl=\"34\" sc=\"4\" el=\"34\" ec=\"5\" />\r\n" +
" <pt visit=\"0\" pos=\"1\" len=\"8\" fid=\"1\" sl=\"33\" sc=\"5\" el=\"33\" ec=\"12\" />\r\n" +
" <pt visit=\"0\" pos=\"0\" len=\"1\" fid=\"1\" sl=\"32\" sc=\"8\" el=\"32\" ec=\"9\" />\r\n" +
" </Method>\r\n" +
" <Method name=\"get_Count\" sig=\"int ()\" flags=\"2182\" iflags=\"0\">\r\n" +
" <pt visit=\"0\" pos=\"6\" len=\"2\" fid=\"1\" sl=\"31\" sc=\"4\" el=\"31\" ec=\"5\" />\r\n" +
" <pt visit=\"0\" pos=\"1\" len=\"5\" fid=\"1\" sl=\"30\" sc=\"5\" el=\"30\" ec=\"15\" />\r\n" +
" <pt visit=\"0\" pos=\"0\" len=\"1\" fid=\"1\" sl=\"29\" sc=\"8\" el=\"29\" ec=\"9\" />\r\n" +
" </Method>\r\n" +
" <Method name=\"get_NotAProperty\" sig=\"void ()\" flags=\"134\" iflags=\"0\">\r\n" +
" <pt visit=\"0\" pos=\"1\" len=\"1\" fid=\"1\" sl=\"26\" sc=\"3\" el=\"26\" ec=\"4\" />\r\n" +
" <pt visit=\"0\" pos=\"0\" len=\"1\" fid=\"1\" sl=\"25\" sc=\"3\" el=\"25\" ec=\"4\" />\r\n" +
" </Method>\r\n" +
" <Method name=\"PropertyFlagsButJustAMethod\" sig=\"void ()\" flags=\"2182\" iflags=\"0\">\r\n" +
" <pt visit=\"0\" pos=\"8\" len=\"2\" fid=\"1\" sl=\"22\" sc=\"3\" el=\"22\" ec=\"4\" />\r\n" +
" <pt visit=\"0\" pos=\"7\" len=\"1\" fid=\"1\" sl=\"21\" sc=\"3\" el=\"21\" ec=\"4\" />\r\n" +
" <pt visit=\"0\" pos=\"0\" len=\"7\" fid=\"1\" sl=\"20\" sc=\"3\" el=\"20\" ec=\"18\" />\r\n" +
" </Method>\r\n" +
" <Method name=\"InvalidFlags\" sig=\"void ()\" flags=\"\" iflags=\"0\">\r\n" +
" <pt visit=\"0\" pos=\"8\" len=\"2\" fid=\"1\" sl=\"22\" sc=\"3\" el=\"22\" ec=\"4\" />\r\n" +
" <pt visit=\"0\" pos=\"7\" len=\"1\" fid=\"1\" sl=\"21\" sc=\"3\" el=\"21\" ec=\"4\" />\r\n" +
" <pt visit=\"0\" pos=\"0\" len=\"7\" fid=\"1\" sl=\"20\" sc=\"3\" el=\"20\" ec=\"18\" />\r\n" +
" </Method>\r\n" +
" </Type>\r\n" +
"</PartCoverReport>";

"<CoverageSession xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\r\n" +
"\t<Modules>\r\n" +
"\t\t<Module hash=\"44-54-B6-13-97-49-45-F8-6A-74-9E-49-0C-77-87-C6-9C-54-47-7B\">\r\n" +
"\t\t\t<FullName>C:\\Projects\\Test\\MyTests\\bin\\MyTests.DLL</FullName>\r\n" +
"\t\t\t<ModuleName>MyTests</ModuleName>\r\n" +
"\t\t\t<Files>\r\n" +
"\t\t\t\t<File uid=\"1\" fullPath=\"d:\\Projects\\test\\TestFixture1.cs\" />\r\n" +
"\t\t\t</Files>\r\n" +
"\t\t\t<Classes>\r\n" +
"\t\t\t\t<Class>\r\n" +
"\t\t\t\t\t<FullName>MyTests.Class1</FullName>\r\n" +
"\t\t\t\t\t<Methods>\r\n" +
"\t\t\t\t\t\t<Method visited=\"true\" cyclomaticComplexity=\"1\" sequenceCoverage=\"100\" branchCoverage=\"100\" isConstructor=\"false\" isStatic=\"false\" isGetter=\"false\" isSetter=\"true\">\r\n" +
"\t\t\t\t\t\t\t<MetadataToken>100663297</MetadataToken>\r\n" +
"\t\t\t\t\t\t\t<Name>System.Void MyTests.MyClass1::set_Count(System.Int32)</Name>\r\n" +
"\t\t\t\t\t\t\t<FileRef uid=\"1\" />\r\n" +
"\t\t\t\t\t\t\t<SequencePoints>\r\n" +
"\t\t\t\t\t\t\t\t<SequencePoint vc=\"0\" sl=\"34\" sc=\"4\" el=\"34\" ec=\"5\" />\r\n" +
"\t\t\t\t\t\t\t\t<SequencePoint vc=\"0\" sl=\"33\" sc=\"5\" el=\"33\" ec=\"12\" />\r\n" +
"\t\t\t\t\t\t\t\t<SequencePoint vc=\"0\" sl=\"32\" sc=\"8\" el=\"32\" ec=\"9\" />\r\n" +
"\t\t\t\t\t\t\t</SequencePoints>\r\n" +
"\t\t\t\t\t\t</Method>\r\n" +
"\t\t\t\t\t\t<Method visited=\"true\" cyclomaticComplexity=\"1\" sequenceCoverage=\"100\" branchCoverage=\"100\" isConstructor=\"false\" isStatic=\"false\" isGetter=\"true\" isSetter=\"false\">\r\n" +
"\t\t\t\t\t\t\t<MetadataToken>100663297</MetadataToken>\r\n" +
"\t\t\t\t\t\t\t<Name>System.Int32 MyTests.MyClass1::get_Count())</Name>\r\n" +
"\t\t\t\t\t\t\t<FileRef uid=\"1\" />\r\n" +
"\t\t\t\t\t\t\t<SequencePoints>\r\n" +
"\t\t\t\t\t\t\t\t<SequencePoint vc=\"0\" sl=\"31\" sc=\"4\" el=\"31\" ec=\"5\" />\r\n" +
"\t\t\t\t\t\t\t\t<SequencePoint vc=\"0\" sl=\"30\" sc=\"5\" el=\"30\" ec=\"15\" />\r\n" +
"\t\t\t\t\t\t\t\t<SequencePoint vc=\"0\" sl=\"29\" sc=\"8\" el=\"29\" ec=\"9\" />\r\n" +
"\t\t\t\t\t\t\t</SequencePoints>\r\n" +
"\t\t\t\t\t\t</Method>\r\n" +
"\t\t\t\t\t\t<Method visited=\"true\" cyclomaticComplexity=\"1\" sequenceCoverage=\"100\" branchCoverage=\"100\" isConstructor=\"false\" isStatic=\"false\" isGetter=\"false\" isSetter=\"false\">\r\n" +
"\t\t\t\t\t\t\t<MetadataToken>100663297</MetadataToken>\r\n" +
"\t\t\t\t\t\t\t<Name>System.Void MyTests.MyClass1::get_NotAProperty())</Name>\r\n" +
"\t\t\t\t\t\t\t<FileRef uid=\"1\" />\r\n" +
"\t\t\t\t\t\t\t<SequencePoints>\r\n" +
"\t\t\t\t\t\t\t\t<SequencePoint vc=\"0\" sl=\"21\" sc=\"3\" el=\"21\" ec=\"4\" />\r\n" +
"\t\t\t\t\t\t\t\t<SequencePoint vc=\"0\" sl=\"20\" sc=\"3\" el=\"20\" ec=\"4\" />\r\n" +
"\t\t\t\t\t\t\t\t<SequencePoint vc=\"0\" sl=\"19\" sc=\"3\" el=\"19\" ec=\"18\" />\r\n" +
"\t\t\t\t\t\t\t</SequencePoints>\r\n" +
"\t\t\t\t\t\t</Method>\r\n" +
"\t\t\t\t\t\t<Method visited=\"true\" cyclomaticComplexity=\"1\" sequenceCoverage=\"100\" branchCoverage=\"100\" isConstructor=\"false\" isStatic=\"false\" isGetter=\"true\" isSetter=\"false\">\r\n" +
"\t\t\t\t\t\t\t<MetadataToken>100663297</MetadataToken>\r\n" +
"\t\t\t\t\t\t\t<Name>System.Void MyTests.Tests.MyClass::PropertyFlagsButJustAMethod()</Name>\r\n" +
"\t\t\t\t\t\t\t<FileRef uid=\"1\" />\r\n" +
"\t\t\t\t\t\t\t<SequencePoints>\r\n" +
"\t\t\t\t\t\t\t\t<SequencePoint vc=\"0\" sl=\"21\" sc=\"3\" el=\"21\" ec=\"4\" />\r\n" +
"\t\t\t\t\t\t\t\t<SequencePoint vc=\"0\" sl=\"20\" sc=\"3\" el=\"20\" ec=\"4\" />\r\n" +
"\t\t\t\t\t\t\t\t<SequencePoint vc=\"0\" sl=\"19\" sc=\"3\" el=\"19\" ec=\"18\" />\r\n" +
"\t\t\t\t\t\t\t</SequencePoints>\r\n" +
"\t\t\t\t\t\t</Method>\r\n" +
"\t\t\t\t\t\t<Method visited=\"true\" cyclomaticComplexity=\"1\" sequenceCoverage=\"100\" branchCoverage=\"100\" isConstructor=\"\" isStatic=\"false\" isGetter=\"\" isSetter=\"\">\r\n" +
"\t\t\t\t\t\t\t<MetadataToken>100663297</MetadataToken>\r\n" +
"\t\t\t\t\t\t\t<Name>System.Void MyTests.Tests.MyClass::InvalidFlags()</Name>\r\n" +
"\t\t\t\t\t\t\t<FileRef uid=\"1\" />\r\n" +
"\t\t\t\t\t\t\t<SequencePoints>\r\n" +
"\t\t\t\t\t\t\t\t<SequencePoint vc=\"0\" sl=\"21\" sc=\"3\" el=\"21\" ec=\"4\" />\r\n" +
"\t\t\t\t\t\t\t\t<SequencePoint vc=\"0\" sl=\"20\" sc=\"3\" el=\"20\" ec=\"4\" />\r\n" +
"\t\t\t\t\t\t\t\t<SequencePoint vc=\"0\" sl=\"19\" sc=\"3\" el=\"19\" ec=\"18\" />\r\n" +
"\t\t\t\t\t\t\t</SequencePoints>\r\n" +
"\t\t\t\t\t\t</Method>\r\n" +
"\t\t\t\t\t</Methods>\r\n" +
"\t\t\t\t</Class>\r\n" +
"\t\t\t</Classes>\r\n" +
"\t\t</Module>\r\n" +
"\t</Modules>\r\n" +
"</CoverageSession>";

base.CreateCodeCoverageResults(xml);
}

[Test]
public void MethodName_GetterMethod_ReturnsExpectedGetterName()
{
string name = GetterMethod.Name;
string expectedName = "get_Count";
string expectedName = "System.Int32 MyTests.MyClass1::get_Count())";
Assert.AreEqual(expectedName, name);
}

Expand All @@ -76,7 +114,7 @@ public void MethodIsProperty_GetterMethod_ReturnsTrue()
public void MethodName_NameOfMethodWithPropertyFlagsButInvalidName_ReturnsMethodName()
{
string name = MethodWithPropertyFlagsButInvalidName.Name;
string expectedName = "PropertyFlagsButJustAMethod";
string expectedName = "System.Void MyTests.Tests.MyClass::PropertyFlagsButJustAMethod()";
Assert.AreEqual(expectedName, name);
}

Expand All @@ -88,7 +126,7 @@ public void MethodName_NameOfMethodWithPropertyFlagsButInvalidName_ReturnsMethod
public void MethodName_SetterMethod_ReturnsSetterMethodName()
{
string name = SetterMethod.Name;
string expectedName = "set_Count";
string expectedName = "System.Void MyTests.MyClass1::set_Count(System.Int32)";
Assert.AreEqual(expectedName, name);
}

Expand All @@ -107,7 +145,7 @@ public void MethodIsProperty_SetterMethod_ReturnsTrue()
public void MethodName_OrdinaryMethod_ReturnsMethodName()
{
string name = OrdinaryMethod.Name;
string expectedName = "get_NotAProperty";
string expectedName = "System.Void MyTests.MyClass1::get_NotAProperty())";
Assert.AreEqual(expectedName, name);
}

Expand Down
Expand Up @@ -155,14 +155,14 @@ public void NotVisitedSequencePointsCount_FirstMethod_ReturnsOne()
public void GetVisitedCodeLength_FirstMethod_ReturnsSummedLengthOfVisitedSequencePoints()
{
int length = FirstModuleFirstMethod.GetVisitedCodeLength();
Assert.AreEqual(3, length);
Assert.AreEqual(2, length);
}

[Test]
public void GetUnvisitedCodeLength_FirstMethod_ReturnsSummedLengthOfUnvisitedSequencePoints()
{
int length = FirstModuleFirstMethod.GetUnvisitedCodeLength();
Assert.AreEqual(4, length);
Assert.AreEqual(1, length);
}
}
}
Expand Up @@ -53,7 +53,7 @@ public void ModulesCount_MethodWithNoSequencePointsInModule_ReturnsOneModule()
public void MethodUnvisitedCodeLength_MethodWithNoSequencePoints_ReturnsBodySize()
{
int unvisitedCodeLength = FirstModuleFirstMethod.GetUnvisitedCodeLength();
int expectedUnvisitedCodeLength = 42;
int expectedUnvisitedCodeLength = 0;
Assert.AreEqual(expectedUnvisitedCodeLength, unvisitedCodeLength);
}
}
Expand Down

0 comments on commit 98c93a3

Please sign in to comment.