2 // ToBase64TransformTest.cs - NUnit Test Cases for ToBase64Transform
5 // Sebastien Pouliot (sebastien@ximian.com)
7 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
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.
29 using NUnit.Framework;
31 using System.Security.Cryptography;
33 namespace MonoTests.System.Security.Cryptography {
36 public class ToBase64TransformTest : Assertion {
39 public void Properties ()
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);
49 [ExpectedException (typeof (ArgumentNullException))]
50 public void TransformBlock_NullInput ()
52 byte[] output = new byte [4];
53 ToBase64Transform t = new ToBase64Transform ();
54 t.TransformBlock (null, 0, 0, output, 0);
58 public void TransformBlock_WrongLength ()
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));
69 [ExpectedException (typeof (ArgumentNullException))]
71 [Category ("NotDotNet")] // MS throw a ExecutionEngineException
73 public void TransformBlock_NullOutput ()
75 byte[] input = new byte [3];
76 ToBase64Transform t = new ToBase64Transform ();
77 t.TransformBlock (input, 0, 3, null, 0);
81 [ExpectedException (typeof (ObjectDisposedException))]
82 public void TransformBlock_Dispose ()
84 byte[] input = new byte [3];
85 byte[] output = new byte [4];
86 ToBase64Transform t = new ToBase64Transform ();
88 t.TransformBlock (input, 0, input.Length, output, 0);
92 [ExpectedException (typeof (ArgumentNullException))]
93 public void TransformFinalBlock_Null ()
95 byte[] input = new byte [3];
96 ToBase64Transform t = new ToBase64Transform ();
97 t.TransformFinalBlock (null, 0, 3);
101 public void TransformFinalBlock_SmallLength ()
103 byte[] input = new byte [2]; // smaller than InputBlockSize
104 ToBase64Transform t = new ToBase64Transform ();
105 t.TransformFinalBlock (input, 0, 2);
109 [ExpectedException (typeof (ArgumentOutOfRangeException))]
110 public void TransformFinalBlock_WrongLength ()
112 byte[] input = new byte [6];
113 ToBase64Transform t = new ToBase64Transform ();
114 t.TransformFinalBlock (input, 0, 6);
118 [ExpectedException (typeof (ObjectDisposedException))]
119 public void TransformFinalBlock_Dispose ()
121 byte[] input = new byte [3];
122 ToBase64Transform t = new ToBase64Transform ();
124 t.TransformFinalBlock (input, 0, input.Length);
128 [ExpectedException (typeof (ArgumentOutOfRangeException))]
129 public void TransformBlock_InputOffset_Negative ()
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);
139 [ExpectedException (typeof (ArgumentException))]
140 public void TransformBlock_InputOffset_Overflow ()
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);
150 [ExpectedException (typeof (ArgumentException))]
151 public void TransformBlock_InputCount_Negative ()
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);
161 [ExpectedException (typeof (ArgumentException))]
162 public void TransformBlock_InputCount_Overflow ()
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);
173 [ExpectedException (typeof (ArgumentOutOfRangeException))]
175 [ExpectedException (typeof (IndexOutOfRangeException))]
177 public void TransformBlock_OutputOffset_Negative ()
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);
188 [ExpectedException (typeof (ArgumentException))]
190 [ExpectedException (typeof (IndexOutOfRangeException))]
192 public void TransformBlock_OutputOffset_Overflow ()
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);
202 [ExpectedException (typeof (ArgumentNullException))]
203 public void TransformFinalBlock_Input_Null ()
205 using (ICryptoTransform t = new ToBase64Transform ()) {
206 t.TransformFinalBlock (null, 0, 15);
211 [ExpectedException (typeof (ArgumentOutOfRangeException))]
212 public void TransformFinalBlock_InputOffset_Negative ()
214 byte[] input = new byte [15];
215 using (ICryptoTransform t = new ToBase64Transform ()) {
216 t.TransformFinalBlock (input, -1, input.Length);
221 [ExpectedException (typeof (ArgumentException))]
222 public void TransformFinalBlock_InputOffset_Overflow ()
224 byte[] input = new byte [15];
225 using (ICryptoTransform t = new ToBase64Transform ()) {
226 t.TransformFinalBlock (input, Int32.MaxValue, input.Length);
231 [ExpectedException (typeof (ArgumentException))]
232 public void TransformFinalBlock_InputCount_Negative ()
234 byte[] input = new byte [15];
235 using (ICryptoTransform t = new ToBase64Transform ()) {
236 t.TransformFinalBlock (input, 0, -1);
241 [ExpectedException (typeof (ArgumentException))]
242 public void TransformFinalBlock_InputCount_Overflow ()
244 byte[] input = new byte [15];
245 using (ICryptoTransform t = new ToBase64Transform ()) {
246 t.TransformFinalBlock (input, 0, Int32.MaxValue);