* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / corlib / Test / System.Security.Cryptography / ToBase64TransformTest.cs
1 //
2 // ToBase64TransformTest.cs - NUnit Test Cases for ToBase64Transform
3 //
4 // Author:
5 //      Sebastien Pouliot (sebastien@ximian.com)
6 //
7 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
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 NUnit.Framework;
30 using System;
31 using System.Security.Cryptography;
32
33 namespace MonoTests.System.Security.Cryptography {
34
35         [TestFixture]
36         public class ToBase64TransformTest : Assertion {
37
38                 [Test]
39                 public void Properties ()
40                 {
41                         ICryptoTransform t = new ToBase64Transform ();
42                         Assert ("CanReuseTransform", t.CanReuseTransform);
43                         Assert ("CanTransformMultipleBlocks", !t.CanTransformMultipleBlocks);
44                         AssertEquals ("InputBlockSize", 3, t.InputBlockSize);
45                         AssertEquals ("OutputBlockSize", 4, t.OutputBlockSize);
46                 }
47
48                 [Test]
49                 [ExpectedException (typeof (ArgumentNullException))]
50                 public void TransformBlock_NullInput () 
51                 {
52                         byte[] output = new byte [4];
53                         ToBase64Transform t = new ToBase64Transform ();
54                         t.TransformBlock (null, 0, 0, output, 0);
55                 }
56
57                 [Test]
58                 public void TransformBlock_WrongLength () 
59                 {
60                         byte[] input = new byte [6];
61                         byte[] output = new byte [8];
62                         ToBase64Transform t = new ToBase64Transform ();
63                         t.TransformBlock (input, 0, 6, output, 0);
64                         // note only the first block has been processed
65                         AssertEquals ("WrongLength", "41-41-41-41-00-00-00-00", BitConverter.ToString (output));
66                 }
67
68                 [Test]
69                 [ExpectedException (typeof (ArgumentNullException))]
70 #if ! NET_2_0
71                 [Category ("NotDotNet")] // MS throw a ExecutionEngineException
72 #endif
73                 public void TransformBlock_NullOutput () 
74                 {
75                         byte[] input = new byte [3];
76                         ToBase64Transform t = new ToBase64Transform ();
77                         t.TransformBlock (input, 0, 3, null, 0);
78                 }
79
80                 [Test]
81                 [ExpectedException (typeof (ObjectDisposedException))]
82                 public void TransformBlock_Dispose () 
83                 {
84                         byte[] input = new byte [3];
85                         byte[] output = new byte [4];
86                         ToBase64Transform t = new ToBase64Transform ();
87                         t.Clear ();
88                         t.TransformBlock (input, 0, input.Length, output, 0);
89                 }
90
91                 [Test]
92                 [ExpectedException (typeof (ArgumentNullException))]
93                 public void TransformFinalBlock_Null () 
94                 {
95                         byte[] input = new byte [3];
96                         ToBase64Transform t = new ToBase64Transform ();
97                         t.TransformFinalBlock (null, 0, 3);
98                 }
99
100                 [Test]
101                 public void TransformFinalBlock_SmallLength () 
102                 {
103                         byte[] input = new byte [2]; // smaller than InputBlockSize
104                         ToBase64Transform t = new ToBase64Transform ();
105                         t.TransformFinalBlock (input, 0, 2);
106                 }
107
108                 [Test]
109                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
110                 public void TransformFinalBlock_WrongLength () 
111                 {
112                         byte[] input = new byte [6];
113                         ToBase64Transform t = new ToBase64Transform ();
114                         t.TransformFinalBlock (input, 0, 6);
115                 }
116
117                 [Test]
118                 [ExpectedException (typeof (ObjectDisposedException))]
119                 public void TransformFinalBlock_Dispose () 
120                 {
121                         byte[] input = new byte [3];
122                         ToBase64Transform t = new ToBase64Transform ();
123                         t.Clear ();
124                         t.TransformFinalBlock (input, 0, input.Length);
125                 }
126
127                 [Test]
128                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
129                 public void TransformBlock_InputOffset_Negative () 
130                 {
131                         byte[] input = new byte [15];
132                         byte[] output = new byte [16];
133                         using (ICryptoTransform t = new ToBase64Transform ()) {
134                                 t.TransformBlock (input, -1, input.Length, output, 0);
135                         }
136                 }
137
138                 [Test]
139                 [ExpectedException (typeof (ArgumentException))]
140                 public void TransformBlock_InputOffset_Overflow () 
141                 {
142                         byte[] input = new byte [15];
143                         byte[] output = new byte [16];
144                         using (ICryptoTransform t = new ToBase64Transform ()) {
145                                 t.TransformBlock (input, Int32.MaxValue, input.Length, output, 0);
146                         }
147                 }
148
149                 [Test]
150                 [ExpectedException (typeof (ArgumentException))]
151                 public void TransformBlock_InputCount_Negative () 
152                 {
153                         byte[] input = new byte [15];
154                         byte[] output = new byte [16];
155                         using (ICryptoTransform t = new ToBase64Transform ()) {
156                                 t.TransformBlock (input, 0, -1, output, 0);
157                         }
158                 }
159
160                 [Test]
161                 [ExpectedException (typeof (ArgumentException))]
162                 public void TransformBlock_InputCount_Overflow () 
163                 {
164                         byte[] input = new byte [15];
165                         byte[] output = new byte [16];
166                         using (ICryptoTransform t = new ToBase64Transform ()) {
167                                 t.TransformBlock (input, 0, Int32.MaxValue, output, 0);
168                         }
169                 }
170
171                 [Test]
172 #if NET_2_0
173                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
174 #else
175                 [ExpectedException (typeof (IndexOutOfRangeException))]
176 #endif
177                 public void TransformBlock_OutputOffset_Negative () 
178                 {
179                         byte[] input = new byte [15];
180                         byte[] output = new byte [16];
181                         using (ICryptoTransform t = new ToBase64Transform ()) {
182                                 t.TransformBlock (input, 0, input.Length, output, -1);
183                         }
184                 }
185
186                 [Test]
187 #if NET_2_0
188                 [ExpectedException (typeof (ArgumentException))]
189 #else
190                 [ExpectedException (typeof (IndexOutOfRangeException))]
191 #endif
192                 public void TransformBlock_OutputOffset_Overflow () 
193                 {
194                         byte[] input = new byte [15];
195                         byte[] output = new byte [16];
196                         using (ICryptoTransform t = new ToBase64Transform ()) {
197                                 t.TransformBlock (input, 0, input.Length, output, Int32.MaxValue);
198                         }
199                 }
200
201                 [Test]
202                 [ExpectedException (typeof (ArgumentNullException))]
203                 public void TransformFinalBlock_Input_Null () 
204                 {
205                         using (ICryptoTransform t = new ToBase64Transform ()) {
206                                 t.TransformFinalBlock (null, 0, 15);
207                         }
208                 }
209
210                 [Test]
211                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
212                 public void TransformFinalBlock_InputOffset_Negative () 
213                 {
214                         byte[] input = new byte [15];
215                         using (ICryptoTransform t = new ToBase64Transform ()) {
216                                 t.TransformFinalBlock (input, -1, input.Length);
217                         }
218                 }
219
220                 [Test]
221                 [ExpectedException (typeof (ArgumentException))]
222                 public void TransformFinalBlock_InputOffset_Overflow () 
223                 {
224                         byte[] input = new byte [15];
225                         using (ICryptoTransform t = new ToBase64Transform ()) {
226                                 t.TransformFinalBlock (input, Int32.MaxValue, input.Length);
227                         }
228                 }
229
230                 [Test]
231                 [ExpectedException (typeof (ArgumentException))]
232                 public void TransformFinalBlock_InputCount_Negative () 
233                 {
234                         byte[] input = new byte [15];
235                         using (ICryptoTransform t = new ToBase64Transform ()) {
236                                 t.TransformFinalBlock (input, 0, -1);
237                         }
238                 }
239
240                 [Test]
241                 [ExpectedException (typeof (ArgumentException))]
242                 public void TransformFinalBlock_InputCount_Overflow () 
243                 {
244                         byte[] input = new byte [15];
245                         using (ICryptoTransform t = new ToBase64Transform ()) {
246                                 t.TransformFinalBlock (input, 0, Int32.MaxValue);
247                         }
248                 }
249         }
250 }