示例#1
0
        public void TestValueOption(uint value, int length, byte[] expected)
        {
            var optionToBytes = new CoapOption(0, type: OptionType.UInt, maxLength: 4);

            optionToBytes.ValueUInt = value;
            Assert.AreEqual(length, optionToBytes.Length);
            Assert.AreEqual(expected, optionToBytes.GetBytes());

            var optionFromBytes = new CoapOption(0, type: OptionType.UInt, maxLength: 4);

            optionFromBytes.FromBytes(expected);
            Assert.AreEqual(length, optionFromBytes.Length);
            Assert.AreEqual(value, optionFromBytes.ValueUInt);
        }
示例#2
0
        public void TestOpaqueOption(byte[] data, int length)
        {
            var option = new CoapOption(0, type: OptionType.Opaque, maxLength: 256);

            option.ValueOpaque = new byte[] { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xF0 };
            Assert.AreEqual(8, option.Length);
            Assert.AreEqual(new byte[] { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xF0 }, option.ValueOpaque);
            Assert.AreEqual(new byte[] { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xF0 }, option.GetBytes());
        }
示例#3
0
        public void TestOpaqueOption()
        {
            var option = new CoapOption(0, type: OptionType.Opaque);

            option.ValueOpaque = new byte[] { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xF0 };
            Assert.AreEqual(8, option.Length);
            Assert.AreEqual(new byte[] { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xF0 }, option.ValueOpaque);
            Assert.AreEqual(new byte[] { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xF0 }, option.GetBytes());

            option.FromBytes(new byte[] { 0xAA, 0x55, 0x11 });
            Assert.AreEqual(3, option.Length);
            Assert.AreEqual(new byte[] { 0xAA, 0x55, 0x11 }, option.ValueOpaque);
        }