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); } }
public void Nested_ToArrayTest() { OscBundle target = UnitTestHelper.DoubleNestedBundle(); byte[] expected = UnitTestHelper.DoubleNestedBundleBody; byte[] actual; actual = target.ToByteArray(); Assert.AreEqual(expected.Length, actual.Length); UnitTestHelper.AreEqual(expected, actual); }
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); }
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)); }
public void OscBundleManyMessagesTest_1() { OscBundle expected = new OscBundle(new OscTimeTag(0), new OscMessage("/ping"), new OscMessage("/moop"), new OscMessage("/ping"), new OscMessage("/ping"), new OscMessage("/ping")); byte[] bytes = expected.ToByteArray(); OscBundleRaw actual = new OscBundleRaw(new ArraySegment <byte>(bytes, 0, bytes.Length)); Assert.Equal(actual.Count, expected.Count); for (int i = 0; i < actual.Count; i++) { OscMessageRaw raw = actual[i]; OscMessage expectedMessage = expected[i] as OscMessage; Assert.Equal(raw.Address, expectedMessage.Address); } }