示例#1
0
文件: testA.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 A can be written/received without errors.";
     DDS.IDomainParticipant participant;
     testDefConstr.ATypeSupport aTS;
     string aTypeName;
     DDS.ITopic aTopic;
     DDS.IPublisher pub;
     DDS.ISubscriber sub;
     DDS.IDataWriter dw;
     testDefConstr.ADataWriter aDW;
     DDS.IDataReader dr;
     testDefConstr.ADataReader aDR;
     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.
     aTS = new testDefConstr.ATypeSupport();
     aTypeName = aTS.TypeName;
     status = aTS.RegisterType(participant, aTypeName);
     if (status != DDS.ReturnCode.Ok)
     {
         result = new Test.Framework.TestResult(expResult, "Registering of A TypeSupport failed."
             , expVerdict, Test.Framework.TestVerdict.Fail);
         return result;
     }
     // Create Topic.
     aTopic = participant.CreateTopic("structA", aTypeName, DDS.TOPIC_QOS_DEFAULT.Value
         , null, 0);
     if (aTopic == null)
     {
         result = new Test.Framework.TestResult(expResult, "Creation of A 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(aTopic, DDS.DATAWRITER_QOS_USE_TOPIC_QOS.Value, null,
         0);
     aDW = testDefConstr.ADataWriterHelper.Narrow(dw);
     if (aDW == null)
     {
         result = new Test.Framework.TestResult(expResult, "Creation of ADataWriter 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(aTopic, DDS.DATAREADER_QOS_USE_TOPIC_QOS.Value, null,
         0);
     aDR = testDefConstr.ADataReaderHelper.Narrow(dr);
     if (aDR == null)
     {
         result = new Test.Framework.TestResult(expResult, "Creation of ADataReader failed."
             , expVerdict, Test.Framework.TestVerdict.Fail);
         return result;
     }
     // Instantiate a sample of A and test if it is initialized properly.
     testDefConstr.A myA = new testDefConstr.A();
     resultMsg = TestInit(myA);
     if (resultMsg != null)
     {
         result = new Test.Framework.TestResult(expResult, "Default initialization of A not successful: "
              + resultMsg, expVerdict, Test.Framework.TestVerdict.Fail);
         return result;
     }
     // Register the sample and write it into the system.
     handle = aDW.Register_instance(myA);
     if (handle == 0)
     {
         result = new Test.Framework.TestResult(expResult, "Registering an instance of type A failed."
             , expVerdict, Test.Framework.TestVerdict.Fail);
         return result;
     }
     status = aDW.Write(myA, handle);
     if (status != DDS.ReturnCode.Ok)
     {
         result = new Test.Framework.TestResult(expResult, "Writing an instance of type A failed."
             , expVerdict, Test.Framework.TestVerdict.Fail);
         return result;
     }
     // Read the sample and check whether everything is initialized properly.
     testDefConstr.ASeqHolder msgSeq = new testDefConstr.ASeqHolder();
     DDS.SampleInfo[] infoSeq = new DDS.SampleInfo[]();
     status = aDR.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 A 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 A can be written/received without errors.";

            DDS.IDomainParticipant     participant;
            testDefConstr.ATypeSupport aTS;
            string aTypeName;

            DDS.ITopic                aTopic;
            DDS.IPublisher            pub;
            DDS.ISubscriber           sub;
            DDS.IDataWriter           dw;
            testDefConstr.ADataWriter aDW;
            DDS.IDataReader           dr;
            testDefConstr.ADataReader aDR;
            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.
            aTS       = new testDefConstr.ATypeSupport();
            aTypeName = aTS.TypeName;
            status    = aTS.RegisterType(participant, aTypeName);
            if (status != DDS.ReturnCode.Ok)
            {
                result = new Test.Framework.TestResult(expResult, "Registering of A TypeSupport failed."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            // Create Topic.
            aTopic = participant.CreateTopic("structA", aTypeName, DDS.TOPIC_QOS_DEFAULT.Value
                                             , null, 0);
            if (aTopic == null)
            {
                result = new Test.Framework.TestResult(expResult, "Creation of A 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(aTopic, DDS.DATAWRITER_QOS_USE_TOPIC_QOS.Value, null,
                                      0);
            aDW = testDefConstr.ADataWriterHelper.Narrow(dw);
            if (aDW == null)
            {
                result = new Test.Framework.TestResult(expResult, "Creation of ADataWriter 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(aTopic, DDS.DATAREADER_QOS_USE_TOPIC_QOS.Value, null,
                                      0);
            aDR = testDefConstr.ADataReaderHelper.Narrow(dr);
            if (aDR == null)
            {
                result = new Test.Framework.TestResult(expResult, "Creation of ADataReader failed."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            // Instantiate a sample of A and test if it is initialized properly.
            testDefConstr.A myA = new testDefConstr.A();
            resultMsg = TestInit(myA);
            if (resultMsg != null)
            {
                result = new Test.Framework.TestResult(expResult, "Default initialization of A not successful: "
                                                       + resultMsg, expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            // Register the sample and write it into the system.
            handle = aDW.Register_instance(myA);
            if (handle == 0)
            {
                result = new Test.Framework.TestResult(expResult, "Registering an instance of type A failed."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            status = aDW.Write(myA, handle);
            if (status != DDS.ReturnCode.Ok)
            {
                result = new Test.Framework.TestResult(expResult, "Writing an instance of type A failed."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            // Read the sample and check whether everything is initialized properly.
            testDefConstr.ASeqHolder msgSeq  = new testDefConstr.ASeqHolder();
            DDS.SampleInfo[]         infoSeq = new DDS.SampleInfo[] ();
            status = aDR.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 A 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);
        }
示例#3
0
        public override Test.Framework.TestResult Run()
        {
            Test.Framework.TestResult  result;
            DDS.ReturnCode             status;
            Test.Framework.TestVerdict expVerdict = Test.Framework.TestVerdict.Pass;
            string expResult = "Both uninitialized and initialized struct A can be written/received without errors.";

            DDS.IDomainParticipant     participant;
            testDefConstr.ATypeSupport aTS;
            string aTypeName;

            DDS.ITopic                aTopic;
            DDS.IPublisher            pub;
            DDS.ISubscriber           sub;
            testDefConstr.ADataWriter aDW;
            testDefConstr.ADataReader aDR;
            long   handle;
            string resultMsg;

            // Create Participant.
            participant = DDS.DomainParticipantFactory.Instance.CreateParticipant(DDS.DomainId.Default);
            if (participant == null)
            {
                result = new Test.Framework.TestResult(expResult, "Creation of DomainParticipant failed."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            // Register TypeSupport.
            aTS       = new testDefConstr.ATypeSupport();
            aTypeName = aTS.TypeName;
            status    = aTS.RegisterType(participant, aTypeName);
            if (status != DDS.ReturnCode.Ok)
            {
                result = new Test.Framework.TestResult(expResult, "Registering of A TypeSupport failed."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            // Create Topic.
            aTopic = participant.CreateTopic("structA", aTypeName);
            if (aTopic == null)
            {
                result = new Test.Framework.TestResult(expResult, "Creation of A Topic failed.",
                                                       expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            // Create Publisher.
            pub = participant.CreatePublisher();
            if (pub == null)
            {
                result = new Test.Framework.TestResult(expResult, "Creation of Publisher failed."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            // Create ADataWriter.
            aDW = pub.CreateDataWriter(aTopic) as testDefConstr.ADataWriter;;
            if (aDW == null)
            {
                result = new Test.Framework.TestResult(expResult, "Creation of ADataWriter failed."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            // Create Subscriber.
            sub = participant.CreateSubscriber();
            if (pub == null)
            {
                result = new Test.Framework.TestResult(expResult, "Creation of Subscriber failed."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            // Create ADataReader.
            aDR = sub.CreateDataReader(aTopic) as testDefConstr.ADataReader;
            if (aDR == null)
            {
                result = new Test.Framework.TestResult(expResult, "Creation of ADataReader failed."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            // Instantiate a sample of A and test if it is initialized properly.
            testDefConstr.A myA = new testDefConstr.A();
            resultMsg = TestInit(myA);
            if (resultMsg != null)
            {
                result = new Test.Framework.TestResult(expResult, "Default initialization of A not successful: "
                                                       + resultMsg, expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            // Register the sample and write it into the system.
            handle = aDW.RegisterInstance(myA);
            if (handle == 0)
            {
                result = new Test.Framework.TestResult(expResult, "Registering an instance of type A failed."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            status = aDW.Write(myA, handle);
            if (status != DDS.ReturnCode.Ok)
            {
                result = new Test.Framework.TestResult(expResult, "Writing an instance of type A failed."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            // Read the sample and check whether everything is initialized properly.
            testDefConstr.A[] msgSeq  = null;
            DDS.SampleInfo[]  infoSeq = null;
            status = aDR.Take(ref msgSeq, ref infoSeq, DDS.Length.Unlimited, DDS.SampleStateKind.NotRead,
                              DDS.ViewStateKind.Any, DDS.InstanceStateKind.Alive);
            if (msgSeq.Length != 1)
            {
                result = new Test.Framework.TestResult(expResult, "Wrong number of samples received."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            resultMsg = TestInit(msgSeq[0]);
            if (resultMsg != null)
            {
                result = new Test.Framework.TestResult(expResult, "Received A Sample has a different state from its orginial: "
                                                       + resultMsg, expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }

            //Now explicitly initlaize sample to some preset values.
            myA.id         = 5;
            myA.name       = "Mary";
            myA.embedded.x = 1;
            myA.embedded.y = 2;
            myA.embedded.z = 3;
            myA.c          = testDefConstr.Color.Blue;
            for (int i = 0; i < testDefConstr.DIM_NUMS_1.value; i++)
            {
                for (int j = 0; j < testDefConstr.DIM_NUMS_2.value; j++)
                {
                    myA.nums[i, j] = 10 + i + j;
                }
            }
            myA.nums2       = new int[2][];
            myA.nums2[0]    = new int[1];
            myA.nums2[1]    = new int[1];
            myA.nums2[0][0] = 8;
            myA.nums2[1][0] = 9;

            myA.floatList       = new float[1][];
            myA.floatList[0]    = new float[2];
            myA.floatList[0][0] = 0.1f;
            myA.floatList[0][1] = 0.2f;

            myA.stringList = new string[3] {
                "Erik", "Maurtis", "Hans"
            };

            for (int i = 0; i < testDefConstr.DIM_LA2DIM_1.value; i++)
            {
                for (int j = 0; j < testDefConstr.DIM_LONGARRAY10_1.value; j++)
                {
                    myA.la2Dim[i, j] = testDefConstr.DIM_LA2DIM_1.value * i + j;
                }
            }

            // Register the sample and write it into the system.
            handle = aDW.RegisterInstance(myA);
            if (handle == 0)
            {
                result = new Test.Framework.TestResult(expResult, "Registering an initialized instance of type A failed."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            status = aDW.Write(myA, handle);
            if (status != DDS.ReturnCode.Ok)
            {
                result = new Test.Framework.TestResult(expResult, "Writing an initialized instance of type A failed."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            // Read the sample and check whether everything is initialized properly.
            status = aDR.Take(ref msgSeq, ref infoSeq, DDS.Length.Unlimited, DDS.SampleStateKind.NotRead,
                              DDS.ViewStateKind.Any, DDS.InstanceStateKind.Alive);
            if (msgSeq.Length != 1)
            {
                result = new Test.Framework.TestResult(expResult, "Wrong number of samples received."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            resultMsg = compareSamples(myA, msgSeq[0]);
            if (resultMsg != null)
            {
                result = new Test.Framework.TestResult(expResult, "Received A 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.DomainParticipantFactory.Instance.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);
        }