void SetupRandPartA()
        {
            if (i2 <= last)
            {
                chPrev = ch2;
                ch2    = ll8[tPos];
                tPos   = tt[tPos];
                if (rNToGo == 0)
                {
                    rNToGo = BZip2Constants.RandomNumbers[rTPos];
                    rTPos++;
                    if (rTPos == 512)
                    {
                        rTPos = 0;
                    }
                }

                rNToGo--;
                ch2 ^= (rNToGo == 1) ? 1 : 0;
                i2++;

                currentChar  = ch2;
                currentState = State.RandPartB;
                mCrc.Update(ch2);
            }
            else
            {
                EndBlock();
                InitBlock();
                SetupBlock();
            }
        }
Ejemplo n.º 2
0
        void exceptionTesting(IZipChecksum crcUnderTest)
        {
            var exception = false;

            try
            {
                crcUnderTest.Update(null);
            }
            catch (ArgumentNullException)
            {
                exception = true;
            }
            Assert.IsTrue(exception, "Passing a null buffer should cause an ArgumentNullException");

            // reset exception
            exception = false;
            try
            {
                crcUnderTest.Update(new ArraySegment <byte>(null, 0, 0).Array);
            }
            catch (ArgumentNullException)
            {
                exception = true;
            }
            Assert.IsTrue(exception, "Passing a null buffer should cause an ArgumentNullException");

            // reset exception
            exception = false;
            try
            {
                crcUnderTest.Update(new ArraySegment <byte>(check, -1, 9).Array);
            }
            catch (ArgumentOutOfRangeException)
            {
                exception = true;
            }
            Assert.IsTrue(exception, "Passing a negative offset should cause an ArgumentOutOfRangeException");

            // reset exception
            exception = false;
            try
            {
                crcUnderTest.Update(new ArraySegment <byte>(check, 10, 0).Array);
            }
            catch (ArgumentException)
            {
                exception = true;
            }
            Assert.IsTrue(exception, "Passing an offset greater than buffer.Length should cause an ArgumentException");

            // reset exception
            exception = false;
            try
            {
                crcUnderTest.Update(new ArraySegment <byte>(check, 0, -1).Array);
            }
            catch (ArgumentOutOfRangeException)
            {
                exception = true;
            }
            Assert.IsTrue(exception, "Passing a negative count should cause an ArgumentOutOfRangeException");

            // reset exception
            exception = false;
            try
            {
                crcUnderTest.Update(new ArraySegment <byte>(check, 0, 10).Array);
            }
            catch (ArgumentException)
            {
                exception = true;
            }
            Assert.IsTrue(exception, "Passing a count + offset greater than buffer.Length should cause an ArgumentException");
        }