예제 #1
0
        public void TestTake()
        {
            List <SubscriptionBuiltinTopicData> data = new List <SubscriptionBuiltinTopicData>();
            List <SampleInfo> infos = new List <SampleInfo>();
            ReturnCode        ret   = _dr.Take(data, infos);

            Assert.AreEqual(ReturnCode.NoData, ret);
            Assert.AreEqual(0, data.Count);
            Assert.AreEqual(0, infos.Count);

            DomainParticipant otherParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.RTPS_DOMAIN);

            Assert.IsNotNull(otherParticipant);
            otherParticipant.BindRtpsUdpTransportConfig();

            TestStructTypeSupport support = new TestStructTypeSupport();
            string     typeName           = support.GetTypeName();
            ReturnCode result             = support.RegisterType(otherParticipant, typeName);

            Assert.AreEqual(ReturnCode.Ok, result);

            var topic = otherParticipant.CreateTopic(TestContext.TestName, typeName);

            Assert.IsNotNull(topic);

            var subscriber = otherParticipant.CreateSubscriber();

            Assert.IsNotNull(subscriber);

            DataReaderQos drQos      = TestHelper.CreateNonDefaultDataReaderQos();
            DataReader    dataReader = subscriber.CreateDataReader(topic, drQos);

            Assert.IsNotNull(dataReader);

            Thread.Sleep(500);

            ret = _dr.Take(data, infos);
            Assert.AreEqual(ReturnCode.Ok, ret);
            Assert.AreEqual(1, data.Count);
            Assert.AreEqual(1, infos.Count);
            TestHelper.TestNonDefaultSubscriptionData(data.First());

            ret = otherParticipant.DeleteContainedEntities();
            Assert.AreEqual(ReturnCode.Ok, ret);

            ret = AssemblyInitializer.Factory.DeleteParticipant(otherParticipant);
            Assert.AreEqual(ReturnCode.Ok, ret);
        }
예제 #2
0
        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);

            _topic = _participant.CreateTopic(TestContext.TestName, typeName);
            Assert.IsNotNull(_topic);
            Assert.IsNull(_topic.GetListener());
            Assert.AreEqual(TestContext.TestName, _topic.Name);
            Assert.AreEqual(typeName, _topic.TypeName);

            SubscriberQos sQos = new SubscriberQos();

            sQos.EntityFactory.AutoenableCreatedEntities = false;
            sQos.Presentation.OrderedAccess  = true;
            sQos.Presentation.CoherentAccess = true;
            sQos.Presentation.AccessScope    = PresentationQosPolicyAccessScopeKind.InstancePresentationQos;
            _subscriber = _participant.CreateSubscriber(sQos);
            Assert.IsNotNull(_subscriber);

            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);

            _listener = new MyDataWriterListener();
            _writer   = _publisher.CreateDataWriter(_topic, _listener);
            Assert.IsNotNull(_writer);
            _dataWriter = new TestStructDataWriter(_writer);

            DataReaderQos qos = new DataReaderQos();

            qos.Reliability.Kind = ReliabilityQosPolicyKind.ReliableReliabilityQos;
            _reader = _subscriber.CreateDataReader(_topic, qos);
            Assert.IsNotNull(_reader);
        }
예제 #3
0
        public void TestLookupInstance()
        {
            SubscriptionBuiltinTopicData data = default;
            SampleInfo info = new SampleInfo();

            DomainParticipant otherParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.RTPS_DOMAIN);

            Assert.IsNotNull(otherParticipant);
            otherParticipant.BindRtpsUdpTransportConfig();

            TestStructTypeSupport support = new TestStructTypeSupport();
            string     typeName           = support.GetTypeName();
            ReturnCode result             = support.RegisterType(otherParticipant, typeName);

            Assert.AreEqual(ReturnCode.Ok, result);

            var topic = otherParticipant.CreateTopic(TestContext.TestName, typeName);

            Assert.IsNotNull(topic);

            var subscriber = otherParticipant.CreateSubscriber();

            Assert.IsNotNull(subscriber);

            DataReaderQos drQos      = TestHelper.CreateNonDefaultDataReaderQos();
            DataReader    dataReader = subscriber.CreateDataReader(topic, drQos);

            Assert.IsNotNull(dataReader);

            Thread.Sleep(500);

            ReturnCode ret = _dr.ReadNextSample(ref data, info);

            Assert.AreEqual(ReturnCode.Ok, ret);
            TestHelper.TestNonDefaultSubscriptionData(data);

            // Lookup for an existing instance
            var handle = _dr.LookupInstance(data);

            Assert.AreNotEqual(InstanceHandle.HandleNil, handle);

            ret = otherParticipant.DeleteContainedEntities();
            Assert.AreEqual(ReturnCode.Ok, ret);

            ret = AssemblyInitializer.Factory.DeleteParticipant(otherParticipant);
            Assert.AreEqual(ReturnCode.Ok, ret);
        }
        public void TestTakeNextSample()
        {
            PublicationBuiltinTopicData data = default;
            SampleInfo infos = new SampleInfo();
            ReturnCode ret   = _dr.TakeNextSample(ref data, infos);

            Assert.AreEqual(ReturnCode.NoData, ret);

            DomainParticipant otherParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.RTPS_DOMAIN);

            Assert.IsNotNull(otherParticipant);
            otherParticipant.BindRtpsUdpTransportConfig();

            TestStructTypeSupport support = new TestStructTypeSupport();
            string     typeName           = support.GetTypeName();
            ReturnCode result             = support.RegisterType(otherParticipant, typeName);

            Assert.AreEqual(ReturnCode.Ok, result);

            var topic = otherParticipant.CreateTopic(TestContext.TestName, typeName);

            Assert.IsNotNull(topic);

            var publisher = otherParticipant.CreatePublisher();

            Assert.IsNotNull(publisher);

            DataWriterQos dwQos = TestHelper.CreateNonDefaultDataWriterQos();

            dwQos.Ownership.Kind = OwnershipQosPolicyKind.SharedOwnershipQos;
            DataWriter dataWriter = publisher.CreateDataWriter(topic, dwQos);

            Assert.IsNotNull(dataWriter);

            Thread.Sleep(500);

            ret = _dr.TakeNextSample(ref data, infos);
            Assert.AreEqual(ReturnCode.Ok, ret);
            TestHelper.TestNonDefaultPublicationData(data);

            ret = otherParticipant.DeleteContainedEntities();
            Assert.AreEqual(ReturnCode.Ok, ret);

            ret = AssemblyInitializer.Factory.DeleteParticipant(otherParticipant);
            Assert.AreEqual(ReturnCode.Ok, ret);
        }
예제 #5
0
        public void TestTakeInstance()
        {
            List <ParticipantBuiltinTopicData> data = new List <ParticipantBuiltinTopicData>();
            List <SampleInfo> infos = new List <SampleInfo>();
            ReturnCode        ret   = _dr.Read(data, infos);

            Assert.AreEqual(ReturnCode.NoData, ret);
            Assert.AreEqual(0, data.Count);
            Assert.AreEqual(0, infos.Count);

            DomainParticipantQos qos = new DomainParticipantQos();

            qos.UserData.Value = new byte[] { 0x42 };
            DomainParticipant otherParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.RTPS_DOMAIN, qos);

            Assert.IsNotNull(otherParticipant);
            otherParticipant.BindRtpsUdpTransportConfig();

            Thread.Sleep(500);

            ret = _dr.ReadNextInstance(data, infos, InstanceHandle.HandleNil);
            Assert.AreEqual(ReturnCode.Ok, ret);
            Assert.AreEqual(1, data.Count);
            Assert.AreEqual(1, infos.Count);
            Assert.AreEqual(1, data.First().UserData.Value.Count());
            Assert.AreEqual(0x42, data.First().UserData.Value.First());

            var handle = infos.First().InstanceHandle;

            data  = new List <ParticipantBuiltinTopicData>();
            infos = new List <SampleInfo>();

            ret = _dr.TakeInstance(data, infos, handle);
            Assert.AreEqual(ReturnCode.Ok, ret);
            Assert.AreEqual(1, data.Count);
            Assert.AreEqual(1, infos.Count);
            Assert.AreEqual(1, data.First().UserData.Value.Count());
            Assert.AreEqual(0x42, data.First().UserData.Value.First());

            ret = otherParticipant.DeleteContainedEntities();
            Assert.AreEqual(ReturnCode.Ok, ret);

            ret = AssemblyInitializer.Factory.DeleteParticipant(otherParticipant);
            Assert.AreEqual(ReturnCode.Ok, ret);
        }
예제 #6
0
        public void TestGetKeyValue()
        {
            // Call GetKeyValue with HandleNil
            ParticipantBuiltinTopicData data = default;
            SampleInfo info = new SampleInfo();
            ReturnCode ret  = _dr.GetKeyValue(ref data, InstanceHandle.HandleNil);

            Assert.AreEqual(ReturnCode.BadParameter, ret);

            DomainParticipantQos qos = new DomainParticipantQos();

            qos.UserData.Value = new byte[] { 0x42 };
            DomainParticipant otherParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.RTPS_DOMAIN, qos);

            Assert.IsNotNull(otherParticipant);
            otherParticipant.BindRtpsUdpTransportConfig();

            Assert.IsTrue(_participant.WaitForParticipants(1, 20_000));
            Assert.IsTrue(otherParticipant.WaitForParticipants(1, 20_000));

            // Get the for an existing instance
            ret = _dr.ReadNextSample(ref data, info);
            Assert.AreEqual(ReturnCode.Ok, ret);
            Assert.AreEqual(1, data.UserData.Value.Count);
            Assert.AreEqual(0x42, data.UserData.Value.First());

            ParticipantBuiltinTopicData aux = default;

            ret = _dr.GetKeyValue(ref aux, info.InstanceHandle);
            Assert.AreEqual(ReturnCode.Ok, ret);
            for (int i = 0; i < 3; i++)
            {
                Assert.AreEqual(data.Key.Value[i], aux.Key.Value[i]);
            }

            ret = otherParticipant.DeleteContainedEntities();
            Assert.AreEqual(ReturnCode.Ok, ret);

            ret = AssemblyInitializer.Factory.DeleteParticipant(otherParticipant);
            Assert.AreEqual(ReturnCode.Ok, ret);
        }
예제 #7
0
        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);

            _topic = _participant.CreateTopic(TestContext.TestName, typeName);
            Assert.IsNotNull(_topic);
            Assert.IsNull(_topic.Listener);
            Assert.AreEqual(TestContext.TestName, _topic.Name);
            Assert.AreEqual(typeName, _topic.TypeName);

            _publisher = _participant.CreatePublisher();
            Assert.IsNotNull(_publisher);
        }
예제 #8
0
        public void TestDeleteParticipant()
        {
            DomainParticipant participant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.RTPS_DOMAIN);

            Assert.IsNotNull(participant);
            participant.BindRtpsUdpTransportConfig();

            Subscriber subscriber = participant.CreateSubscriber();

            Assert.IsNotNull(subscriber);

            ReturnCode result = AssemblyInitializer.Factory.DeleteParticipant(participant);

            Assert.AreEqual(ReturnCode.PreconditionNotMet, result);

            result = participant.DeleteContainedEntities();
            Assert.AreEqual(ReturnCode.Ok, result);

            result = AssemblyInitializer.Factory.DeleteParticipant(participant);
            Assert.AreEqual(ReturnCode.Ok, result);

            result = AssemblyInitializer.Factory.DeleteParticipant(null);
            Assert.AreEqual(ReturnCode.Ok, result);
        }
예제 #9
0
 public void TestInitialize()
 {
     _participant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.RTPS_DOMAIN);
     Assert.IsNotNull(_participant);
     _participant.BindRtpsUdpTransportConfig();
 }
예제 #10
0
        public void TestGetKeyValue()
        {
            ReturnCode        ret;
            DomainParticipant otherParticipant = null;
            Topic             topic            = null;

            try
            {
                // Call GetKeyValue with HandleNil
                TopicBuiltinTopicData data = default;
                SampleInfo            info = new SampleInfo();
                ret = _dr.GetKeyValue(ref data, InstanceHandle.HandleNil);
                Assert.AreEqual(ReturnCode.BadParameter, ret);

                otherParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.INFOREPO_DOMAIN);
                Assert.IsNotNull(otherParticipant);
                otherParticipant.BindRtpsUdpTransportConfig();

                TestStructTypeSupport support = new TestStructTypeSupport();
                string     typeName           = support.GetTypeName();
                ReturnCode result             = support.RegisterType(otherParticipant, typeName);
                Assert.AreEqual(ReturnCode.Ok, result);

                TopicQos qos = TestHelper.CreateNonDefaultTopicQos();
                topic = otherParticipant.CreateTopic(TestContext.TestName, typeName, qos);
                Assert.IsNotNull(topic);

                int count = 200;
                ret = ReturnCode.NoData;
                while (ret != ReturnCode.Ok && count > 0)
                {
                    Thread.Sleep(100);
                    // Get the for an existing instance
                    ret = _dr.ReadNextSample(ref data, info);
                    count--;
                }

                Assert.AreEqual(ReturnCode.Ok, ret);
                Assert.AreEqual(typeName, data.TypeName);
                Assert.IsNotNull(data.Key);
                TestHelper.TestNonDefaultTopicData(data);

                TopicBuiltinTopicData aux = default;
                ret = _dr.GetKeyValue(ref aux, info.InstanceHandle);
                Assert.AreEqual(ReturnCode.Ok, ret);
                for (int i = 0; i < 16; i++)
                {
                    Assert.AreEqual(data.Key.Value[i], aux.Key.Value[i]);
                }
            }
            finally
            {
                ret = otherParticipant.DeleteTopic(topic);
                Assert.AreEqual(ReturnCode.Ok, ret);
                ret = otherParticipant.DeleteContainedEntities();
                Assert.AreEqual(ReturnCode.Ok, ret);

                ret = AssemblyInitializer.Factory.DeleteParticipant(otherParticipant);
                Assert.AreEqual(ReturnCode.Ok, ret);
            }
        }
예제 #11
0
        public void TestTakeInstance()
        {
            ReturnCode        ret;
            DomainParticipant otherParticipant = null;
            Topic             topic            = null;

            try
            {
                List <TopicBuiltinTopicData> data  = new List <TopicBuiltinTopicData>();
                List <SampleInfo>            infos = new List <SampleInfo>();
                ret = _dr.Read(data, infos);
                Assert.AreEqual(ReturnCode.NoData, ret);
                Assert.AreEqual(0, data.Count);
                Assert.AreEqual(0, infos.Count);

                otherParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.INFOREPO_DOMAIN);
                Assert.IsNotNull(otherParticipant);
                otherParticipant.BindRtpsUdpTransportConfig();

                TestStructTypeSupport support = new TestStructTypeSupport();
                string     typeName           = support.GetTypeName();
                ReturnCode result             = support.RegisterType(otherParticipant, typeName);
                Assert.AreEqual(ReturnCode.Ok, result);

                TopicQos qos = TestHelper.CreateNonDefaultTopicQos();
                topic = otherParticipant.CreateTopic(TestContext.TestName, typeName, qos);
                Assert.IsNotNull(topic);

                int count = 200;
                ret = ReturnCode.NoData;
                while (ret != ReturnCode.Ok && count > 0)
                {
                    Thread.Sleep(100);
                    ret = _dr.ReadNextInstance(data, infos, InstanceHandle.HandleNil);
                    count--;
                }

                Assert.AreEqual(ReturnCode.Ok, ret);
                Assert.AreEqual(1, data.Count);
                Assert.AreEqual(1, infos.Count);
                Assert.AreEqual(typeName, data.First().TypeName);
                Assert.IsNotNull(data.First().Key);
                TestHelper.TestNonDefaultTopicData(data.First());

                var handle = infos.First().InstanceHandle;
                data  = new List <TopicBuiltinTopicData>();
                infos = new List <SampleInfo>();

                ret = _dr.TakeInstance(data, infos, handle);
                Assert.AreEqual(ReturnCode.Ok, ret);
                Assert.AreEqual(1, data.Count);
                Assert.AreEqual(1, infos.Count);
                Assert.AreEqual(typeName, data.First().TypeName);
                Assert.IsNotNull(data.First().Key);
                TestHelper.TestNonDefaultTopicData(data.First());
            }
            finally
            {
                ret = otherParticipant.DeleteTopic(topic);
                Assert.AreEqual(ReturnCode.Ok, ret);
                ret = otherParticipant.DeleteContainedEntities();
                Assert.AreEqual(ReturnCode.Ok, ret);

                ret = AssemblyInitializer.Factory.DeleteParticipant(otherParticipant);
                Assert.AreEqual(ReturnCode.Ok, ret);
            }
        }
예제 #12
0
        public void TestGetMatchedSubscriptionData()
        {
            // Initialize entities
            DataWriterQos dwQos = TestHelper.CreateNonDefaultDataWriterQos();

            dwQos.Reliability.Kind = ReliabilityQosPolicyKind.ReliableReliabilityQos;
            DataWriter writer = _publisher.CreateDataWriter(_topic, dwQos);

            Assert.IsNotNull(writer);

            // DCPSInfoRepo-based discovery generates Built-In Topic data once (inside the
            // info repo process) and therefore all known entities in the domain are
            // reflected in the Built-In Topics.  RTPS discovery, on the other hand, follows
            // the DDS specification and omits "local" entities from the Built-In Topics.
            // The definition of "local" means those entities belonging to the same Domain
            // Participant as the given Built-In Topic Subscriber.
            // https://github.com/objectcomputing/OpenDDS/blob/master/docs/design/RTPS

            // OPENDDS ISSUE: GetMatchedSubscriptions returns local entities but GetMatchedSubscriptionData doesn't
            // because is looking in the Built-in topic. If not found in the built-in, shouldn't try to look locally?
            // WORKAROUND: Create another particpant for the DataReader.
            DomainParticipant otherParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.RTPS_DOMAIN);

            Assert.IsNotNull(otherParticipant);
            otherParticipant.BindRtpsUdpTransportConfig();

            TestStructTypeSupport support = new TestStructTypeSupport();
            string     typeName           = support.GetTypeName();
            ReturnCode result             = support.RegisterType(otherParticipant, typeName);

            Assert.AreEqual(ReturnCode.Ok, result);

            Topic otherTopic = otherParticipant.CreateTopic(nameof(TestGetMatchedSubscriptionData), typeName);

            Assert.IsNotNull(otherTopic);

            Subscriber subscriber = otherParticipant.CreateSubscriber();

            Assert.IsNotNull(subscriber);

            DataReaderQos drQos  = TestHelper.CreateNonDefaultDataReaderQos();
            DataReader    reader = subscriber.CreateDataReader(otherTopic, drQos);

            Assert.IsNotNull(reader);

            // Wait for subscriptions
            bool found = writer.WaitForSubscriptions(1, 5000);

            Assert.IsTrue(found);

            // Get the matched subscriptions
            List <InstanceHandle> list = new List <InstanceHandle>();

            result = writer.GetMatchedSubscriptions(list);
            Assert.AreEqual(ReturnCode.Ok, result);
            Assert.AreEqual(1, list.Count);

            // Get the matched subscription data
            SubscriptionBuiltinTopicData data = default;

            result = writer.GetMatchedSubscriptionData(list.First(), ref data);
            Assert.AreEqual(ReturnCode.Ok, result);
            TestHelper.TestNonDefaultSubscriptionData(data);

            // Destroy the other participant
            result = otherParticipant.DeleteContainedEntities();
            Assert.AreEqual(ReturnCode.Ok, result);

            result = AssemblyInitializer.Factory.DeleteParticipant(otherParticipant);
            Assert.AreEqual(ReturnCode.Ok, result);
        }
        public void TestTakeInstance()
        {
            List <PublicationBuiltinTopicData> data = new List <PublicationBuiltinTopicData>();
            List <SampleInfo> infos = new List <SampleInfo>();
            ReturnCode        ret   = _dr.Read(data, infos);

            Assert.AreEqual(ReturnCode.NoData, ret);
            Assert.AreEqual(0, data.Count);
            Assert.AreEqual(0, infos.Count);

            DomainParticipant otherParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.RTPS_DOMAIN);

            Assert.IsNotNull(otherParticipant);
            otherParticipant.BindRtpsUdpTransportConfig();

            TestStructTypeSupport support = new TestStructTypeSupport();
            string     typeName           = support.GetTypeName();
            ReturnCode result             = support.RegisterType(otherParticipant, typeName);

            Assert.AreEqual(ReturnCode.Ok, result);

            var topic = otherParticipant.CreateTopic(TestContext.TestName, typeName);

            Assert.IsNotNull(topic);

            var publisher = otherParticipant.CreatePublisher();

            Assert.IsNotNull(publisher);

            DataWriterQos dwQos = TestHelper.CreateNonDefaultDataWriterQos();

            dwQos.Ownership.Kind = OwnershipQosPolicyKind.SharedOwnershipQos;
            DataWriter dataWriter = publisher.CreateDataWriter(topic, dwQos);

            Assert.IsNotNull(dataWriter);

            Thread.Sleep(500);

            ret = _dr.ReadNextInstance(data, infos, InstanceHandle.HandleNil);
            Assert.AreEqual(ReturnCode.Ok, ret);
            Assert.AreEqual(1, data.Count);
            Assert.AreEqual(1, infos.Count);
            TestHelper.TestNonDefaultPublicationData(data.First());

            var handle = infos.First().InstanceHandle;

            data  = new List <PublicationBuiltinTopicData>();
            infos = new List <SampleInfo>();

            ret = _dr.TakeInstance(data, infos, handle);
            Assert.AreEqual(ReturnCode.Ok, ret);
            Assert.AreEqual(1, data.Count);
            Assert.AreEqual(1, infos.Count);
            TestHelper.TestNonDefaultPublicationData(data.First());

            ret = otherParticipant.DeleteContainedEntities();
            Assert.AreEqual(ReturnCode.Ok, ret);

            ret = AssemblyInitializer.Factory.DeleteParticipant(otherParticipant);
            Assert.AreEqual(ReturnCode.Ok, ret);
        }
예제 #14
0
        public void TestBindConfig()
        {
            // Create a domain participant
            DomainParticipant participant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.RTPS_OTHER_DOMAIN);

            Assert.IsNotNull(participant);
            participant.BindRtpsUdpTransportConfig();

            // Create a transport config
            TransportConfig config = TransportRegistry.Instance.CreateConfig(nameof(TestBindConfig));

            Assert.IsNotNull(config);

            // Bind the participant using the name
            bool exception = false;

            try
            {
                TransportRegistry.Instance.BindConfig(nameof(TestBindConfig), participant);
            }
            catch
            {
                exception = true;
            }
            Assert.IsFalse(exception);

            // Bind the participant using the transport config
            exception = false;
            try
            {
                TransportRegistry.Instance.BindConfig(config, participant);
            }
            catch
            {
                exception = true;
            }
            Assert.IsFalse(exception);

            // Test parameters guards
            exception = false;
            try
            {
                TransportRegistry.Instance.BindConfig((string)null, participant);
            }
            catch (Exception ex)
            {
                exception = true;
                Assert.IsTrue(ex.GetType() == typeof(ArgumentNullException));
            }
            Assert.IsTrue(exception);

            exception = false;
            try
            {
                TransportRegistry.Instance.BindConfig(string.Empty, participant);
            }
            catch (Exception ex)
            {
                exception = true;
                Assert.IsTrue(ex.GetType() == typeof(ArgumentNullException));
            }
            Assert.IsTrue(exception);

            exception = false;
            try
            {
                TransportRegistry.Instance.BindConfig("  ", participant);
            }
            catch (Exception ex)
            {
                exception = true;
                Assert.IsTrue(ex.GetType() == typeof(ArgumentNullException));
            }
            Assert.IsTrue(exception);

            exception = false;
            try
            {
                TransportRegistry.Instance.BindConfig(nameof(TestBindConfig), null);
            }
            catch (Exception ex)
            {
                exception = true;
                Assert.IsTrue(ex.GetType() == typeof(ArgumentNullException));
            }
            Assert.IsTrue(exception);

            exception = false;
            try
            {
                TransportRegistry.Instance.BindConfig((TransportConfig)null, participant);
            }
            catch (Exception ex)
            {
                exception = true;
                Assert.IsTrue(ex.GetType() == typeof(ArgumentNullException));
            }
            Assert.IsTrue(exception);

            exception = false;
            try
            {
                TransportRegistry.Instance.BindConfig(config, null);
            }
            catch (Exception ex)
            {
                exception = true;
                Assert.IsTrue(ex.GetType() == typeof(ArgumentNullException));
            }
            Assert.IsTrue(exception);

            ReturnCode ret = AssemblyInitializer.Factory.DeleteParticipant(participant);

            Assert.AreEqual(ReturnCode.Ok, ret);
        }
예제 #15
0
        public void TestGetKeyValue()
        {
            // Call GetKeyValue with HandleNil
            PublicationBuiltinTopicData data = default;
            SampleInfo info = new SampleInfo();
            ReturnCode ret  = _dr.GetKeyValue(ref data, InstanceHandle.HandleNil);

            Assert.AreEqual(ReturnCode.BadParameter, ret);

            DomainParticipant otherParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.RTPS_DOMAIN);

            Assert.IsNotNull(otherParticipant);
            otherParticipant.BindRtpsUdpTransportConfig();

            Assert.IsTrue(_participant.WaitForParticipants(1, 20_000));

            TestStructTypeSupport support = new TestStructTypeSupport();
            string     typeName           = support.GetTypeName();
            ReturnCode result             = support.RegisterType(otherParticipant, typeName);

            Assert.AreEqual(ReturnCode.Ok, result);

            var topic = otherParticipant.CreateTopic(TestContext.TestName, typeName);

            Assert.IsNotNull(topic);

            var publisher = otherParticipant.CreatePublisher();

            Assert.IsNotNull(publisher);

            DataWriterQos dwQos = TestHelper.CreateNonDefaultDataWriterQos();

            dwQos.Ownership.Kind = OwnershipQosPolicyKind.SharedOwnershipQos;
            DataWriter dataWriter = publisher.CreateDataWriter(topic, dwQos);

            Assert.IsNotNull(dataWriter);

            int count = 200;

            ret = ReturnCode.NoData;
            while (ret != ReturnCode.Ok && count > 0)
            {
                Thread.Sleep(100);
                // Get an existing instance
                ret = _dr.ReadNextSample(ref data, info);
                count--;
            }
            Assert.AreEqual(ReturnCode.Ok, ret);
            TestHelper.TestNonDefaultPublicationData(data);

            PublicationBuiltinTopicData aux = default;

            ret = _dr.GetKeyValue(ref aux, info.InstanceHandle);
            Assert.AreEqual(ReturnCode.Ok, ret);
            for (int i = 0; i < 16; i++)
            {
                Assert.AreEqual(data.Key.Value[i], aux.Key.Value[i]);
            }

            ret = otherParticipant.DeleteContainedEntities();
            Assert.AreEqual(ReturnCode.Ok, ret);

            ret = AssemblyInitializer.Factory.DeleteParticipant(otherParticipant);
            Assert.AreEqual(ReturnCode.Ok, ret);
        }