Beispiel #1
0
        protected static void ConvertTest(BaseEncoding encoding)
        {
            var initialData = new Byte[128];

            var odd = false;

            for (var index = 0; index < UnitTestsIterationsCount; index++, odd = !odd)
            {
                // Generate test data
                Random.NextBytes(initialData);

                var offset = odd ? 0 : Random.Next(64);

                var count = odd ? 128 : Random.Next(64);

                // Convert byte array to string
                var intermediateResult = odd ? encoding.Encode(initialData) : encoding.Encode(initialData, offset, count);

                // Convert string to byte array
                var actualResult = encoding.Decode(intermediateResult, 0, intermediateResult.Length);

                // Compare by item
                for (Int32 expectedResultIndex = offset, actualResultIndex = 0; expectedResultIndex < offset + count; expectedResultIndex++, actualResultIndex++)
                {
                    var expectedItem = initialData[expectedResultIndex];

                    var actualItem = actualResult[actualResultIndex];

                    Assert.AreEqual(expectedItem, actualItem);
                }
            }
        }
Beispiel #2
0
        protected static void TestDecodeOffsetCountMethodArguments(BaseEncoding encoding)
        {
            try             // null
            {
                encoding.Decode(null, 0, 2);

                Assert.Fail(typeof(ArgumentNullException).ToString());
            }
            catch (ArgumentNullException)
            {
            }

            try             // bad count
            {
                encoding.Decode("abcd", 0, -4);

                Assert.Fail(typeof(ArgumentOutOfRangeException).ToString());
            }
            catch (ArgumentOutOfRangeException)
            {
            }

            try             // bad offset
            {
                encoding.Decode("abcd", -1, 4);

                Assert.Fail(typeof(ArgumentOutOfRangeException).ToString());
            }
            catch (ArgumentOutOfRangeException)
            {
            }

            try             // bad offset
            {
                encoding.Decode("abcd", 1, 4);

                Assert.Fail(typeof(ArgumentOutOfRangeException).ToString());
            }
            catch (ArgumentOutOfRangeException)
            {
            }
        }
Beispiel #3
0
        protected static void TestDecodeMethodArguments(BaseEncoding encoding)
        {
            try             // null
            {
                encoding.Decode(null);

                Assert.Fail(typeof(ArgumentNullException).ToString());
            }
            catch (ArgumentNullException)
            {
            }
        }