Пример #1
0
        public void Decode_Composite_Test()
        {
            int i = -1;
            // Input
            byte[] input = new byte[14];

            input[++i] = 0x61;  // T
            input[++i] = 12;    // L
            input[++i] = 0x02;  // T (int)
            input[++i] = 1;     // L
            input[++i] = 0x13;    // V
            input[++i] = 0x62;  // T (constructed: PrimitivePurposeWrapper)
            input[++i] = 7;     // L
            input[++i] = 0x02;  // T (int)
            input[++i] = 1;    // L
            input[++i] = 17;   // V
            input[++i] = 0x02; // T (int)
            input[++i] = 2;    // L
            input[++i] = 0x1;  // V
            input[++i] = 0x0;  // V

            // Expected input
            Purpose purpose = new Purpose();
            PrimitivePurposeWrapper primPurp = new PrimitivePurposeWrapper();
            primPurp.A = 17;
            primPurp.B = 256;
            purpose.Value = primPurp;
            purpose.MethodID = 0x13;

            ITLVable result = TLVDec.Decode(input);
            Purpose convResult = result as Purpose;
            PrimitivePurposeWrapper embedded = convResult.Value as PrimitivePurposeWrapper;

            Assert.AreEqual(17, embedded.A);
            Assert.AreEqual(256, embedded.B);
            Assert.AreEqual(0x13, convResult.MethodID);
        }
Пример #2
0
        public void MinimalCompositeTest()
        {
            int i = -1;

            // Create input
            Purpose purpose = new Purpose();
            PrimitivePurposeWrapper primPurp = new PrimitivePurposeWrapper();
            primPurp.A = 17;
            primPurp.B = 256;
            purpose.Value = primPurp;
            purpose.MethodID = 13;

            // Exptected result
            byte[] exp = new byte[14];

            exp[++i] = 0x61;  // T
            exp[++i] = 12;    // L
            exp[++i] = 0x02;  // T (int)
            exp[++i] = 1;     // L
            exp[++i] = 13;    // V
            exp[++i] = 0x62;  // T (constructed: PrimitivePurposeWrapper)
            exp[++i] = 7;     // L
            exp[++i] = 0x02;  // T (int)
            exp[++i] = 1;    // L
            exp[++i] = 17;   // V
            exp[++i] = 0x02; // T (int)
            exp[++i] = 2;    // L
            exp[++i] = 0x1;  // V
            exp[++i] = 0x0;  // V

            byte[] result = TlvConv.Encode(purpose);

            Assert.IsNotNull(result);
            Assert.AreEqual(14, result.Length);

            for (i = 0; i < 14; i++)
            {
                Assert.AreEqual(exp[i], result[i]);
            }
        }