public static IEnumerable <object[]> GetByteCount_TestData()
        {
            string randomString = EncodingHelpers.GetRandomString(10);

            yield return(new object[] { string.Empty, 0, 0, 0 });

            yield return(new object[] { randomString, 0, randomString.Length, 20 });

            yield return(new object[] { randomString, 0, 1, 2 });
        }
Exemple #2
0
        public static IEnumerable <object[]> GetString_TestData()
        {
            string randomString = EncodingHelpers.GetRandomString(10);

            byte[] randomBytes = new UnicodeEncoding().GetBytes(randomString);
            yield return(new object[] { randomBytes, 0, randomBytes.Length, randomString });

            yield return(new object[] { randomBytes, 0, 2, randomString.Substring(0, 1) });

            yield return(new object[] { randomBytes, 0, 0, string.Empty });

            yield return(new object[] { randomBytes, randomBytes.Length, 0, string.Empty });
        }
        public static IEnumerable <object[]> GetCharCount_TestData()
        {
            string randomString = EncodingHelpers.GetRandomString(10);

            byte[] randomBytes = new UnicodeEncoding().GetBytes(randomString);
            yield return(new object[] { randomBytes, 0, randomBytes.Length, randomBytes.Length / 2 });

            yield return(new object[] { randomBytes, 0, 0, 0 });

            yield return(new object[] { randomBytes, randomBytes.Length, 0, 0 });

            yield return(new object[] { randomBytes, 0, 2, 1 });
        }
        public static IEnumerable <object[]> GetBytes_TestData()
        {
            string randomString = EncodingHelpers.GetRandomString(10);

            yield return(new object[] { randomString, 0, randomString.Length, new byte[30], 5, 20 });

            yield return(new object[] { randomString, 0, 1, new byte[30], 0, 2 });

            yield return(new object[] { randomString, 0, 0, new byte[20], 20, 0 });

            yield return(new object[] { randomString, randomString.Length, 0, new byte[20], 20, 0 });

            yield return(new object[] { string.Empty, 0, 0, new byte[0], 0, 0 });
        }
Exemple #5
0
        public void GetDecoder()
        {
            char[]  sourceChars      = EncodingHelpers.GetRandomString(10).ToCharArray();
            char[]  destinationChars = new char[10];
            byte[]  bytes            = new UnicodeEncoding().GetBytes(sourceChars);
            int     bytesUsed;
            int     charsUsed;
            bool    completed;
            Decoder decoder = new UnicodeEncoding().GetDecoder();

            decoder.Convert(bytes, 0, 20, destinationChars, 0, 10, true, out bytesUsed, out charsUsed, out completed);
            if (completed)
            {
                Assert.Equal(sourceChars, destinationChars);
            }
        }
Exemple #6
0
        public void GetEncoder()
        {
            char[]  chars    = EncodingHelpers.GetRandomString(10).ToCharArray();
            byte[]  bytes    = new UnicodeEncoding().GetBytes(chars);
            byte[]  desBytes = new byte[20];
            int     buffer;
            int     outChars;
            bool    completed;
            Encoder encoder = new UnicodeEncoding().GetEncoder();

            encoder.Convert(chars, 0, 10, desBytes, 0, 20, true, out buffer, out outChars, out completed);
            if (completed)
            {
                Assert.Equal(bytes, desBytes);
            }
        }
Exemple #7
0
        public static IEnumerable <object[]> GetChars_TestData()
        {
            string randomString = EncodingHelpers.GetRandomString(10);

            byte[] randomBytesBasic = new UnicodeEncoding().GetBytes(randomString);

            yield return(new object[] { randomBytesBasic, 0, randomBytesBasic.Length, new char[randomString.Length], 0, randomBytesBasic.Length / 2 });

            int randomByteCount = s_randomDataGenerator.GetInt16(-55) % randomString.Length + 1;

            byte[] randomBytesAdvanced = new UnicodeEncoding().GetBytes(randomString.ToCharArray());
            yield return(new object[] { randomBytesAdvanced, 0, randomByteCount * 2, new char[randomString.Length], 0, randomByteCount });

            yield return(new object[] { randomBytesBasic, 0, 0, new char[randomString.Length], randomString.Length, 0 });

            yield return(new object[] { randomBytesBasic, 20, 0, new char[randomString.Length], randomString.Length, 0 });
        }
        public static IEnumerable <object[]> GetChars_TestData()
        {
            string randomString = EncodingHelpers.GetRandomString(10);

            byte[] randomBytes = new UnicodeEncoding().GetBytes(randomString);

            yield return(new object[] { randomBytes, 0, randomBytes.Length, randomString.ToCharArray() });

            int randomByteCount = s_randomDataGenerator.GetInt16(-55) % randomString.Length + 1;

            yield return(new object[] { randomBytes, 0, randomByteCount * 2, randomString.ToCharArray(0, randomByteCount) });

            yield return(new object[] { randomBytes, 0, 2, randomString.ToCharArray(0, 1) });

            yield return(new object[] { randomBytes, 2, 2, randomString.ToCharArray(1, 1) });

            yield return(new object[] { randomBytes, 0, 0, new char[0] });

            yield return(new object[] { randomBytes, 20, 0, new char[0] });
        }