コード例 #1
0
        public async Task <bool> RunAsync()
        {
            bool result = true;

            {
                byte[] buffer = Encoding.UTF8.GetBytes("hello world");

                MemoryStream memory_stream = new MemoryStream();
                IInputStream input_stream  = new InputStream();
                memory_stream.Write(buffer, 0, buffer.Count());

                input_stream.Initialize(memory_stream);
                ICharacterStream cStream = new CharacterStream();
                cStream.Initialize(input_stream);

                ICharacter c1 = await cStream.Get();

                result = result && (null != c1); // ICharacterStream never returns null

                ICharacter ch = null;
                // verify that Get uses a pushed character
                cStream.Push(c1);
                ch = await cStream.Get();

                result = result && (c1.Info == ch.Info);

                while (ch.Kind != CharKind.NULL)
                {
                    ch = await cStream.Get();
                }
                ch = await cStream.Get(); // verify that Get() continues to get the NULL

                result = result && (ch.Kind == CharKind.NULL);
                memory_stream.Dispose();
            }
            {
                byte[]       buffer        = Encoding.UTF8.GetBytes("\n");
                MemoryStream memory_stream = new MemoryStream();
                IInputStream input_stream  = new InputStream();
                memory_stream.Write(buffer, 0, buffer.Count());

                input_stream.Initialize(memory_stream);
                ICharacterStream cStream = new CharacterStream();
                cStream.Initialize(input_stream);
                ICharacter ch = await cStream.Get();

                result = result && (ch.Kind == CharKind.CARRAGERETURN);
                ch     = await cStream.Get();

                result = result && (ch.Kind == CharKind.NULL);
                memory_stream.Dispose();
            }
            return(result);
        }