[configure] rename "--with-interpreter=yes" to "--enable-interpreter"
[mono.git] / mcs / nunit24 / NUnitFramework / framework / FileAssert.cs
1 // ****************************************************************\r
2 // This is free software licensed under the NUnit license. You\r
3 // may obtain a copy of the license as well as information regarding\r
4 // copyright ownership at http://nunit.org/?p=license&r=2.4.\r
5 // ****************************************************************\r
6 \r
7 using System;\r
8 using System.IO;\r
9 using System.ComponentModel;\r
10 using NUnit.Framework.Constraints;\r
11 \r
12 namespace NUnit.Framework\r
13 {\r
14         /// <summary>\r
15         /// Summary description for FileAssert.\r
16         /// </summary>\r
17         public class FileAssert\r
18         {\r
19                 #region Equals and ReferenceEquals\r
20 \r
21                 /// <summary>\r
22                 /// The Equals method throws an AssertionException. This is done \r
23                 /// to make sure there is no mistake by calling this function.\r
24                 /// </summary>\r
25                 /// <param name="a"></param>\r
26                 /// <param name="b"></param>\r
27                 [EditorBrowsable(EditorBrowsableState.Never)]\r
28                 public static new bool Equals(object a, object b)\r
29                 {\r
30                         throw new AssertionException("Assert.Equals should not be used for Assertions");\r
31                 }\r
32 \r
33                 /// <summary>\r
34                 /// override the default ReferenceEquals to throw an AssertionException. This \r
35                 /// implementation makes sure there is no mistake in calling this function \r
36                 /// as part of Assert. \r
37                 /// </summary>\r
38                 /// <param name="a"></param>\r
39                 /// <param name="b"></param>\r
40                 public static new void ReferenceEquals(object a, object b)\r
41                 {\r
42                         throw new AssertionException("Assert.ReferenceEquals should not be used for Assertions");\r
43                 }\r
44 \r
45                 #endregion\r
46                                 \r
47                 #region Constructor\r
48 \r
49                 /// <summary>\r
50                 /// We don't actually want any instances of this object, but some people\r
51                 /// like to inherit from it to add other static methods. Hence, the\r
52                 /// protected constructor disallows any instances of this object. \r
53                 /// </summary>\r
54                 protected FileAssert() {}\r
55 \r
56                 #endregion\r
57 \r
58                 #region AreEqual\r
59 \r
60                 #region Streams\r
61                 \r
62                 /// <summary>\r
63                 /// Verifies that two Streams are equal.  Two Streams are considered\r
64                 /// equal if both are null, or if both have the same value byte for byte.\r
65                 /// If they are not equal an <see cref="AssertionException"/> is thrown.\r
66                 /// </summary>\r
67                 /// <param name="expected">The expected Stream</param>\r
68                 /// <param name="actual">The actual Stream</param>\r
69                 /// <param name="message">The message to display if Streams are not equal</param>\r
70                 /// <param name="args">Arguments to be used in formatting the message</param>\r
71                 static public void AreEqual(Stream expected, Stream actual, string message, params object[] args)\r
72                 {\r
73                         Assert.That( actual, new EqualConstraint( expected ), message, args );\r
74                 }\r
75 \r
76                 /// <summary>\r
77                 /// Verifies that two Streams are equal.  Two Streams are considered\r
78                 /// equal if both are null, or if both have the same value byte for byte.\r
79                 /// If they are not equal an <see cref="AssertionException"/> is thrown.\r
80                 /// </summary>\r
81                 /// <param name="expected">The expected Stream</param>\r
82                 /// <param name="actual">The actual Stream</param>\r
83                 /// <param name="message">The message to display if objects are not equal</param>\r
84                 static public void AreEqual(Stream expected, Stream actual, string message) \r
85                 {\r
86                         AreEqual(expected, actual, message, null);\r
87                 }\r
88 \r
89                 /// <summary>\r
90                 /// Verifies that two Streams are equal.  Two Streams are considered\r
91                 /// equal if both are null, or if both have the same value byte for byte.\r
92                 /// If they are not equal an <see cref="AssertionException"/> is thrown.\r
93                 /// </summary>\r
94                 /// <param name="expected">The expected Stream</param>\r
95                 /// <param name="actual">The actual Stream</param>\r
96                 static public void AreEqual(Stream expected, Stream actual) \r
97                 {\r
98                         AreEqual(expected, actual, string.Empty, null);\r
99                 }\r
100 \r
101                 #endregion\r
102 \r
103                 #region FileInfo\r
104                 /// <summary>\r
105                 /// Verifies that two files are equal.  Two files are considered\r
106                 /// equal if both are null, or if both have the same value byte for byte.\r
107                 /// If they are not equal an <see cref="AssertionException"/> is thrown.\r
108                 /// </summary>\r
109                 /// <param name="expected">A file containing the value that is expected</param>\r
110                 /// <param name="actual">A file containing the actual value</param>\r
111                 /// <param name="message">The message to display if Streams are not equal</param>\r
112                 /// <param name="args">Arguments to be used in formatting the message</param>\r
113                 static public void AreEqual(FileInfo expected, FileInfo actual, string message, params object[] args)\r
114                 {\r
115                         using (FileStream exStream = expected.OpenRead())\r
116                         {\r
117                                 using (FileStream acStream = actual.OpenRead())\r
118                                 {\r
119                                         AreEqual(exStream,acStream,message,args);\r
120                                 }\r
121                         }\r
122                 }\r
123 \r
124                 /// <summary>\r
125                 /// Verifies that two files are equal.  Two files are considered\r
126                 /// equal if both are null, or if both have the same value byte for byte.\r
127                 /// If they are not equal an <see cref="AssertionException"/> is thrown.\r
128                 /// </summary>\r
129                 /// <param name="expected">A file containing the value that is expected</param>\r
130                 /// <param name="actual">A file containing the actual value</param>\r
131                 /// <param name="message">The message to display if objects are not equal</param>\r
132                 static public void AreEqual(FileInfo expected, FileInfo actual, string message) \r
133                 {\r
134                         AreEqual(expected, actual, message, null);\r
135                 }\r
136 \r
137                 /// <summary>\r
138                 /// Verifies that two files are equal.  Two files are considered\r
139                 /// equal if both are null, or if both have the same value byte for byte.\r
140                 /// If they are not equal an <see cref="AssertionException"/> is thrown.\r
141                 /// </summary>\r
142                 /// <param name="expected">A file containing the value that is expected</param>\r
143                 /// <param name="actual">A file containing the actual value</param>\r
144                 static public void AreEqual(FileInfo expected, FileInfo actual) \r
145                 {\r
146                         AreEqual(expected, actual, string.Empty, null);\r
147                 }\r
148 \r
149                 #endregion\r
150 \r
151                 #region String\r
152                 /// <summary>\r
153                 /// Verifies that two files are equal.  Two files are considered\r
154                 /// equal if both are null, or if both have the same value byte for byte.\r
155                 /// If they are not equal an <see cref="AssertionException"/> is thrown.\r
156                 /// </summary>\r
157                 /// <param name="expected">The path to a file containing the value that is expected</param>\r
158                 /// <param name="actual">The path to a file containing the actual value</param>\r
159                 /// <param name="message">The message to display if Streams are not equal</param>\r
160                 /// <param name="args">Arguments to be used in formatting the message</param>\r
161                 static public void AreEqual(string expected, string actual, string message, params object[] args)\r
162                 {\r
163                         using (FileStream exStream = File.OpenRead(expected))\r
164                         {\r
165                                 using (FileStream acStream = File.OpenRead(actual))\r
166                                 {\r
167                                         AreEqual(exStream,acStream,message,args);\r
168                                 }\r
169                         }\r
170                 }\r
171 \r
172                 /// <summary>\r
173                 /// Verifies that two files are equal.  Two files are considered\r
174                 /// equal if both are null, or if both have the same value byte for byte.\r
175                 /// If they are not equal an <see cref="AssertionException"/> is thrown.\r
176                 /// </summary>\r
177                 /// <param name="expected">The path to a file containing the value that is expected</param>\r
178                 /// <param name="actual">The path to a file containing the actual value</param>\r
179                 /// <param name="message">The message to display if objects are not equal</param>\r
180                 static public void AreEqual(string expected, string actual, string message) \r
181                 {\r
182                         AreEqual(expected, actual, message, null);\r
183                 }\r
184 \r
185                 /// <summary>\r
186                 /// Verifies that two files are equal.  Two files are considered\r
187                 /// equal if both are null, or if both have the same value byte for byte.\r
188                 /// If they are not equal an <see cref="AssertionException"/> is thrown.\r
189                 /// </summary>\r
190                 /// <param name="expected">The path to a file containing the value that is expected</param>\r
191                 /// <param name="actual">The path to a file containing the actual value</param>\r
192                 static public void AreEqual(string expected, string actual) \r
193                 {\r
194                         AreEqual(expected, actual, string.Empty, null);\r
195                 }\r
196 \r
197                 #endregion\r
198 \r
199                 #endregion\r
200 \r
201                 #region AreNotEqual\r
202 \r
203                 #region Streams\r
204                 /// <summary>\r
205                 /// Asserts that two Streams are not equal. If they are equal\r
206                 /// an <see cref="AssertionException"/> is thrown.\r
207                 /// </summary>\r
208                 /// <param name="expected">The expected Stream</param>\r
209                 /// <param name="actual">The actual Stream</param>\r
210                 /// <param name="message">The message to be displayed when the two Stream are the same.</param>\r
211                 /// <param name="args">Arguments to be used in formatting the message</param>\r
212                 static public void AreNotEqual( Stream expected, Stream actual, string message, params object[] args)\r
213                 {\r
214                         Assert.That( actual, new NotConstraint( new EqualConstraint( expected ) ), message, args );\r
215                 }\r
216 \r
217                 /// <summary>\r
218                 /// Asserts that two Streams are not equal. If they are equal\r
219                 /// an <see cref="AssertionException"/> is thrown.\r
220                 /// </summary>\r
221                 /// <param name="expected">The expected Stream</param>\r
222                 /// <param name="actual">The actual Stream</param>\r
223                 /// <param name="message">The message to be displayed when the Streams are the same.</param>\r
224                 static public void AreNotEqual(Stream expected, Stream actual, string message) \r
225                 {\r
226                         AreNotEqual(expected, actual, message, null);\r
227                 }\r
228    \r
229                 /// <summary>\r
230                 /// Asserts that two Streams are not equal. If they are equal\r
231                 /// an <see cref="AssertionException"/> is thrown.\r
232                 /// </summary>\r
233                 /// <param name="expected">The expected Stream</param>\r
234                 /// <param name="actual">The actual Stream</param>\r
235                 static public void AreNotEqual(Stream expected, Stream actual) \r
236                 {\r
237                         AreNotEqual(expected, actual, string.Empty, null);\r
238                 }\r
239                 #endregion\r
240                 \r
241                 #region FileInfo\r
242                 /// <summary>\r
243                 /// Asserts that two files are not equal. If they are equal\r
244                 /// an <see cref="AssertionException"/> is thrown.\r
245                 /// </summary>\r
246                 /// <param name="expected">A file containing the value that is expected</param>\r
247                 /// <param name="actual">A file containing the actual value</param>\r
248                 /// <param name="message">The message to display if Streams are not equal</param>\r
249                 /// <param name="args">Arguments to be used in formatting the message</param>\r
250                 static public void AreNotEqual(FileInfo expected, FileInfo actual, string message, params object[] args)\r
251                 {\r
252                         using (FileStream exStream = expected.OpenRead())\r
253                         {\r
254                                 using (FileStream acStream = actual.OpenRead())\r
255                                 {\r
256                                         AreNotEqual(exStream,acStream,message,args);\r
257                                 }\r
258                         }\r
259                 }\r
260 \r
261                 /// <summary>\r
262                 /// Asserts that two files are not equal. If they are equal\r
263                 /// an <see cref="AssertionException"/> is thrown.\r
264                 /// </summary>\r
265                 /// <param name="expected">A file containing the value that is expected</param>\r
266                 /// <param name="actual">A file containing the actual value</param>\r
267                 /// <param name="message">The message to display if objects are not equal</param>\r
268                 static public void AreNotEqual(FileInfo expected, FileInfo actual, string message) \r
269                 {\r
270                         AreNotEqual(expected, actual, message, null);\r
271                 }\r
272 \r
273                 /// <summary>\r
274                 /// Asserts that two files are not equal. If they are equal\r
275                 /// an <see cref="AssertionException"/> is thrown.\r
276                 /// </summary>\r
277                 /// <param name="expected">A file containing the value that is expected</param>\r
278                 /// <param name="actual">A file containing the actual value</param>\r
279                 static public void AreNotEqual(FileInfo expected, FileInfo actual) \r
280                 {\r
281                         AreNotEqual(expected, actual, string.Empty, null);\r
282                 }\r
283 \r
284                 #endregion\r
285                 \r
286                 #region String\r
287                 /// <summary>\r
288                 /// Asserts that two files are not equal. If they are equal\r
289                 /// an <see cref="AssertionException"/> is thrown.\r
290                 /// </summary>\r
291                 /// <param name="expected">The path to a file containing the value that is expected</param>\r
292                 /// <param name="actual">The path to a file containing the actual value</param>\r
293                 /// <param name="message">The message to display if Streams are not equal</param>\r
294                 /// <param name="args">Arguments to be used in formatting the message</param>\r
295                 static public void AreNotEqual(string expected, string actual, string message, params object[] args)\r
296                 {\r
297                         using (FileStream exStream = File.OpenRead(expected))\r
298                         {\r
299                                 using (FileStream acStream = File.OpenRead(actual))\r
300                                 {\r
301                                         AreNotEqual(exStream,acStream,message,args);\r
302                                 }\r
303                         }\r
304                 }\r
305 \r
306                 /// <summary>\r
307                 /// Asserts that two files are not equal. If they are equal\r
308                 /// an <see cref="AssertionException"/> is thrown.\r
309                 /// </summary>\r
310                 /// <param name="expected">The path to a file containing the value that is expected</param>\r
311                 /// <param name="actual">The path to a file containing the actual value</param>\r
312                 /// <param name="message">The message to display if objects are not equal</param>\r
313                 static public void AreNotEqual(string expected, string actual, string message) \r
314                 {\r
315                         AreNotEqual(expected, actual, message, null);\r
316                 }\r
317 \r
318                 /// <summary>\r
319                 /// Asserts that two files are not equal. If they are equal\r
320                 /// an <see cref="AssertionException"/> is thrown.\r
321                 /// </summary>\r
322                 /// <param name="expected">The path to a file containing the value that is expected</param>\r
323                 /// <param name="actual">The path to a file containing the actual value</param>\r
324                 static public void AreNotEqual(string expected, string actual) \r
325                 {\r
326                         AreNotEqual(expected, actual, string.Empty, null);\r
327                 }\r
328 \r
329                 #endregion\r
330 \r
331                 #endregion\r
332         }\r
333 }\r