2 // EncodingTest.cs - Unit Tests for System.Text.Encoding
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.
32 using NUnit.Framework;
34 namespace MonoTests.System.Text
37 public class EncodingTest
40 [ExpectedException (typeof (NotSupportedException))]
41 public void IsBrowserDisplay ()
43 MyEncoding enc = new MyEncoding ();
44 Assert.IsFalse (enc.IsBrowserDisplay);
48 [ExpectedException (typeof (NotSupportedException))]
49 public void IsBrowserSave ()
51 MyEncoding enc = new MyEncoding ();
52 Assert.IsFalse (enc.IsBrowserSave);
56 [ExpectedException (typeof (NotSupportedException))]
57 public void IsMailNewsDisplay ()
59 MyEncoding enc = new MyEncoding ();
60 Assert.IsFalse (enc.IsMailNewsDisplay);
64 [ExpectedException (typeof (NotSupportedException))]
65 public void IsMailNewsSave ()
67 MyEncoding enc = new MyEncoding ();
68 Assert.IsFalse (enc.IsMailNewsSave);
72 public void GetEncoding_CodePage_Default ()
74 Assert.AreEqual (Encoding.Default, Encoding.GetEncoding (0));
78 public void GetEncoding_CodePage_Invalid ()
81 Encoding.GetEncoding (-1);
83 } catch (ArgumentOutOfRangeException ex) {
84 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
85 Assert.IsNull (ex.InnerException, "#A3");
86 Assert.IsNotNull (ex.Message, "#A4");
87 Assert.IsNotNull (ex.ParamName, "#A5");
88 Assert.AreEqual ("codepage", ex.ParamName, "#A6");
92 Encoding.GetEncoding (65536);
94 } catch (ArgumentOutOfRangeException ex) {
95 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
96 Assert.IsNull (ex.InnerException, "#B3");
97 Assert.IsNotNull (ex.Message, "#B4");
98 Assert.IsNotNull (ex.ParamName, "#B5");
99 Assert.AreEqual ("codepage", ex.ParamName, "#B6");
104 public void GetEncoding_Name_NotSupported ()
107 Encoding.GetEncoding ("doesnotexist");
109 } catch (ArgumentException ex) {
110 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
111 Assert.IsNull (ex.InnerException, "#3");
112 Assert.IsNotNull (ex.Message, "#4");
113 Assert.IsTrue (ex.Message.IndexOf ("doesnotexist") != -1, "#5");
114 Assert.IsNotNull (ex.ParamName, "#6");
115 Assert.AreEqual ("name", ex.ParamName, "#7");
120 [ExpectedException (typeof (ArgumentNullException))]
121 public void GetEncoding_Name_Null ()
123 Encoding.GetEncoding ((string) null);
127 public void EncodingName ()
129 Assert.AreEqual ("Unicode (UTF-8)", Encoding.UTF8.EncodingName);