Merge pull request #249 from pcc/xgetinputfocus
[mono.git] / mcs / class / corlib / Test / System.Security.Cryptography / SHA512Test.cs
index 430928b02c4a47317d25fa86d63558d856f0013a..a8096271ad5f298d8484e9262642bf015c4a52fb 100644 (file)
@@ -5,7 +5,7 @@
 //     Sebastien Pouliot  <sebastien@ximian.com>
 //
 // (C) 2002 Motus Technologies Inc. (http://www.motus.com)
-// (C) 2004 Novell  http://www.novell.com
+// Copyright (C) 2004, 2007-2008 Novell, Inc (http://www.novell.com)
 //
 
 using NUnit.Framework;
@@ -27,11 +27,16 @@ namespace MonoTests.System.Security.Cryptography {
 public class SHA512Test : HashAlgorithmTest {
 
        [SetUp]
-       protected override void SetUp () 
+       public override void SetUp () 
        {
                hash = SHA512.Create ();
        }
 
+       // the hash algorithm only exists as a managed implementation
+       public override bool ManagedHashImplementation {
+               get { return true; }
+       }
+
        // test vectors from NIST FIPS 186-2
 
        private string input1 = "abc";
@@ -105,8 +110,8 @@ public class SHA512Test : HashAlgorithmTest {
        public void FIPS186_a (string testName, SHA512 hash, byte[] input, byte[] result) 
        {
                byte[] output = hash.ComputeHash (input); 
-               AssertEquals (testName + ".a.1", result, output);
-               AssertEquals (testName + ".a.2", result, hash.Hash);
+               Assert.AreEqual (result, output, testName + ".a.1");
+               Assert.AreEqual (result, hash.Hash, testName + ".a.2");
                // required or next operation will still return old hash
                hash.Initialize ();
        }
@@ -114,8 +119,8 @@ public class SHA512Test : HashAlgorithmTest {
        public void FIPS186_b (string testName, SHA512 hash, byte[] input, byte[] result) 
        {
                byte[] output = hash.ComputeHash (input, 0, input.Length); 
-               AssertEquals (testName + ".b.1", result, output);
-               AssertEquals (testName + ".b.2", result, hash.Hash);
+               Assert.AreEqual (result, output, testName + ".b.1");
+               Assert.AreEqual (result, hash.Hash, testName + ".b.2");
                // required or next operation will still return old hash
                hash.Initialize ();
        }
@@ -124,8 +129,8 @@ public class SHA512Test : HashAlgorithmTest {
        {
                MemoryStream ms = new MemoryStream (input);
                byte[] output = hash.ComputeHash (ms); 
-               AssertEquals (testName + ".c.1", result, output);
-               AssertEquals (testName + ".c.2", result, hash.Hash);
+               Assert.AreEqual (result, output, testName + ".c.1");
+               Assert.AreEqual (result, hash.Hash, testName + ".c.2");
                // required or next operation will still return old hash
                hash.Initialize ();
        }
@@ -135,7 +140,8 @@ public class SHA512Test : HashAlgorithmTest {
                byte[] output = hash.TransformFinalBlock (input, 0, input.Length);
                // LAMESPEC or FIXME: TransformFinalBlock doesn't return HashValue !
                // AssertEquals( testName + ".d.1", result, output );
-               AssertEquals (testName + ".d", result, hash.Hash);
+               Assert.IsNotNull (output, testName + ".d.1");
+               Assert.AreEqual (result, hash.Hash, testName + ".d.2");
                // required or next operation will still return old hash
                hash.Initialize ();
        }
@@ -148,7 +154,8 @@ public class SHA512Test : HashAlgorithmTest {
                byte[] output = hash.TransformFinalBlock (input, input.Length - 1, 1);
                // LAMESPEC or FIXME: TransformFinalBlock doesn't return HashValue !
                // AssertEquals (testName + ".e.1", result, output);
-               AssertEquals (testName + ".e", result, hash.Hash);
+               Assert.IsNotNull (output, testName + ".e.1");
+               Assert.AreEqual (result, hash.Hash, testName + ".e.2");
                // required or next operation will still return old hash
                hash.Initialize ();
        }
@@ -163,13 +170,13 @@ public class SHA512Test : HashAlgorithmTest {
 
                // try to build the default implementation
                SHA512 hash = SHA512.Create ();
-               AssertEquals ("SHA512.Create()", hash.ToString (), defaultSHA512);
+               Assert.AreEqual (hash.ToString (), defaultSHA512, "SHA512.Create()");
 
                // try to build, in every way, a SHA512 implementation
                hash = SHA512.Create ("SHA512");
-               AssertEquals ("SHA512.Create('SHA512')", hash.ToString (), defaultSHA512);
+               Assert.AreEqual (hash.ToString (), defaultSHA512, "SHA512.Create('SHA512')");
                hash = SHA512.Create ("SHA-512");
-               AssertEquals ("SHA512.Create('SHA-512')", hash.ToString (), defaultSHA512);
+               Assert.AreEqual (hash.ToString (), defaultSHA512, "SHA512.Create('SHA-512')");
        }
 
        [Test]
@@ -185,7 +192,7 @@ public class SHA512Test : HashAlgorithmTest {
        {
                // try to build invalid implementation
                hash = SHA512.Create ("InvalidHash");
-               AssertNull ("SHA512.Create('InvalidHash')", hash);
+               Assert.IsNull (hash, "SHA512.Create('InvalidHash')");
        }
 
        [Test]
@@ -201,9 +208,9 @@ public class SHA512Test : HashAlgorithmTest {
        public virtual void StaticInfo () 
        {
                string className = hash.ToString ();
-               AssertEquals (className + ".HashSize", 512, hash.HashSize);
-               AssertEquals (className + ".InputBlockSize", 1, hash.InputBlockSize);
-               AssertEquals (className + ".OutputBlockSize", 1, hash.OutputBlockSize);
+               Assert.AreEqual (512, hash.HashSize, className + ".HashSize");
+               Assert.AreEqual (1, hash.InputBlockSize, className + ".InputBlockSize");
+               Assert.AreEqual (1, hash.OutputBlockSize, className + ".OutputBlockSize");
        }
 }