void test_ntscalarArray()
{
    testDiag("test_ntscalarArray");

    NTScalarArrayBuilderPtr builder = NTScalarArray::createBuilder();
    testOk(builder.get() != 0, "Got builder");

    NTScalarArrayPtr ntScalarArray = builder->
            value(pvInt)->
            addDescriptor()->
            addAlarm()->
            addTimeStamp()->
            addDisplay()->
            addControl()->
            create();
    testOk1(ntScalarArray.get() != 0);

    testOk1(ntScalarArray->getPVStructure().get() != 0);
    testOk1(ntScalarArray->getValue().get() != 0);
    testOk1(ntScalarArray->getDescriptor().get() != 0);
    testOk1(ntScalarArray->getAlarm().get() != 0);
    testOk1(ntScalarArray->getTimeStamp().get() != 0);
    testOk1(ntScalarArray->getDisplay().get() != 0);
    testOk1(ntScalarArray->getControl().get() != 0);

    //
    // example how to set values
    //
    PVIntArray::svector newValues;
    newValues.push_back(1);
    newValues.push_back(2);
    newValues.push_back(8);

    PVIntArrayPtr pvValueField = ntScalarArray->getValue<PVIntArray>();
    pvValueField->replace(freeze(newValues));

    //
    // example how to get values
    //
    PVIntArray::const_svector values(pvValueField->view());

    testOk1(values.size() == 3);
    testOk1(values[0] == 1);
    testOk1(values[1] == 2);
    testOk1(values[2] == 8);

    //
    // timeStamp ops
    //
    PVTimeStamp pvTimeStamp;
    if (ntScalarArray->attachTimeStamp(pvTimeStamp))
    {
        testPass("timeStamp attach");

        // example how to set current time
        TimeStamp ts;
        ts.getCurrent();
        pvTimeStamp.set(ts);

        // example how to get EPICS time
        TimeStamp ts2;
        pvTimeStamp.get(ts2);
        testOk1(ts2.getEpicsSecondsPastEpoch() != 0);
    }
    else
        testFail("timeStamp attach fail");

    //
    // alarm ops
    //
    PVAlarm pvAlarm;
    if (ntScalarArray->attachAlarm(pvAlarm))
    {
        testPass("alarm attach");

        // example how to set an alarm
        Alarm alarm;
        alarm.setStatus(deviceStatus);
        alarm.setSeverity(minorAlarm);
        alarm.setMessage("simulation alarm");
        pvAlarm.set(alarm);
    }
    else
        testFail("alarm attach fail");

    //
    // display ops
    //
    PVDisplay pvDisplay;
    if (ntScalarArray->attachDisplay(pvDisplay))
    {
        testPass("display attach");

        // example how to set an display
        Display display;
        display.setLow(-15);
        display.setHigh(15);
        display.setDescription("This is a test scalar array");
        display.setFormat("%d");
        display.setUnits("A");
        pvDisplay.set(display);
    }
    else
        testFail("display attach fail");

    //
    // control ops
    //
    PVControl pvControl;
    if (ntScalarArray->attachControl(pvControl))
    {
        testPass("control attach");

        // example how to set an control
        Control control;
        control.setLow(-10);
        control.setHigh(10);
        control.setMinStep(1);
        pvControl.set(control);
    }
    else
        testFail("control attach fail");

    //
    // set descriptor
    //
    ntScalarArray->getDescriptor()->put("This is a test NTScalarArray");

    // dump ntScalarArray
    std::cout << *ntScalarArray->getPVStructure() << std::endl;

}
void test_nthistogram()
{
    testDiag("test_nthistogram");

    NTHistogramBuilderPtr builder = NTHistogram::createBuilder();
    testOk(builder.get() != 0, "Got builder");

    NTHistogramPtr ntHistogram = builder->
            value(pvInt)->
            addDescriptor()->
            addAlarm()->
            addTimeStamp()->
            add("extra1",fieldCreate->createScalar(pvString)) ->
            add("extra2",fieldCreate->createScalarArray(pvString)) ->
            create();
    testOk1(ntHistogram.get() != 0);

    testOk1(ntHistogram->getPVStructure().get() != 0);
    testOk1(ntHistogram->getDescriptor().get() != 0);
    testOk1(ntHistogram->getAlarm().get() != 0);
    testOk1(ntHistogram->getTimeStamp().get() != 0);
    testOk1(ntHistogram->getRanges().get() != 0);
    testOk1(ntHistogram->getValue().get() != 0);
    testOk1(ntHistogram->getValue<PVIntArray>().get() != 0);
    //
    // example how to set ranges
    //
    PVDoubleArray::svector newRanges;
    newRanges.push_back(-100.0);
    newRanges.push_back(0.0);
    newRanges.push_back(100.0);

    PVDoubleArrayPtr pvRangesField = ntHistogram->getRanges();
    pvRangesField->replace(freeze(newRanges));

    //
    // example how to get ranges
    //
    PVDoubleArray::const_svector ranges(pvRangesField->view());

    testOk1(ranges.size() == 3);
    testOk1(ranges[0] == -100.0);
    testOk1(ranges[1] == 0.0);
    testOk1(ranges[2] == 100.0);

    //
    // example how to set value
    //
    PVIntArray::svector newValue;
    newValue.push_back(1);
    newValue.push_back(2);

    PVIntArrayPtr pvValueField = ntHistogram->getValue<PVIntArray>();
    pvValueField->replace(freeze(newValue));

    //
    // example how to get values for each bin
    //
    PVIntArray::const_svector value(pvValueField->view());

    testOk1(value.size() == 2);
    testOk1(value[0] == 1);
    testOk1(value[1] == 2);

    //
    // test isValid
    //
    testOk1(ntHistogram->isValid());
    //
    // timeStamp ops
    //
    PVTimeStamp pvTimeStamp;
    if (ntHistogram->attachTimeStamp(pvTimeStamp))
    {
        testPass("timeStamp attach");

        // example how to set current time
        TimeStamp ts;
        ts.getCurrent();
        pvTimeStamp.set(ts);

        // example how to get EPICS time
        TimeStamp ts2;
        pvTimeStamp.get(ts2);
        testOk1(ts2.getEpicsSecondsPastEpoch() != 0);
    }
    else
        testFail("timeStamp attach fail");

    //
    // alarm ops
    //
    PVAlarm pvAlarm;
    if (ntHistogram->attachAlarm(pvAlarm))
    {
        testPass("alarm attach");

        // example how to set an alarm
        Alarm alarm;
        alarm.setStatus(deviceStatus);
        alarm.setSeverity(minorAlarm);
        alarm.setMessage("simulation alarm");
        pvAlarm.set(alarm);
    }
    else
        testFail("alarm attach fail");

    //
    // set descriptor
    //
    ntHistogram->getDescriptor()->put("This is a test NTHistogram");

    // dump NTHistogram
    std::cout << *ntHistogram->getPVStructure() << std::endl;

}
Пример #3
0
void test_nttable()
{
    testDiag("test_nttable");

    NTTableBuilderPtr builder = NTTable::createBuilder();
    testOk(builder.get() != 0, "Got builder");

    NTTablePtr ntTable = builder->
            addColumn("column0", pvDouble)->
            addColumn("column1", pvString)->
            addColumn("column2", pvInt)->
            addDescriptor()->
            addAlarm()->
            addTimeStamp()->
            create();
    testOk1(ntTable.get() != 0);

    testOk1(ntTable->getPVStructure().get() != 0);
    testOk1(ntTable->getDescriptor().get() != 0);
    testOk1(ntTable->getAlarm().get() != 0);
    testOk1(ntTable->getTimeStamp().get() != 0);
    testOk1(ntTable->getLabels().get() != 0);

    testOk1(ntTable->getColumn<PVDoubleArray>("column0").get() != 0);
    testOk1(ntTable->getColumn<PVStringArray>("column1").get() != 0);
    testOk1(ntTable->getColumn<PVIntArray>("column2").get() != 0);

    testOk1(ntTable->getColumn("invalid").get() == 0);

    //
    // example how to set column values
    //
    PVIntArray::svector newValues;
    newValues.push_back(1);
    newValues.push_back(2);
    newValues.push_back(8);

    PVIntArrayPtr intColumn = ntTable->getColumn<PVIntArray>("column2");
    intColumn->replace(freeze(newValues));

    //
    // example how to get column values
    //
    PVIntArray::const_svector values(intColumn->view());

    testOk1(values.size() == 3);
    testOk1(values[0] == 1);
    testOk1(values[1] == 2);
    testOk1(values[2] == 8);

    //
    // timeStamp ops
    //
    PVTimeStamp pvTimeStamp;
    if (ntTable->attachTimeStamp(pvTimeStamp))
    {
        testPass("timeStamp attach");

        // example how to set current time
        TimeStamp ts;
        ts.getCurrent();
        pvTimeStamp.set(ts);

        // example how to get EPICS time
        TimeStamp ts2;
        pvTimeStamp.get(ts2);
        testOk1(ts2.getEpicsSecondsPastEpoch() != 0);
    }
    else
        testFail("timeStamp attach fail");

    //
    // alarm ops
    //
    PVAlarm pvAlarm;
    if (ntTable->attachAlarm(pvAlarm))
    {
        testPass("alarm attach");

        // example how to set an alarm
        Alarm alarm;
        alarm.setStatus(deviceStatus);
        alarm.setSeverity(minorAlarm);
        alarm.setMessage("simulation alarm");
        pvAlarm.set(alarm);
    }
    else
        testFail("alarm attach fail");

    //
    // set descriptor
    //
    ntTable->getDescriptor()->put("This is a test NTTable");

    // dump NTTable
    std::cout << *ntTable->getPVStructure() << std::endl;

}
Пример #4
0
void test_ntnameValue()
{
    testDiag("test_ntnameValue");

    NTNameValueBuilderPtr builder = NTNameValue::createBuilder();
    testOk(builder.get() != 0, "Got builder");

    NTNameValuePtr ntNameValue = builder->
            value(pvInt)->
            addDescriptor()->
            addAlarm()->
            addTimeStamp()->
            add("extra1",fieldCreate->createScalar(pvString)) ->
            add("extra2",fieldCreate->createScalarArray(pvString)) ->
            create();
    testOk1(ntNameValue.get() != 0);

    testOk1(NTNameValue::is_a(ntNameValue->getPVStructure()));
    testOk1(NTNameValue::isCompatible(ntNameValue->getPVStructure()));

    testOk1(ntNameValue->getPVStructure().get() != 0);
    testOk1(ntNameValue->getDescriptor().get() != 0);
    testOk1(ntNameValue->getAlarm().get() != 0);
    testOk1(ntNameValue->getTimeStamp().get() != 0);
    testOk1(ntNameValue->getName().get() != 0);
    testOk1(ntNameValue->getValue().get() != 0);

    //
    // example how to set name
    //
    PVStringArray::svector newName;
    newName.push_back("name1");
    newName.push_back("name2");
    newName.push_back("name3");

    PVStringArrayPtr pvNameField = ntNameValue->getName();
    pvNameField->replace(freeze(newName));

    //
    // example how to get name
    //
    PVStringArray::const_svector name(pvNameField->view());

    testOk1(name.size() == 3);
    testOk1(name[0] == "name1");
    testOk1(name[1] == "name2");
    testOk1(name[2] == "name3");

    //
    // example how to set value
    //
    PVIntArray::svector newValue;
    newValue.push_back(1);
    newValue.push_back(2);
    newValue.push_back(8);

    PVIntArrayPtr pvValueField = ntNameValue->getValue<PVIntArray>();
    pvValueField->replace(freeze(newValue));

    //
    // example how to get column value
    //
    PVIntArray::const_svector value(pvValueField->view());

    testOk1(value.size() == 3);
    testOk1(value[0] == 1);
    testOk1(value[1] == 2);
    testOk1(value[2] == 8);

    //
    // timeStamp ops
    //
    PVTimeStamp pvTimeStamp;
    if (ntNameValue->attachTimeStamp(pvTimeStamp))
    {
        testPass("timeStamp attach");

        // example how to set current time
        TimeStamp ts;
        ts.getCurrent();
        pvTimeStamp.set(ts);

        // example how to get EPICS time
        TimeStamp ts2;
        pvTimeStamp.get(ts2);
        testOk1(ts2.getEpicsSecondsPastEpoch() != 0);
    }
    else
        testFail("timeStamp attach fail");

    //
    // alarm ops
    //
    PVAlarm pvAlarm;
    if (ntNameValue->attachAlarm(pvAlarm))
    {
        testPass("alarm attach");

        // example how to set an alarm
        Alarm alarm;
        alarm.setStatus(deviceStatus);
        alarm.setSeverity(minorAlarm);
        alarm.setMessage("simulation alarm");
        pvAlarm.set(alarm);
    }
    else
        testFail("alarm attach fail");

    //
    // set descriptor
    //
    ntNameValue->getDescriptor()->put("This is a test NTNameValue");

    // dump NTNameValue
    std::cout << *ntNameValue->getPVStructure() << std::endl;

}