예제 #1
0
void test_invalid()
{
    testDiag("Test test_invalid()");

    FieldCreatePtr fieldCreate = getFieldCreate();

    try
    {
        fieldCreate->createFieldBuilder()->
            add("f1", pvByte)->
            endNested();
        testFail("endNested() allowed in non-nested FieldBuilder");
    }
    catch (std::runtime_error& re) {
        // ok
        testPass("endNested() disallowed in non-nested FieldBuilder");
    }

    try
    {
        fieldCreate->createFieldBuilder()->
            add("f1", pvByte)->
            addNestedStructure("nested")->
                add("n1", pvUInt)->
                createStructure();
        testFail("createStructure() allowed in nested FieldBuilder");
    }
    catch (std::runtime_error& re) {
        // ok
        testPass("createStructure() disallowed in nested FieldBuilder");
    }
}
예제 #2
0
void test_factory()
{
    testDiag("Test test_factory()");

    FieldCreatePtr fieldCreate = getFieldCreate();

    FieldBuilderPtr fb = fieldCreate->createFieldBuilder();
    testOk1(fb.get() != 0);

    FieldBuilderPtr fb2 = fieldCreate->createFieldBuilder();
	testOk1(fb.get() != fb2.get());
}
static void createDumbPowerSupplyRecord(
    PVDatabasePtr const &master,
    string const &recordName)
{
     StructureConstPtr top = fieldCreate->createFieldBuilder()->
         add("alarm",standardField->alarm()) ->
            add("timeStamp",standardField->timeStamp()) ->
            addNestedStructure("power") ->
               add("value",pvDouble) ->
               add("alarm",standardField->alarm()) ->
               endNested()->
            addNestedStructure("voltage") ->
               add("value",pvDouble) ->
               add("alarm",standardField->alarm()) ->
               endNested()->
            addNestedStructure("current") ->
               add("value",pvDouble) ->
               add("alarm",standardField->alarm()) ->
               endNested()->
            createStructure();
    PVStructurePtr pvStructure = pvDataCreate->createPVStructure(top);
    PVRecordPtr pvRecord = PVRecord::create(recordName,pvStructure);
    bool result = master->addRecord(pvRecord);
    if(!result) cout<< "record " << recordName << " not added" << endl;
}
예제 #4
0
PowerSupplyRecordPtr PowerSupplyRecord::create(
    string const & recordName)
{
    FieldCreatePtr fieldCreate = getFieldCreate();
    StandardFieldPtr standardField = getStandardField();
    PVDataCreatePtr pvDataCreate = getPVDataCreate();

    StructureConstPtr  topStructure = fieldCreate->createFieldBuilder()->
            add("alarm",standardField->alarm()) ->
            add("timeStamp",standardField->timeStamp()) ->
            addNestedStructure("power") ->
               add("value",pvDouble) ->
               endNested()->
            addNestedStructure("voltage") ->
               add("value",pvDouble) ->
               endNested()->
            addNestedStructure("current") ->
               add("value",pvDouble) ->
               endNested()->
            createStructure();
    PVStructurePtr pvStructure = pvDataCreate->createPVStructure(topStructure);
    PowerSupplyRecordPtr pvRecord(
        new PowerSupplyRecord(recordName,pvStructure));
    if(!pvRecord->init()) pvRecord.reset();
    return pvRecord;
}
예제 #5
0
void test_nestedStructureArray()
{
    testDiag("Test test_nestedStructureArray()");

    FieldCreatePtr fieldCreate = getFieldCreate();
    
    string NESTED_ID = "nestedID";
    StructureConstPtr s = fieldCreate->createFieldBuilder()->
                            add("double", pvDouble)->
                            addNestedStructureArray("nested")->
                                setId(NESTED_ID)->
                                add("short", pvShort)->
                                add("long", pvLong)->
                                endNested()->
                            addArray("intArray", pvInt)->
                            createStructure();
    testOk1(s.get() != 0);
    testOk1(Structure::DEFAULT_ID == s->getID());
    testOk1(3 == s->getFields().size());

    FieldConstPtr f0 = s->getField(0);
    testOk1(scalar == f0->getType());
    testOk1("double" == s->getFieldName(0));
    testOk(pvDouble == static_pointer_cast<const Scalar>(f0)->getScalarType(), "f0 scalar type == double");

    FieldConstPtr f1 = s->getField(1);
    testOk1(structureArray == f1->getType());
    testOk1("nested" == s->getFieldName(1));

    {
        StructureConstPtr s2 = static_pointer_cast<const StructureArray>(f1)->getStructure();
        
        testOk1(s2.get() != 0);
        testOk1(NESTED_ID == s2->getID());
        testOk1(2 == s2->getFields().size());
        
        FieldConstPtr f20 = s2->getField(0);
        testOk1(scalar == f20->getType());
        testOk1("short" == s2->getFieldName(0));
        testOk(pvShort == static_pointer_cast<const Scalar>(f20)->getScalarType(), "f20 scalar type == short");
    
        FieldConstPtr f21 = s2->getField(1);
        testOk1(scalar == f21->getType());
        testOk1("long" == s2->getFieldName(1));
        testOk(pvLong == static_pointer_cast<const Scalar>(f21)->getScalarType(), "f21 element type == long");
        
    }

    FieldConstPtr f2 = s->getField(2);
    testOk1(scalarArray == f2->getType());
    testOk1("intArray" == s->getFieldName(2));
    testOk(pvInt == static_pointer_cast<const ScalarArray>(f2)->getElementType(), "f2 element type == int");

}	
예제 #6
0
RPCService::shared_pointer  ExampleHelloRPC::create()
{
    FieldCreatePtr fieldCreate = getFieldCreate();
    PVDataCreatePtr pvDataCreate = getPVDataCreate();
    StructureConstPtr  topStructure = fieldCreate->createFieldBuilder()->
        add("value",pvString)->
        createStructure();
    PVStructurePtr pvStructure = pvDataCreate->createPVStructure(topStructure);
    ExampleHelloRPCPtr hello(
        new ExampleHelloRPC(pvStructure));
    return hello;
}
static void createVariantUnionRecord(
    PVDatabasePtr const &master,
    string const &recordName)
{
    StructureConstPtr top = fieldCreate->createFieldBuilder()->
         add("value",fieldCreate->createVariantUnion())->
         createStructure();
    PVStructurePtr pvStructure = pvDataCreate->createPVStructure(top);
    PVRecordPtr pvRecord = PVRecord::create(recordName,pvStructure);
    bool result = master->addRecord(pvRecord);
    if(!result) cout<< "record " << recordName << " not added" << endl;
}
예제 #8
0
void test_structure()
{
    testDiag("Test test_structure()");

    FieldCreatePtr fieldCreate = getFieldCreate();
    FieldBuilderPtr fb = fieldCreate->createFieldBuilder();
    
    // test with simple (non-nested) structure
    string ID = "testStructureID";
    StructureConstPtr s = fb->setId(ID)->
                         add("double", pvDouble)->
                         addArray("intArray", pvInt)->
                         createStructure();
    testOk1(s.get() != 0);
    testOk1(ID == s->getID());
    testOk1(2 == s->getFields().size());
    
    FieldConstPtr f0 = s->getField(0);
    testOk1(scalar == f0->getType());
    testOk1("double" == s->getFieldName(0));
    testOk(pvDouble == static_pointer_cast<const Scalar>(f0)->getScalarType(), "f0 scalar type == double");

    FieldConstPtr f1 = s->getField(1);
    testOk1(scalarArray == f1->getType());
    testOk1("intArray" == s->getFieldName(1));
    testOk(pvInt == static_pointer_cast<const ScalarArray>(f1)->getElementType(), "f1 element type == int");
    
    // test reuse with empty structure
    StructureConstPtr emptyStructure = fb->createStructure();
    testOk1(emptyStructure.get() != 0);
    testOk1(Structure::DEFAULT_ID == emptyStructure->getID());
    testOk1(0 == emptyStructure->getFields().size());
    
    // test add/addArray with Field
    StructureConstPtr s2 = fb->add("s", s)->
                            addArray("sArray", s)->
                            createStructure();
    testOk1(s2.get()!=0);
    testOk1(Structure::DEFAULT_ID == s2->getID());
    testOk1(2 == s2->getFields().size());

    f0 = s2->getField(0);
    testOk1(structure == f0->getType());
    testOk1("s" == s2->getFieldName(0));
    testOk1(s.get() == f0.get());

    f1 = s2->getField(1);
    testOk1(structureArray == f1->getType());
    testOk1("sArray" == s2->getFieldName(1));
    testOk(s.get() == static_pointer_cast<const StructureArray>(f1)->getStructure().get(), "array element is given structure");
}
예제 #9
0
void test_arraySizeTypes()
{
    testDiag("Test test_arraySizeTypes()");

    FieldCreatePtr fieldCreate = getFieldCreate();

    StructureConstPtr s = fieldCreate->createFieldBuilder()->
                            addArray("variableArray", pvDouble)->
                            addFixedArray("fixedArray", pvDouble, 10)->
                            addBoundedArray("boundedArray", pvDouble, 1024)->
                            createStructure();
    testOk1(s.get() != 0);
    testOk1(Structure::DEFAULT_ID == s->getID());
    testOk1(3 == s->getFields().size());
}
static void createRegularUnionArrayRecord(
    PVDatabasePtr const &master,
    string const &recordName)
{
    StructureConstPtr top = fieldCreate->createFieldBuilder()->
         addNestedUnionArray("value")->
             add("string",pvString)->
             addArray("stringArray",pvString)->
             endNested()->
         createStructure();
    PVStructurePtr pvStructure = pvDataCreate->createPVStructure(top);
    PVRecordPtr pvRecord = PVRecord::create(recordName,pvStructure);
    bool result = master->addRecord(pvRecord);
    if(!result) cout<< "record " << recordName << " not added" << endl;
}
예제 #11
0
static void testPostPut()
{
    testDiag("== testPostPut ==");
    StructureConstPtr structure =
       fieldCreate->createFieldBuilder()->
            add("alarm",standardField->alarm()) ->
            add("timeStamp",standardField->timeStamp()) ->
            addNestedStructure("power") ->
               add("value",pvDouble) ->
               add("alarm",standardField->alarm()) ->
               endNested()->
            addNestedStructure("voltage") ->
               add("value",pvDouble) ->
               add("alarm",standardField->alarm()) ->
               endNested()->
            addNestedStructure("current") ->
               add("value",pvDouble) ->
               add("alarm",standardField->alarm()) ->
               endNested()->
            createStructure();

    PvaClientPutDataPtr pvaData = PvaClientPutData::create(structure);
    PVStructurePtr pvStructure = pvaData->getPVStructure();

    BitSetPtr change = pvaData->getChangedBitSet();
    PVDoublePtr powerValue = pvStructure->getSubField<PVDouble>("power.value");
    PVDoublePtr voltageValue = pvStructure->getSubField<PVDouble>("voltage.value");
    PVDoublePtr currentValue = pvStructure->getSubField<PVDouble>("current.value");
    size_t powerOffset = powerValue->getFieldOffset();
    size_t voltageOffset = voltageValue->getFieldOffset();
    size_t currentOffset = currentValue->getFieldOffset();

    change->clear();
    powerValue->put(1.0);
    voltageValue->put(2.0);
    currentValue->put(.5);

    testOk(change->cardinality()==3,"3 fields changed");
    testOk(change->get(powerOffset),"power changed");
    testOk(change->get(voltageOffset),"voltage changed");
    testOk(change->get(currentOffset),"current changed");
}
예제 #12
0
RecordListRecordPtr RecordListRecord::create(
    std::string const & recordName)
{
    FieldCreatePtr fieldCreate = getFieldCreate();
    PVDataCreatePtr pvDataCreate = getPVDataCreate();
    StructureConstPtr  topStructure = fieldCreate->createFieldBuilder()->
        addNestedStructure("argument")->
            add("database",pvString)->
            add("regularExpression",pvString)->
            endNested()->
        addNestedStructure("result") ->
            add("status",pvString) ->
            addArray("names",pvString) ->
            endNested()->
        createStructure();
    PVStructurePtr pvStructure = pvDataCreate->createPVStructure(topStructure);
    RecordListRecordPtr pvRecord(
        new RecordListRecord(recordName,pvStructure));
    if(!pvRecord->init()) pvRecord.reset();
    return pvRecord;
}
예제 #13
0
ExampleHelloPtr ExampleHello::create(
    string const & recordName)
{
    StandardFieldPtr standardField = getStandardField();
    FieldCreatePtr fieldCreate = getFieldCreate();
    PVDataCreatePtr pvDataCreate = getPVDataCreate();
    StructureConstPtr  topStructure = fieldCreate->createFieldBuilder()->
        addNestedStructure("argument")->
            add("value",pvString)->
            endNested()->
        addNestedStructure("result") ->
            add("value",pvString) ->
            add("timeStamp",standardField->timeStamp()) ->
            endNested()->
        createStructure();
    PVStructurePtr pvStructure = pvDataCreate->createPVStructure(topStructure);

    ExampleHelloPtr pvRecord(
        new ExampleHello(recordName,pvStructure));
    if(!pvRecord->init()) pvRecord.reset();
    return pvRecord;
}
예제 #14
0
PVStructurePtr createPowerSupply()
{
    FieldCreatePtr fieldCreate = getFieldCreate();
    StandardFieldPtr standardField = getStandardField();
    PVDataCreatePtr pvDataCreate = getPVDataCreate();

    return pvDataCreate->createPVStructure(
        fieldCreate->createFieldBuilder()->
            add("alarm",standardField->alarm()) ->
            add("timeStamp",standardField->timeStamp()) ->
            addNestedStructure("power") ->
               add("value",pvDouble) ->
               add("alarm",standardField->alarm()) ->
               endNested()->
            addNestedStructure("voltage") ->
               add("value",pvDouble) ->
               add("alarm",standardField->alarm()) ->
               endNested()->
            addNestedStructure("current") ->
               add("value",pvDouble) ->
               add("alarm",standardField->alarm()) ->
               endNested()->
            createStructure());
}
static void test()
{
    NTMultiChannelBuilderPtr builder = NTMultiChannel::createBuilder();
    testOk(builder.get() != 0, "Got builder");

    NTMultiChannelPtr multiChannel = builder->
            addDescriptor()->
            addAlarm()->
            addTimeStamp()->
            addSeverity() ->
            add("extra1",fieldCreate->createScalar(pvString)) ->
            add("extra2",fieldCreate->createScalarArray(pvString)) ->
            create();
    testOk1(multiChannel.get() != 0);

    PVStructurePtr pvStructure = multiChannel->getPVStructure();
    testOk1(pvStructure.get()!=NULL);
    testOk1(NTMultiChannel::is_a(pvStructure->getStructure()));
    size_t nchan = 3;
    shared_vector<string> names(nchan);
    names[0] = "channel 0";
    names[1] = "channel 1";
    names[2] = "channel 2";
    shared_vector<const string> channelNames(freeze(names));
    PVStringArrayPtr pvChannelName = multiChannel->getChannelName();
    pvChannelName->replace(channelNames);
    if(debug) {cout << *pvStructure << endl;}
    UnionConstPtr unionPtr =
       fieldCreate->createFieldBuilder()->
           add("doubleValue", pvDouble)->
           add("intValue", pvInt)->
           createUnion();
    multiChannel = builder->
            value(unionPtr) ->
            addDescriptor()->
            addAlarm()->
            addTimeStamp()->
            addSeverity() ->
            addIsConnected() ->
            create();
    testOk1(multiChannel.get() != 0);
    pvStructure = multiChannel->getPVStructure();
    if(debug) {cout << *pvStructure << endl;}
    pvChannelName = multiChannel->getChannelName();
    pvChannelName->replace(channelNames);
    PVUnionArrayPtr pvValue = multiChannel->getValue();
    shared_vector<PVUnionPtr> unions(nchan);
    unions[0] = pvDataCreate->createPVUnion(unionPtr);
    unions[1] = pvDataCreate->createPVUnion(unionPtr);
    unions[2] = pvDataCreate->createPVUnion(unionPtr);
    unions[0]->select("doubleValue");
    unions[1]->select("intValue");
    unions[2]->select("intValue");
    PVDoublePtr pvDouble = unions[0]->get<PVDouble>();
    pvDouble->put(1.235);
    PVIntPtr pvInt = unions[1]->get<PVInt>();
    pvInt->put(5);
    pvInt = unions[2]->get<PVInt>();
    pvInt->put(7);
    pvValue->replace(freeze(unions));
    shared_vector<int32> severities(nchan);
    severities[0] = 0;
    severities[1] = 1;
    severities[2] = 2;
    PVIntArrayPtr pvSeverity = multiChannel->getSeverity();
    pvSeverity->replace(freeze(severities));
    if(debug) {cout << *pvStructure << endl;}
    PVBooleanArrayPtr pvIsConnected = multiChannel->getIsConnected();
    shared_vector<const epics::pvData::boolean> isConnected = pvIsConnected->view();
    multiChannel = builder->
            value(unionPtr) ->
            addDescriptor()->
            addAlarm()->
            addTimeStamp()->
            addSeverity() ->
            addStatus() ->
            addMessage() ->
            addSecondsPastEpoch() ->
            addNanoseconds() ->
            addUserTag() ->
            addIsConnected() ->
            create();
    testOk1(multiChannel.get() != 0);
    pvStructure = multiChannel->getPVStructure();
    if(debug) {cout << *pvStructure << endl;}
    testOk1(NTMultiChannel::isCompatible(pvStructure)==true);
    PVStructurePtr pvTimeStamp = multiChannel->getTimeStamp();
    testOk1(pvTimeStamp.get() !=0);
    PVStructurePtr pvAlarm = multiChannel->getAlarm();
    testOk1(pvAlarm.get() !=0);
    pvValue = multiChannel->getValue();
    testOk1(pvValue.get() !=0);
    pvChannelName = multiChannel->getChannelName();
    testOk1(pvChannelName.get() !=0);
    pvIsConnected = multiChannel->getIsConnected();
    testOk1(pvIsConnected.get() !=0);
    pvSeverity = multiChannel->getSeverity();
    testOk1(pvSeverity.get() !=0);
    PVIntArrayPtr pvStatus = multiChannel->getStatus();
    testOk1(pvStatus.get() !=0);
    PVStringArrayPtr pvMessage = multiChannel->getMessage();
    testOk1(pvMessage.get() !=0);
    PVLongArrayPtr pvSecondsPastEpoch = multiChannel->getSecondsPastEpoch();
    testOk1(pvSecondsPastEpoch.get() !=0);
    PVIntArrayPtr pvNanoseconds = multiChannel->getNanoseconds();
    testOk1(pvNanoseconds.get() !=0);
    PVIntArrayPtr pvUserTag = multiChannel->getUserTag();
    testOk1(pvUserTag.get() !=0);
    PVStringPtr pvDescriptor = multiChannel->getDescriptor();
    testOk1(pvDescriptor.get() !=0);
}
예제 #16
0
static void testDouble()
{
    testDiag("== testDouble ==");
    StructureConstPtr structure =
        fieldCreate->createFieldBuilder() ->
            add("alarm",standardField->alarm()) ->
            add("timeStamp",standardField->timeStamp()) ->
            add("value",pvDouble) ->
            createStructure();

    PvaClientPutDataPtr pvaData = PvaClientPutData::create(structure);
    PVDoublePtr pvDouble = pvaData->getPVStructure() ->
        getSubField<PVDouble>("value");
    pvDouble->put(5.0);

    BitSetPtr change = pvaData->getChangedBitSet();
    size_t valueOffset = pvDouble->getFieldOffset();
    testOk(change->cardinality()==1,"1 field changed");
    testOk(change->get(valueOffset),"value changed");

    testOk(pvaData->hasValue(),"hasValue");
    testOk(pvaData->isValueScalar(),"isValueScalar");
    testOk(!pvaData->isValueScalarArray(),"!isValueScalarArray");

    try {
        testOk(!!pvaData->getValue(), "getValue");
    } catch (std::runtime_error e) {
        testFail("getValue exception '%s'", e.what());
    }

    try {
        testOk(!!pvaData->getScalarValue(), "getScalarValue");
    } catch (std::runtime_error e) {
        testFail("getScalarValue exception '%s'", e.what());
    }
    try {
        testOk(!pvaData->getArrayValue(), "!getArrayValue");
    } catch (std::runtime_error e) {
        testPass("getArrayValue exception '%s'", e.what());
    }
    try {
        testOk(!pvaData->getScalarArrayValue(), "!getScalarArrayValue");
    } catch (std::runtime_error e) {
        testPass("getScalarArrayValue exception '%s'", e.what());
    }

    try {
        testOk(pvaData->getDouble() == 5.0, "getDouble value");
    } catch (std::runtime_error e) {
        testFail("getDouble exception '%s'", e.what());
    }
    try {
        testOk(pvaData->getString() == "5", "getString value");
    } catch (std::runtime_error e) {
        testFail("getString exception '%s'", e.what());
    }

    try {
        shared_vector<const double> value = pvaData->getDoubleArray();
        testFail("getDoubleArray");
    } catch (std::runtime_error e) {
        testPass("getDoubleArray exception '%s'", e.what());
    }
    try {
        shared_vector<const string> value = pvaData->getStringArray();
        testFail("getStringArray");
    } catch (std::runtime_error e) {
        testPass("getStringArray exception '%s'", e.what());
    }

    try {
        pvaData->putDouble(5.0);
        testPass("putDouble");
    } catch (std::runtime_error e) {
        testFail("putDouble exception '%s'", e.what());
    }
    try {
        pvaData->putString("1e5");
        testPass("putString");
    } catch (std::runtime_error e) {
        testFail("putString exception '%s'", e.what());
    }

    try {
        size_t len = 2;
        shared_vector<double> val(len);
        for (size_t i=0; i<len; ++i)
            val[i] = (i+1) * 10.0;
        pvaData->putDoubleArray(freeze(val));
        testFail("putDoubleArray");
    } catch (std::runtime_error e) {
        testPass("putDoubleArray exception '%s'", e.what());
    }
    try {
        size_t len = 2;
        shared_vector<string> val(len);
        val[0] = "one"; val[1] = "two";
        pvaData->putStringArray(freeze(val));
        testFail("putStringArray");
    } catch (std::runtime_error e) {
        testPass("putStringArray exception '%s'", e.what());
    }
}
예제 #17
0
StructureConstPtr NTNDArrayBuilder::createStructure()
{
    enum
    {
        DISCRIPTOR_INDEX,
        TIMESTAMP_INDEX,
        ALARM_INDEX,
        DISPLAY_INDEX
    };

    const size_t NUMBER_OF_INDICES = DISPLAY_INDEX+1;
    const size_t NUMBER_OF_STRUCTURES = 1 << NUMBER_OF_INDICES;

    Lock xx(mutex);

    static StructureConstPtr ntndarrayStruc[NUMBER_OF_STRUCTURES];
    static UnionConstPtr valueType;
    static StructureConstPtr codecStruc;
    static StructureConstPtr dimensionStruc;
    static StructureConstPtr attributeStruc;

    StructureConstPtr returnedStruc;

    size_t index = 0;
    if (descriptor) index  |= 1 << DISCRIPTOR_INDEX;
    if (timeStamp)  index  |= 1 << TIMESTAMP_INDEX;
    if (alarm)      index  |= 1 << ALARM_INDEX;
    if (display)    index  |= 1 << DISPLAY_INDEX;

    bool isExtended = !extraFieldNames.empty();

    if (isExtended || !ntndarrayStruc[index])
    {
        StandardFieldPtr standardField = getStandardField();
        FieldBuilderPtr fb = fieldCreate->createFieldBuilder();

        if (!valueType)
        {
            for (int i = pvBoolean; i < pvString; ++i)
            {
                ScalarType st = static_cast<ScalarType>(i);
                fb->addArray(std::string(ScalarTypeFunc::name(st)) + "Value", st);
            }
            valueType = fb->createUnion();                
        }

        if (!codecStruc)
        {
            codecStruc = fb->setId("codec_t")->
                add("name", pvString)->
                add("parameters", fieldCreate->createVariantUnion())->
                createStructure();
        }

        if (!dimensionStruc)
        {
            dimensionStruc = fb->setId("dimension_t")->
                add("size", pvInt)->
                add("offset",  pvInt)->
                add("fullSize",  pvInt)->
                add("binning",  pvInt)->
                add("reverse",  pvBoolean)->
                createStructure();
        }

        if (!attributeStruc)
        {
            attributeStruc = NTNDArrayAttribute::createBuilder()->createStructure();
        }

        fb->setId(NTNDArray::URI)->
            add("value", valueType)->
            add("codec", codecStruc)->
            add("compressedSize", pvLong)->
            add("uncompressedSize", pvLong)->
            addArray("dimension", dimensionStruc)->
            add("uniqueId", pvInt)->
            add("dataTimeStamp", standardField->timeStamp())->
            addArray("attribute", attributeStruc);

        if (descriptor)
            fb->add("descriptor", pvString);

        if (alarm)
            fb->add("alarm", standardField->alarm());

        if (timeStamp)
            fb->add("timeStamp", standardField->timeStamp());

        if (display)
            fb->add("display", standardField->display());

        size_t extraCount = extraFieldNames.size();
        for (size_t i = 0; i< extraCount; i++)
            fb->add(extraFieldNames[i], extraFields[i]);

        returnedStruc = fb->createStructure();

        if (!isExtended)
            ntndarrayStruc[index] = returnedStruc; 
    }
    else
    {
        return ntndarrayStruc[index];
    }

    return returnedStruc;
}
예제 #18
0
static void testFieldAccess()
{
    testDiag("Check methods for accessing structure fields");

    StructureConstPtr tdef = fieldCreate->createFieldBuilder()->
            add("test", pvInt)->
            addNestedStructure("hello")->
              add("world", pvInt)->
            endNested()->
            createStructure();

    PVStructurePtr fld = pvDataCreate->createPVStructure(tdef);

    PVIntPtr a = fld->getSubField<PVInt>("test");
    testOk1(a.get() != NULL);
    if(a.get()) {
        PVIntPtr b = fld->getSubFieldT<PVInt>("test");
        testOk(b.get()==a.get(), "%p == %p", b.get(), a.get());
    } else
        testSkip(1, "test doesn't exist?");

    a = fld->getSubField<PVInt>("hello.world");
    testOk1(a.get() != NULL);
    if(a.get()) {
        PVIntPtr b = fld->getSubFieldT<PVInt>("hello.world");
        testOk(b.get()==a.get(), "%p == %p", b.get(), a.get());
    } else
        testSkip(1, "hello.world doesn't exist?");

    // non-existent
    testOk1(fld->getSubField<PVInt>("invalid").get()==NULL);

    // wrong type
    testOk1(fld->getSubField<PVDouble>("test").get()==NULL);

    // intermediate struct non-existent
    testOk1(fld->getSubField<PVDouble>("helo.world").get()==NULL);

    // empty leaf field name
    testOk1(fld->getSubField<PVDouble>("hello.").get()==NULL);

    // empty field name
    testOk1(fld->getSubField<PVDouble>("hello..world").get()==NULL);
    testOk1(fld->getSubField<PVDouble>(".").get()==NULL);

    // whitespace
    testOk1(fld->getSubField<PVInt>(" test").get()==NULL);

    // intermediate field not structure
    testOk1(fld->getSubField<PVInt>("hello.world.invalid").get()==NULL);

    // null string
    try{
        char * name = NULL;
        fld->getSubFieldT<PVInt>(name);
        testFail("missing required exception");
    }catch(std::invalid_argument& e){
        testPass("caught expected exception: %s", e.what());
    }

    // non-existent
    try{
        fld->getSubFieldT<PVInt>("invalid");
        testFail("missing required exception");
    }catch(std::runtime_error& e){
        testPass("caught expected exception: %s", e.what());
    }

    // wrong type
    try{
        fld->getSubFieldT<PVDouble>("test");
        testFail("missing required exception");
    }catch(std::runtime_error& e){
        testPass("caught expected exception: %s", e.what());
    }

    // empty leaf field name
    try{
        fld->getSubFieldT<PVDouble>("hello.");
        testFail("missing required exception");
    }catch(std::runtime_error& e){
        testPass("caught expected exception: %s", e.what());
    }

    // empty field name
    try{
        fld->getSubFieldT<PVDouble>("hello..world");
        testFail("missing required exception");
    }catch(std::runtime_error& e){
        testPass("caught expected exception: %s", e.what());
    }
    try{
        fld->getSubFieldT<PVDouble>(".");
        testFail("missing required exception");
    }catch(std::runtime_error& e){
        testPass("caught expected exception: %s", e.what());
    }

    // whitespace
    try{
        fld->getSubFieldT<PVDouble>(" test");
        testFail("missing required exception");
    }catch(std::runtime_error& e){
        testPass("caught expected exception: %s", e.what());
    }

    // intermediate field not structure
    try{
        fld->getSubFieldT<PVDouble>("hello.world.invalid");
        testFail("missing required exception");
    }catch(std::runtime_error& e){
        testPass("caught expected exception: %s", e.what());
    }
}
예제 #19
0
static void testCopy()
{
    TEST_COPY(PVBoolean, 1);
    TEST_COPY(PVByte, 12);
    TEST_COPY(PVShort, 128);
    TEST_COPY(PVInt, 128000);
    TEST_COPY(PVLong, 128000000);
    TEST_COPY(PVUByte, 12);
    TEST_COPY(PVUShort, 128);
    TEST_COPY(PVUInt, 128000);
    TEST_COPY(PVULong, 128000000);
    TEST_COPY(PVFloat, 12.8);
    TEST_COPY(PVDouble, 8.12);
    TEST_COPY(PVString, "jikes");

    int32 testValue = 128;

    // PVStructure test
    PVStructurePtr pvStructure =
            standardPVField->scalar(pvInt, alarmTimeStampValueAlarm);
    pvStructure->getSubField<PVInt>("value")->put(testValue);

    PVTimeStamp timeStamp;
    timeStamp.attach(pvStructure->getSubField<PVStructure>("timeStamp"));
    TimeStamp current;
    current.getCurrent();
    timeStamp.set(current);

    PVStructurePtr pvStructureCopy =
            standardPVField->scalar(pvInt, alarmTimeStampValueAlarm);
    pvStructureCopy->copy(*pvStructure);
    testOk(*pvStructure == *pvStructureCopy, "PVStructure copy");


    PVStructurePtr pvStructureCopy2 =
            standardPVField->scalar(pvInt, alarmTimeStampValueAlarm);
    pvStructureCopy2->copyUnchecked(*pvStructure);
    testOk(*pvStructure == *pvStructureCopy2, "PVStructure copyUnchecked");

    BitSet mask(pvStructure->getNumberFields());
    PVStructurePtr pvStructureCopy3 =
            standardPVField->scalar(pvInt, alarmTimeStampValueAlarm);
    PVStructurePtr pvStructureCopy4 =
            standardPVField->scalar(pvInt, alarmTimeStampValueAlarm);
    pvStructureCopy3->copyUnchecked(*pvStructure, mask);
    testOk(*pvStructureCopy3 == *pvStructureCopy4, "PVStructure copyUnchecked w/ cleared mask");

    mask.set(pvStructure->getSubField<PVInt>("value")->getFieldOffset());
    pvStructureCopy3->copyUnchecked(*pvStructure, mask);
    pvStructureCopy4->getSubField<PVInt>("value")->put(testValue);
    testOk(*pvStructureCopy3 == *pvStructureCopy4, "PVStructure copyUnchecked w/ value mask only");

    mask.set(pvStructure->getSubField<PVStructure>("timeStamp")->getFieldOffset());
    PVStructurePtr pvStructureCopy5 =
            standardPVField->scalar(pvInt, alarmTimeStampValueAlarm);
    pvStructureCopy5->copyUnchecked(*pvStructure, mask);
    testOk(*pvStructure == *pvStructureCopy5, "PVStructure copyUnchecked w/ value+timeStamp mask");


    UnionConstPtr _union = fieldCreate->createFieldBuilder()->
        add("doubleValue", pvDouble)->
        add("intValue", pvInt)->
        add("timeStamp",standardField->timeStamp())->
        createUnion();

    PVUnionPtr pvUnion = pvDataCreate->createPVUnion(_union);
    PVUnionPtr pvUnion2 = pvDataCreate->createPVUnion(_union);
    pvUnion2->copy(*pvUnion);
    testOk(*pvUnion == *pvUnion2, "null PVUnion copy");

    pvUnion->select<PVInt>("intValue")->put(123);
    pvUnion2->copy(*pvUnion);
    testOk(*pvUnion == *pvUnion2, "PVUnion scalar copy, to null PVUnion");

    pvUnion->select("doubleValue");
    pvUnion2->copy(*pvUnion);
    testOk(*pvUnion == *pvUnion2, "PVUnion scalar copy, to different type PVUnion");

    pvUnion->select<PVStructure>("timeStamp")->copy(
        *pvStructure->getSubField<PVStructure>("timeStamp")
    );
    pvUnion2->copy(*pvUnion);
    testOk(*pvUnion == *pvUnion2, "PVUnion PVStructure copy, to different type PVUnion");
}