Beispiel #1
0
        public AllDecodeScenarios()
        {
            // Decode 0 character.
            var doneResult    = new DecodeExpectedData(OperationStatus.Done, 0, 0, new byte[0]);
            var encodedString = string.Empty;

            Add(Input(encodedString, false), doneResult);
            Add(Input(encodedString, true), doneResult);

            // Decode 1 character.
            // One character is special and can never be decoded.
            var needMoreDataResult = new DecodeExpectedData(OperationStatus.NeedMoreData, 0, 0, new byte[0]);
            var invalidDataResult  = new DecodeExpectedData(OperationStatus.InvalidData, 0, 0, new byte[0]);

            encodedString = Z85eSampleData.GetHelloString(1);

            Add(Input(encodedString, false), needMoreDataResult);
            Add(Input(encodedString, true), invalidDataResult);

            // Decode 2 chars.
            encodedString = Z85eSampleData.GetHelloString(2);
            var paddedOneByteFinalResult = new DecodeExpectedData(OperationStatus.Done, 2, 1, Z85eSampleData.HelloWorldBytes(1));

            Add(Input(encodedString, false), needMoreDataResult);
            Add(Input(encodedString, true), paddedOneByteFinalResult); // different

            // Decode 3 chars.
            encodedString = Z85eSampleData.GetHelloString(3);
            var paddedTwoByteFinalResult = new DecodeExpectedData(OperationStatus.Done, 3, 2, Z85eSampleData.HelloWorldBytes(2));

            Add(Input(encodedString, false), needMoreDataResult);
            Add(Input(encodedString, true), paddedTwoByteFinalResult); // different

            // Decode 4 chars.
            encodedString = Z85eSampleData.GetHelloString(4);
            var paddedThreeByteFinalResult = new DecodeExpectedData(OperationStatus.Done, 4, 3, Z85eSampleData.HelloWorldBytes(3));

            Add(Input(encodedString, false), needMoreDataResult);
            Add(Input(encodedString, true), paddedThreeByteFinalResult); // different

            // Decode 5 chars.
            encodedString      = Z85eSampleData.GetHelloString(5);
            needMoreDataResult = new DecodeExpectedData(OperationStatus.NeedMoreData, 5, 4, Z85eSampleData.HelloWorldBytes(4));
            var helloDecodedDoneResult = new DecodeExpectedData(OperationStatus.Done, 5, 4, Z85eSampleData.HelloWorldBytes(4));

            Add(Input(encodedString, false), needMoreDataResult);
            Add(Input(encodedString, true), helloDecodedDoneResult);

            // Decode 6 chars.
            encodedString     = Z85eSampleData.GetHelloString(6);
            invalidDataResult = new DecodeExpectedData(OperationStatus.InvalidData, 5, 4, Z85eSampleData.HelloWorldBytes(4));

            Add(Input(encodedString, false), needMoreDataResult);
            Add(Input(encodedString, true), invalidDataResult);

            // Decode 7 chars.
            encodedString      = Z85eSampleData.GetHelloString(7);
            needMoreDataResult = new DecodeExpectedData(OperationStatus.NeedMoreData, 5, 4, Z85eSampleData.HelloWorldBytes(4));
            var paddedFiveByteFinalResult = new DecodeExpectedData(OperationStatus.Done, 7, 5, Z85eSampleData.HelloWorldBytes(5));

            Add(Input(encodedString, false), needMoreDataResult);
            Add(Input(encodedString, true), paddedFiveByteFinalResult);  // different

            // Decode 8 chars.
            encodedString      = Z85eSampleData.GetHelloString(8);
            needMoreDataResult = new DecodeExpectedData(OperationStatus.NeedMoreData, 5, 4, Z85eSampleData.HelloWorldBytes(4));
            var paddedSixByteFinalResult = new DecodeExpectedData(OperationStatus.Done, 8, 6, Z85eSampleData.HelloWorldBytes(6));

            Add(Input(encodedString, false), needMoreDataResult);
            Add(Input(encodedString, true), paddedSixByteFinalResult);  // different

            // Decode 9 chars.
            encodedString      = Z85eSampleData.GetHelloString(9);
            needMoreDataResult = new DecodeExpectedData(OperationStatus.NeedMoreData, 5, 4, Z85eSampleData.HelloWorldBytes(4));
            var paddedSevenByteFinalResult = new DecodeExpectedData(OperationStatus.Done, 9, 7, Z85eSampleData.HelloWorldBytes(7));

            Add(Input(encodedString, false), needMoreDataResult);
            Add(Input(encodedString, true), paddedSevenByteFinalResult);  // different

            // Decode 10 chars.
            encodedString      = Z85eSampleData.GetHelloString(10);
            needMoreDataResult = new DecodeExpectedData(OperationStatus.NeedMoreData, 10, 8, Z85eSampleData.HelloWorldBytes(8));
            var helloWorldDecodedDoneResult = new DecodeExpectedData(OperationStatus.Done, 10, 8, Z85eSampleData.HelloWorldBytes(8));

            Add(Input(encodedString, false), needMoreDataResult);
            Add(Input(encodedString, true), helloWorldDecodedDoneResult);
        }
Beispiel #2
0
        public AllEncodeScenarios()
        {
            // Encode 0 bytes.
            var bytesToEncode = 0;

            var inputBytes         = Z85eSampleData.HelloWorldBytes(bytesToEncode);
            var needMoreDataResult = new EncodeExpectedData(OperationStatus.NeedMoreData, 0, 0, string.Empty);
            var destinationTooSmallZeroBytesResult = new EncodeExpectedData(OperationStatus.DestinationTooSmall, 0, 0, string.Empty);
            var destinationTooSmallFourBytesResult = new EncodeExpectedData(OperationStatus.DestinationTooSmall, 4, 5, Z85eSampleData.GetHelloString(5));
            var doneResult = new EncodeExpectedData(OperationStatus.Done, 0, 0, string.Empty);

            Add(Input(inputBytes, false, 0), needMoreDataResult);
            Add(Input(inputBytes, true, 0), doneResult);
            Add(Input(inputBytes, false, 10), needMoreDataResult);
            Add(Input(inputBytes, true, 10), doneResult);

            // Encode 1 byte.
            bytesToEncode = 1;
            inputBytes    = Z85eSampleData.HelloWorldBytes(bytesToEncode);
            var paddedTwoCharsFinalResult = new EncodeExpectedData(OperationStatus.Done, bytesToEncode, bytesToEncode + 1, Z85eSampleData.GetHelloString(bytesToEncode + 1));

            Add(Input(inputBytes, false, 0), needMoreDataResult);
            Add(Input(inputBytes, true, 0), destinationTooSmallZeroBytesResult);
            Add(Input(inputBytes, false, 2), needMoreDataResult);
            Add(Input(inputBytes, true, 2), paddedTwoCharsFinalResult); // different

            // Encode 2 bytes.
            bytesToEncode = 2;
            inputBytes    = Z85eSampleData.HelloWorldBytes(bytesToEncode);
            var paddedThreeCharsFinalResult = new EncodeExpectedData(OperationStatus.Done, bytesToEncode, bytesToEncode + 1, Z85eSampleData.GetHelloString(bytesToEncode + 1));

            Add(Input(inputBytes, false, 0), needMoreDataResult);
            Add(Input(inputBytes, true, 0), destinationTooSmallZeroBytesResult);
            Add(Input(inputBytes, false), needMoreDataResult);
            Add(Input(inputBytes, true), paddedThreeCharsFinalResult); // different

            // Encode 3 bytes.
            bytesToEncode = 3;
            inputBytes    = Z85eSampleData.HelloWorldBytes(bytesToEncode);
            var paddedFourCharsFinalResult = new EncodeExpectedData(OperationStatus.Done, bytesToEncode, bytesToEncode + 1, Z85eSampleData.GetHelloString(bytesToEncode + 1));

            Add(Input(inputBytes, false, 0), needMoreDataResult);
            Add(Input(inputBytes, true, 0), destinationTooSmallZeroBytesResult);
            Add(Input(inputBytes, false), needMoreDataResult);
            Add(Input(inputBytes, true), paddedFourCharsFinalResult); // different

            // Encode 4 bytes.
            // For all the same.
            bytesToEncode = 4;
            inputBytes    = Z85eSampleData.HelloWorldBytes(bytesToEncode);
            var helloDecodedDoneResult         = new EncodeExpectedData(OperationStatus.Done, bytesToEncode, bytesToEncode + 1, Z85eSampleData.GetHelloString(bytesToEncode + 1));
            var helloDecodedNeedMoreDataResult = new EncodeExpectedData(OperationStatus.NeedMoreData, bytesToEncode, bytesToEncode + 1, Z85eSampleData.GetHelloString(bytesToEncode + 1));

            Add(Input(inputBytes, false, 0), destinationTooSmallZeroBytesResult); // different
            Add(Input(inputBytes, true, 0), destinationTooSmallZeroBytesResult);
            Add(Input(inputBytes, false), helloDecodedNeedMoreDataResult);
            Add(Input(inputBytes, true), helloDecodedDoneResult);

            // Encode 5 bytes.
            // first four bytes will be encoded, 5th byte depends on mode.
            bytesToEncode      = 5;
            inputBytes         = Z85eSampleData.HelloWorldBytes(bytesToEncode);
            needMoreDataResult = new EncodeExpectedData(OperationStatus.NeedMoreData, 4, 5, Z85eSampleData.GetHelloString(5));
            var paddedSevenCharsFinalResult = new EncodeExpectedData(OperationStatus.Done, 5, 7, Z85eSampleData.GetHelloString(7));

            Add(Input(inputBytes, false, 0), destinationTooSmallZeroBytesResult); // different
            Add(Input(inputBytes, true, 0), destinationTooSmallZeroBytesResult);
            Add(Input(inputBytes, false, 5), needMoreDataResult);                 // different
            Add(Input(inputBytes, true, 5), destinationTooSmallFourBytesResult);
            Add(Input(inputBytes, false), needMoreDataResult);
            Add(Input(inputBytes, true), paddedSevenCharsFinalResult); // different

            // Encode 6 bytes.
            bytesToEncode = 6;
            inputBytes    = Z85eSampleData.HelloWorldBytes(bytesToEncode);
            var paddedEightCharsFinalResult = new EncodeExpectedData(OperationStatus.Done, 6, 8, Z85eSampleData.GetHelloString(8));

            Add(Input(inputBytes, false, 0), destinationTooSmallZeroBytesResult);
            Add(Input(inputBytes, true, 0), destinationTooSmallZeroBytesResult);
            Add(Input(inputBytes, false, 5), needMoreDataResult);  // different
            Add(Input(inputBytes, true, 5), destinationTooSmallFourBytesResult);
            Add(Input(inputBytes, false), needMoreDataResult);
            Add(Input(inputBytes, true), paddedEightCharsFinalResult);

            // Encode 7 bytes.
            bytesToEncode = 7;
            inputBytes    = Z85eSampleData.HelloWorldBytes(bytesToEncode);
            var paddedNineCharsFinalResult = new EncodeExpectedData(OperationStatus.Done, 7, 9, Z85eSampleData.GetHelloString(9));

            Add(Input(inputBytes, false, 0), destinationTooSmallZeroBytesResult);
            Add(Input(inputBytes, true, 0), destinationTooSmallZeroBytesResult);
            Add(Input(inputBytes, false, 5), needMoreDataResult);  // different
            Add(Input(inputBytes, true, 5), destinationTooSmallFourBytesResult);
            Add(Input(inputBytes, false), needMoreDataResult);
            Add(Input(inputBytes, true), paddedNineCharsFinalResult);  // different

            // Encode 8 bytes.
            bytesToEncode = 8;
            inputBytes    = Z85eSampleData.HelloWorldBytes(bytesToEncode);
            var helloWorldDecodedNeedMoreDataResult = new EncodeExpectedData(OperationStatus.NeedMoreData, bytesToEncode, bytesToEncode + 2, Z85eSampleData.GetHelloString(bytesToEncode + 2));
            var helloWorldDecodedDoneResult         = new EncodeExpectedData(OperationStatus.Done, bytesToEncode, bytesToEncode + 2, Z85eSampleData.GetHelloString(bytesToEncode + 2));

            Add(Input(inputBytes, false, 0), destinationTooSmallZeroBytesResult);
            Add(Input(inputBytes, true, 0), destinationTooSmallZeroBytesResult);
            Add(Input(inputBytes, false, 5), destinationTooSmallFourBytesResult);  // different
            Add(Input(inputBytes, true, 5), destinationTooSmallFourBytesResult);
            Add(Input(inputBytes, false), helloWorldDecodedNeedMoreDataResult);
            Add(Input(inputBytes, true), helloWorldDecodedDoneResult);
        }