Пример #1
0
        public void TestSingleByteCalls()
        {
            FrameProtocolTester tester = new FrameProtocolTester();
            FrameProtocolFilter filter = new FrameProtocolFilter();

            filter.HandleBytes(tester, new Byte[] { 0 });
            filter.HandleBytes(tester, new Byte[] { 0 });
            filter.HandleBytes(tester, new Byte[] { 0 });
            tester.ExpectFrames(new Byte[0]);
            filter.HandleBytes(tester, new Byte[] { 0 });
            tester.AssertNoMoreExpectedFrames();

            filter.HandleBytes(tester, new Byte[] { 0 });
            filter.HandleBytes(tester, new Byte[] { 0 });
            filter.HandleBytes(tester, new Byte[] { 0 });
            filter.HandleBytes(tester, new Byte[] { 1 });
            tester.ExpectFrames(new Byte[] { 0x49 });
            filter.HandleBytes(tester, new Byte[] { 0x49 });
            tester.AssertNoMoreExpectedFrames();

            filter.HandleBytes(tester, new Byte[] { 0 });
            filter.HandleBytes(tester, new Byte[] { 0 });
            filter.HandleBytes(tester, new Byte[] { 0 });
            filter.HandleBytes(tester, new Byte[] { 2 });
            filter.HandleBytes(tester, new Byte[] { 0xE1 });
            tester.ExpectFrames(new Byte[] { 0xE1, 0xCA });
            filter.HandleBytes(tester, new Byte[] { 0xCA });
            tester.AssertNoMoreExpectedFrames();
        }
Пример #2
0
        public void TestMultipleHandleBytesPerCommand()
        {
            FrameProtocolTester tester = new FrameProtocolTester();
            FrameProtocolFilter filter = new FrameProtocolFilter();

            filter.HandleBytes(tester, new Byte[] { 0, 0, 0, 1 });
            tester.ExpectFrames(new Byte[] { 0x72 });
            filter.HandleBytes(tester, new Byte[] { 0x72 });
            tester.AssertNoMoreExpectedFrames();

            filter.HandleBytes(tester, new Byte[] { 0, 0, 0 });
            filter.HandleBytes(tester, new Byte[] { 2 });
            filter.HandleBytes(tester, new Byte[] { 0x84 });
            tester.ExpectFrames(new Byte[] { 0x84, 0xF0 });
            filter.HandleBytes(tester, new Byte[] { 0xF0 });
            tester.AssertNoMoreExpectedFrames();

            filter.HandleBytes(tester, new Byte[] { 0 });
            filter.HandleBytes(tester, new Byte[] { 0, 0, 10 });
            filter.HandleBytes(tester, new Byte[] { 0x12, 0x34, 0x56, 0x78 });
            filter.HandleBytes(tester, new Byte[] { 0x9A, 0xBC });
            tester.ExpectFrames(new Byte[] { 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0, 0x12, 0x34 });
            filter.HandleBytes(tester, new Byte[] { 0xDE, 0xF0, 0x12, 0x34 });
            tester.AssertNoMoreExpectedFrames();
        }
Пример #3
0
        public void TestMultipleCommandsPerHandleBytes()
        {
            FrameProtocolTester tester = new FrameProtocolTester();
            FrameProtocolFilter filter = new FrameProtocolFilter();

            tester.ExpectFrames(new Byte[0], new Byte[] { 0xA4 }, new Byte[0], new Byte[] { 0x73, 0xF3, 0x29, 0x44 }, new Byte[0]);
            filter.HandleBytes(tester, new Byte[] { 0, 0, 0, 0, 0, 0, 0, 1, 0xA4, 0, 0, 0, 0, 0, 0, 0, 4, 0x73, 0xF3, 0x29, 0x44, 0, 0, 0, 0 });
            tester.AssertNoMoreExpectedFrames();
        }
Пример #4
0
        public void TestHeartbeat()
        {
            FrameProtocolTester tester = new FrameProtocolTester();
            FrameProtocolFilter filter = new FrameProtocolFilter();

            tester.ExpectFrames(new Byte[0]);
            filter.HandleBytes(tester, new Byte[] { 0, 0, 0, 0 });
            tester.AssertNoMoreExpectedFrames();

            tester.ExpectFrames(new Byte[0], new Byte[0]);
            filter.HandleBytes(tester, new Byte[] { 0, 0, 0, 0, 0, 0, 0, 0 });
            tester.AssertNoMoreExpectedFrames();
        }
Пример #5
0
        public void TestOverlappingHandleBytePerCommand()
        {
            FrameProtocolTester tester = new FrameProtocolTester();
            FrameProtocolFilter filter = new FrameProtocolFilter();

            tester.ExpectFrames(new Byte[0], new Byte[] { 0xA4 });
            filter.HandleBytes(tester, new Byte[] { 0, 0, 0, 0, 0, 0, 0, 1, 0xA4, 0 });
            tester.AssertNoMoreExpectedFrames();

            tester.ExpectFrames(new Byte[] { 0x73, 0xF3, 0x29, 0x44 });
            filter.HandleBytes(tester, new Byte[] { 0, 0, 4, 0x73, 0xF3, 0x29, 0x44, 0, 0 });
            tester.AssertNoMoreExpectedFrames();

            tester.ExpectFrames(new Byte[] { 0x43, 0xAB, 0x71 });
            filter.HandleBytes(tester, new Byte[] { 0, 3, 0x43, 0xAB, 0x71, 0, 0, 0, 1 });
            tester.AssertNoMoreExpectedFrames();

            tester.ExpectFrames(new Byte[] { 0xF0 }, new Byte[] { }, new Byte[] { 0x12, 0x34 }, new Byte[0]);
            filter.HandleBytes(tester, new Byte[] { 0xF0, 0, 0, 0, 0, 0, 0, 0, 2, 0x12, 0x34, 0, 0, 0, 0 });
            tester.AssertNoMoreExpectedFrames();
        }
Пример #6
0
 public FrameProtocolReceiverHandler(DataHandler dataHandler, Action disposeHandler)
 {
     this.dataHandler    = dataHandler;
     this.disposeHandler = disposeHandler;
     this.filter         = new FrameProtocolFilter();
 }
Пример #7
0
 /*
  * public static void HandleBytes(this FrameAndHeartbeatReceiverFilter filter,
  *  FrameAndHeartbeatTestCommandHandler testHandler, Byte[] bytes)
  * {
  *  filter.FilterTo(testHandler.HandleData, testHandler.HandleHeartbeat, bytes, 0, (UInt32)bytes.Length);
  * }
  */
 public static void HandleBytes(this FrameProtocolFilter filter,
                                FrameProtocolTester testHandler, Byte[] bytes)
 {
     filter.FilterTo(testHandler.HandleData, bytes, 0, (UInt32)bytes.Length);
 }