[runtime] Fix Empty generic enumerator equality
[mono.git] / mcs / class / corlib / Test / System / ArgumentExceptionTest.cs
1 //
2 // ArgumentExceptionTest.cs - Unit tests for
3 //      System.ArgumentException
4 //
5 // Author:
6 //      Gert Driesen  <drieseng@users.sourceforge.net>
7 //
8 // Copyright (C) 2007 Gert Driesen
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 using System;
31
32 using NUnit.Framework;
33
34 namespace MonoTests.System
35 {
36         [TestFixture]
37         public class ArgumentExceptionTest
38         {
39                 [Test] // ctor ()
40                 public void Constructor0 ()
41                 {
42                         // Value does not fall within the expected range
43                         ArgumentException ae = new ArgumentException ();
44                         Assert.IsNull (ae.InnerException, "#1");
45                         Assert.IsNotNull (ae.Message, "#2");
46                         Assert.IsFalse (ae.Message.IndexOf (typeof (ArgumentException).FullName) != -1, "#3");
47                         Assert.IsFalse (ae.Message.IndexOf (Environment.NewLine) != -1, "#4");
48                         Assert.IsNull (ae.ParamName, "#5");
49                 }
50
51                 [Test] // ctor (string)
52                 public void Constructor1 ()
53                 {
54                         ArgumentException ae;
55
56                         ae = new ArgumentException ((string) null);
57                         Assert.IsNull (ae.InnerException, "#A1");
58                         Assert.IsNotNull (ae.Message, "#A2");
59                         Assert.IsTrue (ae.Message.IndexOf (typeof (ArgumentException).FullName) != -1, "#A3");
60                         Assert.IsFalse (ae.Message.IndexOf (Environment.NewLine) != -1, "#A4");
61                         Assert.IsNull (ae.ParamName, "#A5");
62                         
63                         ae = new ArgumentException ("MSG");
64                         Assert.IsNull (ae.InnerException, "#B1");
65                         Assert.IsNotNull (ae.Message, "#B2");
66                         Assert.AreEqual ("MSG", ae.Message, "#B3");
67                         Assert.IsNull (ae.ParamName, "#B4");
68
69                         ae = new ArgumentException (string.Empty);
70                         Assert.IsNull (ae.InnerException, "#C1");
71                         Assert.IsNotNull (ae.Message, "#C2");
72                         Assert.AreEqual (string.Empty, ae.Message, "#C3");
73                         Assert.IsNull (ae.ParamName, "#C4");
74                 }
75
76                 [Test] // ctor (string, string)
77                 public void Constructor4 ()
78                 {
79                         ArgumentException ae = new ArgumentException ("MSG", (string) null);
80                         Assert.IsNotNull (ae.Message, "#A1");
81                         Assert.AreEqual ("MSG", ae.Message, "#A2");
82                         Assert.IsNull (ae.ParamName, "#A3");
83
84                         ae = new ArgumentException ("MSG", string.Empty);
85                         Assert.IsNotNull (ae.Message, "#B1");
86                         Assert.AreEqual ("MSG", ae.Message, "#B2");
87                         Assert.IsNotNull (ae.ParamName, "#B3");
88                         Assert.AreEqual (string.Empty, ae.ParamName, "#B4");
89
90                         ae = new ArgumentException ("MSG", "PARAM");
91                         Assert.IsNotNull (ae.Message, "#C1");
92                         Assert.IsTrue (ae.Message.StartsWith ("MSG"), "#C2");
93                         Assert.IsTrue (ae.Message.IndexOf (Environment.NewLine) != -1, "#C3");
94                         Assert.IsFalse (ae.Message.IndexOf (typeof (ArgumentException).FullName) != -1, "#C4");
95                         Assert.IsTrue (ae.Message.IndexOf ("PARAM") != -1, "#C5");
96                         Assert.IsNotNull (ae.ParamName, "#C6");
97                         Assert.AreEqual ("PARAM", ae.ParamName, "#C7");
98
99                         ae = new ArgumentException ("MSG", " \t ");
100                         Assert.IsNotNull (ae.Message, "#D1");
101                         Assert.IsTrue (ae.Message.StartsWith ("MSG"), "#D2");
102                         Assert.IsTrue (ae.Message.IndexOf (Environment.NewLine) != -1, "#D3");
103                         Assert.IsFalse (ae.Message.IndexOf (typeof (ArgumentException).FullName) != -1, "#D4");
104                         Assert.IsTrue (ae.Message.IndexOf (" \t ") != -1, "#D5");
105                         Assert.IsNotNull (ae.ParamName, "#D6");
106                         Assert.AreEqual (" \t ", ae.ParamName, "#D7");
107                 }
108         }
109 }