コード例 #1
0
ファイル: testTestUnionStarts.cs プロジェクト: xrl/opensplice
 public override Test.Framework.TestResult Run()
 {
     Test.Framework.TestResult result;
     int status;
     Test.Framework.TestVerdict expVerdict = Test.Framework.TestVerdict.Pass;
     string expResult = "uninitialized struct TestUnionStarts can be written/received without errors.";
     DDS.IDomainParticipant participant;
     testDefConstr.TestUnionStartsTypeSupport tusTS;
     string tusTypeName;
     DDS.ITopic tusTopic;
     DDS.IPublisher pub;
     DDS.ISubscriber sub;
     DDS.IDataWriter dw;
     testDefConstr.TestUnionStartsDataWriter tusDW;
     DDS.IDataReader dr;
     testDefConstr.TestUnionStartsDataReader tusDR;
     long handle;
     string resultMsg;
     // Create Participant.
     participant = DDS.TheParticipantFactory.Value.CreateParticipant(null, DDS.PARTICIPANT_QOS_DEFAULT
         .Value, null, 0);
     if (participant == null)
     {
         result = new Test.Framework.TestResult(expResult, "Creation of DomainParticipant failed."
             , expVerdict, Test.Framework.TestVerdict.Fail);
         return result;
     }
     // Register TypeSupport.
     tusTS = new testDefConstr.TestUnionStartsTypeSupport();
     tusTypeName = tusTS.TypeName;
     status = tusTS.RegisterType(participant, tusTypeName);
     if (status != DDS.ReturnCode.Ok)
     {
         result = new Test.Framework.TestResult(expResult, "Registering of TestUnionStarts TypeSupport failed."
             , expVerdict, Test.Framework.TestVerdict.Fail);
         return result;
     }
     // Create Topic.
     tusTopic = participant.CreateTopic("TestUnionStarts", tusTypeName, DDS.TOPIC_QOS_DEFAULT
         .Value, null, 0);
     if (tusTopic == null)
     {
         result = new Test.Framework.TestResult(expResult, "Creation of TestUnionStarts Topic failed."
             , expVerdict, Test.Framework.TestVerdict.Fail);
         return result;
     }
     // Create Publisher.
     pub = participant.CreatePublisher(DDS.PUBLISHER_QOS_DEFAULT.Value, null, 0);
     if (pub == null)
     {
         result = new Test.Framework.TestResult(expResult, "Creation of Publisher failed."
             , expVerdict, Test.Framework.TestVerdict.Fail);
         return result;
     }
     // Create ADataWriter.
     dw = pub.CreateDataWriter(tusTopic, DDS.DATAWRITER_QOS_USE_TOPIC_QOS.Value, null
         , 0);
     tusDW = testDefConstr.TestUnionStartsDataWriterHelper.Narrow(dw);
     if (tusDW == null)
     {
         result = new Test.Framework.TestResult(expResult, "Creation of TestUnionStartsDataWriter failed."
             , expVerdict, Test.Framework.TestVerdict.Fail);
         return result;
     }
     // Create Subscriber.
     sub = participant.CreateSubscriber(DDS.SUBSCRIBER_QOS_DEFAULT.Value, null, 0);
     if (pub == null)
     {
         result = new Test.Framework.TestResult(expResult, "Creation of Subscriber failed."
             , expVerdict, Test.Framework.TestVerdict.Fail);
         return result;
     }
     // Create ADataReader.
     dr = sub.CreateDataReader(tusTopic, DDS.DATAREADER_QOS_USE_TOPIC_QOS.Value, null
         , 0);
     tusDR = testDefConstr.TestUnionStartsDataReaderHelper.Narrow(dr);
     if (tusDR == null)
     {
         result = new Test.Framework.TestResult(expResult, "Creation of TestUnionStartsDataReader failed."
             , expVerdict, Test.Framework.TestVerdict.Fail);
         return result;
     }
     // Instantiate a sample of A and test if it is initialized properly.
     testDefConstr.TestUnionStarts tus = new testDefConstr.TestUnionStarts();
     resultMsg = TestInit(tus);
     if (resultMsg != null)
     {
         result = new Test.Framework.TestResult(expResult, "Default initialization of TestUnionStarts not successful: "
              + resultMsg, expVerdict, Test.Framework.TestVerdict.Fail);
         return result;
     }
     // Register the sample and write it into the system.
     handle = tusDW.Register_instance(tus);
     if (handle == 0)
     {
         result = new Test.Framework.TestResult(expResult, "Registering an instance of type TestUnionStarts failed."
             , expVerdict, Test.Framework.TestVerdict.Fail);
         return result;
     }
     status = tusDW.Write(tus, handle);
     if (status != DDS.ReturnCode.Ok)
     {
         result = new Test.Framework.TestResult(expResult, "Writing an instance of type TestUnionStarts failed."
             , expVerdict, Test.Framework.TestVerdict.Fail);
         return result;
     }
     // Read the sample and check whether everything is initialized properly.
     testDefConstr.TestUnionStartsSeqHolder msgSeq = new testDefConstr.TestUnionStartsSeqHolder
         ();
     DDS.SampleInfo[] infoSeq = new DDS.SampleInfo[]();
     status = tusDR.Take(msgSeq, infoSeq, DDS.Length.Unlimited, DDS.NOT_READ_SAMPLE_STATE
         .Value, DDS.ViewStateKind.Any, DDS.InstanceStateKind.Alive);
     if (msgSeq.Value.Length != 1)
     {
         result = new Test.Framework.TestResult(expResult, "Wrong number of samples received."
             , expVerdict, Test.Framework.TestVerdict.Fail);
         return result;
     }
     resultMsg = TestInit(msgSeq.Value[0]);
     if (resultMsg != null)
     {
         result = new Test.Framework.TestResult(expResult, "Received TestUnionStarts Sample has a different state from its orginial: "
              + resultMsg, expVerdict, Test.Framework.TestVerdict.Fail);
         return result;
     }
     // Delete all entities.
     status = participant.DeleteContainedEntities();
     if (status != DDS.ReturnCode.Ok)
     {
         result = new Test.Framework.TestResult(expResult, "Deleting contained entities failed."
             , expVerdict, Test.Framework.TestVerdict.Fail);
         return result;
     }
     status = DDS.TheParticipantFactory.Value.DeleteParticipant(participant);
     if (status != DDS.ReturnCode.Ok)
     {
         result = new Test.Framework.TestResult(expResult, "Deleting participant failed.",
             expVerdict, Test.Framework.TestVerdict.Fail);
         return result;
     }
     result = new Test.Framework.TestResult(expResult, expResult, expVerdict, expVerdict
         );
     return result;
 }
コード例 #2
0
        public override Test.Framework.TestResult Run()
        {
            Test.Framework.TestResult result;
            int status;

            Test.Framework.TestVerdict expVerdict = Test.Framework.TestVerdict.Pass;
            string expResult = "uninitialized struct TestUnionStarts can be written/received without errors.";

            DDS.IDomainParticipant participant;
            testDefConstr.TestUnionStartsTypeSupport tusTS;
            string tusTypeName;

            DDS.ITopic      tusTopic;
            DDS.IPublisher  pub;
            DDS.ISubscriber sub;
            DDS.IDataWriter dw;
            testDefConstr.TestUnionStartsDataWriter tusDW;
            DDS.IDataReader dr;
            testDefConstr.TestUnionStartsDataReader tusDR;
            long   handle;
            string resultMsg;

            // Create Participant.
            participant = DDS.TheParticipantFactory.Value.CreateParticipant(DDS.DomainId.Default, DDS.PARTICIPANT_QOS_DEFAULT
                                                                            .Value, null, 0);
            if (participant == null)
            {
                result = new Test.Framework.TestResult(expResult, "Creation of DomainParticipant failed."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            // Register TypeSupport.
            tusTS       = new testDefConstr.TestUnionStartsTypeSupport();
            tusTypeName = tusTS.TypeName;
            status      = tusTS.RegisterType(participant, tusTypeName);
            if (status != DDS.ReturnCode.Ok)
            {
                result = new Test.Framework.TestResult(expResult, "Registering of TestUnionStarts TypeSupport failed."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            // Create Topic.
            tusTopic = participant.CreateTopic("TestUnionStarts", tusTypeName, DDS.TOPIC_QOS_DEFAULT
                                               .Value, null, 0);
            if (tusTopic == null)
            {
                result = new Test.Framework.TestResult(expResult, "Creation of TestUnionStarts Topic failed."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            // Create Publisher.
            pub = participant.CreatePublisher(DDS.PUBLISHER_QOS_DEFAULT.Value, null, 0);
            if (pub == null)
            {
                result = new Test.Framework.TestResult(expResult, "Creation of Publisher failed."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            // Create ADataWriter.
            dw = pub.CreateDataWriter(tusTopic, DDS.DATAWRITER_QOS_USE_TOPIC_QOS.Value, null
                                      , 0);
            tusDW = testDefConstr.TestUnionStartsDataWriterHelper.Narrow(dw);
            if (tusDW == null)
            {
                result = new Test.Framework.TestResult(expResult, "Creation of TestUnionStartsDataWriter failed."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            // Create Subscriber.
            sub = participant.CreateSubscriber(DDS.SUBSCRIBER_QOS_DEFAULT.Value, null, 0);
            if (pub == null)
            {
                result = new Test.Framework.TestResult(expResult, "Creation of Subscriber failed."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            // Create ADataReader.
            dr = sub.CreateDataReader(tusTopic, DDS.DATAREADER_QOS_USE_TOPIC_QOS.Value, null
                                      , 0);
            tusDR = testDefConstr.TestUnionStartsDataReaderHelper.Narrow(dr);
            if (tusDR == null)
            {
                result = new Test.Framework.TestResult(expResult, "Creation of TestUnionStartsDataReader failed."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            // Instantiate a sample of A and test if it is initialized properly.
            testDefConstr.TestUnionStarts tus = new testDefConstr.TestUnionStarts();
            resultMsg = TestInit(tus);
            if (resultMsg != null)
            {
                result = new Test.Framework.TestResult(expResult, "Default initialization of TestUnionStarts not successful: "
                                                       + resultMsg, expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            // Register the sample and write it into the system.
            handle = tusDW.Register_instance(tus);
            if (handle == 0)
            {
                result = new Test.Framework.TestResult(expResult, "Registering an instance of type TestUnionStarts failed."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            status = tusDW.Write(tus, handle);
            if (status != DDS.ReturnCode.Ok)
            {
                result = new Test.Framework.TestResult(expResult, "Writing an instance of type TestUnionStarts failed."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            // Read the sample and check whether everything is initialized properly.
            testDefConstr.TestUnionStartsSeqHolder msgSeq = new testDefConstr.TestUnionStartsSeqHolder
                                                                ();
            DDS.SampleInfo[] infoSeq = new DDS.SampleInfo[] ();
            status = tusDR.Take(msgSeq, infoSeq, DDS.Length.Unlimited, DDS.NOT_READ_SAMPLE_STATE
                                .Value, DDS.ViewStateKind.Any, DDS.InstanceStateKind.Alive);
            if (msgSeq.Value.Length != 1)
            {
                result = new Test.Framework.TestResult(expResult, "Wrong number of samples received."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            resultMsg = TestInit(msgSeq.Value[0]);
            if (resultMsg != null)
            {
                result = new Test.Framework.TestResult(expResult, "Received TestUnionStarts Sample has a different state from its orginial: "
                                                       + resultMsg, expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            // Delete all entities.
            status = participant.DeleteContainedEntities();
            if (status != DDS.ReturnCode.Ok)
            {
                result = new Test.Framework.TestResult(expResult, "Deleting contained entities failed."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            status = DDS.TheParticipantFactory.Value.DeleteParticipant(participant);
            if (status != DDS.ReturnCode.Ok)
            {
                result = new Test.Framework.TestResult(expResult, "Deleting participant failed.",
                                                       expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            result = new Test.Framework.TestResult(expResult, expResult, expVerdict, expVerdict
                                                   );
            return(result);
        }