public void RDAMessageParserShouldReturnFalseIfNoMessageToBuild()
        {
            var fifoStream = new FifoStream();

            var desktopMessage = new RdapMessage(
                RdapMessageType.DesktopWindowImageFrameMessage,
                new byte[]
                    {
                        1, 4, 0, 0, 0, 4, 0, 0, 0, 48, 0, 0, 0, 0, 0, 0, 0, 0,
                        0, 0, 0,
                        0, 0, 0, 0, 0
                        , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                        0, 0, 0,
                        0, 0, 0, 0,
                        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 10, 0, 0, 0,
                        10, 0, 0,
                        0, 40, 0, 0,
                        0, 50, 0, 0, 0, 10, 0, 0, 0, 10, 0, 0, 0, 40, 0, 0, 0,
                        50, 0, 0,
                        0
                    }
                );

            var mouseClickEventMessage = new RdapMessage(
                RdapMessageType.MouseClickEventMessage,
                new byte[] { 2, 56, 0, 0, 0, 67, 0, 0, 0 }
                );

            var bytesToWrite1 = desktopMessage.ToBytes();
            var bytesToWrite2 = mouseClickEventMessage.ToBytes();

            var parser = new RdapMessageParser(fifoStream);

            fifoStream.Write(bytesToWrite1, 0, bytesToWrite1.Length - 10);

            RdapMessage desktopMessageOutput;
            var retVal = parser.TryParseMessage(out desktopMessageOutput);
            Assert.AreEqual(false, retVal);
            Assert.AreEqual(null, desktopMessageOutput);

            fifoStream.Write(bytesToWrite1, bytesToWrite1.Length - 10, 10);
            fifoStream.Write(bytesToWrite2, 0, bytesToWrite2.Length);

            parser.TryParseMessage(out desktopMessageOutput);
            Assert.AreEqual(RdapMessageType.DesktopWindowImageFrameMessage, desktopMessageOutput.MessageType);
            Assert.AreEqual(97, desktopMessageOutput.Data.Length);

            RdapMessage mouseClickEventMessageOutput;
            parser.TryParseMessage(out mouseClickEventMessageOutput);
            Assert.AreEqual(RdapMessageType.MouseClickEventMessage, mouseClickEventMessageOutput.MessageType);
            Assert.AreEqual(9, mouseClickEventMessageOutput.Data.Length);
        }
예제 #2
0
        public void CheckForThreadSafe()
        {
            var fs = new FifoStream();
            var actualResult = new List<byte>();
            var running = true;
            var dataToWrite = new byte[]
                                  {
                                      0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20
                                  };

            var readThread = new Thread(new ParameterizedThreadStart(delegate
            {
                while (running || fs.Length > 0)
                {
                    if (fs.Length <= 0) continue;
                    var dataBuffer = new byte[10];
                    var actualCount = fs.Read(dataBuffer, 0, dataBuffer.Length);

                    for (var i = 0; i < actualCount; i++)
                        actualResult.Add(dataBuffer[i]);
                }
            }));

            readThread.Start();

            var writeThread = new Thread(new ParameterizedThreadStart(delegate
            {
                for (var i = 0; i < 100; i++)
                    fs.Write(dataToWrite, 0, dataToWrite.Length);
            }));

            writeThread.Start();

            Assert.AreEqual(true, writeThread.Join(60000));

            running = false;

            Assert.AreEqual(true, readThread.Join(60000));

            var exceptionFlag = false;
            for (int i = 0, k=0; i < 100; i++)
            {
                foreach (var b in dataToWrite)
                {
                    exceptionFlag = (actualResult[k] != b);
                    k++;
                    if (exceptionFlag == false)
                        break;
                }
            }

            Assert.AreEqual(true, exceptionFlag);
        }
예제 #3
0
        public void ShouldAbleToAdvanceTheBytes()
        {
            var data = new byte[]
                              {
                                  0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10
                              };

            var fs = new FifoStream();
            fs.Write(data, 0, data.Length);

            fs.Advance(2);

            var finalData = new byte[8];
            fs.Read(finalData, 0, finalData.Length);

            for (var i = 2; i < data.Length; i++)
                if (data[i] != finalData[i - 2])
                    Assert.Fail("Array value is not same");
        }
예제 #4
0
        public void ShouldAbleToGetThePeekBytes()
        {
            var data = new byte[]
                              {
                                  0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10
                              };

            var fs = new FifoStream();
            fs.Write(data, 0, data.Length);

            var peekData = new byte[10];
            fs.Peek(peekData, 0, peekData.Length);

            for (var i = 0; i < data.Length; i++)
                if (data[i] != peekData[i])
                    Assert.Fail("Array value is not same");

            Assert.AreEqual(10, fs.Length);
        }
예제 #5
0
        public void ShouldAbleToWriteBytes()
        {
            var data = new byte[]
                              {
                                  0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10
                              };

            var fs = new FifoStream();
            fs.Write(data, 0, data.Length);
            Assert.AreEqual(10, fs.Length);
        }
        public void ShouldAbleToReadRDAMessageFromStream()
        {
            var fifoStream = new FifoStream();

            var desktopMessage = new RdapMessage(
                RdapMessageType.DesktopWindowImageFrameMessage,
                new byte[]
                    {
                        1, 4, 0, 0, 0, 4, 0, 0, 0, 48, 0, 0, 0, 0, 0, 0, 0, 0,
                        0, 0, 0,
                        0, 0, 0, 0, 0
                        , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                        0, 0, 0,
                        0, 0, 0, 0,
                        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 10, 0, 0, 0,
                        10, 0, 0,
                        0, 40, 0, 0,
                        0, 50, 0, 0, 0, 10, 0, 0, 0, 10, 0, 0, 0, 40, 0, 0, 0,
                        50, 0, 0,
                        0
                    }
                );

            var mouseClickEventMessage = new RdapMessage(
                RdapMessageType.MouseClickEventMessage,
                new byte[] { 2, 56, 0, 0, 0, 67, 0, 0, 0 }
                );

            var bytesToWrite1 = desktopMessage.ToBytes();
            var bytesToWrite2 = mouseClickEventMessage.ToBytes();

            fifoStream.Write(bytesToWrite1, 0, bytesToWrite1.Length);
            fifoStream.Write(bytesToWrite2, 0, bytesToWrite2.Length);

            var parser = new RdapMessageParser(fifoStream);

            RdapMessage desktopMessageOutput;
            parser.TryParseMessage(out desktopMessageOutput);
            Assert.AreEqual(RdapMessageType.DesktopWindowImageFrameMessage, desktopMessageOutput.MessageType);
            Assert.AreEqual(97, desktopMessageOutput.Data.Length);

            RdapMessage mouseClickEventMessageOutput;
            parser.TryParseMessage(out mouseClickEventMessageOutput);
            Assert.AreEqual(RdapMessageType.MouseClickEventMessage, mouseClickEventMessageOutput.MessageType);
            Assert.AreEqual(9, mouseClickEventMessageOutput.Data.Length);
        }