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

« back to all changes in this revision

Viewing changes to src/framework/Api/TestPackage.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.IO;
26
 
using System.Collections;
27
 
using System.Collections.Specialized;
28
 
 
29
 
namespace NUnit.Core
30
 
{
31
 
    /// <summary>
32
 
    /// Represents the manner in which test assemblies are
33
 
    /// distributed across processes.
34
 
    /// </summary>
35
 
    public enum ProcessModel
36
 
    {
37
 
        /// <summary>
38
 
        /// Use the default setting, depending on the runner
39
 
        /// and the nature of the tests to be loaded.
40
 
        /// </summary>
41
 
        Default,
42
 
        /// <summary>
43
 
        /// Run tests directly in the NUnit process
44
 
        /// </summary>
45
 
        Single,
46
 
        /// <summary>
47
 
        /// Run tests in a single separate process
48
 
        /// </summary>
49
 
        Separate,
50
 
        /// <summary>
51
 
        /// Run tests in a separate process per assembly
52
 
        /// </summary>
53
 
        Multiple
54
 
    }
55
 
 
56
 
    /// <summary>
57
 
    /// Represents the manner in which test assemblies use
58
 
    /// AppDomains to provide isolation
59
 
    /// </summary>
60
 
    public enum DomainUsage
61
 
    {
62
 
        /// <summary>
63
 
        /// Use the default setting, depending on the runner
64
 
        /// and the nature of the tests to be loaded.
65
 
        /// </summary>
66
 
        Default,
67
 
        /// <summary>
68
 
        /// Don't create a test domain - run in the primary AppDomain
69
 
        /// </summary>
70
 
        None,
71
 
        /// <summary>
72
 
        /// Run tests in a single separate test domain
73
 
        /// </summary>
74
 
        Single,
75
 
        /// <summary>
76
 
        /// Run tests in a separate domain per assembly
77
 
        /// </summary>
78
 
        Multiple
79
 
    }
80
 
 
81
 
    /// <summary>
82
 
        /// TestPackage holds information about a set of tests to
83
 
        /// be loaded by a TestRunner. It may represent a single
84
 
        /// assembly or a set of assemblies. It supports selection
85
 
        /// of a single test fixture for loading.
86
 
        /// </summary>
87
 
        [Serializable]
88
 
        public class TestPackage
89
 
        {
90
 
                private string name;
91
 
                private string fullName;
92
 
 
93
 
                private ListDictionary settings = new ListDictionary();
94
 
 
95
 
                private string basePath;
96
 
                private string configFile;
97
 
                private string binPath;
98
 
                private bool autoBinPath;
99
 
 
100
 
                private ArrayList assemblies;
101
 
                private string testName;
102
 
                private bool isSingleAssembly;
103
 
 
104
 
 
105
 
                /// <summary>
106
 
                /// Construct a package, specifying the name of the package.
107
 
                /// If the package name is an assembly file type (dll or exe)
108
 
                /// then the resulting package represents a single assembly.
109
 
                /// Otherwise it is a container for multiple assemblies.
110
 
                /// </summary>
111
 
                /// <param name="name">The name of the package</param>
112
 
                public TestPackage( string name )
113
 
                {
114
 
                        this.fullName = name;
115
 
                        this.name = Path.GetFileName( name );
116
 
                        this.assemblies = new ArrayList();
117
 
                        if ( IsAssemblyFileType( name ) )
118
 
                        {
119
 
                                this.isSingleAssembly = true;
120
 
                                this.assemblies.Add( name );
121
 
                        }
122
 
                }
123
 
 
124
 
                /// <summary>
125
 
                /// Construct a package, specifying the name to be used
126
 
                /// and a list of assemblies.
127
 
                /// </summary>
128
 
                /// <param name="name">The package name, used to name the top-level test node</param>
129
 
                /// <param name="assemblies">The list of assemblies comprising the package</param>
130
 
                public TestPackage( string name, IList assemblies )
131
 
                {
132
 
                        this.fullName = name;
133
 
                        this.name = Path.GetFileName( name );
134
 
                        this.assemblies = new ArrayList( assemblies );
135
 
                        this.isSingleAssembly = false;
136
 
                }
137
 
 
138
 
                /// <summary>
139
 
                /// Gets the name of the package
140
 
                /// </summary>
141
 
                public string Name
142
 
                {
143
 
                        get { return name; }
144
 
                }
145
 
 
146
 
                /// <summary>
147
 
                /// Gets the full name of the package, which is usually
148
 
                /// the path to the NUnit project used to create the it
149
 
                /// </summary>
150
 
                public string FullName
151
 
                {
152
 
                        get { return fullName; }
153
 
                }
154
 
 
155
 
                /// <summary>
156
 
                /// The BasePath to be used in loading the assemblies
157
 
                /// </summary>
158
 
                public string BasePath
159
 
                {
160
 
                        get { return basePath; }
161
 
                        set { basePath = value; }
162
 
                }
163
 
 
164
 
                /// <summary>
165
 
                /// The configuration file to be used
166
 
                /// </summary>
167
 
                public string ConfigurationFile
168
 
                {
169
 
                        get { return configFile; }
170
 
                        set { configFile = value; }
171
 
                }
172
 
 
173
 
                /// <summary>
174
 
                /// Addditional directories to be probed when loading assemblies
175
 
                /// </summary>
176
 
                public string PrivateBinPath
177
 
                {
178
 
                        get { return binPath; }
179
 
                        set { binPath = value; }
180
 
                }
181
 
 
182
 
                /// <summary>
183
 
                /// Indicates whether the probing path should be generated
184
 
                /// automatically based on the list of assemblies.
185
 
                /// </summary>
186
 
                public bool AutoBinPath
187
 
                {
188
 
                        get { return autoBinPath; }
189
 
                        set { autoBinPath = value; }
190
 
                }
191
 
 
192
 
                /// <summary>
193
 
                /// Assemblies to be loaded. At least one must be specified.
194
 
                /// </summary>
195
 
                public IList Assemblies
196
 
                {
197
 
                        get { return assemblies; }
198
 
                }
199
 
 
200
 
                /// <summary>
201
 
                /// Return true if the package represents a single assembly.
202
 
                /// No root node is displayed in that case.
203
 
                /// </summary>
204
 
                public bool IsSingleAssembly
205
 
                {
206
 
                        get { return isSingleAssembly; }
207
 
                }
208
 
 
209
 
                /// <summary>
210
 
                /// Fully qualified name of test to be loaded. If not 
211
 
                /// specified, all the tests in the assemblies are loaded.
212
 
                /// </summary>
213
 
                public string TestName
214
 
                {
215
 
                        get { return testName; }
216
 
                        set { testName = value; }
217
 
                }
218
 
 
219
 
                /// <summary>
220
 
                /// Gets the dictionary of settings for this TestPackage
221
 
                /// </summary>
222
 
                public IDictionary Settings
223
 
                {
224
 
                        get { return settings; }
225
 
                }
226
 
 
227
 
        /// <summary>
228
 
        /// Return the value of a setting or a default.
229
 
        /// </summary>
230
 
        /// <param name="name">The name of the setting</param>
231
 
        /// <param name="defaultSetting">The default value</param>
232
 
        /// <returns></returns>
233
 
        public object GetSetting(string name, object defaultSetting)
234
 
        {
235
 
            object setting = settings[name];
236
 
 
237
 
            return setting == null ? defaultSetting : setting;
238
 
        }
239
 
 
240
 
        /// <summary>
241
 
        /// Return the value of a string setting or a default.
242
 
        /// </summary>
243
 
        /// <param name="name">The name of the setting</param>
244
 
        /// <param name="defaultSetting">The default value</param>
245
 
        /// <returns></returns>
246
 
        public string GetSetting(string name, string defaultSetting)
247
 
        {
248
 
            object setting = settings[name];
249
 
 
250
 
            return setting == null ? defaultSetting : (string)setting;
251
 
        }
252
 
 
253
 
        /// <summary>
254
 
        /// Return the value of a bool setting or a default.
255
 
        /// </summary>
256
 
        /// <param name="name">The name of the setting</param>
257
 
        /// <param name="defaultSetting">The default value</param>
258
 
        /// <returns></returns>
259
 
        public bool GetSetting(string name, bool defaultSetting)
260
 
        {
261
 
            object setting = settings[name];
262
 
 
263
 
            return setting == null ? defaultSetting : (bool)setting;
264
 
        }
265
 
 
266
 
        /// <summary>
267
 
        /// Return the value of an int setting or a default.
268
 
        /// </summary>
269
 
        /// <param name="name">The name of the setting</param>
270
 
        /// <param name="defaultSetting">The default value</param>
271
 
        /// <returns></returns>
272
 
        public int GetSetting(string name, int defaultSetting)
273
 
        {
274
 
            object setting = settings[name];
275
 
 
276
 
            return setting == null ? defaultSetting : (int)setting;
277
 
        }
278
 
 
279
 
        /// <summary>
280
 
        /// Return the value of a enum setting or a default.
281
 
        /// </summary>
282
 
        /// <param name="name">The name of the setting</param>
283
 
        /// <param name="defaultSetting">The default value</param>
284
 
        /// <returns></returns>
285
 
        public System.Enum GetSetting(string name, System.Enum defaultSetting)
286
 
        {
287
 
            object setting = settings[name];
288
 
 
289
 
            return setting == null ? defaultSetting : (System.Enum)setting;
290
 
        }
291
 
 
292
 
        private static bool IsAssemblyFileType(string path)
293
 
                {
294
 
                        string extension = Path.GetExtension( path ).ToLower();
295
 
                        return extension == ".dll" || extension == ".exe";
296
 
                }
297
 
        }
298
 
}