Пример #1
0
 def test_runtime(self):
     comp = sb.launch('cpp_dev')
     teststring = CF.DataType(id='teststring', value=_any.to_any('foo'))
     comp.configure([teststring])
     teststring = CF.DataType(id='teststring', value=_any.to_any(None))
     retval = comp.query([teststring])
     self.assertEquals(retval[0].value._v, 'foo')
     comp.teststring = 'hello'
     retval = comp.query([teststring])
     self.assertEquals(retval[0].value._v, 'hello')
     snk = sb.DataSink()
     comp.connect(snk)
     sb.start()
     self.assertTrue(comp._get_started())
     time.sleep(2)
     self.assertTrue(len(snk.getData()) > 10000)
Пример #2
0
    def runConfigurationTest(self, spd_file, prf_file):
        """
        Tests all the properties defined in the PRF file and attempts to 
        configure each property.  If the property is of kind 'configure' and 
        the mode is not readonly, then it compares the results with what is
        expected.  Otherwise it expects an exception to be thrown
        
        Inputs:
            <spd_file>    The component's SPD file
            <prf_file>    The component's properties file
        """
        self.launch()
        prf = PRFParser.parse(prf_file)
        props = prf.get_simple()
        int_off = 1
        frac_off = 1.0
        # iterating through all the properties
        for prop in props:
            id_ = prop.get_id()
            mode_ = prop.get_mode()
            val_ = prop.get_value()
            type_ = prop.get_type()

            kinds = prop.get_kind()
            is_configurable = False

            # check each kind to see if at least one of them is configure
            for kind in kinds:
                kind_type = kind.get_kindtype()
                if kind_type == 'configure':
                    is_configurable = True
                    break
            # generate some bogus value
            if type_ == 'double' or type_ == 'float':
                new_val = frac_off + float(val_)
            elif type_ == 'integer' or type_ == 'long':
                new_val = int_off + int(val_)
            else:
                new_val = '%s_%d' % (val_, int_off)

            conf_prop = CF.DataType(id=str(id_), value=any.to_any(new_val))

            # if it can be configured, test that is the case
            if is_configurable and mode_ != 'readonly':
                self.comp_obj.configure([conf_prop])
                q_value = self.comp_obj.query([conf_prop])
                self.assertEqual(len(q_value), 1)
                self.assertEqual(conf_prop.id, q_value[0].id)
                self.assertEqual(conf_prop.value._v, q_value[0].value._v)

            # this property should be be configurable
            else:
                try:
                    self.comp_obj.configure([conf_prop])
                    self.assertFalse()
                except:
                    # Got an expected error, so we should continue
                    continue
Пример #3
0
    def getPropertySet(self, kinds=("configure","property",), \
                             modes=("readwrite", "writeonly", "readonly"), \
                             action="external", \
                             includeNil=True,
                             commandline=False):
        """
        A useful utility function that extracts specified property types from
        the PRF file and turns them into a CF.PropertySet
        """
        propertySet = []

        # Simples
        if self.prf != None:
            for prop in self.prf.get_simple():
                if self.isMatch(prop, modes, kinds, (action, )):
                    if prop.get_value() is not None:
                        if prop.complex.lower() == "true":
                            type = mapComplexType(prop.get_type())
                            value = stringToComplex(prop.get_value(), type)
                        else:
                            type = prop.get_type()
                            value = prop.get_value()
                        dt = properties.to_tc_value(value, type)
                    elif not includeNil:
                        continue
                    else:
                        dt = any.to_any(None)
                    p = CF.DataType(id=str(prop.get_id()), value=dt)
                    propertySet.append(p)

            # Simple Sequences
            for prop in self.prf.get_simplesequence():
                if self.isMatch(prop, modes, kinds, (action, )):
                    if prop.get_values() is not None:
                        seq = []
                        if prop.complex.lower() == "true":
                            type = mapComplexType(prop.get_type())
                            for v in prop.get_values().get_value():
                                seq.append(stringToComplex(v, type))
                            expectedType = properties.getTypeCode(type)
                            expectedTypeCode = tcInternal.createTypeCode(
                                (tcInternal.tv_sequence, expectedType._d, 0))
                            dt = CORBA.Any(expectedTypeCode, [
                                properties._convertComplexToCFComplex(
                                    item, type) for item in seq
                            ])
                        else:
                            type = prop.get_type()
                            for v in prop.get_values().get_value():
                                value = v
                                seq.append(properties.to_pyvalue(value, type))
                            dt = any.to_any(seq)
                    elif not includeNil:
                        continue
                    else:
                        dt = any.to_any(None)
                    p = CF.DataType(id=str(prop.get_id()), value=dt)
                    propertySet.append(p)

            # Structures
            for prop in self.prf.get_struct():
                if self.isMatch(prop, modes, kinds, (action, )):
                    if (prop.get_simple()
                            is not None) or (prop.get_simplesequence()
                                             is not None):
                        fields = []
                        hasValue = False
                        if prop.get_simple() is not None:
                            for p in prop.get_simple():
                                if p.get_value() is not None:
                                    hasValue = True
                                dt = properties.to_tc_value(
                                    p.get_value(), p.get_type())
                                fields.append(
                                    CF.DataType(id=str(p.get_id()), value=dt))
                        if prop.get_simplesequence() is not None:
                            for p in prop.get_simplesequence():
                                if p.get_values() is not None:
                                    hasValue = True
                                dt = properties.to_tc_value(
                                    p.get_values(), p.get_type())
                                fields.append(
                                    CF.DataType(id=str(p.get_id()), value=dt))
                        if not hasValue and not includeNil:
                            continue
                        dt = any.to_any(fields)
                    else:
                        dt = any.to_any(None)
                    p = CF.DataType(id=str(prop.get_id()), value=dt)
                    propertySet.append(p)

            # Struct Sequence
            for prop in self.prf.get_structsequence():
                if self.isMatch(prop, modes, kinds, (action, )):
                    baseProp = []
                    if prop.get_struct() != None:
                        fields = []
                        for internal_prop in prop.get_struct().get_simple():
                            fields.append(
                                CF.DataType(id=str(internal_prop.get_id()),
                                            value=any.to_any(None)))
                        for internal_prop in prop.get_struct(
                        ).get_simplesequence():
                            fields.append(
                                CF.DataType(id=str(internal_prop.get_id()),
                                            value=any.to_any(None)))
                    for val in prop.get_structvalue():
                        baseProp.append(copy.deepcopy(fields))
                        for entry in val.get_simpleref():
                            val_type = None
                            for internal_prop in prop.get_struct().get_simple(
                            ):
                                if str(internal_prop.get_id()) == entry.refid:
                                    val_type = internal_prop.get_type()
                            for subfield in baseProp[-1]:
                                if subfield.id == entry.refid:
                                    subfield.value = properties.to_tc_value(
                                        entry.get_value(), val_type)
                        for entry in val.get_simplesequenceref():
                            val_type = None
                            for internal_prop in prop.get_struct(
                            ).get_simplesequence():
                                if str(internal_prop.get_id()) == entry.refid:
                                    val_type = internal_prop.get_type()
                            for subfield in baseProp[-1]:
                                if subfield.id == entry.refid:
                                    subfield.value = properties.to_tc_value(
                                        entry.get_values(), val_type)
                    anybp = []
                    for bp in baseProp:
                        anybp.append(properties.props_to_any(bp))
                    p = CF.DataType(id=str(prop.get_id()),
                                    value=any.to_any(anybp))
                    propertySet.append(p)

        return propertySet