~a-schlapsi/nunit-3.0/linux-makefile

« back to all changes in this revision

Viewing changes to src/framework/Api/TestInfo.cs

  • Committer: Andreas Schlapsi
  • Date: 2010-01-23 23:14:05 UTC
  • mfrom: (18.1.137 work)
  • Revision ID: a.schlapsi@gmx.at-20100123231405-17deqoh18nfnbq1j
Merged with trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// ***********************************************************************
2
 
// Copyright (c) 2007 Charlie Poole
3
 
//
4
 
// Permission is hereby granted, free of charge, to any person obtaining
5
 
// a copy of this software and associated documentation files (the
6
 
// "Software"), to deal in the Software without restriction, including
7
 
// without limitation the rights to use, copy, modify, merge, publish,
8
 
// distribute, sublicense, and/or sell copies of the Software, and to
9
 
// permit persons to whom the Software is furnished to do so, subject to
10
 
// the following conditions:
11
 
// 
12
 
// The above copyright notice and this permission notice shall be
13
 
// included in all copies or substantial portions of the Software.
14
 
// 
15
 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
 
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
 
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
 
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
 
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
 
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
 
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
 
// ***********************************************************************
23
 
 
24
 
using System;
25
 
using System.Collections;
26
 
using System.Collections.Specialized;
27
 
 
28
 
namespace NUnit.Core
29
 
{
30
 
        /// <summary>
31
 
        /// TestInfo holds common info about a test. It represents only
32
 
        /// a single test or a suite and contains no references to other
33
 
        /// tests. Since it is informational only, it can easily be passed
34
 
        /// around using .Net remoting.
35
 
        /// 
36
 
        /// TestInfo is used directly in all EventListener events and in
37
 
        /// TestResults. It contains an ID, which can be used by a 
38
 
        /// runner to locate the actual test.
39
 
        /// 
40
 
        /// TestInfo also serves as the base class for TestNode, which
41
 
        /// adds hierarchical information and is used in client code to
42
 
        /// maintain a visible image of the structure of the tests.
43
 
        /// </summary>
44
 
        [Serializable]
45
 
        public class TestInfo : ITest
46
 
        {
47
 
                #region Instance Variables
48
 
                /// <summary>
49
 
                /// TestName that identifies this test
50
 
                /// </summary>
51
 
                private TestName testName;
52
 
 
53
 
                private string testType;
54
 
 
55
 
        private RunState runState;
56
 
 
57
 
                /// <summary>
58
 
                /// Reason for not running the test
59
 
                /// </summary>
60
 
                private string ignoreReason;
61
 
 
62
 
                /// <summary>
63
 
                /// Number of test cases in this test or suite
64
 
                /// </summary>
65
 
                private int testCaseCount;
66
 
 
67
 
                /// <summary>
68
 
                /// True if this is a suite
69
 
                /// </summary>
70
 
                private bool isSuite;
71
 
 
72
 
                /// <summary>
73
 
                /// The test description
74
 
                /// </summary>
75
 
                private string description;
76
 
 
77
 
                /// <summary>
78
 
                /// A list of all the categories assigned to a test
79
 
                /// </summary>
80
 
                private ArrayList categories = new ArrayList();
81
 
 
82
 
                /// <summary>
83
 
                /// A dictionary of properties, used to add information
84
 
                /// to tests without requiring the class to change.
85
 
                /// </summary>
86
 
                private ListDictionary properties = new ListDictionary();
87
 
 
88
 
                #endregion
89
 
 
90
 
                #region Constructors
91
 
                /// <summary>
92
 
                /// Construct from an ITest
93
 
                /// </summary>
94
 
                /// <param name="test">Test from which a TestNode is to be constructed</param>
95
 
                public TestInfo( ITest test )
96
 
                {
97
 
                        this.testName = (TestName)test.TestName.Clone();
98
 
                        this.testType = test.TestType;
99
 
 
100
 
            this.runState = test.RunState;
101
 
                        this.ignoreReason = test.IgnoreReason;
102
 
                        this.description = test.Description;
103
 
                        this.isSuite = test.IsSuite;
104
 
 
105
 
                        if (test.Categories != null) 
106
 
                                this.categories.AddRange(test.Categories);
107
 
                        if (test.Properties != null)
108
 
                        {
109
 
                                this.properties = new ListDictionary();
110
 
                                foreach( DictionaryEntry entry in test.Properties )
111
 
                                        this.properties.Add( entry.Key, entry.Value );
112
 
                        }
113
 
 
114
 
                        this.testCaseCount = test.TestCount;
115
 
                }
116
 
 
117
 
                /// <summary>
118
 
                /// Construct as a parent to multiple tests.
119
 
                /// </summary>
120
 
                /// <param name="testName">The name to use for the new test</param>
121
 
                /// <param name="tests">An array of child tests</param>
122
 
                public TestInfo( TestName testName, ITest[] tests )
123
 
                {
124
 
                        this.testName = testName;
125
 
                        this.testType = "Test Project";
126
 
 
127
 
            this.runState = RunState.Runnable;
128
 
                        this.ignoreReason = null;
129
 
                        this.description = null;
130
 
                        this.isSuite = true;
131
 
 
132
 
            if ( tests != null )
133
 
                            foreach( ITest test in tests )
134
 
                                this.testCaseCount += test.TestCount;
135
 
                }
136
 
 
137
 
                /// <summary>
138
 
                /// Construct given a test name
139
 
                /// </summary>
140
 
                /// <param name="testName">The TestName for the new test</param>
141
 
                public TestInfo( TestName testName ) : this( testName, null) { }
142
 
                #endregion
143
 
 
144
 
                #region Properties
145
 
                /// <summary>
146
 
                /// Gets the completely specified name of the test
147
 
                /// encapsulated in a TestName object.
148
 
                /// </summary>
149
 
                public TestName TestName
150
 
                {
151
 
                        get { return testName; }
152
 
                }
153
 
 
154
 
                /// <summary>
155
 
                /// Gets a string representing the kind of test this
156
 
                /// object represents for display purposes.
157
 
                /// </summary>
158
 
                public string TestType
159
 
                {
160
 
                        get { return testType; }
161
 
                }
162
 
 
163
 
                /// <summary>
164
 
                /// The test description 
165
 
                /// </summary>
166
 
                public string Description
167
 
                {
168
 
                        get { return description; }
169
 
                        set { description = value; }
170
 
                }
171
 
 
172
 
                /// <summary>
173
 
                /// Gets the RunState for this test
174
 
                /// </summary>
175
 
        public RunState RunState
176
 
        {
177
 
            get { return runState; }
178
 
            set { runState = value; }
179
 
        }
180
 
 
181
 
                /// <summary>
182
 
                /// The reason for ignoring a test
183
 
                /// </summary>
184
 
                public string IgnoreReason
185
 
                {
186
 
                        get { return ignoreReason; }
187
 
                        set { ignoreReason = value; }
188
 
                }
189
 
 
190
 
                /// <summary>
191
 
                /// Count of test cases in this test.
192
 
                /// </summary>
193
 
                public int TestCount
194
 
                { 
195
 
                        get { return testCaseCount; } 
196
 
                }
197
 
 
198
 
                /// <summary>
199
 
                ///  Gets the parent test of this test
200
 
                /// </summary>
201
 
                public virtual ITest Parent
202
 
                {
203
 
                        get { return null; }
204
 
                }
205
 
 
206
 
                /// <summary>
207
 
                /// Gets a list of the categories applied to this test
208
 
                /// </summary>
209
 
                public IList Categories 
210
 
                {
211
 
                        get { return categories; }
212
 
                }
213
 
 
214
 
                /// <summary>
215
 
                /// Gets a list of any child tests
216
 
                /// </summary>
217
 
                public virtual IList Tests
218
 
                {
219
 
                        get { return null; }
220
 
                }
221
 
 
222
 
                /// <summary>
223
 
                /// True if this is a suite, false if a test case
224
 
                /// </summary>
225
 
                public bool IsSuite
226
 
                {
227
 
                        get { return isSuite; }
228
 
                }
229
 
 
230
 
                /// <summary>
231
 
                /// Gets the Properties dictionary for this test
232
 
                /// </summary>
233
 
                public IDictionary Properties
234
 
                {
235
 
                        get 
236
 
                        {
237
 
                                if ( properties == null )
238
 
                                        properties = new ListDictionary();
239
 
 
240
 
                                return properties; 
241
 
                        }
242
 
                }
243
 
                #endregion
244
 
 
245
 
        #region Methods
246
 
                /// <summary>
247
 
                /// Counts the test cases that would be run if this
248
 
                /// test were executed using the provided filter.
249
 
                /// </summary>
250
 
                /// <param name="filter">The filter to apply</param>
251
 
                /// <returns>A count of test cases</returns>
252
 
        public virtual int CountTestCases(TestFilter filter)
253
 
        {
254
 
            if (filter.IsEmpty)
255
 
                return TestCount;
256
 
 
257
 
            if (!isSuite)
258
 
                return filter.Pass(this) ? 1 : 0;
259
 
 
260
 
            int count = 0;
261
 
            if (filter.Pass(this))
262
 
            {
263
 
                foreach (ITest test in Tests)
264
 
                {
265
 
                    count += test.CountTestCases(filter);
266
 
                }
267
 
            }
268
 
            return count;
269
 
        }
270
 
        #endregion
271
 
    }
272
 
}