[NUI] Rebase develnui (DevelNUI only patches --> master) (#3910)
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Devel.Tests.Ubuntu / nunit.framework / Interfaces / ResultState.cs
1 // ***********************************************************************
2 // Copyright (c) 2007-2014 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.Text;
30
31 namespace NUnit.Framework.Interfaces
32 {
33     /// <summary>
34     /// The ResultState class represents the outcome of running a test.
35     /// It contains two pieces of information. The Status of the test
36     /// is an enum indicating whether the test passed, failed, was
37     /// skipped or was inconclusive. The Label provides a more
38     /// detailed breakdown for use by client runners.
39     /// </summary>
40     public class ResultState
41     {
42         #region Constructors
43
44         /// <summary>
45         /// Initializes a new instance of the <see cref="ResultState"/> class.
46         /// </summary>
47         /// <param name="status">The TestStatus.</param>
48         public ResultState(TestStatus status) : this (status, string.Empty, FailureSite.Test)
49         {
50         }
51
52         /// <summary>
53         /// Initializes a new instance of the <see cref="ResultState"/> class.
54         /// </summary>
55         /// <param name="status">The TestStatus.</param>
56         /// <param name="label">The label.</param>
57         public ResultState(TestStatus status, string label) : this (status, label, FailureSite.Test)
58         {
59         }
60
61         /// <summary>
62         /// Initializes a new instance of the <see cref="ResultState"/> class.
63         /// </summary>
64         /// <param name="status">The TestStatus.</param>
65         /// <param name="site">The stage at which the result was produced</param>
66         public ResultState(TestStatus status, FailureSite site) : this(status, string.Empty, site)
67         {
68         }
69
70         /// <summary>
71         /// Initializes a new instance of the <see cref="ResultState"/> class.
72         /// </summary>
73         /// <param name="status">The TestStatus.</param>
74         /// <param name="label">The label.</param>
75         /// <param name="site">The stage at which the result was produced</param>
76         public ResultState(TestStatus status, string label, FailureSite site)
77         {
78             Status = status;
79             Label = label == null ? string.Empty : label;
80             Site = site;
81         }
82
83         #endregion
84
85         #region Predefined ResultStates
86
87         /// <summary>
88         /// The result is inconclusive
89         /// </summary>
90         public readonly static ResultState Inconclusive = new ResultState(TestStatus.Inconclusive);
91         
92         /// <summary>
93         /// The test has been skipped. 
94         /// </summary>
95         public readonly static ResultState Skipped = new ResultState(TestStatus.Skipped);
96
97         /// <summary>
98         /// The test has been ignored.
99         /// </summary>
100         public readonly static ResultState Ignored = new ResultState(TestStatus.Skipped, "Ignored");
101
102         /// <summary>
103         /// The test was skipped because it is explicit
104         /// </summary>
105         public readonly static ResultState Explicit = new ResultState(TestStatus.Skipped, "Explicit");
106
107         /// <summary>
108         /// The test succeeded
109         /// </summary>
110         public readonly static ResultState Success = new ResultState(TestStatus.Passed);
111
112         /// <summary>
113         /// The test failed
114         /// </summary>
115         public readonly static ResultState Failure = new ResultState(TestStatus.Failed);
116
117         /// <summary>
118         /// The test encountered an unexpected exception
119         /// </summary>
120         public readonly static ResultState Error = new ResultState(TestStatus.Failed, "Error");
121
122         /// <summary>
123         /// The test was cancelled by the user
124         /// </summary>
125         public readonly static ResultState Cancelled = new ResultState(TestStatus.Failed, "Cancelled");
126
127         /// <summary>
128         /// The test was not runnable.
129         /// </summary>
130         public readonly static ResultState NotRunnable = new ResultState(TestStatus.Failed, "Invalid");
131
132         /// <summary>
133         /// A suite failed because one or more child tests failed or had errors
134         /// </summary>
135         public readonly static ResultState ChildFailure = ResultState.Failure.WithSite(FailureSite.Child);
136
137         /// <summary>
138         /// A suite failed in its OneTimeSetUp
139         /// </summary>
140         public readonly static ResultState SetUpFailure = ResultState.Failure.WithSite(FailureSite.SetUp);
141
142         /// <summary>
143         /// A suite had an unexpected exception in its OneTimeSetUp
144         /// </summary>
145         public readonly static ResultState SetUpError = ResultState.Error.WithSite(FailureSite.SetUp);
146
147         /// <summary>
148         /// A suite had an unexpected exception in its OneTimeDown
149         /// </summary>
150         public readonly static ResultState TearDownError = ResultState.Error.WithSite(FailureSite.TearDown);
151
152         #endregion
153
154         #region Properties
155
156         /// <summary>
157         /// Gets the TestStatus for the test.
158         /// </summary>
159         /// <value>The status.</value>
160         public TestStatus Status { get; private set; }
161
162         /// <summary>
163         /// Gets the label under which this test result is
164         /// categorized, if any.
165         /// </summary>
166         public string Label { get; private set; }
167
168         /// <summary>
169         /// Gets the stage of test execution in which
170         /// the failure or other result took place.
171         /// </summary>
172         public FailureSite Site { get; private set; }
173
174         /// <summary>
175         /// Get a new ResultState, which is the same as the current
176         /// one but with the FailureSite set to the specified value.
177         /// </summary>
178         /// <param name="site">The FailureSite to use</param>
179         /// <returns>A new ResultState</returns>
180         public ResultState WithSite(FailureSite site)
181         {
182             return new ResultState(this.Status, this.Label, site);
183         }
184
185         #endregion
186
187         #region Equals Override
188
189         /// <summary>
190         /// Determines whether the specified <see cref="System.Object" />, is equal to this instance.
191         /// </summary>
192         /// <param name="obj">The <see cref="System.Object" /> to compare with this instance.</param>
193         /// <returns>
194         ///   <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.
195         /// </returns>
196         public override bool Equals(object obj)
197         {
198             var other = obj as ResultState;
199             if (other == null) return false;
200
201             return Status.Equals(other.Status) && Label.Equals(other.Label) && Site.Equals(other.Site);
202         }
203
204         /// <summary>
205         /// Returns a hash code for this instance.
206         /// </summary>
207         /// <returns>
208         /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. 
209         /// </returns>
210         public override int GetHashCode()
211         {
212             return (int)Status << 8 + (int)Site ^ Label.GetHashCode(); ;
213         }
214
215         #endregion
216
217         #region ToString Override
218
219         /// <summary>
220         /// Returns a <see cref="System.String"/> that represents this instance.
221         /// </summary>
222         /// <returns>
223         /// A <see cref="System.String"/> that represents this instance.
224         /// </returns>
225         public override string ToString()
226         {
227             var sb = new StringBuilder(Status.ToString());
228
229             if (Label != null && Label.Length > 0)
230                 sb.AppendFormat(":{0}", Label);
231             if (Site != FailureSite.Test)
232                 sb.AppendFormat("({0})", Site.ToString());
233
234             return sb.ToString();
235         }
236
237         #endregion
238     }
239
240     /// <summary>
241     /// The FailureSite enum indicates the stage of a test
242     /// in which an error or failure occurred.
243     /// </summary>
244     public enum FailureSite
245     {
246         /// <summary>
247         /// Failure in the test itself
248         /// </summary>
249         Test,
250
251         /// <summary>
252         /// Failure in the SetUp method
253         /// </summary>
254         SetUp,
255
256         /// <summary>
257         /// Failure in the TearDown method
258         /// </summary>
259         TearDown,
260
261         /// <summary>
262         /// Failure of a parent test
263         /// </summary>
264         Parent,
265
266         /// <summary>
267         /// Failure of a child test
268         /// </summary>
269         Child
270     }
271 }