Exemplo n.º 1
0
        public void UserDataDomainsDisableTest01()
        {
            //PRECONDITIONS
            DomainParticipantFactory factory = DomainParticipantFactory.GetInstance(Bootstrap.CreateInstance());
            DomainParticipantImpl dp = factory.CreateParticipant() as DomainParticipantImpl;
            Assert.IsFalse(dp.IsEnabled);

            ModifiableDomainParticipantQos qos = dp.GetQos().Modify();

            ModifiableUserDataQosPolicy userData = new UserDataQosPolicyImpl(dp.GetBootstrap()).Modify();
            byte[] userValue = new byte[] { 0x0A };
            userData.SetValue(userValue, 0, userValue.Length);
            qos.SetUserData(userData);
            dp.SetQos(qos);

            Assert.IsNotNull(dp.GetQos());
            Assert.IsNotNull(dp.GetQos().GetUserData());

            byte[] userdataVal = new byte[userValue.Length];
            dp.GetQos().GetUserData().GetValue(userdataVal, 0);

            Assert.AreEqual(userValue.Length, userdataVal.Length);
            Assert.AreEqual(userValue[0], userdataVal[0]);

        }
Exemplo n.º 2
0
        public void UserDataDataReaderTest02()
        {
            //PRECONDITIONS
            DomainParticipantFactory factory = DomainParticipantFactory.GetInstance(Bootstrap.CreateInstance());
            DomainParticipantImpl dp = factory.CreateParticipant() as DomainParticipantImpl;
            Topic<Type> tp = dp.CreateTopic<Type>("Greetings Topic");
            Subscriber sub = dp.CreateSubscriber();
            DataReader<Type> dr = sub.CreateDataReader(tp);
            Assert.IsNotNull(dr);
            ModifiableDataReaderQos qos = dr.GetQos().Modify();

            ModifiableUserDataQosPolicy userData = new UserDataQosPolicyImpl(dr.GetBootstrap()).Modify();
            byte[] userValue = new byte[] { 0x0A };
            userData.SetValue(userValue, 0, userValue.Length);
            qos.SetUserData(userData);
            dr.SetQos(qos);

            Assert.IsNotNull(dr.GetQos());
            Assert.IsNotNull(dr.GetQos().GetUserData());

            byte[] userdataVal = new byte[userValue.Length];
            dr.GetQos().GetUserData().GetValue(userdataVal, 0);

            Assert.AreEqual(userValue.Length, userdataVal.Length);
            Assert.AreEqual(userValue[0], userdataVal[0]);

            byte[] userValue2 = new byte[] { 0x0C };
            userData.SetValue(userValue2, 0, userValue.Length);
            qos.SetUserData(userData);
            dr.SetQos(qos);

            Assert.IsNotNull(dr.GetQos());
            Assert.IsNotNull(dr.GetQos().GetUserData());

            userdataVal = new byte[userValue.Length];
            dr.GetQos().GetUserData().GetValue(userdataVal, 0);

            Assert.AreEqual(userValue2.Length, userdataVal.Length);
            Assert.AreEqual(userValue2[0], userdataVal[0]);
        }