Changeset 855


Ignore:
Timestamp:
Nov 16, 2009, 6:27:02 PM (12 years ago)
Author:
pretzsch
Message:

+ MD5 plugin: Additional tests

Location:
trunk/CrypPlugins/MD5Test
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/MD5Test/MD5Test.csproj

    r854 r855  
    99    <OutputType>Library</OutputType>
    1010    <AppDesignerFolder>Properties</AppDesignerFolder>
    11     <RootNamespace>Cryptool.MD5.Test</RootNamespace>
     11    <RootNamespace>Test.Cryptool.MD5</RootNamespace>
    1212    <AssemblyName>MD5Test</AssemblyName>
    1313    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
  • trunk/CrypPlugins/MD5Test/PresentableMd5Test.cs

    r854 r855  
    55using NUnit.Framework;
    66using System.IO;
     7using Cryptool.MD5;
    78
    8 namespace Cryptool.MD5.Test
     9namespace Test.Cryptool.MD5
    910{
    1011    [TestFixture]
     
    2021
    2122        [Test]
    22         public void CompareResultsToBuiltinMd5()
     23        public void VerifyResultsForRandomData()
    2324        {
    2425            const int TEST_RUNS = 20;
     26            const int MIN_TEST_DATA_LENGTH = 1;
     27            const int MAX_TEST_DATA_LENGTH = 1000;
    2528
    2629            for (int i = 0; i < TEST_RUNS; i++)
    2730            {
    28                 byte[] testData = GenerateTestData();
    29 
    30                 System.Security.Cryptography.MD5 builtinMD5 = System.Security.Cryptography.MD5.Create();
    31                 byte[] builtinResult = builtinMD5.ComputeHash(testData);
    32 
    33                 PresentableMd5 presentableMd5 = new PresentableMd5(new MemoryStream(testData));
    34                 presentableMd5.NextStepUntilFinished();
    35                 byte[] presentableMd5Result = presentableMd5.HashValueBytes;
    36 
    37                 Assert.AreEqual(builtinResult, presentableMd5Result);
     31                byte[] testData = GenerateTestData(MIN_TEST_DATA_LENGTH, MAX_TEST_DATA_LENGTH);
     32                VerifyResult(testData);
    3833            }
    3934        }
    4035
    41         private byte[] GenerateTestData()
     36        [Test]
     37        public void VerifyResultForEmptyData()
    4238        {
    43             const int MIN_TEST_DATA_LENGTH = 1;
    44             const int MAX_TEST_DATA_LENGTH = 1000;
     39            byte[] emptyByteArray = new byte[0];
     40            VerifyResult(emptyByteArray);
     41        }
    4542
    46             int resultLength = MIN_TEST_DATA_LENGTH + RNG.Next(MAX_TEST_DATA_LENGTH - MIN_TEST_DATA_LENGTH) + 1;
    47             byte[] result = new byte[resultLength];
     43        [Test]
     44        public void VerifyResultForRandomDataWithInterestingLength()
     45        {
     46            VerifyResult(GenerateTestData(54));
     47            VerifyResult(GenerateTestData(55));
     48            VerifyResult(GenerateTestData(56));
     49        }
     50
     51        private void VerifyResult(byte[] data)
     52        {
     53            System.Security.Cryptography.MD5 builtinMD5 = System.Security.Cryptography.MD5.Create();
     54            byte[] builtinResult = builtinMD5.ComputeHash(data);
     55
     56            PresentableMd5 presentableMd5 = new PresentableMd5(new MemoryStream(data));
     57            presentableMd5.NextStepUntilFinished();
     58            byte[] presentableMd5Result = presentableMd5.HashValueBytes;
     59
     60            Assert.AreEqual(builtinResult, presentableMd5Result);
     61        }
     62
     63        private byte[] GenerateTestData(int minLength, int maxLength)
     64        {
     65            int resultLength = minLength + RNG.Next(maxLength - minLength) + 1;
     66            return GenerateTestData(resultLength);
     67        }
     68
     69        private byte[] GenerateTestData(int length)
     70        {
     71            byte[] result = new byte[length];
    4872
    4973            RNG.NextBytes(result);
Note: See TracChangeset for help on using the changeset viewer.