[NUI] Rebase develnui (DevelNUI only patches --> master) (#3910)
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Devel.Tests.Ubuntu / nunit.framework / Internal / Results / TestSuiteResult.cs
1 // ***********************************************************************
2 // Copyright (c) 2015 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 #if PARALLEL
32 using System.Collections.Concurrent;
33 #endif
34 using NUnit.Framework.Interfaces;
35 using System.Threading;
36 #if NETCF || NET_2_0
37 using NUnit.Compatibility;
38 #endif
39
40 namespace NUnit.Framework.Internal
41 {
42     /// <summary>
43     /// Represents the result of running a test suite
44     /// </summary>
45     public class TestSuiteResult : TestResult
46     {
47         private int _passCount = 0;
48         private int _failCount = 0;
49         private int _skipCount = 0;
50         private int _inconclusiveCount = 0;
51 #if PARALLEL
52         private ConcurrentQueue<ITestResult> _children;
53 #else
54         private List<ITestResult> _children;
55 #endif
56
57         /// <summary>
58         /// Construct a TestSuiteResult base on a TestSuite
59         /// </summary>
60         /// <param name="suite">The TestSuite to which the result applies</param>
61         public TestSuiteResult(TestSuite suite) : base(suite)
62         {
63 #if PARALLEL
64             _children = new ConcurrentQueue<ITestResult>();
65 #else
66             _children = new List<ITestResult>();
67 #endif
68         }
69
70 #region Overrides
71
72         /// <summary>
73         /// Gets the number of test cases that failed
74         /// when running the test and all its children.
75         /// </summary>
76         public override int FailCount
77         {
78             get
79             {
80 #if PARALLEL
81                 RwLock.EnterReadLock();
82 #endif
83                 try
84                 {
85                     return _failCount;
86                 }
87                 finally
88                 {
89 #if PARALLEL
90                     RwLock.ExitReadLock();
91 #endif
92                 }
93             }
94         }
95
96         /// <summary>
97         /// Gets the number of test cases that passed
98         /// when running the test and all its children.
99         /// </summary>
100         public override int PassCount
101         {
102             get
103             {
104 #if PARALLEL
105                 RwLock.EnterReadLock();
106 #endif
107                 try
108                 {
109                     return _passCount;
110                 }
111                 finally
112                 {
113 #if PARALLEL
114                     RwLock.ExitReadLock();
115 #endif
116                 }
117             }
118         }
119
120         /// <summary>
121         /// Gets the number of test cases that were skipped
122         /// when running the test and all its children.
123         /// </summary>
124         public override int SkipCount
125         {
126             get
127             {
128 #if PARALLEL
129                 RwLock.EnterReadLock();
130 #endif
131                 try
132                 {
133                     return _skipCount;
134                 }
135                 finally
136                 {
137 #if PARALLEL
138                     RwLock.ExitReadLock();
139 #endif
140                 }
141            }
142         }
143
144         /// <summary>
145         /// Gets the number of test cases that were inconclusive
146         /// when running the test and all its children.
147         /// </summary>
148         public override int InconclusiveCount
149         {
150             get
151             {
152 #if PARALLEL
153                 RwLock.EnterReadLock();
154 #endif
155                 try
156                 {
157                     return _inconclusiveCount;
158                 }
159                 finally
160                 {
161 #if PARALLEL
162                     RwLock.ExitReadLock();
163 #endif
164                 }
165             }
166         }
167
168         /// <summary>
169         /// Indicates whether this result has any child results.
170         /// </summary>
171         public override bool HasChildren
172         {
173             get
174             {
175 #if PARALLEL
176                 return !_children.IsEmpty;
177 #else
178                 return _children.Count != 0;
179 #endif
180             }
181         }
182
183         /// <summary>
184         /// Gets the collection of child results.
185         /// </summary>
186         public override IEnumerable<ITestResult> Children
187         {
188             get { return _children; }
189         }
190
191         #endregion
192
193         #region AddResult Method
194
195         /// <summary>
196         /// Adds a child result to this result, setting this result's
197         /// ResultState to Failure if the child result failed.
198         /// </summary>
199         /// <param name="result">The result to be added</param>
200         public virtual void AddResult(ITestResult result)
201         {
202 #if PARALLEL
203             var childrenAsConcurrentQueue = Children as ConcurrentQueue<ITestResult>;
204             if (childrenAsConcurrentQueue != null)
205                 childrenAsConcurrentQueue.Enqueue(result);
206             else
207 #endif
208             {
209                 var childrenAsIList = Children as IList<ITestResult>;
210                 if (childrenAsIList != null)
211                     childrenAsIList.Add(result);
212                 else
213                     throw new NotSupportedException("cannot add results to Children");
214
215             }
216
217 #if PARALLEL
218             RwLock.EnterWriteLock();
219 #endif
220             try
221             {
222                 // If this result is marked cancelled, don't change it
223                 if (ResultState != ResultState.Cancelled)
224                 {
225                     switch (result.ResultState.Status)
226                     {
227                         case TestStatus.Passed:
228
229                             if (ResultState.Status == TestStatus.Inconclusive)
230                                 SetResult(ResultState.Success);
231
232                             break;
233
234                         case TestStatus.Failed:
235
236
237                             if (ResultState.Status != TestStatus.Failed)
238                                 SetResult(ResultState.ChildFailure, CHILD_ERRORS_MESSAGE);
239
240                             break;
241
242                         case TestStatus.Skipped:
243
244                             if (result.ResultState.Label == "Ignored")
245                                 if (ResultState.Status == TestStatus.Inconclusive || ResultState.Status == TestStatus.Passed)
246                                     SetResult(ResultState.Ignored, CHILD_IGNORE_MESSAGE);
247
248                             break;
249                     }
250                 }
251
252                 InternalAssertCount += result.AssertCount;
253                 _passCount += result.PassCount;
254                 _failCount += result.FailCount;
255                 _skipCount += result.SkipCount;
256                 _inconclusiveCount += result.InconclusiveCount;
257             }
258             finally
259             {
260 #if PARALLEL
261                 RwLock.ExitWriteLock();
262 #endif
263             }
264         }
265
266         #endregion
267     }
268 }