2 // ExternalExceptionTest.cs - NUnit tests for ExternalException
5 // Gert Driesen <drieseng@users.sourceforge.net>
7 // Copyright (C) 2007 Gert Driesen
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
30 using System.Runtime.InteropServices;
32 using NUnit.Framework;
34 namespace MonoTests.System.Runtime.InteropServices
37 public class ExternalExceptionTest
40 public void Constructor0 ()
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");
49 [Test] // ctor (string)
50 public void Constructor1 ()
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");
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");
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");
73 [Test] // ctor (string, Exception)
74 public void Constructor3 ()
78 Exception inner = new Exception ();
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");
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");
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");
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");
103 [Test] // ctor (string, int)
104 public void Constructor4 ()
106 ExternalException ex;
107 string msg = "ERROR";
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");
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");
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");
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");