[corlib] Parse datetime string using culture calendar. Fixes #18052
[mono.git] / mcs / class / corlib / Test / System.Runtime.InteropServices / ExternalExceptionTest.cs
1 //
2 // ExternalExceptionTest.cs - NUnit tests for ExternalException
3 //
4 // Author:
5 //      Gert Driesen  <drieseng@users.sourceforge.net>
6 //
7 // Copyright (C) 2007 Gert Driesen
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 using System;
30 using System.Runtime.InteropServices;
31
32 using NUnit.Framework;
33
34 namespace MonoTests.System.Runtime.InteropServices
35 {
36         [TestFixture]
37         public class ExternalExceptionTest
38         {
39                 [Test] // ctor ()
40                 public void Constructor0 ()
41                 {
42                         ExternalException ex = new ExternalException ();
43                         Assert.AreEqual (-2147467259, ex.ErrorCode, "#1");
44                         Assert.IsNull (ex.InnerException, "#2");
45                         Assert.IsNotNull (ex.Message, "#3");
46                         Assert.IsTrue (ex.Message.IndexOf (ex.GetType ().FullName) == -1, "#4");
47                 }
48
49                 [Test] // ctor (string)
50                 public void Constructor1 ()
51                 {
52                         ExternalException ex;
53                         string msg = "ERROR";
54
55                         ex = new ExternalException (msg);
56                         Assert.AreEqual (-2147467259, ex.ErrorCode, "#A1");
57                         Assert.IsNull (ex.InnerException, "#A2");
58                         Assert.AreSame (msg, ex.Message, "#A3");
59
60                         ex = new ExternalException ((string) null);
61                         Assert.AreEqual (-2147467259, ex.ErrorCode, "#B1");
62                         Assert.IsNull (ex.InnerException, "#B2");
63                         Assert.IsNotNull (msg, ex.Message, "#B3");
64                         Assert.IsTrue (ex.Message.IndexOf (ex.GetType ().FullName) != -1, "#B4");
65
66                         ex = new ExternalException (string.Empty);
67                         Assert.AreEqual (-2147467259, ex.ErrorCode, "#C1");
68                         Assert.IsNull (ex.InnerException, "#C2");
69                         Assert.IsNotNull (msg, ex.Message, "#C3");
70                         Assert.AreEqual (string.Empty, ex.Message, "#C4");
71                 }
72
73                 [Test] // ctor (string, Exception)
74                 public void Constructor3 ()
75                 {
76                         ExternalException ex;
77                         string msg = "ERROR";
78                         Exception inner = new Exception ();
79
80                         ex = new ExternalException (msg, inner);
81                         Assert.AreEqual (-2147467259, ex.ErrorCode, "#A1");
82                         Assert.AreSame (inner, ex.InnerException, "#A2");
83                         Assert.AreSame (msg, ex.Message, "#A3");
84
85                         ex = new ExternalException ((string) null, inner);
86                         Assert.AreEqual (-2147467259, ex.ErrorCode, "#B1");
87                         Assert.AreSame (inner, ex.InnerException, "#B2");
88                         Assert.IsNotNull (msg, ex.Message, "#B3");
89                         Assert.AreEqual (new ExternalException (null).Message, ex.Message, "#B4");
90
91                         ex = new ExternalException (msg, (Exception) null);
92                         Assert.AreEqual (-2147467259, ex.ErrorCode, "#C1");
93                         Assert.IsNull (ex.InnerException, "#C2");
94                         Assert.AreSame (msg, ex.Message, "#C3");
95
96                         ex = new ExternalException (string.Empty, (Exception) null);
97                         Assert.AreEqual (-2147467259, ex.ErrorCode, "#D1");
98                         Assert.IsNull (ex.InnerException, "#D2");
99                         Assert.IsNotNull (ex.Message, "#D3");
100                         Assert.AreEqual (string.Empty, ex.Message, "#D4");
101                 }
102
103                 [Test] // ctor (string, int)
104                 public void Constructor4 ()
105                 {
106                         ExternalException ex;
107                         string msg = "ERROR";
108
109                         ex = new ExternalException (msg, int.MinValue);
110                         Assert.AreEqual (int.MinValue, ex.ErrorCode, "#A1");
111                         Assert.IsNull (ex.InnerException, "#A2");
112                         Assert.AreSame (msg, ex.Message, "#A3");
113
114                         ex = new ExternalException ((string) null, int.MaxValue);
115                         Assert.AreEqual (int.MaxValue, ex.ErrorCode, "#B1");
116                         Assert.IsNull (ex.InnerException, "#B2");
117                         Assert.IsNotNull (msg, ex.Message, "#B3");
118                         Assert.AreEqual (new ExternalException (null).Message, ex.Message, "#B4");
119
120                         ex = new ExternalException (msg, 0);
121                         Assert.AreEqual (0, ex.ErrorCode, "#C1");
122                         Assert.IsNull (ex.InnerException, "#C2");
123                         Assert.AreSame (msg, ex.Message, "#C3");
124
125                         ex = new ExternalException (string.Empty, 0);
126                         Assert.AreEqual (0, ex.ErrorCode, "#D1");
127                         Assert.IsNull (ex.InnerException, "#D2");
128                         Assert.IsNotNull (ex.Message, "#D3");
129                         Assert.AreEqual (string.Empty, ex.Message, "#D4");
130                 }
131         }
132 }