X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2Fcorlib%2FTest%2FSystem.Security.Cryptography%2FHashAlgorithmTest.cs;h=3f1278e5e328f42f9c1d4c9bf7659520399e5539;hb=987f8c63e214937c50dcb308149f7558a2cbba41;hp=ef06ba3faf7c07e664274069b63f189193ea8be9;hpb=699e59742843044f6efa1726b7cb64f19d909e64;p=mono.git diff --git a/mcs/class/corlib/Test/System.Security.Cryptography/HashAlgorithmTest.cs b/mcs/class/corlib/Test/System.Security.Cryptography/HashAlgorithmTest.cs index ef06ba3faf7..3f1278e5e32 100644 --- a/mcs/class/corlib/Test/System.Security.Cryptography/HashAlgorithmTest.cs +++ b/mcs/class/corlib/Test/System.Security.Cryptography/HashAlgorithmTest.cs @@ -5,7 +5,7 @@ // Sebastien Pouliot // // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com) -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) +// Copyright (C) 2004, 2006 Novell, Inc (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the @@ -272,9 +272,8 @@ public class HashAlgorithmTest : Assertion { } [Test] - [ExpectedException (typeof (ArgumentNullException))] -#if ! NET_2_0 - [Ignore ("System.ExecutionEngineException on MS runtime (1.1)")] +#if ONLY_1_1 + [Category ("NotDotNet")] // System.ExecutionEngineException on MS runtime (1.1) #endif public void TransformBlock_OutputBuffer_Null () { @@ -357,6 +356,129 @@ public class HashAlgorithmTest : Assertion { byte[] input = new byte [8]; hash.TransformFinalBlock (input, 0, Int32.MaxValue); } + + [Test] + [Category ("NotWorking")] // Mono nevers throws an exception (and we're all managed ;-) + public void TransformFinalBlock_Twice () + { + bool managed = (hash.GetType ().ToString ().IndexOf ("Managed") > 0); + bool exception = false; + byte[] input = new byte [8]; + hash.TransformFinalBlock (input, 0, input.Length); + try { + hash.TransformFinalBlock (input, 0, input.Length); + } + catch (CryptographicException) { + exception = true; + if (managed) + Fail ("*Managed don't throw CryptographicException"); + } + if (!managed && !exception) + Fail ("Expected CryptographicException from non *Managed classes"); + } + + [Test] + [Category ("NotWorking")] // Mono nevers throws an exception (and we're all managed ;-) + public void TransformFinalBlock_TransformBlock () + { + bool managed = (hash.GetType ().ToString ().IndexOf ("Managed") > 0); + bool exception = false; + byte[] input = new byte[8]; + hash.TransformFinalBlock (input, 0, input.Length); + try { + hash.TransformBlock (input, 0, input.Length, input, 0); + } + catch (CryptographicException) { + exception = true; + if (managed) + Fail ("*Managed don't throw CryptographicException"); + } + if (!managed && !exception) + Fail ("Expected CryptographicException from non *Managed classes"); + } + + [Test] + public void TransformFinalBlock_Twice_Initialize () + { + byte[] input = new byte[8]; + hash.TransformFinalBlock (input, 0, input.Length); + hash.Initialize (); + hash.TransformFinalBlock (input, 0, input.Length); + } + + [Test] + public void TransformFinalBlock_ReturnedBuffer () + { + byte[] input = new byte[8]; + byte[] output = hash.TransformFinalBlock (input, 0, input.Length); + AssertEquals ("buffer", input, output); + output[0] = 1; + AssertEquals ("0", 0, input[0]); // output is a copy (not a reference) + } + + private byte[] HashBuffer (bool intersect) + { + byte[] buffer = new byte [256]; + for (int i = 0; i < buffer.Length; i++) + buffer [i] = (byte) i; + + hash.Initialize (); + // ok + hash.TransformBlock (buffer, 0, 64, buffer, 0); + // bad - we rewrite the beginning of the buffer + hash.TransformBlock (buffer, 64, 128, buffer, intersect ? 0 : 64); + // ok + hash.TransformFinalBlock (buffer, 192, 64); + return hash.Hash; + } + + [Test] + public void InputOutputIntersection () + { + AssertEquals ("Intersect", HashBuffer (false), HashBuffer (true)); + } + + [Test] + [ExpectedException (typeof (NullReferenceException))] + [Category ("NotWorking")] // initialization problem ? fx2.0 only ? + public void Hash_AfterInitialize_FirstTime () + { + hash.Initialize (); + // getting the property throws + AssertNull (hash.Hash); + } + + [Test] + [ExpectedException (typeof (CryptographicUnexpectedOperationException))] + public void Hash_AfterInitialize_SecondTime () + { + byte[] input = new byte[8]; + hash.Initialize (); + hash.TransformBlock (input, 0, input.Length, input, 0); + hash.Initialize (); + // getting the property throws + AssertNull (hash.Hash); + } + + [Test] + [ExpectedException (typeof (CryptographicUnexpectedOperationException))] + public void Hash_AfterTransformBlock () + { + byte[] input = new byte[8]; + hash.Initialize (); + hash.TransformBlock (input, 0, input.Length, input, 0); + // getting the property throws + AssertNull (hash.Hash); + } + + [Test] + public void Hash_AfterTransformFinalBlock () + { + byte[] input = new byte[8]; + hash.Initialize (); + hash.TransformFinalBlock (input, 0, input.Length); + AssertNotNull (hash.Hash); + } } }