Exemplo n.º 1
0
            public static byte[] ToBytes(short val)
            {
                UnionShort bt = new UnionShort();

                bt.value = val;
                return(bt.bytes);
            }
Exemplo n.º 2
0
            public static short ToValue(byte[] table, int index)
            {
                UnionShort bt = new UnionShort();

                bt.SetBytes(table, index);
                return(bt.value);
            }
Exemplo n.º 3
0
            // Ex string : size = sizeof(short) + sizeof(char) * num
            public static byte[] ToBytes(string val)
            {
                short byteSize = (short)(val.Length * sizeof(char));

                byte[] bt  = new byte[byteSize + sizeof(short)];
                int    idx = 0;

                // Set ByteSize field
                UnionShort uniSize = new UnionShort();

                uniSize.value = byteSize;
                bt[idx++]     = uniSize.b0;
                bt[idx++]     = uniSize.b1;

                // Set String field
                UnionChar uniCh = new UnionChar();

                foreach (char ch in val.ToCharArray())
                {
                    uniCh.value = ch;
                    foreach (byte b in uniCh.bytes)
                    {
                        bt[idx++] = b;
                    }
                }

                return(bt);
            }
Exemplo n.º 4
0
        public void LoadBytesTest()
        {
            UnionShort target = new UnionShort();

            target.LoadBytes <byte>(0x01, 0x23);
            short      expectedint = (BitConverter.IsLittleEndian) ? (short)0x2301 : (short)0x0123;
            UnionShort expected    = new UnionShort(expectedint);

            Assert.AreEqual(expected, target);
        }
Exemplo n.º 5
0
        public void ToUInt16ArrayTest()
        {
            UnionShort target = new UnionShort(); // TODO: 初始化为适当的值

            ushort[] expected = null;             // TODO: 初始化为适当的值
            ushort[] actual;
            actual = target.ToUInt16Array();
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("验证此测试方法的正确性。");
        }
Exemplo n.º 6
0
        public void ToStringTest()
        {
            UnionShort target   = new UnionShort();     // TODO: 初始化为适当的值
            string     expected = string.Empty;         // TODO: 初始化为适当的值
            string     actual;

            actual = target.ToString();
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("验证此测试方法的正确性。");
        }
Exemplo n.º 7
0
        public void LoadBytesAtTest()
        {
            UnionShort target = new UnionShort();

            target.LoadBytesAt <byte>(0, 1, 2, 0x01);
            short      expectedint = (BitConverter.IsLittleEndian) ? (short)0x0100 : (short)0x0001;
            UnionShort expected    = new UnionShort(expectedint);

            Assert.AreEqual(expected, target);
        }
Exemplo n.º 8
0
        public void EqualsTest()
        {
            UnionShort target = new UnionShort();

            target.B0 = 0x01;
            target.B1 = 0x23;
            short      expectedint = (BitConverter.IsLittleEndian) ? (short)0x2301 : (short)0x0123;
            UnionShort expected    = new UnionShort(expectedint);

            Assert.AreEqual(false, target.Equals(null));
            Assert.AreEqual(true, target.Equals(expected));
            Assert.AreEqual(expected, target);
        }
Exemplo n.º 9
0
        /// <summary>
        ///SaveBytes 的测试
        ///</summary>
        public void SaveBytesTestHelper <T>()
            where T : struct
        {
            UnionShort target = new UnionShort(); // TODO: 初始化为适当的值

            T[] dst      = null;                  // TODO: 初始化为适当的值
            int expected = 0;                     // TODO: 初始化为适当的值
            int actual;

            actual = target.SaveBytes <T>(dst);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("验证此测试方法的正确性。");
        }
Exemplo n.º 10
0
 public static byte[] ToBytes(short val)
 {
     return(UnionShort.ToBytes(val));
 }
Exemplo n.º 11
0
 public static int ToValue(out short ret, byte[] bytes, int index)
 {
     ret = UnionShort.ToValue(bytes, index);
     return(UnionShort.Size);
 }