Ejemplo n.º 1
0
        public void TestVeryLongXofOfEmptyDataWithStreamingOutput()
        {
            const int xofStreamingChunkSize = 250;

            var tempResult          = new byte[1000];
            var actualChunk         = new byte[xofStreamingChunkSize];
            var expectedChunk       = new byte[xofStreamingChunkSize];
            var xofOfEmptyDataBytes = Converters.ConvertHexStringToBytes(XofOfEmptyData);


            XofInstance.Initialize();
            XofInstance.TransformBytes(EmptyBytes);

            // 1
            XofInstance.DoOutput(tempResult, 0, xofStreamingChunkSize);

            Array.Copy(tempResult, 0, actualChunk, 0, xofStreamingChunkSize);
            Array.Copy(xofOfEmptyDataBytes, 0, expectedChunk, 0, xofStreamingChunkSize);

            AssertAreEqual(expectedChunk, actualChunk, $"{XofInstance.Name} streaming test 1 mismatch");

            // 2
            XofInstance.DoOutput(tempResult, xofStreamingChunkSize, xofStreamingChunkSize);

            Array.Copy(tempResult, xofStreamingChunkSize, actualChunk, 0, xofStreamingChunkSize);
            Array.Copy(xofOfEmptyDataBytes, xofStreamingChunkSize, expectedChunk, 0, xofStreamingChunkSize);

            AssertAreEqual(expectedChunk, actualChunk, $"{XofInstance.Name} streaming test 2 mismatch");

            // 3
            XofInstance.DoOutput(tempResult, 500, xofStreamingChunkSize);

            Array.Copy(tempResult, 500, actualChunk, 0, xofStreamingChunkSize);
            Array.Copy(xofOfEmptyDataBytes, 500, expectedChunk, 0, xofStreamingChunkSize);

            AssertAreEqual(expectedChunk, actualChunk, $"{XofInstance.Name} streaming test 3 mismatch");

            // 4
            XofInstance.DoOutput(tempResult, 750, xofStreamingChunkSize);

            Array.Copy(tempResult, 750, actualChunk, 0, xofStreamingChunkSize);
            Array.Copy(xofOfEmptyDataBytes, 750, expectedChunk, 0, xofStreamingChunkSize);

            AssertAreEqual(expectedChunk, actualChunk, $"{XofInstance.Name} streaming test 4 mismatch");

            ActualString   = Converters.ConvertBytesToHexString(tempResult);
            ExpectedString = XofOfEmptyData;

            AssertAreEqual(ExpectedString, ActualString);

            // Verify that Initialization Works
            XofInstance.Initialize();

            XofInstance.DoOutput(tempResult, 0, xofStreamingChunkSize);
            Array.Copy(tempResult, 0, actualChunk, 0, xofStreamingChunkSize);
            Array.Copy(xofOfEmptyDataBytes, 0, expectedChunk, 0, xofStreamingChunkSize);

            AssertAreEqual(expectedChunk, actualChunk, $"{XofInstance.Name} streaming initialization test fail");
        }
Ejemplo n.º 2
0
        public void TestOutputBufferTooShort()
        {
            XofInstance.Initialize();
            var output = new byte[XofInstance.XofSizeInBits >> 3];

            XofInstance.TransformBytes(SmallLettersAToEBytes);
            Assert.Throws <ArgumentException>(() =>
                                              XofInstance.DoOutput(output, 1, (ulong)output.Length));
        }
Ejemplo n.º 3
0
        public void TestOutputOverflow()
        {
            XofInstance.Initialize();
            var output = new byte[(XofInstance.XofSizeInBits >> 3) + 1];

            XofInstance.TransformBytes(SmallLettersAToEBytes);
            Assert.Throws <ArgumentException>(() =>
                                              XofInstance.DoOutput(output, 0, (ulong)output.Length));
        }
Ejemplo n.º 4
0
        public void TestXofShouldRaiseExceptionOnWriteAfterRead()
        {
            XofInstance.Initialize();
            var output = new byte[XofInstance.XofSizeInBits >> 3];

            XofInstance.TransformBytes(SmallLettersAToEBytes);
            XofInstance.DoOutput(output, 0, (ulong)output.Length);
            // this call below should raise exception since we have already read from the Xof
            Assert.Throws <InvalidOperationException>(() => XofInstance.TransformBytes(SmallLettersAToEBytes));
        }
Ejemplo n.º 5
0
        public void TestXofCloningWorks()
        {
            XofInstance.Initialize();
            XofInstance.TransformBytes(ZeroToOneHundredAndNinetyNineBytes);
            var xofInstanceClone = (IXOF)XofInstance.Clone();

            var result      = new byte[XofInstance.XofSizeInBits >> 3];
            var resultClone = new byte[xofInstanceClone.XofSizeInBits >> 3];

            XofInstance.DoOutput(result, 0, (ulong)result.Length);
            xofInstanceClone.DoOutput(resultClone, 0, (ulong)resultClone.Length);

            AssertAreEqual(result, resultClone, $"Error in '{XofInstance.Name}' cloning");
        }
Ejemplo n.º 6
0
 public void TestNullDestinationShouldThrowsCorrectException()
 {
     XofInstance.Initialize();
     XofInstance.TransformBytes(SmallLettersAToEBytes);
     Assert.Throws <ArgumentNullException>(() => XofInstance.DoOutput(NullBytes, 0, 0));
 }