예제 #1
0
        public void BufferInt16IntoByteArrayTest()
        {
            Int16 testVal = 0x3456;

            byte[] testBuff = new byte[10];
            for (int i = 0; i < testBuff.Length;)
            {
                i = SerializeUtilities.BufferInt16InToByteArray(testVal,
                                                                testBuff, i, Endianness.big_endian);
            }

            for (int i = 0; i < testBuff.Length;)
            {
                Assert.AreEqual((byte)((testVal >> 8) & 0xFF), testBuff[i++]);
                Assert.AreEqual((byte)(testVal & 0xFF), testBuff[i++]);
            }

            for (int i = 0; i < testBuff.Length;)
            {
                i = SerializeUtilities.BufferInt16InToByteArray(testVal,
                                                                testBuff, i, Endianness.little_endian);
            }

            for (int i = 0; i < testBuff.Length;)
            {
                Assert.AreEqual((byte)(testVal & 0xFF), testBuff[i++]);
                Assert.AreEqual((byte)((testVal >> 8) & 0xFF), testBuff[i++]);
            }
        }
예제 #2
0
        public void BufferInt16IntoByteArrayBufferOverrunTest()
        {
            Int16 testVal = 0x1234;

            byte[] testBuff = new byte[2];
            int    i        = 0;

            i = SerializeUtilities.BufferInt16InToByteArray(testVal,
                                                            testBuff, i, Endianness.big_endian);
            i = SerializeUtilities.BufferInt16InToByteArray(testVal,
                                                            testBuff, i, Endianness.big_endian);
            i = SerializeUtilities.BufferInt16InToByteArray(testVal,
                                                            testBuff, i, Endianness.big_endian);
            Assert.AreEqual(2, i);

            i = 0;
            i = SerializeUtilities.BufferInt16InToByteArray(testVal,
                                                            testBuff, i, Endianness.little_endian);
            i = SerializeUtilities.BufferInt16InToByteArray(testVal,
                                                            testBuff, i, Endianness.little_endian);
            i = SerializeUtilities.BufferInt16InToByteArray(testVal,
                                                            testBuff, i, Endianness.little_endian);
            Assert.AreEqual(2, i);
        }