testIntrospection now complete

This commit is contained in:
Marty Kraimer
2010-10-28 10:08:20 -04:00
parent 55b44e953d
commit 59c2d447c1
13 changed files with 368 additions and 200 deletions

View File

@@ -53,56 +53,56 @@ PVField::~PVField()
String PVField::getRequesterName()
{
static String none("none");
if(pImpl->requester!=0) return pImpl->requester->getRequesterName();
return none;
static String none("none");
if(pImpl->requester!=0) return pImpl->requester->getRequesterName();
return none;
}
void PVField::message(String message,MessageType messageType)
{
if(pImpl->requester) {
pImpl->requester->message(message,messageType);
} else {
printf("%s %s %s\n",
messageTypeName[messageType].c_str(),
pImpl->field->getFieldName().c_str(),
message.c_str());
}
if(pImpl->requester) {
pImpl->requester->message(message,messageType);
} else {
printf("%s %s %s\n",
messageTypeName[messageType].c_str(),
pImpl->field->getFieldName().c_str(),
message.c_str());
}
}
void PVField::setRequester(Requester *prequester)
{
static String requesterPresent =
"Logic Error. requester is already present";
if(pImpl->requester==0) {
pImpl->requester = prequester;
return;
}
throw std::logic_error(requesterPresent);
static String requesterPresent =
"Logic Error. requester is already present";
if(pImpl->requester==0) {
pImpl->requester = prequester;
return;
}
throw std::logic_error(requesterPresent);
}
int PVField::getFieldOffset()
{
if(pImpl->nextFieldOffset==0) computeOffset(this);
return pImpl->fieldOffset;
if(pImpl->nextFieldOffset==0) computeOffset(this);
return pImpl->fieldOffset;
}
int PVField::getNextFieldOffset()
{
if(pImpl->nextFieldOffset==0) computeOffset(this);
return pImpl->nextFieldOffset;
if(pImpl->nextFieldOffset==0) computeOffset(this);
return pImpl->nextFieldOffset;
}
int PVField::getNumberFields()
{
if(pImpl->nextFieldOffset==0) computeOffset(this);
return (pImpl->nextFieldOffset - pImpl->fieldOffset);
if(pImpl->nextFieldOffset==0) computeOffset(this);
return (pImpl->nextFieldOffset - pImpl->fieldOffset);
}
PVAuxInfo * PVField::getPVAuxInfo(){
if(pImpl->pvAuxInfo==0) {
pImpl->pvAuxInfo = new PVAuxInfo(this);
}
return pImpl->pvAuxInfo;
if(pImpl->pvAuxInfo==0) {
pImpl->pvAuxInfo = new PVAuxInfo(this);
}
return pImpl->pvAuxInfo;
}
bool PVField::isImmutable() {return pImpl->immutable;}
@@ -198,44 +198,37 @@ void PVField::toString(StringBuilder buf,int indentLevel)
}
void PVField::computeOffset(PVField * pvField) {
PVStructure *pvTop = pvField->getParent();
Type type = pvField->getField()->getType();
if(type!=structure) {
pvField->pImpl->nextFieldOffset = 1;
return;
}
if(pvTop==0) {
pvTop = (PVStructure *)pvField;
} else {
while(pvTop->getParent()!=0) {
pvTop = pvTop->getParent();
}
}
int offset = 0;
int nextOffset = 1;
PVFieldPtrArray pvFields = pvTop->getPVFields();
for(int i=0; i < pvTop->getStructure()->getNumberFields(); i++) {
offset = nextOffset;
PVField *pvField = pvFields[i];
FieldConstPtr field = pvField->getField();
switch(field->getType()) {
case scalar:
case scalarArray:
case structureArray:{
nextOffset++;
pvField->pImpl->fieldOffset = offset;
pvField->pImpl->nextFieldOffset = nextOffset;
break;
}
case structure: {
pvField->computeOffset(pvField,offset);
nextOffset = pvField->getNextFieldOffset();
}
}
}
PVField *top = (PVField *)pvTop;
top->pImpl->fieldOffset = 0;
top->pImpl->nextFieldOffset = nextOffset;
PVStructure *pvTop = pvField->getParent();
if(pvTop==0) {
pvTop = (PVStructure *)pvField;
} else {
while(pvTop->getParent()!=0) pvTop = pvTop->getParent();
}
int offset = 0;
int nextOffset = 1;
PVFieldPtrArray pvFields = pvTop->getPVFields();
for(int i=0; i < pvTop->getStructure()->getNumberFields(); i++) {
offset = nextOffset;
PVField *pvField = pvFields[i];
FieldConstPtr field = pvField->getField();
switch(field->getType()) {
case scalar:
case scalarArray:
case structureArray:{
nextOffset++;
pvField->pImpl->fieldOffset = offset;
pvField->pImpl->nextFieldOffset = nextOffset;
break;
}
case structure: {
pvField->computeOffset(pvField,offset);
nextOffset = pvField->getNextFieldOffset();
}
}
}
PVField *top = (PVField *)pvTop;
top->pImpl->fieldOffset = 0;
top->pImpl->nextFieldOffset = nextOffset;
}
void PVField::computeOffset(PVField * pvField,int offset) {

View File

@@ -54,11 +54,8 @@ namespace epics { namespace pvData {
}
void BaseField::toString(StringBuilder buffer,int indentLevel) const{
newLine(buffer,indentLevel);
*buffer += "field ";
*buffer += " ";
*buffer += fieldName.c_str();
*buffer += " type ";
TypeFunc::toString(buffer,type);
}
Scalar::~Scalar(){}
@@ -85,9 +82,8 @@ namespace epics { namespace pvData {
void BaseScalar::toString(StringBuilder buffer,int indentLevel) const{
BaseField::toString(buffer,indentLevel);
*buffer += " scalarType ";
ScalarTypeFunc::toString(buffer,scalarType);
BaseField::toString(buffer,indentLevel);
}
ScalarArray::~ScalarArray(){}
@@ -115,9 +111,11 @@ namespace epics { namespace pvData {
void BaseScalarArray::toString(StringBuilder buffer,int indentLevel) const{
String temp = String();
ScalarTypeFunc::toString(&temp,elementType);
temp += "Array";
*buffer += temp;
BaseField::toString(buffer,indentLevel);
*buffer += " elementType ";
ScalarTypeFunc::toString(buffer,elementType);
}
Structure::~Structure(){}
@@ -196,14 +194,14 @@ namespace epics { namespace pvData {
}
void BaseStructure::toString(StringBuilder buffer,int indentLevel) const{
*buffer += "structure";
BaseField::toString(buffer,indentLevel);
*buffer += " {";
newLine(buffer,indentLevel+1);
for(int i=0; i<numberFields; i++) {
FieldConstPtr pfield = fields[i];
pfield->toString(buffer,indentLevel+1);
if(i<numberFields-1) newLine(buffer,indentLevel+1);
}
newLine(buffer,indentLevel);
*buffer += "}";
}
StructureArray::~StructureArray(){}
@@ -239,8 +237,9 @@ namespace epics { namespace pvData {
void BaseStructureArray::toString(StringBuilder buffer,int indentLevel) const {
*buffer += " structureArray ";
BaseField::toString(buffer,indentLevel);
*buffer += " structure ";
newLine(buffer,indentLevel + 1);
pstructure->toString(buffer,indentLevel + 1);
}

View File

@@ -52,14 +52,14 @@ namespace epics { namespace pvData {
void ScalarTypeFunc::toString(StringBuilder buf,const ScalarType scalarType) {
static String unknownString = "logic error unknown ScalarType";
switch(scalarType) {
case pvBoolean : *buf += "pvBoolean"; return;
case pvByte : *buf += "pvByte"; return;;
case pvShort : *buf += "pvShort"; return;
case pvInt : *buf += "pvInt"; return;
case pvLong : *buf += "pvLong"; return;
case pvFloat : *buf += "pvFloat"; return;
case pvDouble : *buf += "pvDouble"; return;
case pvString : *buf += "pvString"; return;
case pvBoolean : *buf += "boolean"; return;
case pvByte : *buf += "byte"; return;;
case pvShort : *buf += "short"; return;
case pvInt : *buf += "int"; return;
case pvLong : *buf += "long"; return;
case pvFloat : *buf += "float"; return;
case pvDouble : *buf += "double"; return;
case pvString : *buf += "string"; return;
}
throw std::invalid_argument(unknownString);
}

View File

@@ -12,23 +12,35 @@ namespace epics { namespace pvData {
StandardField();
~StandardField();
ScalarConstPtr scalar(String fieldName,ScalarType type);
StructureConstPtr scalar(String fieldName,ScalarType type,String properties);
ScalarArrayConstPtr scalarArray(String fieldName,ScalarType elementType);
StructureConstPtr scalarArray(String fieldName,ScalarType elementType, String properties);
StructureArrayConstPtr structureArray(String fieldName,StructureConstPtr structure);
StructureConstPtr structureArray(String fieldName,StructureConstPtr structure,String properties);
StructureConstPtr structure(String fieldName,int numFields,FieldConstPtrArray fields);
StructureConstPtr enumerated(String fieldName,StringArray choices);
StructureConstPtr enumerated(String fieldName,StringArray choices, String properties);
StructureConstPtr scalar(String fieldName,
ScalarType type,String properties);
ScalarArrayConstPtr scalarArray(String fieldName,
ScalarType elementType);
StructureConstPtr scalarArray(String fieldName,
ScalarType elementType, String properties);
StructureArrayConstPtr structureArray(String fieldName,
StructureConstPtr structure);
StructureConstPtr structureArray(String fieldName,
StructureConstPtr structure,String properties);
StructureConstPtr structure(String fieldName,
int numFields,FieldConstPtrArray fields);
StructureConstPtr enumerated(String fieldName,
StringArray choices);
StructureConstPtr enumerated(String fieldName,
StringArray choices, String properties);
ScalarConstPtr scalarValue(ScalarType type);
StructureConstPtr scalarValue(ScalarType type,String properties);
ScalarArrayConstPtr scalarArrayValue(ScalarType elementType);
StructureConstPtr scalarArrayValue(ScalarType elementType, String properties);
StructureConstPtr scalarArrayValue(ScalarType elementType,
String properties);
StructureArrayConstPtr structureArrayValue(StructureConstPtr structure);
StructureConstPtr structureArrayValue(StructureConstPtr structure,String properties);
StructureConstPtr structureValue(int numFields,FieldConstPtrArray fields);
StructureConstPtr structureArrayValue(StructureConstPtr structure,
String properties);
StructureConstPtr structureValue(
int numFields,FieldConstPtrArray fields);
StructureConstPtr enumeratedValue(StringArray choices);
StructureConstPtr enumeratedValue(StringArray choices, String properties);
StructureConstPtr enumeratedValue(StringArray choices,
String properties);
StructureConstPtr alarm();
StructureConstPtr timeStamp();
StructureConstPtr display();

View File

@@ -4,11 +4,11 @@ include $(TOP)/configure/CONFIG
PROD_HOST += testIntrospect
testIntrospect_SRCS += testIntrospect.cpp
testIntrospect_LIBS += pvFactory
testIntrospect_LIBS += pvFactory Com
PROD_HOST += testSimple
testSimple_SRCS += testSimple.cpp
testSimple_LIBS += pvFactory
testSimple_LIBS += pvFactory Com
include $(TOP)/configure/RULES
#----------------------------------------

View File

@@ -7,6 +7,8 @@
#include <string>
#include <cstdio>
#include <epicsAssert.h>
#include "requester.h"
#include "pvIntrospect.h"
#include "standardField.h"
@@ -15,30 +17,116 @@ using namespace epics::pvData;
static FieldCreate * fieldCreate = 0;
static StandardField *standardField = 0;
static String buffer("");
static String builder("");
static void testScalarCommon(FILE * fd,String fieldName,ScalarType stype,
bool isInteger,bool isNumeric,bool isPrimitive)
{
ScalarConstPtr boolean = standardField->scalar(fieldName,stype);
Type type = boolean->getType();
assert(type==scalar);
builder.clear();
TypeFunc::toString(&builder,type);
assert(builder.compare("scalar")==0);
ScalarType scalarType = boolean->getScalarType();
assert(scalarType==stype);
assert(ScalarTypeFunc::isInteger(scalarType)==isInteger);
assert(ScalarTypeFunc::isNumeric(scalarType)==isNumeric);
assert(ScalarTypeFunc::isPrimitive(scalarType)==isPrimitive);
builder.clear();
boolean->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
}
void testSimpleStructure(FILE * fd) {
static void testScalar(FILE * fd) {
fprintf(fd,"\ntestScalar\n");
testScalarCommon(fd,String("boolean"),pvBoolean,false,false,true);
testScalarCommon(fd,String("byte"),pvByte,true,true,true);
testScalarCommon(fd,String("short"),pvShort,true,true,true);
testScalarCommon(fd,String("int"),pvInt,true,true,true);
testScalarCommon(fd,String("long"),pvLong,true,true,true);
testScalarCommon(fd,String("float"),pvFloat,false,true,true);
testScalarCommon(fd,String("double"),pvDouble,false,true,true);
testScalarCommon(fd,String("string"),pvString,false,false,false);
}
static void testScalarArrayCommon(FILE * fd,String fieldName,ScalarType stype,
bool isInteger,bool isNumeric,bool isPrimitive)
{
ScalarArrayConstPtr boolean = standardField->scalarArray(fieldName,stype);
Type type = boolean->getType();
assert(type==scalarArray);
builder.clear();
TypeFunc::toString(&builder,type);
assert(builder.compare("scalarArray")==0);
ScalarType scalarType = boolean->getElementType();
assert(scalarType==stype);
assert(ScalarTypeFunc::isInteger(scalarType)==isInteger);
assert(ScalarTypeFunc::isNumeric(scalarType)==isNumeric);
assert(ScalarTypeFunc::isPrimitive(scalarType)==isPrimitive);
builder.clear();
boolean->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
}
static void testScalarArray(FILE * fd) {
fprintf(fd,"\ntestScalarArray\n");
testScalarArrayCommon(fd,String("boolean"),pvBoolean,false,false,true);
testScalarArrayCommon(fd,String("byte"),pvByte,true,true,true);
testScalarArrayCommon(fd,String("short"),pvShort,true,true,true);
testScalarArrayCommon(fd,String("int"),pvInt,true,true,true);
testScalarArrayCommon(fd,String("long"),pvLong,true,true,true);
testScalarArrayCommon(fd,String("float"),pvFloat,false,true,true);
testScalarArrayCommon(fd,String("double"),pvDouble,false,true,true);
testScalarArrayCommon(fd,String("string"),pvString,false,false,false);
}
static void testSimpleStructure(FILE * fd) {
fprintf(fd,"\ntestSimpleStructure\n");
String properties("alarm,timeStamp,display,control,valueAlarm");
StructureConstPtr ptop = standardField->scalarValue(pvDouble,properties);
buffer.clear();
ptop->toString(&buffer);
fprintf(fd,"%s\n",buffer.c_str());
builder.clear();
ptop->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
}
static StructureConstPtr createPowerSupply() {
String properties("alarm");
FieldConstPtr powerSupply[3];
powerSupply[0] = standardField->scalar(
String("voltage"),pvDouble,properties);
powerSupply[1] = standardField->scalar(
String("power"),pvDouble,properties);
powerSupply[2] = standardField->scalar(
String("current"),pvDouble,properties);
return standardField->structure( String("powerSupply"),3,powerSupply);
}
static void testStructureArray(FILE * fd) {
fprintf(fd,"\ntestStructureArray\n");
String properties("alarm,timeStamp");
StructureConstPtr powerSupply = createPowerSupply();
StructureConstPtr top = standardField->structureArrayValue(
powerSupply,properties);
builder.clear();
top->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
}
int main(int argc,char *argv[])
{
char *fileName = 0;
if(argc>1) fileName = argv[1];
printf("fileName %p\n",fileName);
FILE * fd = stdout;
if(fileName!=0 && fileName[0]!=0) {
fd = fopen(fileName,"w+");
}
fieldCreate = getFieldCreate();
standardField = getStandardField();
testScalar(fd);
testScalarArray(fd);
testSimpleStructure(fd);
testStructureArray(fd);
return(0);
}

View File

@@ -2,14 +2,6 @@ TOP=../..
include $(TOP)/configure/CONFIG
PROD_HOST += testIntrospect
testIntrospect_SRCS += testIntrospect.cpp
testIntrospect_LIBS += pvFactory
PROD_HOST += testIntrospectScalar
testIntrospectScalar_SRCS += testIntrospectScalar.cpp
testIntrospectScalar_LIBS += pvFactory
PROD_HOST += testPVAuxInfo
testPVAuxInfo_SRCS += testPVAuxInfo.cpp
testPVAuxInfo_LIBS += pvFactory

View File

@@ -1,62 +0,0 @@
/* testIntrospect.cpp */
/* Author: Marty Kraimer Date: 2010.09 */
#include <stddef.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include "pvIntrospect.h"
using namespace epics::pvData;
int main(int argc,char *argv[])
{
Type type = scalar;
ScalarType scalarType = pvDouble;
bool value = ScalarTypeFunc::isNumeric(scalarType);
printf("isNumeric %s\n",(value ? "true" : "false"));
String myString("type ");
TypeFunc::toString(&myString,type);
myString += " scalarType ";
ScalarTypeFunc::toString(&myString,scalarType);
printf("%s\n",myString.c_str());
FieldCreate * pfieldCreate = getFieldCreate();
String valueName("value");
ScalarConstPtr pscalar = pfieldCreate->createScalar(valueName,scalarType);
type = pscalar->getType();
myString.clear();
myString += "type ";
TypeFunc::toString(&myString,type);
printf("%s\n",myString.c_str());
myString.clear();
myString += "fieldName ";
String fieldName = pscalar->getFieldName();
myString += fieldName;
printf("%s\n",myString.c_str());
myString.clear();
pscalar->toString(&myString);
printf("%s\n",myString.c_str());
ScalarArrayConstPtr pscalarArray = pfieldCreate->createScalarArray(valueName,pvString);
myString.clear();
pscalarArray->toString(&myString);
printf("%s\n",myString.c_str());
int numberFields = 2;
FieldConstPtr fields[numberFields];
String name0("high");
String name1("low");
fields[0] = pfieldCreate->createScalar(name0,pvDouble);
fields[1] = pfieldCreate->createScalar(name1,pvDouble);
StructureConstPtr pstructure = pfieldCreate->createStructure(
valueName,numberFields,fields);
myString.clear();
pstructure->toString(&myString);
printf("%s\n",myString.c_str());
FieldConstPtr pfield = pstructure;
myString.clear();
pfield->toString(&myString);
printf("as Field\n%s/n",myString.c_str());
return(0);
}

View File

@@ -1,24 +0,0 @@
/* testIntrospectScalar.cpp */
/* Author: Marty Kraimer Date: 2010.10 */
#include <stddef.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include "pvIntrospect.h"
#include "standardField.h"
using namespace epics::pvData;
int main(int argc,char *argv[])
{
StandardField *standardField = getStandardField();
StructureConstPtr doubleValue = standardField->scalarValue(
pvDouble,String("alarm,timeStamp,display,control,doubleAlarm"));
String buffer("");
doubleValue->toString(&buffer);
printf("doubleValue\n,%s\n",buffer.c_str());
return(0);
}

79
test/testIntrospect Normal file
View File

@@ -0,0 +1,79 @@
testScalar
boolean boolean
byte byte
short short
int int
long long
float float
double double
string string
testScalarArray
booleanArray boolean
byteArray byte
shortArray short
intArray int
longArray long
floatArray float
doubleArray double
stringArray string
testSimpleStructure
structure value
double value
structure alarm
int severity
string message
structure timeStamp
long secondsPastEpoch
int nanoSeconds
structure display
string description
string format
string units
structure limit
double low
double high
structure control
structure limit
double low
double high
double minStep
structure valueAlarm
boolean active
double lowAlarmLimit
double lowWarningLimit
double highWarningLimit
double highAlarmLimit
int lowAlarmSeverity
int lowWarningSeverity
int highWarningSeverity
int highAlarmSeverity
double hystersis
testStructureArray
structure value
structureArray value
structure powerSupply
structure voltage
double value
structure alarm
int severity
string message
structure power
double value
structure alarm
int severity
string message
structure current
double value
structure alarm
int severity
string message
structure alarm
int severity
string message
structure timeStamp
long secondsPastEpoch
int nanoSeconds

12
test/testIntrospect.pl Executable file
View File

@@ -0,0 +1,12 @@
eval 'exec perl -S $0 ${1+"$@"}' # -*- Mode: perl -*-
if $running_under_some_shell; # testIntrospect.pl
$EPICS_HOST_ARCH = "linux-x86";
system ("rm testIntrospect");
system ("rm testIntrospectDiff");
system ("../bin/${EPICS_HOST_ARCH}/testIntrospect testIntrospect");
system ("diff testIntrospect testIntrospectGold >> testIntrospectDiff");
if(-z "testIntrospectDiff") {
print "testIntrospect OK\n";
} else {
print "testIntrospect Failed\n";
}

0
test/testIntrospectDiff Normal file
View File

79
test/testIntrospectGold Normal file
View File

@@ -0,0 +1,79 @@
testScalar
boolean boolean
byte byte
short short
int int
long long
float float
double double
string string
testScalarArray
booleanArray boolean
byteArray byte
shortArray short
intArray int
longArray long
floatArray float
doubleArray double
stringArray string
testSimpleStructure
structure value
double value
structure alarm
int severity
string message
structure timeStamp
long secondsPastEpoch
int nanoSeconds
structure display
string description
string format
string units
structure limit
double low
double high
structure control
structure limit
double low
double high
double minStep
structure valueAlarm
boolean active
double lowAlarmLimit
double lowWarningLimit
double highWarningLimit
double highAlarmLimit
int lowAlarmSeverity
int lowWarningSeverity
int highWarningSeverity
int highAlarmSeverity
double hystersis
testStructureArray
structure value
structureArray value
structure powerSupply
structure voltage
double value
structure alarm
int severity
string message
structure power
double value
structure alarm
int severity
string message
structure current
double value
structure alarm
int severity
string message
structure alarm
int severity
string message
structure timeStamp
long secondsPastEpoch
int nanoSeconds