[NUI] Rebase develnui (DevelNUI only patches --> master) (#3910)
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Devel.Tests.Ubuntu / nunit.framework / Internal / Tests / TestSuite.cs
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 #define PORTABLE
24 #define TIZEN
25 #define NUNIT_FRAMEWORK
26 #define NUNITLITE
27 #define NET_4_5
28 #define PARALLEL
29 using System;
30 using System.Collections.Generic;
31 using System.Reflection;
32 using NUnit.Framework.Interfaces;
33 using NUnit.Framework.Internal.Commands;
34
35 #if NET_4_0 || NET_4_5 || PORTABLE
36 using System.Threading.Tasks;
37 #endif
38
39 namespace NUnit.Framework.Internal
40 {
41     /// <summary>
42     /// TestSuite represents a composite test, which contains other tests.
43     /// </summary>
44     public class TestSuite : Test
45     {
46         #region Fields
47
48         /// <summary>
49         /// Our collection of child tests
50         /// </summary>
51         private List<ITest> tests = new List<ITest>();
52
53         #endregion
54
55         #region Constructors
56
57         /// <summary>
58         /// Initializes a new instance of the <see cref="TestSuite"/> class.
59         /// </summary>
60         /// <param name="name">The name of the suite.</param>
61         public TestSuite(string name) : base(name)
62         {
63             Arguments = new object[0];
64         }
65
66         /// <summary>
67         /// Initializes a new instance of the <see cref="TestSuite"/> class.
68         /// </summary>
69         /// <param name="parentSuiteName">Name of the parent suite.</param>
70         /// <param name="name">The name of the suite.</param>
71         public TestSuite(string parentSuiteName, string name)
72             : base(parentSuiteName, name)
73         {
74             Arguments = new object[0];
75         }
76
77         /// <summary>
78         /// Initializes a new instance of the <see cref="TestSuite"/> class.
79         /// </summary>
80         /// <param name="fixtureType">Type of the fixture.</param>
81         public TestSuite(ITypeInfo fixtureType)
82             : base(fixtureType)
83         {
84             Arguments = new object[0];
85         }
86
87         /// <summary>
88         /// Initializes a new instance of the <see cref="TestSuite"/> class.
89         /// </summary>
90         /// <param name="fixtureType">Type of the fixture.</param>
91         public TestSuite(Type fixtureType)
92             : base(new TypeWrapper(fixtureType))
93         {
94             Arguments = new object[0];
95         }
96
97         #endregion
98
99         #region Public Methods
100
101         /// <summary>
102         /// Sorts tests under this suite.
103         /// </summary>
104         public void Sort()
105         {
106             if (!MaintainTestOrder)
107             {
108                 this.tests.Sort();
109
110                 foreach (Test test in Tests)
111                 {
112                     TestSuite suite = test as TestSuite;
113                     if (suite != null)
114                         suite.Sort();
115                 }
116             }
117         }
118
119 #if false
120         /// <summary>
121         /// Sorts tests under this suite using the specified comparer.
122         /// </summary>
123         /// <param name="comparer">The comparer.</param>
124         public void Sort(IComparer comparer)
125         {
126             this.tests.Sort(comparer);
127
128             foreach( Test test in Tests )
129             {
130                 TestSuite suite = test as TestSuite;
131                 if ( suite != null )
132                     suite.Sort(comparer);
133             }
134         }
135 #endif
136
137         /// <summary>
138         /// Adds a test to the suite.
139         /// </summary>
140         /// <param name="test">The test.</param>
141         public void Add(Test test)
142         {
143             test.Parent = this;
144             tests.Add(test);
145         }
146
147         #endregion
148
149         #region Properties
150
151         /// <summary>
152         /// Gets this test's child tests
153         /// </summary>
154         /// <value>The list of child tests</value>
155         public override IList<ITest> Tests
156         {
157             get { return tests; }
158         }
159
160         /// <summary>
161         /// Gets a count of test cases represented by
162         /// or contained under this test.
163         /// </summary>
164         /// <value></value>
165         public override int TestCaseCount
166         {
167             get
168             {
169                 int count = 0;
170
171                 foreach (Test test in Tests)
172                 {
173                     count += test.TestCaseCount;
174                 }
175                 return count;
176             }
177         }
178
179         /// <summary>
180         /// The arguments to use in creating the fixture
181         /// </summary>
182         public object[] Arguments { get; internal set; }
183
184         /// <summary>
185         /// Set to true to suppress sorting this suite's contents
186         /// </summary>
187         protected bool MaintainTestOrder { get; set; }
188
189         #endregion
190
191         #region Test Overrides
192
193         /// <summary>
194         /// Overridden to return a TestSuiteResult.
195         /// </summary>
196         /// <returns>A TestResult for this test.</returns>
197         public override TestResult MakeTestResult()
198         {
199             return new TestSuiteResult(this);
200         }
201
202         /// <summary>
203         /// Gets a bool indicating whether the current test
204         /// has any descendant tests.
205         /// </summary>
206         public override bool HasChildren
207         {
208             get
209             {
210                 return tests.Count > 0;
211             }
212         }
213
214         /// <summary>
215         /// Gets the name used for the top-level element in the
216         /// XML representation of this test
217         /// </summary>
218         public override string XmlElementName
219         {
220             get { return "test-suite"; }
221         }
222
223         /// <summary>
224         /// Returns an XmlNode representing the current result after
225         /// adding it as a child of the supplied parent node.
226         /// </summary>
227         /// <param name="parentNode">The parent node.</param>
228         /// <param name="recursive">If true, descendant results are included</param>
229         /// <returns></returns>
230         public override TNode AddToXml(TNode parentNode, bool recursive)
231         {
232             TNode thisNode = parentNode.AddElement("test-suite");
233             thisNode.AddAttribute("type", this.TestType);
234
235             PopulateTestNode(thisNode, recursive);
236             thisNode.AddAttribute("testcasecount", this.TestCaseCount.ToString());
237
238
239             if (recursive)
240                 foreach (Test test in this.Tests)
241                     test.AddToXml(thisNode, recursive);
242
243             return thisNode;
244         }
245
246         #endregion
247
248         #region Helper Methods
249
250         /// <summary>
251         /// Check that setup and teardown methods marked by certain attributes
252         /// meet NUnit's requirements and mark the tests not runnable otherwise.
253         /// </summary>
254         /// <param name="attrType">The attribute type to check for</param>
255         protected void CheckSetUpTearDownMethods(Type attrType)
256         {
257             foreach (MethodInfo method in Reflect.GetMethodsWithAttribute(TypeInfo.Type, attrType, true))
258                 if (method.IsAbstract ||
259                      !method.IsPublic && !method.IsFamily ||
260                      method.GetParameters().Length > 0 ||
261                      method.ReturnType != typeof(void)
262 #if NET_4_0 || NET_4_5 || PORTABLE
263                      &&
264                      method.ReturnType != typeof(Task)
265 #endif
266                     )
267                 {
268                     this.Properties.Set(
269                         PropertyNames.SkipReason,
270                         string.Format("Invalid signature for SetUp or TearDown method: {0}", method.Name));
271                     this.RunState = RunState.NotRunnable;
272                     break;
273                 }
274         }
275
276         #endregion
277     }
278 }