public void TestGetListener() { // Create a new Topic with a listener TestStructTypeSupport support = new TestStructTypeSupport(); string typeName = support.GetTypeName(); ReturnCode result = support.RegisterType(_participant, typeName); Assert.AreEqual(ReturnCode.Ok, result); MyTopicListener listener = new MyTopicListener(); Topic topic = _participant.CreateTopic(nameof(TestGetQos), typeName, null, listener); Assert.IsNotNull(topic); Assert.AreEqual(nameof(TestGetQos), topic.Name); Assert.AreEqual(typeName, topic.TypeName); Assert.AreEqual(_participant, topic.Participant); #pragma warning disable CS0618 // Type or member is obsolete // Call to GetListener and check the listener returned MyTopicListener received = (MyTopicListener)topic.GetListener(); #pragma warning restore CS0618 // Type or member is obsolete Assert.IsNotNull(received); Assert.AreEqual(listener, received); }
public void TestInitialize() { _participant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.RTPS_DOMAIN); Assert.IsNotNull(_participant); _participant.BindRtpsUdpTransportConfig(); TestStructTypeSupport support = new TestStructTypeSupport(); string typeName = support.GetTypeName(); ReturnCode result = support.RegisterType(_participant, typeName); Assert.AreEqual(ReturnCode.Ok, result); _listener = new MyTopicListener(); _topic = _participant.CreateTopic(TestContext.TestName, typeName, null, _listener); Assert.IsNotNull(_topic); Assert.IsNotNull(_topic.Listener); Assert.AreEqual(TestContext.TestName, _topic.Name); Assert.AreEqual(typeName, _topic.TypeName); PublisherQos pQos = new PublisherQos(); pQos.EntityFactory.AutoenableCreatedEntities = false; pQos.Presentation.OrderedAccess = true; pQos.Presentation.CoherentAccess = true; pQos.Presentation.AccessScope = PresentationQosPolicyAccessScopeKind.InstancePresentationQos; _publisher = _participant.CreatePublisher(pQos); Assert.IsNotNull(_publisher); _writer = _publisher.CreateDataWriter(_topic); Assert.IsNotNull(_writer); }
public void TestSetListener() { // Create a new Topic without listener TestStructTypeSupport support = new TestStructTypeSupport(); string typeName = support.GetTypeName(); ReturnCode result = support.RegisterType(_participant, typeName); Assert.AreEqual(ReturnCode.Ok, result); Topic topic = _participant.CreateTopic(nameof(TestSetListener), typeName); Assert.IsNotNull(topic); Assert.AreEqual(nameof(TestSetListener), topic.Name); Assert.AreEqual(typeName, topic.TypeName); Assert.AreEqual(_participant, topic.Participant); MyTopicListener listener = (MyTopicListener)topic.GetListener(); Assert.IsNull(listener); // Create a listener, set it and check that is correctly setted listener = new MyTopicListener(); result = topic.SetListener(listener); Assert.AreEqual(ReturnCode.Ok, result); MyTopicListener received = (MyTopicListener)topic.GetListener(); Assert.IsNotNull(received); Assert.AreEqual(listener, received); // Remove the listener calling SetListener with null and check it result = topic.SetListener(null, StatusMask.NoStatusMask); Assert.AreEqual(ReturnCode.Ok, result); received = (MyTopicListener)topic.GetListener(); Assert.IsNull(received); }