private void TestContent <type>(SBUSNet_message _dateFrame, type _testValue, System.Action <SBUSNet_message, type> comparer)
        {
            ResponseSimulator _sim   = new ResponseSimulator(C_RegistersCount, _testValue);
            RecStateEnum      _state = RecStateEnum.RSE_BeforeHeading;

            foreach (byte _bix in _sim)
            {
                FrameStateMachine.DepCharacterTypeEnum _res = _dateFrame.DepositeChar(_bix);
                switch (_state)
                {
                case RecStateEnum.RSE_BeforeHeading:
                    if (_res == FrameStateMachine.DepCharacterTypeEnum.DCT_SOH)
                    {
                        _state = RecStateEnum.RSE_InsideFrame;
                    }
                    Assert.AreNotEqual(FrameStateMachine.DepCharacterTypeEnum.DCT_Reset_Answer, _res, "Wrong DepositeChar return value");
                    Assert.AreNotEqual(FrameStateMachine.DepCharacterTypeEnum.DCT_Last, _res, "Wrong DepositeChar return value");
                    break;

                case RecStateEnum.RSE_InsideFrame:
                    Assert.AreEqual(FrameStateMachine.DepCharacterTypeEnum.DCT_Ordinary, _res, "Wrong DepositeChar return value");
                    break;
                }
            }
            comparer(_dateFrame, _testValue);
        }
        private static string CheckExpectedLength(Medium_T _enumIdx, SBUSNet_message _dateFrame, ushort _expectedFrameLength)
        {
            string _msg = string.Format("The length of the response for {0} is not valid", _enumIdx);

            Assert.AreEqual(_expectedFrameLength, _dateFrame.userDataLength, _msg);
            return(_msg);
        }
 private static void CompareType <type>(SBUSNet_message _dateFrame, type _testValue)
 {
     for (int _bidx = 0; _bidx < C_RegistersCount; _bidx++)
     {
         type _rv = (type)_dateFrame.ReadValue(_bidx, typeof(type));
         Assert.AreEqual <type>(_testValue, _rv, String.Format("Value of type {1} in the frame at {0} are not expected", _bidx, typeof(type)));
     }
 }
예제 #4
0
            protected override FrameStateMachine CreateISesDBuffer()
            {
#if SBUSNET
                FrameStateMachine mes = new SBUSNet_message(this);
#else
                FrameStateMachine mes = new SBUSRS_message(this);
#endif
                return(mes);
            }
예제 #5
0
        public void RequestWrite_ToInputException()
        {
#if !DEBUG
            Assert.Inconclusive("This test requires DEBUG context");
#endif
            using (SBUSNet_message _frame = new SBUSNet_message(null))
            {
                Assert.IsNotNull(_frame, "Message is not created.");
                BlockAddress _tb = new BlockAddress((short)Medium_T.Input);
                _frame.Test_PrepareReqWriteValue(_tb, _tb.station);
            }
        }
예제 #6
0
        private static string CheckExpectedLength(Medium_T _enumIdx, SBUSNet_message _dateFrame, ushort _expectedFrameLength)
        {
            string _msg = string.Format("The length of the response for {0} is not valid", _enumIdx);

            Assert.AreEqual(_expectedFrameLength, _dateFrame.userDataLength, _msg);
            using (SBUSNet_message _newFrame = new SBUSNet_message(null))
            {
                _newFrame.PrepareFrameToBeSend(_dateFrame);
                Assert.AreEqual(_expectedFrameLength + c_CRCLength, _newFrame.userDataLength, _msg); //
            }
            return(_msg);
        }
        public void ResponseReadValue()
        {
#if !DEBUG
            Assert.Inconclusive("This test requires DEBUG context");
#endif
            foreach (Medium_T _enumIdx in Enum.GetValues(typeof(Medium_T)))
            {
                using (SBUSNet_message _frame = new SBUSNet_message(null))
                {
                    Assert.IsNotNull(_frame, "Message is not created.");
                    BlockAddress _tb = new BlockAddress((short)_enumIdx, c_station, C_startAddress, C_RegistersCount);
                    _frame.Test_PrepareRequest(_tb.station, _tb);
                    List <byte> _frameList = _frame.GetManagedBuffer().ToList();
                    Assert.AreEqual(m_TestTable[_enumIdx].Count, _frame.userDataLength, "The length of the request is not valid");
                    string _msg = String.Format("Frame must be equal to the template. Failed for {0} ", _enumIdx);
                    m_TestTable[_enumIdx][7] = _frameList[7]; // sequence numbers must be the same
                    CollectionAssert.AreEqual(m_TestTable[_enumIdx], _frameList, _msg);
                    using (SBUSNet_message _dateFrame = new SBUSNet_message(null))
                    {
                        _dateFrame.InitMsg(_frame);
                        ushort _expectedFrameLength = c_HeaderLength + c_ATLength;
                        switch (_enumIdx)
                        {
                        case Medium_T.Flag:
                        case Medium_T.Input:
                        case Medium_T.Output:
                            _expectedFrameLength += (C_RegistersCount - 1) / 8 + 1; //<header><AT>{fio-count}+
                            CheckExpectedLength(_enumIdx, _dateFrame, _expectedFrameLength);
                            TestContent <bool>(_dateFrame, false, CompareType <bool>);
                            break;

                        case Medium_T.Register:
                        case Medium_T.Timer:
                        case Medium_T.Counter:
                            _expectedFrameLength += C_RegistersCount * 4;
                            CheckExpectedLength(_enumIdx, _dateFrame, _expectedFrameLength);
                            TestContent <int>(_dateFrame, 123, CompareType <int>);
                            break;

                        case Medium_T.Text:
                            _expectedFrameLength += C_RegistersCount;
                            CheckExpectedLength(_enumIdx, _dateFrame, _expectedFrameLength);
                            TestContent <string>(_dateFrame, "1234567890123".Substring(0, _tb.length), CompareString);
                            break;

                        default:
                            Assert.Fail("Application error: unknown requested data type");
                            break;
                        }
                    }
                }
            }
        }
예제 #8
0
        public void RequestWrite_ReadValueTest()
        {
#if !DEBUG
            Assert.Inconclusive("This test requires DEBUG context");
#endif
            using (SBUSNet_message _frame = new SBUSNet_message(null))
            {
                Assert.IsNotNull(_frame, "Message is not created.");
                BlockAddress _tb = new BlockAddress((short)Medium_T.Text);
                _frame.Test_PrepareReqWriteValue(_tb, _tb.station);
                Assert.AreEqual(29, _frame.userDataLength, "The length of the request is not valid");
                object _retValue = _frame.ReadValue(0, typeof(string));
            }
        }
예제 #9
0
        public void ResponseWriteValue()
        {
#if !DEBUG
            Assert.Inconclusive("This test requires DEBUG context");
#endif
            using (SBUSNet_message _frame = new SBUSNet_message(null))
            {
                Assert.IsNotNull(_frame, "Message is not created.");
                BlockAddress _tb = new BlockAddress((short)Medium_T.Text);
                _frame.Test_PrepareRequest(_tb.station, _tb);
                Assert.AreEqual(16, _frame.userDataLength, "The length of the request is not valid");
                using (SBUSNet_message _dateFrame = new SBUSNet_message(null))
                {
                    _dateFrame.InitMsg(_frame);
                    _dateFrame.WriteValue("sassasasa", 0);
                }
            }
        }
예제 #10
0
        public void RequestWrite_RequestContentTest()
        {
#if !DEBUG
            Assert.Inconclusive("This test requires DEBUG context");
#endif
            const int    c_station        = 231;
            const ushort c_startAddress   = 1;
            const byte   c_RegistersCount = 1;
            const byte   c_HeaderLength   = 8;
            const byte   c_ATLength       = 1;
            foreach (Medium_T _enumIdx in Enum.GetValues(typeof(Medium_T)))
            {
                if (_enumIdx == Medium_T.Input)
                {
                    continue;
                }
                using (SBUSNet_message _frame = new SBUSNet_message(null))
                {
                    Assert.IsNotNull(_frame, "Message is not created.");
                    BlockAddress _tb = new BlockAddress((short)_enumIdx, c_station, c_startAddress, c_RegistersCount);
                    _frame.Test_PrepareReqWriteValue(_tb, _tb.station);
                    ushort           _expectedFrameLength = c_HeaderLength + c_ATLength + 1 + 1; //<head><attribute><station><cmd>
                    byte[]           _frameBuff           = null;
                    RequestSimulator _sim = null;
                    switch (_enumIdx)
                    {
                    case Medium_T.Flag:
                    case Medium_T.Input:
                    case Medium_T.Output:
                        _expectedFrameLength += 1 + 2 + 1 + c_RegistersCount / 8 + 1; //<w-count> <address-IOF> <fio-count> {<fio-byte>}+
                        bool _testBool = true;
                        for (int _bx = 0; _bx < c_RegistersCount; _bx++)
                        {
                            _frame.WriteValue(_testBool, _bx);
                        }
                        CheckExpectedLength(_enumIdx, _frame, _expectedFrameLength);
                        _frameBuff = _frame.GetManagedBuffer();
                        _sim       = new RequestSimulator(c_RegistersCount, _testBool, _expectedFrameLength, c_station, _enumIdx, c_startAddress);
                        _sim[7]    = _frameBuff[7];
                        byte _mask = 0xff >> 8 - c_RegistersCount % 8;
                        _sim[_expectedFrameLength - 1]       &= _mask;
                        _frameBuff[_expectedFrameLength - 1] &= _mask;
                        CollectionAssert.AreEqual(_sim, _frameBuff, "Frame and its template must be equal");
                        break;

                    case Medium_T.Register:
                    case Medium_T.Timer:
                    case Medium_T.Counter:
                        _expectedFrameLength += 1 + 2 + c_RegistersCount * 4; //<w-count> <address-RTC> {<4-byte>}+
                        CheckExpectedLength(_enumIdx, _frame, _expectedFrameLength);
                        int[] _testValuesArray = new int[] { int.MaxValue, int.MinValue, 0, -123456, 7654321 };
                        foreach (int _itv in _testValuesArray)
                        {
                            for (int _iix = 0; _iix < c_RegistersCount; _iix++)
                            {
                                _frame.WriteValue(_itv, _iix);
                            }
                            _frameBuff = _frame.GetManagedBuffer();
                            _sim       = new RequestSimulator(c_RegistersCount, _itv, _expectedFrameLength, c_station, _enumIdx, c_startAddress);
                            _sim[7]    = _frameBuff[7];
                            CollectionAssert.AreEqual(_sim, _frameBuff, "Frame and its template must be equal");
                        }
                        break;

                    case Medium_T.Text:
                        _expectedFrameLength += 1 + 1 + 2 + 1 + c_RegistersCount; //<w-count> <text-number> <char-position> {<ascii-char>}+
                        CheckExpectedLength(_enumIdx, _frame, _expectedFrameLength);
                        string[] _testString = new string[] { "0123456789012345678901", "0123456789012", "012345678", null, String.Empty };
                        foreach (string _ts in _testString)
                        {
                            _frame.WriteValue(_ts, 0);
                            _frameBuff = _frame.GetManagedBuffer();
                            _sim       = new RequestSimulator(c_RegistersCount, _ts, _expectedFrameLength, c_station, _enumIdx, c_startAddress);
                            _sim[7]    = _frameBuff[7];
                            CollectionAssert.AreEqual(_sim, _frameBuff, "Frame and its template must be equal");
                        }
                        break;

                    default:
                        Assert.Fail("Application error: unknown requested data type");
                        break;
                    }
                }
            }
        }
        private static void CompareString(SBUSNet_message _dateFrame, string _testValue)
        {
            string _rv = (string)_dateFrame.ReadValue(0, typeof(string));

            Assert.AreEqual <string>(_testValue, _rv, "Value of type string in the frame at are not equal");
        }