(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / corlib / Test / System.Security.Cryptography / FromBase64Transform.cs
blobb079b40b9e1db6022a261ab341645adb1624805c
1 //
2 // TestSuite.System.Security.Cryptography.FromBase64Transform.cs
3 //
4 // Author:
5 // Martin Baulig (martin@gnome.org)
6 // Sebastien Pouliot <sebastien@ximian.com>
7 //
8 // (C) 2002 Ximian, Inc. http://www.ximian.com
9 // (C) 2004 Novell http://www.novell.com
12 using System;
13 using System.Security.Cryptography;
14 using NUnit.Framework;
16 namespace MonoTests.System.Security.Cryptography {
18 [TestFixture]
19 public class FromBase64TransformTest : Assertion {
21 private FromBase64Transform _algo;
23 [SetUp]
24 public void SetUp ()
26 _algo = new FromBase64Transform ();
29 protected void TransformFinalBlock (string name, byte[] input, byte[] expected,
30 int inputOffset, int inputCount)
32 byte[] output = _algo.TransformFinalBlock (input, inputOffset, inputCount);
34 AssertEquals (name, expected.Length, output.Length);
35 for (int i = 0; i < expected.Length; i++)
36 AssertEquals (name + "(" + i + ")", expected [i], output [i]);
39 protected void TransformFinalBlock (string name, byte[] input, byte[] expected)
41 TransformFinalBlock (name, input, expected, 0, input.Length);
44 [Test]
45 public void Properties ()
47 Assert ("CanReuseTransform", _algo.CanReuseTransform);
48 Assert ("CanTransformMultipleBlocks", !_algo.CanTransformMultipleBlocks);
49 AssertEquals ("InputBlockSize", 1, _algo.InputBlockSize);
50 AssertEquals ("OutputBlockSize", 3, _algo.OutputBlockSize);
53 [Test]
54 public void A0 ()
56 byte[] input = { 114, 108, 112, 55, 81, 115, 110, 69 };
57 byte[] expected = { 174, 90, 123, 66, 201, 196 };
59 _algo = new FromBase64Transform (FromBase64TransformMode.DoNotIgnoreWhiteSpaces);
60 TransformFinalBlock ("#A0", input, expected);
63 [Test]
64 public void A1 ()
66 byte[] input = { 114, 108, 112, 55, 81, 115, 110, 69 };
67 byte[] expected = { 174, 90, 123, 66, 201, 196 };
69 TransformFinalBlock ("#A1", input, expected);
72 [Test]
73 public void A2 ()
75 byte[] input = { 114, 108, 112, 55, 81, 115, 61, 61 };
76 byte[] expected = { 174, 90, 123, 66 };
78 TransformFinalBlock ("#A2", input, expected);
81 [Test]
82 public void A3 ()
84 byte[] input = { 114, 108, 112, 55, 81, 115, 61, 61 };
85 byte[] expected = { 150, 158, 208 };
87 TransformFinalBlock ("#A3", input, expected, 1, 5);
90 [Test]
91 public void IgnoreTAB ()
93 byte[] input = { 9, 114, 108, 112, 55, 9, 81, 115, 61, 61, 9 };
94 byte[] expected = { 174, 90, 123, 66 };
96 TransformFinalBlock ("IgnoreTAB", input, expected);
99 [Test]
100 public void IgnoreLF ()
102 byte[] input = { 10, 114, 108, 112, 55, 10, 81, 115, 61, 61, 10 };
103 byte[] expected = { 174, 90, 123, 66 };
105 TransformFinalBlock ("IgnoreLF", input, expected);
108 [Test]
109 public void IgnoreCR ()
111 byte[] input = { 13, 114, 108, 112, 55, 13, 81, 115, 61, 61, 13 };
112 byte[] expected = { 174, 90, 123, 66 };
114 TransformFinalBlock ("IgnoreCR", input, expected);
117 [Test]
118 public void IgnoreSPACE ()
120 byte[] input = { 32, 114, 108, 112, 55, 32, 81, 115, 61, 61, 32 };
121 byte[] expected = { 174, 90, 123, 66 };
123 TransformFinalBlock ("IgnoreSPACE", input, expected);
126 [Test]
127 [ExpectedException (typeof (FormatException))]
128 public void DontIgnore ()
130 byte[] input = { 7, 114, 108, 112, 55, 81, 115, 61, 61 };
131 byte[] expected = { 174, 90, 123, 66 };
133 TransformFinalBlock ("DontIgnore", input, expected);
136 [Test]
137 public void ReuseTransform ()
139 byte[] input = { 114, 108, 112, 55, 81, 115, 61, 61 };
140 byte[] expected = { 174, 90, 123, 66 };
142 TransformFinalBlock ("UseTransform", input, expected);
143 TransformFinalBlock ("ReuseTransform", input, expected);
146 [Test]
147 [ExpectedException (typeof (ObjectDisposedException))]
148 public void ReuseDisposedTransform ()
150 byte[] input = { 114, 108, 112, 55, 81, 115, 61, 61 };
151 byte[] output = new byte [16];
153 _algo.Clear ();
154 _algo.TransformBlock (input, 0, input.Length, output, 0);
157 [Test]
158 [ExpectedException (typeof (ObjectDisposedException))]
159 public void ReuseDisposedTransformFinal ()
161 byte[] input = { 114, 108, 112, 55, 81, 115, 61, 61 };
163 _algo.Clear ();
164 _algo.TransformFinalBlock (input, 0, input.Length);
167 [Test]
168 public void InvalidLength ()
170 byte[] input = { 114, 108, 112 };
171 byte[] result = _algo.TransformFinalBlock (input, 0, input.Length);
172 AssertEquals ("No result", 0, result.Length);
175 [Test]
176 public void InvalidData ()
178 byte[] input = { 114, 108, 112, 32 };
179 byte[] result = _algo.TransformFinalBlock (input, 0, input.Length);
180 AssertEquals ("No result", 0, result.Length);
183 [Test]
184 public void Dispose ()
186 byte[] input = { 114, 108, 112, 55, 81, 115, 61, 61 };
187 byte[] expected = { 174, 90, 123, 66 };
188 byte[] output = null;
190 using (ICryptoTransform t = new FromBase64Transform ()) {
191 output = t.TransformFinalBlock (input, 0, input.Length);
194 AssertEquals ("IDisposable", expected.Length, output.Length);
195 for (int i = 0; i < expected.Length; i++)
196 AssertEquals ("IDisposable(" + i + ")", expected [i], output [i]);
199 [Test]
200 [ExpectedException (typeof (ArgumentNullException))]
201 public void TransformBlock_Input_Null ()
203 byte[] output = new byte [16];
204 using (ICryptoTransform t = new FromBase64Transform ()) {
205 t.TransformBlock (null, 0, output.Length, output, 0);
209 [Test]
210 [ExpectedException (typeof (ArgumentOutOfRangeException))]
211 public void TransformBlock_InputOffset_Negative ()
213 byte[] input = new byte [16];
214 byte[] output = new byte [16];
215 using (ICryptoTransform t = new FromBase64Transform ()) {
216 t.TransformBlock (input, -1, input.Length, output, 0);
220 [Test]
221 [ExpectedException (typeof (ArgumentException))]
222 public void TransformBlock_InputOffset_Overflow ()
224 byte[] input = new byte [16];
225 byte[] output = new byte [16];
226 using (ICryptoTransform t = new FromBase64Transform ()) {
227 t.TransformBlock (input, Int32.MaxValue, input.Length, output, 0);
231 [Test]
232 [ExpectedException (typeof (OverflowException))]
233 public void TransformBlock_InputCount_Negative ()
235 byte[] input = new byte [16];
236 byte[] output = new byte [16];
237 using (ICryptoTransform t = new FromBase64Transform ()) {
238 t.TransformBlock (input, 0, -1, output, 0);
242 [Test]
243 [ExpectedException (typeof (OutOfMemoryException))]
244 public void TransformBlock_InputCount_Overflow ()
246 byte[] input = new byte [16];
247 byte[] output = new byte [16];
248 using (ICryptoTransform t = new FromBase64Transform ()) {
249 t.TransformBlock (input, 0, Int32.MaxValue, output, 0);
253 [Test]
254 [ExpectedException (typeof (FormatException))]
255 public void TransformBlock_Output_Null ()
257 byte[] input = new byte [16];
258 using (ICryptoTransform t = new FromBase64Transform ()) {
259 t.TransformBlock (input, 0, input.Length, null, 0);
263 [Test]
264 [ExpectedException (typeof (FormatException))]
265 public void TransformBlock_OutputOffset_Negative ()
267 byte[] input = new byte [16];
268 byte[] output = new byte [16];
269 using (ICryptoTransform t = new FromBase64Transform ()) {
270 t.TransformBlock (input, 0, input.Length, output, -1);
274 [Test]
275 [ExpectedException (typeof (FormatException))]
276 public void TransformBlock_OutputOffset_Overflow ()
278 byte[] input = new byte [16];
279 byte[] output = new byte [16];
280 using (ICryptoTransform t = new FromBase64Transform ()) {
281 t.TransformBlock (input, 0, input.Length, output, Int32.MaxValue);
285 [Test]
286 [ExpectedException (typeof (ArgumentNullException))]
287 public void TransformFinalBlock_Input_Null ()
289 using (ICryptoTransform t = new FromBase64Transform ()) {
290 t.TransformFinalBlock (null, 0, 16);
294 [Test]
295 [ExpectedException (typeof (ArgumentOutOfRangeException))]
296 public void TransformFinalBlock_InputOffset_Negative ()
298 byte[] input = new byte [16];
299 using (ICryptoTransform t = new FromBase64Transform ()) {
300 t.TransformFinalBlock (input, -1, input.Length);
304 [Test]
305 [ExpectedException (typeof (ArgumentException))]
306 public void TransformFinalBlock_InputOffset_Overflow ()
308 byte[] input = new byte [16];
309 using (ICryptoTransform t = new FromBase64Transform ()) {
310 t.TransformFinalBlock (input, Int32.MaxValue, input.Length);
314 [Test]
315 [ExpectedException (typeof (OverflowException))]
316 public void TransformFinalBlock_InputCount_Negative ()
318 byte[] input = new byte [16];
319 using (ICryptoTransform t = new FromBase64Transform ()) {
320 t.TransformFinalBlock (input, 0, -1);
324 [Test]
325 [ExpectedException (typeof (OutOfMemoryException))]
326 public void TransformFinalBlock_InputCount_Overflow ()
328 byte[] input = new byte [16];
329 using (ICryptoTransform t = new FromBase64Transform ()) {
330 t.TransformFinalBlock (input, 0, Int32.MaxValue);