Exemplo n.º 1
0
        public void ReadTest_Bad_ToShort()
        {
            byte[] bytes = new byte[] {
                // #bundle
                35, 98, 117, 110, 100, 108, 101, 0,

                // Time-tag
                197, 146, 134, 227, 3, 18, 110, 152,

                // length
                0, 0, 0, 24,                 // 32,

                // message body
                47, 116, 101, 115, 116, 0, 0, 0,
                44, 105, 91, 105, 105, 105, 93, 0,

                26, 42, 58, 74, 26, 42, 58, 74,
                90, 106, 122, 138, 154, 170, 186, 202
            };

            int       index = 0;
            int       count = bytes.Length;
            OscBundle actual;

            actual = OscBundle.Read(bytes, index, count);

            Assert.AreEqual(actual.Error, OscPacketError.InvalidBundleMessageLength);
        }
Exemplo n.º 2
0
        public void ReadOffsetTest()
        {
            Random random = new Random();

            for (int i = 0; i < 1000; i++)
            {
                OscTimeTag timestamp = new OscTimeTag(14236589681638796952);

                List <OscPacket> messages = new List <OscPacket>();

                for (int j = 0; j < 10; j++)
                {
                    messages.Add(new OscMessage("/" + j, (float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble()));
                }

                OscBundle expected = new OscBundle(timestamp, messages.ToArray());

                int index      = random.Next(1, 32);
                int endPadding = random.Next(0, 32);
                int count      = expected.SizeInBytes;

                byte[] bytes = new byte[count + index + endPadding];

                random.NextBytes(bytes);

                expected.ToByteArray().CopyTo(bytes, index);

                OscBundle actual;

                actual = OscBundle.Read(bytes, index, count);

                UnitTestHelper.AreEqual(expected, actual);
            }
        }
Exemplo n.º 3
0
        public void OscBundleManyMessagesTest_2()
        {
            OscBundle target   = OscBundle.Parse("#bundle, 0, { /ping }, { /moop }, { /ping }, { /ping }, { /ping }");
            OscBundle expected = new OscBundle(new OscTimeTag(0),
                                               new OscMessage("/ping"), new OscMessage("/moop"), new OscMessage("/ping"), new OscMessage("/ping"), new OscMessage("/ping"));

            byte[] targetBytes = target.ToByteArray();

            OscBundle actual = OscBundle.Read(targetBytes, targetBytes.Length);

            UnitTestHelper.AreEqual(actual, expected);
        }
Exemplo n.º 4
0
        public void Nested_ReadTest()
        {
            OscBundle expected = UnitTestHelper.DoubleNestedBundle();

            byte[] bytes = UnitTestHelper.DoubleNestedBundleBody;

            int       count = bytes.Length;
            OscBundle actual;

            actual = OscBundle.Read(bytes, count);

            UnitTestHelper.AreEqual(expected, actual);
        }
        public void ReadTest()
        {
            OscTimeTag timestamp = new OscTimeTag(14236589681638796952);
            OscMessage[] messages = new OscMessage[] { UnitTestHelper.Message_Array_Ints(), UnitTestHelper.Message_Array_Ints() };
            OscBundle expected = new OscBundle(timestamp, messages);

            byte[] bytes = expected.ToByteArray();
            int index = 0;
            int count = bytes.Length;
            OscBundle actual;
            actual = OscBundle.Read(bytes, index, count);
            UnitTestHelper.AreEqual(expected, actual);

            Assert.IsTrue(actual.Equals(expected));
        }
Exemplo n.º 6
0
        public void ReadTest_Bad_ToShort()
        {
            try
            {
                byte[] bytes =
                {
                    // #bundle
                    35,   98, 117, 110, 100, 108, 101,   0,

                    // Time-tag
                    197, 146, 134, 227,   3,  18, 110, 152,

                    // length
                    0,     0,   0,  24, // 32,

                    // message body
                    47,  116, 101, 115, 116,   0,   0,   0,
                    44,  105,  91, 105, 105, 105,  93,   0,

                    26,   42,  58,  74,  26,  42,  58,  74,
                    90,  106, 122, 138, 154, 170, 186, 202
                };

                int       index = 0;
                int       count = bytes.Length;
                OscBundle actual;
                actual = OscBundle.Read(bytes, index, count);

                Assert.True(false, "Exception not thrown");
            }
            catch (OscException ex)
            {
                Assert.Equal(ex.OscError, OscError.ErrorParsingInt32);
            }
            catch (Exception ex)
            {
                Assert.True(false, ex.Message);
            }
        }