[NUI] Rebase develnui (DevelNUI only patches --> master) (#3910)
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Devel.Tests.Ubuntu / nunit.framework / Assert / Assert.cs
1 // ***********************************************************************
2 // Copyright (c) 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;
30 using System.Collections;
31 using System.ComponentModel;
32 using NUnit.Framework.Constraints;
33
34 namespace NUnit.Framework
35 {
36     /// <summary>
37     /// Delegate used by tests that execute code and
38     /// capture any thrown exception.
39     /// </summary>
40     public delegate void TestDelegate();
41
42 #if NET_4_0 || NET_4_5 || PORTABLE
43     /// <summary>
44     /// Delegate used by tests that execute async code and
45     /// capture any thrown exception.
46     /// </summary>
47     public delegate System.Threading.Tasks.Task AsyncTestDelegate();
48 #endif
49
50     /// <summary>
51     /// The Assert class contains a collection of static methods that
52     /// implement the most common assertions used in NUnit.
53     /// </summary>
54     public partial class Assert
55     {
56         #region Constructor
57
58         /// <summary>
59         /// We don't actually want any instances of this object, but some people
60         /// like to inherit from it to add other static methods. Hence, the
61         /// protected constructor disallows any instances of this object. 
62         /// </summary>
63         protected Assert() { }
64
65         #endregion
66
67         #region Equals and ReferenceEquals
68
69         /// <summary>
70         /// The Equals method throws an InvalidOperationException. This is done 
71         /// to make sure there is no mistake by calling this function.
72         /// </summary>
73         /// <param name="a"></param>
74         /// <param name="b"></param>
75         [EditorBrowsable(EditorBrowsableState.Never)]
76         public static new bool Equals(object a, object b)
77         {
78             throw new InvalidOperationException("Assert.Equals should not be used for Assertions");
79         }
80
81         /// <summary>
82         /// override the default ReferenceEquals to throw an InvalidOperationException. This 
83         /// implementation makes sure there is no mistake in calling this function 
84         /// as part of Assert. 
85         /// </summary>
86         /// <param name="a"></param>
87         /// <param name="b"></param>
88         public static new void ReferenceEquals(object a, object b)
89         {
90             throw new InvalidOperationException("Assert.ReferenceEquals should not be used for Assertions");
91         }
92
93         #endregion
94
95         #region Pass
96
97         /// <summary>
98         /// Throws a <see cref="SuccessException"/> with the message and arguments 
99         /// that are passed in. This allows a test to be cut short, with a result
100         /// of success returned to NUnit.
101         /// </summary>
102         /// <param name="message">The message to initialize the <see cref="AssertionException"/> with.</param>
103         /// <param name="args">Arguments to be used in formatting the message</param>
104         static public void Pass(string message, params object[] args)
105         {
106             if (message == null) message = string.Empty;
107             else if (args != null && args.Length > 0)
108                 message = string.Format(message, args);
109
110             //throw new SuccessException(message);
111         }
112
113         /// <summary>
114         /// Throws a <see cref="SuccessException"/> with the message and arguments 
115         /// that are passed in. This allows a test to be cut short, with a result
116         /// of success returned to NUnit.
117         /// </summary>
118         /// <param name="message">The message to initialize the <see cref="AssertionException"/> with.</param>
119         static public void Pass(string message)
120         {
121             Assert.Pass(message, null);
122         }
123
124         /// <summary>
125         /// Throws a <see cref="SuccessException"/> with the message and arguments 
126         /// that are passed in. This allows a test to be cut short, with a result
127         /// of success returned to NUnit.
128         /// </summary>
129         static public void Pass()
130         {
131             Assert.Pass(string.Empty, null);
132         }
133
134         #endregion
135
136         #region Fail
137
138         /// <summary>
139         /// Throws an <see cref="AssertionException"/> with the message and arguments 
140         /// that are passed in. This is used by the other Assert functions. 
141         /// </summary>
142         /// <param name="message">The message to initialize the <see cref="AssertionException"/> with.</param>
143         /// <param name="args">Arguments to be used in formatting the message</param>
144         static public void Fail(string message, params object[] args)
145         {
146             if (message == null) message = string.Empty;
147             else if (args != null && args.Length > 0)
148                 message = string.Format(message, args);
149
150             throw new AssertionException(message);
151         }
152
153         /// <summary>
154         /// Throws an <see cref="AssertionException"/> with the message that is 
155         /// passed in. This is used by the other Assert functions. 
156         /// </summary>
157         /// <param name="message">The message to initialize the <see cref="AssertionException"/> with.</param>
158         static public void Fail(string message)
159         {
160             Assert.Fail(message, null);
161         }
162
163         /// <summary>
164         /// Throws an <see cref="AssertionException"/>. 
165         /// This is used by the other Assert functions. 
166         /// </summary>
167         static public void Fail()
168         {
169             Assert.Fail(string.Empty, null);
170         }
171
172         #endregion
173
174         #region Ignore
175
176         /// <summary>
177         /// Throws an <see cref="IgnoreException"/> with the message and arguments 
178         /// that are passed in.  This causes the test to be reported as ignored.
179         /// </summary>
180         /// <param name="message">The message to initialize the <see cref="AssertionException"/> with.</param>
181         /// <param name="args">Arguments to be used in formatting the message</param>
182         static public void Ignore(string message, params object[] args)
183         {
184             if (message == null) message = string.Empty;
185             else if (args != null && args.Length > 0)
186                 message = string.Format(message, args);
187
188             throw new IgnoreException(message);
189         }
190
191         /// <summary>
192         /// Throws an <see cref="IgnoreException"/> with the message that is 
193         /// passed in. This causes the test to be reported as ignored. 
194         /// </summary>
195         /// <param name="message">The message to initialize the <see cref="AssertionException"/> with.</param>
196         static public void Ignore(string message)
197         {
198             Assert.Ignore(message, null);
199         }
200
201         /// <summary>
202         /// Throws an <see cref="IgnoreException"/>. 
203         /// This causes the test to be reported as ignored. 
204         /// </summary>
205         static public void Ignore()
206         {
207             Assert.Ignore(string.Empty, null);
208         }
209
210         #endregion
211
212         #region InConclusive
213
214         /// <summary>
215         /// Throws an <see cref="InconclusiveException"/> with the message and arguments 
216         /// that are passed in.  This causes the test to be reported as inconclusive.
217         /// </summary>
218         /// <param name="message">The message to initialize the <see cref="InconclusiveException"/> with.</param>
219         /// <param name="args">Arguments to be used in formatting the message</param>
220         static public void Inconclusive(string message, params object[] args)
221         {
222             if (message == null) message = string.Empty;
223             else if (args != null && args.Length > 0)
224                 message = string.Format(message, args);
225
226             throw new InconclusiveException(message);
227         }
228
229         /// <summary>
230         /// Throws an <see cref="InconclusiveException"/> with the message that is 
231         /// passed in. This causes the test to be reported as inconclusive. 
232         /// </summary>
233         /// <param name="message">The message to initialize the <see cref="InconclusiveException"/> with.</param>
234         static public void Inconclusive(string message)
235         {
236             Assert.Inconclusive(message, null);
237         }
238
239         /// <summary>
240         /// Throws an <see cref="InconclusiveException"/>. 
241         /// This causes the test to be reported as Inconclusive. 
242         /// </summary>
243         static public void Inconclusive()
244         {
245             Assert.Inconclusive(string.Empty, null);
246         }
247
248         #endregion
249
250         #region Contains
251
252         /// <summary>
253         /// Asserts that an object is contained in a list.
254         /// </summary>
255         /// <param name="expected">The expected object</param>
256         /// <param name="actual">The list to be examined</param>
257         /// <param name="message">The message to display in case of failure</param>
258         /// <param name="args">Array of objects to be used in formatting the message</param>
259         public static void Contains(object expected, ICollection actual, string message, params object[] args)
260         {
261             Assert.That(actual, new CollectionContainsConstraint(expected) ,message, args);
262         }
263
264         /// <summary>
265         /// Asserts that an object is contained in a list.
266         /// </summary>
267         /// <param name="expected">The expected object</param>
268         /// <param name="actual">The list to be examined</param>
269         public static void Contains(object expected, ICollection actual)
270         {
271             Assert.That(actual, new CollectionContainsConstraint(expected) ,null, null);
272         }
273
274         #endregion
275
276         #region Multiple
277
278         ///// <summary>
279         ///// If an assert fails within this block, execution will continue and 
280         ///// the errors will be reported at the end of the block.
281         ///// </summary>
282         ///// <param name="del">The test delegate</param>
283         //public static void Multiple(TestDelegate del)
284         //{
285         //    del();
286         //}
287
288         #endregion
289     }
290 }