~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/Analysis/CodeCoverage/Test/Coverage/CodeCoverageResultsPropertyFlagsTestFixture.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
 
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
 
3
 
 
4
using System;
 
5
using System.IO;
 
6
using ICSharpCode.CodeCoverage;
 
7
using NUnit.Framework;
 
8
 
 
9
namespace ICSharpCode.CodeCoverage.Tests.Coverage
 
10
{
 
11
        /// <summary>
 
12
        /// Tests that property methods (e.g. get_SomeValue) are identified by the CodeCoverageResults class
 
13
        /// via the flags attribute in the code coverage results file.
 
14
        /// </summary>
 
15
        [TestFixture]
 
16
        public class CodeCoverageResultsPropertyFlagsTestFixture : CodeCoverageResultsTestsBase
 
17
        {
 
18
                [SetUp]
 
19
                public void SetUpFixture()
 
20
                {
 
21
                        string xml = 
 
22
                                "<PartCoverReport ver=\"1.0.2796.35184\">\r\n" +
 
23
                                "  <File id=\"1\" url=\"d:\\Projects\\test\\TestFixture1.cs\" />\r\n" +
 
24
                                "  <Assembly id=\"1\" name=\"MyTests\" module=\"C:\\Projects\\Test\\MyTests\\bin\\MyTests.DLL\" domain=\"test-domain-MyTests.dll\" domainIdx=\"1\" />\r\n" +
 
25
                                "  <Type asmref=\"1\" name=\"MyTests.Class1\" flags=\"2606412\">\r\n" +
 
26
                                "    <Method name=\"set_Count\" sig=\"void  (int)\" flags=\"2182\" iflags=\"0\">\r\n" +
 
27
                                "      <pt visit=\"0\" pos=\"9\" len=\"1\" fid=\"1\" sl=\"34\" sc=\"4\" el=\"34\" ec=\"5\" />\r\n" +
 
28
                                "      <pt visit=\"0\" pos=\"1\" len=\"8\" fid=\"1\" sl=\"33\" sc=\"5\" el=\"33\" ec=\"12\" />\r\n" +
 
29
                                "      <pt visit=\"0\" pos=\"0\" len=\"1\" fid=\"1\" sl=\"32\" sc=\"8\" el=\"32\" ec=\"9\" />\r\n" +
 
30
                                "    </Method>\r\n" +
 
31
                                "    <Method name=\"get_Count\" sig=\"int  ()\" flags=\"2182\" iflags=\"0\">\r\n" +
 
32
                                "      <pt visit=\"0\" pos=\"6\" len=\"2\" fid=\"1\" sl=\"31\" sc=\"4\" el=\"31\" ec=\"5\" />\r\n" +
 
33
                                "      <pt visit=\"0\" pos=\"1\" len=\"5\" fid=\"1\" sl=\"30\" sc=\"5\" el=\"30\" ec=\"15\" />\r\n" +
 
34
                                "      <pt visit=\"0\" pos=\"0\" len=\"1\" fid=\"1\" sl=\"29\" sc=\"8\" el=\"29\" ec=\"9\" />\r\n" +
 
35
                                "    </Method>\r\n" +
 
36
                                "    <Method name=\"get_NotAProperty\" sig=\"void  ()\" flags=\"134\" iflags=\"0\">\r\n" +
 
37
                                "      <pt visit=\"0\" pos=\"1\" len=\"1\" fid=\"1\" sl=\"26\" sc=\"3\" el=\"26\" ec=\"4\" />\r\n" +
 
38
                                "      <pt visit=\"0\" pos=\"0\" len=\"1\" fid=\"1\" sl=\"25\" sc=\"3\" el=\"25\" ec=\"4\" />\r\n" +
 
39
                                "    </Method>\r\n" +
 
40
                                "    <Method name=\"PropertyFlagsButJustAMethod\" sig=\"void  ()\" flags=\"2182\" iflags=\"0\">\r\n" +
 
41
                                "      <pt visit=\"0\" pos=\"8\" len=\"2\" fid=\"1\" sl=\"22\" sc=\"3\" el=\"22\" ec=\"4\" />\r\n" +
 
42
                                "      <pt visit=\"0\" pos=\"7\" len=\"1\" fid=\"1\" sl=\"21\" sc=\"3\" el=\"21\" ec=\"4\" />\r\n" +
 
43
                                "      <pt visit=\"0\" pos=\"0\" len=\"7\" fid=\"1\" sl=\"20\" sc=\"3\" el=\"20\" ec=\"18\" />\r\n" +
 
44
                                "    </Method>\r\n" +
 
45
                                "    <Method name=\"InvalidFlags\" sig=\"void  ()\" flags=\"\" iflags=\"0\">\r\n" +
 
46
                                "      <pt visit=\"0\" pos=\"8\" len=\"2\" fid=\"1\" sl=\"22\" sc=\"3\" el=\"22\" ec=\"4\" />\r\n" +
 
47
                                "      <pt visit=\"0\" pos=\"7\" len=\"1\" fid=\"1\" sl=\"21\" sc=\"3\" el=\"21\" ec=\"4\" />\r\n" +
 
48
                                "      <pt visit=\"0\" pos=\"0\" len=\"7\" fid=\"1\" sl=\"20\" sc=\"3\" el=\"20\" ec=\"18\" />\r\n" +
 
49
                                "    </Method>\r\n" +
 
50
                                "  </Type>\r\n" +
 
51
                                "</PartCoverReport>";
 
52
 
 
53
                        base.CreateCodeCoverageResults(xml);                    
 
54
                }
 
55
                
 
56
                [Test]
 
57
                public void MethodName_GetterMethod_ReturnsExpectedGetterName()
 
58
                {
 
59
                        string name = GetterMethod.Name;
 
60
                        string expectedName = "get_Count";
 
61
                        Assert.AreEqual(expectedName, name);
 
62
                }
 
63
                
 
64
                CodeCoverageMethod GetterMethod {
 
65
                        get { return base.FirstModuleSecondMethod; }
 
66
                }
 
67
                
 
68
                [Test]
 
69
                public void MethodIsProperty_GetterMethod_ReturnsTrue()
 
70
                {
 
71
                        bool result = GetterMethod.IsProperty;
 
72
                        Assert.IsTrue(result);
 
73
                }
 
74
                
 
75
                [Test]
 
76
                public void MethodName_NameOfMethodWithPropertyFlagsButInvalidName_ReturnsMethodName()
 
77
                {
 
78
                        string name = MethodWithPropertyFlagsButInvalidName.Name;
 
79
                        string expectedName = "PropertyFlagsButJustAMethod";
 
80
                        Assert.AreEqual(expectedName, name);
 
81
                }
 
82
                
 
83
                CodeCoverageMethod MethodWithPropertyFlagsButInvalidName {
 
84
                        get { return FirstModule.Methods[3]; }
 
85
                }
 
86
                
 
87
                [Test]
 
88
                public void MethodName_SetterMethod_ReturnsSetterMethodName()
 
89
                {
 
90
                        string name = SetterMethod.Name;
 
91
                        string expectedName = "set_Count";
 
92
                        Assert.AreEqual(expectedName, name);
 
93
                }
 
94
                
 
95
                CodeCoverageMethod SetterMethod {
 
96
                        get { return FirstModuleFirstMethod; }
 
97
                }
 
98
                
 
99
                [Test]
 
100
                public void MethodIsProperty_SetterMethod_ReturnsTrue()
 
101
                {
 
102
                        bool result = SetterMethod.IsProperty;
 
103
                        Assert.IsTrue(result);
 
104
                }               
 
105
                
 
106
                [Test]
 
107
                public void MethodName_OrdinaryMethod_ReturnsMethodName()
 
108
                {
 
109
                        string name = OrdinaryMethod.Name;
 
110
                        string expectedName = "get_NotAProperty";
 
111
                        Assert.AreEqual(expectedName, name);
 
112
                }
 
113
                
 
114
                CodeCoverageMethod OrdinaryMethod {
 
115
                        get { return FirstModule.Methods[2]; }
 
116
                }
 
117
                
 
118
                [Test]
 
119
                public void MethodIsProperty_OrdinaryMethod_ReturnsFalse()
 
120
                {
 
121
                        bool result = OrdinaryMethod.IsProperty;
 
122
                        Assert.IsFalse(result);
 
123
                }
 
124
                
 
125
                /// <summary>
 
126
                /// Only methods with get_ or set_ as the start of the name are marked as properties.
 
127
                /// </summary>
 
128
                [Test]
 
129
                public void MethodIsProperty_MethodWithPropertyFlagButInvalidName_IsNotMarkedAsProperty()
 
130
                {
 
131
                        bool result = MethodWithPropertyFlagsButInvalidName.IsProperty;
 
132
                        Assert.IsFalse(result);
 
133
                }
 
134
        }
 
135
}