void test_builder() { testDiag("test_builder"); NTEnumBuilderPtr builder = NTEnum::createBuilder(); testOk(builder.get() != 0, "Got builder"); StructureConstPtr structure = builder-> addDescriptor()-> addAlarm()-> addTimeStamp()-> add("valueAlarm",standardField->doubleAlarm()) -> add("extra",fieldCreate->createScalarArray(pvString)) -> createStructure(); testOk1(structure.get() != 0); if (!structure) return; testOk1(NTEnum::is_a(structure)); testOk1(structure->getID() == NTEnum::URI); testOk1(structure->getNumberFields() == 6); testOk1(structure->getField("value").get() != 0); testOk1(structure->getField("descriptor").get() != 0); testOk1(structure->getField("alarm").get() != 0); testOk1(structure->getField("timeStamp").get() != 0); FieldConstPtr valueField = structure->getField("value"); testOk(valueField.get() != 0 && ntField->isEnumerated(valueField), "value is enum"); std::cout << *structure << std::endl; }
void test_extra() { testDiag("test_extra"); NTContinuumBuilderPtr builder = NTContinuum::createBuilder(); testOk(builder.get() != 0, "Got builder"); StructureConstPtr structure = builder-> addTimeStamp()-> add("function", getFieldCreate()->createScalar(pvString))-> createStructure(); testOk1(structure.get() != 0); if (!structure) return; testOk1(NTContinuum::is_a(structure)); testOk1(structure->getID() == NTContinuum::URI); testOk1(structure->getNumberFields() == 5); testOk1(structure->getField("base").get() != 0); testOk1(structure->getField("value").get() != 0); testOk1(structure->getField("units").get() != 0); testOk1(structure->getField("timeStamp").get() != 0); testOk1(structure->getField("function").get() != 0); testOk(dynamic_pointer_cast<const Scalar>(structure->getField("function")).get() != 0 && dynamic_pointer_cast<const Scalar>(structure->getField("function"))->getScalarType() == pvString, "function type"); std::cout << *structure << std::endl; }
void test_builder() { testDiag("test_builder"); NTTableBuilderPtr builder = NTTable::createBuilder(); testOk(builder.get() != 0, "Got builder"); StructureConstPtr structure = builder-> addColumn("column0", pvDouble)-> addColumn("column1", pvString)-> addColumn("column2", pvInt)-> addDescriptor()-> addAlarm()-> addTimeStamp()-> add("extra1",fieldCreate->createScalar(pvString)) -> add("extra2",fieldCreate->createScalarArray(pvString)) -> createStructure(); testOk1(structure.get() != 0); if (!structure) return; testOk1(NTTable::is_a(structure)); testOk1(structure->getID() == NTTable::URI); testOk1(structure->getNumberFields() == 7); testOk1(structure->getField("labels").get() != 0); testOk1(structure->getField("value").get() != 0); testOk1(structure->getField("descriptor").get() != 0); testOk1(structure->getField("alarm").get() != 0); testOk1(structure->getField("timeStamp").get() != 0); testOk1(structure->getField("extra1").get() != 0); testOk1(structure->getField("extra2").get() != 0); StructureConstPtr s = dynamic_pointer_cast<const Structure>(structure->getField("value")); #define TEST_COLUMN(name, type) \ testOk(s.get() != 0 && \ s->getField(name).get() != 0 && \ dynamic_pointer_cast<const ScalarArray>(s->getField(name)).get() != 0 && \ dynamic_pointer_cast<const ScalarArray>(s->getField(name))->getElementType() == type, \ name " check"); TEST_COLUMN("column0", pvDouble); TEST_COLUMN("column1", pvString); TEST_COLUMN("column2", pvInt); #undef TEST_COLUMN std::cout << *structure << std::endl; // duplicate test try { structure = builder-> addColumn("column0", pvDouble)-> addColumn("column0", pvString)-> createStructure(); testFail("duplicate column name"); } catch (std::runtime_error &) { testPass("duplicate column name"); } }
void test_builder() { testDiag("test_builder"); NTScalarArrayBuilderPtr builder = NTScalarArray::createBuilder(); testOk(builder.get() != 0, "Got builder"); StructureConstPtr structure = builder-> value(pvDouble)-> addDescriptor()-> addAlarm()-> addTimeStamp()-> addDisplay()-> addControl()-> add("extra1",fieldCreate->createScalar(pvString)) -> add("extra2",fieldCreate->createScalarArray(pvString)) -> createStructure(); testOk1(structure.get() != 0); if (!structure) return; testOk1(NTScalarArray::is_a(structure)); testOk1(structure->getID() == NTScalarArray::URI); testOk1(structure->getNumberFields() == 8); testOk1(structure->getField("value").get() != 0); testOk1(structure->getField("descriptor").get() != 0); testOk1(structure->getField("alarm").get() != 0); testOk1(structure->getField("timeStamp").get() != 0); testOk1(structure->getField("display").get() != 0); testOk1(structure->getField("control").get() != 0); testOk(dynamic_pointer_cast<const ScalarArray>(structure->getField("value")).get() != 0 && dynamic_pointer_cast<const ScalarArray>(structure->getField("value"))->getElementType() == pvDouble, "value type"); std::cout << *structure << std::endl; // no value set try { structure = builder-> addDescriptor()-> addAlarm()-> addTimeStamp()-> addDisplay()-> addControl()-> createStructure(); testFail("no value type set"); } catch (std::runtime_error &) { testPass("no value type set"); } }
PVStructure::PVStructure(StructureConstPtr const & structurePtr, PVFieldPtrArray const & pvs ) : PVField(structurePtr), structurePtr(structurePtr), extendsStructureName("") { size_t numberFields = structurePtr->getNumberFields(); StringArray fieldNames = structurePtr->getFieldNames(); pvFields.reserve(numberFields); for(size_t i=0; i<numberFields; i++) { pvFields.push_back(pvs[i]); } for(size_t i=0; i<numberFields; i++) { pvFields[i]->setParentAndName(this,fieldNames[i]); } }
PVStructure::PVStructure(StructureConstPtr const & structurePtr) : PVField(structurePtr), structurePtr(structurePtr), extendsStructureName("") { size_t numberFields = structurePtr->getNumberFields(); FieldConstPtrArray fields = structurePtr->getFields(); StringArray fieldNames = structurePtr->getFieldNames(); // PVFieldPtrArray * xxx = const_cast<PVFieldPtrArray *>(&pvFields); pvFields.reserve(numberFields); PVDataCreatePtr pvDataCreate = getPVDataCreate(); for(size_t i=0; i<numberFields; i++) { pvFields.push_back(pvDataCreate->createPVField(fields[i])); } for(size_t i=0; i<numberFields; i++) { pvFields[i]->setParentAndName(this,fieldNames[i]); } }
void test_builder() { testDiag("test_builder"); NTNDArrayAttributeBuilderPtr builder = NTNDArrayAttribute::createBuilder(); testOk(builder.get() != 0, "Got builder"); StructureConstPtr structure = builder-> addTags()-> addAlarm()-> addTimeStamp()-> add("extra",fieldCreate->createScalar(pvString)) -> createStructure(); testOk1(structure.get() != 0); if (!structure) return; testOk1(NTNDArrayAttribute::is_a(structure)); testOk1(structure->getID() == NTNDArrayAttribute::URI); testOk1(structure->getNumberFields() == 9); testOk1(structure->getField("name").get() != 0); testOk1(structure->getField("value").get() != 0); testOk1(structure->getField("tags").get() != 0); testOk1(structure->getField("descriptor").get() != 0); testOk1(structure->getField("alarm").get() != 0); testOk1(structure->getField("timeStamp").get() != 0); testOk1(structure->getField("sourceType").get() != 0); testOk1(structure->getField("source").get() != 0); ScalarConstPtr nameField = structure->getField<Scalar>("name"); testOk(nameField.get() != 0 && nameField->getScalarType() == pvString, "name is string"); UnionConstPtr valueField = structure->getField<Union>("value"); testOk(valueField.get() != 0, "value is enum"); ScalarArrayConstPtr tagsField = structure->getField<ScalarArray>("tags"); testOk(tagsField.get() != 0 && tagsField->getElementType() == pvString, "tags is string[]"); std::cout << *structure << std::endl; }
void test_builder() { testDiag("test_builder"); NTContinuumBuilderPtr builder = NTContinuum::createBuilder(); testOk(builder.get() != 0, "Got builder"); StructureConstPtr structure = builder-> addDescriptor()-> addAlarm()-> addTimeStamp()-> add("extra1",fieldCreate->createScalar(pvString)) -> add("extra2",fieldCreate->createScalarArray(pvString)) -> createStructure(); testOk1(structure.get() != 0); if (!structure) return; testOk1(NTContinuum::is_a(structure)); testOk1(structure->getID() == NTContinuum::URI); testOk1(structure->getNumberFields() == 8); testOk1(structure->getField("base").get() != 0); testOk1(structure->getField("value").get() != 0); testOk1(structure->getField("units").get() != 0); testOk1(structure->getField("descriptor").get() != 0); testOk1(structure->getField("alarm").get() != 0); testOk1(structure->getField("timeStamp").get() != 0); testOk(dynamic_pointer_cast<const ScalarArray>(structure->getField("base")).get() != 0 && dynamic_pointer_cast<const ScalarArray>(structure->getField("base"))->getElementType() == pvDouble, "base array element type"); testOk(dynamic_pointer_cast<const ScalarArray>(structure->getField("value")).get() != 0 && dynamic_pointer_cast<const ScalarArray>(structure->getField("value"))->getElementType() == pvDouble, "value array element type"); testOk(dynamic_pointer_cast<const ScalarArray>(structure->getField("units")).get() != 0 && dynamic_pointer_cast<const ScalarArray>(structure->getField("units"))->getElementType() == pvString, "units array element type"); std::cout << *structure << std::endl; }