Merge pull request #1685 from esdrubal/touint64
[mono.git] / mcs / class / corlib / Test / System.Text / EncodingTest.cs
1 //
2 // EncodingTest.cs - Unit Tests for System.Text.Encoding
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.Text;
31
32 using NUnit.Framework;
33
34 namespace MonoTests.System.Text
35 {
36         [TestFixture]
37         public class EncodingTest
38         {
39                 [Test]
40                 [ExpectedException (typeof (NotSupportedException))]
41                 public void IsBrowserDisplay ()
42                 {
43                         MyEncoding enc = new MyEncoding ();
44                         Assert.IsFalse (enc.IsBrowserDisplay);
45                 }
46
47                 [Test]
48                 [ExpectedException (typeof (NotSupportedException))]
49                 public void IsBrowserSave ()
50                 {
51                         MyEncoding enc = new MyEncoding ();
52                         Assert.IsFalse (enc.IsBrowserSave);
53                 }
54
55                 [Test]
56                 [ExpectedException (typeof (NotSupportedException))]
57                 public void IsMailNewsDisplay ()
58                 {
59                         MyEncoding enc = new MyEncoding ();
60                         Assert.IsFalse (enc.IsMailNewsDisplay);
61                 }
62
63                 [Test]
64                 [ExpectedException (typeof (NotSupportedException))]
65                 public void IsMailNewsSave ()
66                 {
67                         MyEncoding enc = new MyEncoding ();
68                         Assert.IsFalse (enc.IsMailNewsSave);
69                 }
70
71                 [Test]
72                 public void GetEncoding_CodePage_Default ()
73                 {
74                         Assert.AreEqual (Encoding.Default, Encoding.GetEncoding (0));
75                 }
76
77                 [Test]
78                 public void GetEncoding_CodePage_Invalid ()
79                 {
80                         try {
81                                 Encoding.GetEncoding (-1);
82                                 Assert.Fail ("#A1");
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");
89                         }
90
91                         try {
92                                 Encoding.GetEncoding (65536);
93                                 Assert.Fail ("#B1");
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");
100                         }
101                 }
102
103                 [Test]
104                 public void GetEncoding_Name_NotSupported ()
105                 {
106                         try {
107                                 Encoding.GetEncoding ("doesnotexist");
108                                 Assert.Fail ("#1");
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");
116                         }
117                 }
118
119                 [Test]
120                 [ExpectedException (typeof (ArgumentNullException))]
121                 public void GetEncoding_Name_Null ()
122                 {
123                         Encoding.GetEncoding ((string) null);
124                 }
125
126                 [Test]
127                 public void EncodingName ()
128                 {
129                         Assert.AreEqual ("Unicode (UTF-8)", Encoding.UTF8.EncodingName);
130                 }
131         }
132 }