示例#1
0
        public void FromBufferTest()
        {
            var target = new AccelParams();

            var expected = new AccelParams
                               {
                                   SensorNumber = 1,
                                   OffsetX = 20.0,
                                   OffsetY = -75.0,
                                   GravityX = -20.0,
                                   GravityY = 75.0
                               };

            var buffer = new DataBuffer(Endianness.LittleEndian);
            buffer.WriteUInt16(1);
            buffer.WriteDouble(20.0);
            buffer.WriteDouble(-75.0);
            buffer.WriteDouble(-20.0);
            buffer.WriteDouble(75.0);

            target.FromBuffer(buffer);

            var tt = new DataBuffer(Endianness.LittleEndian);
            target.ToBuffer(tt);

            Assert.AreEqual(expected.SensorNumber,target.SensorNumber);
            Assert.AreEqual(expected.OffsetX, target.OffsetX);
            Assert.AreEqual(expected.OffsetY, target.OffsetY);
            Assert.AreEqual(expected.GravityX, target.GravityX);
            Assert.AreEqual(expected.GravityY, target.GravityY);
        }
示例#2
0
        public void ReadUInt32Test_LittleEndian()
        {
            var endianess = Endianness.LittleEndian;
            DataBuffer target = new DataBuffer(endianess);

            UInt32 expected = 0xFFAABB22;

            var data = new byte[] { 0x22, 0xBB, 0xAA, 0xFF };
            target.WriteRawData(data);
            var actual = target.ReadUInt32();

            Assert.AreEqual(expected, actual);
        }
示例#3
0
        public void WriteDoubleTest_LittleEndian()
        {
            var endianess = Endianness.LittleEndian;
            DataBuffer target = new DataBuffer(endianess);

            double data = 365784e40;
            var expected = BitConverter.GetBytes(data);

            target.WriteDouble(data);
            var actual = target.RawData;

            CollectionAssert.AreEqual(expected, actual);
        }
示例#4
0
        public void ReadDoubleTest_LittleEndian()
        {
            var endianess = Endianness.LittleEndian;
            DataBuffer target = new DataBuffer(endianess);

            double expected = 365784e40;
            var expectedBytes = BitConverter.GetBytes(expected);
            target.WriteRawData(expectedBytes);

            var actual = target.ReadDouble();

            Assert.AreEqual(expected, actual);
        }
示例#5
0
        public void FromBufferTest()
        {
            var target = new AccelData(15.0, 75.0);

            var expected = new AccelData(20.0, -75.0);

            var buffer = new DataBuffer(Endianness.LittleEndian);
            buffer.WriteDouble(20.0);
            buffer.WriteDouble(-75.0);

            target.FromBuffer(buffer);

            Assert.AreEqual(expected.Ax, target.Ax);
            Assert.AreEqual(expected.Ay, target.Ay);
        }
示例#6
0
        public void ToBufferTest()
        {
            var target = new AccelParams
                             {
                                 SensorNumber = 1,
                                 OffsetX = 20.0,
                                 OffsetY = -75.0,
                                 GravityX = 20.0,
                                 GravityY = -75.0
                             };

            var expected = new byte[] { 1,0,0, 0, 0, 0, 0, 0, 52, 64, 0, 0, 0, 0, 0, 192, 82, 192, 0, 0, 0, 0, 0, 0, 52, 64, 0, 0, 0, 0, 0, 192, 82, 192 };

            var buffer = new DataBuffer(Endianness.LittleEndian);

            target.ToBuffer(buffer);

            CollectionAssert.AreEqual(expected, buffer.RawData);
        }
示例#7
0
        public void ToBufferTest()
        {
            var target = new AccelData(20.0, -75.0);

            var expected = new byte[] {0, 0, 0, 0, 0, 0,52,64,0,0,0,0,0,192,82,192};

            var buffer = new DataBuffer(Endianness.LittleEndian);

            target.ToBuffer(buffer);

            CollectionAssert.AreEqual(expected, buffer.RawData);
        }
示例#8
0
 public void ConstructorTest()
 {
     var endianess = Endianness.BigEndian;
     DataBuffer target = new DataBuffer(endianess);
     Assert.AreEqual(endianess,target.ByteOrder);
 }
示例#9
0
        public void WriteUInt32Test_LittleEndian()
        {
            var endianess = Endianness.LittleEndian;
            DataBuffer target = new DataBuffer(endianess);

            var expected = new byte[] { 0x22, 0xBB, 0xAA, 0xFF };
            target.WriteUInt32(0xFFAABB22);

            Assert.AreEqual(expected.Length, target.UnreadedData);
            CollectionAssert.AreEqual(expected, target.RawData);
        }
示例#10
0
        public void WriteRawDataTest()
        {
            var endianess = Endianness.BigEndian;
            DataBuffer target = new DataBuffer(endianess);

            var data = new byte[10];
            target.WriteRawData(data);

            Assert.AreEqual(data.Length, target.UnreadedData);
            CollectionAssert.AreEqual(data, target.RawData);
        }
示例#11
0
 public object Clone()
 {
     DataBuffer buffer = new DataBuffer(this.ByteOrder);
     buffer.WriteRawData(this.RawData);
     return buffer;
 }